/[MITgcm]/MITgcm/eesupp/src/gather_2d_rx.template
ViewVC logotype

Contents of /MITgcm/eesupp/src/gather_2d_rx.template

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


Revision 1.7 - (show annotations) (download)
Mon Sep 3 19:36:29 2012 UTC (11 years, 9 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint64y, checkpoint64x, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, checkpoint63s, checkpoint64, checkpoint65, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65o, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, HEAD
Changes since 1.6: +15 -13 lines
add "if usingMPI" test where needed (+ start to remove ALWAYS_USE_MPI)

1 C $Header: /u/gcmpack/MITgcm/eesupp/src/gather_2d_rx.template,v 1.6 2009/06/28 01:02:17 jmc Exp $
2 C $Name: $
3
4 #include "PACKAGES_CONFIG.h"
5 #include "CPP_EEOPTIONS.h"
6
7 CBOP
8 C !ROUTINE: GATHER_2D_RX
9 C !INTERFACE:
10 SUBROUTINE GATHER_2D_RX(
11 O gloBuff,
12 I myField,
13 I xSize, ySize,
14 I useExch2GlobLayOut,
15 I zeroBuff,
16 I myThid )
17 C !DESCRIPTION:
18 C Gather elements of a global 2-D array from all mpi processes to process 0.
19 C Note: done by Master-Thread ; might need barrier calls before and after
20 C this S/R call.
21
22 C !USES:
23 IMPLICIT NONE
24 #include "SIZE.h"
25 #include "EEPARAMS.h"
26 #include "EESUPPORT.h"
27 #ifdef ALLOW_EXCH2
28 #include "W2_EXCH2_SIZE.h"
29 #include "W2_EXCH2_TOPOLOGY.h"
30 #endif /* ALLOW_EXCH2 */
31
32 C !INPUT/OUTPUT PARAMETERS:
33 C gloBuff ( _RX ) :: full-domain 2D IO-buffer array (Output)
34 C myField ( _RX ) :: tiled, local (i.e. my Proc. tiles) 2D array (Input)
35 C xSize (integer):: global buffer 1rst dim (x)
36 C ySize (integer):: global buffer 2nd dim (y)
37 C useExch2GlobLayOut:: =T: Use Exch2 global-map layout (only with EXCH2)
38 C zeroBuff (logical):: =T: initialise the buffer to zero before copy
39 C myThid (integer):: my Thread Id number
40
41 INTEGER xSize, ySize
42 _RX gloBuff(xSize,ySize)
43 _RX myField(1:sNx,1:sNy,nSx,nSy)
44 LOGICAL useExch2GlobLayOut
45 LOGICAL zeroBuff
46 INTEGER myThid
47 CEOP
48
49 C !LOCAL VARIABLES:
50 INTEGER i,j, bi,bj
51 INTEGER iG, jG
52 INTEGER iBase, jBase
53 #ifdef ALLOW_EXCH2
54 INTEGER iGjLoc, jGjLoc
55 INTEGER tN
56 #endif /* ALLOW_EXCH2 */
57 #ifdef ALLOW_USE_MPI
58 INTEGER np, pId
59 _RX temp(1:sNx,1:sNy,nSx,nSy)
60 INTEGER istatus(MPI_STATUS_SIZE), ierr
61 INTEGER lbuff, idest, itag, ready_to_receive
62 #endif /* ALLOW_USE_MPI */
63
64 _BEGIN_MASTER( myThid )
65
66 IF( myProcId .EQ. 0 ) THEN
67 C-- Process 0 fills-in its local data
68
69 #ifdef ALLOW_EXCH2
70 IF ( useExch2GlobLayOut ) THEN
71 C-- If using blank-tiles, buffer will not be completely filled;
72 C safer to reset to zero to avoid unknown values in output file
73 IF ( zeroBuff ) THEN
74 DO j=1,ySize
75 DO i=1,xSize
76 gloBuff(i,j) = 0.
77 ENDDO
78 ENDDO
79 ENDIF
80
81 DO bj=1,nSy
82 DO bi=1,nSx
83 tN = W2_myTileList(bi,bj)
84 IF ( exch2_mydNx(tN) .GT. xSize ) THEN
85 C- face x-size larger than glob-size : fold it
86 iGjLoc = 0
87 jGjLoc = exch2_mydNx(tN) / xSize
88 ELSEIF ( exch2_tNy(tN) .GT. ySize ) THEN
89 C- tile y-size larger than glob-size : make a long line
90 iGjLoc = exch2_mydNx(tN)
91 jGjLoc = 0
92 ELSE
93 C- default (face fit into global-IO-array)
94 iGjLoc = 0
95 jGjLoc = 1
96 ENDIF
97
98 DO j=1,sNy
99 #ifdef TARGET_NEC_SX
100 !cdir novector
101 #endif
102 iG=exch2_txGlobalo(tN)+iGjLoc*(j-1)-1
103 jG=exch2_tyGlobalo(tN)+jGjLoc*(j-1)
104 DO i=1,sNx
105 gloBuff(iG+i,jG) = myField(i,j,bi,bj)
106 ENDDO
107 ENDDO
108
109 ENDDO
110 ENDDO
111
112 ELSE
113 #else /* ALLOW_EXCH2 */
114 IF (.TRUE.) THEN
115 #endif /* ALLOW_EXCH2 */
116
117 iBase = myXGlobalLo-1
118 jBase = myYGlobalLo-1
119
120 DO bj=1,nSy
121 DO bi=1,nSx
122 DO j=1,sNy
123 #ifdef TARGET_NEC_SX
124 !cdir novector
125 #endif
126 iG = iBase+(bi-1)*sNx
127 jG = jBase+(bj-1)*sNy+j
128 DO i=1,sNx
129 gloBuff(iG+i,jG) = myField(i,j,bi,bj)
130 ENDDO
131 ENDDO
132 ENDDO
133 ENDDO
134
135 C end if-else useExch2GlobLayOut
136 ENDIF
137
138 C- end if myProcId = 0
139 ENDIF
140
141 #ifdef ALLOW_USE_MPI
142 IF ( usingMPI ) THEN
143
144 lbuff = sNx*nSx*sNy*nSy
145 idest = 0
146 itag = 0
147 ready_to_receive = 0
148
149 IF( mpiMyId .EQ. 0 ) THEN
150
151 C-- Process 0 polls and receives data from each process in turn
152 DO np = 2, nPx*nPy
153 pId = np - 1
154 #ifndef DISABLE_MPI_READY_TO_RECEIVE
155 CALL MPI_SEND (ready_to_receive, 1, MPI_INTEGER,
156 & pId, itag, MPI_COMM_MODEL, ierr)
157 #endif
158 CALL MPI_RECV (temp, lbuff, _MPI_TYPE_RX,
159 & pId, itag, MPI_COMM_MODEL, istatus, ierr)
160
161 C-- Process 0 gathers the local arrays into the global buffer.
162 #ifdef ALLOW_EXCH2
163 IF ( useExch2GlobLayOut ) THEN
164
165 DO bj=1,nSy
166 DO bi=1,nSx
167 tN = W2_procTileList(bi,bj,np)
168 IF ( exch2_mydNx(tN) .GT. xSize ) THEN
169 C- face x-size larger than glob-size : fold it
170 iGjLoc = 0
171 jGjLoc = exch2_mydNx(tN) / xSize
172 ELSEIF ( exch2_tNy(tN) .GT. ySize ) THEN
173 C- tile y-size larger than glob-size : make a long line
174 iGjLoc = exch2_mydNx(tN)
175 jGjLoc = 0
176 ELSE
177 C- default (face fit into global-IO-array)
178 iGjLoc = 0
179 jGjLoc = 1
180 ENDIF
181
182 DO j=1,sNy
183 #ifdef TARGET_NEC_SX
184 !cdir novector
185 #endif
186 iG=exch2_txGlobalo(tN)+iGjLoc*(j-1)-1
187 jG=exch2_tyGlobalo(tN)+jGjLoc*(j-1)
188 DO i=1,sNx
189 gloBuff(iG+i,jG) = temp(i,j,bi,bj)
190 ENDDO
191 ENDDO
192
193 ENDDO
194 ENDDO
195
196 ELSE
197 #else /* ALLOW_EXCH2 */
198 IF (.TRUE.) THEN
199 #endif /* ALLOW_EXCH2 */
200
201 iBase = mpi_myXGlobalLo(np)-1
202 jBase = mpi_myYGlobalLo(np)-1
203
204 DO bj=1,nSy
205 DO bi=1,nSx
206 DO j=1,sNy
207 #ifdef TARGET_NEC_SX
208 !cdir novector
209 #endif
210 iG = iBase+(bi-1)*sNx
211 jG = jBase+(bj-1)*sNy+j
212 DO i=1,sNx
213 gloBuff(iG+i,jG) = temp(i,j,bi,bj)
214 ENDDO
215 ENDDO
216 ENDDO
217 ENDDO
218
219 C end if-else useExch2GlobLayOut
220 ENDIF
221
222 C- end loop on np
223 ENDDO
224
225 ELSE
226
227 C-- All proceses except 0 wait to be polled then send local array
228 #ifndef DISABLE_MPI_READY_TO_RECEIVE
229 CALL MPI_RECV (ready_to_receive, 1, MPI_INTEGER,
230 & idest, itag, MPI_COMM_MODEL, istatus, ierr)
231 #endif
232 CALL MPI_SEND (myField, lbuff, _MPI_TYPE_RX,
233 & idest, itag, MPI_COMM_MODEL, ierr)
234
235 ENDIF
236
237 ENDIF
238 #endif /* ALLOW_USE_MPI */
239
240 _END_MASTER( myThid )
241
242 RETURN
243 END

  ViewVC Help
Powered by ViewVC 1.1.22