/[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.5 - (show annotations) (download)
Mon Jun 8 03:34:03 2009 UTC (15 years ago) by jmc
Branch: MAIN
CVS Tags: checkpoint61r, checkpoint61p, checkpoint61q
Changes since 1.4: +3 -4 lines
- move barrier calls outside gather/scatter_2d to mds_read/write_field

1 C $Header: /u/gcmpack/MITgcm/eesupp/src/gather_2d_rx.template,v 1.4 2009/05/22 00:15:00 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 np0, np
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 c DO bj=1,nSy
82 bj=1
83 DO bi=1,nSx
84 tN = W2_myTileList(bi)
85 IF ( exch2_mydNx(tN) .GT. xSize ) THEN
86 C- face x-size larger than glob-size : fold it
87 iGjLoc = 0
88 jGjLoc = exch2_mydNx(tN) / xSize
89 ELSEIF ( exch2_tNy(tN) .GT. ySize ) THEN
90 C- tile y-size larger than glob-size : make a long line
91 iGjLoc = exch2_mydNx(tN)
92 jGjLoc = 0
93 ELSE
94 C- default (face fit into global-IO-array)
95 iGjLoc = 0
96 jGjLoc = 1
97 ENDIF
98
99 DO j=1,sNy
100 #ifdef TARGET_NEC_SX
101 !cdir novector
102 #endif
103 iG=exch2_txGlobalo(tN)+iGjLoc*(j-1)-1
104 jG=exch2_tyGlobalo(tN)+jGjLoc*(j-1)
105 DO i=1,sNx
106 gloBuff(iG+i,jG) = myField(i,j,bi,bj)
107 ENDDO
108 ENDDO
109
110 ENDDO
111 c ENDDO
112
113 ELSE
114 #else /* ALLOW_EXCH2 */
115 IF (.TRUE.) THEN
116 #endif /* ALLOW_EXCH2 */
117
118 iBase = myXGlobalLo-1
119 jBase = myYGlobalLo-1
120
121 DO bj=1,nSy
122 DO bi=1,nSx
123 DO j=1,sNy
124 #ifdef TARGET_NEC_SX
125 !cdir novector
126 #endif
127 iG = iBase+(bi-1)*sNx
128 jG = jBase+(bj-1)*sNy+j
129 DO i=1,sNx
130 gloBuff(iG+i,jG) = myField(i,j,bi,bj)
131 ENDDO
132 ENDDO
133 ENDDO
134 ENDDO
135
136 C end if-else useExch2GlobLayOut
137 ENDIF
138
139 C- end if myProcId = 0
140 ENDIF
141
142 #ifdef ALLOW_USE_MPI
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, numberOfProcs
153 np0 = np - 1
154 #ifndef DISABLE_MPI_READY_TO_RECEIVE
155 CALL MPI_SEND (ready_to_receive, 1, MPI_INTEGER,
156 & np0, itag, MPI_COMM_MODEL, ierr)
157 #endif
158 CALL MPI_RECV (temp, lbuff, _MPI_TYPE_RX,
159 & np0, 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 c DO bj=1,nSy
166 bj=1
167 DO bi=1,nSx
168 tN = W2_procTileList(bi,np)
169 IF ( exch2_mydNx(tN) .GT. xSize ) THEN
170 C- face x-size larger than glob-size : fold it
171 iGjLoc = 0
172 jGjLoc = exch2_mydNx(tN) / xSize
173 ELSEIF ( exch2_tNy(tN) .GT. ySize ) THEN
174 C- tile y-size larger than glob-size : make a long line
175 iGjLoc = exch2_mydNx(tN)
176 jGjLoc = 0
177 ELSE
178 C- default (face fit into global-IO-array)
179 iGjLoc = 0
180 jGjLoc = 1
181 ENDIF
182
183 DO j=1,sNy
184 #ifdef TARGET_NEC_SX
185 !cdir novector
186 #endif
187 iG=exch2_txGlobalo(tN)+iGjLoc*(j-1)-1
188 jG=exch2_tyGlobalo(tN)+jGjLoc*(j-1)
189 DO i=1,sNx
190 gloBuff(iG+i,jG) = temp(i,j,bi,bj)
191 ENDDO
192 ENDDO
193
194 ENDDO
195 c ENDDO
196
197 ELSE
198 #else /* ALLOW_EXCH2 */
199 IF (.TRUE.) THEN
200 #endif /* ALLOW_EXCH2 */
201
202 iBase = mpi_myXGlobalLo(np)-1
203 jBase = mpi_myYGlobalLo(np)-1
204
205 DO bj=1,nSy
206 DO bi=1,nSx
207 DO j=1,sNy
208 #ifdef TARGET_NEC_SX
209 !cdir novector
210 #endif
211 iG = iBase+(bi-1)*sNx
212 jG = jBase+(bj-1)*sNy+j
213 DO i=1,sNx
214 gloBuff(iG+i,jG) = temp(i,j,bi,bj)
215 ENDDO
216 ENDDO
217 ENDDO
218 ENDDO
219
220 C end if-else useExch2GlobLayOut
221 ENDIF
222
223 C- end loop on np
224 ENDDO
225
226 ELSE
227
228 C-- All proceses except 0 wait to be polled then send local array
229 #ifndef DISABLE_MPI_READY_TO_RECEIVE
230 CALL MPI_RECV (ready_to_receive, 1, MPI_INTEGER,
231 & idest, itag, MPI_COMM_MODEL, istatus, ierr)
232 #endif
233 CALL MPI_SEND (myField, lbuff, _MPI_TYPE_RX,
234 & idest, itag, MPI_COMM_MODEL, ierr)
235
236 ENDIF
237
238 #endif /* ALLOW_USE_MPI */
239
240 _END_MASTER( myThid )
241
242 RETURN
243 END

  ViewVC Help
Powered by ViewVC 1.1.22