/[MITgcm]/MITgcm/pkg/exch2/exch2_rx1_cube_ad.template
ViewVC logotype

Annotation of /MITgcm/pkg/exch2/exch2_rx1_cube_ad.template

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (hide annotations) (download)
Thu May 6 23:28:44 2010 UTC (14 years, 1 month ago) by jmc
Branch: MAIN
Changes since 1.8: +7 -4 lines
- S/R EXCH2_RX1,2_CUBE: remove argument "simulationMode" ;
- add argument "signOption" to EXCH2_RX1_CUBE (will be needed for SM exch)

1 jmc 1.9 C $Header: /u/gcmpack/MITgcm/pkg/exch2/exch2_rx1_cube_ad.template,v 1.8 2010/04/23 20:21:07 jmc Exp $
2 heimbach 1.1 C $Name: $
3    
4     #include "CPP_EEOPTIONS.h"
5    
6     #undef Dbg
7    
8     CBOP
9     C !ROUTINE: EXCH_RX_CUBE_AD
10    
11     C !INTERFACE:
12 jmc 1.5 SUBROUTINE EXCH2_RX1_CUBE_AD(
13 jmc 1.9 U array,
14     I signOption, fieldCode,
15 heimbach 1.1 I myOLw, myOLe, myOLn, myOLs, myNz,
16     I exchWidthX, exchWidthY,
17 jmc 1.9 I cornerMode, myThid )
18 heimbach 1.1
19     C !DESCRIPTION:
20 jmc 1.5 C Scalar field (1 component) AD-Exchange:
21     C Tile-edge overlap-region of a 1 component scalar field is added to
22     C corresponding near-edge interior data point and then zero out.
23 heimbach 1.1
24     C !USES:
25 jmc 1.5 IMPLICIT NONE
26    
27 heimbach 1.1 C == Global data ==
28     #include "SIZE.h"
29     #include "EEPARAMS.h"
30     #include "EESUPPORT.h"
31 jmc 1.4 #include "W2_EXCH2_SIZE.h"
32 heimbach 1.1 #include "W2_EXCH2_TOPOLOGY.h"
33 jmc 1.4 #include "W2_EXCH2_BUFFER.h"
34 heimbach 1.1
35     C !INPUT/OUTPUT PARAMETERS:
36 jmc 1.5 C array :: Array with edges to exchange.
37 jmc 1.9 C signOption :: Flag controlling whether field sign depends on orientation
38     C :: (signOption not yet implemented but needed for SM exch)
39 jmc 1.5 C fieldCode :: field code (position on staggered grid)
40     C myOLw,myOLe :: West and East overlap region sizes.
41     C myOLn,myOLs :: North and South overlap region sizes.
42     C exchWidthX :: Width of data regi exchanged in X.
43     C exchWidthY :: Width of data region exchanged in Y.
44     C cornerMode :: halo-corner-region treatment: update/ignore corner region
45     C myThid :: Thread number of this instance of S/R EXCH...
46 heimbach 1.1 INTEGER myOLw
47     INTEGER myOLe
48     INTEGER myOLs
49     INTEGER myOLn
50     INTEGER myNz
51 jmc 1.5 _RX array(1-myOLw:sNx+myOLe,
52     & 1-myOLs:sNy+myOLn,
53     & myNZ, nSx, nSy)
54 jmc 1.9 LOGICAL signOption
55 jmc 1.5 CHARACTER*2 fieldCode
56 heimbach 1.1 INTEGER exchWidthX
57     INTEGER exchWidthY
58     INTEGER cornerMode
59     INTEGER myThid
60    
61     C !LOCAL VARIABLES:
62 jmc 1.5 C e2_msgHandles :: Synchronization and coordination data structure used to
63     C :: coordinate access to e2Bufr1_RX or to regulate message
64     C :: buffering. In PUT communication sender will increment
65     C :: handle entry once data is ready in buffer. Receiver will
66     C :: decrement handle once data is consumed from buffer.
67 jmc 1.8 C :: For MPI MSG communication MPI_Wait uses handle to check
68 jmc 1.5 C :: Isend has cleared. This is done in routine after receives.
69     C note: a) current implementation does not use e2_msgHandles for communication
70     C between threads: all-threads barriers are used (see CNH note below).
71     C For a 2-threads synchro communication (future version),
72     C e2_msgHandles should be shared (in common block, moved to BUFFER.h)
73     C b) 1rst dim=2 so that it could be used also by exch2_rx2_cube.
74     INTEGER bi, bj
75 heimbach 1.1 C Variables for working through W2 topology
76 jmc 1.5 INTEGER e2_msgHandles( 2, W2_maxNeighbours, nSx, nSy )
77 heimbach 1.1 INTEGER thisTile, farTile, N, nN, oN
78     INTEGER tIlo, tIhi, tJlo, tJhi, tKlo, tKhi
79     INTEGER tIStride, tJStride, tKStride
80     INTEGER i1Lo, i1Hi, j1Lo, j1Hi, k1Lo, k1Hi
81 jmc 1.5 LOGICAL updateCorners
82 heimbach 1.1
83 jmc 1.5 #ifdef ALLOW_USE_MPI
84     INTEGER iBufr, nri, nrj
85 heimbach 1.1 C MPI stuff (should be in a routine call)
86     INTEGER mpiStatus(MPI_STATUS_SIZE)
87     INTEGER mpiRc
88     INTEGER wHandle
89     #endif
90     CEOP
91    
92 jmc 1.5 updateCorners = cornerMode .EQ. EXCH_UPDATE_CORNERS
93     C- Tile size of array to exchange:
94     i1Lo = 1-myOLw
95     i1Hi = sNx+myOLe
96     j1Lo = 1-myOLs
97     j1Hi = sNy+myOLn
98     k1Lo = 1
99     k1Hi = myNz
100 heimbach 1.1
101 jmc 1.7 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
102    
103     C Prevent anyone to access shared buffer while an other thread modifies it
104 heimbach 1.1 CALL BAR2( myThid )
105    
106 jmc 1.5 C-- Extract from buffer (either from level 1 if local exch,
107     C or level 2 if coming from an other Proc)
108     C AD: = fill buffer from my-tile-edge overlap-region, level 1 or 2 depending
109     C AD: on local (to this Proc) or remote Proc tile destination
110     DO bj=myByLo(myThid), myByHi(myThid)
111     DO bi=myBxLo(myThid), myBxHi(myThid)
112 jmc 1.6 thisTile=W2_myTileList(bi,bj)
113 jmc 1.5 nN=exch2_nNeighbours(thisTile)
114     DO N=1,nN
115     CALL EXCH2_GET_SCAL_BOUNDS(
116     I fieldCode, exchWidthX, updateCorners,
117     I thisTile, N,
118     O tIlo, tiHi, tjLo, tjHi,
119     O tiStride, tjStride,
120     I myThid )
121     tKLo=1
122     tKHi=myNz
123     tKStride=1
124    
125     C From buffer, get my points
126     C (tIlo:tIhi:tiStride,tJlo:tJhi,tJStride,tKlo:tKhi,tKStride) in "array":
127     C Note: when transferring data within a process:
128     C o e2Bufr entry to read is entry associated with opposing send record
129     C o e2_msgHandle entry to read is entry associated with opposing send record.
130     CALL EXCH2_AD_GET_RX1(
131     I tIlo, tIhi, tiStride,
132     I tJlo, tJhi, tjStride,
133     I tKlo, tKhi, tkStride,
134     I thisTile, N, bi, bj,
135     I e2BufrRecSize, W2_maxNeighbours, nSx, nSy,
136 jmc 1.6 O iBuf1Filled(N,bi,bj),
137 jmc 1.5 O e2Bufr1_RX,
138     U array(1-myOLw,1-myOLs,1,bi,bj),
139     I i1Lo, i1Hi, j1Lo, j1Hi, k1Lo, k1Hi,
140     U e2_msgHandles,
141 jmc 1.6 I W2_myCommFlag(N,bi,bj), myThid )
142 jmc 1.5 ENDDO
143 heimbach 1.1 ENDDO
144     ENDDO
145    
146 jmc 1.7 C Wait until all threads finish filling buffer
147     CALL BAR2( myThid )
148    
149 jmc 1.5 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
150    
151     #ifdef ALLOW_USE_MPI
152     C AD: all MPI part is acting on buffer and is identical to forward code,
153     C AD: except a) the buffer level: send from lev.2, receive into lev.1
154 jmc 1.8 C AD: b) the length of transferred buffer (<- match the ad_put/ad_get)
155 jmc 1.5
156     _BEGIN_MASTER( myThid )
157    
158     C-- Send my data (in buffer, level 2) to target Process
159     DO bj=1,nSy
160     DO bi=1,nSx
161 jmc 1.6 thisTile=W2_myTileList(bi,bj)
162 jmc 1.5 nN=exch2_nNeighbours(thisTile)
163     DO N=1,nN
164     C- Skip the call if this is an internal exchange
165 jmc 1.6 IF ( W2_myCommFlag(N,bi,bj) .EQ. 'M' ) THEN
166 jmc 1.5 CALL EXCH2_SEND_RX1(
167     I thisTile, N,
168     I e2BufrRecSize,
169 jmc 1.6 I iBuf1Filled(N,bi,bj),
170     I e2Bufr1_RX(1,N,bi,bj,2),
171 jmc 1.5 O e2_msgHandles(1,N,bi,bj),
172 jmc 1.6 I W2_myCommFlag(N,bi,bj), myThid )
173 jmc 1.5 ENDIF
174     ENDDO
175     ENDDO
176     ENDDO
177    
178     C-- Receive data (in buffer, level 1) from source Process
179     DO bj=1,nSy
180     DO bi=1,nSx
181 jmc 1.6 thisTile=W2_myTileList(bi,bj)
182 jmc 1.5 nN=exch2_nNeighbours(thisTile)
183     DO N=1,nN
184     C- Skip the call if this is an internal exchange
185 jmc 1.6 IF ( W2_myCommFlag(N,bi,bj) .EQ. 'M' ) THEN
186 jmc 1.5 farTile=exch2_neighbourId(N,thisTile)
187     oN = exch2_opposingSend(N,thisTile)
188     CALL EXCH2_GET_SCAL_BOUNDS(
189     I fieldCode, exchWidthX, updateCorners,
190     I farTile, oN,
191     O tIlo, tiHi, tjLo, tjHi,
192     O tiStride, tjStride,
193     I myThid )
194     nri = 1 + (tIhi-tIlo)/tiStride
195     nrj = 1 + (tJhi-tJlo)/tjStride
196     iBufr = nri*nrj*myNz
197     C Receive from neighbour N to fill buffer and later on the array
198     CALL EXCH2_RECV_RX1(
199     I thisTile, N,
200     I e2BufrRecSize,
201     I iBufr,
202 jmc 1.6 O e2Bufr1_RX(1,N,bi,bj,1),
203     I W2_myCommFlag(N,bi,bj), myThid )
204 jmc 1.5 ENDIF
205     ENDDO
206     ENDDO
207     ENDDO
208 heimbach 1.1
209 jmc 1.5 C-- Clear message handles/locks
210     DO bj=1,nSy
211     DO bi=1,nSx
212 jmc 1.6 thisTile=W2_myTileList(bi,bj)
213 jmc 1.5 nN=exch2_nNeighbours(thisTile)
214     DO N=1,nN
215     C Note: In a between process tile-tile data transport using
216     C MPI the sender needs to clear an Isend wait handle here.
217     C In a within process tile-tile data transport using true
218     C shared address space/or direct transfer through commonly
219     C addressable memory blocks the receiver needs to assert
220     C that he has consumed the buffer the sender filled here.
221     c farTile=exch2_neighbourId(N,thisTile)
222 jmc 1.6 IF ( W2_myCommFlag(N,bi,bj) .EQ. 'M' ) THEN
223 jmc 1.5 wHandle = e2_msgHandles(1,N,bi,bj)
224     CALL MPI_Wait( wHandle, mpiStatus, mpiRc )
225 jmc 1.6 ELSEIF ( W2_myCommFlag(N,bi,bj) .EQ. 'P' ) THEN
226 jmc 1.5 ELSE
227     ENDIF
228     ENDDO
229 heimbach 1.1 ENDDO
230     ENDDO
231    
232 jmc 1.5 _END_MASTER( myThid )
233 jmc 1.7 C Everyone waits until master-thread finishes receiving
234     CALL BAR2( myThid )
235    
236 jmc 1.5 #endif /* ALLOW_USE_MPI */
237    
238     C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
239    
240     C-- Post sends into buffer (buffer level 1):
241     C- AD: = get exch-data from buffer (level 1), formerly in source tile
242     C AD: overlap region, and add to my tile near-Edge interior
243     DO bj=myByLo(myThid), myByHi(myThid)
244     DO bi=myBxLo(myThid), myBxHi(myThid)
245 jmc 1.6 thisTile=W2_myTileList(bi,bj)
246 jmc 1.5 nN=exch2_nNeighbours(thisTile)
247     DO N=1,nN
248     farTile=exch2_neighbourId(N,thisTile)
249     oN = exch2_opposingSend(N,thisTile)
250     CALL EXCH2_GET_SCAL_BOUNDS(
251     I fieldCode, exchWidthX, updateCorners,
252     I farTile, oN,
253     O tIlo, tiHi, tjLo, tjHi,
254     O tiStride, tjStride,
255     I myThid )
256     tKLo=1
257     tKHi=myNz
258     tKStride=1
259     C- Put my points in buffer for neighbour N to fill points
260     C (tIlo:tIhi:tiStride,tJlo:tJhi,tJStride,tKlo:tKhi,tKStride)
261     C in its copy of "array".
262     CALL EXCH2_AD_PUT_RX1(
263     I tIlo, tIhi, tiStride,
264     I tJlo, tJhi, tjStride,
265     I tKlo, tKhi, tkStride,
266     I thisTile, N,
267     I e2BufrRecSize,
268 jmc 1.6 I e2Bufr1_RX(1,N,bi,bj,1),
269 jmc 1.5 U array(1-myOLw,1-myOLs,1,bi,bj),
270     I i1Lo, i1Hi, j1Lo, j1Hi, k1Lo, k1Hi,
271     O e2_msgHandles(1,N,bi,bj),
272 jmc 1.6 I W2_myCommFlag(N,bi,bj), myThid )
273 jmc 1.5 ENDDO
274 heimbach 1.1 ENDDO
275     ENDDO
276    
277     RETURN
278     END
279    
280     C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
281    
282     CEH3 ;;; Local Variables: ***
283     CEH3 ;;; mode:fortran ***
284     CEH3 ;;; End: ***

  ViewVC Help
Powered by ViewVC 1.1.22