| 1 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/exch_rx_send_put_y.template,v 1.1 2001/05/29 14:06:38 adcroft Exp $ |
| 2 |
C $Name: $ |
| 3 |
#include "CPP_EEOPTIONS.h" |
| 4 |
|
| 5 |
CBOP |
| 6 |
C !ROUTINE: EXCH_RX_SEND_PUT_Y |
| 7 |
|
| 8 |
C !INTERFACE: |
| 9 |
SUBROUTINE EXCH_RX_SEND_PUT_Y( array, |
| 10 |
I myOLw, myOLe, myOLs, myOLn, myNz, |
| 11 |
I exchWidthX, exchWidthY, |
| 12 |
I thesimulationMode, thecornerMode, myThid ) |
| 13 |
IMPLICIT NONE |
| 14 |
C !DESCRIPTION: |
| 15 |
C *==========================================================* |
| 16 |
C | SUBROUTINE SEND_PUT_Y |
| 17 |
C | o "Send" or "put" Y edges for RX array. |
| 18 |
C *==========================================================* |
| 19 |
C | Routine that invokes actual message passing send or |
| 20 |
C | direct "put" of data to update Y faces of an XY[R] array. |
| 21 |
C *==========================================================* |
| 22 |
|
| 23 |
C !USES: |
| 24 |
C == Global variables == |
| 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 array :: Array with edges to exchange. |
| 33 |
C myOLw :: West, East, North and South overlap region sizes. |
| 34 |
C myOLe |
| 35 |
C myOLn |
| 36 |
C myOLs |
| 37 |
C exchWidthX :: Width of data region exchanged. |
| 38 |
C exchWidthY |
| 39 |
C theSimulationMode :: Forward or reverse mode exchange ( provides |
| 40 |
C support for adjoint integration of code. ) |
| 41 |
C Note - the reverse mode for an assignment |
| 42 |
C is an accumulation. This means that |
| 43 |
C put implementations that do leary things |
| 44 |
C like writing to overlap regions in a |
| 45 |
C remote process need to be even more |
| 46 |
C careful. You need to be pretty careful |
| 47 |
C in forward mode too! |
| 48 |
C theCornerMode :: Flag indicating whether corner updates are |
| 49 |
C needed. |
| 50 |
C myThid :: Thread number of this instance of S/R EXCH... |
| 51 |
C eBl :: Edge buffer level |
| 52 |
INTEGER myOLw |
| 53 |
INTEGER myOLe |
| 54 |
INTEGER myOLs |
| 55 |
INTEGER myOLn |
| 56 |
INTEGER myNz |
| 57 |
_RX array(1-myOLw:sNx+myOLe, |
| 58 |
& 1-myOLs:sNy+myOLn, |
| 59 |
& myNZ, nSx, nSy) |
| 60 |
INTEGER exchWidthX |
| 61 |
INTEGER exchWidthY |
| 62 |
INTEGER theSimulationMode |
| 63 |
INTEGER theCornerMode |
| 64 |
INTEGER myThid |
| 65 |
|
| 66 |
C !LOCAL VARIABLES: |
| 67 |
C == Local variables == |
| 68 |
C I, J, K, jMin, jMax, iB - Loop counters and extents |
| 69 |
C bi, bj |
| 70 |
C biS, bjS - South tile indices |
| 71 |
C biN, bjN - North tile indices |
| 72 |
C eBl - Current exchange buffer level |
| 73 |
C theProc, theTag, theType, - Variables used in message building |
| 74 |
C theSize |
| 75 |
C southCommMode - Working variables holding type |
| 76 |
C northCommMode of communication a particular |
| 77 |
C tile face uses. |
| 78 |
INTEGER I, J, K, jMin, jMax, iMin, iMax, iB |
| 79 |
INTEGER bi, bj, biS, bjS, biN, bjN |
| 80 |
INTEGER eBl |
| 81 |
INTEGER northCommMode |
| 82 |
INTEGER southCommMode |
| 83 |
#ifdef ALLOW_USE_MPI |
| 84 |
INTEGER theProc, theTag, theType, theSize, mpiRc |
| 85 |
#endif |
| 86 |
|
| 87 |
C-- Write data to exchange buffer |
| 88 |
C Various actions are possible depending on the communication mode |
| 89 |
C as follows: |
| 90 |
C Mode Action |
| 91 |
C -------- --------------------------- |
| 92 |
C COMM_NONE Do nothing |
| 93 |
C |
| 94 |
C COMM_MSG Message passing communication ( e.g. MPI ) |
| 95 |
C Fill south send buffer from this tile. |
| 96 |
C Send data with tag identifying tile and direction. |
| 97 |
C Fill north send buffer from this tile. |
| 98 |
C Send data with tag identifying tile and direction. |
| 99 |
C |
| 100 |
C COMM_PUT "Put" communication ( UMP_, shmemput, etc... ) |
| 101 |
C Fill south receive buffer of south-neighbor tile |
| 102 |
C Fill north receive buffer of north-neighbor tile |
| 103 |
C Sync. memory |
| 104 |
C Write data-ready Ack for north edge of south-neighbor |
| 105 |
C tile |
| 106 |
C Write data-ready Ack for south edge of north-neighbor |
| 107 |
C tile |
| 108 |
C Sync. memory |
| 109 |
CEOP |
| 110 |
|
| 111 |
C |
| 112 |
DO bj=myByLo(myThid),myByHi(myThid) |
| 113 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
| 114 |
|
| 115 |
ebL = exchangeBufLevel(1,bi,bj) |
| 116 |
southCommMode = _tileCommModeS(bi,bj) |
| 117 |
northCommMode = _tileCommModeN(bi,bj) |
| 118 |
biS = _tileBiS(bi,bj) |
| 119 |
bjS = _tileBjS(bi,bj) |
| 120 |
biN = _tileBiN(bi,bj) |
| 121 |
bjN = _tileBjN(bi,bj) |
| 122 |
iMin = 1 |
| 123 |
iMax = sNx |
| 124 |
IF ( theCornerMode .EQ. EXCH_UPDATE_CORNERS ) THEN |
| 125 |
iMin = 1-exchWidthX |
| 126 |
iMax = sNx+exchWidthX |
| 127 |
ENDIF |
| 128 |
|
| 129 |
|
| 130 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
| 131 |
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
| 132 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
| 133 |
|
| 134 |
C o Send or Put south edge |
| 135 |
IF ( _theSimulationMode .EQ. FORWARD_SIMULATION ) THEN |
| 136 |
jMin = 1 |
| 137 |
jMax = 1+exchWidthY-1 |
| 138 |
IF ( southCommMode .EQ. COMM_MSG ) THEN |
| 139 |
iB = 0 |
| 140 |
DO K=1,myNz |
| 141 |
DO J=jMin,jMax |
| 142 |
DO I=iMin,iMax |
| 143 |
iB = iB + 1 |
| 144 |
southSendBuf_RX(iB,eBl,bi,bj) = array(I,J,K,bi,bj) |
| 145 |
ENDDO |
| 146 |
ENDDO |
| 147 |
ENDDO |
| 148 |
C Send the data |
| 149 |
#ifdef ALLOW_USE_MPI |
| 150 |
#ifndef ALWAYS_USE_MPI |
| 151 |
IF ( usingMPI ) THEN |
| 152 |
#endif |
| 153 |
theProc = tilePidS(bi,bj) |
| 154 |
theTag = _tileTagSendS(bi,bj) |
| 155 |
theSize = iB |
| 156 |
theType = MPI_DOUBLE_PRECISION |
| 157 |
exchNreqsY(1,bi,bj) = exchNreqsY(1,bi,bj)+1 |
| 158 |
CALL MPI_Isend(southSendBuf_RX(1,eBl,bi,bj), theSize, theType, |
| 159 |
& theProc, theTag, MPI_COMM_MODEL, |
| 160 |
& exchReqIdY(exchNreqsY(1,bi,bj),1,bi,bj), mpiRc) |
| 161 |
#ifndef ALWAYS_USE_MPI |
| 162 |
ENDIF |
| 163 |
#endif |
| 164 |
#endif /* ALLOW_USE_MPI */ |
| 165 |
northRecvAck(eBl,biS,bjS) = 1. |
| 166 |
ELSEIF ( southCommMode .EQ. COMM_PUT ) THEN |
| 167 |
iB = 0 |
| 168 |
DO K=1,myNz |
| 169 |
DO J=jMin,jMax |
| 170 |
DO I=iMin,iMax |
| 171 |
iB = iB + 1 |
| 172 |
northRecvBuf_RX(iB,eBl,biS,bjS) = array(I,J,K,bi,bj) |
| 173 |
ENDDO |
| 174 |
ENDDO |
| 175 |
ENDDO |
| 176 |
ELSEIF ( southCommMode .NE. COMM_NONE |
| 177 |
& .AND. southCommMode .NE. COMM_GET ) THEN |
| 178 |
STOP ' S/R EXCH: Invalid commS mode.' |
| 179 |
ENDIF |
| 180 |
|
| 181 |
C o Send or Put north edge |
| 182 |
jMin = sNy-exchWidthY+1 |
| 183 |
jMax = sNy |
| 184 |
IF ( northCommMode .EQ. COMM_MSG ) THEN |
| 185 |
iB = 0 |
| 186 |
DO K=1,myNz |
| 187 |
DO J=jMin,jMax |
| 188 |
DO I=iMin,iMax |
| 189 |
iB = iB + 1 |
| 190 |
northSendBuf_RX(iB,eBl,bi,bj) = array(I,J,K,bi,bj) |
| 191 |
ENDDO |
| 192 |
ENDDO |
| 193 |
ENDDO |
| 194 |
C Send the data |
| 195 |
#ifdef ALLOW_USE_MPI |
| 196 |
#ifndef ALWAYS_USE_MPI |
| 197 |
IF ( usingMPI ) THEN |
| 198 |
#endif |
| 199 |
theProc = tilePidN(bi,bj) |
| 200 |
theTag = _tileTagSendN(bi,bj) |
| 201 |
theSize = iB |
| 202 |
theType = MPI_DOUBLE_PRECISION |
| 203 |
exchNreqsY(1,bi,bj) = exchNreqsY(1,bi,bj)+1 |
| 204 |
CALL MPI_Isend(northSendBuf_RX(1,eBl,bi,bj), theSize, theType, |
| 205 |
& theProc, theTag, MPI_COMM_MODEL, |
| 206 |
& exchReqIdY(exchNreqsY(1,bi,bj),1,bi,bj), mpiRc ) |
| 207 |
#ifndef ALWAYS_USE_MPI |
| 208 |
ENDIF |
| 209 |
#endif |
| 210 |
#endif /* ALLOW_USE_MPI */ |
| 211 |
southRecvAck(eBl,biN,bjN) = 1. |
| 212 |
ELSEIF ( northCommMode .EQ. COMM_PUT ) THEN |
| 213 |
iB = 0 |
| 214 |
DO K=1,myNz |
| 215 |
DO J=jMin,jMax |
| 216 |
DO I=iMin,iMax |
| 217 |
iB = iB + 1 |
| 218 |
southRecvBuf_RX(iB,eBl,biN,bjN) = array(I,J,K,bi,bj) |
| 219 |
ENDDO |
| 220 |
ENDDO |
| 221 |
ENDDO |
| 222 |
ELSEIF ( northCommMode .NE. COMM_NONE |
| 223 |
& .AND. northCommMode .NE. COMM_GET ) THEN |
| 224 |
STOP ' S/R EXCH: Invalid commN mode.' |
| 225 |
ENDIF |
| 226 |
|
| 227 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
| 228 |
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
| 229 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
| 230 |
|
| 231 |
ELSEIF ( _theSimulationMode .EQ. REVERSE_SIMULATION ) THEN |
| 232 |
jMin = 1-exchWidthY |
| 233 |
jMax = 0 |
| 234 |
IF ( southCommMode .EQ. COMM_MSG ) THEN |
| 235 |
iB = 0 |
| 236 |
DO K=1,myNz |
| 237 |
DO J=jMin,jMax |
| 238 |
DO I=iMin,iMax |
| 239 |
iB = iB + 1 |
| 240 |
southSendBuf_RX(iB,eBl,bi,bj) = array(I,J,K,bi,bj) |
| 241 |
array(I,J,K,bi,bj) = 0.0 |
| 242 |
ENDDO |
| 243 |
ENDDO |
| 244 |
ENDDO |
| 245 |
C Send the data |
| 246 |
#ifdef ALLOW_USE_MPI |
| 247 |
#ifndef ALWAYS_USE_MPI |
| 248 |
IF ( usingMPI ) THEN |
| 249 |
#endif |
| 250 |
theProc = tilePidS(bi,bj) |
| 251 |
theTag = _tileTagSendS(bi,bj) |
| 252 |
theSize = iB |
| 253 |
theType = MPI_DOUBLE_PRECISION |
| 254 |
exchNreqsY(1,bi,bj) = exchNreqsY(1,bi,bj)+1 |
| 255 |
CALL MPI_Isend(southSendBuf_RX(1,eBl,bi,bj), theSize, theType, |
| 256 |
& theProc, theTag, MPI_COMM_MODEL, |
| 257 |
& exchReqIdY(exchNreqsY(1,bi,bj),1,bi,bj), mpiRc) |
| 258 |
#ifndef ALWAYS_USE_MPI |
| 259 |
ENDIF |
| 260 |
#endif |
| 261 |
#endif /* ALLOW_USE_MPI */ |
| 262 |
northRecvAck(eBl,biS,bjS) = 1. |
| 263 |
ELSEIF ( southCommMode .EQ. COMM_PUT ) THEN |
| 264 |
iB = 0 |
| 265 |
DO K=1,myNz |
| 266 |
DO J=jMin,jMax |
| 267 |
DO I=iMin,iMax |
| 268 |
iB = iB + 1 |
| 269 |
northRecvBuf_RX(iB,eBl,biS,bjS) = array(I,J,K,bi,bj) |
| 270 |
array(I,J,K,bi,bj) = 0.0 |
| 271 |
ENDDO |
| 272 |
ENDDO |
| 273 |
ENDDO |
| 274 |
ELSEIF ( southCommMode .NE. COMM_NONE |
| 275 |
& .AND. southCommMode .NE. COMM_GET ) THEN |
| 276 |
STOP ' S/R EXCH: Invalid commS mode.' |
| 277 |
ENDIF |
| 278 |
|
| 279 |
C o Send or Put north edge |
| 280 |
jMin = sNy+1 |
| 281 |
jMax = sNy+exchWidthY |
| 282 |
IF ( northCommMode .EQ. COMM_MSG ) THEN |
| 283 |
iB = 0 |
| 284 |
DO K=1,myNz |
| 285 |
DO J=jMin,jMax |
| 286 |
DO I=iMin,iMax |
| 287 |
iB = iB + 1 |
| 288 |
northSendBuf_RX(iB,eBl,bi,bj) = array(I,J,K,bi,bj) |
| 289 |
array(I,J,K,bi,bj) = 0.0 |
| 290 |
ENDDO |
| 291 |
ENDDO |
| 292 |
ENDDO |
| 293 |
C Send the data |
| 294 |
#ifdef ALLOW_USE_MPI |
| 295 |
#ifndef ALWAYS_USE_MPI |
| 296 |
IF ( usingMPI ) THEN |
| 297 |
#endif |
| 298 |
theProc = tilePidN(bi,bj) |
| 299 |
theTag = _tileTagSendN(bi,bj) |
| 300 |
theSize = iB |
| 301 |
theType = MPI_DOUBLE_PRECISION |
| 302 |
exchNreqsY(1,bi,bj) = exchNreqsY(1,bi,bj)+1 |
| 303 |
CALL MPI_Isend(northSendBuf_RX(1,eBl,bi,bj), theSize, theType, |
| 304 |
& theProc, theTag, MPI_COMM_MODEL, |
| 305 |
& exchReqIdY(exchNreqsY(1,bi,bj),1,bi,bj), mpiRc ) |
| 306 |
#ifndef ALWAYS_USE_MPI |
| 307 |
ENDIF |
| 308 |
#endif |
| 309 |
#endif /* ALLOW_USE_MPI */ |
| 310 |
southRecvAck(eBl,biN,bjN) = 1. |
| 311 |
ELSEIF ( northCommMode .EQ. COMM_PUT ) THEN |
| 312 |
iB = 0 |
| 313 |
DO K=1,myNz |
| 314 |
DO J=jMin,jMax |
| 315 |
DO I=iMin,iMax |
| 316 |
iB = iB + 1 |
| 317 |
southRecvBuf_RX(iB,eBl,biN,bjN) = array(I,J,K,bi,bj) |
| 318 |
array(I,J,K,bi,bj) = 0.0 |
| 319 |
ENDDO |
| 320 |
ENDDO |
| 321 |
ENDDO |
| 322 |
ELSEIF ( northCommMode .NE. COMM_NONE |
| 323 |
& .AND. northCommMode .NE. COMM_GET ) THEN |
| 324 |
STOP ' S/R EXCH: Invalid commN mode.' |
| 325 |
ENDIF |
| 326 |
endif |
| 327 |
ENDDO |
| 328 |
ENDDO |
| 329 |
|
| 330 |
C-- Signal completetion ( making sure system-wide memory state is |
| 331 |
C-- consistent ). |
| 332 |
|
| 333 |
C ** NOTE ** We are relying on being able to produce strong-ordered |
| 334 |
C memory semantics here. In other words we assume that there is a |
| 335 |
C mechanism which can ensure that by the time the Ack is seen the |
| 336 |
C overlap region data that will be exchanged is up to date. |
| 337 |
IF ( exchNeedsMemSync ) CALL MEMSYNC |
| 338 |
|
| 339 |
DO bj=myByLo(myThid),myByHi(myThid) |
| 340 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
| 341 |
ebL = exchangeBufLevel(1,bi,bj) |
| 342 |
biS = _tileBiS(bi,bj) |
| 343 |
bjS = _tileBjS(bi,bj) |
| 344 |
biN = _tileBiN(bi,bj) |
| 345 |
bjN = _tileBjN(bi,bj) |
| 346 |
southCommMode = _tileCommModeS(bi,bj) |
| 347 |
northCommMode = _tileCommModeN(bi,bj) |
| 348 |
IF ( southCommMode .EQ. COMM_PUT ) northRecvAck(eBl,biS,bjS) = 1. |
| 349 |
IF ( northCommMode .EQ. COMM_PUT ) southRecvAck(eBl,biN,bjN) = 1. |
| 350 |
IF ( southCommMode .EQ. COMM_GET ) northRecvAck(eBl,biS,bjS) = 1. |
| 351 |
IF ( northCommMode .EQ. COMM_GET ) southRecvAck(eBl,biN,bjN) = 1. |
| 352 |
ENDDO |
| 353 |
ENDDO |
| 354 |
|
| 355 |
C-- Make sure "ack" setting is seen system-wide. |
| 356 |
C Here strong-ordering is not an issue but we want to make |
| 357 |
C sure that processes that might spin on the above Ack settings |
| 358 |
C will see the setting. |
| 359 |
C ** NOTE ** On some machines we wont spin on the Ack setting |
| 360 |
C ( particularly the T90 ), instead we will use s system barrier. |
| 361 |
C On the T90 the system barrier is very fast and switches out the |
| 362 |
C thread while it waits. On most machines the system barrier |
| 363 |
C is much too slow and if we own the machine and have one thread |
| 364 |
C per process preemption is not a problem. |
| 365 |
IF ( exchNeedsMemSync ) CALL MEMSYNC |
| 366 |
|
| 367 |
RETURN |
| 368 |
END |