1 |
adcroft |
1.26 |
C $Header: /u/gcmpack/models/MITgcmUV/model/src/the_model_main.F,v 1.25 1999/03/12 16:44:04 adcroft 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 |
adcroft |
1.24 |
IMPLICIT NONE |
26 |
cnh |
1.10 |
C |
27 |
|
|
C Call Tree |
28 |
|
|
C ========= |
29 |
|
|
C |
30 |
|
|
C main ( eesupp ) |
31 |
|
|
C | |
32 |
|
|
C . |
33 |
|
|
C . |
34 |
|
|
C . Generic environment initialisation ( see eesupp/src and |
35 |
|
|
C . eesupp/inc ) |
36 |
|
|
C . multiple threads and/or processes are created in here |
37 |
|
|
C . |
38 |
|
|
C . |
39 |
|
|
C . |
40 |
|
|
C | |
41 |
|
|
C |-THE_MODEL_MAIN - Begin specific model. One instance |
42 |
|
|
C | | of this codes exists for each thread |
43 |
|
|
C | | and/or instance. Each instance manages |
44 |
|
|
C | | a specifc set of tiles. |
45 |
|
|
C | | |
46 |
|
|
C | |--INITIALISE |
47 |
|
|
C | | o Set initial conditions and model configuration |
48 |
|
|
C | | Topography, hydrography, timestep, grid, etc.. |
49 |
|
|
C | | |
50 |
|
|
C ==> | | ** Time stepping loop starts here ** |
51 |
|
|
C | | | |
52 |
|
|
C /|\ | | |
53 |
|
|
C | | |--LOAD_EXTERNAL_DATA |
54 |
|
|
C /|\ | | o Load and/or set time dependent forcing fields |
55 |
|
|
C | | | |
56 |
|
|
C /|\ | |--DYNAMICS |
57 |
|
|
C | | | o Evaluate "forward" terms |
58 |
|
|
C /|\ | | |
59 |
|
|
C | | |--DO_THE_MODEL_IO |
60 |
|
|
C /|\ | | o Write model state |
61 |
|
|
C | | | |
62 |
|
|
C /|\ | |--SOLVE_FOR_PRESSURE |
63 |
|
|
C | | | o Find pressure field to keep flow non-divergent |
64 |
|
|
C /|\ | | |
65 |
|
|
C | | |--DO_GTERM_BLOCKING_EXCHANGES |
66 |
|
|
C /|\ | | o Update overlap regions |
67 |
|
|
C | | | |
68 |
|
|
C /|\ | |--WRITE_CHECKPOINT |
69 |
|
|
C | | | o Write restart file(s) |
70 |
|
|
C /|\ | | |
71 |
|
|
C | | | |
72 |
|
|
C |<== | | ** Time stepping loop finishes here ** |
73 |
|
|
C | | |
74 |
|
|
C | |--WRITE_STATE |
75 |
adcroft |
1.17 |
C | |--WRITE_CHECKPOINT |
76 |
cnh |
1.10 |
C | |
77 |
|
|
C . |
78 |
|
|
C . |
79 |
|
|
C . Generic environment termination ( see eesupp/src and |
80 |
|
|
C . eesupp/inc ) |
81 |
|
|
C . |
82 |
|
|
C . |
83 |
cnh |
1.1 |
|
84 |
|
|
C == Global variables === |
85 |
|
|
#include "SIZE.h" |
86 |
|
|
#include "EEPARAMS.h" |
87 |
|
|
#include "PARAMS.h" |
88 |
adcroft |
1.26 |
#include "DYNVARS.h" |
89 |
cnh |
1.1 |
#include "CG2D.h" |
90 |
adcroft |
1.26 |
#include "CG3D.h" |
91 |
cnh |
1.1 |
|
92 |
|
|
C == Routine arguments == |
93 |
|
|
C myThid - Thread number for this instance of the routine. |
94 |
cnh |
1.6 |
INTEGER myThid |
95 |
cnh |
1.1 |
|
96 |
|
|
C == Local variables == |
97 |
cnh |
1.7 |
C Note: Under the multi-threaded model myCurrentIter and |
98 |
|
|
C myCurrentTime are local variables passed around as routine |
99 |
|
|
C arguments. Although this is fiddly it saves the need to |
100 |
|
|
C impose additional synchronisation points when they are |
101 |
|
|
C updated. |
102 |
cnh |
1.1 |
C myCurrentIter - Iteration counter for this thread |
103 |
|
|
C myCurrentTime - Time counter for this thread |
104 |
|
|
C I - Loop counter |
105 |
|
|
INTEGER I, myCurrentIter |
106 |
|
|
REAL myCurrentTime |
107 |
adcroft |
1.26 |
CHARACTER*(30) suff |
108 |
cnh |
1.1 |
|
109 |
adcroft |
1.19 |
C-- This timer encompasses the whole code |
110 |
|
|
CALL TIMER_START('ALL',myThid) |
111 |
|
|
|
112 |
|
|
CALL TIMER_START('SPIN-UP',myThid) |
113 |
|
|
|
114 |
cnh |
1.1 |
C-- Set model initial conditions |
115 |
adcroft |
1.19 |
CALL TIMER_START('INITIALISE [SPIN-UP]',myThid) |
116 |
cnh |
1.1 |
CALL INITIALISE( myThid ) |
117 |
|
|
myCurrentTime = startTime |
118 |
|
|
myCurrentIter = nIter0 |
119 |
adcroft |
1.19 |
CALL TIMER_STOP ('INITIALISE [SPIN-UP]',myThid) |
120 |
cnh |
1.1 |
|
121 |
adcroft |
1.15 |
C-- Dump for start state |
122 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [SPIN-UP]',myThid) |
123 |
adcroft |
1.15 |
CALL WRITE_STATE( .TRUE., myCurrentTime, myCurrentIter, myThid ) |
124 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-UP]',myThid) |
125 |
|
|
|
126 |
|
|
CALL TIMER_STOP ('SPIN-UP',myThid) |
127 |
adcroft |
1.15 |
|
128 |
cnh |
1.1 |
C-- Begin time stepping loop |
129 |
adcroft |
1.19 |
CALL TIMER_START('MAIN LOOP',myThid) |
130 |
cnh |
1.1 |
DO I=1, nTimeSteps |
131 |
cnh |
1.4 |
|
132 |
cnh |
1.11 |
C-- Load forcing/external data fields |
133 |
adcroft |
1.19 |
CALL TIMER_START('I/O (READ) [MAIN LOOP]',myThid) |
134 |
cnh |
1.11 |
CALL LOAD_EXTERNAL_FIELDS( myCurrentTime, myCurrentIter, myThid ) |
135 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (READ) [MAIN LOOP]',myThid) |
136 |
cnh |
1.1 |
|
137 |
cnh |
1.22 |
#ifdef INCLUDE_SHAPIRO_FILTER_CODE |
138 |
|
|
C-- Step forward all tiles, filter and exchange. |
139 |
|
|
CALL TIMER_START('SHAP_FILT [MAIN LOOP]',myThid) |
140 |
|
|
CALL SHAP_FILT( myCurrentTime, myCurrentIter, myThid ) |
141 |
|
|
CALL TIMER_STOP ('SHAP_FILT [MAIN LOOP]',myThid) |
142 |
|
|
#endif |
143 |
|
|
|
144 |
adcroft |
1.23 |
C-- Set Open Boundaries Values |
145 |
|
|
IF (openBoundaries) THEN |
146 |
|
|
CALL TIMER_START('OBCS [MAIN LOOP]',myThid) |
147 |
|
|
CALL SET_OBCS( myCurrentTime, myThid ) |
148 |
|
|
CALL TIMER_STOP ('OBCS [MAIN LOOP]',myThid) |
149 |
|
|
ENDIF |
150 |
cnh |
1.22 |
|
151 |
cnh |
1.1 |
C-- Step forward fields and calculate time tendency terms |
152 |
adcroft |
1.19 |
CALL TIMER_START('DYNAMICS [MAIN LOOP]',myThid) |
153 |
cnh |
1.8 |
CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) |
154 |
adcroft |
1.19 |
CALL TIMER_STOP ('DYNAMICS [MAIN LOOP]',myThid) |
155 |
cnh |
1.1 |
|
156 |
adcroft |
1.26 |
#ifdef ALLOW_NONHYDROSTATIC |
157 |
|
|
C-- Step forward W field in N-H algorithm |
158 |
|
|
IF ( nonHydrostatic ) THEN |
159 |
|
|
CALL TIMER_START('CALC_GW [MAIN LOOP]',myThid) |
160 |
|
|
CALL CALC_GW( myThid) |
161 |
|
|
CALL TIMER_STOP ('CALC_GW [MAIN LOOP]',myThid) |
162 |
|
|
ENDIF |
163 |
|
|
#endif |
164 |
|
|
|
165 |
adcroft |
1.14 |
C-- Do time averages |
166 |
cnh |
1.22 |
#ifdef INCLUDE_DIAGNOSTICS_INTERFACE_CODE |
167 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [MAIN LOOP]',myThid) |
168 |
adcroft |
1.14 |
IF (taveFreq.GT.0.) THEN |
169 |
adcroft |
1.17 |
CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid ) |
170 |
adcroft |
1.14 |
ENDIF |
171 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [MAIN LOOP]',myThid) |
172 |
adcroft |
1.17 |
#endif |
173 |
adcroft |
1.14 |
|
174 |
cnh |
1.7 |
C-- Do IO if needed. |
175 |
|
|
C Note: |
176 |
|
|
C ===== |
177 |
|
|
C At this point model arrays hold U,V,T,S at "time-level" N |
178 |
|
|
C and cg2d_x at "time-level" N-1/2 where N = I+timeLevBase-1. |
179 |
|
|
C By convention this is taken to be the model "state". |
180 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [MAIN LOOP]',myThid) |
181 |
cnh |
1.7 |
CALL DO_THE_MODEL_IO( myCurrentTime, myCurrentIter, myThid ) |
182 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [MAIN LOOP]',myThid) |
183 |
cnh |
1.7 |
|
184 |
adcroft |
1.26 |
Caja |
185 |
|
|
WRITE(suff,'(I10.10)') myCurrentIter |
186 |
|
|
CALL WRITE_FLD_XY_RL('B2d.',suff,cg2d_b, |
187 |
|
|
& myCurrentIter,myThid) |
188 |
|
|
CALL WRITE_FLD_XYZ_RL('B3d.',suff,cg3d_b, |
189 |
|
|
& myCurrentIter,myThid) |
190 |
|
|
Caja |
191 |
|
|
|
192 |
cnh |
1.1 |
C-- Solve elliptic equation(s). |
193 |
cnh |
1.7 |
C Two-dimensional only for conventional hydrostatic or |
194 |
|
|
C three-dimensional for non-hydrostatic and/or IGW scheme. |
195 |
adcroft |
1.19 |
CALL TIMER_START('SOLVE_FOR_PRESSURE [MAIN LOOP]',myThid) |
196 |
cnh |
1.1 |
CALL SOLVE_FOR_PRESSURE( myThid ) |
197 |
adcroft |
1.19 |
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [MAIN LOOP]',myThid) |
198 |
cnh |
1.1 |
|
199 |
|
|
C-- Do "blocking" sends and receives for tendency "overlap" terms |
200 |
adcroft |
1.19 |
CALL TIMER_START('BLOCKING_EXCHANGES [MAIN LOOP]',myThid) |
201 |
cnh |
1.1 |
CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
202 |
adcroft |
1.19 |
CALL TIMER_STOP ('BLOCKING_EXCHANGES [MAIN LOOP]',myThid) |
203 |
cnh |
1.1 |
|
204 |
|
|
myCurrentIter = myCurrentIter + 1 |
205 |
cnh |
1.7 |
myCurrentTime = myCurrentTime + deltaTClock |
206 |
cnh |
1.1 |
|
207 |
|
|
C-- Save state for restarts |
208 |
cnh |
1.7 |
C Note: |
209 |
|
|
C ===== |
210 |
adcroft |
1.12 |
C Because of the ordering of the timestepping code and |
211 |
cnh |
1.7 |
C tendency term code at end of loop model arrays hold |
212 |
|
|
C U,V,T,S at "time-level" N but gu, gv, gs, gt, guNM1,... |
213 |
|
|
C at "time-level" N+1/2 (guNM1 at "time-level" N+1/2 is |
214 |
|
|
C gu at "time-level" N-1/2) and cg2d_x at "time-level" N+1/2. |
215 |
|
|
C where N = I+timeLevBase-1 |
216 |
|
|
C Thus a checkpoint contains U.0000000000, GU.0000000001 and |
217 |
|
|
C cg2d_x.0000000001 in the indexing scheme used for the model |
218 |
|
|
C "state" files. This example is referred to as a checkpoint |
219 |
|
|
C at time level 1 |
220 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [MAIN LOOP]',myThid) |
221 |
cnh |
1.21 |
CALL |
222 |
|
|
& WRITE_CHECKPOINT( .FALSE., myCurrentTime, myCurrentIter, myThid ) |
223 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [MAIN LOOP]',myThid) |
224 |
cnh |
1.1 |
|
225 |
|
|
ENDDO |
226 |
adcroft |
1.19 |
CALL TIMER_STOP ('MAIN LOOP',myThid) |
227 |
|
|
CALL TIMER_START('SPIN-DOWN',myThid) |
228 |
adcroft |
1.13 |
|
229 |
adcroft |
1.12 |
C-- Final checkpoint (incase the in-loop checkpoint was missed) |
230 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
231 |
cnh |
1.21 |
CALL |
232 |
|
|
& WRITE_CHECKPOINT( .TRUE., myCurrentTime, myCurrentIter, myThid ) |
233 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
234 |
adcroft |
1.23 |
|
235 |
|
|
C-- Set Open Boundaries Values |
236 |
|
|
IF (openBoundaries) THEN |
237 |
|
|
CALL TIMER_START('OBCS [SPIN_DOWN]',myThid) |
238 |
|
|
CALL SET_OBCS( myCurrentTime, myThid ) |
239 |
|
|
CALL TIMER_STOP ('OBCS [SPIN_DOWN]',myThid) |
240 |
|
|
ENDIF |
241 |
adcroft |
1.12 |
|
242 |
|
|
C-- Step-forward U/V/Theta/Salt for purposes of final I/O dump |
243 |
adcroft |
1.19 |
CALL TIMER_START('DYNAMICS [SPIN-DOWN]',myThid) |
244 |
adcroft |
1.12 |
CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) |
245 |
adcroft |
1.19 |
CALL TIMER_STOP ('DYNAMICS [SPIN-DOWN]',myThid) |
246 |
adcroft |
1.26 |
|
247 |
|
|
#ifdef ALLOW_NONHYDROSTATIC |
248 |
|
|
IF ( nonHydrostatic ) THEN |
249 |
|
|
C-- Step forward W field in N-H algorithm |
250 |
|
|
CALL TIMER_START('CALC_GW [SPIN-DOWN]',myThid) |
251 |
|
|
CALL CALC_GW( myThid) |
252 |
|
|
CALL TIMER_STOP ('CALC_GW [SPIN-DOWN]',myThid) |
253 |
|
|
ENDIF |
254 |
|
|
#endif |
255 |
adcroft |
1.14 |
|
256 |
|
|
C-- Do time averages |
257 |
adcroft |
1.17 |
#ifdef ALLOW_DIAGNOSTICS |
258 |
adcroft |
1.14 |
IF (taveFreq.GT.0.) THEN |
259 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
260 |
|
|
CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid ) |
261 |
|
|
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
262 |
adcroft |
1.14 |
ENDIF |
263 |
adcroft |
1.17 |
#endif |
264 |
adcroft |
1.12 |
|
265 |
|
|
C-- Dump for end state |
266 |
adcroft |
1.19 |
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
267 |
adcroft |
1.15 |
CALL WRITE_STATE( .FALSE., myCurrentTime, myCurrentIter, myThid ) |
268 |
adcroft |
1.19 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
269 |
|
|
|
270 |
|
|
CALL TIMER_STOP ('SPIN-DOWN',myThid) |
271 |
|
|
CALL TIMER_STOP ('ALL',myThid) |
272 |
cnh |
1.7 |
|
273 |
adcroft |
1.19 |
C-- Write timer statistics |
274 |
cnh |
1.20 |
IF ( myThid .EQ. 1 ) THEN |
275 |
|
|
CALL TIMER_PRINTALL( myThid ) |
276 |
|
|
CALL COMM_STATS |
277 |
|
|
ENDIF |
278 |
cnh |
1.1 |
|
279 |
|
|
RETURN |
280 |
|
|
END |