/[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.2 by cnh, Thu Apr 23 20:37:30 1998 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 9  C      o global_sum_r8 Line 10  C      o global_sum_r8
10    
11  CStartOfInterface  CStartOfInterface
12        SUBROUTINE GLOBAL_SUM_R4(        SUBROUTINE GLOBAL_SUM_R4(
13       I                       phi,       U                       sumPhi,
      O                       sumPhi,  
14       I                       myThid )       I                       myThid )
15  C     /==========================================================\  C     /==========================================================\
16  C     | SUBROUTINE GLOBAL_SUM_R4                                 |  C     | SUBROUTINE GLOBAL_SUM_R4                                 |
# Line 26  C     | The same thread also does the in Line 26  C     | The same thread also does the in
26  C     | example with MPI and then writes the result into a shared|  C     | example with MPI and then writes the result into a shared|
27  C     | location. All threads wait until the sum is avaiailable. |  C     | location. All threads wait until the sum is avaiailable. |
28  C     \==========================================================/  C     \==========================================================/
29          IMPLICIT NONE
30    
31  C     == Global data ==  C     == Global data ==
32  #include "SIZE.h"  #include "SIZE.h"
# Line 33  C     == Global data == Line 34  C     == Global data ==
34  #include "EESUPPORT.h"  #include "EESUPPORT.h"
35    
36  C     == Routine arguments ==  C     == Routine arguments ==
 C     phi    - Array to be summed.  
37  C     sumPhi - Result of sum.  C     sumPhi - Result of sum.
38  C     myThid - My thread id.  C     myThid - My thread id.
       Real*4 phi(lShare4,MAX_NO_THREADS)  
39        Real*4 sumPhi        Real*4 sumPhi
40        INTEGER myThid        INTEGER myThid
41  CEndOfInterface  CEndOfInterface
42    
43  C     == Local variables ==  C     == Local variables ==
44    C     phi    - Array to be summed.
45  C     I      - Loop counters  C     I      - Loop counters
46  C     mpiRC  - MPI return code  C     mpiRC  - MPI return code
47          Real*4 phi(lShare4,MAX_NO_THREADS)
48        INTEGER I        INTEGER I
49        Real*4  tmp        Real*4  tmp
50  #ifdef   ALLOW_USE_MPI  #ifdef   ALLOW_USE_MPI
51        INTEGER mpiRC        INTEGER mpiRC
52  #endif /* ALLOW_USE_MPI */  #endif /* ALLOW_USE_MPI */
53    
54  C--   Can't start until everyone is ready  C--   write local sum into array
55          phi(1,myThid) = sumPhi
56    
57    C--   Can not start until everyone is ready
58        _BARRIER        _BARRIER
59    
60  C--   Sum within the process first  C--   Sum within the process first
# Line 70  C--   Sum within the process first Line 74  C--   Sum within the process first
74         ENDIF         ENDIF
75  #endif  #endif
76  #endif /*  ALLOW_USE_MPI */  #endif /*  ALLOW_USE_MPI */
77    C--     Write solution to place where all threads can see it
78         phi(1,1) = sumPhi         phi(1,1) = sumPhi
79    
80        _END_MASTER( myThid )        _END_MASTER( myThid )
81  C--  C--
82        _BARRIER        _BARRIER
83  C  
84    C--   set result for every process
85          sumPhi = phi(1,1)
86    
87        RETURN        RETURN
88        END        END
89                
90    
91  CStartOfInterface  CStartOfInterface
92        SUBROUTINE GLOBAL_SUM_R8(        SUBROUTINE GLOBAL_SUM_R8(
93       I                       phi,       U                       sumPhi,
      O                       sumPhi,  
94       I                       myThid )       I                       myThid )
95  C     /==========================================================\  C     /==========================================================\
96  C     | SUBROUTINE GLOBAL_SUM_R8                                 |  C     | SUBROUTINE GLOBAL_SUM_R8                                 |
# Line 98  C     | The same thread also does the in Line 106  C     | The same thread also does the in
106  C     | example with MPI and then writes the result into a shared|  C     | example with MPI and then writes the result into a shared|
107  C     | location. All threads wait until the sum is avaiailable. |  C     | location. All threads wait until the sum is avaiailable. |
108  C     \==========================================================/  C     \==========================================================/
109          IMPLICIT NONE
110    
111  C     === Global data ===  C     === Global data ===
112  #include "SIZE.h"  #include "SIZE.h"
# Line 105  C     === Global data === Line 114  C     === Global data ===
114  #include "EESUPPORT.h"  #include "EESUPPORT.h"
115    
116  C     === Routine arguments ===  C     === Routine arguments ===
 C     phi    - Array to be summed.  
117  C     sumPhi - Result of sum.  C     sumPhi - Result of sum.
118  C     myThid - My thread id.  C     myThid - My thread id.
       Real*8 phi(lShare8,MAX_NO_THREADS)  
119        Real*8 sumPhi        Real*8 sumPhi
120        INTEGER myThid        INTEGER myThid
121  CEndOfInterface  CEndOfInterface
122    
123  C     === Local variables ===  C     === Local variables ===
124    C     phi    - Array to be summed.
125  C     I      - Loop counters  C     I      - Loop counters
126  C     mpiRC  - MPI return code  C     mpiRC  - MPI return code
127          Real*8 phi(lShare8,MAX_NO_THREADS)
128        INTEGER I        INTEGER I
129        Real*8  tmp        Real*8  tmp
130  #ifdef   ALLOW_USE_MPI  #ifdef   ALLOW_USE_MPI
131        INTEGER mpiRC        INTEGER mpiRC
132  #endif   /* ALLOW_USE_MPI */  #endif   /* ALLOW_USE_MPI */
133    
134  C--   Can't start until everyone is ready  C--   write local sum into array
135          phi(1,myThid) = sumPhi
136    
137    C--   Can not start until everyone is ready
138        _BARRIER        _BARRIER
139    
140  C--   Sum within the process first  C--   Sum within the process first
# Line 146  C--     Write solution to place where al Line 158  C--     Write solution to place where al
158          phi(1,1) = sumPhi          phi(1,1) = sumPhi
159        _END_MASTER( myThid )        _END_MASTER( myThid )
160    
161  C--   Don't leave until we are sure that the sum is done  C--   Do not leave until we are sure that the sum is done
162        _BARRIER        _BARRIER
163  C  
164    C--   set result for every process
165          sumPhi = phi(1,1)
166    
167        RETURN        RETURN
168        END        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 $Id$  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
234    #endif /*  ALLOW_USE_MPI */
235    C--     Write solution to place where all threads can see it
236            phi(1,1) = sumPhi
237          _END_MASTER( myThid )
238    
239    C--   Do not leave until we are sure that the sum is done
240          _BARRIER
241    
242    C--   set result for every process
243          sumPhi = phi(1,1)
244    
245          RETURN
246          END

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

  ViewVC Help
Powered by ViewVC 1.1.22