/[MITgcm]/MITgcm/pkg/autodiff/global_max_ad.F
ViewVC logotype

Contents of /MITgcm/pkg/autodiff/global_max_ad.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download)
Fri Jun 20 21:43:19 2008 UTC (15 years, 11 months ago) by heimbach
Branch: MAIN
CVS Tags: checkpoint61, checkpoint61f, checkpoint61n, checkpoint61e, checkpoint61g, checkpoint61d, checkpoint61b, checkpoint61c, checkpoint61a, checkpoint61o, checkpoint61l, checkpoint61m, checkpoint61j, checkpoint61k, checkpoint61h, checkpoint61i
Changes since 1.2: +17 -3 lines
o autodiff
  Change default for TAF usage by removing argument '-nonew_arg'
  This changes TAF subroutine argument list (ordering of active var.)
  Omission of this flag leads to incompatibility w.r.t. TAMC
  To restore TAMC-compatibility, need following modifs:
  * use adoptfile tools/adjoint_options/adjoint_tamc_compatibility
  * use CPP option #define AUTODIFF_TAMC_COMPATIBILITY
  Tested TAF version is 1.9.22
  N.B.: exch2 hand-written adjoint code currently not TAMC compatible

1 C $Header: /u/gcmpack/MITgcm/pkg/autodiff/global_max_ad.F,v 1.2 2002/07/13 03:30:30 heimbach Exp $
2 C $Name: $
3
4 C-- File global_max.F: Routines that perform global max reduction on an array
5 C of thread values.
6 C
7 C Adjoint routines are identical to forward routines,
8 C but parameter list is reversed to be consistent with
9 C call statement generated by TAMC/TAF
10 C P. Heimbach, 16-Apr-2002
11 C
12 C Contents
13 C o global_admax_r4
14 C o global_admax_r8
15 #include "CPP_EEOPTIONS.h"
16
17 CBOP
18
19 C !ROUTINE: GLOBAL_ADMAX_R4
20
21 C !INTERFACE:
22 #ifdef AUTODIFF_TAMC_COMPATIBILITY
23 SUBROUTINE GLOBAL_ADMAX_R4(
24 I myThid,
25 U maxPhi
26 & )
27 #else
28 SUBROUTINE GLOBAL_ADMAX_R4(
29 U maxPhi,
30 I myThid
31 & )
32 #endif
33 IMPLICIT NONE
34 C !DESCRIPTION:
35 C *==========================================================*
36 C | SUBROUTINE GLOBAL_ADMAX_R4
37 C | o Handle max for real*4 data.
38 C *==========================================================*
39 C | Perform max on array of one value per thread and then
40 C | max result of all the processes.
41 C | Notes
42 C | =====
43 C | Within a process only one thread does the max, each
44 C | thread is assumed to have already maxed its local data.
45 C | The same thread also does the inter-process max for
46 C | example with MPI and then writes the result into a shared
47 C | location. All threads wait until the max is avaiailable.
48 C *==========================================================*
49
50 C !USES:
51 C == Global data ==
52 #include "SIZE.h"
53 #include "EEPARAMS.h"
54 #include "EESUPPORT.h"
55 #include "GLOBAL_MAX.h"
56
57 C !INPUT/OUTPUT PARAMETERS:
58 C == Routine arguments ==
59 C maxPhi :: Result of max.
60 C myThid :: My thread id.
61 Real*4 maxPhi
62 INTEGER myThid
63
64 C !LOCAL VARIABLES:
65 C == Local variables ==
66 C I :: Loop counters
67 C mpiRC :: MPI return code
68 INTEGER I
69 Real*4 tmp
70 #ifdef ALLOW_USE_MPI
71 INTEGER mpiRC
72 #endif /* ALLOW_USE_MPI */
73 CEOP
74
75 CALL BAR2( myThid )
76 C-- write local max into array
77 phiGMRS(1,myThid) = maxPhi
78
79 C-- Can not start until everyone is ready
80 CALL BAR2( myThid )
81
82 C-- Max within the process first
83 _BEGIN_MASTER( myThid )
84 tmp = phiGMRS(1,1)
85 DO I=2,nThreads
86 tmp = MAX(tmp,phiGMRS(1,I))
87 ENDDO
88 maxPhi = tmp
89 #ifdef ALLOW_USE_MPI
90 #ifndef ALWAYS_USE_MPI
91 IF ( usingMPI ) THEN
92 #endif
93 CALL MPI_Allreduce(tmp,maxPhi,1,MPI_REAL,MPI_MAX,
94 & MPI_COMM_WORLD,mpiRC)
95 #ifndef ALWAYS_USE_MPI
96 ENDIF
97 #endif
98 #endif /* ALLOW_USE_MPI */
99 phiGMRS(1,1) = maxPhi
100 _END_MASTER( myThid )
101 C--
102 CALL BAR2( myThid )
103
104 C-- set result for every process
105 maxPhi = phiGMRS(1,1)
106 CALL BAR2( myThid )
107
108 RETURN
109 END
110
111 CBOP
112
113 C !ROUTINE: GLOBAL_ADMAX_R8
114
115 C !INTERFACE:
116 #ifdef AUTODIFF_TAMC_COMPATIBILITY
117 SUBROUTINE GLOBAL_ADMAX_R8(
118 I myThid,
119 U maxPhi
120 & )
121 #else
122 SUBROUTINE GLOBAL_ADMAX_R8(
123 U maxPhi,
124 I myThid
125 & )
126 #endif
127 IMPLICIT NONE
128 C !DESCRIPTION:
129 C *==========================================================*
130 C | SUBROUTINE GLOBAL_ADMAX_R8
131 C | o Handle max for real*8 data.
132 C *==========================================================*
133 C | Perform max on array of one value per thread and then
134 C | max result of all the processes.
135 C | Notes
136 C | =====
137 C | Within a process only one thread does the max, each
138 C | thread is assumed to have already maxed its local data.
139 C | The same thread also does the inter-process max for
140 C | example with MPI and then writes the result into a shared
141 C | location. All threads wait until the max is avaiailable.
142 C *==========================================================*
143
144 C !USES:
145 C === Global data ===
146 #include "SIZE.h"
147 #include "EEPARAMS.h"
148 #include "EESUPPORT.h"
149 #include "GLOBAL_MAX.h"
150
151 C !INPUT/OUTPUT PARAMETERS:
152 C === Routine arguments ===
153 C maxPhi :: Result of max.
154 C myThid :: My thread id.
155 Real*8 maxPhi
156 INTEGER myThid
157
158 C !LOCAL VARIABLES:
159 C === Local variables ===
160 C I :: Loop counters
161 C mpiRC :: MPI return code
162 INTEGER I
163 Real*8 tmp
164 #ifdef ALLOW_USE_MPI
165 INTEGER mpiRC
166 #endif /* ALLOW_USE_MPI */
167 CEOP
168
169 CALL BAR2( myThid )
170 C-- write local max into array
171 phiGMRL(1,myThid) = maxPhi
172
173 C-- Can not start until everyone is ready
174 CALL BAR2( myThid )
175
176 C-- Max within the process first
177 _BEGIN_MASTER( myThid )
178 tmp = phiGMRL(1,1)
179 DO I=2,nThreads
180 tmp = MAX(tmp,phiGMRL(1,I))
181 ENDDO
182 maxPhi = tmp
183 #ifdef ALLOW_USE_MPI
184 #ifndef ALWAYS_USE_MPI
185 IF ( usingMPI ) THEN
186 #endif
187 CALL MPI_Allreduce(tmp,maxPhi,1,MPI_DOUBLE_PRECISION,MPI_MAX,
188 & MPI_COMM_WORLD,mpiRC)
189 #ifndef ALWAYS_USE_MPI
190 ENDIF
191 #endif
192 #endif /* ALLOW_USE_MPI */
193 C-- Write solution to place where all threads can see it
194 phiGMRL(1,1) = maxPhi
195 _END_MASTER( myThid )
196
197 C-- Do not leave until we are sure that the max is done
198 CALL BAR2( myThid )
199
200 C-- set result for every process
201 maxPhi = phiGMRL(1,1)
202 CALL BAR2( myThid )
203
204 RETURN
205 END

  ViewVC Help
Powered by ViewVC 1.1.22