1 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/main.F,v 1.6 1999/05/18 17:39:21 adcroft Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
C-- Get C preprocessor options |
5 |
#include "CPP_OPTIONS.h" |
6 |
#include "CPP_EEOPTIONS.h" |
7 |
|
8 |
PROGRAM MAIN |
9 |
C /==========================================================\ |
10 |
C | PROGRAM MAIN | |
11 |
C | o MAIN wrapper for MITgcm UV implementation. | |
12 |
C |==========================================================| |
13 |
C | MAIN controls the "execution environment". | |
14 |
C | Its main functions are | |
15 |
C | 1. call procedure EEBOOT to perform execution environment| |
16 |
C | initialisation. | |
17 |
C | 2. call procedure THE_MODEL_MAIN once for each concurrent| |
18 |
C | thread. THE_MODEL_MAIN is the user supplied top-level | |
19 |
C | routine. | |
20 |
C | 3. call procedure EEDIE to perform execution environment | |
21 |
C | shutdown. | |
22 |
C \==========================================================/ |
23 |
IMPLICIT NONE |
24 |
|
25 |
C == Global variables == |
26 |
C Include all the "shared" data here. That means all common |
27 |
C blocks used in the model. On many implementations this is not |
28 |
C necessary but doing this is the safest method. |
29 |
#include "SIZE.h" |
30 |
#include "EEPARAMS.h" |
31 |
#include "EESUPPORT.h" |
32 |
#include "THE_MODEL_COMMON_BLOCKS.h" |
33 |
|
34 |
C-- Local variables |
35 |
INTEGER myThid |
36 |
INTEGER I |
37 |
|
38 |
C-- Set up the execution environment |
39 |
C EEBOOT loads a execution environment parameter file |
40 |
C ( called "eedata" by default ) and sets variables |
41 |
C accordingly. |
42 |
CALL EEBOOT |
43 |
|
44 |
C-- Trap errors |
45 |
IF ( eeBootError ) THEN |
46 |
fatalError = .TRUE. |
47 |
GOTO 999 |
48 |
ENDIF |
49 |
|
50 |
C-- Start nThreads concurrent threads. |
51 |
C Note: We do a fiddly check here. The check is performed |
52 |
C by CHECK_THREADS. CHECK_THREADS does a count |
53 |
C of all the threads. If after ten seconds it has not |
54 |
C found nThreads threads are running it flags an |
55 |
C error. This traps the case in which the input |
56 |
C parameter nThreads is different from the actual |
57 |
C number of concurrent threads the OS gives us. This |
58 |
C case causes a deadlock if we do not trap it here. |
59 |
#include "MAIN_PDIRECTIVES1.h" |
60 |
DO I=1,nThreads |
61 |
myThid = I |
62 |
|
63 |
C-- Do check to see if there are nThreads threads running |
64 |
IF ( .NOT. eeBootError ) THEN |
65 |
CALL CHECK_THREADS( myThid ) |
66 |
ENDIF |
67 |
|
68 |
C-- Invoke nThreads instances of the numerical model |
69 |
IF ( .NOT. eeBootError ) THEN |
70 |
CALL THE_MODEL_MAIN(myThid) |
71 |
ENDIF |
72 |
|
73 |
C-- Each threads sets flag indicating it is done |
74 |
threadIsComplete(myThid) = .TRUE. |
75 |
IF ( .NOT. eeBootError ) THEN |
76 |
_BARRIER |
77 |
ENDIF |
78 |
ENDDO |
79 |
#include "MAIN_PDIRECTIVES2.h" |
80 |
|
81 |
999 CONTINUE |
82 |
C-- Shut down execution environment |
83 |
CALL EEDIE |
84 |
|
85 |
C-- Write closedown status |
86 |
IF ( fatalError ) THEN |
87 |
STOP 'ABNORMAL END: PROGRAM MAIN' |
88 |
ELSE |
89 |
STOP 'NORMAL END' |
90 |
ENDIF |
91 |
C |
92 |
END |