1 |
dimitri |
1.3 |
C $Header: /usr/local/gcmpack/MITgcm/eesupp/src/exch_rx_recv_get_x.template,v 1.2 2001/09/21 03:55:50 cnh Exp $ |
2 |
cnh |
1.2 |
C $Name: $ |
3 |
adcroft |
1.1 |
#include "CPP_EEOPTIONS.h" |
4 |
|
|
|
5 |
cnh |
1.2 |
CBOP |
6 |
|
|
C !ROUTINE: EXCH_RX_RECV_GET_X |
7 |
|
|
|
8 |
|
|
C !INTERFACE: |
9 |
adcroft |
1.1 |
SUBROUTINE EXCH_RX_RECV_GET_X( array, |
10 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
11 |
|
|
I exchWidthX, exchWidthY, |
12 |
|
|
I theSimulationMode, theCornerMode, myThid ) |
13 |
|
|
IMPLICIT NONE |
14 |
|
|
|
15 |
cnh |
1.2 |
C !DESCRIPTION: |
16 |
|
|
C *==========================================================* |
17 |
|
|
C | SUBROUTINE RECV_RX_GET_X |
18 |
|
|
C | o "Send" or "put" X edges for RX array. |
19 |
|
|
C *==========================================================* |
20 |
|
|
C | Routine that invokes actual message passing send or |
21 |
|
|
C | direct "put" of data to update X faces of an XY[R] array. |
22 |
|
|
C *==========================================================* |
23 |
|
|
|
24 |
|
|
C !USES: |
25 |
adcroft |
1.1 |
C == Global variables == |
26 |
|
|
#include "SIZE.h" |
27 |
|
|
#include "EEPARAMS.h" |
28 |
|
|
#include "EESUPPORT.h" |
29 |
|
|
#include "EXCH.h" |
30 |
|
|
|
31 |
cnh |
1.2 |
C !INPUT/OUTPUT PARAMETERS: |
32 |
adcroft |
1.1 |
C == Routine arguments == |
33 |
cnh |
1.2 |
C array :: Array with edges to exchange. |
34 |
|
|
C myOLw :: West, East, North and South overlap region sizes. |
35 |
adcroft |
1.1 |
C myOLe |
36 |
|
|
C myOLn |
37 |
|
|
C myOLs |
38 |
cnh |
1.2 |
C exchWidthX :: Width of data region exchanged. |
39 |
adcroft |
1.1 |
C exchWidthY |
40 |
cnh |
1.2 |
C theSimulationMode :: Forward or reverse mode exchange ( provides |
41 |
adcroft |
1.1 |
C support for adjoint integration of code. ) |
42 |
cnh |
1.2 |
C theCornerMode :: Flag indicating whether corner updates are |
43 |
adcroft |
1.1 |
C needed. |
44 |
cnh |
1.2 |
C myThid :: Thread number of this instance of S/R EXCH... |
45 |
|
|
C eBl :: Edge buffer level |
46 |
adcroft |
1.1 |
INTEGER myOLw |
47 |
|
|
INTEGER myOLe |
48 |
|
|
INTEGER myOLs |
49 |
|
|
INTEGER myOLn |
50 |
|
|
INTEGER myNz |
51 |
|
|
_RX array(1-myOLw:sNx+myOLe, |
52 |
|
|
& 1-myOLs:sNy+myOLn, |
53 |
|
|
& myNZ, nSx, nSy) |
54 |
|
|
INTEGER exchWidthX |
55 |
|
|
INTEGER exchWidthY |
56 |
|
|
INTEGER theSimulationMode |
57 |
|
|
INTEGER theCornerMode |
58 |
|
|
INTEGER myThid |
59 |
|
|
|
60 |
cnh |
1.2 |
C !LOCAL VARIABLES: |
61 |
adcroft |
1.1 |
C == Local variables == |
62 |
cnh |
1.2 |
C I, J, K, iMin, iMax, iB :: Loop counters and extents |
63 |
adcroft |
1.1 |
C bi, bj |
64 |
cnh |
1.2 |
C biW, bjW :: West tile indices |
65 |
|
|
C biE, bjE :: East tile indices |
66 |
|
|
C eBl :: Current exchange buffer level |
67 |
|
|
C theProc, theTag, theType, :: Variables used in message building |
68 |
adcroft |
1.1 |
C theSize |
69 |
cnh |
1.2 |
C westCommMode :: Working variables holding type |
70 |
|
|
C eastCommMode of communication a particular |
71 |
|
|
C tile face uses. |
72 |
adcroft |
1.1 |
INTEGER I, J, K, iMin, iMax, iB, iB0 |
73 |
|
|
INTEGER bi, bj, biW, bjW, biE, bjE |
74 |
|
|
INTEGER eBl |
75 |
|
|
INTEGER westCommMode |
76 |
|
|
INTEGER eastCommMode |
77 |
|
|
INTEGER spinCount |
78 |
|
|
#ifdef ALLOW_USE_MPI |
79 |
|
|
INTEGER theProc, theTag, theType, theSize |
80 |
|
|
INTEGER mpiStatus(MPI_STATUS_SIZE,4), mpiRc |
81 |
|
|
#endif |
82 |
cnh |
1.2 |
CEOP |
83 |
adcroft |
1.1 |
|
84 |
|
|
|
85 |
|
|
C-- Under a "put" scenario we |
86 |
|
|
C-- i. set completetion signal for buffer we put into. |
87 |
|
|
C-- ii. wait for completetion signal indicating data has been put in |
88 |
|
|
C-- our buffer. |
89 |
|
|
C-- Under a messaging mode we "receive" the message. |
90 |
|
|
C-- Under a "get" scenario we |
91 |
|
|
C-- i. Check that the data is ready. |
92 |
|
|
C-- ii. Read the data. |
93 |
|
|
C-- iii. Set data read flag + memory sync. |
94 |
|
|
|
95 |
|
|
|
96 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
97 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
98 |
|
|
ebL = exchangeBufLevel(1,bi,bj) |
99 |
|
|
westCommMode = _tileCommModeW(bi,bj) |
100 |
|
|
eastCommMode = _tileCommModeE(bi,bj) |
101 |
|
|
biE = _tileBiE(bi,bj) |
102 |
|
|
bjE = _tileBjE(bi,bj) |
103 |
|
|
biW = _tileBiW(bi,bj) |
104 |
|
|
bjW = _tileBjW(bi,bj) |
105 |
|
|
IF ( westCommMode .EQ. COMM_MSG ) THEN |
106 |
|
|
#ifdef ALLOW_USE_MPI |
107 |
|
|
#ifndef ALWAYS_USE_MPI |
108 |
|
|
IF ( usingMPI ) THEN |
109 |
|
|
#endif |
110 |
|
|
theProc = tilePidW(bi,bj) |
111 |
|
|
theTag = _tileTagRecvW(bi,bj) |
112 |
dimitri |
1.3 |
theType = _MPI_TYPE_RX |
113 |
adcroft |
1.1 |
theSize = sNy*exchWidthX*myNz |
114 |
|
|
CALL MPI_Recv( westRecvBuf_RX(1,eBl,bi,bj), theSize, theType, |
115 |
|
|
& theProc, theTag, MPI_COMM_MODEL, |
116 |
|
|
& mpiStatus, mpiRc ) |
117 |
|
|
#ifndef ALWAYS_USE_MPI |
118 |
|
|
ENDIF |
119 |
|
|
#endif |
120 |
|
|
#endif /* ALLOW_USE_MPI */ |
121 |
|
|
ENDIF |
122 |
|
|
IF ( eastCommMode .EQ. COMM_MSG ) THEN |
123 |
|
|
#ifdef ALLOW_USE_MPI |
124 |
|
|
#ifndef ALWAYS_USE_MPI |
125 |
|
|
IF ( usingMPI ) THEN |
126 |
|
|
#endif |
127 |
|
|
theProc = tilePidE(bi,bj) |
128 |
|
|
theTag = _tileTagRecvE(bi,bj) |
129 |
dimitri |
1.3 |
theType = _MPI_TYPE_RX |
130 |
adcroft |
1.1 |
theSize = sNy*exchWidthX*myNz |
131 |
|
|
CALL MPI_Recv( eastRecvBuf_RX(1,eBl,bi,bj), theSize, theType, |
132 |
|
|
& theProc, theTag, MPI_COMM_MODEL, |
133 |
|
|
& mpiStatus, mpiRc ) |
134 |
|
|
#ifndef ALWAYS_USE_MPI |
135 |
|
|
ENDIF |
136 |
|
|
#endif |
137 |
|
|
#endif /* ALLOW_USE_MPI */ |
138 |
|
|
ENDIF |
139 |
|
|
ENDDO |
140 |
|
|
ENDDO |
141 |
|
|
|
142 |
|
|
C-- Wait for buffers I am going read to be ready. |
143 |
|
|
IF ( exchUsesBarrier ) THEN |
144 |
|
|
C o On some machines ( T90 ) use system barrier rather than spinning. |
145 |
|
|
CALL BARRIER( myThid ) |
146 |
|
|
ELSE |
147 |
|
|
C o Spin waiting for completetion flag. This avoids a global-lock |
148 |
|
|
C i.e. we only lock waiting for data that we need. |
149 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
150 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
151 |
|
|
spinCount = 0 |
152 |
|
|
ebL = exchangeBufLevel(1,bi,bj) |
153 |
|
|
westCommMode = _tileCommModeW(bi,bj) |
154 |
|
|
eastCommMode = _tileCommModeE(bi,bj) |
155 |
|
|
10 CONTINUE |
156 |
|
|
CALL FOOL_THE_COMPILER |
157 |
|
|
spinCount = spinCount+1 |
158 |
|
|
C IF ( myThid .EQ. 1 .AND. spinCount .GT. _EXCH_SPIN_LIMIT ) THEN |
159 |
|
|
C WRITE(*,*) ' eBl = ', ebl |
160 |
|
|
C STOP ' S/R EXCH_RECV_GET_X: spinCount .GT. _EXCH_SPIN_LIMIT' |
161 |
|
|
C ENDIF |
162 |
|
|
IF ( westRecvAck(eBl,bi,bj) .EQ. 0. ) GOTO 10 |
163 |
|
|
IF ( eastRecvAck(eBl,bi,bj) .EQ. 0. ) GOTO 10 |
164 |
|
|
C Clear outstanding requests |
165 |
|
|
westRecvAck(eBl,bi,bj) = 0. |
166 |
|
|
eastRecvAck(eBl,bi,bj) = 0. |
167 |
|
|
|
168 |
|
|
IF ( exchNReqsX(1,bi,bj) .GT. 0 ) THEN |
169 |
|
|
#ifdef ALLOW_USE_MPI |
170 |
|
|
#ifndef ALWAYS_USE_MPI |
171 |
|
|
IF ( usingMPI ) THEN |
172 |
|
|
#endif |
173 |
|
|
CALL MPI_Waitall( exchNReqsX(1,bi,bj), exchReqIdX(1,1,bi,bj), |
174 |
|
|
& mpiStatus, mpiRC ) |
175 |
|
|
#ifndef ALWAYS_USE_MPI |
176 |
|
|
ENDIF |
177 |
|
|
#endif |
178 |
|
|
#endif /* ALLOW_USE_MPI */ |
179 |
|
|
ENDIF |
180 |
|
|
C Clear outstanding requests counter |
181 |
|
|
exchNReqsX(1,bi,bj) = 0 |
182 |
|
|
C Update statistics |
183 |
|
|
IF ( exchCollectStatistics ) THEN |
184 |
|
|
exchRecvXExchCount(1,bi,bj) = exchRecvXExchCount(1,bi,bj)+1 |
185 |
|
|
exchRecvXSpinCount(1,bi,bj) = |
186 |
|
|
& exchRecvXSpinCount(1,bi,bj)+spinCount |
187 |
|
|
exchRecvXSpinMax(1,bi,bj) = |
188 |
|
|
& MAX(exchRecvXSpinMax(1,bi,bj),spinCount) |
189 |
|
|
exchRecvXSpinMin(1,bi,bj) = |
190 |
|
|
& MIN(exchRecvXSpinMin(1,bi,bj),spinCount) |
191 |
|
|
ENDIF |
192 |
|
|
ENDDO |
193 |
|
|
ENDDO |
194 |
|
|
ENDIF |
195 |
|
|
|
196 |
|
|
C-- Read from the buffers |
197 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
198 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
199 |
|
|
|
200 |
|
|
ebL = exchangeBufLevel(1,bi,bj) |
201 |
|
|
biE = _tileBiE(bi,bj) |
202 |
|
|
bjE = _tileBjE(bi,bj) |
203 |
|
|
biW = _tileBiW(bi,bj) |
204 |
|
|
bjW = _tileBjW(bi,bj) |
205 |
|
|
westCommMode = _tileCommModeW(bi,bj) |
206 |
|
|
eastCommMode = _tileCommModeE(bi,bj) |
207 |
|
|
IF ( _theSimulationMode .EQ. FORWARD_SIMULATION ) THEN |
208 |
|
|
iMin = sNx+1 |
209 |
|
|
iMax = sNx+exchWidthX |
210 |
|
|
iB0 = 0 |
211 |
|
|
IF ( eastCommMode .EQ. COMM_PUT |
212 |
|
|
& .OR. eastCommMode .EQ. COMM_MSG ) THEN |
213 |
|
|
iB = 0 |
214 |
|
|
DO K=1,myNz |
215 |
|
|
DO J=1,sNy |
216 |
|
|
DO I=iMin,iMax |
217 |
|
|
iB = iB + 1 |
218 |
|
|
array(I,J,K,bi,bj) = eastRecvBuf_RX(iB,eBl,bi,bj) |
219 |
|
|
ENDDO |
220 |
|
|
ENDDO |
221 |
|
|
ENDDO |
222 |
|
|
ELSEIF ( eastCommMode .EQ. COMM_GET ) THEN |
223 |
|
|
DO K=1,myNz |
224 |
|
|
DO J=1,sNy |
225 |
|
|
iB = iB0 |
226 |
|
|
DO I=iMin,iMax |
227 |
|
|
iB = iB+1 |
228 |
|
|
array(I,J,K,bi,bj) = array(iB,J,K,biE,bjE) |
229 |
|
|
ENDDO |
230 |
|
|
ENDDO |
231 |
|
|
ENDDO |
232 |
|
|
ENDIF |
233 |
|
|
ELSEIF ( _theSimulationMode .EQ. REVERSE_SIMULATION ) THEN |
234 |
|
|
iMin = sNx-exchWidthX+1 |
235 |
|
|
iMax = sNx |
236 |
|
|
iB0 = 1-exchWidthX-1 |
237 |
|
|
IF ( eastCommMode .EQ. COMM_PUT |
238 |
|
|
& .OR. eastCommMode .EQ. COMM_MSG ) THEN |
239 |
|
|
iB = 0 |
240 |
|
|
DO K=1,myNz |
241 |
|
|
DO J=1,sNy |
242 |
|
|
DO I=iMin,iMax |
243 |
|
|
iB = iB + 1 |
244 |
|
|
array(I,J,K,bi,bj) = |
245 |
|
|
& array(I,J,K,bi,bj)+eastRecvBuf_RX(iB,eBl,bi,bj) |
246 |
|
|
ENDDO |
247 |
|
|
ENDDO |
248 |
|
|
ENDDO |
249 |
|
|
ELSEIF ( eastCommMode .EQ. COMM_GET ) THEN |
250 |
|
|
DO K=1,myNz |
251 |
|
|
DO J=1,sNy |
252 |
|
|
iB = iB0 |
253 |
|
|
DO I=iMin,iMax |
254 |
|
|
iB = iB+1 |
255 |
|
|
array(I,J,K,bi,bj) = |
256 |
|
|
& array(I,J,K,bi,bj)+array(iB,J,K,biE,bjE) |
257 |
|
|
ENDDO |
258 |
|
|
ENDDO |
259 |
|
|
ENDDO |
260 |
|
|
ENDIF |
261 |
|
|
ENDIF |
262 |
|
|
IF ( _theSimulationMode .EQ. FORWARD_SIMULATION ) THEN |
263 |
|
|
iMin = 1-exchWidthX |
264 |
|
|
iMax = 0 |
265 |
|
|
iB0 = sNx-exchWidthX |
266 |
|
|
IF ( westCommMode .EQ. COMM_PUT |
267 |
|
|
& .OR. westCommMode .EQ. COMM_MSG ) THEN |
268 |
|
|
iB = 0 |
269 |
|
|
DO K=1,myNz |
270 |
|
|
DO J=1,sNy |
271 |
|
|
DO I=iMin,iMax |
272 |
|
|
iB = iB + 1 |
273 |
|
|
array(I,J,K,bi,bj) = westRecvBuf_RX(iB,eBl,bi,bj) |
274 |
|
|
ENDDO |
275 |
|
|
ENDDO |
276 |
|
|
ENDDO |
277 |
|
|
ELSEIF ( westCommMode .EQ. COMM_GET ) THEN |
278 |
|
|
DO K=1,myNz |
279 |
|
|
DO J=1,sNy |
280 |
|
|
iB = iB0 |
281 |
|
|
DO I=iMin,iMax |
282 |
|
|
iB = iB+1 |
283 |
|
|
array(I,J,K,bi,bj) = array(iB,J,K,biW,bjW) |
284 |
|
|
ENDDO |
285 |
|
|
ENDDO |
286 |
|
|
ENDDO |
287 |
|
|
ENDIF |
288 |
|
|
ELSEIF ( _theSimulationMode .EQ. REVERSE_SIMULATION ) THEN |
289 |
|
|
iMin = 1 |
290 |
|
|
iMax = 1+exchWidthX-1 |
291 |
|
|
iB0 = sNx |
292 |
|
|
IF ( westCommMode .EQ. COMM_PUT |
293 |
|
|
& .OR. westCommMode .EQ. COMM_MSG ) THEN |
294 |
|
|
iB = 0 |
295 |
|
|
DO K=1,myNz |
296 |
|
|
DO J=1,sNy |
297 |
|
|
DO I=iMin,iMax |
298 |
|
|
iB = iB + 1 |
299 |
|
|
array(I,J,K,bi,bj) = |
300 |
|
|
& array(I,J,K,bi,bj)+westRecvBuf_RX(iB,eBl,bi,bj) |
301 |
|
|
ENDDO |
302 |
|
|
ENDDO |
303 |
|
|
ENDDO |
304 |
|
|
ELSEIF ( westCommMode .EQ. COMM_GET ) THEN |
305 |
|
|
DO K=1,myNz |
306 |
|
|
DO J=1,sNy |
307 |
|
|
iB = iB0 |
308 |
|
|
DO I=iMin,iMax |
309 |
|
|
iB = iB+1 |
310 |
|
|
array(I,J,K,bi,bj) = |
311 |
|
|
& array(I,J,K,bi,bj)+array(iB,J,K,biW,bjW) |
312 |
|
|
ENDDO |
313 |
|
|
ENDDO |
314 |
|
|
ENDDO |
315 |
|
|
ENDIF |
316 |
|
|
ENDIF |
317 |
|
|
|
318 |
|
|
ENDDO |
319 |
|
|
ENDDO |
320 |
|
|
|
321 |
|
|
RETURN |
322 |
|
|
END |