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