1 |
jmc |
1.28 |
C $Header: /u/gcmpack/MITgcm/eesupp/src/main.F,v 1.27 2013/11/26 00:52:09 jmc Exp $ |
2 |
cnh |
1.8 |
C $Name: $ |
3 |
|
|
|
4 |
|
|
CBOI |
5 |
|
|
C |
6 |
|
|
C !TITLE: WRAPPER CODE SYNOPSIS |
7 |
|
|
C !AUTHORS: mitgcm developers ( support@mitgcm.org ) |
8 |
|
|
C !AFFILIATION: Massachussetts Institute of Technology |
9 |
|
|
C !DATE: |
10 |
jmc |
1.24 |
C !INTRODUCTION: |
11 |
edhill |
1.14 |
C Wrapper synopsis and code Routines in the subdirectories under |
12 |
|
|
C eesupp/ ( src/ and inc/ ) provide the core framework within which |
13 |
|
|
C numerical and ancilliary software of MITgcm operates. The eesupp/ |
14 |
|
|
C directories provide a collection of software we call {\bf WRAPPER} |
15 |
|
|
C ( ({\bf W}rappable {\bf A}pplication {\bf P}aralell {\bf |
16 |
|
|
C P}rogramming {\bf E}nvironment {\bf R}esource). The {bf WRAPPER} |
17 |
|
|
C provides a generic bootstrapping capability to start applications |
18 |
|
|
C in a manner that allows them to exploit single and |
19 |
|
|
C multi-processing environments on all present day hardware |
20 |
|
|
C platforms (spanning vector SMP systems to distributed memory and |
21 |
|
|
C processing cluster systems). Numerical applications must be coded |
22 |
|
|
C to fit within the {\bf WRAPPER}. This entails applications |
23 |
|
|
C adopting a particular style for declaring data structures |
24 |
|
|
C representing grids and values on grids. The {\bf WRAPPER} |
25 |
|
|
C currently provides support for grid point models using a single |
26 |
|
|
C global indexing system. This is sufficient for latitude-logitude, |
27 |
|
|
C cylindrical, and cartesian coordinate configurations. There is |
28 |
|
|
C also limited support for composing grids in which no single, |
29 |
|
|
C sructured global index can be defined. At present, this support is |
30 |
|
|
C limited to specific configurations of projections of a cube onto |
31 |
|
|
C the sphere. |
32 |
cnh |
1.8 |
C |
33 |
edhill |
1.14 |
C The main functions supported by the current {\bf WRAPPER} code are |
34 |
|
|
C \begin{itemize} |
35 |
|
|
C \item program startup and termination including |
36 |
|
|
C creation/management of multiple threads and/or processes |
37 |
|
|
C \item communication and synchronisatioin operations between |
38 |
|
|
C multiple processes and/or threads |
39 |
|
|
C \item multi-process input and output operations to disk and to |
40 |
|
|
C other applications |
41 |
|
|
C \end{itemize} |
42 |
cnh |
1.8 |
C |
43 |
edhill |
1.14 |
C Multi-process execution assumes the existence of MPI for process |
44 |
|
|
C startup and termination. However, MPI does not have to be used for |
45 |
|
|
C performance critical operations. Instead, {\bf WRAPPER} |
46 |
|
|
C performance critical parallel primitives are implemented to allow |
47 |
|
|
C them to bind to different low-level system software |
48 |
|
|
C layers. Bindings exist for using {\bf WRAPPER} with portable |
49 |
|
|
C systems such as MPI and UNIX System V IPC memory mapping, as well |
50 |
|
|
C bindings for high-performance propreitary systems such as Myrinet |
51 |
|
|
C GM software and Compaq IMC memory channel technology. |
52 |
cnh |
1.23 |
C |
53 |
cnh |
1.8 |
CEOI |
54 |
|
|
|
55 |
cnh |
1.1 |
C-- Get C preprocessor options |
56 |
edhill |
1.11 |
#include "PACKAGES_CONFIG.h" |
57 |
cnh |
1.1 |
#include "CPP_OPTIONS.h" |
58 |
|
|
|
59 |
edhill |
1.14 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
60 |
cnh |
1.8 |
CBOP |
61 |
|
|
C !ROUTINE: MAIN |
62 |
|
|
|
63 |
|
|
C !INTERFACE: |
64 |
cnh |
1.1 |
PROGRAM MAIN |
65 |
|
|
|
66 |
cnh |
1.8 |
C !DESCRIPTION: |
67 |
|
|
C *==========================================================* |
68 |
jmc |
1.24 |
C | PROGRAM MAIN |
69 |
|
|
C | o MAIN wrapper for MITgcm UV implementation. |
70 |
cnh |
1.8 |
C *==========================================================* |
71 |
jmc |
1.24 |
C | MAIN controls the "execution environment". |
72 |
|
|
C | Its main functions are |
73 |
cnh |
1.8 |
C | 1. call procedure EEBOOT to perform execution environment |
74 |
jmc |
1.24 |
C | initialisation. |
75 |
edhill |
1.13 |
C | 2. call procedure THE\_MODEL\_MAIN once for each concurrent |
76 |
jmc |
1.24 |
C | thread. THE\_MODEL\_MAIN is the user supplied top-level |
77 |
|
|
C | routine. |
78 |
|
|
C | 3. call procedure EEDIE to perform execution environment |
79 |
|
|
C | shutdown. |
80 |
cnh |
1.8 |
C *==========================================================* |
81 |
|
|
|
82 |
|
|
C !CALLING SEQUENCE: |
83 |
|
|
C |
84 |
jmc |
1.24 |
C main() |
85 |
cnh |
1.8 |
C | |
86 |
|
|
C |--eeboot() :: WRAPPER initilization |
87 |
|
|
C | |
88 |
|
|
C |--check_threads() :: Validate multiple thread start up. |
89 |
|
|
C | |
90 |
|
|
C |--the_model_main() :: Numerical code top-level driver routine |
91 |
|
|
C | |
92 |
|
|
C |--eedie() :: WRAPPER termination |
93 |
|
|
|
94 |
|
|
C !USES: |
95 |
jmc |
1.26 |
IMPLICIT NONE |
96 |
|
|
|
97 |
cnh |
1.1 |
C == Global variables == |
98 |
|
|
C Include all the "shared" data here. That means all common |
99 |
|
|
C blocks used in the model. On many implementations this is not |
100 |
|
|
C necessary but doing this is the safest method. |
101 |
|
|
#include "SIZE.h" |
102 |
|
|
#include "EEPARAMS.h" |
103 |
|
|
#include "EESUPPORT.h" |
104 |
heimbach |
1.16 |
#include "PARAMS.h" |
105 |
|
|
#include "GRID.h" |
106 |
|
|
#include "DYNVARS.h" |
107 |
|
|
#include "FFIELDS.h" |
108 |
|
|
#include "SURFACE.h" |
109 |
edhill |
1.19 |
#ifdef HAVE_SIGREG |
110 |
|
|
#include "SIGREG.h" |
111 |
|
|
#endif |
112 |
cnh |
1.1 |
|
113 |
cnh |
1.8 |
C !LOCAL VARIABLES: |
114 |
jmc |
1.26 |
C msgBuf :: I/O message buffer |
115 |
|
|
C I :: loop counter |
116 |
|
|
C myThid :: thread Id number |
117 |
|
|
CHARACTER*(MAX_LEN_MBUF) msgBuf |
118 |
cnh |
1.1 |
INTEGER myThid |
119 |
|
|
INTEGER I |
120 |
jmc |
1.28 |
INTEGER dummyComm |
121 |
cnh |
1.18 |
|
122 |
|
|
#ifdef USE_OMP_THREADING |
123 |
|
|
INTEGER OMP_GET_THREAD_NUM |
124 |
|
|
EXTERNAL OMP_GET_THREAD_NUM |
125 |
jmc |
1.24 |
#endif |
126 |
cnh |
1.18 |
|
127 |
cnh |
1.8 |
CEOP |
128 |
cnh |
1.1 |
|
129 |
ce107 |
1.20 |
#ifdef USE_GSL_IEEE |
130 |
jmc |
1.26 |
CALL FGSL_IEEE_ENV_SETUP () |
131 |
ce107 |
1.20 |
#endif |
132 |
|
|
|
133 |
cnh |
1.1 |
C-- Set up the execution environment |
134 |
jmc |
1.24 |
C EEBOOT loads a execution environment parameter file |
135 |
jmc |
1.28 |
C ( called "eedata" by default ) and sets variables accordingly. |
136 |
|
|
dummyComm = -1 |
137 |
|
|
CALL EEBOOT( dummyComm ) |
138 |
cnh |
1.1 |
|
139 |
jmc |
1.24 |
C-- Trap errors |
140 |
cnh |
1.1 |
IF ( eeBootError ) THEN |
141 |
|
|
fatalError = .TRUE. |
142 |
|
|
GOTO 999 |
143 |
|
|
ENDIF |
144 |
|
|
|
145 |
edhill |
1.17 |
#ifdef HAVE_SETRLSTK |
146 |
|
|
IF (useSETRLSTK) THEN |
147 |
|
|
CALL setrlstk |
148 |
|
|
ENDIF |
149 |
|
|
#endif |
150 |
|
|
|
151 |
edhill |
1.19 |
#ifdef HAVE_SIGREG |
152 |
|
|
IF (useSIGREG) THEN |
153 |
|
|
i_got_signal = 0 |
154 |
|
|
CALL sigreg( i_got_signal ) |
155 |
|
|
ENDIF |
156 |
|
|
#endif |
157 |
|
|
|
158 |
edhill |
1.14 |
#ifdef HAVE_PTHREADS |
159 |
jmc |
1.24 |
c IF (usePTHREADS) THEN |
160 |
edhill |
1.14 |
CALL PTINIT(nThreads) |
161 |
jmc |
1.24 |
c ELSE |
162 |
edhill |
1.14 |
#else |
163 |
|
|
|
164 |
jmc |
1.24 |
C-- Start nThreads concurrent threads. |
165 |
cnh |
1.1 |
C Note: We do a fiddly check here. The check is performed |
166 |
|
|
C by CHECK_THREADS. CHECK_THREADS does a count |
167 |
|
|
C of all the threads. If after ten seconds it has not |
168 |
|
|
C found nThreads threads are running it flags an |
169 |
jmc |
1.24 |
C error. This traps the case in which the input |
170 |
|
|
C parameter nThreads is different from the actual |
171 |
cnh |
1.1 |
C number of concurrent threads the OS gives us. This |
172 |
cnh |
1.5 |
C case causes a deadlock if we do not trap it here. |
173 |
cnh |
1.1 |
#include "MAIN_PDIRECTIVES1.h" |
174 |
|
|
DO I=1,nThreads |
175 |
cnh |
1.18 |
#ifdef USE_OMP_THREADING |
176 |
|
|
IF ( OMP_GET_THREAD_NUM() .EQ. I-1 ) THEN |
177 |
jmc |
1.24 |
#endif |
178 |
cnh |
1.18 |
myThid = I |
179 |
|
|
|
180 |
|
|
C-- Do check to see if there are nThreads threads running |
181 |
|
|
IF ( .NOT. eeBootError ) THEN |
182 |
|
|
CALL CHECK_THREADS( myThid ) |
183 |
|
|
ENDIF |
184 |
cnh |
1.1 |
|
185 |
cnh |
1.18 |
C-- Invoke nThreads instances of the numerical model |
186 |
|
|
IF ( .NOT. eeBootError ) THEN |
187 |
heimbach |
1.25 |
#if (defined (ALLOW_ADMTLM)) |
188 |
cnh |
1.18 |
CALL ADMTLM_DSVD(myThid) |
189 |
heimbach |
1.25 |
#elif (defined (ALLOW_HESSIAN_CODE)) |
190 |
|
|
CALL HESSIAN_MAIN(myThid) |
191 |
heimbach |
1.10 |
#else |
192 |
cnh |
1.18 |
CALL THE_MODEL_MAIN(myThid) |
193 |
heimbach |
1.10 |
#endif |
194 |
cnh |
1.18 |
ENDIF |
195 |
cnh |
1.1 |
|
196 |
cnh |
1.18 |
C-- Each threads sets flag indicating it is done |
197 |
|
|
threadIsComplete(myThid) = .TRUE. |
198 |
|
|
IF ( .NOT. eeBootError ) THEN |
199 |
|
|
_BARRIER |
200 |
|
|
ENDIF |
201 |
|
|
#ifdef USE_OMP_THREADING |
202 |
cnh |
1.1 |
ENDIF |
203 |
jmc |
1.24 |
#endif |
204 |
cnh |
1.1 |
ENDDO |
205 |
|
|
#include "MAIN_PDIRECTIVES2.h" |
206 |
|
|
|
207 |
edhill |
1.14 |
#endif /* HAVE_PTHREADS */ |
208 |
|
|
|
209 |
cnh |
1.1 |
999 CONTINUE |
210 |
|
|
C-- Shut down execution environment |
211 |
|
|
CALL EEDIE |
212 |
|
|
|
213 |
|
|
C-- Write closedown status |
214 |
|
|
IF ( fatalError ) THEN |
215 |
jmc |
1.26 |
WRITE( msgBuf,'(A)') 'PROGRAM MAIN: ends with fatal Error' |
216 |
|
|
CALL PRINT_ERROR( msgBuf, 1 ) |
217 |
|
|
WRITE(standardMessageUnit,'(A)') |
218 |
|
|
& 'PROGRAM MAIN: ends with fatal Error' |
219 |
cnh |
1.1 |
STOP 'ABNORMAL END: PROGRAM MAIN' |
220 |
|
|
ELSE |
221 |
jmc |
1.24 |
WRITE(standardMessageUnit,'(A)') |
222 |
|
|
& 'PROGRAM MAIN: Execution ended Normally' |
223 |
cnh |
1.1 |
STOP 'NORMAL END' |
224 |
|
|
ENDIF |
225 |
jmc |
1.24 |
|
226 |
cnh |
1.1 |
END |
227 |
edhill |
1.14 |
|
228 |
|
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
229 |
|
|
|
230 |
|
|
CBOP 0 |
231 |
|
|
C !ROUTINE: PTREENTRY |
232 |
jmc |
1.24 |
|
233 |
edhill |
1.14 |
C !INTERFACE: |
234 |
jmc |
1.24 |
SUBROUTINE PTREENTRY( |
235 |
edhill |
1.14 |
I myThid ) |
236 |
|
|
|
237 |
|
|
C !DESCRIPTION: |
238 |
|
|
C Re-entry point for a pthreads-based threading mechanism. The |
239 |
|
|
C intent is to produce a threading hack that will work with gcc/g77. |
240 |
jmc |
1.24 |
|
241 |
edhill |
1.14 |
C !USES: |
242 |
jmc |
1.26 |
IMPLICIT NONE |
243 |
edhill |
1.14 |
#include "SIZE.h" |
244 |
|
|
#include "EEPARAMS.h" |
245 |
|
|
#include "EESUPPORT.h" |
246 |
heimbach |
1.16 |
#include "PARAMS.h" |
247 |
|
|
#include "GRID.h" |
248 |
|
|
#include "DYNVARS.h" |
249 |
|
|
#include "FFIELDS.h" |
250 |
|
|
#include "SURFACE.h" |
251 |
edhill |
1.14 |
|
252 |
|
|
C !INPUT PARAMETERS: |
253 |
jmc |
1.26 |
C myThid :: my thread Id number |
254 |
|
|
INTEGER myThid |
255 |
edhill |
1.14 |
CEOP |
256 |
|
|
|
257 |
jmc |
1.26 |
WRITE(*,*) 'myThid = ', myThid |
258 |
edhill |
1.14 |
CALL CHECK_THREADS( myThid ) |
259 |
|
|
|
260 |
jmc |
1.24 |
c CALL THE_MODEL_MAIN(myThid) |
261 |
edhill |
1.14 |
|
262 |
|
|
threadIsComplete(myThid) = .TRUE. |
263 |
|
|
|
264 |
|
|
RETURN |
265 |
|
|
END |
266 |
|
|
|
267 |
|
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |