1 |
snarayan |
1.1 |
C $Header: /u/gcmpack/MITgcm/model/src/the_main_loop.F,v 1.175 2015/07/22 20:33:58 gforget Exp $ |
2 |
|
|
C $Name: $ |
3 |
|
|
|
4 |
|
|
#include "PACKAGES_CONFIG.h" |
5 |
|
|
#include "CPP_OPTIONS.h" |
6 |
|
|
#ifdef ALLOW_AUTODIFF |
7 |
|
|
# include "AUTODIFF_OPTIONS.h" |
8 |
|
|
#endif |
9 |
|
|
#ifdef ALLOW_OBCS |
10 |
|
|
# include "OBCS_OPTIONS.h" |
11 |
|
|
#endif |
12 |
|
|
#ifdef ALLOW_SEAICE |
13 |
|
|
# include "SEAICE_OPTIONS.h" |
14 |
|
|
#endif |
15 |
|
|
#ifdef ALLOW_GENERIC_ADVDIFF |
16 |
|
|
# include "GAD_OPTIONS.h" |
17 |
|
|
#endif |
18 |
|
|
#ifdef ALLOW_GMREDI |
19 |
|
|
# include "GMREDI_OPTIONS.h" |
20 |
|
|
#endif |
21 |
|
|
#ifdef ALLOW_STREAMICE |
22 |
|
|
# include "STREAMICE_OPTIONS.h" |
23 |
|
|
#endif |
24 |
|
|
#ifdef ALLOW_GGL90 |
25 |
|
|
# include "GGL90_OPTIONS.h" |
26 |
|
|
#endif |
27 |
|
|
#ifdef ALLOW_EXF |
28 |
|
|
# include "EXF_OPTIONS.h" |
29 |
|
|
#endif |
30 |
|
|
#ifdef ALLOW_COST |
31 |
|
|
# include "COST_OPTIONS.h" |
32 |
|
|
#endif |
33 |
|
|
#ifdef ALLOW_CTRL |
34 |
|
|
# include "CTRL_OPTIONS.h" |
35 |
|
|
#endif |
36 |
|
|
#ifdef ALLOW_ECCO |
37 |
|
|
# include "ECCO_OPTIONS.h" |
38 |
|
|
#endif |
39 |
|
|
|
40 |
|
|
CBOP |
41 |
|
|
C !ROUTINE: THE_MAIN_LOOP |
42 |
|
|
C !INTERFACE: |
43 |
|
|
SUBROUTINE THE_MAIN_LOOP( myTime, myIter, myThid ) |
44 |
|
|
|
45 |
|
|
C !DESCRIPTION: \bv |
46 |
|
|
C *================================================================* |
47 |
|
|
C | SUBROUTINE the_main_loop |
48 |
|
|
C | o Run the ocean model and evaluate the specified cost function. |
49 |
|
|
C *================================================================* |
50 |
|
|
C | |
51 |
|
|
C | THE_MAIN_LOOP is the toplevel routine for the Tangent Linear and |
52 |
|
|
C | Adjoint Model Compiler (TAMC). |
53 |
|
|
C | For this purpose the initialization |
54 |
|
|
C | of the model was split into two parts. Those parameters that do |
55 |
|
|
C | not depend on a specific model run are set in INITIALISE_FIXED, |
56 |
|
|
C | whereas those that do depend on the specific realization are |
57 |
|
|
C | initialized in INITIALISE_VARIA. |
58 |
|
|
C | This routine is to be used in conjuction with the MITgcmuv |
59 |
|
|
C | checkpoint 37. |
60 |
|
|
C *================================================================* |
61 |
|
|
C \ev |
62 |
|
|
|
63 |
|
|
C !USES: |
64 |
|
|
IMPLICIT NONE |
65 |
|
|
C == Global variables == |
66 |
|
|
#include "SIZE.h" |
67 |
|
|
#include "EEPARAMS.h" |
68 |
|
|
#include "PARAMS.h" |
69 |
|
|
|
70 |
|
|
c************************************** |
71 |
|
|
#ifdef ALLOW_AUTODIFF |
72 |
|
|
# ifndef ALLOW_OPENAD |
73 |
|
|
|
74 |
|
|
c These includes are needed for |
75 |
|
|
c AD-checkpointing. |
76 |
|
|
c They provide the fields to be stored. |
77 |
|
|
|
78 |
|
|
# include "AUTODIFF_MYFIELDS.h" |
79 |
|
|
# include "GRID.h" |
80 |
|
|
# include "DYNVARS.h" |
81 |
|
|
# include "SURFACE.h" |
82 |
|
|
# include "FFIELDS.h" |
83 |
|
|
# include "EOS.h" |
84 |
|
|
# include "AUTODIFF.h" |
85 |
|
|
|
86 |
|
|
# ifdef ALLOW_GENERIC_ADVDIFF |
87 |
|
|
# include "GAD.h" |
88 |
|
|
# include "GAD_SOM_VARS.h" |
89 |
|
|
# endif |
90 |
|
|
# ifdef ALLOW_MOM_FLUXFORM |
91 |
|
|
# include "MOM_FLUXFORM.h" |
92 |
|
|
# endif |
93 |
|
|
# ifdef ALLOW_CD_CODE |
94 |
|
|
# include "CD_CODE_VARS.h" |
95 |
|
|
# endif |
96 |
|
|
# ifdef ALLOW_PTRACERS |
97 |
|
|
# include "PTRACERS_SIZE.h" |
98 |
|
|
# include "PTRACERS_FIELDS.h" |
99 |
|
|
# include "PTRACERS_START.h" |
100 |
|
|
# endif |
101 |
|
|
# ifdef ALLOW_GCHEM |
102 |
|
|
# include "GCHEM_FIELDS.h" |
103 |
|
|
# endif |
104 |
|
|
# ifdef ALLOW_CFC |
105 |
|
|
# include "CFC.h" |
106 |
|
|
# endif |
107 |
|
|
# ifdef ALLOW_DIC |
108 |
|
|
# include "DIC_VARS.h" |
109 |
|
|
# include "DIC_LOAD.h" |
110 |
|
|
# include "DIC_ATMOS.h" |
111 |
|
|
# include "DIC_CTRL.h" |
112 |
|
|
# include "DIC_COST.h" |
113 |
|
|
# endif |
114 |
|
|
# ifdef ALLOW_OBCS |
115 |
|
|
# include "OBCS_PARAMS.h" |
116 |
|
|
# include "OBCS_FIELDS.h" |
117 |
|
|
# include "OBCS_SEAICE.h" |
118 |
|
|
# ifdef ALLOW_PTRACERS |
119 |
|
|
# include "OBCS_PTRACERS.h" |
120 |
|
|
# endif |
121 |
|
|
# endif |
122 |
|
|
# ifdef ALLOW_EXF |
123 |
|
|
# include "EXF_FIELDS.h" |
124 |
|
|
# ifdef ALLOW_BULKFORMULAE |
125 |
|
|
# include "EXF_CONSTANTS.h" |
126 |
|
|
# endif |
127 |
|
|
# endif /* ALLOW_EXF */ |
128 |
|
|
# ifdef ALLOW_SEAICE |
129 |
|
|
# include "SEAICE_SIZE.h" |
130 |
|
|
# include "SEAICE.h" |
131 |
|
|
# include "SEAICE_PARAMS.h" |
132 |
|
|
# include "SEAICE_COST.h" |
133 |
|
|
# include "SEAICE_TRACER.h" |
134 |
|
|
# endif |
135 |
|
|
# ifdef ALLOW_SALT_PLUME |
136 |
|
|
# include "SALT_PLUME.h" |
137 |
|
|
# endif |
138 |
|
|
# ifdef ALLOW_THSICE |
139 |
|
|
# include "THSICE_SIZE.h" |
140 |
|
|
# include "THSICE_VARS.h" |
141 |
|
|
# include "THSICE_COST.h" |
142 |
|
|
# endif |
143 |
|
|
# ifdef ALLOW_SHELFICE |
144 |
|
|
# include "SHELFICE.h" |
145 |
|
|
# include "SHELFICE_COST.h" |
146 |
|
|
# endif |
147 |
|
|
# ifdef ALLOW_STREAMICE |
148 |
|
|
# include "STREAMICE.h" |
149 |
|
|
# include "STREAMICE_ADV.h" |
150 |
|
|
# include "STREAMICE_BDRY.h" |
151 |
|
|
# include "STREAMICE_CG.h" |
152 |
|
|
# endif |
153 |
|
|
# ifdef ALLOW_EBM |
154 |
|
|
# include "EBM.h" |
155 |
|
|
# endif |
156 |
|
|
# ifdef ALLOW_RBCS |
157 |
|
|
# include "RBCS_SIZE.h" |
158 |
|
|
# include "RBCS_FIELDS.h" |
159 |
|
|
# endif |
160 |
|
|
# ifdef ALLOW_OFFLINE |
161 |
|
|
# include "OFFLINE.h" |
162 |
|
|
# endif |
163 |
|
|
# ifdef ALLOW_CG2D_NSA |
164 |
|
|
# include "CG2D.h" |
165 |
|
|
# endif |
166 |
|
|
# ifdef ALLOW_DIVIDED_ADJOINT |
167 |
|
|
# ifdef ALLOW_USE_MPI |
168 |
|
|
# include "mpif.h" |
169 |
|
|
# endif |
170 |
|
|
# endif |
171 |
|
|
|
172 |
|
|
# include "tamc.h" |
173 |
|
|
|
174 |
|
|
# ifdef ALLOW_GGL90 |
175 |
|
|
# include "GGL90.h" |
176 |
|
|
# endif |
177 |
|
|
# ifdef ALLOW_PROFILES |
178 |
|
|
# include "profiles.h" |
179 |
|
|
# endif |
180 |
|
|
|
181 |
|
|
# ifdef ALLOW_ECCO_EVOLUTION |
182 |
|
|
# ifdef ALLOW_ECCO |
183 |
|
|
# include "ecco_cost.h" |
184 |
|
|
# endif |
185 |
|
|
# endif |
186 |
|
|
#else |
187 |
|
|
#include "OPENAD_OPTIONS.h" |
188 |
|
|
# endif /* undef ALLOW_OPENAD */ |
189 |
|
|
|
190 |
|
|
# ifdef ALLOW_CTRL |
191 |
|
|
# include "CTRL_SIZE.h" |
192 |
|
|
# include "ctrl.h" |
193 |
|
|
# include "ctrl_dummy.h" |
194 |
|
|
# include "CTRL_GENARR.h" |
195 |
|
|
# include "CTRL_OBCS.h" |
196 |
|
|
# endif |
197 |
|
|
# ifdef ALLOW_COST |
198 |
|
|
# include "cost.h" |
199 |
|
|
# endif |
200 |
|
|
|
201 |
|
|
#endif /* ALLOW_AUTODIFF */ |
202 |
|
|
c************************************** |
203 |
|
|
|
204 |
|
|
C !INPUT/OUTPUT PARAMETERS: |
205 |
|
|
C == Routine arguments == |
206 |
|
|
C note: under the multi-threaded model myIter and |
207 |
|
|
C myTime are local variables passed around as routine |
208 |
|
|
C arguments. Although this is fiddly it saves the need to |
209 |
|
|
C impose additional synchronisation points when they are |
210 |
|
|
C updated. |
211 |
|
|
C myTime :: time counter for this thread |
212 |
|
|
C myIter :: iteration counter for this thread |
213 |
|
|
C myThid :: thread number for this instance of the routine. |
214 |
|
|
_RL myTime |
215 |
|
|
INTEGER myIter |
216 |
|
|
INTEGER myThid |
217 |
|
|
|
218 |
|
|
C !FUNCTIONS: |
219 |
|
|
C == Functions == |
220 |
|
|
|
221 |
|
|
C !LOCAL VARIABLES: |
222 |
|
|
C == Local variables == |
223 |
|
|
INTEGER iloop |
224 |
|
|
#ifdef STORE_LOADEDREC_TEST |
225 |
|
|
INTEGER bi,bj |
226 |
|
|
#endif /* STORE_LOADEDREC_TEST */ |
227 |
|
|
CEOP |
228 |
|
|
|
229 |
|
|
#ifdef ALLOW_DEBUG |
230 |
|
|
IF (debugMode) CALL DEBUG_ENTER('THE_MAIN_LOOP',myThid) |
231 |
|
|
#endif |
232 |
|
|
|
233 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
234 |
|
|
c-- Initialize storage for the cost function evaluation. |
235 |
|
|
CADJ INIT dummytape = common, 1 |
236 |
|
|
c-- Initialize storage for the outermost loop. |
237 |
|
|
# ifndef ALLOW_AUTODIFF_WHTAPEIO |
238 |
|
|
CADJ INIT tapelev_init = USER |
239 |
|
|
CADJ INIT tapelev_ini_bibj_k = USER |
240 |
|
|
# else |
241 |
|
|
CADJ INIT tapelev_init = common, 1 |
242 |
|
|
# endif |
243 |
|
|
c |
244 |
|
|
# ifdef ALLOW_TAMC_CHECKPOINTING |
245 |
|
|
# if (defined (AUTODIFF_2_LEVEL_CHECKPOINT)) |
246 |
|
|
CADJ INIT tapelev2 = USER |
247 |
|
|
# elif (defined (AUTODIFF_4_LEVEL_CHECKPOINT)) |
248 |
|
|
CADJ INIT tapelev4 = USER |
249 |
|
|
# else |
250 |
|
|
CADJ INIT tapelev3 = USER |
251 |
|
|
# endif |
252 |
|
|
# endif |
253 |
|
|
#endif |
254 |
|
|
|
255 |
|
|
#ifdef ALLOW_AUTODIFF |
256 |
|
|
nIter0 = NINT( (startTime-baseTime)/deltaTClock ) |
257 |
|
|
ikey_dynamics = 1 |
258 |
|
|
#endif |
259 |
|
|
|
260 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
261 |
|
|
# ifdef NONLIN_FRSURF |
262 |
|
|
CADJ STORE hFacC = tapelev_init, key = 1 |
263 |
|
|
CADJ STORE recip_hFacC = tapelev_init, key = 1 |
264 |
|
|
# endif |
265 |
|
|
#endif |
266 |
|
|
|
267 |
|
|
#ifdef ALLOW_OPENAD |
268 |
|
|
# ifdef ALLOW_THETA0_CONTROL |
269 |
|
|
c$openad INDEPENDENT(xx_theta_dummy) |
270 |
|
|
# endif |
271 |
|
|
# ifdef ALLOW_SALT0_CONTROL |
272 |
|
|
c$openad INDEPENDENT(xx_salt_dummy) |
273 |
|
|
# endif |
274 |
|
|
# ifdef ALLOW_HFLUX0_CONTROL |
275 |
|
|
c$openad INDEPENDENT(xx_hflux0) |
276 |
|
|
# endif |
277 |
|
|
# ifdef ALLOW_SFLUX0_CONTROL |
278 |
|
|
c$openad INDEPENDENT(xx_sflux0) |
279 |
|
|
# endif |
280 |
|
|
# ifdef ALLOW_TAUU0_CONTROL |
281 |
|
|
c$openad INDEPENDENT(xx_tauu0) |
282 |
|
|
# endif |
283 |
|
|
# ifdef ALLOW_TAUV0_CONTROL |
284 |
|
|
c$openad INDEPENDENT(xx_tauv0) |
285 |
|
|
# endif |
286 |
|
|
# ifdef ALLOW_DIFFKR_CONTROL |
287 |
|
|
c$openad INDEPENDENT(xx_diffkr_dummy) |
288 |
|
|
# endif |
289 |
|
|
# ifdef ALLOW_KAPGM_CONTROL |
290 |
|
|
c$openad INDEPENDENT(xx_kapgm) |
291 |
|
|
# endif |
292 |
|
|
# ifdef ALLOW_TR10_CONTROL |
293 |
|
|
c$openad INDEPENDENT(xx_tr1) |
294 |
|
|
# endif |
295 |
|
|
# ifdef ALLOW_HFLUXM_CONTROL |
296 |
|
|
c$openad INDEPENDENT(xx_hfluxm) |
297 |
|
|
# endif |
298 |
|
|
# ifdef ALLOW_GENARR2D_CONTROL |
299 |
|
|
cphc$openad INDEPENDENT(xx_genarr2d) |
300 |
|
|
c$openad INDEPENDENT(xx_genarr2d_dummy) |
301 |
|
|
# endif |
302 |
|
|
# ifdef ALLOW_GENARR3D_CONTROL |
303 |
|
|
cphc$openad INDEPENDENT(xx_genarr3d) |
304 |
|
|
c$openad INDEPENDENT(xx_genarr3d_dummy) |
305 |
|
|
# endif |
306 |
|
|
# ifdef ALLOW_GENTIM2D_CONTROL |
307 |
|
|
cphc$openad INDEPENDENT(xx_gentim2d) |
308 |
|
|
c$openad INDEPENDENT(xx_gentim2d_dummy) |
309 |
|
|
# endif |
310 |
|
|
#endif /* ALLOW_OPENAD */ |
311 |
|
|
|
312 |
|
|
#ifdef ALLOW_DEBUG |
313 |
|
|
IF (debugMode) CALL DEBUG_CALL('INITIALISE_VARIA',myThid) |
314 |
|
|
#endif |
315 |
|
|
C#ifndef ALLOW_OPENAD |
316 |
|
|
C-- Set initial conditions (variable arrays) |
317 |
|
|
#if (defined (ALLOW_OPENAD) && defined (ALLOW_OPENAD_DIVA)) |
318 |
|
|
if(myIter.eq.nIter0) then |
319 |
|
|
print *, 'DIVA calling INITIALISE_VARIA', myIter, nIter0 |
320 |
|
|
#endif |
321 |
|
|
CALL TIMER_START('INITIALISE_VARIA [THE_MAIN_LOOP]', myThid) |
322 |
|
|
CALL INITIALISE_VARIA( myThid ) |
323 |
|
|
CALL TIMER_STOP ('INITIALISE_VARIA [THE_MAIN_LOOP]', myThid) |
324 |
|
|
#if (defined (ALLOW_OPENAD) && defined (ALLOW_OPENAD_DIVA)) |
325 |
|
|
end if |
326 |
|
|
#endif |
327 |
|
|
C#endif |
328 |
|
|
#if (defined (ALLOW_ECCO_EVOLUTION) && defined (ECCO_CTRL_DEPRECATED)) |
329 |
|
|
#ifdef ALLOW_ECCO |
330 |
|
|
cph: avoid renewed call of initialise_varia in recomputation loop |
331 |
|
|
cph: in some circumstances |
332 |
|
|
CADJ STORE sbar_gen,tbar_gen = onetape |
333 |
|
|
#endif |
334 |
|
|
#endif |
335 |
|
|
|
336 |
|
|
#ifdef ALLOW_SHOWFLOPS |
337 |
|
|
CALL TIMER_START('SHOWFLOPS_INIT [THE_MAIN_LOOP]', myThid) |
338 |
|
|
CALL SHOWFLOPS_INIT( myThid ) |
339 |
|
|
CALL TIMER_STOP ('SHOWFLOPS_INIT [THE_MAIN_LOOP]', myThid) |
340 |
|
|
#endif |
341 |
|
|
|
342 |
|
|
c-- Do the model integration. |
343 |
|
|
CALL TIMER_START('MAIN LOOP [THE_MAIN_LOOP]', myThid) |
344 |
|
|
|
345 |
|
|
c >>>>>>>>>>>>>>>>>>>>>>>>>>> LOOP <<<<<<<<<<<<<<<<<<<<<<<<<<<< |
346 |
|
|
c >>>>>>>>>>>>>>>>>>>>>>>>>>> STARTS <<<<<<<<<<<<<<<<<<<<<<<<<<<< |
347 |
|
|
|
348 |
|
|
c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
349 |
|
|
#ifndef ALLOW_OPENAD |
350 |
|
|
# ifdef ALLOW_AUTODIFF |
351 |
|
|
# ifdef ALLOW_TAMC_CHECKPOINTING |
352 |
|
|
c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
353 |
|
|
|
354 |
|
|
max_lev4=nTimeSteps/(nchklev_1*nchklev_2*nchklev_3)+1 |
355 |
|
|
max_lev3=nTimeSteps/(nchklev_1*nchklev_2)+1 |
356 |
|
|
max_lev2=nTimeSteps/nchklev_1+1 |
357 |
|
|
|
358 |
|
|
c************************************** |
359 |
|
|
# ifdef ALLOW_DIVIDED_ADJOINT |
360 |
|
|
CADJ loop = divided |
361 |
|
|
# endif |
362 |
|
|
c************************************** |
363 |
|
|
|
364 |
|
|
# ifdef AUTODIFF_4_LEVEL_CHECKPOINT |
365 |
|
|
do ilev_4 = 1,nchklev_4 |
366 |
|
|
if(ilev_4.le.max_lev4) then |
367 |
|
|
c************************************** |
368 |
|
|
#ifdef ALLOW_AUTODIFF_WHTAPEIO |
369 |
|
|
CALL AUTODIFF_WHTAPEIO_SYNC( 4 , 0, myThid ) |
370 |
|
|
#endif |
371 |
|
|
CALL AUTODIFF_STORE( myThid ) |
372 |
|
|
#include "checkpoint_lev4_directives.h" |
373 |
|
|
CALL AUTODIFF_RESTORE( myThid ) |
374 |
|
|
#ifdef ALLOW_AUTODIFF_WHTAPEIO |
375 |
|
|
CALL AUTODIFF_WHTAPEIO_SYNC( 4 , 1, myThid ) |
376 |
|
|
#endif |
377 |
|
|
c************************************** |
378 |
|
|
c-- Initialise storage for the middle loop. |
379 |
|
|
CADJ INIT tapelev3 = USER |
380 |
|
|
# endif /* AUTODIFF_4_LEVEL_CHECKPOINT */ |
381 |
|
|
|
382 |
|
|
# ifndef AUTODIFF_2_LEVEL_CHECKPOINT |
383 |
|
|
do ilev_3 = 1,nchklev_3 |
384 |
|
|
if(ilev_3.le.max_lev3) then |
385 |
|
|
c************************************** |
386 |
|
|
#ifdef ALLOW_AUTODIFF_WHTAPEIO |
387 |
|
|
CALL AUTODIFF_WHTAPEIO_SYNC( 3 , 0, myThid ) |
388 |
|
|
#endif |
389 |
|
|
CALL AUTODIFF_STORE( myThid ) |
390 |
|
|
#include "checkpoint_lev3_directives.h" |
391 |
|
|
CALL AUTODIFF_RESTORE( myThid ) |
392 |
|
|
#ifdef ALLOW_AUTODIFF_WHTAPEIO |
393 |
|
|
CALL AUTODIFF_WHTAPEIO_SYNC( 3 , 1, myThid ) |
394 |
|
|
#endif |
395 |
|
|
c************************************** |
396 |
|
|
c-- Initialise storage for the middle loop. |
397 |
|
|
CADJ INIT tapelev2 = USER |
398 |
|
|
# endif /* AUTODIFF_2_LEVEL_CHECKPOINT */ |
399 |
|
|
|
400 |
|
|
do ilev_2 = 1,nchklev_2 |
401 |
|
|
if(ilev_2.le.max_lev2) then |
402 |
|
|
c************************************** |
403 |
|
|
#ifdef ALLOW_AUTODIFF_WHTAPEIO |
404 |
|
|
CALL AUTODIFF_WHTAPEIO_SYNC( 2 , 0, myThid ) |
405 |
|
|
#endif |
406 |
|
|
CALL AUTODIFF_STORE( myThid ) |
407 |
|
|
#include "checkpoint_lev2_directives.h" |
408 |
|
|
CALL AUTODIFF_RESTORE( myThid ) |
409 |
|
|
#ifdef ALLOW_AUTODIFF_WHTAPEIO |
410 |
|
|
CALL AUTODIFF_WHTAPEIO_SYNC( 2 , 1, myThid ) |
411 |
|
|
#endif |
412 |
|
|
c************************************** |
413 |
|
|
|
414 |
|
|
# endif /* ALLOW_TAMC_CHECKPOINTING */ |
415 |
|
|
|
416 |
|
|
c************************************** |
417 |
|
|
c-- |
418 |
|
|
c-- Initialize storage for the innermost loop. |
419 |
|
|
c-- Always check common block sizes for the checkpointing! |
420 |
|
|
c-- |
421 |
|
|
CADJ INIT comlev1 = COMMON,nchklev_1 |
422 |
|
|
CADJ INIT comlev1_bibj = COMMON,nchklev_1*nsx*nsy*nthreads_chkpt |
423 |
|
|
CADJ INIT comlev1_bibj_k = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt |
424 |
|
|
c-- |
425 |
|
|
#ifdef ALLOW_CTRL |
426 |
|
|
CADJ INIT ctrltape = COMMON,1 |
427 |
|
|
#endif |
428 |
|
|
c-- |
429 |
|
|
# ifdef ALLOW_KPP |
430 |
|
|
CADJ INIT comlev1_kpp = COMMON,nchklev_1*nsx*nsy |
431 |
|
|
CADJ INIT comlev1_kpp_k = COMMON,nchklev_1*nsx*nsy*nr |
432 |
|
|
# endif /* ALLOW_KPP */ |
433 |
|
|
c-- |
434 |
|
|
# ifdef ALLOW_GMREDI |
435 |
|
|
CADJ INIT comlev1_gmredi_k_gad |
436 |
|
|
CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass |
437 |
|
|
# endif /* ALLOW_GMREDI */ |
438 |
|
|
c-- |
439 |
|
|
# ifdef ALLOW_PTRACERS |
440 |
|
|
CADJ INIT comlev1_bibj_ptracers = COMMON, |
441 |
|
|
CADJ & nchklev_1*nsx*nsy*nthreads_chkpt*PTRACERS_num |
442 |
|
|
CADJ INIT comlev1_bibj_k_ptracers = COMMON, |
443 |
|
|
CADJ & nchklev_1*nsx*nsy*nthreads_chkpt*PTRACERS_num*nr |
444 |
|
|
# endif /* ALLOW_PTRACERS */ |
445 |
|
|
c-- |
446 |
|
|
# ifndef DISABLE_MULTIDIM_ADVECTION |
447 |
|
|
CADJ INIT comlev1_bibj_gad = COMMON, |
448 |
|
|
CADJ & nchklev_1*nsx*nsy*nthreads_chkpt*maxpass |
449 |
|
|
CADJ INIT comlev1_bibj_k_gad = COMMON, |
450 |
|
|
CADJ & nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass |
451 |
|
|
CADJ INIT comlev1_bibj_k_gad_pass = COMMON, |
452 |
|
|
CADJ & nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass*maxpass |
453 |
|
|
# endif /* DISABLE_MULTIDIM_ADVECTION */ |
454 |
|
|
c-- |
455 |
|
|
# ifdef ALLOW_MOM_COMMON |
456 |
|
|
# ifndef AUTODIFF_DISABLE_LEITH |
457 |
|
|
CADJ INIT comlev1_mom_ijk_loop |
458 |
|
|
CADJ & = COMMON,nchklev_1* |
459 |
|
|
CADJ & (snx+2*olx)*nsx*(sny+2*oly)*nsy*nr*nthreads_chkpt |
460 |
|
|
# endif /* AUTODIFF_DISABLE_LEITH */ |
461 |
|
|
# endif /* ALLOW_MOM_COMMON */ |
462 |
|
|
c-- |
463 |
|
|
# if (defined (ALLOW_EXF) && defined (ALLOW_BULKFORMULAE)) |
464 |
|
|
CADJ INIT comlev1_exf_1 |
465 |
|
|
CADJ & = COMMON,nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt |
466 |
|
|
CADJ INIT comlev1_exf_2 |
467 |
|
|
CADJ & = COMMON,niter_bulk*nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt |
468 |
|
|
# endif /* ALLOW_BULKFORMULAE */ |
469 |
|
|
c-- |
470 |
|
|
# ifdef ALLOW_SEAICE |
471 |
|
|
# ifdef SEAICE_ALLOW_DYNAMICS |
472 |
|
|
CADJ INIT comlev1_dynsol = COMMON,nchklev_1*MPSEUDOTIMESTEPS |
473 |
|
|
# ifdef SEAICE_LSR_ADJOINT_ITER |
474 |
|
|
CADJ INIT comlev1_lsr = COMMON,nchklev_1*MPSEUDOTIMESTEPS*SOLV_MAX_FIXED |
475 |
|
|
CADJ INIT comlev1_bibj_lsr = COMMON, |
476 |
|
|
CADJ & nchklev_1*nsx*nsy*nthreads_chkpt*MPSEUDOTIMESTEPS*SOLV_MAX_FIXED |
477 |
|
|
# else /* make the common blocks smaller to reduce memory footprint */ |
478 |
|
|
CADJ INIT comlev1_lsr = COMMON,nchklev_1*MPSEUDOTIMESTEPS |
479 |
|
|
CADJ INIT comlev1_bibj_lsr = COMMON, |
480 |
|
|
CADJ & nsx*nsy*nthreads_chkpt*nchklev_1*MPSEUDOTIMESTEPS |
481 |
|
|
# endif |
482 |
|
|
# endif |
483 |
|
|
# ifdef SEAICE_ALLOW_EVP |
484 |
|
|
CADJ INIT comlev1_evp = COMMON,nEVPstepMax*nchklev_1 |
485 |
|
|
# endif |
486 |
|
|
CML# ifdef SEAICE_MULTICATEGORY |
487 |
|
|
CMLCADJ INIT comlev1_multdim |
488 |
|
|
CMLCADJ & = COMMON,nchklev_1*nsx*nsy*nthreads_chkpt*nitd |
489 |
|
|
CML# endif |
490 |
|
|
# ifndef DISABLE_MULTIDIM_ADVECTION |
491 |
|
|
CADJ INIT comlev1_bibj_k_gadice = COMMON, |
492 |
|
|
CADJ & nchklev_1*nsx*nsy*nthreads_chkpt*maxpass |
493 |
|
|
CADJ INIT comlev1_bibj_k_gadice_pass = COMMON, |
494 |
|
|
CADJ & nchklev_1*nsx*nsy*nthreads_chkpt*maxpass*maxpass |
495 |
|
|
# endif /* DISABLE_MULTIDIM_ADVECTION */ |
496 |
|
|
# endif /* ALLOW_SEAICE */ |
497 |
|
|
c-- |
498 |
|
|
# ifdef ALLOW_THSICE |
499 |
|
|
CADJ INIT comlev1_thsice_1 = COMMON, |
500 |
|
|
CADJ & nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt |
501 |
|
|
CADJ INIT comlev1_thsice_2 = COMMON, |
502 |
|
|
CADJ & nchklev_1*snx*nsx*sny*nsy*nlyr*nthreads_chkpt |
503 |
|
|
CADJ INIT comlev1_thsice_3 = COMMON, |
504 |
|
|
CADJ & nchklev_1*snx*nsx*sny*nsy*MaxTsf*nthreads_chkpt |
505 |
|
|
CADJ INIT comlev1_thsice_4 = COMMON, |
506 |
|
|
CADJ & nchklev_1*nsx*nsy*maxpass*nthreads_chkpt |
507 |
|
|
CADJ INIT comlev1_thsice_5 = COMMON, |
508 |
|
|
CADJ & nchklev_1*snx*nsx*sny*nsy*MaxTsf*(niter_bulk+1)*nthreads_chkpt |
509 |
|
|
CADJ INIT comlev1_thsice_s4t = COMMON, |
510 |
|
|
CADJ & nchklev_1*nsx*nsy*maxtsf*nthreads_chkpt |
511 |
|
|
# endif /* ALLOW_THSICE */ |
512 |
|
|
c-- |
513 |
|
|
# ifdef ALLOW_STREAMICE |
514 |
|
|
CADJ INIT comlev1_stream_nl = COMMON,nchklev_1*streamice_max_nl |
515 |
|
|
CADJ INIT comlev1_stream_front = COMMON,nchklev_1*4 |
516 |
|
|
CADJ INIT comlev1_stream_ij |
517 |
|
|
CADJ & = COMMON,nchklev_1*4*(snx+2)*nsx*(sny+2)*nsy |
518 |
|
|
CADJ INIT comlev1_stream_hybrid |
519 |
|
|
CADJ & = COMMON,nchklev_1*snx*nsx*sny*nsy*nr*nthreads_chkpt |
520 |
|
|
# endif |
521 |
|
|
c-- |
522 |
|
|
# ifdef ALLOW_CG2D_NSA |
523 |
|
|
CADJ INIT comlev1_cg2d |
524 |
|
|
CADJ & = COMMON,nchklev_1*nthreads_chkpt |
525 |
|
|
CADJ INIT comlev1_cg2d_iter |
526 |
|
|
CADJ & = COMMON,nchklev_1*nthreads_chkpt*numItersMax |
527 |
|
|
# endif |
528 |
|
|
c-- |
529 |
|
|
c************************************** |
530 |
|
|
|
531 |
|
|
#ifdef STORE_LOADEDREC_TEST |
532 |
|
|
DO bj = myByLo(myThid), myByHi(myThid) |
533 |
|
|
DO bi = myBxLo(myThid), myBxHi(myThid) |
534 |
|
|
loadedRec(bi,bj) = 0 |
535 |
|
|
ENDDO |
536 |
|
|
ENDDO |
537 |
|
|
#endif /* STORE_LOADEDREC_TEST */ |
538 |
|
|
|
539 |
|
|
#ifdef ALLOW_TAMC_CHECKPOINTING |
540 |
|
|
|
541 |
|
|
do ilev_1 = 1,nchklev_1 |
542 |
|
|
|
543 |
|
|
c-- The if-statement below introduces a some flexibility in the |
544 |
|
|
c-- choice of the 3-tupel ( nchklev_1, nchklev_2, nchklev_3 ). |
545 |
|
|
|
546 |
|
|
iloop = (ilev_2 - 1)*nchklev_1 + ilev_1 |
547 |
|
|
# ifndef AUTODIFF_2_LEVEL_CHECKPOINT |
548 |
|
|
& + (ilev_3 - 1)*nchklev_2*nchklev_1 |
549 |
|
|
# endif |
550 |
|
|
# ifdef AUTODIFF_4_LEVEL_CHECKPOINT |
551 |
|
|
& + (ilev_4 - 1)*nchklev_3*nchklev_2*nchklev_1 |
552 |
|
|
# endif |
553 |
|
|
|
554 |
|
|
if ( iloop .le. nTimeSteps ) then |
555 |
|
|
|
556 |
|
|
# else /* ALLOW_TAMC_CHECKPOINTING undefined */ |
557 |
|
|
|
558 |
|
|
DO iloop = 1, nTimeSteps |
559 |
|
|
|
560 |
|
|
c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
561 |
|
|
# endif /* ALLOW_TAMC_CHECKPOINTING */ |
562 |
|
|
# endif /* ALLOW_AUTODIFF */ |
563 |
|
|
#endif /* undef ALLOW_OPENAD */ |
564 |
|
|
c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
565 |
|
|
|
566 |
|
|
#ifndef ALLOW_AUTODIFF |
567 |
|
|
DO iloop = 1, nTimeSteps |
568 |
|
|
#endif /* ALLOW_AUTODIFF */ |
569 |
|
|
|
570 |
|
|
c-- >>> Loop body start <<< |
571 |
|
|
|
572 |
|
|
#ifdef ALLOW_AUTODIFF |
573 |
|
|
nIter0 = NINT( (startTime-baseTime)/deltaTClock ) |
574 |
|
|
C-- Reset the model iteration counter and the model time. |
575 |
|
|
myIter = nIter0 + (iloop-1) |
576 |
|
|
myTime = startTime + float(iloop-1)*deltaTClock |
577 |
|
|
# ifndef ALLOW_OPENAD |
578 |
|
|
ikey_dynamics = ilev_1 |
579 |
|
|
# endif |
580 |
|
|
#endif |
581 |
|
|
|
582 |
|
|
#if (defined (ALLOW_ECCO) && defined (ALLOW_ECCO_EVOLUTION)) |
583 |
|
|
IF ( useECCO ) then |
584 |
|
|
# ifdef ALLOW_DEBUG |
585 |
|
|
IF (debugMode) CALL DEBUG_CALL('cost_averagesfields',myThid) |
586 |
|
|
# endif |
587 |
|
|
c-- Accumulate time averages of temperature, salinity |
588 |
|
|
CALL TIMER_START('COST_AVERAGESFIELDS [MAIN_DO_LOOP]',myThid) |
589 |
|
|
CALL COST_AVERAGESFIELDS( myTime, myThid ) |
590 |
|
|
CALL TIMER_STOP ('COST_AVERAGESFIELDS [MAIN_DO_LOOP]',myThid) |
591 |
|
|
ENDIF |
592 |
|
|
#endif /* ALLOW_ECCO_EVOLUTION */ |
593 |
|
|
|
594 |
|
|
#ifdef ALLOW_PROFILES |
595 |
|
|
IF (usePROFILES) THEN |
596 |
|
|
#ifdef ALLOW_DEBUG |
597 |
|
|
IF (debugMode) CALL DEBUG_CALL('profiles_inloop',myThid) |
598 |
|
|
#endif |
599 |
|
|
c-- Accumulate in-situ time averages of theta, salt, and SSH. |
600 |
|
|
#ifdef ALLOW_AUTODIFF |
601 |
|
|
C-- Reset the model iteration counter and the model time. |
602 |
|
|
myIter = nIter0 + (iloop-1) |
603 |
|
|
myTime = startTime + float(iloop-1)*deltaTClock |
604 |
|
|
#endif |
605 |
|
|
CALL TIMER_START('PROFILES_INLOOP [MAIN_DO_LOOP]', myThid) |
606 |
|
|
CALL PROFILES_INLOOP( myTime, myThid ) |
607 |
|
|
CALL TIMER_STOP ('PROFILES_INLOOP [MAIN_DO_LOOP]', myThid) |
608 |
|
|
ENDIF |
609 |
|
|
#endif |
610 |
|
|
|
611 |
|
|
CALL TIMER_START('MAIN_DO_LOOP [THE_MAIN_LOOP]', myThid) |
612 |
|
|
CALL MAIN_DO_LOOP( iloop, myTime, myIter, myThid ) |
613 |
|
|
CALL TIMER_STOP ('MAIN_DO_LOOP [THE_MAIN_LOOP]', myThid) |
614 |
|
|
|
615 |
|
|
c-- >>> Loop body end <<< |
616 |
|
|
#ifndef ALLOW_OPENAD |
617 |
|
|
# ifdef ALLOW_AUTODIFF |
618 |
|
|
# ifdef ALLOW_TAMC_CHECKPOINTING |
619 |
|
|
endif |
620 |
|
|
enddo |
621 |
|
|
endif |
622 |
|
|
enddo |
623 |
|
|
# ifndef AUTODIFF_2_LEVEL_CHECKPOINT |
624 |
|
|
endif |
625 |
|
|
enddo |
626 |
|
|
# endif |
627 |
|
|
# ifdef AUTODIFF_4_LEVEL_CHECKPOINT |
628 |
|
|
endif |
629 |
|
|
enddo |
630 |
|
|
# endif |
631 |
|
|
# else /* ndef ALLOW_TAMC_CHECKPOINTING */ |
632 |
|
|
ENDDO |
633 |
|
|
# endif /* ALLOW_TAMC_CHECKPOINTING */ |
634 |
|
|
# else /* ALLOW_AUTODIFF */ |
635 |
|
|
ENDDO |
636 |
|
|
# endif /* ALLOW_AUTODIFF */ |
637 |
|
|
#endif /* undef ALLOW_OPENAD */ |
638 |
|
|
|
639 |
|
|
c >>>>>>>>>>>>>>>>>>>>>>>>>>> LOOP <<<<<<<<<<<<<<<<<<<<<<<<<<<< |
640 |
|
|
c >>>>>>>>>>>>>>>>>>>>>>>>>>> STOPS <<<<<<<<<<<<<<<<<<<<<<<<<<<< |
641 |
|
|
|
642 |
|
|
|
643 |
|
|
#ifdef ALLOW_ECCO |
644 |
|
|
#ifdef ALLOW_ECCO_EVOLUTION |
645 |
|
|
c-- Accumulate time averages of temperature, salinity |
646 |
|
|
CALL TIMER_START('COST_AVERAGESFIELDS [THE_MAIN_LOOP]',myThid) |
647 |
|
|
CALL COST_AVERAGESFIELDS( endtime, myThid ) |
648 |
|
|
CALL TIMER_STOP ('COST_AVERAGESFIELDS [THE_MAIN_LOOP]',myThid) |
649 |
|
|
#endif /* ALLOW_ECCO_EVOLUTION */ |
650 |
|
|
#endif /* ALLOW_ECCO */ |
651 |
|
|
|
652 |
|
|
#ifdef ALLOW_PROFILES |
653 |
|
|
IF (usePROFILES) THEN |
654 |
|
|
c-- Accumulate in-situ time averages of temperature, salinity, SSH. |
655 |
|
|
CALL TIMER_START('PROFILES_INLOOP [THE_MAIN_LOOP]', myThid) |
656 |
|
|
CALL PROFILES_INLOOP( endtime, myThid ) |
657 |
|
|
CALL TIMER_STOP ('PROFILES_INLOOP [THE_MAIN_LOOP]', myThid) |
658 |
|
|
c-- Compute all profiles cost function contributions. |
659 |
|
|
CALL cost_profiles( myiter, mytime, mythid) |
660 |
|
|
ENDIF |
661 |
|
|
#endif |
662 |
|
|
|
663 |
|
|
#ifdef ALLOW_ECCO |
664 |
|
|
#ifdef ALLOW_ECCO_EVOLUTION |
665 |
|
|
IF ( useECCO ) then |
666 |
|
|
c-- Compute all ecco cost function contributions. |
667 |
|
|
CALL TIMER_START('ECCO_COST_DRIVER [THE_MAIN_LOOP]', myThid) |
668 |
|
|
CALL ECCO_COST_DRIVER ( endTime, myIter, myThid ) |
669 |
|
|
CALL TIMER_STOP ('ECCO_COST_DRIVER [THE_MAIN_LOOP]', myThid) |
670 |
|
|
ENDIF |
671 |
|
|
#endif /* ALLOW_ECCO_EVOLUTION */ |
672 |
|
|
#endif /* ALLOW_ECCO */ |
673 |
|
|
|
674 |
|
|
#ifdef ALLOW_COST |
675 |
|
|
#if (defined (ALLOW_OPENAD) && defined (ALLOW_OPENAD_DIVA)) |
676 |
|
|
IF(MYITER .eq. NITER0+nTimeSteps_l2*nTimeSteps) THEN |
677 |
|
|
#endif |
678 |
|
|
c-- Sum all cost function contributions. |
679 |
|
|
CALL TIMER_START('COST_FINAL [ADJOINT SPIN-DOWN]', myThid) |
680 |
|
|
CALL COST_FINAL ( myThid ) |
681 |
|
|
CALL TIMER_STOP ('COST_FINAL [ADJOINT SPIN-DOWN]', myThid) |
682 |
|
|
#if (defined (ALLOW_OPENAD) && defined (ALLOW_OPENAD_DIVA)) |
683 |
|
|
end if |
684 |
|
|
#endif |
685 |
|
|
# ifdef ALLOW_OPENAD |
686 |
|
|
c$openad DEPENDENT(fc) |
687 |
|
|
# endif /* ALLOW_OPENAD */ |
688 |
|
|
|
689 |
|
|
#endif /* ALLOW_COST */ |
690 |
|
|
|
691 |
|
|
_BARRIER |
692 |
|
|
CALL TIMER_STOP ('MAIN LOOP [THE_MAIN_LOOP]', myThid) |
693 |
|
|
|
694 |
|
|
#ifdef ALLOW_DEBUG |
695 |
|
|
IF (debugMode) CALL DEBUG_LEAVE('THE_MAIN_LOOP',myThid) |
696 |
|
|
#endif |
697 |
|
|
|
698 |
|
|
RETURN |
699 |
|
|
END |