/[MITgcm]/MITgcm/eesupp/src/global_sum.F
ViewVC logotype

Contents of /MITgcm/eesupp/src/global_sum.F

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


Revision 1.16 - (show annotations) (download)
Thu Sep 6 15:25:01 2012 UTC (11 years, 8 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, checkpoint64, checkpoint65, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint65o, checkpoint64y, checkpoint64x, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, HEAD
Changes since 1.15: +10 -22 lines
finish to remove ALWAYS_USE_MPI in source code that TAF does not see

1 C $Header: /u/gcmpack/MITgcm/eesupp/src/global_sum.F,v 1.15 2010/04/27 16:09:47 jmc Exp $
2 C $Name: $
3
4 #include "CPP_EEOPTIONS.h"
5
6 C-- File global_sum.F: Routines that perform global sum on an array
7 C of thread values.
8 C Contents
9 C o GLOBAL_SUM_R4
10 C o GLOBAL_SUM_R8
11 C o GLOBAL_SUM_INT
12
13 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
14 CBOP
15 C !ROUTINE: GLOBAL_SUM_R4
16
17 C !INTERFACE:
18 SUBROUTINE GLOBAL_SUM_R4(
19 U sumPhi,
20 I myThid )
21
22 C !DESCRIPTION:
23 C *==========================================================*
24 C | SUBROUTINE GLOBAL\_SUM\_R4
25 C | o Handle sum for real*4 data.
26 C *==========================================================*
27 C | Perform sum an array of one value per thread and then
28 C | sum result of all the processes.
29 C | Notes:
30 C | Within a process only one thread does the sum.
31 C | The same thread also does the inter-process sum for
32 C | example with MPI and then writes the result into a shared
33 C | location. All threads wait until the sum is avaiailable.
34 C *==========================================================*
35
36 C !USES:
37 IMPLICIT NONE
38
39 C == Global data ==
40 #include "SIZE.h"
41 #include "EEPARAMS.h"
42 #include "EESUPPORT.h"
43 #include "GLOBAL_SUM.h"
44
45 C !INPUT/OUTPUT PARAMETERS:
46 C == Routine arguments ==
47 C sumPhi :: Result of sum.
48 C myThid :: My thread id.
49 Real*4 sumPhi
50 INTEGER myThid
51
52 C !LOCAL VARIABLES:
53 C == Local variables ==
54 C I :: Loop counters
55 C mpiRC :: MPI return code
56 INTEGER I
57 Real*4 tmp
58 #ifdef ALLOW_USE_MPI
59 INTEGER mpiRC
60 #endif /* ALLOW_USE_MPI */
61 CEOP
62
63 C-- write local sum into array
64 phiGSR4(1,myThid) = sumPhi
65
66 C-- Can not start until everyone is ready
67 CALL BAR2( myThid )
68
69 C-- Sum within the process first
70 _BEGIN_MASTER( myThid )
71 tmp = 0.
72 DO I=1,nThreads
73 tmp = tmp + phiGSR4(1,I)
74 ENDDO
75 sumPhi = tmp
76 #ifdef ALLOW_USE_MPI
77 IF ( usingMPI ) THEN
78 CALL MPI_Allreduce(tmp,sumPhi,1,MPI_REAL,MPI_SUM,
79 & MPI_COMM_MODEL,mpiRC)
80 ENDIF
81 #endif /* ALLOW_USE_MPI */
82 C-- Write solution to place where all threads can see it
83 phiGSR4(1,0) = sumPhi
84
85 _END_MASTER( myThid )
86 C--
87 CALL BAR2( myThid )
88
89 C-- set result for every process
90 sumPhi = phiGSR4(1,0)
91
92 RETURN
93 END
94
95
96 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
97 CBOP
98 C !ROUTINE: GLOBAL_SUM_R8
99
100 C !INTERFACE:
101 SUBROUTINE GLOBAL_SUM_R8(
102 U sumPhi,
103 I myThid )
104
105 C !DESCRIPTION:
106 C *==========================================================*
107 C | SUBROUTINE GLOBAL\_SUM\_R8
108 C | o Handle sum for real*8 data.
109 C *==========================================================*
110 C | Perform sum an array of one value per thread and then
111 C | sum result of all the processes.
112 C | Notes:
113 C | Within a process only one thread does the sum.
114 C | The same thread also does the inter-process sum for
115 C | example with MPI and then writes the result into a shared
116 C | location. All threads wait until the sum is avaiailable.
117 C *==========================================================*
118
119 C !USES:
120 IMPLICIT NONE
121
122 C === Global data ===
123 #include "SIZE.h"
124 #include "EEPARAMS.h"
125 #include "EESUPPORT.h"
126 #include "GLOBAL_SUM.h"
127
128 C !INPUT/OUTPUT PARAMETERS:
129 C === Routine arguments ===
130 C sumPhi :: Result of sum.
131 C myThid :: My thread id.
132 Real*8 sumPhi
133 INTEGER myThid
134
135 C !LOCAL VARIABLES:
136 C === Local variables ===
137 C I :: Loop counters
138 C mpiRC :: MPI return code
139 INTEGER I
140 Real*8 tmp
141 #ifdef ALLOW_USE_MPI
142 INTEGER mpiRC
143 #endif /* ALLOW_USE_MPI */
144 CEOP
145
146 C-- write local sum into array
147 phiGSR8(1,myThid) = sumPhi
148
149 C-- Can not start until everyone is ready
150 C CALL FOOL_THE_COMPILER( phiGSR8 )
151 C CALL MS
152 CALL BAR2( myThid )
153 C _BARRIER
154 C _BARRIER
155 C CALL FOOL_THE_COMPILER( phiGSR8 )
156
157 C-- Sum within the process first
158 _BEGIN_MASTER( myThid )
159 tmp = 0. _d 0
160 DO I=1,nThreads
161 tmp = tmp + phiGSR8(1,I)
162 ENDDO
163 sumPhi = tmp
164 #ifdef ALLOW_USE_MPI
165 IF ( usingMPI ) THEN
166 CALL MPI_Allreduce(tmp,sumPhi,1,MPI_DOUBLE_PRECISION,MPI_SUM,
167 & MPI_COMM_MODEL,mpiRC)
168 ENDIF
169 #endif /* ALLOW_USE_MPI */
170 C-- Write solution to place where all threads can see it
171 phiGSR8(1,0) = sumPhi
172 _END_MASTER( myThid )
173
174 C-- Do not leave until we are sure that the sum is done
175 C CALL FOOL_THE_COMPILER( phiGSR8 )
176 C CALL MS
177 C _BARRIER
178 C _BARRIER
179 CALL BAR2( myThid )
180 C CALL FOOL_THE_COMPILER( phiGSR8 )
181
182 C-- set result for every process
183 sumPhi = phiGSR8(1,0)
184
185 RETURN
186 END
187
188 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
189 CBOP
190 C !ROUTINE: GLOBAL_SUM_INT
191 C !INTERFACE:
192 SUBROUTINE GLOBAL_SUM_INT(
193 U sumPhi,
194 I myThid )
195
196 C !DESCRIPTION:
197 C *==========================================================*
198 C | SUBROUTINE GLOBAL\_SUM\_INT
199 C | o Handle sum for integer data.
200 C *==========================================================*
201 C | Perform sum an array of one value per thread and then
202 C | sum result of all the processes.
203 C | Notes:
204 C | Within a process only one thread does the sum.
205 C | The same thread also does the inter-process sum for
206 C | example with MPI and then writes the result into a shared
207 C | location. All threads wait until the sum is avaiailable.
208 C *==========================================================*
209
210 C !USES:
211 IMPLICIT NONE
212
213 C === Global data ===
214 #include "SIZE.h"
215 #include "EEPARAMS.h"
216 #include "EESUPPORT.h"
217 #include "GLOBAL_SUM.h"
218
219 C !INPUT/OUTPUT PARAMETERS:
220 C === Routine arguments ===
221 C sumPhi :: Result of sum.
222 C myThid :: My thread id.
223 INTEGER sumPhi
224 INTEGER myThid
225
226 C !LOCAL VARIABLES:
227 C === Local variables ===
228 C I :: Loop counters
229 C mpiRC :: MPI return code
230 INTEGER I
231 INTEGER tmp
232 #ifdef ALLOW_USE_MPI
233 INTEGER mpiRC
234 #endif /* ALLOW_USE_MPI */
235 CEOP
236
237 C-- write local sum into array
238 phiGSI(1,myThid) = sumPhi
239
240 C-- Can not start until everyone is ready
241 _BARRIER
242
243 C-- Sum within the process first
244 _BEGIN_MASTER( myThid )
245 tmp = 0
246 DO I=1,nThreads
247 tmp = tmp + phiGSI(1,I)
248 ENDDO
249 sumPhi = tmp
250 #ifdef ALLOW_USE_MPI
251 IF ( usingMPI ) THEN
252 CALL MPI_Allreduce(tmp,sumPhi,1,MPI_INTEGER,MPI_SUM,
253 & MPI_COMM_MODEL,mpiRC)
254 ENDIF
255 #endif /* ALLOW_USE_MPI */
256 C-- Write solution to place where all threads can see it
257 phiGSI(1,0) = sumPhi
258 _END_MASTER( myThid )
259
260 C-- Do not leave until we are sure that the sum is done
261 _BARRIER
262
263 C-- set result for every process
264 sumPhi = phiGSI(1,0)
265
266 RETURN
267 END

  ViewVC Help
Powered by ViewVC 1.1.22