/[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.57 - (show annotations) (download)
Thu Oct 14 05:22:21 2004 UTC (19 years, 8 months ago) by heimbach
Branch: MAIN
CVS Tags: checkpoint56b_post, checkpoint56, checkpoint55i_post, checkpoint55g_post, checkpoint55j_post, checkpoint55h_post, checkpoint56a_post
Changes since 1.56: +2 -1 lines
o Fixing directives for non-ECCO forward_step, after ECCO directives
  have been fixed to avoid recomp. of do_oceanic_phys
o Works well for global_ocean.90x40x15,
  but recomp. issue remains for carbon

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

  ViewVC Help
Powered by ViewVC 1.1.22