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-- write local sum into array |
54 |
|
phi(1,myThid) = sumPhi |
55 |
|
|
56 |
C-- Can not start until everyone is ready |
C-- Can not start until everyone is ready |
57 |
_BARRIER |
_BARRIER |
58 |
|
|
68 |
IF ( usingMPI ) THEN |
IF ( usingMPI ) THEN |
69 |
#endif |
#endif |
70 |
CALL MPI_Allreduce(tmp,sumPhi,1,MPI_REAL,MPI_SUM, |
CALL MPI_Allreduce(tmp,sumPhi,1,MPI_REAL,MPI_SUM, |
71 |
& MPI_COMM_MODEL,mpiRC) |
& MPI_COMM_WORLD,mpiRC) |
72 |
#ifndef ALWAYS_USE_MPI |
#ifndef ALWAYS_USE_MPI |
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-- write local sum into array |
134 |
|
phi(1,myThid) = sumPhi |
135 |
|
|
136 |
C-- Can not start until everyone is ready |
C-- Can not start until everyone is ready |
137 |
_BARRIER |
_BARRIER |
138 |
|
|
148 |
IF ( usingMPI ) THEN |
IF ( usingMPI ) THEN |
149 |
#endif |
#endif |
150 |
CALL MPI_Allreduce(tmp,sumPhi,1,MPI_DOUBLE_PRECISION,MPI_SUM, |
CALL MPI_Allreduce(tmp,sumPhi,1,MPI_DOUBLE_PRECISION,MPI_SUM, |
151 |
& MPI_COMM_MODEL,mpiRC) |
& MPI_COMM_WORLD,mpiRC) |
152 |
#ifndef ALWAYS_USE_MPI |
#ifndef ALWAYS_USE_MPI |
153 |
ENDIF |
ENDIF |
154 |
#endif |
#endif |
159 |
|
|
160 |
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 |
161 |
_BARRIER |
_BARRIER |
162 |
C |
|
163 |
|
C-- set result for every process |
164 |
|
sumPhi = phi(1,1) |
165 |
|
|
166 |
RETURN |
RETURN |
167 |
END |
END |