/[MITgcm]/MITgcm/eesupp/src/ini_threading_environment.F
ViewVC logotype

Contents of /MITgcm/eesupp/src/ini_threading_environment.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download)
Sun Jul 30 00:43:21 2006 UTC (17 years, 10 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint59, checkpoint58y_post, checkpoint58t_post, checkpoint60, checkpoint61, checkpoint58w_post, checkpoint58o_post, checkpoint58p_post, checkpoint58q_post, mitgcm_mapl_00, checkpoint58r_post, checkpoint58n_post, checkpoint59q, checkpoint59p, checkpoint59r, checkpoint59e, checkpoint59d, checkpoint59g, checkpoint59f, checkpoint59a, checkpoint59c, checkpoint59b, checkpoint59m, checkpoint59l, checkpoint59o, checkpoint59n, checkpoint59i, checkpoint59h, checkpoint59k, checkpoint58v_post, checkpoint61f, checkpoint58x_post, checkpoint59j, checkpoint61e, checkpoint58u_post, checkpoint58s_post, checkpoint61g, checkpoint61d, checkpoint61b, checkpoint61c, checkpoint61a, checkpoint61l, checkpoint61j, checkpoint61k, checkpoint61h, checkpoint61i
Changes since 1.9: +14 -1 lines
stop if MAX_NO_THREADS is too small.

1 C $Header: /u/gcmpack/MITgcm/eesupp/src/ini_threading_environment.F,v 1.9 2004/03/27 03:51:51 edhill Exp $
2 C $Name: $
3
4 #include "CPP_EEOPTIONS.h"
5
6 CBOP
7
8 C !ROUTINE: INI_THREADING_ENVIRONMENT
9
10 C !INTERFACE:
11 SUBROUTINE INI_THREADING_ENVIRONMENT
12 IMPLICIT NONE
13
14 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 C == Global data ==
30 #include "SIZE.h"
31 #include "EEPARAMS.h"
32 #include "EESUPPORT.h"
33
34 C !LOCAL VARIABLES:
35 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 C ( this routine "INI_THREADING_ENVIRONMENT" is
50 C called before multi-threading has started.)
51 INTEGER bxPerThread
52 INTEGER byPerThread
53 INTEGER Thid
54 INTEGER bxLo, bxHi
55 INTEGER byLo, byHi
56 INTEGER I, J, nT
57 CHARACTER*(MAX_LEN_MBUF) msgBuf
58 INTEGER myThid
59
60 CEOP
61
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 myBxHi(I) = 0
71 myByLo(I) = 0
72 myByHi(I) = 0
73 ENDDO
74 myThid = 1
75 commName(COMM_NONE) = 'none'
76 commName(COMM_MSG ) = 'messages'
77 commName(COMM_PUT ) = 'put'
78 commName(COMM_GET ) = 'get'
79
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 C needs to be consistent with the code here.
88 nThreads = nTx * nTy
89
90 C-- Initialise the barrier mechanisms
91 C BAR2 will eventually replace barrier everywhere.
92 CALL BARRIER_INIT
93 DO I=1, MAX_NO_THREADS
94 CALL BAR2_INIT(I)
95 ENDDO
96
97 C-- Initialise exchange mechanism
98 CALL EXCH_INIT
99
100 IF ( nThreads .NE. nTx*nTy ) THEN
101 WRITE(msgBuf,'(A,A,A,I5,A,I5)')
102 & '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 IF ( nThreads .GT. MAX_NO_THREADS ) THEN
110 WRITE(msgBuf,'(2A,2I6)')
111 & 'S/R INI_THREADING_ENVIRONMENT:',
112 & ' Total number of threads exceeds MAX_NO_THREADS',
113 & nTx*nTy, MAX_NO_THREADS
114 CALL PRINT_ERROR(msgBuf, myThid)
115 WRITE(msgBuf,'(2A)')
116 & ' Needs to increase MAX_NO_THREADS',
117 & ' in file "EEPARAMS.h" and to re-compile'
118 CALL PRINT_ERROR(msgBuf, myThid)
119 eeBootError = .TRUE.
120 STOP 'ABNORMAL END: S/R INI_THREADING_ENVIRONMENT'
121 ENDIF
122 bxPerThread = nSx/nTx
123 IF ( bxPerThread*nTx .NE. nSx ) THEN
124 WRITE(msgBuf,'(A,A,A)')
125 & 'S/R INI_THREADING_ENVIRONMENT:',
126 & ' Number of blocks in X (nSx)',
127 & ' must be exact multiple of threads in X (nTx).'
128 CALL PRINT_ERROR(msgBuf, myThid)
129 eeBootError = .TRUE.
130 STOP 'ABNORMAL END: S/R INI_THREADING_ENVIRONMENT'
131 ENDIF
132 byPerThread = nSy/nTy
133 IF ( byPerThread*nTy .NE. nSy ) THEN
134 WRITE(msgBuf,'(A,A,A)')
135 & 'S/R INI_THREADING_ENVIRONMENT:',
136 & ' Number of blocks in Y (nSy)',
137 & ' must be exact multiple of threads in Y (nTy).'
138 CALL PRINT_ERROR(msgBuf, myThid)
139 eeBootError = .TRUE.
140 STOP 'ABNORMAL END: S/R INI_THREADING_ENVIRONMENT'
141 ENDIF
142 IF ( .NOT. eeBootError ) THEN
143 byLo = 1
144 DO J=1,nTy
145 byHi = byLo+byPerThread-1
146 bxLo = 1
147 DO I=1,nTx
148 Thid = (J-1)*nTx+I
149 bxHi = bxLo+bxPerThread-1
150 myBxLo(Thid) = bxLo
151 myBxHi(Thid) = bxHi
152 myByLo(Thid) = byLo
153 myByHi(Thid) = byHi
154 bxLo = bxHi+1
155 ENDDO
156 byLo = byHi+1
157 ENDDO
158 ENDIF
159
160 DO nT=1,nThreads
161 CALL INI_COMMUNICATION_PATTERNS( nT )
162 ENDDO
163
164 C-- Print mapping of threads to grid points.
165 WRITE(msgBuf,'(A)')
166 &'// ======================================================'
167 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
168 & SQUEEZE_RIGHT , 1)
169 WRITE(msgBuf,'(A)') '// Mapping of tiles to threads'
170 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
171 & SQUEEZE_RIGHT , 1)
172 C o Write list of tiles each thread is responsible for
173 WRITE(msgBuf,'(A)')
174 &'// ======================================================'
175 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
176 & SQUEEZE_RIGHT , 1)
177 DO I=1,nThreads
178 WRITE(msgBuf,'(A,I4,A,4(I4,A1))')
179 & '// -o- Thread',I,', tiles (',
180 & myBxLo(I),':',myBxHi(I),',',myByLo(I),':',myByHi(I),')'
181 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,SQUEEZE_BOTH , 1)
182 ENDDO
183 WRITE(msgBuf,'(A)') ' '
184 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,SQUEEZE_RIGHT , 1)
185
186 C o For each tile print its communication method(s)
187 WRITE(msgBuf,'(A)')
188 &'// ======================================================'
189 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
190 & SQUEEZE_RIGHT , 1)
191 WRITE(msgBuf,'(A)') '// Tile <-> Tile connectvity table'
192 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
193 & SQUEEZE_RIGHT , 1)
194 WRITE(msgBuf,'(A)')
195 &'// ======================================================'
196 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
197 & SQUEEZE_RIGHT , 1)
198 DO J=1,nSy
199 DO I=1,nSx
200 WRITE(msgBuf,'(A,A,I6.6,A,I6.6,A)')
201 & '//',' Tile number: ',tileNo(I,J),
202 & ' (process no. = ',myPid,')'
203 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT , 1)
204 C o West communication details
205 IF ( tileNoW(I,J).NE. NULL_TILE ) THEN
206 WRITE(msgBuf,'(A,A,I6.6,A,I6.6,A,A)')
207 & '// WEST: ',
208 & 'Tile = ',tileNoW(I,J),
209 & ', Process = ',tilePidW(I,J),
210 & ', Comm = ',commName(tileCommModeW(I,J))
211 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
212 WRITE(msgBuf,'(A,A,I6.6,A,I6.6)')
213 & '// ',
214 & ' bi = ',tileBiW(I,J),
215 & ', bj = ',tileBjW(I,J)
216 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
217 ELSE
218 WRITE(msgBuf,'(A)')
219 & '// WEST: no neighbor'
220 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
221 ENDIF
222 C o East communication details
223 IF ( tileNoE(I,J).NE. NULL_TILE ) THEN
224 WRITE(msgBuf,'(A,A,I6.6,A,I6.6,A,A)')
225 & '// EAST: ',
226 & 'Tile = ',tileNoE(I,J),
227 & ', Process = ',tilePidE(I,J),
228 & ', Comm = ',commName(tileCommModeE(I,J))
229 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
230 WRITE(msgBuf,'(A,A,I6.6,A,I6.6)')
231 & '// ',
232 & ' bi = ',tileBiE(I,J),
233 & ', bj = ',tileBjE(I,J)
234 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
235 ELSE
236 WRITE(msgBuf,'(A)')
237 & '// EAST: no neighbor'
238 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
239 ENDIF
240 C o South communication method
241 IF ( tileNoS(I,J).NE. NULL_TILE ) THEN
242 WRITE(msgBuf,'(A,A,I6.6,A,I6.6,A,A)')
243 & '// SOUTH: ',
244 & 'Tile = ',tileNoS(I,J),
245 & ', Process = ',tilePidS(I,J),
246 & ', Comm = ',commName(tileCommModeS(I,J))
247 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
248 WRITE(msgBuf,'(A,A,I6.6,A,I6.6)')
249 & '// ',
250 & ' bi = ',tileBiS(I,J),
251 & ', bj = ',tileBjS(I,J)
252 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
253 ELSE
254 WRITE(msgBuf,'(A)')
255 & '// SOUTH: no neighbor'
256 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
257 ENDIF
258 C o North communication method
259 IF ( tileNoN(I,J).NE. NULL_TILE ) THEN
260 WRITE(msgBuf,'(A,A,I6.6,A,I6.6,A,A)')
261 & '// NORTH: ',
262 & 'Tile = ',tileNoN(I,J),
263 & ', Process = ',tilePidN(I,J),
264 & ', Comm = ',commName(tileCommModeN(I,J))
265 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
266 WRITE(msgBuf,'(A,A,I6.6,A,I6.6)')
267 & '// ',
268 & ' bi = ',tileBiN(I,J),
269 & ', bj = ',tileBjN(I,J)
270 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
271 ELSE
272 WRITE(msgBuf,'(A)')
273 & '// NORTH: no neighbor'
274 CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
275 ENDIF
276 ENDDO
277 ENDDO
278 WRITE(msgBuf,'(A)') ' '
279 CALL PRINT_MESSAGE( msgBuf,standardMessageUnit,SQUEEZE_RIGHT, 1)
280
281 RETURN
282 END

  ViewVC Help
Powered by ViewVC 1.1.22