/[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.7 by heimbach, Tue Jan 30 20:49:49 2001 UTC
# Line 165  C--   set result for every process Line 165  C--   set result for every process
165    
166        RETURN        RETURN
167        END        END
168    CStartOfInterface
169          SUBROUTINE GLOBAL_SUM_INT(
170         U                       sumPhi,
171         I                       myThid )
172    C     /==========================================================\
173    C     | SUBROUTINE GLOBAL_SUM_INT                                |
174    C     | o Handle sum for integer data.                           |
175    C     |==========================================================|
176    C     | Perform sum an array of one value per thread and then    |
177    C     | sum result of all the processes.                         |
178    C     | Notes                                                    |
179    C     | =====                                                    |
180    C     | Within a process only one thread does the sum, each      |
181    C     | thread is assumed to have already summed its local data. |
182    C     | The same thread also does the inter-process sum for      |
183    C     | example with MPI and then writes the result into a shared|
184    C     | location. All threads wait until the sum is avaiailable. |
185    C     \==========================================================/
186          IMPLICIT NONE
187    
188    C     === Global data ===
189    #include "SIZE.h"
190    #include "EEPARAMS.h"
191    #include "EESUPPORT.h"
192    
193    C     === Routine arguments ===
194    C     sumPhi - Result of sum.
195    C     myThid - My thread id.
196          INTEGER sumPhi
197          INTEGER myThid
198    CEndOfInterface
199    
200    C     === Local variables ===
201    C     phi    - Array to be summed.
202    C     I      - Loop counters
203    C     mpiRC  - MPI return code
204          INTEGER phi(lShare8,MAX_NO_THREADS)
205          INTEGER I
206          INTEGER  tmp
207    #ifdef   ALLOW_USE_MPI
208          INTEGER mpiRC
209    #endif   /* ALLOW_USE_MPI */
210    
211    C--   write local sum into array
212          phi(1,myThid) = sumPhi
213    
214    C--   Can not start until everyone is ready
215          _BARRIER
216    
217    C--   Sum within the process first
218          _BEGIN_MASTER( myThid )
219           tmp = 0. _d 0
220           DO I=1,nThreads
221            tmp = tmp + phi(1,I)
222           ENDDO
223           sumPhi = tmp
224    #ifdef  ALLOW_USE_MPI
225    #ifndef ALWAYS_USE_MPI
226           IF ( usingMPI ) THEN
227    #endif
228            CALL MPI_Allreduce(tmp,sumPhi,1,MPI_INTEGER,MPI_SUM,
229         &                   MPI_COMM_WORLD,mpiRC)
230    #ifndef ALWAYS_USE_MPI
231           ENDIF
232    #endif
233    #endif /*  ALLOW_USE_MPI */
234    C--     Write solution to place where all threads can see it
235            phi(1,1) = sumPhi
236          _END_MASTER( myThid )
237    
238    C--   Do not leave until we are sure that the sum is done
239          _BARRIER
240    
241    C--   set result for every process
242          sumPhi = phi(1,1)
243    
244          RETURN
245          END

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

  ViewVC Help
Powered by ViewVC 1.1.22