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