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

Diff of /MITgcm/eesupp/src/global_sum.F

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

revision 1.6 by adcroft, Tue May 18 17:35:23 1999 UTC revision 1.8 by cnh, Sun Feb 4 14:38:43 2001 UTC
# Line 1  Line 1 
1  C $Header$  C $Header$
2    C $Name$
3    
4  C--   File global_sum.F: Routines that perform global sum on an array  C--   File global_sum.F: Routines that perform global sum on an array
5  C                        of thread values.  C                        of thread values.
# Line 151  C--   Sum within the process first Line 152  C--   Sum within the process first
152       &                   MPI_COMM_WORLD,mpiRC)       &                   MPI_COMM_WORLD,mpiRC)
153  #ifndef ALWAYS_USE_MPI  #ifndef ALWAYS_USE_MPI
154         ENDIF         ENDIF
155    #endif
156    #endif /*  ALLOW_USE_MPI */
157    C--     Write solution to place where all threads can see it
158            phi(1,1) = sumPhi
159          _END_MASTER( myThid )
160    
161    C--   Do not leave until we are sure that the sum is done
162          _BARRIER
163    
164    C--   set result for every process
165          sumPhi = phi(1,1)
166    
167          RETURN
168          END
169    CStartOfInterface
170          SUBROUTINE GLOBAL_SUM_INT(
171         U                       sumPhi,
172         I                       myThid )
173    C     /==========================================================\
174    C     | SUBROUTINE GLOBAL_SUM_INT                                |
175    C     | o Handle sum for integer data.                           |
176    C     |==========================================================|
177    C     | Perform sum an array of one value per thread and then    |
178    C     | sum result of all the processes.                         |
179    C     | Notes                                                    |
180    C     | =====                                                    |
181    C     | Within a process only one thread does the sum, each      |
182    C     | thread is assumed to have already summed its local data. |
183    C     | The same thread also does the inter-process sum for      |
184    C     | example with MPI and then writes the result into a shared|
185    C     | location. All threads wait until the sum is avaiailable. |
186    C     \==========================================================/
187          IMPLICIT NONE
188    
189    C     === Global data ===
190    #include "SIZE.h"
191    #include "EEPARAMS.h"
192    #include "EESUPPORT.h"
193    
194    C     === Routine arguments ===
195    C     sumPhi - Result of sum.
196    C     myThid - My thread id.
197          INTEGER sumPhi
198          INTEGER myThid
199    CEndOfInterface
200    
201    C     === Local variables ===
202    C     phi    - Array to be summed.
203    C     I      - Loop counters
204    C     mpiRC  - MPI return code
205          INTEGER phi(lShare8,MAX_NO_THREADS)
206          INTEGER I
207          INTEGER  tmp
208    #ifdef   ALLOW_USE_MPI
209          INTEGER mpiRC
210    #endif   /* ALLOW_USE_MPI */
211    
212    C--   write local sum into array
213          phi(1,myThid) = sumPhi
214    
215    C--   Can not start until everyone is ready
216          _BARRIER
217    
218    C--   Sum within the process first
219          _BEGIN_MASTER( myThid )
220           tmp = 0. _d 0
221           DO I=1,nThreads
222            tmp = tmp + phi(1,I)
223           ENDDO
224           sumPhi = tmp
225    #ifdef  ALLOW_USE_MPI
226    #ifndef ALWAYS_USE_MPI
227           IF ( usingMPI ) THEN
228    #endif
229            CALL MPI_Allreduce(tmp,sumPhi,1,MPI_INTEGER,MPI_SUM,
230         &                   MPI_COMM_WORLD,mpiRC)
231    #ifndef ALWAYS_USE_MPI
232           ENDIF
233  #endif  #endif
234  #endif /*  ALLOW_USE_MPI */  #endif /*  ALLOW_USE_MPI */
235  C--     Write solution to place where all threads can see it  C--     Write solution to place where all threads can see it

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.22