1 |
cnh |
1.8 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/ini_threading_environment.F,v 1.7 2001/02/04 14:38:43 cnh Exp $ |
2 |
|
|
C $Name: $ |
3 |
cnh |
1.1 |
|
4 |
|
|
#include "CPP_EEOPTIONS.h" |
5 |
|
|
|
6 |
cnh |
1.8 |
CBOP |
7 |
|
|
|
8 |
|
|
C !ROUTINE: INI_THREADING_ENVIRONMENT |
9 |
|
|
|
10 |
|
|
C !INTERFACE: |
11 |
cnh |
1.1 |
SUBROUTINE INI_THREADING_ENVIRONMENT |
12 |
adcroft |
1.6 |
IMPLICIT NONE |
13 |
cnh |
1.1 |
|
14 |
cnh |
1.8 |
C !DESCRIPTION: |
15 |
|
|
C *==========================================================* |
16 |
|
|
C | SUBROUTINE INI_THREADING_ENVIRONMENT |
17 |
|
|
C | o Initialise multi-threaded environment. |
18 |
|
|
C *==========================================================* |
19 |
|
|
C | Generally we do not start separate threads here. |
20 |
|
|
C | The separate threads a spawned at later on. |
21 |
|
|
C | Here we perform initialisation of data-structures |
22 |
|
|
C | that indicate which of the nSx x nSy tiles a thread is |
23 |
|
|
C | responsible for. |
24 |
|
|
C | The multiple threads are spawned in the top level MAIN |
25 |
|
|
C | routine. |
26 |
|
|
C *==========================================================* |
27 |
|
|
|
28 |
|
|
C !USES: |
29 |
cnh |
1.1 |
C == Global data == |
30 |
|
|
#include "SIZE.h" |
31 |
|
|
#include "EEPARAMS.h" |
32 |
|
|
#include "EESUPPORT.h" |
33 |
|
|
|
34 |
cnh |
1.8 |
C !LOCAL VARIABLES: |
35 |
cnh |
1.1 |
C == Local variables == |
36 |
|
|
C bXPerThread - Blocks of size sNx per thread. |
37 |
|
|
C byPerThread - Blocks of size sNy per thread. |
38 |
|
|
C Thid - Thread index. Temporary used in loops |
39 |
|
|
C which set per. thread values on a |
40 |
|
|
C cartesian grid. |
41 |
|
|
C bxLo, bxHi - Work vars. for thread index |
42 |
|
|
C byLo, byHi range. bxLo is the lowest i index |
43 |
|
|
C that a thread covers, bxHi is the |
44 |
|
|
C highest i index. byLo is the lowest |
45 |
|
|
C j index, byHi is the highest j index. |
46 |
|
|
C I, J - Loop counter |
47 |
|
|
C msgBuf - I/O buffer for reporting status information. |
48 |
|
|
C myThid - Dummy thread id for use in printed messages |
49 |
cnh |
1.5 |
C ( this routine "INI_THREADING_ENVIRONMENT" is |
50 |
|
|
C called before multi-threading has started.) |
51 |
cnh |
1.1 |
INTEGER bxPerThread |
52 |
|
|
INTEGER byPerThread |
53 |
|
|
INTEGER Thid |
54 |
|
|
INTEGER bxLo, bxHi |
55 |
|
|
INTEGER byLo, byHi |
56 |
cnh |
1.5 |
INTEGER I, J, nT |
57 |
cnh |
1.1 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
58 |
|
|
INTEGER myThid |
59 |
cnh |
1.8 |
|
60 |
|
|
CEOP |
61 |
cnh |
1.1 |
|
62 |
|
|
C-- Set default for all threads of having no blocks to |
63 |
|
|
C-- work on - except for thread 1. |
64 |
|
|
myBxLo(1) = 1 |
65 |
|
|
myBxHi(1) = nSx |
66 |
|
|
myByLo(1) = 1 |
67 |
|
|
myByHi(1) = nSy |
68 |
|
|
DO I = 2, MAX_NO_THREADS |
69 |
|
|
myBxLo(I) = 0 |
70 |
cnh |
1.5 |
myBxHi(I) = 0 |
71 |
cnh |
1.1 |
myByLo(I) = 0 |
72 |
cnh |
1.5 |
myByHi(I) = 0 |
73 |
cnh |
1.1 |
ENDDO |
74 |
|
|
myThid = 1 |
75 |
cnh |
1.5 |
commName(COMM_NONE) = 'none' |
76 |
|
|
commName(COMM_MSG ) = 'messages' |
77 |
|
|
commName(COMM_PUT ) = 'put' |
78 |
|
|
commName(COMM_GET ) = 'get' |
79 |
cnh |
1.1 |
|
80 |
|
|
C-- If there are multiple threads allocate different range of the |
81 |
|
|
C-- nSx*nSy blocks to each thread. |
82 |
|
|
C For now handle simple case of no. blocks nSx = n*nTx and |
83 |
|
|
C no. blocks nSy = m*nTy ( where m and n are integer ). This |
84 |
|
|
C is handled by simply mapping threads to blocks in sequence |
85 |
|
|
C with the x thread index moving fastest. |
86 |
|
|
C Later code which sets the thread number of neighboring blocks |
87 |
cnh |
1.5 |
C needs to be consistent with the code here. |
88 |
cnh |
1.1 |
nThreads = nTx * nTy |
89 |
|
|
|
90 |
cnh |
1.5 |
C-- Initialise the barrier mechanisms |
91 |
|
|
C BAR2 will eventually replace barrier everywhere. |
92 |
cnh |
1.1 |
CALL BARRIER_INIT |
93 |
cnh |
1.5 |
DO I=1, MAX_NO_THREADS |
94 |
|
|
CALL BAR2_INIT(I) |
95 |
|
|
ENDDO |
96 |
|
|
|
97 |
|
|
C-- Initialise exchange mechanism |
98 |
|
|
CALL EXCH_INIT |
99 |
cnh |
1.1 |
|
100 |
|
|
IF ( nThreads .NE. nTx*nTy ) THEN |
101 |
adcroft |
1.6 |
WRITE(msgBuf,'(A,A,A,I5,A,I5)') |
102 |
cnh |
1.1 |
& 'S/R INI_THREADING_ENVIRONMENT:', |
103 |
|
|
& ' Total number of threads is not the same as nTx*nTy.', |
104 |
|
|
& ' nTx * nTy = ',nTx*nTy,' nThreads = ',nThreads |
105 |
|
|
CALL PRINT_ERROR(msgBuf, myThid) |
106 |
|
|
eeBootError = .TRUE. |
107 |
|
|
STOP 'ABNORMAL END: S/R INI_THREADING_ENVIRONMENT' |
108 |
|
|
ENDIF |
109 |
|
|
bxPerThread = nSx/nTx |
110 |
|
|
IF ( bxPerThread*nTx .NE. nSx ) THEN |
111 |
cnh |
1.5 |
WRITE(msgBuf,'(A,A,A)') |
112 |
cnh |
1.1 |
& 'S/R INI_THREADING_ENVIRONMENT:', |
113 |
cnh |
1.5 |
& ' Number of blocks in X (nSx)', |
114 |
|
|
& ' must be exact multiple of threads in X (nTx).' |
115 |
cnh |
1.1 |
CALL PRINT_ERROR(msgBuf, myThid) |
116 |
|
|
eeBootError = .TRUE. |
117 |
|
|
STOP 'ABNORMAL END: S/R INI_THREADING_ENVIRONMENT' |
118 |
|
|
ENDIF |
119 |
|
|
byPerThread = nSy/nTy |
120 |
|
|
IF ( byPerThread*nTy .NE. nSy ) THEN |
121 |
cnh |
1.5 |
WRITE(msgBuf,'(A,A,A)') |
122 |
cnh |
1.1 |
& 'S/R INI_THREADING_ENVIRONMENT:', |
123 |
cnh |
1.5 |
& ' Number of blocks in Y (nSy)', |
124 |
|
|
& ' must be exact multiple of threads in Y (nTy).' |
125 |
cnh |
1.1 |
CALL PRINT_ERROR(msgBuf, myThid) |
126 |
|
|
eeBootError = .TRUE. |
127 |
|
|
STOP 'ABNORMAL END: S/R INI_THREADING_ENVIRONMENT' |
128 |
|
|
ENDIF |
129 |
|
|
IF ( .NOT. eeBootError ) THEN |
130 |
|
|
byLo = 1 |
131 |
|
|
DO J=1,nTy |
132 |
|
|
byHi = byLo+byPerThread-1 |
133 |
|
|
bxLo = 1 |
134 |
|
|
DO I=1,nTx |
135 |
|
|
Thid = (J-1)*nTx+I |
136 |
|
|
bxHi = bxLo+bxPerThread-1 |
137 |
|
|
myBxLo(Thid) = bxLo |
138 |
|
|
myBxHi(Thid) = bxHi |
139 |
|
|
myByLo(Thid) = byLo |
140 |
|
|
myByHi(Thid) = byHi |
141 |
|
|
bxLo = bxHi+1 |
142 |
|
|
ENDDO |
143 |
|
|
byLo = byHi+1 |
144 |
|
|
ENDDO |
145 |
|
|
ENDIF |
146 |
|
|
|
147 |
cnh |
1.5 |
DO nT=1,nThreads |
148 |
|
|
CALL INI_COMMUNICATION_PATTERNS( nT ) |
149 |
cnh |
1.1 |
ENDDO |
150 |
|
|
|
151 |
|
|
C-- Print mapping of threads to grid points. |
152 |
cnh |
1.5 |
WRITE(msgBuf,'(A)') |
153 |
|
|
&'// ======================================================' |
154 |
cnh |
1.1 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
155 |
|
|
& SQUEEZE_RIGHT , 1) |
156 |
|
|
WRITE(msgBuf,'(A)') '// Mapping of tiles to threads' |
157 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
158 |
|
|
& SQUEEZE_RIGHT , 1) |
159 |
cnh |
1.5 |
C o Write list of tiles each thread is responsible for |
160 |
|
|
WRITE(msgBuf,'(A)') |
161 |
|
|
&'// ======================================================' |
162 |
cnh |
1.1 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
163 |
|
|
& SQUEEZE_RIGHT , 1) |
164 |
|
|
DO I=1,nThreads |
165 |
|
|
WRITE(msgBuf,'(A,I4,A,4(I4,A1))') |
166 |
|
|
& '// -o- Thread',I,', tiles (', |
167 |
|
|
& myBxLo(I),':',myBxHi(I),',',myByLo(I),':',myByHi(I),')' |
168 |
cnh |
1.5 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,SQUEEZE_BOTH , 1) |
169 |
cnh |
1.1 |
ENDDO |
170 |
|
|
WRITE(msgBuf,'(A)') ' ' |
171 |
cnh |
1.5 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,SQUEEZE_RIGHT , 1) |
172 |
cnh |
1.1 |
|
173 |
cnh |
1.5 |
C o For each tile print its communication method(s) |
174 |
|
|
WRITE(msgBuf,'(A)') |
175 |
|
|
&'// ======================================================' |
176 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
177 |
|
|
& SQUEEZE_RIGHT , 1) |
178 |
|
|
WRITE(msgBuf,'(A)') '// Tile <-> Tile connectvity table' |
179 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
180 |
|
|
& SQUEEZE_RIGHT , 1) |
181 |
|
|
WRITE(msgBuf,'(A)') |
182 |
|
|
&'// ======================================================' |
183 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
184 |
|
|
& SQUEEZE_RIGHT , 1) |
185 |
|
|
DO J=1,nSy |
186 |
|
|
DO I=1,nSx |
187 |
|
|
WRITE(msgBuf,'(A,A,I6.6,A,I6.6,A)') |
188 |
|
|
& '//',' Tile number: ',tileNo(I,J), |
189 |
|
|
& ' (process no. = ',myPid,')' |
190 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT , 1) |
191 |
|
|
C o West communication details |
192 |
|
|
IF ( tileNoW(I,J).NE. NULL_TILE ) THEN |
193 |
|
|
WRITE(msgBuf,'(A,A,I6.6,A,I6.6,A,A)') |
194 |
|
|
& '// WEST: ', |
195 |
|
|
& 'Tile = ',tileNoW(I,J), |
196 |
|
|
& ', Process = ',tilePidW(I,J), |
197 |
|
|
& ', Comm = ',commName(tileCommModeW(I,J)) |
198 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
199 |
|
|
WRITE(msgBuf,'(A,A,I6.6,A,I6.6)') |
200 |
|
|
& '// ', |
201 |
|
|
& ' bi = ',tileBiW(I,J), |
202 |
|
|
& ', bj = ',tileBjW(I,J) |
203 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
204 |
|
|
ELSE |
205 |
|
|
WRITE(msgBuf,'(A)') |
206 |
|
|
& '// WEST: no neighbor' |
207 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
208 |
|
|
ENDIF |
209 |
|
|
C o East communication details |
210 |
|
|
IF ( tileNoE(I,J).NE. NULL_TILE ) THEN |
211 |
|
|
WRITE(msgBuf,'(A,A,I6.6,A,I6.6,A,A)') |
212 |
|
|
& '// EAST: ', |
213 |
|
|
& 'Tile = ',tileNoE(I,J), |
214 |
|
|
& ', Process = ',tilePidE(I,J), |
215 |
|
|
& ', Comm = ',commName(tileCommModeE(I,J)) |
216 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
217 |
|
|
WRITE(msgBuf,'(A,A,I6.6,A,I6.6)') |
218 |
|
|
& '// ', |
219 |
|
|
& ' bi = ',tileBiE(I,J), |
220 |
|
|
& ', bj = ',tileBjE(I,J) |
221 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
222 |
|
|
ELSE |
223 |
|
|
WRITE(msgBuf,'(A)') |
224 |
|
|
& '// EAST: no neighbor' |
225 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
226 |
|
|
ENDIF |
227 |
|
|
C o South communication method |
228 |
|
|
IF ( tileNoS(I,J).NE. NULL_TILE ) THEN |
229 |
|
|
WRITE(msgBuf,'(A,A,I6.6,A,I6.6,A,A)') |
230 |
|
|
& '// SOUTH: ', |
231 |
|
|
& 'Tile = ',tileNoS(I,J), |
232 |
|
|
& ', Process = ',tilePidS(I,J), |
233 |
|
|
& ', Comm = ',commName(tileCommModeS(I,J)) |
234 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
235 |
|
|
WRITE(msgBuf,'(A,A,I6.6,A,I6.6)') |
236 |
|
|
& '// ', |
237 |
|
|
& ' bi = ',tileBiS(I,J), |
238 |
|
|
& ', bj = ',tileBjS(I,J) |
239 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
240 |
|
|
ELSE |
241 |
|
|
WRITE(msgBuf,'(A)') |
242 |
|
|
& '// SOUTH: no neighbor' |
243 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
244 |
|
|
ENDIF |
245 |
|
|
C o North communication method |
246 |
|
|
IF ( tileNoN(I,J).NE. NULL_TILE ) THEN |
247 |
|
|
WRITE(msgBuf,'(A,A,I6.6,A,I6.6,A,A)') |
248 |
|
|
& '// NORTH: ', |
249 |
|
|
& 'Tile = ',tileNoN(I,J), |
250 |
|
|
& ', Process = ',tilePidN(I,J), |
251 |
|
|
& ', Comm = ',commName(tileCommModeN(I,J)) |
252 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
253 |
|
|
WRITE(msgBuf,'(A,A,I6.6,A,I6.6)') |
254 |
|
|
& '// ', |
255 |
|
|
& ' bi = ',tileBiN(I,J), |
256 |
|
|
& ', bj = ',tileBjN(I,J) |
257 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
258 |
|
|
ELSE |
259 |
|
|
WRITE(msgBuf,'(A)') |
260 |
|
|
& '// NORTH: no neighbor' |
261 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
262 |
cnh |
1.1 |
ENDIF |
263 |
|
|
ENDDO |
264 |
|
|
ENDDO |
265 |
cnh |
1.5 |
WRITE(msgBuf,'(A)') ' ' |
266 |
|
|
CALL PRINT_MESSAGE( msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1) |
267 |
cnh |
1.1 |
|
268 |
|
|
RETURN |
269 |
|
|
END |