1 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/exch_send_put_x.F,v 1.2 1999/03/22 17:37:43 adcroft Exp $ |
2 |
#include "CPP_OPTIONS.h" |
3 |
#ifdef ALLOW_FLT |
4 |
#include "CPP_EEOPTIONS.h" |
5 |
|
6 |
SUBROUTINE EXCH_RL_SEND_PUT_VEC_X( arrayE, arrayW, |
7 |
I myd1, myThid ) |
8 |
C /==========================================================\ |
9 |
C | SUBROUTINE EXCH_RL_SEND_PUT_X | |
10 |
C | o "Send" or "put" X edges for RL array. | |
11 |
C |==========================================================| |
12 |
C | Routine that invokes actual message passing send or | |
13 |
C | direct "put" of data to update X faces of an XY[R] array.| |
14 |
C \==========================================================/ |
15 |
IMPLICIT NONE |
16 |
|
17 |
C == Global variables == |
18 |
#include "SIZE.h" |
19 |
#include "EEPARAMS.h" |
20 |
#include "EESUPPORT.h" |
21 |
#include "FLT.h" |
22 |
#include "EXCH.h" |
23 |
C == Routine arguments == |
24 |
C arrayE - Array to be exchanged. |
25 |
C arrayW |
26 |
C myd1 - sizes. |
27 |
C myd2 |
28 |
C myThid - Thread number of this instance of S/R EXCH... |
29 |
INTEGER myd1 |
30 |
INTEGER myd2 |
31 |
_RL arrayE(myd1, nSx, nSy), arrayW(myd1, nSx, nSy) |
32 |
INTEGER theSimulationMode |
33 |
INTEGER myThid |
34 |
CEndOfInterface |
35 |
|
36 |
C == Local variables == |
37 |
C I, J - Loop counters and extents |
38 |
C bi, bj |
39 |
C biW, bjW - West tile indices |
40 |
C biE, bjE - East tile indices |
41 |
C theProc, theTag, theType, - Variables used in message building |
42 |
C theSize |
43 |
C westCommMode - Working variables holding type |
44 |
C eastCommMode of communication a particular |
45 |
C tile face uses. |
46 |
INTEGER I, J |
47 |
INTEGER bi, bj, biW, bjW, biE, bjE |
48 |
INTEGER westCommMode |
49 |
INTEGER eastCommMode |
50 |
|
51 |
#ifdef ALLOW_USE_MPI |
52 |
INTEGER theProc, theTag, theType, theSize, mpiRc |
53 |
#endif |
54 |
C-- Write data to exchange buffer |
55 |
C Various actions are possible depending on the communication mode |
56 |
C as follows: |
57 |
C Mode Action |
58 |
C -------- --------------------------- |
59 |
C COMM_NONE Do nothing |
60 |
C |
61 |
C COMM_MSG Message passing communication ( e.g. MPI ) |
62 |
C Fill west send buffer from this tile. |
63 |
C Send data with tag identifying tile and direction. |
64 |
C Fill east send buffer from this tile. |
65 |
C Send data with tag identifying tile and direction. |
66 |
C |
67 |
C COMM_PUT "Put" communication ( UMP_, shmemput, etc... ) |
68 |
C Fill east receive buffer of west-neighbor tile |
69 |
C Fill west receive buffer of east-neighbor tile |
70 |
C Sync. memory |
71 |
C Write data-ready Ack for east edge of west-neighbor |
72 |
C tile |
73 |
C Write data-ready Ack for west edge of east-neighbor |
74 |
C tile |
75 |
C Sync. memory |
76 |
C |
77 |
DO bj=myByLo(myThid),myByHi(myThid) |
78 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
79 |
|
80 |
westCommMode = _tileCommModeW(bi,bj) |
81 |
eastCommMode = _tileCommModeE(bi,bj) |
82 |
biE = _tileBiE(bi,bj) |
83 |
bjE = _tileBjE(bi,bj) |
84 |
biW = _tileBiW(bi,bj) |
85 |
bjW = _tileBjW(bi,bj) |
86 |
|
87 |
C o Send or Put west edge |
88 |
IF ( westCommMode .EQ. COMM_MSG ) THEN |
89 |
C Send the data |
90 |
#ifdef ALLOW_USE_MPI |
91 |
#ifndef ALWAYS_USE_MPI |
92 |
IF ( usingMPI ) THEN |
93 |
#endif |
94 |
theProc = tilePidW(bi,bj) |
95 |
theTag = _tileTagSendW(bi,bj) |
96 |
theSize = myd1 |
97 |
theType = MPI_DOUBLE_PRECISION |
98 |
c exchVReqsX(1,bi,bj) = exchVReqsX(1,bi,bj)+1 |
99 |
exchNReqsX(1,bi,bj) = exchNReqsX(1,bi,bj)+1 |
100 |
CALL MPI_Isend(arrayW(1,bi,bj), theSize, theType, |
101 |
& theProc, theTag, MPI_COMM_MODEL, |
102 |
& exchReqIdX(exchNReqsX(1,bi,bj),1,bi,bj), mpiRc) |
103 |
c & exchReqVIdX(exchVReqsX(1,bi,bj),1,bi,bj), mpiRc) |
104 |
#ifndef ALWAYS_USE_MPI |
105 |
ENDIF |
106 |
#endif |
107 |
#endif /* ALLOW_USE_MPI */ |
108 |
eastRecvAck(1,biW,bjW) = 1. |
109 |
ELSEIF ( westCommMode .EQ. COMM_PUT ) THEN |
110 |
DO I=1,myd1 |
111 |
arrayE(I,biW,bjW) = arrayW(I,bi,bj) |
112 |
ENDDO |
113 |
ELSEIF ( westCommMode .NE. COMM_NONE |
114 |
& .AND. westCommMode .NE. COMM_GET ) THEN |
115 |
STOP ' S/R EXCH: Invalid commW mode.' |
116 |
ENDIF |
117 |
|
118 |
C o Send or Put east edge |
119 |
IF ( eastCommMode .EQ. COMM_MSG ) THEN |
120 |
C Send the data |
121 |
#ifdef ALLOW_USE_MPI |
122 |
#ifndef ALWAYS_USE_MPI |
123 |
IF ( usingMPI ) THEN |
124 |
#endif |
125 |
theProc = tilePidE(bi,bj) |
126 |
theTag = _tileTagSendE(bi,bj) |
127 |
theSize = myd1 |
128 |
theType = MPI_DOUBLE_PRECISION |
129 |
c exchVReqsX(1,bi,bj) = exchVReqsX(1,bi,bj)+1 |
130 |
exchNReqsX(1,bi,bj) = exchNReqsX(1,bi,bj)+1 |
131 |
c if (theProc .eq. 2 .or. theProc .eq. 4) then |
132 |
c if (arrayE(1,bi,bj) .ne. 0.) then |
133 |
c write(errormessageunit,*) 'qq1y: ',myprocid, |
134 |
c & theProc,theTag,theSize,(arrayE(i,bi,bj),i=1,32) |
135 |
c endif |
136 |
c endif |
137 |
CALL MPI_Isend(arrayE(1,bi,bj), theSize, theType, |
138 |
& theProc, theTag, MPI_COMM_MODEL, |
139 |
& exchReqIdX(exchNReqsX(1,bi,bj),1,bi,bj), mpiRc) |
140 |
c & exchReqVIdX(exchVReqsX(1,bi,bj),1,bi,bj), mpiRc) |
141 |
#ifndef ALWAYS_USE_MPI |
142 |
ENDIF |
143 |
#endif |
144 |
#endif /* ALLOW_USE_MPI */ |
145 |
westRecvAck(1,biE,bjE) = 1. |
146 |
ELSEIF ( eastCommMode .EQ. COMM_PUT ) THEN |
147 |
DO I=1,myd1 |
148 |
arrayW(I,biE,bjE) = arrayE(I,bi,bj) |
149 |
ENDDO |
150 |
ELSEIF ( eastCommMode .NE. COMM_NONE |
151 |
& .AND. eastCommMode .NE. COMM_GET ) THEN |
152 |
STOP ' S/R EXCH: Invalid commE mode.' |
153 |
ENDIF |
154 |
|
155 |
ENDDO |
156 |
ENDDO |
157 |
|
158 |
C-- Signal completetion ( making sure system-wide memory state is |
159 |
C-- consistent ). |
160 |
|
161 |
C ** NOTE ** We are relying on being able to produce strong-ordered |
162 |
C memory semantics here. In other words we assume that there is a |
163 |
C mechanism which can ensure that by the time the Ack is seen the |
164 |
C overlap region data that will be exchanged is up to date. |
165 |
IF ( exchNeedsMemSync ) CALL MEMSYNC |
166 |
|
167 |
DO bj=myByLo(myThid),myByHi(myThid) |
168 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
169 |
biE = _tileBiE(bi,bj) |
170 |
bjE = _tileBjE(bi,bj) |
171 |
biW = _tileBiW(bi,bj) |
172 |
bjW = _tileBjW(bi,bj) |
173 |
westCommMode = _tileCommModeW(bi,bj) |
174 |
eastCommMode = _tileCommModeE(bi,bj) |
175 |
IF ( westCommMode .EQ. COMM_PUT ) eastRecvAck(1,biW,bjW) = 1. |
176 |
IF ( eastCommMode .EQ. COMM_PUT ) westRecvAck(1,biE,bjE) = 1. |
177 |
IF ( westCommMode .EQ. COMM_GET ) eastRecvAck(1,biW,bjW) = 1. |
178 |
IF ( eastCommMode .EQ. COMM_GET ) westRecvAck(1,biE,bjE) = 1. |
179 |
ENDDO |
180 |
ENDDO |
181 |
|
182 |
C-- Make sure "ack" setting is seen system-wide. |
183 |
C Here strong-ordering is not an issue but we want to make |
184 |
C sure that processes that might spin on the above Ack settings |
185 |
C will see the setting. |
186 |
C ** NOTE ** On some machines we wont spin on the Ack setting |
187 |
C ( particularly the T90 ), instead we will use s system barrier. |
188 |
C On the T90 the system barrier is very fast and switches out the |
189 |
C thread while it waits. On most machines the system barrier |
190 |
C is much too slow and if we own the machine and have one thread |
191 |
C per process preemption is not a problem. |
192 |
IF ( exchNeedsMemSync ) CALL MEMSYNC |
193 |
|
194 |
RETURN |
195 |
END |
196 |
|
197 |
SUBROUTINE EXCH_RL_SEND_PUT_VEC_Y( arrayN, arrayS, |
198 |
I myd1, myThid ) |
199 |
C /==========================================================\ |
200 |
C | SUBROUTINE EXCH_RL_SEND_PUT_Y | |
201 |
C | o "Send" or "put" Y edges for RL array. | |
202 |
C |==========================================================| |
203 |
C | Routine that invokes actual message passing send or | |
204 |
C | direct "put" of data to update X faces of an XY[R] array.| |
205 |
C \==========================================================/ |
206 |
IMPLICIT NONE |
207 |
|
208 |
C == Global variables == |
209 |
#include "SIZE.h" |
210 |
#include "EEPARAMS.h" |
211 |
#include "EESUPPORT.h" |
212 |
#include "FLT.h" |
213 |
#include "EXCH.h" |
214 |
C == Routine arguments == |
215 |
C arrayN - Array to be exchanged. |
216 |
C arrayS |
217 |
C myd1 - sizes. |
218 |
C myd2 |
219 |
C myThid - Thread number of this instance of S/R EXCH... |
220 |
INTEGER myd1 |
221 |
INTEGER myd2 |
222 |
_RL arrayN(myd1, nSx, nSy), arrayS(myd1, nSx, nSy) |
223 |
INTEGER myThid |
224 |
CEndOfInterface |
225 |
|
226 |
C == Local variables == |
227 |
C I, J - Loop counters and extents |
228 |
C bi, bj |
229 |
C biN, bjN - North tile indices |
230 |
C biS, bjS - South tile indices |
231 |
C theProc, theTag, theType, - Variables used in message building |
232 |
C theSize |
233 |
C westCommMode - Working variables holding type |
234 |
C eastCommMode of communication a particular |
235 |
C tile face uses. |
236 |
INTEGER I, J |
237 |
INTEGER bi, bj, biS, bjS, biN, bjN |
238 |
INTEGER southCommMode |
239 |
INTEGER northCommMode |
240 |
|
241 |
#ifdef ALLOW_USE_MPI |
242 |
INTEGER theProc, theTag, theType, theSize, mpiRc |
243 |
#endif |
244 |
C-- Write data to exchange buffer |
245 |
C Various actions are possible depending on the communication mode |
246 |
C as follows: |
247 |
C Mode Action |
248 |
C -------- --------------------------- |
249 |
C COMM_NONE Do nothing |
250 |
C |
251 |
C COMM_MSG Message passing communication ( e.g. MPI ) |
252 |
C Fill west send buffer from this tile. |
253 |
C Send data with tag identifying tile and direction. |
254 |
C Fill east send buffer from this tile. |
255 |
C Send data with tag identifying tile and direction. |
256 |
C |
257 |
C COMM_PUT "Put" communication ( UMP_, shmemput, etc... ) |
258 |
C Fill east receive buffer of south-neighbor tile |
259 |
C Fill west receive buffer of north-neighbor tile |
260 |
C Sync. memory |
261 |
C Write data-ready Ack for east edge of south-neighbor |
262 |
C tile |
263 |
C Write data-ready Ack for west edge of north-neighbor |
264 |
C tile |
265 |
C Sync. memory |
266 |
C |
267 |
DO bj=myByLo(myThid),myByHi(myThid) |
268 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
269 |
|
270 |
southCommMode = _tileCommModeS(bi,bj) |
271 |
northCommMode = _tileCommModeN(bi,bj) |
272 |
biN = _tileBiN(bi,bj) |
273 |
bjN = _tileBjN(bi,bj) |
274 |
biS = _tileBiS(bi,bj) |
275 |
bjS = _tileBjS(bi,bj) |
276 |
|
277 |
C o Send or Put south edge |
278 |
IF ( southCommMode .EQ. COMM_MSG ) THEN |
279 |
C Send the data |
280 |
#ifdef ALLOW_USE_MPI |
281 |
#ifndef ALWAYS_USE_MPI |
282 |
IF ( usingMPI ) THEN |
283 |
#endif |
284 |
theProc = tilePidS(bi,bj) |
285 |
theTag = _tileTagSendS(bi,bj) |
286 |
theSize = myd1 |
287 |
theType = MPI_DOUBLE_PRECISION |
288 |
c exchVReqsY(1,bi,bj) = exchVReqsY(1,bi,bj)+1 |
289 |
exchNReqsY(1,bi,bj) = exchNReqsY(1,bi,bj)+1 |
290 |
CALL MPI_Isend(arrayS(1,bi,bj), theSize, theType, |
291 |
& theProc, theTag, MPI_COMM_MODEL, |
292 |
& exchReqIdY(exchNReqsY(1,bi,bj),1,bi,bj), mpiRc) |
293 |
c & exchReqVIdY(exchVReqsY(1,bi,bj),1,bi,bj), mpiRc) |
294 |
#ifndef ALWAYS_USE_MPI |
295 |
ENDIF |
296 |
#endif |
297 |
#endif /* ALLOW_USE_MPI */ |
298 |
northRecvAck(1,biS,bjS) = 1. |
299 |
ELSEIF ( southCommMode .EQ. COMM_PUT ) THEN |
300 |
DO I=1,myd1 |
301 |
arrayN(I,biS,bjS) = arrayS(I,bi,bj) |
302 |
ENDDO |
303 |
ELSEIF ( southCommMode .NE. COMM_NONE |
304 |
& .AND. southCommMode .NE. COMM_GET ) THEN |
305 |
STOP ' S/R EXCH: Invalid commS mode.' |
306 |
ENDIF |
307 |
|
308 |
C o Send or Put north edge |
309 |
IF ( northCommMode .EQ. COMM_MSG ) THEN |
310 |
C Send the data |
311 |
#ifdef ALLOW_USE_MPI |
312 |
#ifndef ALWAYS_USE_MPI |
313 |
IF ( usingMPI ) THEN |
314 |
#endif |
315 |
theProc = tilePidN(bi,bj) |
316 |
theTag = _tileTagSendN(bi,bj) |
317 |
theSize = myd1 |
318 |
theType = MPI_DOUBLE_PRECISION |
319 |
c exchVReqsY(1,bi,bj) = exchVReqsY(1,bi,bj)+1 |
320 |
exchNReqsY(1,bi,bj) = exchNReqsY(1,bi,bj)+1 |
321 |
CALL MPI_Isend(arrayN(1,bi,bj), theSize, theType, |
322 |
& theProc, theTag, MPI_COMM_MODEL, |
323 |
& exchReqIdY(exchNReqsY(1,bi,bj),1,bi,bj), mpiRc) |
324 |
c & exchReqVIdY(exchVReqsY(1,bi,bj),1,bi,bj), mpiRc) |
325 |
#ifndef ALWAYS_USE_MPI |
326 |
ENDIF |
327 |
#endif |
328 |
#endif /* ALLOW_USE_MPI */ |
329 |
southRecvAck(1,biN,bjN) = 1. |
330 |
ELSEIF ( northCommMode .EQ. COMM_PUT ) THEN |
331 |
DO I=1,myd1 |
332 |
arrayS(I,biN,bjN) = arrayN(I,bi,bj) |
333 |
ENDDO |
334 |
ELSEIF ( northCommMode .NE. COMM_NONE |
335 |
& .AND. northCommMode .NE. COMM_GET ) THEN |
336 |
STOP ' S/R EXCH: Invalid commN mode.' |
337 |
ENDIF |
338 |
|
339 |
ENDDO |
340 |
ENDDO |
341 |
|
342 |
C-- Signal completetion ( making sure system-wide memory state is |
343 |
C-- consistent ). |
344 |
|
345 |
C ** NOTE ** We are relying on being able to produce strong-ordered |
346 |
C memory semantics here. In other words we assume that there is a |
347 |
C mechanism which can ensure that by the time the Ack is seen the |
348 |
C overlap region data that will be exchanged is up to date. |
349 |
IF ( exchNeedsMemSync ) CALL MEMSYNC |
350 |
|
351 |
DO bj=myByLo(myThid),myByHi(myThid) |
352 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
353 |
biN = _tileBiN(bi,bj) |
354 |
bjN = _tileBjN(bi,bj) |
355 |
biS = _tileBiS(bi,bj) |
356 |
bjS = _tileBjS(bi,bj) |
357 |
southCommMode = _tileCommModeE(bi,bj) |
358 |
northCommMode = _tileCommModeN(bi,bj) |
359 |
IF ( southCommMode .EQ. COMM_PUT ) northRecvAck(1,biS,bjS) = 1. |
360 |
IF ( northCommMode .EQ. COMM_PUT ) southRecvAck(1,biN,bjN) = 1. |
361 |
IF ( southCommMode .EQ. COMM_GET ) northRecvAck(1,biS,bjS) = 1. |
362 |
IF ( northCommMode .EQ. COMM_GET ) southRecvAck(1,biN,bjN) = 1. |
363 |
ENDDO |
364 |
ENDDO |
365 |
|
366 |
C-- Make sure "ack" setting is seen system-wide. |
367 |
C Here strong-ordering is not an issue but we want to make |
368 |
C sure that processes that might spin on the above Ack settings |
369 |
C will see the setting. |
370 |
C ** NOTE ** On some machines we wont spin on the Ack setting |
371 |
C ( particularly the T90 ), instead we will use s system barrier. |
372 |
C On the T90 the system barrier is very fast and switches out the |
373 |
C thread while it waits. On most machines the system barrier |
374 |
C is much too slow and if we own the machine and have one thread |
375 |
C per process preemption is not a problem. |
376 |
IF ( exchNeedsMemSync ) CALL MEMSYNC |
377 |
|
378 |
RETURN |
379 |
END |
380 |
|
381 |
#else |
382 |
SUBROUTINE EXCH_RL_SEND_PUT_VEC_X( myThid ) |
383 |
INTEGER myThid |
384 |
return |
385 |
end |
386 |
SUBROUTINE EXCH_RL_SEND_PUT_VEC_Y( myThid ) |
387 |
INTEGER myThid |
388 |
return |
389 |
end |
390 |
#endif |