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