1 |
C $Header: /u/gcmpack/MITgcm/eesupp/src/global_max.F,v 1.11 2004/03/27 03:51:51 edhill Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CPP_EEOPTIONS.h" |
5 |
|
6 |
C-- File global_max.F: Routines that perform global max reduction on an array |
7 |
C of thread values. |
8 |
C Contents |
9 |
C o GLOBAL_MAX_R4 |
10 |
C o GLOBAL_MAX_R8 |
11 |
|
12 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
13 |
CBOP |
14 |
C !ROUTINE: GLOBAL_MAX_R4 |
15 |
|
16 |
C !INTERFACE: |
17 |
SUBROUTINE GLOBAL_MAX_R4( |
18 |
U maxPhi, |
19 |
I myThid ) |
20 |
|
21 |
C !DESCRIPTION: |
22 |
C *==========================================================* |
23 |
C | SUBROUTINE GLOBAL\_MAX\_R4 |
24 |
C | o Handle max for real*4 data. |
25 |
C *==========================================================* |
26 |
C | Perform max on array of one value per thread and then |
27 |
C | max result of all the processes. |
28 |
C | Notes |
29 |
C | ===== |
30 |
C | Within a process only one thread does the max, each |
31 |
C | thread is assumed to have already maxed its local data. |
32 |
C | The same thread also does the inter-process max for |
33 |
C | example with MPI and then writes the result into a shared |
34 |
C | location. All threads wait until the max is avaiailable. |
35 |
C *==========================================================* |
36 |
|
37 |
C !USES: |
38 |
IMPLICIT NONE |
39 |
|
40 |
C == Global data == |
41 |
#include "SIZE.h" |
42 |
#include "EEPARAMS.h" |
43 |
#include "EESUPPORT.h" |
44 |
#include "GLOBAL_MAX.h" |
45 |
|
46 |
C !INPUT/OUTPUT PARAMETERS: |
47 |
C == Routine arguments == |
48 |
C maxPhi :: Result of max. |
49 |
C myThid :: My thread id. |
50 |
Real*4 maxPhi |
51 |
INTEGER myThid |
52 |
|
53 |
C !LOCAL VARIABLES: |
54 |
C == Local variables == |
55 |
C I :: Loop counters |
56 |
C mpiRC :: MPI return code |
57 |
INTEGER I |
58 |
Real*4 tmp |
59 |
#ifdef ALLOW_USE_MPI |
60 |
INTEGER mpiRC |
61 |
#endif /* ALLOW_USE_MPI */ |
62 |
CEOP |
63 |
|
64 |
C-- write local max into array |
65 |
phiGMR4(1,myThid) = maxPhi |
66 |
|
67 |
C-- Can not start until everyone is ready |
68 |
CALL BAR2( myThid ) |
69 |
|
70 |
C-- Max within the process first |
71 |
_BEGIN_MASTER( myThid ) |
72 |
tmp = phiGMR4(1,1) |
73 |
DO I=2,nThreads |
74 |
tmp = MAX(tmp,phiGMR4(1,I)) |
75 |
ENDDO |
76 |
maxPhi = tmp |
77 |
#ifdef ALLOW_USE_MPI |
78 |
#ifndef ALWAYS_USE_MPI |
79 |
IF ( usingMPI ) THEN |
80 |
#endif |
81 |
CALL MPI_Allreduce(tmp,maxPhi,1,MPI_REAL,MPI_MAX, |
82 |
& MPI_COMM_MODEL,mpiRC) |
83 |
#ifndef ALWAYS_USE_MPI |
84 |
ENDIF |
85 |
#endif |
86 |
#endif /* ALLOW_USE_MPI */ |
87 |
phiGMR4(1,0) = maxPhi |
88 |
_END_MASTER( myThid ) |
89 |
C-- |
90 |
CALL BAR2( myThid ) |
91 |
|
92 |
C-- set result for every process |
93 |
maxPhi = phiGMR4(1,0) |
94 |
|
95 |
RETURN |
96 |
END |
97 |
|
98 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
99 |
CBOP |
100 |
C !ROUTINE: GLOBAL_MAX_R8 |
101 |
|
102 |
C !INTERFACE: |
103 |
SUBROUTINE GLOBAL_MAX_R8( |
104 |
O maxPhi, |
105 |
I myThid ) |
106 |
|
107 |
C !DESCRIPTION: |
108 |
C *==========================================================* |
109 |
C | SUBROUTINE GLOBAL\_MAX\_R8 |
110 |
C | o Handle max for real*8 data. |
111 |
C *==========================================================* |
112 |
C | Perform max on array of one value per thread and then |
113 |
C | max result of all the processes. |
114 |
C | Notes |
115 |
C | ===== |
116 |
C | Within a process only one thread does the max, each |
117 |
C | thread is assumed to have already maxed its local data. |
118 |
C | The same thread also does the inter-process max for |
119 |
C | example with MPI and then writes the result into a shared |
120 |
C | location. All threads wait until the max is avaiailable. |
121 |
C *==========================================================* |
122 |
|
123 |
C !USES: |
124 |
IMPLICIT NONE |
125 |
|
126 |
C === Global data === |
127 |
#include "SIZE.h" |
128 |
#include "EEPARAMS.h" |
129 |
#include "EESUPPORT.h" |
130 |
#include "GLOBAL_MAX.h" |
131 |
|
132 |
C !INPUT/OUTPUT PARAMETERS: |
133 |
C === Routine arguments === |
134 |
C maxPhi :: Result of max. |
135 |
C myThid :: My thread id. |
136 |
Real*8 maxPhi |
137 |
INTEGER myThid |
138 |
|
139 |
C !LOCAL VARIABLES: |
140 |
C === Local variables === |
141 |
C I :: Loop counters |
142 |
C mpiRC :: MPI return code |
143 |
INTEGER I |
144 |
Real*8 tmp |
145 |
#ifdef ALLOW_USE_MPI |
146 |
INTEGER mpiRC |
147 |
#endif /* ALLOW_USE_MPI */ |
148 |
CEOP |
149 |
|
150 |
C-- write local max into array |
151 |
phiGMR8(1,myThid) = maxPhi |
152 |
|
153 |
C-- Can not start until everyone is ready |
154 |
CALL BAR2( myThid ) |
155 |
|
156 |
C-- Max within the process first |
157 |
_BEGIN_MASTER( myThid ) |
158 |
tmp = phiGMR8(1,1) |
159 |
DO I=2,nThreads |
160 |
tmp = MAX(tmp,phiGMR8(1,I)) |
161 |
ENDDO |
162 |
maxPhi = tmp |
163 |
#ifdef ALLOW_USE_MPI |
164 |
#ifndef ALWAYS_USE_MPI |
165 |
IF ( usingMPI ) THEN |
166 |
#endif |
167 |
CALL MPI_Allreduce(tmp,maxPhi,1,MPI_DOUBLE_PRECISION,MPI_MAX, |
168 |
& MPI_COMM_MODEL,mpiRC) |
169 |
#ifndef ALWAYS_USE_MPI |
170 |
ENDIF |
171 |
#endif |
172 |
#endif /* ALLOW_USE_MPI */ |
173 |
C-- Write solution to place where all threads can see it |
174 |
phiGMR8(1,0) = maxPhi |
175 |
_END_MASTER( myThid ) |
176 |
|
177 |
C-- Do not leave until we are sure that the max is done |
178 |
CALL BAR2( myThid ) |
179 |
|
180 |
C-- set result for every process |
181 |
maxPhi = phiGMR8(1,0) |
182 |
|
183 |
RETURN |
184 |
END |