9 |
|
|
10 |
CStartOfInterface |
CStartOfInterface |
11 |
SUBROUTINE GLOBAL_SUM_R4( |
SUBROUTINE GLOBAL_SUM_R4( |
12 |
I phi, |
U sumPhi, |
|
O sumPhi, |
|
13 |
I myThid ) |
I myThid ) |
14 |
C /==========================================================\ |
C /==========================================================\ |
15 |
C | SUBROUTINE GLOBAL_SUM_R4 | |
C | SUBROUTINE GLOBAL_SUM_R4 | |
25 |
C | example with MPI and then writes the result into a shared| |
C | example with MPI and then writes the result into a shared| |
26 |
C | location. All threads wait until the sum is avaiailable. | |
C | location. All threads wait until the sum is avaiailable. | |
27 |
C \==========================================================/ |
C \==========================================================/ |
28 |
|
IMPLICIT NONE |
29 |
|
|
30 |
C == Global data == |
C == Global data == |
31 |
#include "SIZE.h" |
#include "SIZE.h" |
33 |
#include "EESUPPORT.h" |
#include "EESUPPORT.h" |
34 |
|
|
35 |
C == Routine arguments == |
C == Routine arguments == |
|
C phi - Array to be summed. |
|
36 |
C sumPhi - Result of sum. |
C sumPhi - Result of sum. |
37 |
C myThid - My thread id. |
C myThid - My thread id. |
|
Real*4 phi(lShare4,MAX_NO_THREADS) |
|
38 |
Real*4 sumPhi |
Real*4 sumPhi |
39 |
INTEGER myThid |
INTEGER myThid |
40 |
CEndOfInterface |
CEndOfInterface |
41 |
|
|
42 |
C == Local variables == |
C == Local variables == |
43 |
|
C phi - Array to be summed. |
44 |
C I - Loop counters |
C I - Loop counters |
45 |
C mpiRC - MPI return code |
C mpiRC - MPI return code |
46 |
|
Real*4 phi(lShare4,MAX_NO_THREADS) |
47 |
INTEGER I |
INTEGER I |
48 |
Real*4 tmp |
Real*4 tmp |
49 |
#ifdef ALLOW_USE_MPI |
#ifdef ALLOW_USE_MPI |
50 |
INTEGER mpiRC |
INTEGER mpiRC |
51 |
#endif /* ALLOW_USE_MPI */ |
#endif /* ALLOW_USE_MPI */ |
52 |
|
|
53 |
C-- Can't start until everyone is ready |
C-- write local sum into array |
54 |
|
phi(1,myThid) = sumPhi |
55 |
|
|
56 |
|
C-- Can not start until everyone is ready |
57 |
_BARRIER |
_BARRIER |
58 |
|
|
59 |
C-- Sum within the process first |
C-- Sum within the process first |
73 |
ENDIF |
ENDIF |
74 |
#endif |
#endif |
75 |
#endif /* ALLOW_USE_MPI */ |
#endif /* ALLOW_USE_MPI */ |
76 |
|
C-- Write solution to place where all threads can see it |
77 |
phi(1,1) = sumPhi |
phi(1,1) = sumPhi |
78 |
|
|
79 |
_END_MASTER( myThid ) |
_END_MASTER( myThid ) |
80 |
C-- |
C-- |
81 |
_BARRIER |
_BARRIER |
82 |
C |
|
83 |
|
C-- set result for every process |
84 |
|
sumPhi = phi(1,1) |
85 |
|
|
86 |
RETURN |
RETURN |
87 |
END |
END |
88 |
|
|
89 |
|
|
90 |
CStartOfInterface |
CStartOfInterface |
91 |
SUBROUTINE GLOBAL_SUM_R8( |
SUBROUTINE GLOBAL_SUM_R8( |
92 |
I phi, |
U sumPhi, |
|
O sumPhi, |
|
93 |
I myThid ) |
I myThid ) |
94 |
C /==========================================================\ |
C /==========================================================\ |
95 |
C | SUBROUTINE GLOBAL_SUM_R8 | |
C | SUBROUTINE GLOBAL_SUM_R8 | |
105 |
C | example with MPI and then writes the result into a shared| |
C | example with MPI and then writes the result into a shared| |
106 |
C | location. All threads wait until the sum is avaiailable. | |
C | location. All threads wait until the sum is avaiailable. | |
107 |
C \==========================================================/ |
C \==========================================================/ |
108 |
|
IMPLICIT NONE |
109 |
|
|
110 |
C === Global data === |
C === Global data === |
111 |
#include "SIZE.h" |
#include "SIZE.h" |
113 |
#include "EESUPPORT.h" |
#include "EESUPPORT.h" |
114 |
|
|
115 |
C === Routine arguments === |
C === Routine arguments === |
|
C phi - Array to be summed. |
|
116 |
C sumPhi - Result of sum. |
C sumPhi - Result of sum. |
117 |
C myThid - My thread id. |
C myThid - My thread id. |
|
Real*8 phi(lShare8,MAX_NO_THREADS) |
|
118 |
Real*8 sumPhi |
Real*8 sumPhi |
119 |
INTEGER myThid |
INTEGER myThid |
120 |
CEndOfInterface |
CEndOfInterface |
121 |
|
|
122 |
C === Local variables === |
C === Local variables === |
123 |
|
C phi - Array to be summed. |
124 |
C I - Loop counters |
C I - Loop counters |
125 |
C mpiRC - MPI return code |
C mpiRC - MPI return code |
126 |
|
Real*8 phi(lShare8,MAX_NO_THREADS) |
127 |
INTEGER I |
INTEGER I |
128 |
Real*8 tmp |
Real*8 tmp |
129 |
#ifdef ALLOW_USE_MPI |
#ifdef ALLOW_USE_MPI |
130 |
INTEGER mpiRC |
INTEGER mpiRC |
131 |
#endif /* ALLOW_USE_MPI */ |
#endif /* ALLOW_USE_MPI */ |
132 |
|
|
133 |
C-- Can't start until everyone is ready |
C-- write local sum into array |
134 |
|
phi(1,myThid) = sumPhi |
135 |
|
|
136 |
|
C-- Can not start until everyone is ready |
137 |
_BARRIER |
_BARRIER |
138 |
|
|
139 |
C-- Sum within the process first |
C-- Sum within the process first |
157 |
phi(1,1) = sumPhi |
phi(1,1) = sumPhi |
158 |
_END_MASTER( myThid ) |
_END_MASTER( myThid ) |
159 |
|
|
160 |
C-- Don't leave until we are sure that the sum is done |
C-- Do not leave until we are sure that the sum is done |
161 |
_BARRIER |
_BARRIER |
162 |
C |
|
163 |
|
C-- set result for every process |
164 |
|
sumPhi = phi(1,1) |
165 |
|
|
166 |
RETURN |
RETURN |
167 |
END |
END |
168 |
|
CStartOfInterface |
169 |
|
SUBROUTINE GLOBAL_SUM_INT( |
170 |
|
U sumPhi, |
171 |
|
I myThid ) |
172 |
|
C /==========================================================\ |
173 |
|
C | SUBROUTINE GLOBAL_SUM_INT | |
174 |
|
C | o Handle sum for integer data. | |
175 |
|
C |==========================================================| |
176 |
|
C | Perform sum an array of one value per thread and then | |
177 |
|
C | sum result of all the processes. | |
178 |
|
C | Notes | |
179 |
|
C | ===== | |
180 |
|
C | Within a process only one thread does the sum, each | |
181 |
|
C | thread is assumed to have already summed its local data. | |
182 |
|
C | The same thread also does the inter-process sum for | |
183 |
|
C | example with MPI and then writes the result into a shared| |
184 |
|
C | location. All threads wait until the sum is avaiailable. | |
185 |
|
C \==========================================================/ |
186 |
|
IMPLICIT NONE |
187 |
|
|
188 |
|
C === Global data === |
189 |
|
#include "SIZE.h" |
190 |
|
#include "EEPARAMS.h" |
191 |
|
#include "EESUPPORT.h" |
192 |
|
|
193 |
|
C === Routine arguments === |
194 |
|
C sumPhi - Result of sum. |
195 |
|
C myThid - My thread id. |
196 |
|
INTEGER sumPhi |
197 |
|
INTEGER myThid |
198 |
|
CEndOfInterface |
199 |
|
|
200 |
|
C === Local variables === |
201 |
|
C phi - Array to be summed. |
202 |
|
C I - Loop counters |
203 |
|
C mpiRC - MPI return code |
204 |
|
INTEGER phi(lShare8,MAX_NO_THREADS) |
205 |
|
INTEGER I |
206 |
|
INTEGER tmp |
207 |
|
#ifdef ALLOW_USE_MPI |
208 |
|
INTEGER mpiRC |
209 |
|
#endif /* ALLOW_USE_MPI */ |
210 |
|
|
211 |
|
C-- write local sum into array |
212 |
|
phi(1,myThid) = sumPhi |
213 |
|
|
214 |
C $Id$ |
C-- Can not start until everyone is ready |
215 |
|
_BARRIER |
216 |
|
|
217 |
|
C-- Sum within the process first |
218 |
|
_BEGIN_MASTER( myThid ) |
219 |
|
tmp = 0. _d 0 |
220 |
|
DO I=1,nThreads |
221 |
|
tmp = tmp + phi(1,I) |
222 |
|
ENDDO |
223 |
|
sumPhi = tmp |
224 |
|
#ifdef ALLOW_USE_MPI |
225 |
|
#ifndef ALWAYS_USE_MPI |
226 |
|
IF ( usingMPI ) THEN |
227 |
|
#endif |
228 |
|
CALL MPI_Allreduce(tmp,sumPhi,1,MPI_INTEGER,MPI_SUM, |
229 |
|
& MPI_COMM_WORLD,mpiRC) |
230 |
|
#ifndef ALWAYS_USE_MPI |
231 |
|
ENDIF |
232 |
|
#endif |
233 |
|
#endif /* ALLOW_USE_MPI */ |
234 |
|
C-- Write solution to place where all threads can see it |
235 |
|
phi(1,1) = sumPhi |
236 |
|
_END_MASTER( myThid ) |
237 |
|
|
238 |
|
C-- Do not leave until we are sure that the sum is done |
239 |
|
_BARRIER |
240 |
|
|
241 |
|
C-- set result for every process |
242 |
|
sumPhi = phi(1,1) |
243 |
|
|
244 |
|
RETURN |
245 |
|
END |