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