1 |
C $Header: /u/gcmpack/MITgcm/pkg/flt/exch2_send_put_vec.F,v 1.2 2012/09/04 00:46:15 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "PACKAGES_CONFIG.h" |
5 |
#include "CPP_EEOPTIONS.h" |
6 |
#undef DBUG_EXCH_VEC |
7 |
|
8 |
C-- Contents |
9 |
C-- o EXCH2_SEND_PUT_VEC_RL |
10 |
|
11 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
12 |
CBOP 0 |
13 |
C !ROUTINE: EXCH2_SEND_PUT_VEC_RL |
14 |
|
15 |
C !INTERFACE: |
16 |
SUBROUTINE EXCH2_SEND_PUT_VEC_RL( |
17 |
I array, |
18 |
O bufRec, |
19 |
O theHandle, |
20 |
I myd1, myThid ) |
21 |
C !DESCRIPTION: |
22 |
C *==========================================================* |
23 |
C | SUBROUTINE EXCH2_SEND_PUT_VEC_RL |
24 |
C | o "Send" or "put" edges for RL array. |
25 |
C *==========================================================* |
26 |
C | Routine that invokes actual message passing send or |
27 |
C | direct "put" of data to update buffer |
28 |
C *==========================================================* |
29 |
|
30 |
C !USES: |
31 |
IMPLICIT NONE |
32 |
|
33 |
C == Global variables == |
34 |
#include "SIZE.h" |
35 |
#include "EEPARAMS.h" |
36 |
#include "EESUPPORT.h" |
37 |
#ifdef ALLOW_EXCH2 |
38 |
#include "W2_EXCH2_SIZE.h" |
39 |
#include "W2_EXCH2_TOPOLOGY.h" |
40 |
#endif |
41 |
|
42 |
C !INPUT/OUTPUT PARAMETERS: |
43 |
C array :: Input buffer array to send to Neighbours |
44 |
C bufRec :: buffer array to collect Neighbour values |
45 |
C myd1 :: size |
46 |
C myThid :: my Thread Id. number |
47 |
INTEGER myd1 |
48 |
_RL array(myd1,nSx,nSy,4) |
49 |
_RL bufRec(myd1,nSx,nSy,4) |
50 |
#ifdef ALLOW_EXCH2 |
51 |
INTEGER theHandle(2,W2_maxNeighbours,nSx,nSy) |
52 |
#else |
53 |
INTEGER theHandle |
54 |
#endif |
55 |
INTEGER myThid |
56 |
CEOP |
57 |
|
58 |
#ifdef ALLOW_EXCH2 |
59 |
|
60 |
C !LOCAL VARIABLES: |
61 |
C I :: Loop counters |
62 |
C bi, bj :: tile indices |
63 |
C theProc :: Variables used in message building |
64 |
C theTag :: Variables used in message building |
65 |
C theType :: Variables used in message building |
66 |
C theSize :: Variables used in message building |
67 |
INTEGER I,J,sBi,sBj, nN, thisTile, tgT, tgN, dir, sDir |
68 |
INTEGER bi, bj |
69 |
#ifdef ALLOW_USE_MPI |
70 |
INTEGER theProc, theTag, theType, theSize, mpiRc |
71 |
#endif |
72 |
#ifdef DBUG_EXCH_VEC |
73 |
INTEGER ioUnit |
74 |
#endif |
75 |
|
76 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
77 |
C-- Write data to exchange buffer |
78 |
C Various actions are possible depending on the communication mode |
79 |
C as follows: |
80 |
C Mode Action |
81 |
C -------- --------------------------- |
82 |
C COMM_NONE Do nothing |
83 |
C |
84 |
C COMM_MSG Message passing communication ( e.g. MPI ) |
85 |
C Fill west send buffer from this tile. |
86 |
C Send data with tag identifying tile and direction. |
87 |
C Fill east send buffer from this tile. |
88 |
C Send data with tag identifying tile and direction. |
89 |
C |
90 |
C COMM_PUT "Put" communication ( UMP_, shmemput, etc... ) |
91 |
C Fill east receive buffer of west-neighbor tile |
92 |
C Fill west receive buffer of east-neighbor tile |
93 |
C Sync. memory |
94 |
C Write data-ready Ack for east edge of west-neighbor tile |
95 |
C Write data-ready Ack for west edge of east-neighbor tile |
96 |
C Sync. memory |
97 |
|
98 |
_BEGIN_MASTER(myThid) |
99 |
|
100 |
#ifdef DBUG_EXCH_VEC |
101 |
ioUnit = errorMessageUnit |
102 |
#endif |
103 |
|
104 |
DO bj=1,nSy |
105 |
DO bi=1,nSx |
106 |
|
107 |
thisTile = W2_myTileList(bi,bj) |
108 |
|
109 |
C- loop over neighboring tiles |
110 |
DO nN=1,exch2_nNeighbours(thisTile) |
111 |
|
112 |
tgT = exch2_neighbourId(nN, thisTile ) |
113 |
dir = exch2_neighbourDir(nN,thisTile) |
114 |
tgN = exch2_opposingSend(nN,thisTIle) |
115 |
sDir = exch2_neighbourDir(tgN,tgT) |
116 |
|
117 |
IF ( W2_myCommFlag(nN,bi,bj) .EQ. 'P' ) THEN |
118 |
C find bi,bj of target tile |
119 |
DO j=1,nSy |
120 |
DO i=1,nSx |
121 |
IF ( W2_myTileList(i,j).EQ.tgT ) THEN |
122 |
sBi = i |
123 |
sBj = j |
124 |
ENDIF |
125 |
ENDDO |
126 |
ENDDO |
127 |
DO I=1,myd1 |
128 |
bufRec(I,sBi,sBj,sDir) = array(I,bi,bj,dir) |
129 |
ENDDO |
130 |
#ifdef ALLOW_USE_MPI |
131 |
ELSEIF ( usingMPI .AND. |
132 |
& W2_myCommFlag(nN,bi,bj) .EQ. 'M' ) THEN |
133 |
C Send the data |
134 |
theProc = W2_tileProc(tgT) - 1 |
135 |
theTag = (thisTile-1)*W2_maxNeighbours + nN |
136 |
theSize = myd1 |
137 |
theType = _MPI_TYPE_RL |
138 |
#ifdef DBUG_EXCH_VEC |
139 |
write(ioUnit,'(A,5I5,I8)') 'qq1xW: ',myProcId,bi,bj, |
140 |
& theProc,theTag, theSize |
141 |
#endif |
142 |
CALL MPI_Isend(array(1,bi,bj,dir), theSize, theType, |
143 |
& theProc, theTag, MPI_COMM_MODEL, |
144 |
& theHandle(1,nN,bi,bj), mpiRc) |
145 |
#endif /* ALLOW_USE_MPI */ |
146 |
ELSE |
147 |
STOP 'S/R EXCH2_SEND_PUT_VEC_RL: Invalid commFlag.' |
148 |
ENDIF |
149 |
|
150 |
C- nN |
151 |
ENDDO |
152 |
|
153 |
C- bj,bi |
154 |
ENDDO |
155 |
ENDDO |
156 |
|
157 |
_END_MASTER(myThid) |
158 |
|
159 |
#endif /* ALLOW_EXCH2 */ |
160 |
|
161 |
RETURN |
162 |
END |