1 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/exch_uv_rx_cube.template,v 1.2 2001/05/29 14:01:36 adcroft Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CPP_EEOPTIONS.h" |
5 |
|
6 |
CBOP |
7 |
C !ROUTINE: EXCH_UV_RX_CUBE |
8 |
|
9 |
C !INTERFACE: |
10 |
SUBROUTINE EXCH_UV_RX_CUBE( |
11 |
U Uarray,Varray, withSigns, |
12 |
I myOLw, myOLe, myOLn, myOLs, myNz, |
13 |
I exchWidthX, exchWidthY, |
14 |
I simulationMode, cornerMode, myThid ) |
15 |
IMPLICIT NONE |
16 |
|
17 |
C !DESCRIPTION: |
18 |
C *==========================================================* |
19 |
C | SUBROUTINE EXCH_UV_RX_CUBE |
20 |
C | o Control edge exchanges for RX array for CS config. |
21 |
C *==========================================================* |
22 |
C | |
23 |
C | Controlling routine for exchange of XY edges of an array |
24 |
C | distributed in X and Y. The routine interfaces to |
25 |
C | communication routines that can use messages passing |
26 |
C | exchanges, put type exchanges or get type exchanges. |
27 |
C | This allows anything from MPI to raw memory channel to |
28 |
C | memmap segments to be used as a inter-process and/or |
29 |
C | inter-thread communiation and synchronisation |
30 |
C | mechanism. |
31 |
C | Notes -- |
32 |
C | 1. Some low-level mechanisms such as raw memory-channel |
33 |
C | or SGI/CRAY shmem put do not have direct Fortran bindings |
34 |
C | and are invoked through C stub routines. |
35 |
C | 2. Although this routine is fairly general but it does |
36 |
C | require nSx and nSy are the same for all innvocations. |
37 |
C | There are many common data structures ( myByLo, |
38 |
C | westCommunicationMode, mpiIdW etc... ) tied in with |
39 |
C | (nSx,nSy). To support arbitray nSx and nSy would require |
40 |
C | general forms of these. |
41 |
C | 3. Exchanges on the cube of vector quantities need to be |
42 |
C | paired to allow rotations and sign reversal to be applied |
43 |
C | consistently between vector components as they rotate. |
44 |
C | |
45 |
C *==========================================================* |
46 |
|
47 |
C !USES: |
48 |
C == Global data == |
49 |
#include "SIZE.h" |
50 |
#include "EEPARAMS.h" |
51 |
#include "EESUPPORT.h" |
52 |
#include "EXCH.h" |
53 |
|
54 |
C !INPUT/OUTPUT PARAMETERS: |
55 |
C == Routine arguments == |
56 |
C Uarray :: (u-type) Array with edges to exchange. |
57 |
C Varray :: (v-type) Array with edges to exchange. |
58 |
C withSigns :: Uarray,Varray are vector components. |
59 |
C myOLw :: West, East, North and South overlap region sizes. |
60 |
C myOLe |
61 |
C myOLn |
62 |
C myOLs |
63 |
C exchWidthX :: Width of data region exchanged in X. |
64 |
C exchWidthY :: Width of data region exchanged in Y. |
65 |
C Note -- |
66 |
C 1. In theory one could have a send width and |
67 |
C a receive width for each face of each tile. The only |
68 |
C restriction woul be that the send width of one |
69 |
C face should equal the receive width of the sent to |
70 |
C tile face. Dont know if this would be useful. I |
71 |
C have left it out for now as it requires additional |
72 |
C bookeeping. |
73 |
C simulationMode :: Forward or reverse mode exchange ( provides |
74 |
C support for adjoint integration of code. ) |
75 |
C cornerMode :: Flag indicating whether corner updates are |
76 |
C needed. |
77 |
C myThid :: Thread number of this instance of S/R EXCH... |
78 |
LOGICAL withSigns |
79 |
INTEGER myOLw |
80 |
INTEGER myOLe |
81 |
INTEGER myOLs |
82 |
INTEGER myOLn |
83 |
INTEGER myNz |
84 |
INTEGER exchWidthX |
85 |
INTEGER exchWidthY |
86 |
INTEGER simulationMode |
87 |
INTEGER cornerMode |
88 |
INTEGER myThid |
89 |
_RX Uarray(1-myOLw:sNx+myOLe, |
90 |
& 1-myOLs:sNy+myOLn, |
91 |
& myNZ, nSx, nSy) |
92 |
_RX Varray(1-myOLw:sNx+myOLe, |
93 |
& 1-myOLs:sNy+myOLn, |
94 |
& myNZ, nSx, nSy) |
95 |
|
96 |
C !LOCAL VARIABLES: |
97 |
C == Local variables == |
98 |
C theSimulationMode :: Holds working copy of simulation mode |
99 |
C theCornerMode :: Holds working copy of corner mode |
100 |
C I,J,K :: Loop counters and index variables |
101 |
C bl,bt,bn,bs,be,bw |
102 |
C negOne,Utmp,Vtmp :: Temps used in swapping and rotating |
103 |
C vectors. |
104 |
INTEGER theSimulationMode |
105 |
INTEGER theCornerMode |
106 |
INTEGER I,J,K,repeat |
107 |
INTEGER bl,bt,bn,bs,be,bw |
108 |
_RL negOne,Utmp,Vtmp |
109 |
C == Statement function == |
110 |
C tilemod :: Permutes indices to return neighboring tile index on |
111 |
C six face cube. |
112 |
INTEGER tilemod |
113 |
tilemod(I)=1+mod(I-1+6,6) |
114 |
CEOP |
115 |
|
116 |
theSimulationMode = simulationMode |
117 |
theCornerMode = cornerMode |
118 |
|
119 |
negOne = 1. |
120 |
IF (withSigns) negOne = -1. |
121 |
|
122 |
C For now tile<->tile exchanges are sequentialised through |
123 |
C thread 1. This is a temporary feature for preliminary testing until |
124 |
C general tile decomposistion is in place (CNH April 11, 2001) |
125 |
CALL BAR2( myThid ) |
126 |
IF ( myThid .EQ. 1 ) THEN |
127 |
|
128 |
DO repeat=1,2 |
129 |
|
130 |
DO bl = 1, 5, 2 |
131 |
|
132 |
bt = bl |
133 |
bn=tilemod(bt+2) |
134 |
bs=tilemod(bt-1) |
135 |
be=tilemod(bt+1) |
136 |
bw=tilemod(bt-2) |
137 |
|
138 |
DO K = 1,myNz |
139 |
|
140 |
C Tile Odd:Odd+2 [get] [North<-West] |
141 |
DO J = 1,sNy+1 |
142 |
DO I = 1,exchWidthX |
143 |
Uarray(J,sNy+I,K,bt,1) = negOne*Varray(I,sNy+2-J,K,bn,1) |
144 |
ENDDO |
145 |
ENDDO |
146 |
DO J = 1,sNy |
147 |
DO I = 1,exchWidthX |
148 |
Varray(J,sNy+I,K,bt,1) = Uarray(I,sNy+1-J,K,bn,1) |
149 |
ENDDO |
150 |
ENDDO |
151 |
C Tile Odd:Odd-1 [get] [South<-North] |
152 |
DO J = 1,sNy+1 |
153 |
DO I = 1,exchWidthX |
154 |
Uarray(J,1-I,K,bt,1) = Uarray(J,sNy+1-I,K,bs,1) |
155 |
ENDDO |
156 |
ENDDO |
157 |
DO J = 1,sNy |
158 |
DO I = 1,exchWidthX |
159 |
Varray(J,1-I,K,bt,1) = Varray(J,sNy+1-I,K,bs,1) |
160 |
ENDDO |
161 |
ENDDO |
162 |
C Tile Odd:Odd+1 [get] [East<-West] |
163 |
DO J = 1,sNy |
164 |
DO I = 1,exchWidthX |
165 |
Uarray(sNx+I,J,K,bt,1) = Uarray(I,J,K,be,1) |
166 |
ENDDO |
167 |
ENDDO |
168 |
DO J = 1,sNy+1 |
169 |
DO I = 1,exchWidthX |
170 |
Varray(sNx+I,J,K,bt,1) = Varray(I,J,K,be,1) |
171 |
ENDDO |
172 |
ENDDO |
173 |
C Tile Odd:Odd-2 [get] [West<-North] |
174 |
DO J = 1,sNy |
175 |
DO I = 1,exchWidthX |
176 |
Uarray(1-I,J,K,bt,1) = Varray(sNx+1-J,sNy+1-I,K,bw,1) |
177 |
ENDDO |
178 |
ENDDO |
179 |
DO J = 1,sNy+1 |
180 |
DO I = 1,exchWidthX |
181 |
Varray(1-I,J,K,bt,1) = negOne*Uarray(sNx+2-J,sNy+1-I,K,bw,1) |
182 |
ENDDO |
183 |
ENDDO |
184 |
|
185 |
ENDDO |
186 |
|
187 |
bt = bl+1 |
188 |
bn=tilemod(bt+1) |
189 |
bs=tilemod(bt-2) |
190 |
be=tilemod(bt+2) |
191 |
bw=tilemod(bt-1) |
192 |
|
193 |
DO K = 1,myNz |
194 |
|
195 |
C Tile Even:Even+1 [get] [North<-South] |
196 |
DO J = 1,sNy+1 |
197 |
DO I = 1,exchWidthX |
198 |
Uarray(J,sNy+I,K,bt,1) = Uarray(J,I,K,bn,1) |
199 |
ENDDO |
200 |
ENDDO |
201 |
DO J = 1,sNy |
202 |
DO I = 1,exchWidthX |
203 |
Varray(J,sNy+I,K,bt,1) = Varray(J,I,K,bn,1) |
204 |
ENDDO |
205 |
ENDDO |
206 |
C Tile Even:Even-2 [get] [South<-East] |
207 |
DO J = 1,sNy+1 |
208 |
DO I = 1,exchWidthX |
209 |
Uarray(J,1-I,K,bt,1) = negOne*Varray(sNx+1-I,sNy+2-J,K,bs,1) |
210 |
ENDDO |
211 |
ENDDO |
212 |
DO J = 1,sNy |
213 |
DO I = 1,exchWidthX |
214 |
Varray(J,1-I,K,bt,1) = Uarray(sNx+1-I,sNy+1-J,K,bs,1) |
215 |
ENDDO |
216 |
ENDDO |
217 |
C Tile Even:Even+2 [get] [East<-South] |
218 |
DO J = 1,sNy |
219 |
DO I = 1,exchWidthX |
220 |
Uarray(sNx+I,J,K,bt,1) = Varray(sNx+1-J,I,K,be,1) |
221 |
ENDDO |
222 |
ENDDO |
223 |
DO J = 1,sNy+1 |
224 |
DO I = 1,exchWidthX |
225 |
Varray(sNx+I,J,K,bt,1) = negOne*Uarray(sNx+2-J,I,K,be,1) |
226 |
ENDDO |
227 |
ENDDO |
228 |
C Tile Even:Even-1 [get] [West<-East] |
229 |
DO J = 1,sNy |
230 |
DO I = 1,exchWidthX |
231 |
Uarray(1-I,J,K,bt,1) = Uarray(sNx+1-I,J,K,bw,1) |
232 |
ENDDO |
233 |
ENDDO |
234 |
DO J = 1,sNy+1 |
235 |
DO I = 1,exchWidthX |
236 |
Varray(1-I,J,K,bt,1) = Varray(sNx+1-I,J,K,bw,1) |
237 |
ENDDO |
238 |
ENDDO |
239 |
|
240 |
ENDDO |
241 |
|
242 |
ENDDO |
243 |
|
244 |
C Fix degeneracy at corners |
245 |
IF (.FALSE.) THEN |
246 |
c IF (withSigns) THEN |
247 |
DO bt = 1, 6 |
248 |
DO K = 1,myNz |
249 |
C Top left |
250 |
Utmp=0.5*(Uarray(1,sNy,K,bt,1)+Uarray(0,sNy,K,bt,1)) |
251 |
Vtmp=0.5*(Varray(0,sNy+1,K,bt,1)+Varray(0,sNy,K,bt,1)) |
252 |
Varray(0,sNx+1,K,bt,1)=(Vtmp-Utmp)*0.70710678 |
253 |
Utmp=0.5*(Uarray(1,sNy+1,K,bt,1)+Uarray(2,sNy+1,K,bt,1)) |
254 |
Vtmp=0.5*(Varray(1,sNy+1,K,bt,1)+Varray(1,sNy+2,K,bt,1)) |
255 |
Uarray(1,sNy+1,K,bt,1)=(Utmp-Vtmp)*0.70710678 |
256 |
C Bottom right |
257 |
Utmp=0.5*(Uarray(sNx+1,1,K,bt,1)+Uarray(sNx+2,1,K,bt,1)) |
258 |
Vtmp=0.5*(Varray(sNx+1,1,K,bt,1)+Varray(sNx+1,2,K,bt,1)) |
259 |
Varray(sNx+1,1,K,bt,1)=(Vtmp-Utmp)*0.70710678 |
260 |
Utmp=0.5*(Uarray(sNx+1,0,K,bt,1)+Uarray(sNx,0,K,bt,1)) |
261 |
Vtmp=0.5*(Varray(sNx,1,K,bt,1)+Varray(sNx,0,K,bt,1)) |
262 |
Uarray(sNx+1,0,K,bt,1)=(Utmp-Vtmp)*0.70710678 |
263 |
C Bottom left |
264 |
Utmp=0.5*(Uarray(1,1,K,bt,1)+Uarray(0,1,K,bt,1)) |
265 |
Vtmp=0.5*(Varray(0,1,K,bt,1)+Varray(0,2,K,bt,1)) |
266 |
Varray(0,1,K,bt,1)=(Vtmp+Utmp)*0.70710678 |
267 |
Utmp=0.5*(Uarray(1,0,K,bt,1)+Uarray(2,0,K,bt,1)) |
268 |
Vtmp=0.5*(Varray(1,1,K,bt,1)+Varray(1,0,K,bt,1)) |
269 |
Uarray(1,0,K,bt,1)=(Utmp+Vtmp)*0.70710678 |
270 |
C Top right |
271 |
Utmp=0.5*(Uarray(sNx+1,sNy,K,bt,1)+Uarray(sNx+2,sNy,K,bt,1)) |
272 |
Vtmp=0.5*(Varray(sNx+1,sNy+1,K,bt,1)+Varray(sNx+1,sNy,K,bt,1)) |
273 |
Varray(sNx+1,sNy+1,K,bt,1)=(Vtmp+Utmp)*0.70710678 |
274 |
Utmp=0.5*(Uarray(sNx+1,sNy+1,K,bt,1)+Uarray(sNx,sNy+1,K,bt,1)) |
275 |
Vtmp=0.5*(Varray(sNx,sNy+1,K,bt,1)+Varray(sNx,sNy+2,K,bt,1)) |
276 |
Uarray(sNx+1,sNy+1,K,bt,1)=(Utmp+Vtmp)*0.70710678 |
277 |
ENDDO |
278 |
ENDDO |
279 |
ENDIF |
280 |
|
281 |
ENDDO |
282 |
|
283 |
ENDIF |
284 |
CALL BAR2(myThid) |
285 |
|
286 |
RETURN |
287 |
END |