1 |
jmc |
1.4 |
C $Header: /u/gcmpack/MITgcm/eesupp/src/global_sum_singlecpu.F,v 1.3 2009/05/16 13:41:19 jmc Exp $ |
2 |
jmc |
1.2 |
C $Name: $ |
3 |
jahn |
1.1 |
|
4 |
jmc |
1.4 |
#include "PACKAGES_CONFIG.h" |
5 |
|
|
#include "CPP_EEOPTIONS.h" |
6 |
|
|
|
7 |
jahn |
1.1 |
C-- File global_sum_singlecpu.F: Routines that perform global sum |
8 |
jmc |
1.3 |
C on a single CPU |
9 |
|
|
C Contents |
10 |
jmc |
1.4 |
C o GLOBAL_SUM_SINGLECPU_RL |
11 |
|
|
C o GLOBAL_SUM_SINGLECPU_RS <- not yet coded |
12 |
jahn |
1.1 |
|
13 |
jmc |
1.4 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
14 |
jahn |
1.1 |
CBOP |
15 |
|
|
C !ROUTINE: GLOBAL_SUM_SINGLECPU_RL |
16 |
|
|
|
17 |
|
|
C !INTERFACE: |
18 |
|
|
SUBROUTINE GLOBAL_SUM_SINGLECPU_RL( |
19 |
|
|
I phiLocal, |
20 |
|
|
O sumPhi, |
21 |
jmc |
1.3 |
I oLi, oLj, myThid ) |
22 |
jahn |
1.1 |
IMPLICIT NONE |
23 |
|
|
C !DESCRIPTION: |
24 |
|
|
C *==========================================================* |
25 |
|
|
C | SUBROUTINE GLOBAL\_SUM\_SINGLECPU\_RL |
26 |
|
|
C | o Handle sum for _RL data. |
27 |
|
|
C *==========================================================* |
28 |
|
|
C | Global sum of 2d array |
29 |
|
|
C | independent of tiling as sum is performed on a single CPU |
30 |
|
|
C | sum is performed in REAL*8 |
31 |
|
|
C *==========================================================* |
32 |
|
|
|
33 |
|
|
C !USES: |
34 |
|
|
C == Global data == |
35 |
|
|
#include "SIZE.h" |
36 |
|
|
#include "EEPARAMS.h" |
37 |
|
|
#include "EESUPPORT.h" |
38 |
|
|
#include "GLOBAL_SUM.h" |
39 |
jmc |
1.3 |
#ifdef ALLOW_EXCH2 |
40 |
|
|
#include "W2_EXCH2_SIZE.h" |
41 |
|
|
#include "W2_EXCH2_TOPOLOGY.h" |
42 |
|
|
#endif |
43 |
|
|
#include "EEBUFF_SCPU.h" |
44 |
jahn |
1.1 |
|
45 |
|
|
C !INPUT/OUTPUT PARAMETERS: |
46 |
|
|
C == Routine arguments == |
47 |
|
|
C phiLocal :: local input array without overlap regions. |
48 |
|
|
C sumPhi :: Result of sum. |
49 |
jmc |
1.3 |
C oLi, oLj :: overlap size of input array in I & J direction. |
50 |
jahn |
1.1 |
C myThid :: My thread id. |
51 |
jmc |
1.3 |
INTEGER oLi, oLj |
52 |
|
|
_RL phiLocal(1-oLi:sNx+oLi,1-oLj:sNy+oLj,nSx,nSy) |
53 |
jahn |
1.1 |
_RL sumPhi |
54 |
|
|
INTEGER myThid |
55 |
|
|
|
56 |
|
|
C !LOCAL VARIABLES: |
57 |
|
|
C == Local variables == |
58 |
|
|
C- type declaration of: sumAll, globalBuf : |
59 |
|
|
C sumAll needs to have the same length as MPI_DOUBLE_PRECISION |
60 |
jmc |
1.3 |
LOGICAL useExch2GlobLayOut, zeroBuff |
61 |
|
|
INTEGER xSize, ySize |
62 |
|
|
INTEGER i, j, ij |
63 |
|
|
INTEGER bi, bj |
64 |
jahn |
1.1 |
Real*8 sumAll |
65 |
|
|
#ifdef ALLOW_USE_MPI |
66 |
|
|
INTEGER npe |
67 |
|
|
INTEGER lbuff, idest, itag |
68 |
|
|
INTEGER istatus(MPI_STATUS_SIZE), ierr |
69 |
|
|
#endif /* ALLOW_USE_MPI */ |
70 |
|
|
CEOP |
71 |
|
|
|
72 |
jmc |
1.3 |
#ifdef ALLOW_EXCH2 |
73 |
|
|
zeroBuff = .TRUE. |
74 |
|
|
useExch2GlobLayOut = .TRUE. |
75 |
|
|
xSize = exch2_global_Nx |
76 |
|
|
ySize = exch2_global_Ny |
77 |
|
|
#else /* ALLOW_EXCH2 */ |
78 |
|
|
zeroBuff = .FALSE. |
79 |
|
|
useExch2GlobLayOut = .FALSE. |
80 |
|
|
xSize = Nx |
81 |
|
|
ySize = Ny |
82 |
|
|
#endif /* ALLOW_EXCH2 */ |
83 |
|
|
|
84 |
|
|
C-- copy (and conversion to real*8) to Shared buffer: |
85 |
|
|
DO bj = myByLo(myThid), myByHi(myThid) |
86 |
|
|
DO bi = myBxLo(myThid), myBxHi(myThid) |
87 |
|
|
DO j=1,sNy |
88 |
|
|
DO i=1,sNx |
89 |
|
|
sharedLocBuf_r8(i,j,bi,bj) = phiLocal(i,j,bi,bj) |
90 |
|
|
ENDDO |
91 |
|
|
ENDDO |
92 |
|
|
ENDDO |
93 |
|
|
ENDDO |
94 |
|
|
|
95 |
jmc |
1.4 |
C-- Master thread does the communications and the global sum |
96 |
|
|
C-- Master thread cannot start until everyone is ready: |
97 |
jahn |
1.1 |
CALL BAR2( myThid ) |
98 |
jmc |
1.4 |
_BEGIN_MASTER( myThid ) |
99 |
jahn |
1.1 |
|
100 |
|
|
C-- Gather local arrays |
101 |
jmc |
1.3 |
CALL GATHER_2D_R8( |
102 |
|
|
O xy_buffer_r8, |
103 |
|
|
I sharedLocBuf_r8, |
104 |
|
|
I xSize, ySize, |
105 |
|
|
I useExch2GlobLayOut, zeroBuff, myThid ) |
106 |
jahn |
1.1 |
|
107 |
|
|
#ifdef ALLOW_USE_MPI |
108 |
|
|
idest = 0 |
109 |
|
|
itag = 0 |
110 |
|
|
|
111 |
|
|
IF ( mpiMyId.EQ.0 ) THEN |
112 |
|
|
#endif |
113 |
|
|
|
114 |
|
|
C-- Process 0 sums the global array |
115 |
jmc |
1.2 |
sumAll = 0. _d 0 |
116 |
jmc |
1.3 |
DO ij=1,xSize*ySize |
117 |
|
|
sumAll = sumAll + xy_buffer_r8(ij) |
118 |
jmc |
1.2 |
ENDDO |
119 |
jahn |
1.1 |
|
120 |
|
|
#ifdef ALLOW_USE_MPI |
121 |
|
|
C-- Process 0 sends result to all other processes |
122 |
|
|
lbuff = 1 |
123 |
|
|
DO npe = 1, numberOfProcs-1 |
124 |
|
|
CALL MPI_SEND (sumAll, 1, MPI_DOUBLE_PRECISION, |
125 |
|
|
& npe, itag, MPI_COMM_MODEL, ierr) |
126 |
|
|
ENDDO |
127 |
|
|
|
128 |
|
|
ELSE |
129 |
jmc |
1.3 |
|
130 |
jahn |
1.1 |
C-- All proceses except 0 receive result from process 0 |
131 |
|
|
CALL MPI_RECV (sumAll, 1, MPI_DOUBLE_PRECISION, |
132 |
|
|
& idest, itag, MPI_COMM_MODEL, istatus, ierr) |
133 |
|
|
|
134 |
|
|
ENDIF |
135 |
|
|
#endif /* not ALLOW_USE_MPI */ |
136 |
|
|
|
137 |
|
|
C-- Write solution to shared buffer (all threads can see it) |
138 |
jmc |
1.4 |
phiGSR8(1,0) = sumAll |
139 |
jahn |
1.1 |
|
140 |
|
|
_END_MASTER( myThid ) |
141 |
|
|
C-- Everyone wait for Master thread to be ready |
142 |
|
|
CALL BAR2( myThid ) |
143 |
|
|
|
144 |
|
|
C-- set result for every threads |
145 |
jmc |
1.4 |
sumPhi = phiGSR8(1,0) |
146 |
jahn |
1.1 |
|
147 |
|
|
RETURN |
148 |
|
|
END |