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