1 |
C $Header: /u/gcmpack/models/MITgcmUV/model/src/the_model_main.F,v 1.39 2001/07/13 14:26:57 heimbach Exp $ |
2 |
C $Name: checkpoint40pre2 $ |
3 |
|
4 |
#include "CPP_OPTIONS.h" |
5 |
|
6 |
SUBROUTINE THE_MODEL_MAIN(myThid) |
7 |
C /==========================================================\ |
8 |
C | SUBROUTINE THE_MODEL_MAIN | |
9 |
C | o Master controlling routine for model using the MITgcm | |
10 |
C | UV parallel wrapper. | |
11 |
C |==========================================================| |
12 |
C | THE_MODEL_MAIN is invoked by the MITgcm UV parallel | |
13 |
C | wrapper with a single integer argument "myThid". This | |
14 |
C | variable identifies the thread number of an instance of | |
15 |
C | THE_MODEL_MAIN. Each instance of THE_MODEL_MAIN works | |
16 |
C | on a particular region of the models domain and | |
17 |
C | synchronises with other instances as necessary. The | |
18 |
C | routine has to "understand" the MITgcm parallel | |
19 |
C | environment and the numerical algorithm. Editing this | |
20 |
C | routine is best done with some knowledge of both aspects.| |
21 |
C | Notes | |
22 |
C | ===== | |
23 |
C | C*P* comments indicating place holders for which code is | |
24 |
C | presently being developed. | |
25 |
C \==========================================================/ |
26 |
IMPLICIT NONE |
27 |
C |
28 |
C == Global variables === |
29 |
#include "SIZE.h" |
30 |
#include "EEPARAMS.h" |
31 |
#include "PARAMS.h" |
32 |
#include "DYNVARS.h" |
33 |
#ifdef ALLOW_NONHYDROSTATIC |
34 |
#include "CG3D.h" |
35 |
#endif |
36 |
|
37 |
#ifdef ALLOW_AUTODIFF_TAMC |
38 |
#include "tamc.h" |
39 |
#include "cost.h" |
40 |
#include "adcost.h" |
41 |
#endif |
42 |
|
43 |
C == Routine arguments == |
44 |
C myThid - Thread number for this instance of the routine. |
45 |
INTEGER myThid |
46 |
|
47 |
C == Local variables == |
48 |
C Note: Under the multi-threaded model myCurrentIter and |
49 |
C myCurrentTime are local variables passed around as routine |
50 |
C arguments. Although this is fiddly it saves the need to |
51 |
C impose additional synchronisation points when they are |
52 |
C updated. |
53 |
C myCurrentTime - Time counter for this thread |
54 |
C myCurrentIter - Iteration counter for this thread |
55 |
INTEGER myCurrentIter |
56 |
_RL myCurrentTime |
57 |
|
58 |
C-- This timer encompasses the whole code |
59 |
CALL TIMER_START('ALL [THE_MODEL_MAIN]',myThid) |
60 |
|
61 |
|
62 |
C-- Set model configuration (fixed arrays) |
63 |
CALL TIMER_START('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) |
64 |
CALL INITIALISE_FIXED( myThid ) |
65 |
CALL TIMER_STOP ('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) |
66 |
|
67 |
myCurrentTime = startTime |
68 |
myCurrentIter = nIter0 |
69 |
|
70 |
#if ( defined (ALLOW_ADJOINT_RUN) || \ |
71 |
defined (ALLOW_GRADIENT_CHECK) || \ |
72 |
defined (ALLOW_ECCO_OPTIMIZATION) ) |
73 |
|
74 |
_BEGIN_MASTER( mythid ) |
75 |
IF (myProcId .eq. 0) THEN |
76 |
CALL CTRL_UNPACK( mycurrentiter, mycurrenttime, mythid ) |
77 |
ENDIF |
78 |
_END_MASTER( mythid ) |
79 |
_BARRIER |
80 |
|
81 |
fc = 0.0 |
82 |
adfc = 1.0 |
83 |
CALL TIMER_START('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) |
84 |
CALL ADTHE_MAIN_LOOP ( mythid ) |
85 |
CALL TIMER_STOP ('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) |
86 |
_BARRIER |
87 |
|
88 |
_BEGIN_MASTER( mythid ) |
89 |
IF (myProcId .eq. 0) THEN |
90 |
call CTRL_PACK( mycurrentiter, mycurrenttime, mythid ) |
91 |
ENDIF |
92 |
_END_MASTER( mythid ) |
93 |
_BARRIER |
94 |
|
95 |
#ifdef ALLOW_GRADIENT_CHECK |
96 |
if (useGrdchk) then |
97 |
CALL TIMER_START('GRDCHK_MAIN [ADJOINT RUN]', mythid) |
98 |
CALL GRDCHK_MAIN( mythid ) |
99 |
CALL TIMER_STOP ('GRDCHK_MAIN [ADJOINT RUN]', mythid) |
100 |
_BARRIER |
101 |
end if |
102 |
#endif |
103 |
|
104 |
#else /* ALLOW_ADJOINT_RUN undef */ |
105 |
|
106 |
C-- Call time stepping loop of full model |
107 |
CALL TIMER_START('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
108 |
CALL THE_MAIN_LOOP(myCurrentTime, myCurrentIter, myThid ) |
109 |
CALL TIMER_STOP ('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
110 |
|
111 |
#endif /* ALLOW_ADJOINT_RUN */ |
112 |
|
113 |
C-- Final checkpoint (incase the in-loop checkpoint was missed) |
114 |
CALL TIMER_START('WRITE_CHECKPOINT [THE_MODEL_MAIN]',myThid) |
115 |
CALL WRITE_CHECKPOINT( |
116 |
& .TRUE., myCurrentTime, myCurrentIter, myThid ) |
117 |
CALL TIMER_STOP ('WRITE_CHECKPOINT [THE_MODEL_MAIN]',myThid) |
118 |
|
119 |
CALL TIMER_STOP ('ALL [THE_MODEL_MAIN]',myThid) |
120 |
|
121 |
C-- Write timer statistics |
122 |
IF ( myThid .EQ. 1 ) THEN |
123 |
CALL TIMER_PRINTALL( myThid ) |
124 |
CALL COMM_STATS |
125 |
ENDIF |
126 |
|
127 |
RETURN |
128 |
END |