1 |
C-- File global_adsum.F: Routines that perform adjoint of |
2 |
C global sum on an array of thread values. |
3 |
C Contents |
4 |
C o global_adsum_r4 |
5 |
C o global_adsum_r8 |
6 |
#include "CPP_EEOPTIONS.h" |
7 |
|
8 |
CStartOfInterface |
9 |
SUBROUTINE GLOBAL_ADSUM_R4( |
10 |
I myThid, |
11 |
U adsumPhi |
12 |
& ) |
13 |
C /==========================================================\ |
14 |
C | SUBROUTINE GLOBAL_ADSUM_R4 | |
15 |
C | o Handle sum for real*4 data. | |
16 |
C |==========================================================| |
17 |
C \==========================================================/ |
18 |
|
19 |
C == Global data == |
20 |
implicit none |
21 |
#include "SIZE.h" |
22 |
#include "EEPARAMS.h" |
23 |
#include "EESUPPORT.h" |
24 |
|
25 |
C == Routine arguments == |
26 |
C sumPhi - Result of sum. |
27 |
C myThid - My thread id. |
28 |
Real*4 adsumPhi |
29 |
INTEGER myThid |
30 |
CEndOfInterface |
31 |
|
32 |
C == Local variables == |
33 |
C adphi - Array to be summed. |
34 |
C I - Loop counters |
35 |
C mpiRC - MPI return code |
36 |
Real*4 adphi(lShare4,MAX_NO_THREADS) |
37 |
INTEGER I |
38 |
Real*4 tmp |
39 |
#ifdef ALLOW_USE_MPI |
40 |
INTEGER mpiRC |
41 |
#endif /* ALLOW_USE_MPI */ |
42 |
|
43 |
C-- Can not start until everyone is ready |
44 |
_BARRIER |
45 |
|
46 |
C-- broadcast to all processes |
47 |
_BEGIN_MASTER( myThid ) |
48 |
|
49 |
tmp = adsumPhi |
50 |
|
51 |
#ifdef ALLOW_USE_MPI |
52 |
#ifndef ALWAYS_USE_MPI |
53 |
IF ( usingMPI ) THEN |
54 |
#endif |
55 |
CALL MPI_Bcast(tmp, 1, MPI_REAL, myThid |
56 |
& , MPI_COMM_WORLD, mpiRC |
57 |
& ) |
58 |
#ifndef ALWAYS_USE_MPI |
59 |
ENDIF |
60 |
#endif |
61 |
#endif /* ALLOW_USE_MPI */ |
62 |
|
63 |
DO I=1,nThreads |
64 |
adphi(1,I) = tmp |
65 |
ENDDO |
66 |
|
67 |
_END_MASTER( myThid ) |
68 |
C-- |
69 |
_BARRIER |
70 |
C |
71 |
C-- every thread takes its adjoint sum |
72 |
adsumPhi = adphi(1,myThid) |
73 |
|
74 |
RETURN |
75 |
END |
76 |
|
77 |
|
78 |
#include "CPP_EEOPTIONS.h" |
79 |
|
80 |
CStartOfInterface |
81 |
SUBROUTINE GLOBAL_ADSUM_R8( |
82 |
I myThid, |
83 |
U adsumPhi |
84 |
& ) |
85 |
C /==========================================================\ |
86 |
C | SUBROUTINE GLOBAL_ADSUM_R4 | |
87 |
C | o Handle sum for real*8 data. | |
88 |
C |==========================================================| |
89 |
C \==========================================================/ |
90 |
|
91 |
C == Global data == |
92 |
#include "SIZE.h" |
93 |
#include "EEPARAMS.h" |
94 |
#include "EESUPPORT.h" |
95 |
|
96 |
C == Routine arguments == |
97 |
C sumPhi - Result of sum. |
98 |
C myThid - My thread id. |
99 |
Real*8 adsumPhi |
100 |
INTEGER myThid |
101 |
CEndOfInterface |
102 |
|
103 |
C == Local variables == |
104 |
C adphi - Array to be summed. |
105 |
C I - Loop counters |
106 |
C mpiRC - MPI return code |
107 |
Real*8 adphi(lShare8,MAX_NO_THREADS) |
108 |
INTEGER I |
109 |
Real*8 tmp |
110 |
#ifdef ALLOW_USE_MPI |
111 |
INTEGER mpiRC |
112 |
#endif /* ALLOW_USE_MPI */ |
113 |
|
114 |
C-- Can not start until everyone is ready |
115 |
_BARRIER |
116 |
|
117 |
C-- broadcast to all processes |
118 |
_BEGIN_MASTER( myThid ) |
119 |
|
120 |
tmp = adsumPhi |
121 |
|
122 |
#ifdef ALLOW_USE_MPI |
123 |
#ifndef ALWAYS_USE_MPI |
124 |
IF ( usingMPI ) THEN |
125 |
#endif |
126 |
CALL MPI_Bcast(tmp, 1, MPI_DOUBLE_PRECISION, myThid |
127 |
& , MPI_COMM_WORLD, mpiRC |
128 |
& ) |
129 |
#ifndef ALWAYS_USE_MPI |
130 |
ENDIF |
131 |
#endif |
132 |
#endif /* ALLOW_USE_MPI */ |
133 |
|
134 |
DO I=1,nThreads |
135 |
adphi(1,I) = tmp |
136 |
ENDDO |
137 |
|
138 |
_END_MASTER( myThid ) |
139 |
C-- |
140 |
_BARRIER |
141 |
C |
142 |
C-- every thread takes its adjoint sum |
143 |
adsumPhi = adphi(1,myThid) |
144 |
|
145 |
RETURN |
146 |
END |