1 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/exch_control.F,v 1.3 1999/05/24 15:17:10 adcroft Exp $ |
2 |
|
3 |
C MITgcmUV Exchange routine |
4 |
C ------------------------- |
5 |
C These routines include support for arrays with different |
6 |
C overlap extents and a mechanism to allow reverse mode |
7 |
C exchanges for adjoint based minimisation experiments. |
8 |
C Differing extents for array overlap regions allows for example |
9 |
C the conjugate gradient solver to be optimised for edge |
10 |
C exchages of width one whilst for Shapiro filtered |
11 |
C atmospheric fileds overlap regions of 8 or more can |
12 |
C be defined. |
13 |
C Another important new feature is a tile by tile definition |
14 |
C of the class of exchange operation used to update the |
15 |
C tile. This provides support for partially tiled regular |
16 |
C domains where land-filled tiles are eliminated. |
17 |
C Communication between tiles |
18 |
C can be based on any of |
19 |
C 1. message passing. |
20 |
C 2. writes to remote memory. |
21 |
C 3. direct reads from remote tiles. |
22 |
C The class of communication utilised is specified on a |
23 |
C tile by tile basis. So that one face of a tile can |
24 |
C exchange via MPI, another via UMP, another via shared |
25 |
C memory and another not at all. The only requirement is that |
26 |
C of symmetry i.e. if one tile sends its data to another tile via |
27 |
C some mechanism the "sent to" tile must receive the data by the |
28 |
C same mechanism. There is no support for multiple communication |
29 |
C channels for a single tile face. |
30 |
C To support this a tile has the following attributes associated |
31 |
C with it: |
32 |
C tileNo - A unique number identifying the tile |
33 |
C tileNoW - tileNo for the tile to my west |
34 |
C tileNoN - tileNo for the tile to my north |
35 |
C tileNoS - tileNo for the tile to my south |
36 |
C tileNoE - tileNo for the tile to my east |
37 |
C tilePid - Process id for this tile |
38 |
C tilePidW - Process id for tile to west |
39 |
C tilePidE - Process id for tile to east |
40 |
C tilePidN - Process id for tile to north |
41 |
C tilePidS - Process id for tile to south |
42 |
C tileCommModeW - Style of communication used to west |
43 |
C tileCommModeE - Style of communication used to east |
44 |
C tileCommModeN - Style of communication used to north |
45 |
C tileCommModeS - Style of communication used to south |
46 |
C tileTagSendW - Tag for identifying send from tiles west |
47 |
C communication "channel". |
48 |
C tileTagSendE - Tag for identifying send from tiles east |
49 |
C communication "channel". |
50 |
C tileTagSendN - Tag for identifying send from tiles north |
51 |
C communication "channel". |
52 |
C tileTagSendS - Tag for identifying send from tiles south |
53 |
C communication "channel". |
54 |
C tileTagRecvW - Tag for identifying send from tiles west |
55 |
C communication "channel". |
56 |
C tileTagRecvE - Tag for identifying send from tiles east |
57 |
C communication "channel". |
58 |
C tileTagRecvN - Tag for identifying send from tiles north |
59 |
C communication "channel". |
60 |
C tileTagRecvS - Tag for identifying send from tiles south |
61 |
C communication "channel". |
62 |
C tileB[ij]W - bi and bj index for tile to west |
63 |
C tileB[ij]E - bi and bj index for tile to east |
64 |
C tileB[ij]N - bi and bj index for tile to north |
65 |
C tileB[ij]S - bi and bj index for tile to south |
66 |
C The code in here although intricate is fairly |
67 |
C straightforward. There are four routines, one |
68 |
C for each of the data patterns we wish to do overlap |
69 |
C updates on - as listed below. Each routine has two |
70 |
C parts. The first part does overlap updates to and from |
71 |
C remote "processes", that is processes who do not truly |
72 |
C share the address space of this process. This part |
73 |
C requires a facility like MPI, CRAY shmem, Memory Channel UMP, |
74 |
C VMMC VIA. In the case of a simple |
75 |
C serial execution nothing happens in this part. |
76 |
C The second part of each routine does the true shared memory |
77 |
C overlap copying i.e. copying from one part of array phi |
78 |
C to another part. This part is always active, in the case |
79 |
C of a single threaded messaging code, however, this part |
80 |
C will not do any copies as all edges will be flagged as using |
81 |
C for example MPI. |
82 |
C |
83 |
|
84 |
|
85 |
CStartOfInterface |
86 |
SUBROUTINE EXCH_RL( |
87 |
U array, |
88 |
I myOLw, myOLe, myOLn, myOLs, myNz, |
89 |
I exchWidthX, exchWidthY, |
90 |
I simulationMode, cornerMode, myThid ) |
91 |
C /==========================================================\ |
92 |
C | SUBROUTINE EXCH_RL | |
93 |
C | o Control edge exchanges for RL array. | |
94 |
C |==========================================================| |
95 |
C | | |
96 |
C | Controlling routine for exchange of XY edges of an array | |
97 |
C | distributed in X and Y. The routine interfaces to | |
98 |
C | communication routines that can use messages passing | |
99 |
C | exchanges, put type exchanges or get type exchanges. | |
100 |
C | This allows anything from MPI to raw memory channel to | |
101 |
C | memmap segments to be used as a inter-process and/or | |
102 |
C | inter-thread communiation and synchronisation | |
103 |
C | mechanism. | |
104 |
C | Notes -- | |
105 |
C | 1. Some low-level mechanisms such as raw memory-channel | |
106 |
C | or SGI/CRAY shmem put do not have direct Fortran bindings| |
107 |
C | and are invoked through C stub routines. | |
108 |
C | 2. Although this routine is fairly general but it does | |
109 |
C | require nSx and nSy are the same for all innvocations. | |
110 |
C | There are many common data structures ( myByLo, | |
111 |
C | westCommunicationMode, mpiIdW etc... ) tied in with | |
112 |
C | (nSx,nSy). To support arbitray nSx and nSy would require | |
113 |
C | general forms of these. | |
114 |
C | | |
115 |
C \==========================================================/ |
116 |
IMPLICIT NONE |
117 |
|
118 |
C == Global data == |
119 |
#include "SIZE.h" |
120 |
#include "EEPARAMS.h" |
121 |
#include "EESUPPORT.h" |
122 |
#include "EXCH.h" |
123 |
|
124 |
C == Routine arguments == |
125 |
C array - Array with edges to exchange. |
126 |
C myOLw - West, East, North and South overlap region sizes. |
127 |
C myOLe |
128 |
C myOLn |
129 |
C myOLs |
130 |
C exchWidthX - Width of data region exchanged in X. |
131 |
C exchWidthY - Width of data region exchanged in Y. |
132 |
C Note -- |
133 |
C 1. In theory one could have a send width and |
134 |
C a receive width for each face of each tile. The only |
135 |
C restriction woul be that the send width of one |
136 |
C face should equal the receive width of the sent to |
137 |
C tile face. Dont know if this would be useful. I |
138 |
C have left it out for now as it requires additional |
139 |
C bookeeping. |
140 |
C simulationMode - Forward or reverse mode exchange ( provides |
141 |
C support for adjoint integration of code. ) |
142 |
C cornerMode - Flag indicating whether corner updates are |
143 |
C needed. |
144 |
C myThid - Thread number of this instance of S/R EXCH... |
145 |
INTEGER myOLw |
146 |
INTEGER myOLe |
147 |
INTEGER myOLs |
148 |
INTEGER myOLn |
149 |
INTEGER myNz |
150 |
INTEGER exchWidthX |
151 |
INTEGER exchWidthY |
152 |
INTEGER simulationMode |
153 |
INTEGER cornerMode |
154 |
INTEGER myThid |
155 |
_RL array(1-myOLw:sNx+myOLe, |
156 |
& 1-myOLs:sNy+myOLn, |
157 |
& myNZ, nSx, nSy) |
158 |
CEndOfInterface |
159 |
|
160 |
C == Local variables == |
161 |
C theSimulationMode - Holds working copy of simulation mode |
162 |
C theCornerMode - Holds working copy of corner mode |
163 |
INTEGER theSimulationMode |
164 |
INTEGER theCornerMode |
165 |
INTEGER I,J,K,bi,bj |
166 |
|
167 |
theSimulationMode = simulationMode |
168 |
theCornerMode = cornerMode |
169 |
|
170 |
C-- Error checks |
171 |
IF ( exchWidthX .GT. myOLw ) |
172 |
& STOP ' S/R EXCH_RL: exchWidthX .GT. myOLw' |
173 |
IF ( exchWidthX .GT. myOLe ) |
174 |
& STOP ' S/R EXCH_RL: exchWidthX .GT. myOLe' |
175 |
IF ( exchWidthY .GT. myOLs ) |
176 |
& STOP ' S/R EXCH_RL: exchWidthY .GT. myOLs' |
177 |
IF ( exchWidthY .GT. myOLn ) |
178 |
& STOP ' S/R EXCH_RL: exchWidthY .GT. myOLn' |
179 |
IF ( myOLw .GT. MAX_OLX_EXCH ) |
180 |
& STOP ' S/R EXCH_RL: myOLw .GT. MAX_OLX_EXCH' |
181 |
IF ( myOLe .GT. MAX_OLX_EXCH ) |
182 |
& STOP ' S/R EXCH_RL: myOLe .GT. MAX_OLX_EXCH' |
183 |
IF ( myOLn .GT. MAX_OLX_EXCH ) |
184 |
& STOP ' S/R EXCH_RL: myOLn .GT. MAX_OLY_EXCH' |
185 |
IF ( myOLs .GT. MAX_OLY_EXCH ) |
186 |
& STOP ' S/R EXCH_RL: myOLs .GT. MAX_OLY_EXCH' |
187 |
IF ( myNZ .GT. MAX_NR_EXCH ) |
188 |
& STOP ' S/R EXCH_RL: myNZ .GT. MAX_NR_EXCH ' |
189 |
IF ( theSimulationMode .NE. FORWARD_SIMULATION |
190 |
& .AND. theSimulationMode .NE. REVERSE_SIMULATION |
191 |
& ) STOP ' S/R EXCH_RL: Unrecognised simulationMode ' |
192 |
IF ( theCornerMode .NE. EXCH_IGNORE_CORNERS |
193 |
& .AND. theCornerMode .NE. EXCH_UPDATE_CORNERS |
194 |
& ) STOP ' S/R EXCH_RL: Unrecognised cornerMode ' |
195 |
|
196 |
C-- Cycle edge buffer level |
197 |
CALL EXCH_CYCLE_EBL( myThid ) |
198 |
|
199 |
C-- "Put" east and west edges. |
200 |
CALL EXCH_RL_SEND_PUT_X( array, |
201 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
202 |
I exchWidthX, exchWidthY, |
203 |
I theSimulationMode, theCornerMode, myThid ) |
204 |
|
205 |
C-- If corners are important then sync and update east and west edges |
206 |
C-- before doing north and south exchanges. |
207 |
IF ( theCornerMode .EQ. EXCH_UPDATE_CORNERS ) THEN |
208 |
CALL EXCH_RL_RECV_GET_X( array, |
209 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
210 |
I exchWidthX, exchWidthY, |
211 |
I theSimulationMode, theCornerMode, myThid ) |
212 |
ENDIF |
213 |
|
214 |
C "Put" north and south edges. |
215 |
CALL EXCH_RL_SEND_PUT_Y( array, |
216 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
217 |
I exchWidthX, exchWidthY, |
218 |
I theSimulationMode, theCornerMode, myThid ) |
219 |
|
220 |
|
221 |
C-- Sync and update north, south (and east, west if corner updating |
222 |
C-- not active). |
223 |
IF ( theCornerMode .NE. EXCH_UPDATE_CORNERS ) THEN |
224 |
CALL EXCH_RL_RECV_GET_X( array, |
225 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
226 |
I exchWidthX, exchWidthY, |
227 |
I theSimulationMode, theCornerMode, myThid ) |
228 |
ENDIF |
229 |
CALL EXCH_RL_RECV_GET_Y( array, |
230 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
231 |
I exchWidthX, exchWidthY, |
232 |
I theSimulationMode, theCornerMode, myThid ) |
233 |
C Special case for zonal average model i.e. case where sNx == 1 |
234 |
C In this case a forward mode exchange simply sets array to |
235 |
C the i=1 value for all i. |
236 |
IF ( sNx .EQ. 1 ) THEN |
237 |
DO bj=myByLo(myThid),myByHi(myThid) |
238 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
239 |
DO K = 1,myNz |
240 |
DO J = 1-myOLs,sNy+myOLn |
241 |
DO I = 1-myOLw,sNx+myOLe |
242 |
array(I,J,K,bi,bj) = array(sNx,J,K,bi,bj) |
243 |
ENDDO |
244 |
ENDDO |
245 |
ENDDO |
246 |
ENDDO |
247 |
ENDDO |
248 |
ENDIF |
249 |
|
250 |
RETURN |
251 |
END |
252 |
|
253 |
CStartOfInterface |
254 |
SUBROUTINE EXCH_RS( |
255 |
U array, |
256 |
I myOLw, myOLe, myOLn, myOLs, myNz, |
257 |
I exchWidthX, exchWidthY, |
258 |
I simulationMode, cornerMode, myThid ) |
259 |
C /==========================================================\ |
260 |
C | SUBROUTINE EXCH_RS | |
261 |
C | o Control edge exchanges for RS array. | |
262 |
C |==========================================================| |
263 |
C | | |
264 |
C | Controlling routine for exchange of XY edges of an array | |
265 |
C | distributed in X and Y. The routine interfaces to | |
266 |
C | communication routines that can use messages passing | |
267 |
C | exchanges, put type exchanges or get type exchanges. | |
268 |
C | This allows anything from MPI to raw memory channel to | |
269 |
C | memmap segments to be used as a inter-process and/or | |
270 |
C | inter-thread communiation and synchronisation | |
271 |
C | mechanism. | |
272 |
C | Notes -- | |
273 |
C | 1. Some low-level mechanisms such as raw memory-channel | |
274 |
C | or SGI/CRAY shmem put do not have direct Fortran bindings| |
275 |
C | and are invoked through C stub routines. | |
276 |
C | 2. Although this routine is fairly general but it does | |
277 |
C | require nSx and nSy are the same for all innvocations. | |
278 |
C | There are many common data structures ( myByLo, | |
279 |
C | westCommunicationMode, mpiIdW etc... ) tied in with | |
280 |
C | (nSx,nSy). To support arbitray nSx and nSy would require | |
281 |
C | general forms of these. | |
282 |
C | | |
283 |
C \==========================================================/ |
284 |
IMPLICIT NONE |
285 |
|
286 |
C == Global data == |
287 |
#include "SIZE.h" |
288 |
#include "EEPARAMS.h" |
289 |
#include "EESUPPORT.h" |
290 |
#include "EXCH.h" |
291 |
|
292 |
C == Routine arguments == |
293 |
C array - Array with edges to exchange. |
294 |
C myOLw - West, East, North and South overlap region sizes. |
295 |
C myOLe |
296 |
C myOLn |
297 |
C myOLs |
298 |
C exchWidthX - Width of data region exchanged in X. |
299 |
C exchWidthY - Width of data region exchanged in Y. |
300 |
C Note -- |
301 |
C 1. In theory one could have a send width and |
302 |
C a receive width for each face of each tile. The only |
303 |
C restriction woul be that the send width of one |
304 |
C face should equal the receive width of the sent to |
305 |
C tile face. Dont know if this would be useful. I |
306 |
C have left it out for now as it requires additional |
307 |
C bookeeping. |
308 |
C simulationMode - Forward or reverse mode exchange ( provides |
309 |
C support for adjoint integration of code. ) |
310 |
C cornerMode - Flag indicating whether corner updates are |
311 |
C needed. |
312 |
C myThid - Thread number of this instance of S/R EXCH... |
313 |
INTEGER myOLw |
314 |
INTEGER myOLe |
315 |
INTEGER myOLs |
316 |
INTEGER myOLn |
317 |
INTEGER myNz |
318 |
INTEGER exchWidthX |
319 |
INTEGER exchWidthY |
320 |
INTEGER simulationMode |
321 |
INTEGER cornerMode |
322 |
INTEGER myThid |
323 |
_RS array(1-myOLw:sNx+myOLe, |
324 |
& 1-myOLs:sNy+myOLn, |
325 |
& myNZ, nSx, nSy) |
326 |
CEndOfInterface |
327 |
|
328 |
C == Local variables == |
329 |
C theSimulationMode - Holds working copy of simulation mode |
330 |
C theCornerMode - Holds working copy of corner mode |
331 |
INTEGER theSimulationMode |
332 |
INTEGER theCornerMode |
333 |
INTEGER I,J,K,bi,bj |
334 |
|
335 |
theSimulationMode = simulationMode |
336 |
theCornerMode = cornerMode |
337 |
|
338 |
C-- Error checks |
339 |
IF ( exchWidthX .GT. myOLw ) |
340 |
& STOP ' S/R EXCH_RS: exchWidthX .GT. myOLw' |
341 |
IF ( exchWidthX .GT. myOLe ) |
342 |
& STOP ' S/R EXCH_RS: exchWidthX .GT. myOLe' |
343 |
IF ( exchWidthY .GT. myOLs ) |
344 |
& STOP ' S/R EXCH_RS: exchWidthY .GT. myOLs' |
345 |
IF ( exchWidthY .GT. myOLn ) |
346 |
& STOP ' S/R EXCH_RS: exchWidthY .GT. myOLn' |
347 |
IF ( myOLw .GT. MAX_OLX_EXCH ) |
348 |
& STOP ' S/R EXCH_RS: myOLw .GT. MAX_OLX_EXCH' |
349 |
IF ( myOLe .GT. MAX_OLX_EXCH ) |
350 |
& STOP ' S/R EXCH_RS: myOLe .GT. MAX_OLX_EXCH' |
351 |
IF ( myOLn .GT. MAX_OLX_EXCH ) |
352 |
& STOP ' S/R EXCH_RS: myOLn .GT. MAX_OLY_EXCH' |
353 |
IF ( myOLs .GT. MAX_OLY_EXCH ) |
354 |
& STOP ' S/R EXCH_RS: myOLs .GT. MAX_OLY_EXCH' |
355 |
IF ( myNZ .GT. MAX_NR_EXCH ) |
356 |
& STOP ' S/R EXCH_RS: myNZ .GT. MAX_NR_EXCH ' |
357 |
IF ( theSimulationMode .NE. FORWARD_SIMULATION |
358 |
& .AND. theSimulationMode .NE. REVERSE_SIMULATION |
359 |
& ) STOP ' S/R EXCH_RS: Unrecognised simulationMode ' |
360 |
IF ( theCornerMode .NE. EXCH_IGNORE_CORNERS |
361 |
& .AND. theCornerMode .NE. EXCH_UPDATE_CORNERS |
362 |
& ) STOP ' S/R EXCH_RS: Unrecognised cornerMode ' |
363 |
|
364 |
C-- Cycle edge buffer level |
365 |
CALL EXCH_CYCLE_EBL( myThid ) |
366 |
|
367 |
IF ( theSimulationMode .EQ. FORWARD_SIMULATION ) THEN |
368 |
C-- "Put" east and west edges. |
369 |
CALL EXCH_RS_SEND_PUT_X( array, |
370 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
371 |
I exchWidthX, exchWidthY, |
372 |
I theSimulationMode, theCornerMode, myThid ) |
373 |
C-- If corners are important then sync and update east and west edges |
374 |
C-- before doing north and south exchanges. |
375 |
IF ( theCornerMode .EQ. EXCH_UPDATE_CORNERS ) THEN |
376 |
CALL EXCH_RS_RECV_GET_X( array, |
377 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
378 |
I exchWidthX, exchWidthY, |
379 |
I theSimulationMode, theCornerMode, myThid ) |
380 |
ENDIF |
381 |
C "Put" north and south edges. |
382 |
CALL EXCH_RS_SEND_PUT_Y( array, |
383 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
384 |
I exchWidthX, exchWidthY, |
385 |
I theSimulationMode, theCornerMode, myThid ) |
386 |
C-- Sync and update north, south (and east, west if corner updating |
387 |
C-- not active). |
388 |
IF ( theCornerMode .NE. EXCH_UPDATE_CORNERS ) THEN |
389 |
CALL EXCH_RS_RECV_GET_X( array, |
390 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
391 |
I exchWidthX, exchWidthY, |
392 |
I theSimulationMode, theCornerMode, myThid ) |
393 |
ENDIF |
394 |
CALL EXCH_RS_RECV_GET_Y( array, |
395 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
396 |
I exchWidthX, exchWidthY, |
397 |
I theSimulationMode, theCornerMode, myThid ) |
398 |
ENDIF |
399 |
|
400 |
IF ( theSimulationMode .EQ. REVERSE_SIMULATION ) THEN |
401 |
C "Put" north and south edges. |
402 |
CALL EXCH_RS_SEND_PUT_Y( array, |
403 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
404 |
I exchWidthX, exchWidthY, |
405 |
I theSimulationMode, theCornerMode, myThid ) |
406 |
C-- If corners are important then sync and update east and west edges |
407 |
C-- before doing north and south exchanges. |
408 |
IF ( theCornerMode .EQ. EXCH_UPDATE_CORNERS ) THEN |
409 |
CALL EXCH_RS_RECV_GET_Y( array, |
410 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
411 |
I exchWidthX, exchWidthY, |
412 |
I theSimulationMode, theCornerMode, myThid ) |
413 |
ENDIF |
414 |
C-- "Put" east and west edges. |
415 |
CALL EXCH_RS_SEND_PUT_X( array, |
416 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
417 |
I exchWidthX, exchWidthY, |
418 |
I theSimulationMode, theCornerMode, myThid ) |
419 |
C-- Sync and update east, west (and north, south if corner updating |
420 |
C-- not active). |
421 |
IF ( theCornerMode .NE. EXCH_UPDATE_CORNERS ) THEN |
422 |
CALL EXCH_RS_RECV_GET_Y( array, |
423 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
424 |
I exchWidthX, exchWidthY, |
425 |
I theSimulationMode, theCornerMode, myThid ) |
426 |
ENDIF |
427 |
CALL EXCH_RS_RECV_GET_X( array, |
428 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
429 |
I exchWidthX, exchWidthY, |
430 |
I theSimulationMode, theCornerMode, myThid ) |
431 |
ENDIF |
432 |
C Special case for zonal average model i.e. case where sNx == 1 |
433 |
C In this case a forward mode exchange simply sets array to |
434 |
C the i=1 value for all i. |
435 |
IF ( sNx .EQ. 1 ) THEN |
436 |
DO bj=myByLo(myThid),myByHi(myThid) |
437 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
438 |
DO K = 1,myNz |
439 |
DO J = 1-myOLs,sNy+myOLn |
440 |
DO I = 1-myOLw,sNx+myOLe |
441 |
array(I,J,K,bi,bj) = array(sNx,J,K,bi,bj) |
442 |
ENDDO |
443 |
ENDDO |
444 |
ENDDO |
445 |
ENDDO |
446 |
ENDDO |
447 |
ENDIF |
448 |
|
449 |
RETURN |
450 |
END |