1 |
C $Header: /u/gcmpack/MITgcm/eesupp/src/main.F,v 1.22 2006/01/12 03:24:09 edhill Exp $ |
2 |
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 |
C !INTRODUCTION: |
11 |
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 |
C |
33 |
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 |
C |
43 |
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 |
C |
53 |
CEOI |
54 |
|
55 |
|
56 |
C-- Get C preprocessor options |
57 |
#include "PACKAGES_CONFIG.h" |
58 |
#include "CPP_OPTIONS.h" |
59 |
#include "CPP_EEOPTIONS.h" |
60 |
|
61 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
62 |
CBOP |
63 |
C !ROUTINE: MAIN |
64 |
|
65 |
C !INTERFACE: |
66 |
PROGRAM MAIN |
67 |
IMPLICIT NONE |
68 |
|
69 |
C !DESCRIPTION: |
70 |
C *==========================================================* |
71 |
C | PROGRAM MAIN |
72 |
C | o MAIN wrapper for MITgcm UV implementation. |
73 |
C *==========================================================* |
74 |
C | MAIN controls the "execution environment". |
75 |
C | Its main functions are |
76 |
C | 1. call procedure EEBOOT to perform execution environment |
77 |
C | initialisation. |
78 |
C | 2. call procedure THE\_MODEL\_MAIN once for each concurrent |
79 |
C | thread. THE\_MODEL\_MAIN is the user supplied top-level |
80 |
C | routine. |
81 |
C | 3. call procedure EEDIE to perform execution environment |
82 |
C | shutdown. |
83 |
C *==========================================================* |
84 |
|
85 |
C !CALLING SEQUENCE: |
86 |
C |
87 |
C main() |
88 |
C | |
89 |
C |--eeboot() :: WRAPPER initilization |
90 |
C | |
91 |
C |--check_threads() :: Validate multiple thread start up. |
92 |
C | |
93 |
C |--the_model_main() :: Numerical code top-level driver routine |
94 |
C | |
95 |
C |--eedie() :: WRAPPER termination |
96 |
|
97 |
C !USES: |
98 |
C == Global variables == |
99 |
C Include all the "shared" data here. That means all common |
100 |
C blocks used in the model. On many implementations this is not |
101 |
C necessary but doing this is the safest method. |
102 |
#include "SIZE.h" |
103 |
#include "EEPARAMS.h" |
104 |
#include "EESUPPORT.h" |
105 |
#include "PARAMS.h" |
106 |
#include "GRID.h" |
107 |
#include "DYNVARS.h" |
108 |
#include "FFIELDS.h" |
109 |
#include "SURFACE.h" |
110 |
#ifdef ALLOW_TIMEAVE |
111 |
#include "TIMEAVE_STATV.h" |
112 |
#endif |
113 |
#ifdef HAVE_SIGREG |
114 |
#include "SIGREG.h" |
115 |
#endif |
116 |
|
117 |
C !LOCAL VARIABLES: |
118 |
C-- Local variables |
119 |
INTEGER myThid |
120 |
INTEGER I |
121 |
|
122 |
#ifdef USE_OMP_THREADING |
123 |
INTEGER OMP_GET_THREAD_NUM |
124 |
EXTERNAL OMP_GET_THREAD_NUM |
125 |
#endif |
126 |
|
127 |
CEOP |
128 |
|
129 |
#ifdef USE_GSL_IEEE |
130 |
call fgsl_ieee_env_setup () |
131 |
#endif |
132 |
|
133 |
C-- Set up the execution environment |
134 |
C EEBOOT loads a execution environment parameter file |
135 |
C ( called "eedata" by default ) and sets variables |
136 |
C accordingly. |
137 |
CALL EEBOOT |
138 |
|
139 |
C-- Trap errors |
140 |
IF ( eeBootError ) THEN |
141 |
fatalError = .TRUE. |
142 |
GOTO 999 |
143 |
ENDIF |
144 |
|
145 |
#ifdef HAVE_SETRLSTK |
146 |
IF (useSETRLSTK) THEN |
147 |
CALL setrlstk |
148 |
ENDIF |
149 |
#endif |
150 |
|
151 |
#ifdef HAVE_SIGREG |
152 |
IF (useSIGREG) THEN |
153 |
i_got_signal = 0 |
154 |
CALL sigreg( i_got_signal ) |
155 |
ENDIF |
156 |
#endif |
157 |
|
158 |
#ifdef HAVE_PTHREADS |
159 |
C IF (usePTHREADS) THEN |
160 |
CALL PTINIT(nThreads) |
161 |
C ELSE |
162 |
#else |
163 |
|
164 |
C-- Start nThreads concurrent threads. |
165 |
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 |
C error. This traps the case in which the input |
170 |
C parameter nThreads is different from the actual |
171 |
C number of concurrent threads the OS gives us. This |
172 |
C case causes a deadlock if we do not trap it here. |
173 |
#include "MAIN_PDIRECTIVES1.h" |
174 |
DO I=1,nThreads |
175 |
#ifdef USE_OMP_THREADING |
176 |
IF ( OMP_GET_THREAD_NUM() .EQ. I-1 ) THEN |
177 |
#endif |
178 |
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 |
|
185 |
C-- Invoke nThreads instances of the numerical model |
186 |
IF ( .NOT. eeBootError ) THEN |
187 |
#ifdef ALLOW_ADMTLM |
188 |
CALL ADMTLM_DSVD(myThid) |
189 |
#else |
190 |
CALL THE_MODEL_MAIN(myThid) |
191 |
#endif |
192 |
ENDIF |
193 |
|
194 |
C-- Each threads sets flag indicating it is done |
195 |
threadIsComplete(myThid) = .TRUE. |
196 |
IF ( .NOT. eeBootError ) THEN |
197 |
_BARRIER |
198 |
ENDIF |
199 |
#ifdef USE_OMP_THREADING |
200 |
ENDIF |
201 |
#endif |
202 |
ENDDO |
203 |
#include "MAIN_PDIRECTIVES2.h" |
204 |
|
205 |
#endif /* HAVE_PTHREADS */ |
206 |
|
207 |
999 CONTINUE |
208 |
C-- Shut down execution environment |
209 |
cgmOASIS( |
210 |
# ifdef ALLOW_OASIS |
211 |
CALL OASIS_FINALIZE |
212 |
# endif |
213 |
cgmOASIS) |
214 |
CALL EEDIE |
215 |
|
216 |
C-- Write closedown status |
217 |
IF ( fatalError ) THEN |
218 |
STOP 'ABNORMAL END: PROGRAM MAIN' |
219 |
ELSE |
220 |
STOP 'NORMAL END' |
221 |
ENDIF |
222 |
C |
223 |
END |
224 |
|
225 |
|
226 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
227 |
|
228 |
CBOP 0 |
229 |
C !ROUTINE: PTREENTRY |
230 |
|
231 |
C !INTERFACE: |
232 |
SUBROUTINE PTREENTRY( |
233 |
I myThid ) |
234 |
|
235 |
C !DESCRIPTION: |
236 |
C Re-entry point for a pthreads-based threading mechanism. The |
237 |
C intent is to produce a threading hack that will work with gcc/g77. |
238 |
|
239 |
C !USES: |
240 |
implicit none |
241 |
#include "SIZE.h" |
242 |
#include "EEPARAMS.h" |
243 |
#include "EESUPPORT.h" |
244 |
#include "PARAMS.h" |
245 |
#include "GRID.h" |
246 |
#include "DYNVARS.h" |
247 |
#include "FFIELDS.h" |
248 |
#include "SURFACE.h" |
249 |
#ifdef ALLOW_TIMEAVE |
250 |
#include "TIMEAVE_STATV.h" |
251 |
#endif |
252 |
|
253 |
C !INPUT PARAMETERS: |
254 |
integer myThid |
255 |
CEOP |
256 |
|
257 |
write(*,*) 'myThid = ', myThid |
258 |
CALL CHECK_THREADS( myThid ) |
259 |
|
260 |
C CALL THE_MODEL_MAIN(myThid) |
261 |
|
262 |
threadIsComplete(myThid) = .TRUE. |
263 |
|
264 |
RETURN |
265 |
END |
266 |
|
267 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |