/[MITgcm]/MITgcm/model/src/the_main_loop.F
ViewVC logotype

Contents of /MITgcm/model/src/the_main_loop.F

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


Revision 1.59 - (show annotations) (download)
Thu Feb 10 05:39:29 2005 UTC (19 years, 3 months ago) by heimbach
Branch: MAIN
CVS Tags: checkpoint57d_post, checkpoint57e_post, eckpoint57e_pre
Changes since 1.58: +10 -3 lines
Add hooks for inAdExact.

1 C $Header: /u/gcmpack/MITgcm/model/src/the_main_loop.F,v 1.58 2004/12/03 00:40:40 mlosch Exp $
2 C $Name: $
3
4 #include "PACKAGES_CONFIG.h"
5 #include "CPP_OPTIONS.h"
6 #ifdef ALLOW_OBCS
7 # include "OBCS_OPTIONS.h"
8 #endif
9 #ifdef ALLOW_SEAICE
10 # include "SEAICE_OPTIONS.h"
11 #endif
12 #ifdef ALLOW_GMREDI
13 # include "GMREDI_OPTIONS.h"
14 #endif
15
16 CBOP
17 C !ROUTINE: THE_MAIN_LOOP
18 C !INTERFACE:
19 SUBROUTINE THE_MAIN_LOOP( myTime, myIter, myThid )
20
21 C !DESCRIPTION: \bv
22 C *================================================================*
23 C | SUBROUTINE the_main_loop
24 C | o Run the ocean model and evaluate the specified cost function.
25 C *================================================================*
26 C |
27 C | THE_MAIN_LOOP is the toplevel routine for the Tangent Linear and
28 C | Adjoint Model Compiler (TAMC). For this purpose the initialization
29 C | of the model was split into two parts. Those parameters that do
30 C | not depend on a specific model run are set in INITIALISE_FIXED,
31 C | whereas those that do depend on the specific realization are
32 C | initialized in INITIALISE_VARIA.
33 C | This routine is to be used in conjuction with the MITgcmuv
34 C | checkpoint 37.
35 C *================================================================*
36 C \ev
37
38 C !USES:
39 IMPLICIT NONE
40 C == Global variables ==
41 #include "SIZE.h"
42 #include "EEPARAMS.h"
43 #include "PARAMS.h"
44
45 c**************************************
46 #ifdef ALLOW_AUTODIFF_TAMC
47
48 c These includes are needed for
49 c AD-checkpointing.
50 c They provide the fields to be stored.
51
52 # include "GRID.h"
53 # include "DYNVARS.h"
54 # include "FFIELDS.h"
55 # include "EOS.h"
56 # include "GAD.h"
57 # ifdef ALLOW_CD_CODE
58 # include "CD_CODE_VARS.h"
59 # endif
60 # ifdef ALLOW_PTRACERS
61 # include "PTRACERS_SIZE.h"
62 # include "PTRACERS.h"
63 # endif
64 # ifdef ALLOW_NONHYDROSTATIC
65 # include "CG3D.h"
66 # endif
67 # ifdef EXACT_CONSERV
68 # include "SURFACE.h"
69 # endif
70 # ifdef ALLOW_OBCS
71 # include "OBCS.h"
72 # endif
73 # ifdef ALLOW_EXF
74 # include "exf_fields.h"
75 # include "exf_clim_fields.h"
76 # ifdef ALLOW_BULKFORMULAE
77 # include "exf_constants.h"
78 # endif
79 # endif /* ALLOW_EXF */
80 # ifdef ALLOW_SEAICE
81 # include "SEAICE.h"
82 # endif
83 # ifdef ALLOW_EBM
84 # include "EBM.h"
85 # endif
86 # ifdef ALLOW_DIVIDED_ADJOINT_MPI
87 # include "mpif.h"
88 # endif
89
90 # include "tamc.h"
91 # include "ctrl.h"
92 # include "ctrl_dummy.h"
93 # include "cost.h"
94
95 #endif /* ALLOW_AUTODIFF_TAMC */
96 c**************************************
97
98 C !INPUT/OUTPUT PARAMETERS:
99 C == Routine arguments ==
100 C note: under the multi-threaded model myiter and
101 C mytime are local variables passed around as routine
102 C arguments. Although this is fiddly it saves the need to
103 C impose additional synchronisation points when they are
104 C updated.
105 C myIter - iteration counter for this thread
106 C myTime - time counter for this thread
107 C myThid - thread number for this instance of the routine.
108 INTEGER myThid
109 INTEGER myIter
110 _RL myTime
111
112 C !LOCAL VARIABLES:
113 C == Local variables ==
114 integer iloop
115 #ifdef ALLOW_AUTODIFF_TAMC
116 integer ilev_1
117 integer ilev_2
118 integer ilev_3
119 integer max_lev2
120 integer max_lev3
121 #endif
122 CEOP
123
124 #ifdef ALLOW_DEBUG
125 IF (debugMode) CALL DEBUG_ENTER('THE_MAIN_LOOP',myThid)
126 #endif
127
128 #ifdef ALLOW_AUTODIFF_TAMC
129 c-- Initialize storage for the cost function evaluation.
130 CADJ INIT dummytape = common, 1
131 c-- Initialize storage for the outermost loop.
132 CADJ INIT tapelev_ini_bibj_k = USER
133 CADJ INIT tapelev_init = USER
134 #ifdef AUTODIFF_2_LEVEL_CHECKPOINT
135 CADJ INIT tapelev2 = USER
136 #else
137 CADJ INIT tapelev3 = USER
138 #endif
139
140 nIter0 = INT( startTime/deltaTClock )
141 ikey_dynamics = 1
142
143 CALL TIMER_START('ADJOINT SPIN-UP', mythid)
144 #endif
145
146 #ifdef ALLOW_DEBUG
147 IF (debugMode) CALL DEBUG_CALL('INITIALISE_VARIA',myThid)
148 #endif
149
150 C-- Set initial conditions (variable arrays)
151 CALL TIMER_START('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid)
152 CALL INITIALISE_VARIA( mythid )
153 CALL TIMER_STOP ('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid)
154
155 #ifdef ALLOW_MONITOR
156 #ifdef ALLOW_DEBUG
157 IF (debugMode) CALL DEBUG_CALL('MONITOR',myThid)
158 #endif
159 C-- Check status of solution (statistics, cfl, etc...)
160 CALL TIMER_START('MONITOR [THE_MAIN_LOOP]', mythid)
161 CALL MONITOR( myIter, myTime, myThid )
162 CALL TIMER_STOP ('MONITOR [THE_MAIN_LOOP]', mythid)
163 #endif /* ALLOW_MONITOR */
164
165 C-- Do IO if needed (Dump for start state).
166 #ifdef ALLOW_DEBUG
167 IF (debugMode) CALL DEBUG_CALL('DO_THE_MODEL_IO',myThid)
168 #endif
169
170 #ifdef ALLOW_OFFLINE
171 CALL TIMER_START('OFFLINE_MODEL_IO [FORWARD_STEP]',myThid)
172 CALL OFFLINE_MODEL_IO( myTime, myIter, myThid )
173 CALL TIMER_STOP ('OFFLINE_MODEL_IO [FORWARD_STEP]',myThid)
174 #else
175 CALL TIMER_START('DO_THE_MODEL_IO [THE_MAIN_LOOP]', mythid)
176 CALL DO_THE_MODEL_IO( myTime, myIter, mythid )
177 CALL TIMER_STOP ('DO_THE_MODEL_IO [THE_MAIN_LOOP]', mythid)
178 #endif
179
180
181 #ifdef ALLOW_AUTODIFF_TAMC
182 CALL TIMER_STOP ('ADJOINT SPIN-UP', mythid)
183 _BARRIER
184 #endif
185
186 c-- Do the model integration.
187 CALL TIMER_START('MAIN LOOP [THE_MAIN_LOOP]', mythid)
188
189 c >>>>>>>>>>>>>>>>>>>>>>>>>>> LOOP <<<<<<<<<<<<<<<<<<<<<<<<<<<<
190 c >>>>>>>>>>>>>>>>>>>>>>>>>>> STARTS <<<<<<<<<<<<<<<<<<<<<<<<<<<<
191
192 #ifdef ALLOW_AUTODIFF_TAMC
193 #ifdef ALLOW_TAMC_CHECKPOINTING
194
195 max_lev3=nTimeSteps/(nchklev_1*nchklev_2)+1
196 max_lev2=nTimeSteps/nchklev_1+1
197
198 c**************************************
199 #ifdef ALLOW_DIVIDED_ADJOINT
200 CADJ loop = divided
201 #endif
202 c**************************************
203
204 #ifndef AUTODIFF_2_LEVEL_CHECKPOINT
205
206 do ilev_3 = 1,nchklev_3
207 if(ilev_3.le.max_lev3) then
208 c**************************************
209 #include "checkpoint_lev3_directives.h"
210 c**************************************
211
212 c-- Initialise storage for the middle loop.
213 CADJ INIT tapelev2 = USER
214
215 #endif /* AUTODIFF_2_LEVEL_CHECKPOINT */
216
217 do ilev_2 = 1,nchklev_2
218 if(ilev_2.le.max_lev2) then
219 c**************************************
220 #include "checkpoint_lev2_directives.h"
221 c**************************************
222
223 c**************************************
224 #ifdef ALLOW_AUTODIFF_TAMC
225 c-- Initialize storage for the innermost loop.
226 c-- Always check common block sizes for the checkpointing!
227 c--
228 CADJ INIT comlev1 = COMMON,nchklev_1
229 CADJ INIT comlev1_bibj = COMMON,nchklev_1*nsx*nsy*nthreads_chkpt
230 CADJ INIT comlev1_bibj_k = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt
231 c--
232 #ifdef ALLOW_KPP
233 CADJ INIT comlev1_kpp = COMMON,nchklev_1*nsx*nsy
234 CADJ INIT comlev1_kpp_k = COMMON,nchklev_1*nsx*nsy*nr
235 #endif /* ALLOW_KPP */
236 c--
237 #ifdef ALLOW_GMREDI
238 CADJ INIT comlev1_gmredi_k_gad
239 CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass
240 #endif /* ALLOW_GMREDI */
241 c--
242 #ifdef ALLOW_PTRACERS
243 CADJ INIT comlev1_bibj_ptracers = COMMON,
244 CADJ & nchklev_1*nsx*nsy*nthreads_chkpt*PTRACERS_num
245 #endif /* ALLOW_PTRACERS */
246 c--
247 #ifndef DISABLE_MULTIDIM_ADVECTION
248 CADJ INIT comlev1_bibj_k_gad
249 CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass
250 CADJ INIT comlev1_bibj_k_gad_pass
251 CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass*maxcube
252 #endif /* DISABLE_MULTIDIM_ADVECTION */
253 c--
254 #if (defined (ALLOW_EXF) && defined (ALLOW_BULKFORMULAE))
255 CADJ INIT comlev1_exf_1
256 CADJ & = COMMON,nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt
257 CADJ INIT comlev1_exf_2
258 CADJ & = COMMON,niter_bulk*nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt
259 #endif /* ALLOW_BULKFORMULAE */
260 c--
261 #ifdef ALLOW_SEAICE
262 # ifdef SEAICE_ALLOW_DYNAMICS
263 CADJ INIT comlev1_lsr = COMMON,nchklev_1*2
264 # endif
265 #endif /* ALLOW_SEAICE */
266 c--
267 #endif /* ALLOW_AUTODIFF_TAMC */
268 c**************************************
269
270 do ilev_1 = 1,nchklev_1
271
272 c-- The if-statement below introduces a some flexibility in the
273 c-- choice of the 3-tupel ( nchklev_1, nchklev_2, nchklev_3 ).
274
275 iloop = (ilev_2 - 1)*nchklev_1 + ilev_1
276 #ifndef AUTODIFF_2_LEVEL_CHECKPOINT
277 & + (ilev_3 - 1)*nchklev_2*nchklev_1
278 #endif
279
280 if ( iloop .le. nTimeSteps ) then
281
282 #else /* ALLOW_TAMC_CHECKPOINTING undefined */
283 c-- Initialise storage for reference trajectory without TAMC check-
284 c-- pointing.
285 CADJ INIT history = USER
286 CADJ INIT comlev1_bibj = COMMON,nchklev_0*nsx*nsy*nthreads_chkpt
287 CADJ INIT comlev1_bibj_k = COMMON,nchklev_0*nsx*nsy*nr*nthreads_chkpt
288 CADJ INIT comlev1_kpp = COMMON,nchklev_0*nsx*nsy
289
290 c-- Check the choice of the checkpointing parameters in relation
291 c-- to nTimeSteps: (nchklev_0 .ge. nTimeSteps)
292 if (nchklev_0 .lt. nTimeSteps) then
293 print*
294 print*, ' the_main_loop: TAMC checkpointing parameter ',
295 & 'nchklev_0 = ', nchklev_0
296 print*, ' not consistent with nTimeSteps = ',
297 & nTimeSteps
298 stop ' ... stopped in the_main_loop.'
299 endif
300
301 DO iloop = 1, nTimeSteps
302
303 #endif /* ALLOW_TAMC_CHECKPOINTING */
304
305 #else /* ALLOW_AUTODIFF_TAMC undefined */
306
307 c-- Start the main loop of adjoint_Objfunc. Automatic differentiation
308 c-- NOT enabled.
309 DO iloop = 1, nTimeSteps
310
311 #endif /* ALLOW_AUTODIFF_TAMC */
312
313 c-- >>> Loop body start <<<
314
315 #ifdef ALLOW_AUTODIFF_TAMC
316 nIter0 = INT( startTime/deltaTClock )
317 ikey_dynamics = ilev_1
318 #endif
319
320 #ifdef ALLOW_AUTODIFF_TAMC
321 CALL AUTODIFF_INADMODE_UNSET( myThid )
322 #endif
323
324 #ifdef ALLOW_DEBUG
325 IF (debugMode) CALL DEBUG_CALL('FORWARD_STEP',myThid)
326 #endif
327 CALL TIMER_START('FORWARD_STEP [THE_MAIN_LOOP]',mythid)
328 CALL FORWARD_STEP( iloop, mytime, myiter, mythid )
329 CALL TIMER_STOP ('FORWARD_STEP [THE_MAIN_LOOP]',mythid)
330
331 #ifdef ALLOW_AUTODIFF_TAMC
332 CALL AUTODIFF_INADMODE_SET( myThid )
333 #endif
334
335 c-- >>> Loop body end <<<
336
337 #ifdef ALLOW_AUTODIFF_TAMC
338 #ifdef ALLOW_TAMC_CHECKPOINTING
339 endif
340 enddo
341 endif
342 enddo
343 #ifndef AUTODIFF_2_LEVEL_CHECKPOINT
344 endif
345 enddo
346 #endif
347 #else
348 enddo
349 #endif
350
351 #else
352 enddo
353 #endif
354
355 #ifdef ALLOW_COST
356 c-- Sum all cost function contributions.
357 call TIMER_START('COST_FINAL [ADJOINT SPIN-DOWN]', mythid)
358 call COST_FINAL ( mythid )
359 call TIMER_STOP ('COST_FINAL [ADJOINT SPIN-DOWN]', mythid)
360 #endif
361
362 _BARRIER
363 CALL TIMER_STOP ('MAIN LOOP [THE_MAIN_LOOP]', mythid)
364
365 #ifdef ALLOW_DEBUG
366 IF (debugMode) CALL DEBUG_LEAVE('THE_MAIN_LOOP',myThid)
367 #endif
368
369 END

  ViewVC Help
Powered by ViewVC 1.1.22