/[MITgcm]/MITgcm/pkg/autodiff/global_max_ad.F
ViewVC logotype

Diff of /MITgcm/pkg/autodiff/global_max_ad.F

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

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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.22