1 |
jmc |
1.4 |
C $Header: /u/gcmpack/MITgcm/eesupp/src/exch_rx.template,v 1.3 2001/09/21 03:55:50 cnh Exp $ |
2 |
cnh |
1.3 |
C $Name: $ |
3 |
adcroft |
1.2 |
|
4 |
|
|
#include "CPP_EEOPTIONS.h" |
5 |
|
|
|
6 |
cnh |
1.3 |
CBOP |
7 |
|
|
|
8 |
|
|
C !ROUTINE: EXCH_RX |
9 |
|
|
|
10 |
|
|
C !INTERFACE: |
11 |
adcroft |
1.2 |
SUBROUTINE EXCH_RX( |
12 |
|
|
U array, |
13 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
14 |
|
|
I exchWidthX, exchWidthY, |
15 |
|
|
I simulationMode, cornerMode, myThid ) |
16 |
|
|
IMPLICIT NONE |
17 |
|
|
|
18 |
cnh |
1.3 |
C !DESCRIPTION: |
19 |
|
|
C *==========================================================* |
20 |
|
|
C | SUBROUTINE EXCH_RX |
21 |
|
|
C | o Control edge exchanges for RX array. |
22 |
|
|
C *==========================================================* |
23 |
|
|
C | |
24 |
|
|
C | Controlling routine for exchange of XY edges of an array |
25 |
|
|
C | distributed in X and Y. The routine interfaces to |
26 |
|
|
C | communication routines that can use messages passing |
27 |
|
|
C | exchanges, put type exchanges or get type exchanges. |
28 |
|
|
C | This allows anything from MPI to raw memory channel to |
29 |
|
|
C | memmap segments to be used as a inter-process and/or |
30 |
|
|
C | inter-thread communiation and synchronisation |
31 |
|
|
C | mechanism. |
32 |
|
|
C | Notes -- |
33 |
|
|
C | 1. Some low-level mechanisms such as raw memory-channel |
34 |
|
|
C | or SGI/CRAY shmem put do not have direct Fortran bindings |
35 |
|
|
C | and are invoked through C stub routines. |
36 |
|
|
C | 2. Although this routine is fairly general but it does |
37 |
|
|
C | require nSx and nSy are the same for all innvocations. |
38 |
|
|
C | There are many common data structures ( myByLo, |
39 |
|
|
C | westCommunicationMode, mpiIdW etc... ) tied in with |
40 |
|
|
C | (nSx,nSy). To support arbitray nSx and nSy would require |
41 |
|
|
C | general forms of these. |
42 |
|
|
C | 3. RX arrays are used to generate code for both _RL and |
43 |
|
|
C | _RS forms. |
44 |
|
|
C *==========================================================* |
45 |
|
|
|
46 |
|
|
C !USES: |
47 |
adcroft |
1.2 |
C == Global data == |
48 |
|
|
#include "SIZE.h" |
49 |
|
|
#include "EEPARAMS.h" |
50 |
|
|
#include "EESUPPORT.h" |
51 |
|
|
#include "EXCH.h" |
52 |
|
|
|
53 |
cnh |
1.3 |
C !INPUT/OUTPUT PARAMETERS: |
54 |
adcroft |
1.2 |
C == Routine arguments == |
55 |
cnh |
1.3 |
C array :: Array with edges to exchange. |
56 |
|
|
C myOLw :: West, East, North and South overlap region sizes. |
57 |
adcroft |
1.2 |
C myOLe |
58 |
|
|
C myOLn |
59 |
|
|
C myOLs |
60 |
cnh |
1.3 |
C exchWidthX :: Width of data region exchanged in X. |
61 |
|
|
C exchWidthY :: Width of data region exchanged in Y. |
62 |
|
|
C Note -- |
63 |
|
|
C 1. In theory one could have a send width and |
64 |
|
|
C a receive width for each face of each tile. The only |
65 |
|
|
C restriction woul be that the send width of one |
66 |
|
|
C face should equal the receive width of the sent to |
67 |
|
|
C tile face. Dont know if this would be useful. I |
68 |
|
|
C have left it out for now as it requires additional |
69 |
|
|
C bookeeping. |
70 |
|
|
C simulationMode :: Forward or reverse mode exchange ( provides |
71 |
|
|
C support for adjoint integration of code. ) |
72 |
|
|
C cornerMode :: Flag indicating whether corner updates are |
73 |
|
|
C needed. |
74 |
|
|
C myThid :: Thread number of this instance of S/R EXCH... |
75 |
adcroft |
1.2 |
INTEGER myOLw |
76 |
|
|
INTEGER myOLe |
77 |
|
|
INTEGER myOLs |
78 |
|
|
INTEGER myOLn |
79 |
|
|
INTEGER myNz |
80 |
|
|
INTEGER exchWidthX |
81 |
|
|
INTEGER exchWidthY |
82 |
|
|
INTEGER simulationMode |
83 |
|
|
INTEGER cornerMode |
84 |
|
|
INTEGER myThid |
85 |
|
|
_RX array(1-myOLw:sNx+myOLe, |
86 |
|
|
& 1-myOLs:sNy+myOLn, |
87 |
|
|
& myNZ, nSx, nSy) |
88 |
|
|
|
89 |
cnh |
1.3 |
C !LOCAL VARIABLES: |
90 |
adcroft |
1.2 |
C == Local variables == |
91 |
cnh |
1.3 |
C theSimulationMode :: Holds working copy of simulation mode |
92 |
|
|
C theCornerMode :: Holds working copy of corner mode |
93 |
|
|
C I,J,K,bi,bj :: Loop counters |
94 |
adcroft |
1.2 |
INTEGER theSimulationMode |
95 |
|
|
INTEGER theCornerMode |
96 |
|
|
INTEGER I,J,K,bi,bj |
97 |
cnh |
1.3 |
CEOP |
98 |
adcroft |
1.2 |
|
99 |
|
|
theSimulationMode = simulationMode |
100 |
|
|
theCornerMode = cornerMode |
101 |
|
|
|
102 |
|
|
C-- Error checks |
103 |
|
|
IF ( exchWidthX .GT. myOLw ) |
104 |
|
|
& STOP ' S/R EXCH_RX: exchWidthX .GT. myOLw' |
105 |
|
|
IF ( exchWidthX .GT. myOLe ) |
106 |
|
|
& STOP ' S/R EXCH_RX: exchWidthX .GT. myOLe' |
107 |
|
|
IF ( exchWidthY .GT. myOLs ) |
108 |
|
|
& STOP ' S/R EXCH_RX: exchWidthY .GT. myOLs' |
109 |
|
|
IF ( exchWidthY .GT. myOLn ) |
110 |
|
|
& STOP ' S/R EXCH_RX: exchWidthY .GT. myOLn' |
111 |
|
|
IF ( myOLw .GT. MAX_OLX_EXCH ) |
112 |
|
|
& STOP ' S/R EXCH_RX: myOLw .GT. MAX_OLX_EXCH' |
113 |
|
|
IF ( myOLe .GT. MAX_OLX_EXCH ) |
114 |
|
|
& STOP ' S/R EXCH_RX: myOLe .GT. MAX_OLX_EXCH' |
115 |
|
|
IF ( myOLn .GT. MAX_OLX_EXCH ) |
116 |
|
|
& STOP ' S/R EXCH_RX: myOLn .GT. MAX_OLY_EXCH' |
117 |
|
|
IF ( myOLs .GT. MAX_OLY_EXCH ) |
118 |
|
|
& STOP ' S/R EXCH_RX: myOLs .GT. MAX_OLY_EXCH' |
119 |
|
|
IF ( myNZ .GT. MAX_NR_EXCH ) |
120 |
|
|
& STOP ' S/R EXCH_RX: myNZ .GT. MAX_NR_EXCH ' |
121 |
|
|
IF ( theSimulationMode .NE. FORWARD_SIMULATION |
122 |
|
|
& .AND. theSimulationMode .NE. REVERSE_SIMULATION |
123 |
|
|
& ) STOP ' S/R EXCH_RX: Unrecognised simulationMode ' |
124 |
|
|
IF ( theCornerMode .NE. EXCH_IGNORE_CORNERS |
125 |
|
|
& .AND. theCornerMode .NE. EXCH_UPDATE_CORNERS |
126 |
|
|
& ) STOP ' S/R EXCH_RX: Unrecognised cornerMode ' |
127 |
|
|
|
128 |
|
|
C-- Cycle edge buffer level |
129 |
|
|
CALL EXCH_CYCLE_EBL( myThid ) |
130 |
|
|
|
131 |
|
|
IF ( theSimulationMode .EQ. FORWARD_SIMULATION ) THEN |
132 |
|
|
C-- "Put" east and west edges. |
133 |
|
|
CALL EXCH_RX_SEND_PUT_X( array, |
134 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
135 |
|
|
I exchWidthX, exchWidthY, |
136 |
|
|
I theSimulationMode, theCornerMode, myThid ) |
137 |
|
|
C-- If corners are important then sync and update east and west edges |
138 |
|
|
C-- before doing north and south exchanges. |
139 |
|
|
IF ( theCornerMode .EQ. EXCH_UPDATE_CORNERS ) THEN |
140 |
|
|
CALL EXCH_RX_RECV_GET_X( array, |
141 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
142 |
|
|
I exchWidthX, exchWidthY, |
143 |
|
|
I theSimulationMode, theCornerMode, myThid ) |
144 |
|
|
ENDIF |
145 |
|
|
C "Put" north and south edges. |
146 |
|
|
CALL EXCH_RX_SEND_PUT_Y( array, |
147 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
148 |
|
|
I exchWidthX, exchWidthY, |
149 |
|
|
I theSimulationMode, theCornerMode, myThid ) |
150 |
|
|
C-- Sync and update north, south (and east, west if corner updating |
151 |
|
|
C-- not active). |
152 |
|
|
IF ( theCornerMode .NE. EXCH_UPDATE_CORNERS ) THEN |
153 |
|
|
CALL EXCH_RX_RECV_GET_X( array, |
154 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
155 |
|
|
I exchWidthX, exchWidthY, |
156 |
|
|
I theSimulationMode, theCornerMode, myThid ) |
157 |
|
|
ENDIF |
158 |
|
|
CALL EXCH_RX_RECV_GET_Y( array, |
159 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
160 |
|
|
I exchWidthX, exchWidthY, |
161 |
|
|
I theSimulationMode, theCornerMode, myThid ) |
162 |
|
|
ENDIF |
163 |
|
|
|
164 |
|
|
IF ( theSimulationMode .EQ. REVERSE_SIMULATION ) THEN |
165 |
|
|
C "Put" north and south edges. |
166 |
|
|
CALL EXCH_RX_SEND_PUT_Y( array, |
167 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
168 |
|
|
I exchWidthX, exchWidthY, |
169 |
|
|
I theSimulationMode, theCornerMode, myThid ) |
170 |
|
|
C-- If corners are important then sync and update east and west edges |
171 |
|
|
C-- before doing north and south exchanges. |
172 |
|
|
IF ( theCornerMode .EQ. EXCH_UPDATE_CORNERS ) THEN |
173 |
|
|
CALL EXCH_RX_RECV_GET_Y( array, |
174 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
175 |
|
|
I exchWidthX, exchWidthY, |
176 |
|
|
I theSimulationMode, theCornerMode, myThid ) |
177 |
|
|
ENDIF |
178 |
|
|
C-- "Put" east and west edges. |
179 |
|
|
CALL EXCH_RX_SEND_PUT_X( array, |
180 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
181 |
|
|
I exchWidthX, exchWidthY, |
182 |
|
|
I theSimulationMode, theCornerMode, myThid ) |
183 |
|
|
C-- Sync and update east, west (and north, south if corner updating |
184 |
|
|
C-- not active). |
185 |
|
|
IF ( theCornerMode .NE. EXCH_UPDATE_CORNERS ) THEN |
186 |
|
|
CALL EXCH_RX_RECV_GET_Y( array, |
187 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
188 |
|
|
I exchWidthX, exchWidthY, |
189 |
|
|
I theSimulationMode, theCornerMode, myThid ) |
190 |
|
|
ENDIF |
191 |
|
|
CALL EXCH_RX_RECV_GET_X( array, |
192 |
|
|
I myOLw, myOLe, myOLs, myOLn, myNz, |
193 |
|
|
I exchWidthX, exchWidthY, |
194 |
|
|
I theSimulationMode, theCornerMode, myThid ) |
195 |
|
|
ENDIF |
196 |
jmc |
1.4 |
C Special case for zonal average model i.e. case where Nx == 1 |
197 |
adcroft |
1.2 |
C In this case a forward mode exchange simply sets array to |
198 |
|
|
C the i=1 value for all i. |
199 |
jmc |
1.4 |
IF ( Nx .EQ. 1 ) THEN |
200 |
adcroft |
1.2 |
DO bj=myByLo(myThid),myByHi(myThid) |
201 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
202 |
|
|
DO K = 1,myNz |
203 |
|
|
DO J = 1-myOLs,sNy+myOLn |
204 |
|
|
DO I = 1-myOLw,sNx+myOLe |
205 |
jmc |
1.4 |
array(I,J,K,bi,bj) = array(1,J,K,bi,bj) |
206 |
|
|
ENDDO |
207 |
|
|
ENDDO |
208 |
|
|
ENDDO |
209 |
|
|
ENDDO |
210 |
|
|
ENDDO |
211 |
|
|
ENDIF |
212 |
|
|
C Special case for X-slice domain i.e. case where Ny == 1 |
213 |
|
|
C In this case a forward mode exchange simply sets array to |
214 |
|
|
C the j=1 value for all j. |
215 |
|
|
IF ( Ny .EQ. 1 ) THEN |
216 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
217 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
218 |
|
|
DO K = 1,myNz |
219 |
|
|
DO J = 1-myOLs,sNy+myOLn |
220 |
|
|
DO I = 1-myOLw,sNx+myOLe |
221 |
|
|
array(I,J,K,bi,bj) = array(I,1,K,bi,bj) |
222 |
adcroft |
1.2 |
ENDDO |
223 |
|
|
ENDDO |
224 |
|
|
ENDDO |
225 |
|
|
ENDDO |
226 |
|
|
ENDDO |
227 |
|
|
ENDIF |
228 |
|
|
|
229 |
|
|
RETURN |
230 |
|
|
END |