1 |
C $Header: /u/gcmpack/MITgcm/eesupp/src/main.F,v 1.23 2007/12/06 16:30:05 cnh 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 |
C |
54 |
CEOI |
55 |
|
56 |
C-- Get C preprocessor options |
57 |
#include "PACKAGES_CONFIG.h" |
58 |
#include "CPP_EEOPTIONS.h" |
59 |
|
60 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
61 |
CBOP |
62 |
C !ROUTINE: MAIN |
63 |
|
64 |
C !INTERFACE: |
65 |
PROGRAM MAIN |
66 |
IMPLICIT NONE |
67 |
|
68 |
C !DESCRIPTION: |
69 |
C *==========================================================* |
70 |
C | PROGRAM MAIN |
71 |
C | o MAIN wrapper for MITgcm UV implementation. |
72 |
C *==========================================================* |
73 |
C | MAIN controls the "execution environment". |
74 |
C | Its main functions are |
75 |
C | 1. call procedure EEBOOT to perform execution environment |
76 |
C | initialisation. |
77 |
C | 2. call procedure THE\_MODEL\_MAIN once for each concurrent |
78 |
C | thread. THE\_MODEL\_MAIN is the user supplied top-level |
79 |
C | routine. |
80 |
C | 3. call procedure EEDIE to perform execution environment |
81 |
C | shutdown. |
82 |
C *==========================================================* |
83 |
|
84 |
C !CALLING SEQUENCE: |
85 |
C |
86 |
C main() |
87 |
C | |
88 |
C |--eeboot() :: WRAPPER initilization |
89 |
C | |
90 |
C |--check_threads() :: Validate multiple thread start up. |
91 |
C | |
92 |
C |--the_model_main() :: Numerical code top-level driver routine |
93 |
C | |
94 |
C |--eedie() :: WRAPPER termination |
95 |
|
96 |
C !USES: |
97 |
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 |
#ifdef HAVE_SIGREG |
105 |
#include "SIGREG.h" |
106 |
#endif |
107 |
|
108 |
C !LOCAL VARIABLES: |
109 |
C-- Local variables |
110 |
INTEGER myThid |
111 |
INTEGER I |
112 |
|
113 |
#ifdef USE_OMP_THREADING |
114 |
INTEGER OMP_GET_THREAD_NUM |
115 |
EXTERNAL OMP_GET_THREAD_NUM |
116 |
#endif |
117 |
|
118 |
CEOP |
119 |
|
120 |
#ifdef USE_GSL_IEEE |
121 |
call fgsl_ieee_env_setup () |
122 |
#endif |
123 |
|
124 |
C-- Set up the execution environment |
125 |
C EEBOOT loads a execution environment parameter file |
126 |
C ( called "eedata" by default ) and sets variables |
127 |
C accordingly. |
128 |
CALL EEBOOT |
129 |
|
130 |
C-- Trap errors |
131 |
IF ( eeBootError ) THEN |
132 |
fatalError = .TRUE. |
133 |
GOTO 999 |
134 |
ENDIF |
135 |
|
136 |
#ifdef HAVE_SETRLSTK |
137 |
IF (useSETRLSTK) THEN |
138 |
CALL setrlstk |
139 |
ENDIF |
140 |
#endif |
141 |
|
142 |
#ifdef HAVE_SIGREG |
143 |
IF (useSIGREG) THEN |
144 |
i_got_signal = 0 |
145 |
CALL sigreg( i_got_signal ) |
146 |
ENDIF |
147 |
#endif |
148 |
|
149 |
#ifdef HAVE_PTHREADS |
150 |
C IF (usePTHREADS) THEN |
151 |
CALL PTINIT(nThreads) |
152 |
C ELSE |
153 |
#else |
154 |
|
155 |
C-- Start nThreads concurrent threads. |
156 |
C Note: We do a fiddly check here. The check is performed |
157 |
C by CHECK_THREADS. CHECK_THREADS does a count |
158 |
C of all the threads. If after ten seconds it has not |
159 |
C found nThreads threads are running it flags an |
160 |
C error. This traps the case in which the input |
161 |
C parameter nThreads is different from the actual |
162 |
C number of concurrent threads the OS gives us. This |
163 |
C case causes a deadlock if we do not trap it here. |
164 |
#include "MAIN_PDIRECTIVES1.h" |
165 |
DO I=1,nThreads |
166 |
#ifdef USE_OMP_THREADING |
167 |
IF ( OMP_GET_THREAD_NUM() .EQ. I-1 ) THEN |
168 |
#endif |
169 |
myThid = I |
170 |
|
171 |
C-- Do check to see if there are nThreads threads running |
172 |
IF ( .NOT. eeBootError ) THEN |
173 |
CALL CHECK_THREADS( myThid ) |
174 |
ENDIF |
175 |
|
176 |
C-- Invoke nThreads instances of the numerical model |
177 |
IF ( .NOT. eeBootError ) THEN |
178 |
#ifdef ALLOW_ADMTLM |
179 |
CALL ADMTLM_DSVD(myThid) |
180 |
#else |
181 |
WRITE(0,'(3(A,I4))') '-- PId=', myProcId, ' , TId=', myThid, |
182 |
& ' : ===> Skip THE_MODEL_MAIN call <===' |
183 |
c CALL THE_MODEL_MAIN(myThid) |
184 |
#endif |
185 |
ENDIF |
186 |
|
187 |
C-- Each threads sets flag indicating it is done |
188 |
threadIsComplete(myThid) = .TRUE. |
189 |
IF ( .NOT. eeBootError ) THEN |
190 |
_BARRIER |
191 |
ENDIF |
192 |
#ifdef USE_OMP_THREADING |
193 |
ENDIF |
194 |
#endif |
195 |
ENDDO |
196 |
#include "MAIN_PDIRECTIVES2.h" |
197 |
|
198 |
#endif /* HAVE_PTHREADS */ |
199 |
|
200 |
999 CONTINUE |
201 |
C-- Shut down execution environment |
202 |
CALL EEDIE |
203 |
|
204 |
C-- Write closedown status |
205 |
IF ( fatalError ) THEN |
206 |
STOP 'ABNORMAL END: PROGRAM MAIN' |
207 |
ELSE |
208 |
STOP 'NORMAL END' |
209 |
ENDIF |
210 |
C |
211 |
END |
212 |
|
213 |
|
214 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
215 |
|
216 |
CBOP 0 |
217 |
C !ROUTINE: PTREENTRY |
218 |
|
219 |
C !INTERFACE: |
220 |
SUBROUTINE PTREENTRY( |
221 |
I myThid ) |
222 |
|
223 |
C !DESCRIPTION: |
224 |
C Re-entry point for a pthreads-based threading mechanism. The |
225 |
C intent is to produce a threading hack that will work with gcc/g77. |
226 |
|
227 |
C !USES: |
228 |
implicit none |
229 |
#include "SIZE.h" |
230 |
#include "EEPARAMS.h" |
231 |
#include "EESUPPORT.h" |
232 |
|
233 |
C !INPUT PARAMETERS: |
234 |
integer myThid |
235 |
CEOP |
236 |
|
237 |
write(*,*) 'myThid = ', myThid |
238 |
CALL CHECK_THREADS( myThid ) |
239 |
|
240 |
C CALL THE_MODEL_MAIN(myThid) |
241 |
|
242 |
threadIsComplete(myThid) = .TRUE. |
243 |
|
244 |
RETURN |
245 |
END |
246 |
|
247 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |