| 1 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/ini_communication_patterns.F,v 1.5 2001/09/05 19:59:31 adcroft Exp $ |
| 2 |
C $Name: $ |
| 3 |
|
| 4 |
#include "CPP_EEOPTIONS.h" |
| 5 |
|
| 6 |
CBOP |
| 7 |
|
| 8 |
C !ROUTINE: INI_COMMUNICATION_PATTERNS |
| 9 |
|
| 10 |
C !INTERFACE: |
| 11 |
SUBROUTINE INI_COMMUNICATION_PATTERNS( myThid ) |
| 12 |
IMPLICIT NONE |
| 13 |
C !DESCRIPTION: |
| 14 |
C *==========================================================* |
| 15 |
C | SUBROUTINE INI_COMMUNICATION_PATTERNS |
| 16 |
C | o Initialise between tile communication data structures. |
| 17 |
C *==========================================================* |
| 18 |
C | This routine assigns identifiers to each tile and then |
| 19 |
C | defines a map of neighbors for each tile. |
| 20 |
C | For each neighbor a communication method is defined. |
| 21 |
C *==========================================================* |
| 22 |
|
| 23 |
C !USES: |
| 24 |
C === Global data === |
| 25 |
#include "SIZE.h" |
| 26 |
#include "EEPARAMS.h" |
| 27 |
#include "EESUPPORT.h" |
| 28 |
#include "EXCH.h" |
| 29 |
|
| 30 |
C !INPUT/OUTPUT PARAMETERS: |
| 31 |
C === Routine arguments === |
| 32 |
C myThid :: Thread number we are dealing with in this call |
| 33 |
INTEGER myThid |
| 34 |
|
| 35 |
C !LOCAL VARIABLES: |
| 36 |
C === Local variables === |
| 37 |
C pxW :: Process X coord of process to west. |
| 38 |
C pxE :: Process X coord of process to west. |
| 39 |
C pyN :: Process Y coord of process to north. |
| 40 |
C pyS :: Process Y coord of process to south. |
| 41 |
C procW :: Process Id of process to west. |
| 42 |
C procE :: Process Id of process to east. |
| 43 |
C procN :: Process Id of process to north. |
| 44 |
C procS :: Process Id of process to south. |
| 45 |
C totalTileCount :: Total number of tiles |
| 46 |
C tagW0, tagE0, tagS0, tagN0, theTag :: Working variables for |
| 47 |
C calculating message tags. |
| 48 |
C biW, biE, bjN, bjS :: Tile x and y indices to west, east, |
| 49 |
C south and north. |
| 50 |
C bi, bj :: Tile loop counter |
| 51 |
C pi, pj :: Process loop counter |
| 52 |
C bi0, bj0 :: Base global index coordinate ( on CS there is no global |
| 53 |
C coord). |
| 54 |
INTEGER bi0(nPx) |
| 55 |
INTEGER bj0(nPy) |
| 56 |
INTEGER bi, bj, pi, pj |
| 57 |
INTEGER pxW, pxE, pyN, pyS |
| 58 |
INTEGER procW, procE, procN, procS |
| 59 |
INTEGER totalTileCount |
| 60 |
INTEGER tagW0, tagE0, tagS0, tagN0, theTag |
| 61 |
INTEGER biE, biW, bjN, bjS |
| 62 |
INTEGER thePx, thePy, theBj, theBi |
| 63 |
CEOP |
| 64 |
|
| 65 |
#ifndef ALWAYS_USE_MPI |
| 66 |
C-- Turn off memsync by default (e.g. needed for threads on SUNs) |
| 67 |
exchNeedsMemsync = .TRUE. |
| 68 |
exchUsesBarrier = .TRUE. |
| 69 |
#else |
| 70 |
C-- ... except that MPI needs this until some counter problem is fixed. |
| 71 |
exchNeedsMemsync = .FALSE. |
| 72 |
exchUsesBarrier = .FALSE. |
| 73 |
#endif |
| 74 |
|
| 75 |
C-- Define a globally unique tile numbers for each tile. |
| 76 |
C-- We aslo define the tile numbers for our east, west, south |
| 77 |
C-- and north neighbor tiles here. As coded below this is done from |
| 78 |
C-- a simple cartesian formula. To handle irregular tile distributions |
| 79 |
C-- the code below would be changed. For instance we could read |
| 80 |
C-- the neighbor tile information from a file rather than deriving |
| 81 |
C-- it in-line. This allows general tile distributions and connectivity |
| 82 |
C-- both within a thread, between threads and between processors. |
| 83 |
C Notes -- |
| 84 |
C 1. The cartesian based formula coded below works as follows: |
| 85 |
C i. Each tile has one west neighbor, one east neighbor |
| 86 |
C one north neignbor and one south neighbor. |
| 87 |
C ii. For each of my neighbors store the following |
| 88 |
C - neighbor tile id |
| 89 |
C - neighbor process id |
| 90 |
C 2. The information that is stored is then used to determine |
| 91 |
C the between tile communication method. The method used |
| 92 |
C depends on whether the tile is part of the same process, |
| 93 |
C on the same machine etc... |
| 94 |
C 3. To initialise a tile distribution with holes in it |
| 95 |
C i.e. tiles that are not computed on. Set tile number to |
| 96 |
C the value NULL_TILE. This must also be done for tileNoW, |
| 97 |
C tileNoE, tileNoS, tileNoN. |
| 98 |
C 4. The default formula below assigns tile numbers sequentially |
| 99 |
C in X on the **global** grid. Within a process the tile numbers |
| 100 |
C will not necessairily be sequential. This means that the tile |
| 101 |
C numbering label does not change when nTx, nTy, nPx or nPy change. |
| 102 |
C It will only change if the tile size changes or the global |
| 103 |
C grid changes. |
| 104 |
C bi0 and bj0 are the base global tile grid coordinate for the first |
| 105 |
C tile in this process. |
| 106 |
DO pi = 1, nPx |
| 107 |
bi0(pi) = pi |
| 108 |
ENDDO |
| 109 |
DO pj = 1, nPy |
| 110 |
bj0(pj) = pj |
| 111 |
ENDDO |
| 112 |
DO bj=myByLo(myThid),myByHi(myThid) |
| 113 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
| 114 |
C o My tile identifier |
| 115 |
Crg tileNo(bi,bj) = (bj0(myPy)-1+bj-1)*nSx*nPx+bi0(myPx)+bi-1 |
| 116 |
thePx = myPx |
| 117 |
thePy = myPy |
| 118 |
theBj = bj |
| 119 |
theBi = bi |
| 120 |
tileNo(bi,bj) = |
| 121 |
& ((thePy-1)*nSy+theBj-1)*nSx*nPx |
| 122 |
& + (thePx-1)*nSx |
| 123 |
& + theBi |
| 124 |
C o My west neighbor tile and process identifier |
| 125 |
biW = bi-1 |
| 126 |
pxW = myPx |
| 127 |
procW = myPid |
| 128 |
IF ( biW .LT. 1 ) THEN |
| 129 |
biW = nSx |
| 130 |
pxW = myPx-1 |
| 131 |
procW = pidW |
| 132 |
IF ( pxW .LT. 1 ) pxW = nPx |
| 133 |
ENDIF |
| 134 |
Crg tileNoW (bi,bj) = (bj0(myPy)-1+bj-1)*nSx*nPx+bi0(pxW)+biW-1 |
| 135 |
thePx = pxW |
| 136 |
thePy = myPy |
| 137 |
theBj = bj |
| 138 |
theBi = biW |
| 139 |
tileNoW (bi,bj) = |
| 140 |
& ((thePy-1)*nSy+theBj-1)*nSx*nPx |
| 141 |
& + (thePx-1)*nSx |
| 142 |
& + theBi |
| 143 |
tilePidW(bi,bj) = procW |
| 144 |
tileBiW (bi,bj) = biW |
| 145 |
tileBjW (bi,bj) = bj |
| 146 |
C o My east neighbor tile and process identifier |
| 147 |
biE = bi+1 |
| 148 |
pxE = myPx |
| 149 |
procE = myPid |
| 150 |
IF ( biE .GT. nSx ) THEN |
| 151 |
biE = 1 |
| 152 |
pxE = myPx+1 |
| 153 |
procE = pidE |
| 154 |
IF ( pxE .GT. nPx ) pxE = 1 |
| 155 |
ENDIF |
| 156 |
Crg tileNoE(bi,bj) = (bj0(myPy)-1+bj-1)*nSx*nPx+bi0(pxE)+biE-1 |
| 157 |
thePx = pxE |
| 158 |
thePy = myPy |
| 159 |
theBi = biE |
| 160 |
theBj = bj |
| 161 |
tileNoE(bi,bj) = |
| 162 |
& ((thePy-1)*nSy+theBj-1)*nSx*nPx |
| 163 |
& + (thePx-1)*nSx |
| 164 |
& + theBi |
| 165 |
tilePidE(bi,bj) = procE |
| 166 |
tileBiE (bi,bj) = biE |
| 167 |
tileBjE (bi,bj) = bj |
| 168 |
C o My north neighbor tile and process identifier |
| 169 |
bjN = bj+1 |
| 170 |
pyN = myPy |
| 171 |
procN = myPid |
| 172 |
IF ( bjN .GT. nSy ) THEN |
| 173 |
bjN = 1 |
| 174 |
pyN = myPy+1 |
| 175 |
procN = pidN |
| 176 |
IF ( pyN .GT. nPy ) pyN = 1 |
| 177 |
ENDIF |
| 178 |
Crg tileNoN(bi,bj) = (bj0(pyN)-1+bjN-1)*nSx*nPx+bi0(myPx)+bi-1 |
| 179 |
thePx = myPx |
| 180 |
thePy = pyN |
| 181 |
theBi = bi |
| 182 |
theBj = bjN |
| 183 |
tileNoN(bi,bj) = |
| 184 |
& ((thePy-1)*nSy+theBj-1)*nSx*nPx |
| 185 |
& + (thePx-1)*nSx |
| 186 |
& + theBi |
| 187 |
tilePidN(bi,bj) = procN |
| 188 |
tileBiN(bi,bj) = bi |
| 189 |
tileBjN(bi,bj) = bjN |
| 190 |
C o My south neighbor tile and process identifier |
| 191 |
bjS = bj-1 |
| 192 |
pyS = myPy |
| 193 |
procS = myPid |
| 194 |
IF ( bjS .LT. 1 ) THEN |
| 195 |
bjS = nSy |
| 196 |
pyS = pyS-1 |
| 197 |
procS = pidS |
| 198 |
IF ( pyS .LT. 1 ) pyS = nPy |
| 199 |
ENDIF |
| 200 |
Crg tileNoS(bi,bj) = (bj0(pyS+1)-1+bjS-1)*nSx*nPx+bi0(myPx+1)+bi-1 |
| 201 |
thePx = myPx |
| 202 |
thePy = pyS |
| 203 |
theBi = bi |
| 204 |
theBj = bjS |
| 205 |
tileNoS(bi,bj) = |
| 206 |
& ((thePy-1)*nSy+theBj-1)*nSx*nPx |
| 207 |
& + (thePx-1)*nSx |
| 208 |
& + theBi |
| 209 |
tilePidS(bi,bj) = procS |
| 210 |
tileBiS(bi,bj) = bi |
| 211 |
tileBjS(bi,bj) = bjS |
| 212 |
ENDDO |
| 213 |
ENDDO |
| 214 |
|
| 215 |
C-- Define the total count of tiles. |
| 216 |
totalTileCount = nSx*nSy*nPx*nPy |
| 217 |
|
| 218 |
C-- Set tags for each tile face. |
| 219 |
C Tags are used to distinguish exchanges from particular |
| 220 |
C faces of particular tiles. |
| 221 |
C Tag numbers are based on |
| 222 |
C i - The tile number |
| 223 |
C ii - The direction (N,S,W,E) of the message |
| 224 |
C We dont check for the NULL_TILE tile number here as it |
| 225 |
C should not actually be used. |
| 226 |
TagW0=1 |
| 227 |
TagE0=2 |
| 228 |
TagN0=3 |
| 229 |
TagS0=4 |
| 230 |
DO bj=myByLo(myThid),myByHi(myThid) |
| 231 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
| 232 |
C Send tags |
| 233 |
C o Tag I use for messages I send to west |
| 234 |
theTag = TagW0*totalTileCount+tileNo(bi,bj)-1 |
| 235 |
tileTagSendW(bi,bj) = theTag |
| 236 |
C o Tag I use for messages I send to east |
| 237 |
theTag = TagE0*totalTileCount+tileNo(bi,bj)-1 |
| 238 |
tileTagSendE(bi,bj) = theTag |
| 239 |
C o Tag I use for messages I send to north |
| 240 |
theTag = TagN0*totalTileCount+tileNo(bi,bj)-1 |
| 241 |
tileTagSendN(bi,bj) = theTag |
| 242 |
C o Tag I use for messages I send to south |
| 243 |
theTag = TagS0*totalTileCount+tileNo(bi,bj)-1 |
| 244 |
tileTagSendS(bi,bj) = theTag |
| 245 |
C Receive tags |
| 246 |
C o Tag on messages I receive from my east |
| 247 |
theTag = TagW0*totalTileCount+tileNoE(bi,bj)-1 |
| 248 |
tileTagRecvE(bi,bj) = theTag |
| 249 |
C o Tag on messages I receive from my west |
| 250 |
theTag = TagE0*totalTileCount+tileNoW(bi,bj)-1 |
| 251 |
tileTagRecvW(bi,bj) = theTag |
| 252 |
C o Tag on messages I receive from my north |
| 253 |
theTag = TagS0*totalTileCount+tileNoN(bi,bj)-1 |
| 254 |
tileTagRecvN(bi,bj) = theTag |
| 255 |
C o Tag on messages I receive from my north |
| 256 |
theTag = TagN0*totalTileCount+tileNoS(bi,bj)-1 |
| 257 |
tileTagRecvS(bi,bj) = theTag |
| 258 |
ENDDO |
| 259 |
ENDDO |
| 260 |
|
| 261 |
C-- Set the form of excahnge to use between neighboring |
| 262 |
C -- tiles. |
| 263 |
C For now use either shared memory, messages or nothing. Further |
| 264 |
C rules can be added later to allow shm regions and ump regions |
| 265 |
C etc... |
| 266 |
C Notes - |
| 267 |
C 1. We require symmetry here. If one face of a tile uses |
| 268 |
C communication method A then the matching face on its neighbor |
| 269 |
C tile must also use communication method A. |
| 270 |
DO bj=myByLo(myThid),myByHi(myThid) |
| 271 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
| 272 |
C o West face communication |
| 273 |
IF ( tileNoW(bi,bj) .EQ. NULL_TILE ) THEN |
| 274 |
tileCommModeW(bi,bj) = COMM_NONE |
| 275 |
ELSE |
| 276 |
IF ( myPid .EQ. tilePidW(bi,bj) ) THEN |
| 277 |
tileCommModeW(bi,bj) = COMM_PUT |
| 278 |
ELSE |
| 279 |
tileCommModeW(bi,bj) = COMM_MSG |
| 280 |
ENDIF |
| 281 |
ENDIF |
| 282 |
C o East face communication |
| 283 |
IF ( tileNoE(bi,bj) .EQ. NULL_TILE ) THEN |
| 284 |
tileCommModeE(bi,bj) = COMM_NONE |
| 285 |
ELSE |
| 286 |
IF ( myPid .EQ. tilePidE(bi,bj) ) THEN |
| 287 |
tileCommModeE(bi,bj) = COMM_PUT |
| 288 |
ELSE |
| 289 |
tileCommModeE(bi,bj) = COMM_MSG |
| 290 |
ENDIF |
| 291 |
ENDIF |
| 292 |
C o South face communication |
| 293 |
IF ( tileNoS(bi,bj) .EQ. NULL_TILE ) THEN |
| 294 |
tileCommModeS(bi,bj) = COMM_NONE |
| 295 |
ELSE |
| 296 |
IF ( myPid .EQ. tilePidS(bi,bj) ) THEN |
| 297 |
tileCommModeS(bi,bj) = COMM_PUT |
| 298 |
ELSE |
| 299 |
tileCommModeS(bi,bj) = COMM_MSG |
| 300 |
ENDIF |
| 301 |
ENDIF |
| 302 |
C o North face communication |
| 303 |
IF ( tileNoN(bi,bj) .EQ. NULL_TILE ) THEN |
| 304 |
tileCommModeN(bi,bj) = COMM_NONE |
| 305 |
ELSE |
| 306 |
IF ( myPid .EQ. tilePidN(bi,bj) ) THEN |
| 307 |
tileCommModeN(bi,bj) = COMM_PUT |
| 308 |
ELSE |
| 309 |
tileCommModeN(bi,bj) = COMM_MSG |
| 310 |
ENDIF |
| 311 |
ENDIF |
| 312 |
|
| 313 |
ENDDO |
| 314 |
ENDDO |
| 315 |
|
| 316 |
C Initialise outstanding exchange request counter |
| 317 |
DO bj=myByLo(myThid),myByHi(myThid) |
| 318 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
| 319 |
exchNReqsX(1,bi,bj) = 0 |
| 320 |
exchNReqsY(1,bi,bj) = 0 |
| 321 |
ENDDO |
| 322 |
ENDDO |
| 323 |
|
| 324 |
RETURN |
| 325 |
END |