1 |
jmc |
1.6 |
C $Header: /u/gcmpack/MITgcm/pkg/exch2/w2_set_map_tiles.F,v 1.5 2011/07/09 21:53:35 jmc Exp $ |
2 |
jmc |
1.1 |
C $Name: $ |
3 |
|
|
|
4 |
|
|
#include "CPP_EEOPTIONS.h" |
5 |
|
|
#include "W2_OPTIONS.h" |
6 |
|
|
|
7 |
jmc |
1.3 |
C-- File w2_set_map_tiles.F: |
8 |
|
|
C-- Contents |
9 |
|
|
C-- o W2_SET_MAP_TILES :: Set tiles and IO mapping |
10 |
|
|
C-- o FIND_GCD_N :: Returns the Greatest Common Divisor |
11 |
|
|
|
12 |
jmc |
1.1 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
13 |
|
|
CBOP 0 |
14 |
|
|
C !ROUTINE: W2_SET_MAP_TILES |
15 |
|
|
|
16 |
|
|
C !INTERFACE: |
17 |
|
|
SUBROUTINE W2_SET_MAP_TILES( myThid ) |
18 |
|
|
|
19 |
|
|
C !DESCRIPTION: |
20 |
|
|
C Set-up tiles mapping and IO global mapping |
21 |
|
|
|
22 |
|
|
C !USES: |
23 |
|
|
IMPLICIT NONE |
24 |
|
|
|
25 |
jmc |
1.3 |
C Tile topology settings data structures |
26 |
jmc |
1.1 |
#include "SIZE.h" |
27 |
|
|
#include "EEPARAMS.h" |
28 |
|
|
#include "W2_EXCH2_SIZE.h" |
29 |
|
|
#include "W2_EXCH2_PARAMS.h" |
30 |
|
|
#include "W2_EXCH2_TOPOLOGY.h" |
31 |
|
|
|
32 |
|
|
C !INPUT PARAMETERS: |
33 |
|
|
C myThid :: my Thread Id number |
34 |
|
|
C (Note: not relevant since threading has not yet started) |
35 |
|
|
INTEGER myThid |
36 |
|
|
|
37 |
|
|
C !FUNCTIONS: |
38 |
|
|
INTEGER FIND_GCD_N |
39 |
|
|
EXTERNAL FIND_GCD_N |
40 |
|
|
|
41 |
|
|
C !LOCAL VARIABLES: |
42 |
|
|
C === Local variables === |
43 |
jmc |
1.3 |
C msgBuf :: Informational/error message buffer |
44 |
jmc |
1.1 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
45 |
jahn |
1.4 |
INTEGER tNx, tNy, fNx, fNy, nbPts, fBaseX, fBaseY |
46 |
jmc |
1.1 |
INTEGER nbTx, nbTy |
47 |
|
|
INTEGER j, ii, k, tId, tx, ty |
48 |
jmc |
1.3 |
INTEGER divide, nnx(W2_maxNbFacets) |
49 |
jmc |
1.1 |
INTEGER errCnt, tCnt |
50 |
jmc |
1.2 |
LOGICAL tileIsActive, prtFlag |
51 |
jmc |
1.1 |
CEOP |
52 |
|
|
|
53 |
|
|
C Set-up tiles mapping and IO global mapping |
54 |
|
|
WRITE(msgBuf,'(2A)') 'W2_SET_MAP_TILES:', |
55 |
|
|
& ' tile mapping within facet and global Map:' |
56 |
|
|
CALL PRINT_MESSAGE( msgBuf, W2_oUnit, SQUEEZE_RIGHT, myThid ) |
57 |
|
|
prtFlag = ABS(W2_printMsg).GE.2 |
58 |
|
|
& .OR. ( W2_printMsg .NE.0 .AND. myProcId.EQ.0 ) |
59 |
|
|
|
60 |
|
|
tNx = sNx |
61 |
|
|
tNy = sNy |
62 |
jmc |
1.3 |
C-- Check that tile dims divide facet dims |
63 |
jmc |
1.1 |
errCnt = 0 |
64 |
|
|
tCnt = 0 |
65 |
|
|
nbPts = 0 |
66 |
|
|
DO j=1,nFacets |
67 |
|
|
fNx = facet_dims(2*j-1) |
68 |
|
|
fNy = facet_dims( 2*j ) |
69 |
|
|
nbTx = fNx/tNx |
70 |
|
|
nbTy = fNy/tNy |
71 |
|
|
IF ( nbTx*tNx .NE. fNx ) THEN |
72 |
|
|
WRITE(msgBuf,'(A,I3,2(A,I7))') 'Facet',j, |
73 |
|
|
& ' : X-size=', fNx, ' not multiple of sNx=', tNx |
74 |
|
|
CALL PRINT_ERROR( msgBuf, myThid ) |
75 |
|
|
errCnt = errCnt + 1 |
76 |
|
|
ENDIF |
77 |
|
|
IF ( nbTy*tNy .NE. fNy ) THEN |
78 |
|
|
WRITE(msgBuf,'(A,I3,2(A,I7))') 'Facet',j, |
79 |
|
|
& ' : Y-size=', fNy, ' not multiple of sNy=', tNy |
80 |
|
|
CALL PRINT_ERROR( msgBuf, myThid ) |
81 |
|
|
errCnt = errCnt + 1 |
82 |
|
|
ENDIF |
83 |
|
|
facet_owns(1,j) = tCnt+1 |
84 |
|
|
tCnt = tCnt + nbTx*nbTy |
85 |
|
|
facet_owns(2,j) = tCnt |
86 |
|
|
nbPts = nbPts + fNx*fNy |
87 |
|
|
ENDDO |
88 |
|
|
IF ( errCnt.GT.0 ) THEN |
89 |
|
|
WRITE(msgBuf,'(A,I3,A)') |
90 |
|
|
& ' W2_SET_MAP_TILES: found', errCnt, ' Fatal errors' |
91 |
|
|
CALL PRINT_ERROR( msgBuf, myThid ) |
92 |
|
|
STOP 'ABNORMAL END: S/R W2_SET_MAP_TILES' |
93 |
|
|
ENDIF |
94 |
|
|
C-- Check that domain size and (SIZE.h + blankList) match: |
95 |
jmc |
1.5 |
IF ( tCnt.NE.exch2_nTiles ) THEN |
96 |
jmc |
1.1 |
WRITE(msgBuf,'(A,I6,A)') |
97 |
|
|
& 'W2_SET_MAP_TILES: Domain Total # of tiles =', tCnt, ' does' |
98 |
|
|
CALL PRINT_ERROR( msgBuf, myThid ) |
99 |
|
|
WRITE(msgBuf,'(A,I6)') |
100 |
jmc |
1.5 |
& 'W2_SET_MAP_TILES: not match (SIZE.h+blankList)=',exch2_nTiles |
101 |
jmc |
1.1 |
CALL PRINT_ERROR( msgBuf, myThid ) |
102 |
|
|
STOP 'ABNORMAL END: S/R W2_SET_MAP_TILES' |
103 |
|
|
ENDIF |
104 |
|
|
|
105 |
|
|
IF ( W2_mapIO.EQ.1 ) THEN |
106 |
|
|
C-- Compact IO map (mostly in Y dir): search for Greatest Common Divisor |
107 |
|
|
C of all x-size (faster to apply GCD to Nb of Tiles in X): |
108 |
jmc |
1.6 |
k = 0 |
109 |
|
|
nnx(1) = 0 |
110 |
jmc |
1.1 |
DO j=1,nFacets |
111 |
jmc |
1.6 |
C skip empty facet |
112 |
|
|
IF ( facet_dims(2*j-1).GT.0 ) THEN |
113 |
|
|
k = k + 1 |
114 |
|
|
nnx(k) = facet_dims(2*j-1)/tNx |
115 |
|
|
ENDIF |
116 |
jmc |
1.1 |
ENDDO |
117 |
jmc |
1.6 |
divide = FIND_GCD_N( nnx, k ) |
118 |
jmc |
1.3 |
W2_mapIO = divide*tNx |
119 |
jmc |
1.1 |
WRITE(msgBuf,'(A,2(I5,A))') ' W2_mapIO =', W2_mapIO, |
120 |
jmc |
1.3 |
& ' (=', divide, '*sNx)' |
121 |
jmc |
1.1 |
CALL PRINT_MESSAGE( msgBuf, W2_oUnit, SQUEEZE_RIGHT, myThid ) |
122 |
|
|
ENDIF |
123 |
|
|
|
124 |
|
|
C-- Global Map size: |
125 |
jahn |
1.4 |
C facets stacked in x direction |
126 |
|
|
exch2_xStack_Nx = 0 |
127 |
|
|
exch2_xStack_Ny = 0 |
128 |
|
|
DO j=1,nFacets |
129 |
|
|
exch2_xStack_Nx = exch2_xStack_Nx + facet_dims(2*j-1) |
130 |
|
|
exch2_xStack_Ny = MAX( exch2_xStack_Ny, facet_dims(2*j) ) |
131 |
|
|
ENDDO |
132 |
|
|
C facets stacked in y direction |
133 |
|
|
exch2_yStack_Nx = 0 |
134 |
|
|
exch2_yStack_Ny = 0 |
135 |
|
|
DO j=1,nFacets |
136 |
|
|
exch2_yStack_Nx = MAX( exch2_yStack_Nx, facet_dims(2*j-1) ) |
137 |
|
|
exch2_yStack_Ny = exch2_yStack_Ny + facet_dims(2*j) |
138 |
|
|
ENDDO |
139 |
jmc |
1.1 |
IF ( W2_mapIO.EQ.-1 ) THEN |
140 |
jahn |
1.4 |
exch2_global_Nx = exch2_xStack_Nx |
141 |
|
|
exch2_global_Ny = exch2_xStack_Ny |
142 |
jmc |
1.1 |
ELSEIF ( W2_mapIO.EQ.0 ) THEN |
143 |
|
|
exch2_global_Nx = nbPts |
144 |
|
|
exch2_global_Ny = 1 |
145 |
|
|
ELSE |
146 |
|
|
exch2_global_Nx = W2_mapIO |
147 |
|
|
exch2_global_Ny = nbPts/W2_mapIO |
148 |
|
|
ENDIF |
149 |
|
|
WRITE(msgBuf,'(A,2(A,I8))') ' Global Map (IO):', |
150 |
|
|
& ' X-size=', exch2_global_Nx, ' , Y-size=', exch2_global_Ny |
151 |
|
|
CALL PRINT_MESSAGE( msgBuf, W2_oUnit, SQUEEZE_RIGHT, myThid ) |
152 |
|
|
|
153 |
|
|
C-- Set tiles mapping within facet (sub-domain) and within Global Map |
154 |
|
|
WRITE(msgBuf,'(2A)') 'W2_SET_MAP_TILES:', |
155 |
|
|
& ' tile offset within facet and global Map:' |
156 |
|
|
CALL PRINT_MESSAGE( msgBuf, W2_oUnit, SQUEEZE_RIGHT, myThid ) |
157 |
|
|
tId = 0 |
158 |
|
|
nbPts = 0 |
159 |
|
|
fBaseX = 0 |
160 |
jahn |
1.4 |
fBaseY = 0 |
161 |
jmc |
1.1 |
DO j=1,nFacets |
162 |
|
|
fNx = facet_dims(2*j-1) |
163 |
|
|
fNy = facet_dims( 2*j ) |
164 |
|
|
nbTx = fNx/tNx |
165 |
|
|
nbTy = fNy/tNy |
166 |
|
|
WRITE(W2_oUnit,'(A,I3,2(A,I6),A,I5,2(A,I4),A)') |
167 |
|
|
& '- facet', j, ' : X-size=', fNx, ' , Y-size=', fNy, |
168 |
|
|
& ' ;', nbTx*nbTy, ' tiles (Tx,Ty=', nbTx,',',nbTy,')' |
169 |
|
|
c CALL PRINT_MESSAGE( msgBuf, W2_oUnit, SQUEEZE_RIGHT, myThid ) |
170 |
|
|
DO ty=1,nbTy |
171 |
|
|
DO tx=1,nbTx |
172 |
|
|
tId = tId + 1 |
173 |
|
|
C-- Tags blank tile by removing facet # (exch2_myFace) but keeps its location |
174 |
|
|
tileIsActive = .TRUE. |
175 |
|
|
DO k=1,nBlankTiles |
176 |
|
|
IF ( blankList(k).EQ.tId ) tileIsActive = .FALSE. |
177 |
|
|
ENDDO |
178 |
|
|
IF ( tileIsActive ) exch2_myFace(tId) = j |
179 |
|
|
exch2_mydNx ( tId ) = fNx |
180 |
|
|
exch2_mydNy ( tId ) = fNy |
181 |
|
|
exch2_tNx ( tId ) = tNx |
182 |
|
|
exch2_tNy ( tId ) = tNy |
183 |
|
|
exch2_tBasex( tId ) = (tx-1)*tNx |
184 |
|
|
exch2_tBasey( tId ) = (ty-1)*tNy |
185 |
jahn |
1.4 |
C-- Global IO Mappings |
186 |
|
|
C these are for OBCS (vertical slices) |
187 |
|
|
exch2_txXStackLo( tId ) = 1 + exch2_tBasex(tId) + fBaseX |
188 |
|
|
exch2_tyXStackLo( tId ) = 1 + exch2_tBasey(tId) |
189 |
|
|
exch2_txYStackLo( tId ) = 1 + exch2_tBasex(tId) |
190 |
|
|
exch2_tyYStackLo( tId ) = 1 + exch2_tBasey(tId) + fBaseY |
191 |
|
|
C and these for global files (3d files/horizontal 2d files) |
192 |
jmc |
1.1 |
IF ( W2_mapIO.EQ.-1 ) THEN |
193 |
|
|
C- Old format |
194 |
|
|
exch2_txGlobalo( tId ) = 1 + exch2_tBasex(tId) + fBaseX |
195 |
|
|
exch2_tyGlobalo( tId ) = 1 + exch2_tBasey(tId) |
196 |
|
|
ELSEIF ( W2_mapIO.EQ.0 ) THEN |
197 |
|
|
C- Compact format = 1 long line |
198 |
|
|
ii = nbPts + exch2_tBasex(tId) + exch2_tBasey(tId)*fNx |
199 |
|
|
exch2_txGlobalo( tId ) = 1 + ii |
200 |
|
|
exch2_tyGlobalo( tId ) = 1 |
201 |
|
|
ELSE |
202 |
|
|
C Compact format: piled in the Y direction |
203 |
|
|
ii = nbPts + exch2_tBasex(tId) + exch2_tBasey(tId)*fNx |
204 |
|
|
exch2_txGlobalo( tId ) = 1 + MOD(ii,W2_mapIO) |
205 |
|
|
exch2_tyGlobalo( tId ) = 1 + ii/W2_mapIO |
206 |
|
|
ENDIF |
207 |
|
|
IF ( prtFlag ) |
208 |
|
|
& WRITE(W2_oUnit,'(A,I5,3(A,I3),2A,2I5,2A,2I8)') ' tile',tId, |
209 |
|
|
& ' on facet', exch2_myFace(tId),' (',tx,',',ty,'):', |
210 |
|
|
& ' offset=', exch2_tBasex(tId), exch2_tBasey(tId),' ;', |
211 |
|
|
& ' on Glob.Map=', exch2_txGlobalo(tId),exch2_tyGlobalo(tId) |
212 |
|
|
ENDDO |
213 |
|
|
ENDDO |
214 |
|
|
fBaseX = fBaseX + fNx |
215 |
jahn |
1.4 |
fBaseY = fBaseY + fNy |
216 |
jmc |
1.1 |
nbPts = nbPts + fNx*fNy |
217 |
|
|
ENDDO |
218 |
|
|
|
219 |
|
|
RETURN |
220 |
|
|
END |
221 |
|
|
|
222 |
|
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
223 |
|
|
CBOP |
224 |
|
|
C !ROUTINE: FIND_GCD_N |
225 |
|
|
|
226 |
|
|
C !INTERFACE: |
227 |
|
|
INTEGER FUNCTION FIND_GCD_N( fldList, nFld ) |
228 |
|
|
|
229 |
|
|
C !DESCRIPTION: |
230 |
|
|
C *==========================================================* |
231 |
|
|
C | FUNCTION FIND_GCD_N |
232 |
|
|
C | o Find the Greatest Common Divisor of N integers |
233 |
|
|
C *==========================================================* |
234 |
|
|
|
235 |
|
|
C !USES: |
236 |
|
|
IMPLICIT NONE |
237 |
|
|
|
238 |
|
|
C !INPUT PARAMETERS: |
239 |
|
|
C fldList :: list of integers to search for GCD |
240 |
|
|
C nFLd :: length of the input integer list. |
241 |
|
|
INTEGER nFLd |
242 |
|
|
INTEGER fldList(nFld) |
243 |
|
|
|
244 |
|
|
C !LOCAL VARIABLES: |
245 |
jmc |
1.3 |
INTEGER mnFld, divide |
246 |
jmc |
1.1 |
INTEGER j, ii |
247 |
|
|
LOGICAL flag |
248 |
|
|
LOGICAL localDBg |
249 |
|
|
CEOP |
250 |
|
|
PARAMETER ( localDBg = .FALSE. ) |
251 |
|
|
c PARAMETER ( localDBg = .TRUE. ) |
252 |
|
|
|
253 |
|
|
mnFld = fldList(1) |
254 |
|
|
DO j=1,nFld |
255 |
|
|
mnFld = MIN( mnFld, fldList(j) ) |
256 |
|
|
ENDDO |
257 |
|
|
IF (localDBg) WRITE(0,'(A,I8)') 'FIND_GCD_N: mnFld=',mnFld |
258 |
|
|
|
259 |
|
|
IF (mnFld.GT.1 ) THEN |
260 |
jmc |
1.3 |
divide = 1 |
261 |
jmc |
1.1 |
ii = 2 |
262 |
|
|
DO WHILE ( ii.LE.mnFld ) |
263 |
|
|
IF (localDBg) WRITE(0,'(A,I8)') ' GCD : try',ii |
264 |
|
|
flag = .TRUE. |
265 |
|
|
DO j=1,nFld |
266 |
|
|
flag = flag.AND.(MOD(fldList(j),ii).EQ.0 ) |
267 |
|
|
ENDDO |
268 |
|
|
IF ( flag ) THEN |
269 |
jmc |
1.3 |
divide = divide*ii |
270 |
jmc |
1.1 |
DO j=1,nFld |
271 |
|
|
fldList(j) = fldList(j)/ii |
272 |
|
|
ENDDO |
273 |
|
|
IF (localDBg) WRITE(0,'(A,I8)') |
274 |
|
|
& 'FIND_GCD_N: com.fact=',ii |
275 |
|
|
mnFld = mnFld/ii |
276 |
|
|
ELSE |
277 |
|
|
ii = ii+2 |
278 |
|
|
IF (ii.EQ.4) ii=3 |
279 |
|
|
ENDIF |
280 |
|
|
ENDDO |
281 |
jmc |
1.3 |
C- Put back the original Nb: |
282 |
jmc |
1.1 |
IF (localDBg) WRITE(0,'(10I8)') (fldList(j),j=1,nFld) |
283 |
|
|
DO j=1,nFld |
284 |
jmc |
1.3 |
fldList(j) = fldList(j)*divide |
285 |
jmc |
1.1 |
ENDDO |
286 |
|
|
ELSE |
287 |
jmc |
1.3 |
divide = MAX( 0, mnFld ) |
288 |
jmc |
1.1 |
ENDIF |
289 |
|
|
|
290 |
jmc |
1.3 |
FIND_GCD_N = divide |
291 |
jmc |
1.1 |
|
292 |
|
|
RETURN |
293 |
|
|
END |