/[MITgcm]/MITgcm/verification/offline_exf_seaice/code_ad/the_model_main.F
ViewVC logotype

Contents of /MITgcm/verification/offline_exf_seaice/code_ad/the_model_main.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download)
Mon Mar 4 19:32:24 2013 UTC (11 years, 2 months ago) by heimbach
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +1 -1 lines
FILE REMOVED
Remove special versions of the_main_loop.F from ecco package,
revert to unified routine in model/src/

1 C $Header: /u/gcmpack/MITgcm/verification/offline_exf_seaice/code_ad/the_model_main.F,v 1.5 2012/12/27 20:33:29 heimbach Exp $
2 C $Name: $
3
4 CBOI
5 C
6 C !TITLE: MITGCM KERNEL CODE SYNOPSIS
7 C !AUTHORS: mitgcm developers ( support@mitgcm.org )
8 C !AFFILIATION: Massachussetts Institute of Technology
9 C !DATE:
10 C !INTRODUCTION: Kernel dynamical routines
11 C This document summarises MITgcm code under the model/ subdirectory.
12 C The code under model/ ( src/ and inc/ ) contains most of
13 C the driver routines for the baseline forms of the kernel equations in the
14 C MITgcm algorithm. Numerical code for much of the baseline forms of
15 C these equations is also under the model/ directory. Other numerical code
16 C used for the kernel equations is contained in packages in the pkg/
17 C directory tree.
18 C Code for auxiliary equations and alternate discretizations of the kernel
19 C equations and algorithm can also be found in the pkg/ directory tree.
20 C
21 C \subsection{Getting Help and Reporting Errors and Problems}
22 C If you have questions please subscribe and e-mail support@mitgcm.org.
23 C We also welcome reports of errors and inconsistencies in the code or
24 C in the accompanying documentation. Please feel free to send these
25 C to support@mitgcm.org. For further information and to review
26 C problems reported to support@mitgcm.org please visit http://mitgcm.org.
27 C
28 C \subsection{MITgcm Kernel Code Calling Sequence}
29 C \bv
30 C
31 C Invocation from WRAPPER level...
32 C
33 C |
34 C |-THE_MODEL_MAIN :: Primary driver for the MITgcm algorithm
35 C | :: Called from WRAPPER level numerical
36 C | :: code invocation routine. On entry
37 C | :: to THE_MODEL_MAIN separate thread and
38 C | :: separate processes will have been established.
39 C | :: Each thread and process will have a unique ID
40 C | :: but as yet it will not be associated with a
41 C | :: specific region in decomposed discrete space.
42 C |
43 C |-INITIALISE_FIXED :: Set fixed model arrays such as topography,
44 C | | :: grid, solver matrices etc..
45 C | |
46 C | |-INI_PARMS :: Routine to set kernel model parameters.
47 C | | :: Kernel parameters are read from file "data"
48 C | | :: in directory in which code executes.
49 C | |
50 C | |-PACAKGES_BOOT :: Start up the optional package environment.
51 C | | :: Runtime selection of active packages.
52 C | |-PACKAGES_READPARMS :: read all packages input parameter file
53 C | | |- ${PKG}_READPARMS
54 C | |
55 C | |-INI_MODEL_IO :: Initialise Input/Ouput setting
56 C | |
57 C | |-INI_GRID :: Control grid array (vert. and hori.) initialisation.
58 C | | :: Grid arrays are held and described in GRID.h.
59 C | |
60 C | |-INI_DEPTHS :: Read (from "bathyFile") or set bathymetry/orography.
61 C | |-INI_MASKS_ETC :: Derive horizontal and vertical cell fractions and
62 C | | :: land masking for solid-fluid boundaries.
63 C | |
64 C | |-PACKAGES_INIT_FIXED :: do all packages fixed-initialisation setting
65 C | | |- ${PKG}_INIT_FIXED
66 C | |
67 C | |-CONFIG_SUMMARY :: Provide synopsis of kernel setup. Includes
68 C | | :: annotated table of kernel parameter settings.
69 C | |
70 C | |-PACKAGES_CHECK :: call each package configuration checking S/R
71 C | | |- ${PKG}_CHECK
72 C | |
73 C | |-CONFIG_CHECK :: Check config and parameter consistency.
74 C |
75 C |-CTRL_UNPACK :: Control vector support package. see pkg/ctrl
76 C |
77 C |-ADTHE_MAIN_LOOP :: Derivative evaluating form of main time stepping loop
78 C ! :: Automatically generated by TAMC/TAF.
79 C |
80 C |-THE_MAIN_LOOP :: Main timestepping loop routine.
81 C | |
82 C | |-INITIALISE_VARIA :: Set the initial conditions for time evolving
83 C | | |-INI_DYNVARS :: set common block variable to zero
84 C | | |-INI_NH_VARS :: set common block variable to zero
85 C | | |
86 C | | |-INI_FIELDS :: Control initialising model fields to non-zero
87 C | | | |-INI_VEL,_THETA,_SALT,_PSURF, ...
88 C | | | |-READ_PICKUP
89 C | | |
90 C | | |-INI_FORCING :: initialise forcing fields
91 C | | |
92 C | | |-PACKAGES_INIT_VARIABLES :: Does initialisation of time evolving
93 C | | | | ${PKG}_INIT_VARIA :: package data.
94 C | | |
95 C | | |-MONITOR :: Monitor state (see pkg/monitor)
96 C | | |-STATE_SUMMARY :: Summarise model prognostic variables.
97 C | | |-DO_THE_MODEL_IO :: Standard diagnostic I/O.
98 C | |
99 C====|>| ****************************
100 C====|>| BEGIN MAIN TIMESTEPPING LOOP
101 C====|>| ****************************
102 C | |-COST_AVERAGESFIELDS :: time-averaged Cost function terms (see pkg/cost)
103 C | |
104 C/\ | |-FORWARD_STEP :: Step forward a time-step ( AT LAST !!! )
105 C/\ | | |
106 C/\ | | |-LOAD_FIELDS_DRIVER :: control loading of input fields from files
107 C/\ | | |
108 C/\ | | |-CPL_EXPORT_MY_DATA :: Send coupling fields to coupler
109 C/\ | | |-CPL_IMPORT_EXTERNAL_DATA :: Receive coupling fields from coupler
110 C/\ | | |
111 C/\ | | |-DO_ATMOSPHERIC_PHYS :: Atmospheric physics computation
112 C/\ | | |
113 C/\ | | |-DO_OCEANIC_PHYS :: Oceanic (& seaice) physics computation
114 C/\ | | | |-OBCS_CALC :: Open boundary. package (see pkg/obcs).
115 C/\ | | |
116 C/\ | | |-GCHEM_CALC_TENDENCY :: geochemistry driver routine (see pkg/gchem)
117 C/\ | | |
118 C/\ | | |-THERMODYNAMICS :: (synchronous time-stepping)
119 C/\ | | | theta, salt + tracer equations driver.
120 C/\ | | | |-EXTERNAL_FORCING_SURF:: Accumulates appropriately dimensioned
121 C/\ | | | | :: forcing terms.
122 C/\ | | | |-GAD_ADVECTION :: Generalised advection driver (multi-dim
123 C/\ | | | | advection case) (see pkg/gad).
124 C/\ | | | |-CALC_GT :: Calculate the temperature tendency terms
125 C/\ | | | |-TIMESTEP_TRACER :: Step tracer field forward in time
126 C/\ | | | |-CALC_GS :: Calculate the salinity tendency terms
127 C/\ | | | |-TIMESTEP_TRACER :: Step tracer field forward in time
128 C/\ | | | |-PTRACERS_INTEGRATE :: Integrate other tracer(s) (see pkg/ptracers).
129 C/\ | | | |-IMPLDIFF :: Solve vertical implicit diffusion equation.
130 C/\ | | | |-OBCS_APPLY_TS :: Open boundary package (see pkg/obcs ).
131 C/\ | | |
132 C/\ | | |-DYNAMICS :: Momentum equations driver.
133 C/\ | | | |
134 C/\ | | | |-CALC_GRAD_PHI_SURF :: Calculate the gradient of the surface
135 C/\ | | | | Potential anomaly.
136 C/\ | | | |-CALC_VISCOSITY :: Calculate net vertical viscosity
137 C/\ | | | |-CALC_PHI_HYD :: Integrate the hydrostatic relation.
138 C/\ | | | |-MOM_FLUXFORM :: Flux form mom eqn. package (pkg/mom_fluxform)
139 C/\ | | | |-MOM_VECINV :: Vector invariant form mom eqn (pkg/mom_vecinv)
140 C/\ | | | |-TIMESTEP :: Step momentum fields forward in time
141 C/\ | | | |-OBCS_APPLY_UV :: Open boundary package (see pkg/obcs).
142 C/\ | | | |-IMPLDIFF :: Solve vertical implicit diffusion equation.
143 C/\ | | | |-CALC_GW :: vert. momentum tendency terms (Non-Hydrostatic)
144 C/\ | | |
145 C/\ | | |-UPDATE_SURF_DR :: Update the surface-level thickness fraction.
146 C/\ | | |-UPDATE_R_STAR :: Update the level thickness fraction.
147 C/\ | | |-UPDATE_CG2D :: Update 2d conjugate grad. for Free-Surf.
148 C/\ | | |
149 C/\ | | |-SOLVE_FOR_PRESSURE :: Find surface pressure.
150 C/\ | | | |-CG2D :: Two-dim pre-con. conjugate-gradient.
151 C/\ | | | |-CG3D :: Three-dim pre-con. conjugate-gradient solver.
152 C/\ | | |
153 C/\ | | |-MOMENTUM_CORRECTION_STEP :: Finalise momentum stepping
154 C/\ | | | |-CALC_GRAD_PHI_SURF :: Return DDx and DDy of surface pressure
155 C/\ | | | |-CORRECTION_STEP :: Pressure correction to momentum
156 C/\ | | | |-OBCS_APPLY_UV :: Open boundary package (see pkg/obcs).
157 C/\ | | |
158 C/\ | | |-INTEGR_CONTINUITY :: Integrate continuity equation
159 C/\ | | |
160 C/\ | | |-THERMODYNAMICS :: (staggered time-stepping)
161 C/\ | | | theta, salt + tracer equations driver.
162 C/\ | | |
163 C/\ | | |-TRACERS_CORRECTION_STEP :: Finalise tracer stepping
164 C/\ | | |
165 C/\ | | |-GCHEM_FORCING_SEP :: tracer forcing for gchem pkg (if tracer
166 C/\ | | | dependent tendencies calculated separately)
167 C/\ | | |
168 C/\ | | |-DO_FIELDS_BLOCKING_EXCHANGES :: Sync up overlap regions.
169 C/\ | | |
170 C/\ | | |-MONITOR :: Monitor package (pkg/monitor).
171 C/\ | | |-DO_THE_MODEL_IO :: Standard diagnostic I/O.
172 C/\ | | |
173 C/\ | | |-DO_WRITE_PICKUP :: Write restart files.
174 C | |
175 C<===|=| **************************
176 C<===|=| END MAIN TIMESTEPPING LOOP
177 C<===|=| **************************
178 C | |
179 C | |-COST_AVERAGESFIELDS :: time-averaged Cost function terms (see pkg/cost)
180 C | |-COST_FINAL :: Cost function package. (see pkg/cost)
181 C |
182 C |-CTRL_PACK :: Control vector support package. see pkg/ctrl
183 C |
184 C |-GRDCHK_MAIN :: Gradient check package. see pkg/grdchk
185 C |
186 C |-TIMER_PRINTALL :: Computational timing summary
187 C |
188 C |-COMM_STATS :: Summarise inter-proc and inter-thread communication
189 C :: events.
190 C \ev
191 C
192 CEOI
193
194 #include "PACKAGES_CONFIG.h"
195 #include "CPP_OPTIONS.h"
196 #include "AD_CONFIG.h"
197
198 CBOP
199 C !ROUTINE: THE_MODEL_MAIN
200
201 C !INTERFACE:
202 SUBROUTINE THE_MODEL_MAIN(myThid)
203
204 C !DESCRIPTION: \bv
205 C *==========================================================*
206 C | SUBROUTINE THE_MODEL_MAIN
207 C | o Master controlling routine for model using the MITgcm
208 C | UV parallel wrapper.
209 C *==========================================================*
210 C | THE_MODEL_MAIN is invoked by the MITgcm UV parallel
211 C | wrapper with a single integer argument "myThid". This
212 C | variable identifies the thread number of an instance of
213 C | THE_MODEL_MAIN. Each instance of THE_MODEL_MAIN works
214 C | on a particular region of the models domain and
215 C | synchronises with other instances as necessary. The
216 C | routine has to "understand" the MITgcm parallel
217 C | environment and the numerical algorithm. Editing this
218 C | routine is best done with some knowledge of both aspects.
219 C | Notes
220 C | =====
221 C | C*P* comments indicating place holders for which code is
222 C | presently being developed.
223 C *==========================================================*
224 C \ev
225
226 C !CALLING SEQUENCE:
227 C THE_MODEL_MAIN()
228 C |
229 C |
230 C |--INITIALISE_FIXED
231 C | o Set model configuration (fixed arrays)
232 C | Topography, hydrography, timestep, grid, etc..
233 C |
234 C |--CTRL_UNPACK o Derivative mode. Unpack control vector.
235 C |
236 C |--ADTHE_MAIN_LOOP o Main timestepping loop for combined
237 C | prognostic and reverse mode integration.
238 C |
239 C |--THE_MAIN_LOOP o Main timestepping loop for pure prognostic
240 C | integration.
241 C |
242 C |--CTRL_PACK o Derivative mode. Unpack control vector.
243 C |
244 C |--GRDCHK_MAIN o Gradient check control routine.
245 C |
246 C |--TIMER_PRINTALL o Print out timing statistics.
247 C |
248 C |--COMM_STATS o Print out communication statistics.
249
250 C !USES:
251 IMPLICIT NONE
252
253 C == Global variables ===
254 #include "SIZE.h"
255 #include "EEPARAMS.h"
256 #include "PARAMS.h"
257 #include "DYNVARS.h"
258
259 #ifdef ALLOW_AUTODIFF_TAMC
260 # include "tamc.h"
261 #endif
262 #ifdef ALLOW_CTRL
263 # include "ctrl.h"
264 # include "optim.h"
265 #endif
266
267 C !INPUT/OUTPUT PARAMETERS:
268 C == Routine arguments ==
269 C myThid :: Thread number for this instance of the routine.
270 INTEGER myThid
271
272 C !LOCAL VARIABLES:
273 C == Local variables ==
274 C Note: Under the multi-threaded model myIter and myTime are local
275 C variables passed around as routine arguments.
276 C Although this is fiddly it saves the need to impose
277 C additional synchronisation points when they are updated.
278 C myTime :: Time counter for this thread
279 C myIter :: Iteration counter for this thread
280 INTEGER myIter
281 _RL myTime
282 LOGICAL exst
283 LOGICAL lastdiva
284 CEOP
285 c-- set default:
286 exst = .TRUE.
287 lastdiva = .TRUE.
288
289 #ifdef ALLOW_DEBUG
290 IF (debugMode) CALL DEBUG_ENTER('THE_MODEL_MAIN',myThid)
291 #endif
292
293 #if defined(USE_PAPI) || defined(USE_PCL_FLOPS_SFP) || defined(USE_PCL_FLOPS) || defined(USE_PCL)
294 CALL TIMER_CONTROL('','INIT','THE_MODEL_MAIN',myThid)
295 #endif
296 C-- This timer encompasses the whole code
297 CALL TIMER_START('ALL [THE_MODEL_MAIN]',myThid)
298
299 #ifdef ALLOW_DEBUG
300 IF (debugMode) CALL DEBUG_CALL('INITIALISE_FIXED',myThid)
301 #endif
302 C-- Set model configuration (fixed arrays)
303 CALL TIMER_START('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid)
304 CALL INITIALISE_FIXED( myThid )
305 CALL TIMER_STOP ('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid)
306
307 myTime = startTime
308 myIter = nIter0
309
310 #if ( defined (ALLOW_ADMTLM) )
311 c
312 STOP 'should never get here; ADMTLM_DSVD calls ADMTLM_DRIVER'
313 c
314 #elif ( defined (ALLOW_AUTODIFF))
315
316 # ifndef EXCLUDE_CTRL_PACK
317 inquire( file='costfinal', exist=exst )
318 IF ( .NOT. exst ) THEN
319 IF ( (optimcycle.NE.0 .OR. .NOT.doinitxx)
320 & .AND. doMainUnpack ) THEN
321 CALL TIMER_START('CTRL_UNPACK [THE_MODEL_MAIN]',myThid)
322 CALL CTRL_UNPACK( .TRUE. , myThid )
323 CALL TIMER_STOP ('CTRL_UNPACK [THE_MODEL_MAIN]',myThid)
324 ENDIF
325 ENDIF
326 # endif /* EXCLUDE_CTRL_PACK */
327
328 # ifdef ALLOW_COST
329 CALL COST_DEPENDENT_INIT ( myThid )
330 _BARRIER
331 # endif
332
333 # if ( defined (ALLOW_TANGENTLINEAR_RUN) )
334 c
335 # ifdef ALLOW_DEBUG
336 IF (debugMode) CALL DEBUG_CALL('G_THE_MAIN_LOOP',myThid)
337 # endif
338 CALL TIMER_START('G_THE_MAIN_LOOP [TANGENT RUN]',myThid)
339 CALL G_THE_MAIN_LOOP ( myTime, myIter, myThid )
340 CALL TIMER_STOP ('G_THE_MAIN_LOOP [TANGENT RUN]',myThid)
341 c
342 # elif ( defined (ALLOW_ADJOINT_RUN) || \
343 defined (ALLOW_ECCO_OPTIMIZATION) )
344 c
345 # ifdef ALLOW_DIVIDED_ADJOINT
346 c-- The following assumes the TAF option '-pure'
347 inquire( file='costfinal', exist=exst )
348 IF ( .NOT. exst) THEN
349 # ifdef ALLOW_DEBUG
350 IF (debugMode) CALL DEBUG_CALL('MDTHE_MAIN_LOOP',myThid)
351 # endif
352 CALL TIMER_START('MDTHE_MAIN_LOOP [MD RUN]', myThid)
353 CALL MDTHE_MAIN_LOOP ( myTime, myIter, myThid )
354 CALL TIMER_STOP ('MDTHE_MAIN_LOOP [MD RUN]', myThid)
355 CALL COST_FINAL_STORE ( myThid, lastdiva )
356 ELSE
357 # ifdef ALLOW_DEBUG
358 IF (debugMode) CALL DEBUG_CALL('ADTHE_MAIN_LOOP',myThid)
359 # endif
360 CALL TIMER_START('ADTHE_MAIN_LOOP [ADJOINT RUN]', myThid)
361 CALL ADTHE_MAIN_LOOP ( myThid )
362 CALL TIMER_STOP ('ADTHE_MAIN_LOOP [ADJOINT RUN]', myThid)
363 CALL COST_FINAL_RESTORE ( myThid, lastdiva )
364 ENDIF
365 c--
366 # else /* ALLOW_DIVIDED_ADJOINT undef */
367 # ifdef ALLOW_DEBUG
368 IF (debugMode) CALL DEBUG_CALL('ADTHE_MAIN_LOOP',myThid)
369 # endif
370 CALL TIMER_START('ADTHE_MAIN_LOOP [ADJOINT RUN]', myThid)
371 cph# ifdef ALLOW_ECCO
372 cph CALL ADTHE_MAIN_LOOP ( myTime, myThid )
373 cph# else
374 CALL ADTHE_MAIN_LOOP ( myThid )
375 cph# endif
376 CALL TIMER_STOP ('ADTHE_MAIN_LOOP [ADJOINT RUN]', myThid)
377 # endif /* ALLOW_DIVIDED_ADJOINT */
378 c
379 # else /* forward run only within AD setting */
380
381 # ifdef ALLOW_DEBUG
382 IF (debugMode) CALL DEBUG_CALL('THE_MAIN_LOOP',myThid)
383 # endif
384 C-- Call time stepping loop of full model
385 # ifdef ALLOW_DEBUG
386 IF (debugMode) CALL DEBUG_CALL('THE_MAIN_LOOP',myThid)
387 # endif
388 CALL TIMER_START('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid)
389 CALL THE_MAIN_LOOP( myTime, myIter, myThid )
390 CALL TIMER_STOP ('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid)
391
392 # endif /* forward run only within AD setting */
393
394 # ifndef EXCLUDE_CTRL_PACK
395 IF ( lastdiva .AND. doMainPack ) THEN
396 CALL TIMER_START('CTRL_PACK [THE_MODEL_MAIN]',myThid)
397 CALL CTRL_PACK( .FALSE. , myThid )
398 CALL TIMER_STOP ('CTRL_PACK [THE_MODEL_MAIN]',myThid)
399 IF ( ( optimcycle.EQ.0 .OR. (.NOT. doMainUnpack) )
400 & .AND. myIter.EQ.nIter0 ) THEN
401 CALL TIMER_START('CTRL_PACK [THE_MODEL_MAIN]',myThid)
402 CALL CTRL_PACK( .TRUE. , myThid )
403 CALL TIMER_STOP ('CTRL_PACK [THE_MODEL_MAIN]',myThid)
404 ENDIF
405 ENDIF
406 # endif /* EXCLUDE_CTRL_PACK */
407
408 # ifdef ALLOW_GRDCHK
409 IF ( useGrdchk .AND. lastdiva ) THEN
410 CALL TIMER_START('GRDCHK_MAIN [THE_MODEL_MAIN]',myThid)
411 CALL GRDCHK_MAIN( myThid )
412 CALL TIMER_STOP ('GRDCHK_MAIN [THE_MODEL_MAIN]',myThid)
413 _BARRIER
414 ENDIF
415 # endif
416
417 #else /* ALL AD-related undef */
418
419 # ifdef ALLOW_DEBUG
420 IF (debugMode) CALL DEBUG_CALL('THE_MAIN_LOOP',myThid)
421 # endif
422 C-- Call time stepping loop of full model
423 CALL TIMER_START('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid)
424 CALL THE_MAIN_LOOP( myTime, myIter, myThid )
425 CALL TIMER_STOP ('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid)
426
427 #endif /* ALLOW_TANGENTLINEAR_RUN ALLOW_ADJOINT_RUN ALLOW_ADMTLM */
428
429 #ifdef ALLOW_MNC
430 IF (useMNC) THEN
431 C Close all open NetCDF files
432 _BEGIN_MASTER( myThid )
433 CALL MNC_FILE_CLOSE_ALL( myThid )
434 _END_MASTER( myThid )
435 ENDIF
436 #endif
437
438 C-- This timer encompasses the whole code
439 CALL TIMER_STOP ('ALL [THE_MODEL_MAIN]',myThid)
440
441 C-- Write timer statistics
442 IF ( myThid .EQ. 1 ) THEN
443 CALL TIMER_PRINTALL( myThid )
444 CALL COMM_STATS
445 ENDIF
446
447 C-- Check threads synchronization :
448 CALL BAR_CHECK( 9, myThid )
449
450 #ifdef ALLOW_DEBUG
451 IF (debugMode) CALL DEBUG_LEAVE('THE_MODEL_MAIN',myThid)
452 #endif
453
454 RETURN
455 END

  ViewVC Help
Powered by ViewVC 1.1.22