1 |
adcroft |
1.1 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/exch_recv_get_x.F,v 1.4 1999/05/03 21:40:00 adcroft Exp $ |
2 |
|
|
#include "CPP_OPTIONS.h" |
3 |
|
|
#include "CPP_EEOPTIONS.h" |
4 |
|
|
|
5 |
|
|
SUBROUTINE EXCH_RL_RECV_GET_VEC_X( arrayE, arrayW, |
6 |
|
|
I myd1, myThid ) |
7 |
|
|
C /==========================================================\ |
8 |
|
|
C | SUBROUTINE RECV_RL_GET_X | |
9 |
|
|
C | o "Send" or "put" X edges for RL array. | |
10 |
|
|
C |==========================================================| |
11 |
|
|
C | Routine that invokes actual message passing send or | |
12 |
|
|
C | direct "put" of data to update X faces of an XY[R] array.| |
13 |
|
|
C \==========================================================/ |
14 |
|
|
IMPLICIT NONE |
15 |
|
|
|
16 |
|
|
C == Global variables == |
17 |
|
|
#include "SIZE.h" |
18 |
|
|
#include "EEPARAMS.h" |
19 |
|
|
#include "EESUPPORT.h" |
20 |
|
|
#include "FLT.h" |
21 |
|
|
#include "EXCH.h" |
22 |
|
|
|
23 |
|
|
C == Routine arguments == |
24 |
|
|
C arrayE - Arrays to exchange be exchanged. |
25 |
|
|
C arrayW |
26 |
|
|
C myd1 - sizes. |
27 |
|
|
C myd2 |
28 |
|
|
C theSimulationMode - Forward or reverse mode exchange ( provides |
29 |
|
|
C support for adjoint integration of code. ) |
30 |
|
|
C myThid - Thread number of this instance of S/R EXCH... |
31 |
|
|
C eBl - Edge buffer level |
32 |
|
|
INTEGER myd1 |
33 |
|
|
INTEGER myd2 |
34 |
|
|
_RL arrayE(myd1, nSx, nSy), arrayW(myd1, nSx, nSy) |
35 |
|
|
INTEGER theSimulationMode |
36 |
|
|
INTEGER myThid |
37 |
|
|
CEndOfInterface |
38 |
|
|
|
39 |
|
|
C == Local variables == |
40 |
|
|
C I, J - Loop counters and extents |
41 |
|
|
C bi, bj |
42 |
|
|
C biW, bjW - West tile indices |
43 |
|
|
C biE, bjE - East tile indices |
44 |
|
|
C theProc, theTag, theType, - Variables used in message building |
45 |
|
|
C theSize |
46 |
|
|
C westCommMode - Working variables holding type |
47 |
|
|
C eastCommMode of communication a particular |
48 |
|
|
C tile face uses. |
49 |
|
|
INTEGER I, J |
50 |
|
|
INTEGER bi, bj, biW, bjW, biE, bjE |
51 |
|
|
INTEGER westCommMode |
52 |
|
|
INTEGER eastCommMode |
53 |
|
|
INTEGER spinCount |
54 |
|
|
#ifdef ALLOW_USE_MPI |
55 |
|
|
INTEGER theProc, theTag, theType, theSize |
56 |
|
|
INTEGER mpiStatus(MPI_STATUS_SIZE,4), mpiRc |
57 |
|
|
#endif |
58 |
|
|
|
59 |
|
|
|
60 |
|
|
C-- Under a "put" scenario we |
61 |
|
|
C-- i. set completetion signal for buffer we put into. |
62 |
|
|
C-- ii. wait for completetion signal indicating data has been put in |
63 |
|
|
C-- our buffer. |
64 |
|
|
C-- Under a messaging mode we "receive" the message. |
65 |
|
|
C-- Under a "get" scenario we |
66 |
|
|
C-- i. Check that the data is ready. |
67 |
|
|
C-- ii. Read the data. |
68 |
|
|
C-- iii. Set data read flag + memory sync. |
69 |
|
|
|
70 |
|
|
|
71 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
72 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
73 |
|
|
westCommMode = _tileCommModeW(bi,bj) |
74 |
|
|
eastCommMode = _tileCommModeE(bi,bj) |
75 |
|
|
biE = _tileBiE(bi,bj) |
76 |
|
|
bjE = _tileBjE(bi,bj) |
77 |
|
|
biW = _tileBiW(bi,bj) |
78 |
|
|
bjW = _tileBjW(bi,bj) |
79 |
|
|
IF ( westCommMode .EQ. COMM_MSG ) THEN |
80 |
|
|
#ifdef ALLOW_USE_MPI |
81 |
|
|
#ifndef ALWAYS_USE_MPI |
82 |
|
|
IF ( usingMPI ) THEN |
83 |
|
|
#endif |
84 |
|
|
theProc = tilePidW(bi,bj) |
85 |
|
|
theTag = _tileTagRecvW(bi,bj) |
86 |
|
|
theType = MPI_DOUBLE_PRECISION |
87 |
|
|
theSize = myd1 |
88 |
|
|
CALL MPI_Recv( arrayW(1,bi,bj), theSize, theType, |
89 |
|
|
& theProc, theTag, MPI_COMM_MODEL, |
90 |
|
|
& mpiStatus, mpiRc ) |
91 |
|
|
c if (theProc .eq. 0 .or. theProc .eq. 2) then |
92 |
|
|
c if (arrayW(1,bi,bj) .ne. 0.) then |
93 |
|
|
c write(errormessageunit,*) 'qq2y: ',myprocid, |
94 |
|
|
c & theProc,theTag,theSize,(arrayW(i,bi,bj),i=1,32) |
95 |
|
|
c else |
96 |
|
|
c write(errormessageunit,*) 'qq2n: ',myprocid, |
97 |
|
|
c & theProc,theTag,theSize,(arrayW(i,bi,bj),i=1,32) |
98 |
|
|
c endif |
99 |
|
|
c endif |
100 |
|
|
#ifndef ALWAYS_USE_MPI |
101 |
|
|
ENDIF |
102 |
|
|
#endif |
103 |
|
|
#endif /* ALLOW_USE_MPI */ |
104 |
|
|
ENDIF |
105 |
|
|
IF ( eastCommMode .EQ. COMM_MSG ) THEN |
106 |
|
|
#ifdef ALLOW_USE_MPI |
107 |
|
|
#ifndef ALWAYS_USE_MPI |
108 |
|
|
IF ( usingMPI ) THEN |
109 |
|
|
#endif |
110 |
|
|
theProc = tilePidE(bi,bj) |
111 |
|
|
theTag = _tileTagRecvE(bi,bj) |
112 |
|
|
theType = MPI_DOUBLE_PRECISION |
113 |
|
|
theSize = myd1 |
114 |
|
|
CALL MPI_Recv( arrayE(1,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 |
|
|
ENDDO |
123 |
|
|
ENDDO |
124 |
|
|
|
125 |
|
|
C-- Wait for buffers I am going read to be ready. |
126 |
|
|
IF ( exchUsesBarrier ) THEN |
127 |
|
|
C o On some machines ( T90 ) use system barrier rather than spinning. |
128 |
|
|
CALL BARRIER( myThid ) |
129 |
|
|
ELSE |
130 |
|
|
C o Spin waiting for completetion flag. This avoids a global-lock |
131 |
|
|
C i.e. we only lock waiting for data that we need. |
132 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
133 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
134 |
|
|
spinCount = 0 |
135 |
|
|
westCommMode = _tileCommModeW(bi,bj) |
136 |
|
|
eastCommMode = _tileCommModeE(bi,bj) |
137 |
|
|
10 CONTINUE |
138 |
|
|
CALL FOOL_THE_COMPILER |
139 |
|
|
spinCount = spinCount+1 |
140 |
|
|
C IF ( myThid .EQ. 1 .AND. spinCount .GT. _EXCH_SPIN_LIMIT ) THEN |
141 |
|
|
C WRITE(0,*) ' eBl = ', ebl |
142 |
|
|
C STOP ' S/R EXCH_RECV_GET_X: spinCount .GT. _EXCH_SPIN_LIMIT' |
143 |
|
|
C ENDIF |
144 |
|
|
IF ( westRecvAck(1,bi,bj) .EQ. 0. ) GOTO 10 |
145 |
|
|
IF ( eastRecvAck(1,bi,bj) .EQ. 0. ) GOTO 10 |
146 |
|
|
C Clear outstanding requests |
147 |
|
|
westRecvAck(1,bi,bj) = 0. |
148 |
|
|
eastRecvAck(1,bi,bj) = 0. |
149 |
|
|
|
150 |
|
|
c IF ( exchVReqsX(1,bi,bj) .GT. 0 ) THEN |
151 |
|
|
IF ( exchNReqsX(1,bi,bj) .GT. 0 ) THEN |
152 |
|
|
#ifdef ALLOW_USE_MPI |
153 |
|
|
#ifndef ALWAYS_USE_MPI |
154 |
|
|
IF ( usingMPI ) THEN |
155 |
|
|
#endif |
156 |
|
|
c CALL MPI_Waitall( exchVReqsX(1,bi,bj), exchReqVIdX(1,1,bi,bj), |
157 |
|
|
CALL MPI_Waitall( exchNReqsX(1,bi,bj), exchReqIdX(1,1,bi,bj), |
158 |
|
|
& mpiStatus, mpiRC ) |
159 |
|
|
#ifndef ALWAYS_USE_MPI |
160 |
|
|
ENDIF |
161 |
|
|
#endif |
162 |
|
|
#endif /* ALLOW_USE_MPI */ |
163 |
|
|
ENDIF |
164 |
|
|
C Clear outstanding requests counter |
165 |
|
|
c exchVReqsX(1,bi,bj) = 0 |
166 |
|
|
exchNReqsX(1,bi,bj) = 0 |
167 |
|
|
C Update statistics |
168 |
|
|
ENDDO |
169 |
|
|
ENDDO |
170 |
|
|
ENDIF |
171 |
|
|
|
172 |
|
|
C-- Read from the buffers |
173 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
174 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
175 |
|
|
|
176 |
|
|
biE = _tileBiE(bi,bj) |
177 |
|
|
bjE = _tileBjE(bi,bj) |
178 |
|
|
biW = _tileBiW(bi,bj) |
179 |
|
|
bjW = _tileBjW(bi,bj) |
180 |
|
|
westCommMode = _tileCommModeW(bi,bj) |
181 |
|
|
eastCommMode = _tileCommModeE(bi,bj) |
182 |
|
|
IF ( eastCommMode .EQ. COMM_GET ) THEN |
183 |
|
|
DO I=1,myd1 |
184 |
|
|
arrayE(I,bi,bj) = arrayW(I,biE,bjE) |
185 |
|
|
ENDDO |
186 |
|
|
ENDIF |
187 |
|
|
IF ( westCommMode .EQ. COMM_GET ) THEN |
188 |
|
|
DO I=1,myd1 |
189 |
|
|
arrayW(I,bi,bj) = arrayE(I,biW,bjW) |
190 |
|
|
ENDDO |
191 |
|
|
ENDIF |
192 |
|
|
|
193 |
|
|
ENDDO |
194 |
|
|
ENDDO |
195 |
|
|
|
196 |
|
|
RETURN |
197 |
|
|
END |
198 |
|
|
|
199 |
|
|
|
200 |
|
|
SUBROUTINE EXCH_RL_RECV_GET_VEC_Y( arrayN, arrayS, |
201 |
|
|
I myd1, myThid ) |
202 |
|
|
C /==========================================================\ |
203 |
|
|
C | SUBROUTINE RECV_RL_GET_Y | |
204 |
|
|
C | o "Send" or "put" Y edges for RL array. | |
205 |
|
|
C |==========================================================| |
206 |
|
|
C | Routine that invokes actual message passing send or | |
207 |
|
|
C | direct "put" of data to update Y faces of an XY[R] array.| |
208 |
|
|
C \==========================================================/ |
209 |
|
|
IMPLICIT NONE |
210 |
|
|
|
211 |
|
|
C == Global variables == |
212 |
|
|
#include "SIZE.h" |
213 |
|
|
#include "EEPARAMS.h" |
214 |
|
|
#include "EESUPPORT.h" |
215 |
|
|
#include "FLT.h" |
216 |
|
|
#include "EXCH.h" |
217 |
|
|
|
218 |
|
|
C == Routine arguments == |
219 |
|
|
C arrayN - Arrays to exchange be exchanged. |
220 |
|
|
C arrayS |
221 |
|
|
C myd1 - sizes. |
222 |
|
|
C myd2 |
223 |
|
|
C theSimulationMode - Forward or reverse mode exchange ( provides |
224 |
|
|
C support for adjoint integration of code. ) |
225 |
|
|
C myThid - Thread number of this instance of S/R EXCH... |
226 |
|
|
INTEGER myd1 |
227 |
|
|
INTEGER myd2 |
228 |
|
|
_RL arrayN(myd1, nSx, nSy), arrayS(myd1, nSx, nSy) |
229 |
|
|
INTEGER theSimulationMode |
230 |
|
|
INTEGER myThid |
231 |
|
|
CEndOfInterface |
232 |
|
|
|
233 |
|
|
C == Local variables == |
234 |
|
|
C I, J - Loop counters and extents |
235 |
|
|
C bi, bj |
236 |
|
|
C biS, bjS - South tile indices |
237 |
|
|
C biE, bjE - North tile indices |
238 |
|
|
C theProc, theTag, theType, - Variables used in message building |
239 |
|
|
C theSize |
240 |
|
|
C southCommMode - Working variables holding type |
241 |
|
|
C northCommMode of communication a particular |
242 |
|
|
C tile face uses. |
243 |
|
|
INTEGER I, J |
244 |
|
|
INTEGER bi, bj, biS, bjS, biN, bjN |
245 |
|
|
INTEGER southCommMode |
246 |
|
|
INTEGER northCommMode |
247 |
|
|
INTEGER spinCount |
248 |
|
|
#ifdef ALLOW_USE_MPI |
249 |
|
|
INTEGER theProc, theTag, theType, theSize |
250 |
|
|
INTEGER mpiStatus(MPI_STATUS_SIZE,4), mpiRc |
251 |
|
|
#endif |
252 |
|
|
|
253 |
|
|
|
254 |
|
|
C-- Under a "put" scenario we |
255 |
|
|
C-- i. set completetion signal for buffer we put into. |
256 |
|
|
C-- ii. wait for completetion signal indicating data has been put in |
257 |
|
|
C-- our buffer. |
258 |
|
|
C-- Under a messaging mode we "receive" the message. |
259 |
|
|
C-- Under a "get" scenario we |
260 |
|
|
C-- i. Check that the data is ready. |
261 |
|
|
C-- ii. Read the data. |
262 |
|
|
C-- iii. Set data read flag + memory sync. |
263 |
|
|
|
264 |
|
|
|
265 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
266 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
267 |
|
|
southCommMode = _tileCommModeS(bi,bj) |
268 |
|
|
northCommMode = _tileCommModeN(bi,bj) |
269 |
|
|
biN = _tileBiN(bi,bj) |
270 |
|
|
bjN = _tileBjN(bi,bj) |
271 |
|
|
biS = _tileBiS(bi,bj) |
272 |
|
|
bjS = _tileBjS(bi,bj) |
273 |
|
|
IF ( southCommMode .EQ. COMM_MSG ) THEN |
274 |
|
|
#ifdef ALLOW_USE_MPI |
275 |
|
|
#ifndef ALWAYS_USE_MPI |
276 |
|
|
IF ( usingMPI ) THEN |
277 |
|
|
#endif |
278 |
|
|
theProc = tilePidS(bi,bj) |
279 |
|
|
theTag = _tileTagRecvS(bi,bj) |
280 |
|
|
theType = MPI_DOUBLE_PRECISION |
281 |
|
|
theSize = myd1 |
282 |
|
|
CALL MPI_Recv( arrayS(1,bi,bj), theSize, theType, |
283 |
|
|
& theProc, theTag, MPI_COMM_MODEL, |
284 |
|
|
& mpiStatus, mpiRc ) |
285 |
|
|
#ifndef ALWAYS_USE_MPI |
286 |
|
|
ENDIF |
287 |
|
|
#endif |
288 |
|
|
#endif /* ALLOW_USE_MPI */ |
289 |
|
|
ENDIF |
290 |
|
|
IF ( northCommMode .EQ. COMM_MSG ) THEN |
291 |
|
|
#ifdef ALLOW_USE_MPI |
292 |
|
|
#ifndef ALWAYS_USE_MPI |
293 |
|
|
IF ( usingMPI ) THEN |
294 |
|
|
#endif |
295 |
|
|
theProc = tilePidN(bi,bj) |
296 |
|
|
theTag = _tileTagRecvN(bi,bj) |
297 |
|
|
theType = MPI_DOUBLE_PRECISION |
298 |
|
|
theSize = myd1 |
299 |
|
|
CALL MPI_Recv( arrayN(1,bi,bj), theSize, theType, |
300 |
|
|
& theProc, theTag, MPI_COMM_MODEL, |
301 |
|
|
& mpiStatus, mpiRc ) |
302 |
|
|
#ifndef ALWAYS_USE_MPI |
303 |
|
|
ENDIF |
304 |
|
|
#endif |
305 |
|
|
#endif /* ALLOW_USE_MPI */ |
306 |
|
|
ENDIF |
307 |
|
|
ENDDO |
308 |
|
|
ENDDO |
309 |
|
|
|
310 |
|
|
C-- Wait for buffers I am going read to be ready. |
311 |
|
|
IF ( exchUsesBarrier ) THEN |
312 |
|
|
C o On some machines ( T90 ) use system barrier rather than spinning. |
313 |
|
|
CALL BARRIER( myThid ) |
314 |
|
|
ELSE |
315 |
|
|
C o Spin waiting for completetion flag. This avoids a global-lock |
316 |
|
|
C i.e. we only lock waiting for data that we need. |
317 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
318 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
319 |
|
|
spinCount = 0 |
320 |
|
|
southCommMode = _tileCommModeS(bi,bj) |
321 |
|
|
northCommMode = _tileCommModeN(bi,bj) |
322 |
|
|
10 CONTINUE |
323 |
|
|
CALL FOOL_THE_COMPILER |
324 |
|
|
spinCount = spinCount+1 |
325 |
|
|
C IF ( myThid .EQ. 1 .AND. spinCount .GT. _EXCH_SPIN_LIMIT ) THEN |
326 |
|
|
C WRITE(0,*) ' eBl = ', ebl |
327 |
|
|
C STOP ' S/R EXCH_RECV_GET_X: spinCount .GT. _EXCH_SPIN_LIMIT' |
328 |
|
|
C ENDIF |
329 |
|
|
IF ( southRecvAck(1,bi,bj) .EQ. 0. ) GOTO 10 |
330 |
|
|
IF ( northRecvAck(1,bi,bj) .EQ. 0. ) GOTO 10 |
331 |
|
|
C Clear outstanding requests |
332 |
|
|
southRecvAck(1,bi,bj) = 0. |
333 |
|
|
northRecvAck(1,bi,bj) = 0. |
334 |
|
|
|
335 |
|
|
c IF ( exchVReqsY(1,bi,bj) .GT. 0 ) THEN |
336 |
|
|
IF ( exchNReqsY(1,bi,bj) .GT. 0 ) THEN |
337 |
|
|
#ifdef ALLOW_USE_MPI |
338 |
|
|
#ifndef ALWAYS_USE_MPI |
339 |
|
|
IF ( usingMPI ) THEN |
340 |
|
|
#endif |
341 |
|
|
c CALL MPI_Waitall( exchVReqsY(1,bi,bj), exchReqVIdY(1,1,bi,bj), |
342 |
|
|
CALL MPI_Waitall( exchNReqsY(1,bi,bj), exchReqIdY(1,1,bi,bj), |
343 |
|
|
& mpiStatus, mpiRC ) |
344 |
|
|
#ifndef ALWAYS_USE_MPI |
345 |
|
|
ENDIF |
346 |
|
|
#endif |
347 |
|
|
#endif /* ALLOW_USE_MPI */ |
348 |
|
|
ENDIF |
349 |
|
|
C Clear outstanding requests counter |
350 |
|
|
c exchVReqsY(1,bi,bj) = 0 |
351 |
|
|
exchNReqsY(1,bi,bj) = 0 |
352 |
|
|
C Update statistics |
353 |
|
|
ENDDO |
354 |
|
|
ENDDO |
355 |
|
|
ENDIF |
356 |
|
|
|
357 |
|
|
C-- Read from the buffers |
358 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
359 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
360 |
|
|
|
361 |
|
|
biN = _tileBiN(bi,bj) |
362 |
|
|
bjN = _tileBjN(bi,bj) |
363 |
|
|
biS = _tileBiS(bi,bj) |
364 |
|
|
bjS = _tileBjS(bi,bj) |
365 |
|
|
southCommMode = _tileCommModeS(bi,bj) |
366 |
|
|
northCommMode = _tileCommModeN(bi,bj) |
367 |
|
|
IF ( southCommMode .EQ. COMM_GET ) THEN |
368 |
|
|
DO I=1,myd1 |
369 |
|
|
arrayN(I,bi,bj) = arrayS(I,biN,bjN) |
370 |
|
|
ENDDO |
371 |
|
|
ENDIF |
372 |
|
|
IF ( southCommMode .EQ. COMM_GET ) THEN |
373 |
|
|
DO I=1,myd1 |
374 |
|
|
arrayS(I,bi,bj) = arrayN(I,biS,bjS) |
375 |
|
|
ENDDO |
376 |
|
|
ENDIF |
377 |
|
|
|
378 |
|
|
ENDDO |
379 |
|
|
ENDDO |
380 |
|
|
|
381 |
|
|
RETURN |
382 |
|
|
END |
383 |
|
|
|