1 |
C $Header: /u/gcmpack/MITgcm/eesupp/src/exch_rx_cube.template,v 1.6 2010/05/04 00:39:52 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CPP_EEOPTIONS.h" |
5 |
|
6 |
CBOP |
7 |
C !ROUTINE: EXCH1_RX_CUBE |
8 |
|
9 |
C !INTERFACE: |
10 |
SUBROUTINE EXCH1_RX_CUBE( |
11 |
U array, |
12 |
I withSigns, |
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_CUBE |
20 |
C | o Forward-mode edge exchanges for RX array on CS config. |
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 *==========================================================* |
41 |
|
42 |
C !USES: |
43 |
IMPLICIT NONE |
44 |
|
45 |
C == Global data == |
46 |
#include "SIZE.h" |
47 |
#include "EEPARAMS.h" |
48 |
|
49 |
C !INPUT/OUTPUT PARAMETERS: |
50 |
C == Routine arguments == |
51 |
C array :: Array with edges to exchange. |
52 |
C withSigns :: Flag controlling whether field sign depends on orientation |
53 |
C :: (signOption not yet implemented but needed for SM exch) |
54 |
C myOLw,myOLe :: West and East overlap region sizes. |
55 |
C myOLs,myOLn :: South and North overlap region sizes. |
56 |
C exchWidthX :: Width of data region exchanged in X. |
57 |
C exchWidthY :: Width of data region exchanged in Y. |
58 |
C Note -- |
59 |
C 1. In theory one could have a send width and |
60 |
C a receive width for each face of each tile. The only |
61 |
C restriction would be that the send width of one |
62 |
C face should equal the receive width of the sent to |
63 |
C tile face. Dont know if this would be useful. I |
64 |
C have left it out for now as it requires additional |
65 |
C bookeeping. |
66 |
C cornerMode :: Flag indicating whether corner updates are needed. |
67 |
C myThid :: my Thread Id number |
68 |
|
69 |
INTEGER myOLw, myOLe, myOLs, myOLn, myNz |
70 |
_RX array( 1-myOLw:sNx+myOLe, |
71 |
& 1-myOLs:sNy+myOLn, |
72 |
& myNz, nSx, nSy ) |
73 |
LOGICAL withSigns |
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 :: Loop and index counters |
84 |
C bl,bt,bn,bs,be,bw :: tile indices |
85 |
c INTEGER theSimulationMode |
86 |
c INTEGER theCornerMode |
87 |
INTEGER I,J,K |
88 |
INTEGER bl,bt,bn,bs,be,bw |
89 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
90 |
|
91 |
C == Statement function == |
92 |
C tilemod :: Permutes indices to return neighboring tile index |
93 |
C on six face cube. |
94 |
INTEGER tilemod |
95 |
tilemod(I)=1+mod(I-1+6,6) |
96 |
CEOP |
97 |
|
98 |
c theSimulationMode = FORWARD_SIMULATION |
99 |
c theCornerMode = cornerMode |
100 |
|
101 |
c IF ( simulationMode.EQ.REVERSE_SIMULATION ) THEN |
102 |
c WRITE(msgBuf,'(A)') 'EXCH1_RX_CUBE: AD mode not implemented' |
103 |
c CALL PRINT_ERROR( msgBuf, myThid ) |
104 |
c STOP 'ABNORMAL END: EXCH1_RX_CUBE: no AD code' |
105 |
c ENDIF |
106 |
IF ( sNx.NE.sNy .OR. |
107 |
& nSx.NE.6 .OR. nSy.NE.1 .OR. |
108 |
& nPx.NE.1 .OR. nPy.NE.1 ) THEN |
109 |
WRITE(msgBuf,'(2A)') 'EXCH1_RX_CUBE: Wrong Tiling' |
110 |
CALL PRINT_ERROR( msgBuf, myThid ) |
111 |
WRITE(msgBuf,'(2A)') 'EXCH1_RX_CUBE: ', |
112 |
& 'works only with sNx=sNy & nSx=6 & nSy=nPx=nPy=1' |
113 |
CALL PRINT_ERROR( msgBuf, myThid ) |
114 |
STOP 'ABNORMAL END: EXCH1_RX_CUBE: Wrong Tiling' |
115 |
ENDIF |
116 |
|
117 |
C For now tile<->tile exchanges are sequentialised through |
118 |
C thread 1. This is a temporary feature for preliminary testing until |
119 |
C general tile decomposistion is in place (CNH April 11, 2001) |
120 |
CALL BAR2( myThid ) |
121 |
IF ( myThid .EQ. 1 ) THEN |
122 |
|
123 |
DO bl = 1, 5, 2 |
124 |
|
125 |
bt = bl |
126 |
bn=tilemod(bt+2) |
127 |
bs=tilemod(bt-1) |
128 |
be=tilemod(bt+1) |
129 |
bw=tilemod(bt-2) |
130 |
|
131 |
DO K = 1, myNz |
132 |
DO J = 1, sNy |
133 |
DO I = 1, exchWidthX |
134 |
|
135 |
C Tile Odd:Odd+2 [get] [North<-West] |
136 |
array(J,sNy+I,K,bt,1) = array(I,sNy+1-J,K,bn,1) |
137 |
C Tile Odd:Odd-1 [get] [South<-North] |
138 |
array(J,1-I,K,bt,1) = array(J,sNy+1-I,K,bs,1) |
139 |
C Tile Odd:Odd+1 [get] [East<-West] |
140 |
array(sNx+I,J,K,bt,1) = array(I,J,K,be,1) |
141 |
C Tile Odd:Odd-2 [get] [West<-North] |
142 |
array(1-I,J,K,bt,1) = array(sNx+1-J,sNy+1-I,K,bw,1) |
143 |
|
144 |
ENDDO |
145 |
ENDDO |
146 |
ENDDO |
147 |
|
148 |
bt = bl+1 |
149 |
bn=tilemod(bt+1) |
150 |
bs=tilemod(bt-2) |
151 |
be=tilemod(bt+2) |
152 |
bw=tilemod(bt-1) |
153 |
|
154 |
DO K = 1, myNz |
155 |
DO J = 1, sNy |
156 |
DO I = 1, exchWidthX |
157 |
|
158 |
C Tile Even:Even+1 [get] [North<-South] |
159 |
array(J,sNy+I,K,bt,1) = array(J,I,K,bn,1) |
160 |
C Tile Even:Even-2 [get] [South<-East] |
161 |
array(J,1-I,K,bt,1) = array(sNx+1-I,sNy+1-J,K,bs,1) |
162 |
C Tile Even:Even+2 [get] [East<-South] |
163 |
array(sNx+I,J,K,bt,1) = array(sNx+1-J,I,K,be,1) |
164 |
C Tile Even:Even-1 [get] [West<-East] |
165 |
array(1-I,J,K,bt,1) = array(sNx+1-I,J,K,bw,1) |
166 |
|
167 |
ENDDO |
168 |
ENDDO |
169 |
ENDDO |
170 |
|
171 |
ENDDO |
172 |
|
173 |
ENDIF |
174 |
CALL BAR2(myThid) |
175 |
|
176 |
RETURN |
177 |
END |