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