/[MITgcm]/MITgcm/eesupp/src/global_max.F
ViewVC logotype

Annotation of /MITgcm/eesupp/src/global_max.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (hide annotations) (download)
Tue May 29 14:01:36 2001 UTC (23 years ago) by adcroft
Branch: MAIN
CVS Tags: checkpoint40pre3, checkpoint40pre1, checkpoint40pre7, checkpoint40pre6, checkpoint40pre9, checkpoint40pre8, checkpoint40pre2, checkpoint40pre4, checkpoint40pre5, checkpoint40
Changes since 1.7: +22 -20 lines
Merge from branch pre38:
 o essential mods for cubed sphere
 o debugged atmosphere, dynamcis + physics (aim)
 o new packages (mom_vecinv, mom_fluxform, ...)

1 adcroft 1.8 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 cnh 1.1
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 adcroft 1.6 U maxPhi,
14 cnh 1.1 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 adcroft 1.6 IMPLICIT NONE
30 cnh 1.1
31     C == Global data ==
32     #include "SIZE.h"
33     #include "EEPARAMS.h"
34     #include "EESUPPORT.h"
35 adcroft 1.8 #include "GLOBAL_MAX.h"
36 cnh 1.1
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 adcroft 1.8 CALL BAR2( myThid )
54 adcroft 1.6 C-- write local max into array
55 adcroft 1.8 phiGMRS(1,myThid) = maxPhi
56 adcroft 1.6
57 cnh 1.4 C-- Can not start until everyone is ready
58 adcroft 1.8 CALL BAR2( myThid )
59 cnh 1.1
60     C-- Max within the process first
61     _BEGIN_MASTER( myThid )
62 adcroft 1.8 tmp = phiGMRS(1,1)
63 cnh 1.1 DO I=2,nThreads
64 adcroft 1.8 tmp = MAX(tmp,phiGMRS(1,I))
65 cnh 1.1 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 adcroft 1.6 & MPI_COMM_WORLD,mpiRC)
73 cnh 1.1 #ifndef ALWAYS_USE_MPI
74     ENDIF
75     #endif
76     #endif /* ALLOW_USE_MPI */
77 adcroft 1.8 phiGMRS(1,1) = maxPhi
78 cnh 1.1 _END_MASTER( myThid )
79     C--
80 adcroft 1.8 CALL BAR2( myThid )
81 adcroft 1.6
82     C-- set result for every process
83 adcroft 1.8 maxPhi = phiGMRS(1,1)
84     CALL BAR2( myThid )
85 adcroft 1.6
86 cnh 1.1 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 adcroft 1.6 IMPLICIT NONE
109 cnh 1.1
110     C === Global data ===
111     #include "SIZE.h"
112     #include "EEPARAMS.h"
113     #include "EESUPPORT.h"
114 adcroft 1.8 #include "GLOBAL_MAX.h"
115 cnh 1.1
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 adcroft 1.8 CALL BAR2( myThid )
133 adcroft 1.6 C-- write local max into array
134 adcroft 1.8 phiGMRL(1,myThid) = maxPhi
135 adcroft 1.6
136 cnh 1.4 C-- Can not start until everyone is ready
137 adcroft 1.8 CALL BAR2( myThid )
138 cnh 1.1
139     C-- Max within the process first
140     _BEGIN_MASTER( myThid )
141 adcroft 1.8 tmp = phiGMRL(1,1)
142 cnh 1.1 DO I=2,nThreads
143 adcroft 1.8 tmp = MAX(tmp,phiGMRL(1,I))
144 cnh 1.1 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 adcroft 1.6 & MPI_COMM_WORLD,mpiRC)
152 cnh 1.1 #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 adcroft 1.8 phiGMRL(1,1) = maxPhi
158 cnh 1.1 _END_MASTER( myThid )
159    
160 cnh 1.4 C-- Do not leave until we are sure that the max is done
161 adcroft 1.8 CALL BAR2( myThid )
162 adcroft 1.6
163     C-- set result for every process
164 adcroft 1.8 maxPhi = phiGMRL(1,1)
165     CALL BAR2( myThid )
166 adcroft 1.6
167 cnh 1.1 RETURN
168     END

  ViewVC Help
Powered by ViewVC 1.1.22