1 |
cnh |
1.21 |
C $Header: /u/gcmpack/models/MITgcmUV/model/src/the_model_main.F,v 1.20 1998/09/29 18:50:57 cnh Exp $ |
2 |
cnh |
1.1 |
|
3 |
adcroft |
1.18 |
#include "CPP_OPTIONS.h" |
4 |
cnh |
1.1 |
|
5 |
|
|
SUBROUTINE THE_MODEL_MAIN(myThid) |
6 |
|
|
C /==========================================================\ |
7 |
|
|
C | SUBROUTINE THE_MODEL_MAIN | |
8 |
|
|
C | o Master controlling routine for model using the MITgcm | |
9 |
|
|
C | UV parallel wrapper. | |
10 |
|
|
C |==========================================================| |
11 |
|
|
C | THE_MODEL_MAIN is invoked by the MITgcm UV parallel | |
12 |
|
|
C | wrapper with a single integer argument "myThid". This | |
13 |
|
|
C | variable identifies the thread number of an instance of | |
14 |
|
|
C | THE_MODEL_MAIN. Each instance of THE_MODEL_MAIN works | |
15 |
|
|
C | on a particular region of the models domain and | |
16 |
|
|
C | synchronises with other instances as necessary. The | |
17 |
|
|
C | routine has to "understand" the MITgcm parallel | |
18 |
|
|
C | environment and the numerical algorithm. Editing this | |
19 |
|
|
C | routine is best done with some knowledge of both aspects.| |
20 |
|
|
C | Notes | |
21 |
|
|
C | ===== | |
22 |
|
|
C | C*P* comments indicating place holders for which code is | |
23 |
|
|
C | presently being developed. | |
24 |
|
|
C \==========================================================/ |
25 |
cnh |
1.10 |
C |
26 |
|
|
C Call Tree |
27 |
|
|
C ========= |
28 |
|
|
C |
29 |
|
|
C main ( eesupp ) |
30 |
|
|
C | |
31 |
|
|
C . |
32 |
|
|
C . |
33 |
|
|
C . Generic environment initialisation ( see eesupp/src and |
34 |
|
|
C . eesupp/inc ) |
35 |
|
|
C . multiple threads and/or processes are created in here |
36 |
|
|
C . |
37 |
|
|
C . |
38 |
|
|
C . |
39 |
|
|
C | |
40 |
|
|
C |-THE_MODEL_MAIN - Begin specific model. One instance |
41 |
|
|
C | | of this codes exists for each thread |
42 |
|
|
C | | and/or instance. Each instance manages |
43 |
|
|
C | | a specifc set of tiles. |
44 |
|
|
C | | |
45 |
|
|
C | |--INITIALISE |
46 |
|
|
C | | o Set initial conditions and model configuration |
47 |
|
|
C | | Topography, hydrography, timestep, grid, etc.. |
48 |
|
|
C | | |
49 |
|
|
C ==> | | ** Time stepping loop starts here ** |
50 |
|
|
C | | | |
51 |
|
|
C /|\ | | |
52 |
|
|
C | | |--LOAD_EXTERNAL_DATA |
53 |
|
|
C /|\ | | o Load and/or set time dependent forcing fields |
54 |
|
|
C | | | |
55 |
|
|
C /|\ | |--DYNAMICS |
56 |
|
|
C | | | o Evaluate "forward" terms |
57 |
|
|
C /|\ | | |
58 |
|
|
C | | |--DO_THE_MODEL_IO |
59 |
|
|
C /|\ | | o Write model state |
60 |
|
|
C | | | |
61 |
|
|
C /|\ | |--SOLVE_FOR_PRESSURE |
62 |
|
|
C | | | o Find pressure field to keep flow non-divergent |
63 |
|
|
C /|\ | | |
64 |
|
|
C | | |--DO_GTERM_BLOCKING_EXCHANGES |
65 |
|
|
C /|\ | | o Update overlap regions |
66 |
|
|
C | | | |
67 |
|
|
C /|\ | |--WRITE_CHECKPOINT |
68 |
|
|
C | | | o Write restart file(s) |
69 |
|
|
C /|\ | | |
70 |
|
|
C | | | |
71 |
|
|
C |<== | | ** Time stepping loop finishes here ** |
72 |
|
|
C | | |
73 |
|
|
C | |--WRITE_STATE |
74 |
adcroft |
1.17 |
C | |--WRITE_CHECKPOINT |
75 |
cnh |
1.10 |
C | |
76 |
|
|
C . |
77 |
|
|
C . |
78 |
|
|
C . Generic environment termination ( see eesupp/src and |
79 |
|
|
C . eesupp/inc ) |
80 |
|
|
C . |
81 |
|
|
C . |
82 |
cnh |
1.1 |
|
83 |
|
|
C == Global variables === |
84 |
|
|
#include "SIZE.h" |
85 |
|
|
#include "EEPARAMS.h" |
86 |
|
|
#include "PARAMS.h" |
87 |
|
|
#include "CG2D.h" |
88 |
|
|
#include "DYNVARS.h" |
89 |
adcroft |
1.14 |
#include "AVER.h" |
90 |
cnh |
1.1 |
|
91 |
|
|
C == Routine arguments == |
92 |
|
|
C myThid - Thread number for this instance of the routine. |
93 |
cnh |
1.6 |
INTEGER myThid |
94 |
cnh |
1.1 |
|
95 |
|
|
C == Local variables == |
96 |
cnh |
1.7 |
C Note: Under the multi-threaded model myCurrentIter and |
97 |
|
|
C myCurrentTime are local variables passed around as routine |
98 |
|
|
C arguments. Although this is fiddly it saves the need to |
99 |
|
|
C impose additional synchronisation points when they are |
100 |
|
|
C updated. |
101 |
cnh |
1.1 |
C myCurrentIter - Iteration counter for this thread |
102 |
|
|
C myCurrentTime - Time counter for this thread |
103 |
|
|
C I - Loop counter |
104 |
|
|
INTEGER I, myCurrentIter |
105 |
|
|
REAL myCurrentTime |
106 |
|
|
|
107 |
adcroft |
1.19 |
C-- This timer encompasses the whole code |
108 |
|
|
CALL TIMER_START('ALL',myThid) |
109 |
|
|
|
110 |
|
|
CALL TIMER_START('SPIN-UP',myThid) |
111 |
|
|
|
112 |
cnh |
1.1 |
C-- Set model initial conditions |
113 |
adcroft |
1.19 |
CALL TIMER_START('INITIALISE [SPIN-UP]',myThid) |
114 |
cnh |
1.1 |
CALL INITIALISE( myThid ) |
115 |
|
|
myCurrentTime = startTime |
116 |
|
|
myCurrentIter = nIter0 |
117 |
adcroft |
1.19 |
CALL TIMER_STOP ('INITIALISE [SPIN-UP]',myThid) |
118 |
cnh |
1.1 |
|
119 |
adcroft |
1.15 |
C-- Dump for start state |
120 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [SPIN-UP]',myThid) |
121 |
adcroft |
1.15 |
CALL WRITE_STATE( .TRUE., myCurrentTime, myCurrentIter, myThid ) |
122 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-UP]',myThid) |
123 |
|
|
|
124 |
|
|
CALL TIMER_STOP ('SPIN-UP',myThid) |
125 |
adcroft |
1.15 |
|
126 |
cnh |
1.1 |
C-- Begin time stepping loop |
127 |
adcroft |
1.19 |
CALL TIMER_START('MAIN LOOP',myThid) |
128 |
cnh |
1.1 |
DO I=1, nTimeSteps |
129 |
cnh |
1.4 |
|
130 |
cnh |
1.11 |
C-- Load forcing/external data fields |
131 |
adcroft |
1.19 |
CALL TIMER_START('I/O (READ) [MAIN LOOP]',myThid) |
132 |
cnh |
1.11 |
CALL LOAD_EXTERNAL_FIELDS( myCurrentTime, myCurrentIter, myThid ) |
133 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (READ) [MAIN LOOP]',myThid) |
134 |
cnh |
1.1 |
|
135 |
|
|
C-- Step forward fields and calculate time tendency terms |
136 |
adcroft |
1.19 |
CALL TIMER_START('DYNAMICS [MAIN LOOP]',myThid) |
137 |
cnh |
1.8 |
CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) |
138 |
adcroft |
1.19 |
CALL TIMER_STOP ('DYNAMICS [MAIN LOOP]',myThid) |
139 |
cnh |
1.1 |
|
140 |
adcroft |
1.14 |
C-- Do time averages |
141 |
adcroft |
1.17 |
#ifdef ALLOW_DIAGNOSTICS |
142 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [MAIN LOOP]',myThid) |
143 |
adcroft |
1.14 |
IF (taveFreq.GT.0.) THEN |
144 |
adcroft |
1.17 |
CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid ) |
145 |
adcroft |
1.14 |
ENDIF |
146 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [MAIN LOOP]',myThid) |
147 |
adcroft |
1.17 |
#endif |
148 |
adcroft |
1.14 |
|
149 |
cnh |
1.7 |
C-- Do IO if needed. |
150 |
|
|
C Note: |
151 |
|
|
C ===== |
152 |
|
|
C At this point model arrays hold U,V,T,S at "time-level" N |
153 |
|
|
C and cg2d_x at "time-level" N-1/2 where N = I+timeLevBase-1. |
154 |
|
|
C By convention this is taken to be the model "state". |
155 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [MAIN LOOP]',myThid) |
156 |
cnh |
1.7 |
CALL DO_THE_MODEL_IO( myCurrentTime, myCurrentIter, myThid ) |
157 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [MAIN LOOP]',myThid) |
158 |
cnh |
1.7 |
|
159 |
cnh |
1.1 |
C-- Solve elliptic equation(s). |
160 |
cnh |
1.7 |
C Two-dimensional only for conventional hydrostatic or |
161 |
|
|
C three-dimensional for non-hydrostatic and/or IGW scheme. |
162 |
adcroft |
1.19 |
CALL TIMER_START('SOLVE_FOR_PRESSURE [MAIN LOOP]',myThid) |
163 |
cnh |
1.1 |
CALL SOLVE_FOR_PRESSURE( myThid ) |
164 |
adcroft |
1.19 |
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [MAIN LOOP]',myThid) |
165 |
cnh |
1.1 |
|
166 |
|
|
C-- Do "blocking" sends and receives for tendency "overlap" terms |
167 |
adcroft |
1.19 |
CALL TIMER_START('BLOCKING_EXCHANGES [MAIN LOOP]',myThid) |
168 |
cnh |
1.1 |
CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
169 |
adcroft |
1.19 |
CALL TIMER_STOP ('BLOCKING_EXCHANGES [MAIN LOOP]',myThid) |
170 |
cnh |
1.1 |
|
171 |
|
|
myCurrentIter = myCurrentIter + 1 |
172 |
cnh |
1.7 |
myCurrentTime = myCurrentTime + deltaTClock |
173 |
cnh |
1.1 |
|
174 |
|
|
C-- Save state for restarts |
175 |
cnh |
1.7 |
C Note: |
176 |
|
|
C ===== |
177 |
adcroft |
1.12 |
C Because of the ordering of the timestepping code and |
178 |
cnh |
1.7 |
C tendency term code at end of loop model arrays hold |
179 |
|
|
C U,V,T,S at "time-level" N but gu, gv, gs, gt, guNM1,... |
180 |
|
|
C at "time-level" N+1/2 (guNM1 at "time-level" N+1/2 is |
181 |
|
|
C gu at "time-level" N-1/2) and cg2d_x at "time-level" N+1/2. |
182 |
|
|
C where N = I+timeLevBase-1 |
183 |
|
|
C Thus a checkpoint contains U.0000000000, GU.0000000001 and |
184 |
|
|
C cg2d_x.0000000001 in the indexing scheme used for the model |
185 |
|
|
C "state" files. This example is referred to as a checkpoint |
186 |
|
|
C at time level 1 |
187 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [MAIN LOOP]',myThid) |
188 |
cnh |
1.21 |
CALL |
189 |
|
|
& WRITE_CHECKPOINT( .FALSE., myCurrentTime, myCurrentIter, myThid ) |
190 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [MAIN LOOP]',myThid) |
191 |
cnh |
1.1 |
|
192 |
|
|
ENDDO |
193 |
adcroft |
1.19 |
CALL TIMER_STOP ('MAIN LOOP',myThid) |
194 |
|
|
CALL TIMER_START('SPIN-DOWN',myThid) |
195 |
adcroft |
1.13 |
|
196 |
adcroft |
1.12 |
C-- Final checkpoint (incase the in-loop checkpoint was missed) |
197 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
198 |
cnh |
1.21 |
CALL |
199 |
|
|
& WRITE_CHECKPOINT( .TRUE., myCurrentTime, myCurrentIter, myThid ) |
200 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
201 |
adcroft |
1.12 |
|
202 |
|
|
C-- Step-forward U/V/Theta/Salt for purposes of final I/O dump |
203 |
adcroft |
1.19 |
CALL TIMER_START('DYNAMICS [SPIN-DOWN]',myThid) |
204 |
adcroft |
1.12 |
CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) |
205 |
adcroft |
1.19 |
CALL TIMER_STOP ('DYNAMICS [SPIN-DOWN]',myThid) |
206 |
adcroft |
1.14 |
|
207 |
|
|
C-- Do time averages |
208 |
adcroft |
1.17 |
#ifdef ALLOW_DIAGNOSTICS |
209 |
adcroft |
1.14 |
IF (taveFreq.GT.0.) THEN |
210 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
211 |
|
|
CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid ) |
212 |
|
|
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
213 |
adcroft |
1.14 |
ENDIF |
214 |
adcroft |
1.17 |
#endif |
215 |
adcroft |
1.12 |
|
216 |
|
|
C-- Dump for end state |
217 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
218 |
adcroft |
1.15 |
CALL WRITE_STATE( .FALSE., myCurrentTime, myCurrentIter, myThid ) |
219 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
220 |
|
|
|
221 |
|
|
CALL TIMER_STOP ('SPIN-DOWN',myThid) |
222 |
|
|
CALL TIMER_STOP ('ALL',myThid) |
223 |
cnh |
1.7 |
|
224 |
adcroft |
1.19 |
C-- Write timer statistics |
225 |
cnh |
1.20 |
IF ( myThid .EQ. 1 ) THEN |
226 |
|
|
CALL TIMER_PRINTALL( myThid ) |
227 |
|
|
CALL COMM_STATS |
228 |
|
|
ENDIF |
229 |
cnh |
1.1 |
|
230 |
|
|
RETURN |
231 |
|
|
END |