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

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

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


Revision 1.11 - (show annotations) (download)
Mon Sep 3 19:39:25 2012 UTC (11 years, 8 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint64y, checkpoint64x, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, checkpoint63s, checkpoint64, checkpoint65, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65o, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, HEAD
Changes since 1.10: +3 -3 lines
add "if usingMPI" test where needed

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

  ViewVC Help
Powered by ViewVC 1.1.22