/[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.7 - (hide annotations) (download)
Sun Feb 4 14:38:43 2001 UTC (23 years, 4 months ago) by cnh
Branch: MAIN
CVS Tags: checkpoint38, c37_adj, checkpoint39, checkpoint37, checkpoint36, checkpoint35
Branch point for: pre38
Changes since 1.6: +2 -1 lines
Made sure each .F and .h file had
the CVS keywords Header and Name at its start.
Most had header but very few currently have Name, so
lots of changes!

1 cnh 1.7 C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/global_max.F,v 1.6 1999/05/18 17:35:23 adcroft 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    
36     C == Routine arguments ==
37     C maxPhi - Result of max.
38     C myThid - My thread id.
39     Real*4 maxPhi
40     INTEGER myThid
41     CEndOfInterface
42    
43     C == Local variables ==
44 adcroft 1.6 C phi - Array to be maxed.
45 cnh 1.1 C I - Loop counters
46     C mpiRC - MPI return code
47 adcroft 1.6 Real*4 phi(lShare4,MAX_NO_THREADS)
48 cnh 1.1 INTEGER I
49     Real*4 tmp
50     #ifdef ALLOW_USE_MPI
51     INTEGER mpiRC
52     #endif /* ALLOW_USE_MPI */
53    
54 adcroft 1.6 C-- write local max into array
55     phi(1,myThid) = maxPhi
56    
57 cnh 1.4 C-- Can not start until everyone is ready
58 cnh 1.1 _BARRIER
59    
60     C-- Max within the process first
61     _BEGIN_MASTER( myThid )
62     tmp = phi(1,1)
63     DO I=2,nThreads
64     tmp = MAX(tmp,phi(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 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     phi(1,1) = maxPhi
78     _END_MASTER( myThid )
79     C--
80     _BARRIER
81 adcroft 1.6
82     C-- set result for every process
83     maxPhi = phi(1,1)
84    
85 cnh 1.1 RETURN
86     END
87    
88    
89     CStartOfInterface
90     SUBROUTINE GLOBAL_MAX_R8(
91     O maxPhi,
92     I myThid )
93     C /==========================================================\
94     C | SUBROUTINE GLOBAL_MAX_R8 |
95     C | o Handle max for real*8 data. |
96     C |==========================================================|
97     C | Perform max on array of one value per thread and then |
98     C | max result of all the processes. |
99     C | Notes |
100     C | ===== |
101     C | Within a process only one thread does the max, each |
102     C | thread is assumed to have already maxed its local data. |
103     C | The same thread also does the inter-process max for |
104     C | example with MPI and then writes the result into a shared|
105     C | location. All threads wait until the max is avaiailable. |
106     C \==========================================================/
107 adcroft 1.6 IMPLICIT NONE
108 cnh 1.1
109     C === Global data ===
110     #include "SIZE.h"
111     #include "EEPARAMS.h"
112     #include "EESUPPORT.h"
113    
114     C === Routine arguments ===
115     C maxPhi - Result of max.
116     C myThid - My thread id.
117     Real*8 maxPhi
118     INTEGER myThid
119     CEndOfInterface
120    
121     C === Local variables ===
122 adcroft 1.6 C phi - Array to be maxed.
123 cnh 1.1 C I - Loop counters
124     C mpiRC - MPI return code
125 adcroft 1.6 Real*8 phi(lShare8,MAX_NO_THREADS)
126 cnh 1.1 INTEGER I
127     Real*8 tmp
128     #ifdef ALLOW_USE_MPI
129     INTEGER mpiRC
130     #endif /* ALLOW_USE_MPI */
131    
132 adcroft 1.6 C-- write local max into array
133     phi(1,myThid) = maxPhi
134    
135 cnh 1.4 C-- Can not start until everyone is ready
136 cnh 1.1 _BARRIER
137    
138     C-- Max within the process first
139     _BEGIN_MASTER( myThid )
140     tmp = phi(1,1)
141     DO I=2,nThreads
142     tmp = MAX(tmp,phi(1,I))
143     ENDDO
144     maxPhi = tmp
145     #ifdef ALLOW_USE_MPI
146     #ifndef ALWAYS_USE_MPI
147     IF ( usingMPI ) THEN
148     #endif
149     CALL MPI_Allreduce(tmp,maxPhi,1,MPI_DOUBLE_PRECISION,MPI_MAX,
150 adcroft 1.6 & MPI_COMM_WORLD,mpiRC)
151 cnh 1.1 #ifndef ALWAYS_USE_MPI
152     ENDIF
153     #endif
154     #endif /* ALLOW_USE_MPI */
155     C-- Write solution to place where all threads can see it
156     phi(1,1) = maxPhi
157     _END_MASTER( myThid )
158    
159 cnh 1.4 C-- Do not leave until we are sure that the max is done
160 cnh 1.1 _BARRIER
161 adcroft 1.6
162     C-- set result for every process
163     maxPhi = phi(1,1)
164    
165 cnh 1.1 RETURN
166     END

  ViewVC Help
Powered by ViewVC 1.1.22