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

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

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


Revision 1.57 - (hide 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 heimbach 1.57 C $Header: /u/gcmpack/MITgcm/model/src/the_main_loop.F,v 1.56 2004/10/08 17:25:37 heimbach Exp $
2 edhill 1.40 C $Name: $
3 adcroft 1.1
4 edhill 1.40 #include "PACKAGES_CONFIG.h"
5 adcroft 1.1 #include "CPP_OPTIONS.h"
6 heimbach 1.50 #ifdef ALLOW_OBCS
7     # include "OBCS_OPTIONS.h"
8 heimbach 1.46 #endif
9 adcroft 1.1
10 cnh 1.18 CBOP
11     C !ROUTINE: THE_MAIN_LOOP
12     C !INTERFACE:
13 jmc 1.47 SUBROUTINE THE_MAIN_LOOP( myTime, myIter, myThid )
14 cnh 1.18
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 adcroft 1.1 #include "SIZE.h"
36     #include "EEPARAMS.h"
37     #include "PARAMS.h"
38 heimbach 1.35
39     c**************************************
40 heimbach 1.6 #ifdef ALLOW_AUTODIFF_TAMC
41 heimbach 1.35
42     c These includes are needed for
43     c AD-checkpointing.
44     c They provide the fields to be stored.
45    
46 heimbach 1.32 # include "GRID.h"
47 heimbach 1.16 # include "DYNVARS.h"
48     # include "FFIELDS.h"
49 heimbach 1.29 # include "EOS.h"
50 adcroft 1.21 # include "GAD.h"
51 heimbach 1.41 # ifdef ALLOW_CD_CODE
52     # include "CD_CODE_VARS.h"
53     # endif
54 heimbach 1.38 # ifdef ALLOW_PTRACERS
55 jmc 1.52 # include "PTRACERS_SIZE.h"
56 heimbach 1.38 # include "PTRACERS.h"
57     # endif
58 heimbach 1.16 # ifdef ALLOW_NONHYDROSTATIC
59     # include "CG3D.h"
60     # endif
61 heimbach 1.22 # ifdef EXACT_CONSERV
62     # include "SURFACE.h"
63     # endif
64 heimbach 1.45 # ifdef ALLOW_OBCS
65     # include "OBCS.h"
66     # endif
67 edhill 1.42 # ifdef ALLOW_EXF
68 heimbach 1.35 # include "exf_fields.h"
69     # include "exf_clim_fields.h"
70     # ifdef ALLOW_BULKFORMULAE
71     # include "exf_constants.h"
72     # endif
73 edhill 1.42 # endif /* ALLOW_EXF */
74 heimbach 1.35 # ifdef ALLOW_SEAICE
75     # include "SEAICE.h"
76     # endif
77 heimbach 1.51 # ifdef ALLOW_EBM
78     # include "EBM.h"
79     # endif
80 heimbach 1.35 # 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 heimbach 1.6
92 cnh 1.18 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 heimbach 1.6
106 cnh 1.18 C !LOCAL VARIABLES:
107     C == Local variables ==
108 heimbach 1.6 integer iloop
109 heimbach 1.56 #ifdef ALLOW_AUTODIFF_TAMC
110 heimbach 1.6 integer ilev_1
111     integer ilev_2
112     integer ilev_3
113     integer max_lev2
114     integer max_lev3
115     #endif
116 cnh 1.18 CEOP
117 adcroft 1.1
118 edhill 1.44 #ifdef ALLOW_DEBUG
119 adcroft 1.37 IF (debugMode) CALL DEBUG_ENTER('THE_MAIN_LOOP',myThid)
120     #endif
121    
122 heimbach 1.6 #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 heimbach 1.56 CADJ INIT tapelev_ini_bibj_k = USER
127 heimbach 1.57 CADJ INIT tapelev_init = USER
128 heimbach 1.56 #ifdef AUTODIFF_2_LEVEL_CHECKPOINT
129     CADJ INIT tapelev2 = USER
130     #else
131 heimbach 1.6 CADJ INIT tapelev3 = USER
132 heimbach 1.7 #endif
133 heimbach 1.56
134     nIter0 = INT( startTime/deltaTClock )
135     ikey_dynamics = 1
136    
137 adcroft 1.10 CALL TIMER_START('ADJOINT SPIN-UP', mythid)
138 heimbach 1.6 #endif
139    
140 edhill 1.44 #ifdef ALLOW_DEBUG
141 adcroft 1.37 IF (debugMode) CALL DEBUG_CALL('INITIALISE_VARIA',myThid)
142     #endif
143    
144 adcroft 1.1 C-- Set initial conditions (variable arrays)
145 adcroft 1.10 CALL TIMER_START('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid)
146 heimbach 1.6 CALL INITIALISE_VARIA( mythid )
147 adcroft 1.10 CALL TIMER_STOP ('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid)
148 heimbach 1.6
149 edhill 1.43 #ifdef ALLOW_MONITOR
150 edhill 1.44 #ifdef ALLOW_DEBUG
151 adcroft 1.37 IF (debugMode) CALL DEBUG_CALL('MONITOR',myThid)
152     #endif
153 adcroft 1.9 C-- Check status of solution (statistics, cfl, etc...)
154 adcroft 1.10 CALL TIMER_START('MONITOR [THE_MAIN_LOOP]', mythid)
155 heimbach 1.49 CALL MONITOR( myIter, myTime, myThid )
156 adcroft 1.10 CALL TIMER_STOP ('MONITOR [THE_MAIN_LOOP]', mythid)
157 edhill 1.43 #endif /* ALLOW_MONITOR */
158 jmc 1.47
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 stephd 1.53
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 jmc 1.47 CALL TIMER_START('DO_THE_MODEL_IO [THE_MAIN_LOOP]', mythid)
170 heimbach 1.49 CALL DO_THE_MODEL_IO( myTime, myIter, mythid )
171 jmc 1.47 CALL TIMER_STOP ('DO_THE_MODEL_IO [THE_MAIN_LOOP]', mythid)
172 stephd 1.53 #endif
173    
174 heimbach 1.6
175 adcroft 1.10 #ifdef ALLOW_AUTODIFF_TAMC
176 heimbach 1.6 CALL TIMER_STOP ('ADJOINT SPIN-UP', mythid)
177     _BARRIER
178 adcroft 1.10 #endif
179 heimbach 1.6
180     c-- Do the model integration.
181 adcroft 1.10 CALL TIMER_START('MAIN LOOP [THE_MAIN_LOOP]', mythid)
182 heimbach 1.6
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 heimbach 1.26
192     c**************************************
193     #ifdef ALLOW_DIVIDED_ADJOINT
194     CADJ loop = divided
195     #endif
196     c**************************************
197 heimbach 1.6
198 heimbach 1.56 #ifndef AUTODIFF_2_LEVEL_CHECKPOINT
199    
200 heimbach 1.6 do ilev_3 = 1,nchklev_3
201     if(ilev_3.le.max_lev3) then
202 heimbach 1.24 c**************************************
203     #include "checkpoint_lev3_directives.h"
204     c**************************************
205 heimbach 1.6
206     c-- Initialise storage for the middle loop.
207     CADJ INIT tapelev2 = USER
208    
209 heimbach 1.56 #endif /* AUTODIFF_2_LEVEL_CHECKPOINT */
210    
211 heimbach 1.6 do ilev_2 = 1,nchklev_2
212     if(ilev_2.le.max_lev2) then
213 heimbach 1.24 c**************************************
214     #include "checkpoint_lev2_directives.h"
215     c**************************************
216 heimbach 1.6
217 heimbach 1.36 c**************************************
218     #ifdef ALLOW_AUTODIFF_TAMC
219 heimbach 1.6 c-- Initialize storage for the innermost loop.
220     c-- Always check common block sizes for the checkpointing!
221 heimbach 1.36 c--
222 heimbach 1.6 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 heimbach 1.28 c--
226     #ifdef ALLOW_KPP
227 heimbach 1.6 CADJ INIT comlev1_kpp = COMMON,nchklev_1*nsx*nsy
228 heimbach 1.51 CADJ INIT comlev1_kpp_k = COMMON,nchklev_1*nsx*nsy*nr
229 heimbach 1.28 #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 heimbach 1.45 c--
236 heimbach 1.38 #ifdef ALLOW_PTRACERS
237     CADJ INIT comlev1_bibj_ptracers = COMMON,
238 jmc 1.52 CADJ & nchklev_1*nsx*nsy*nthreads_chkpt*PTRACERS_num
239 heimbach 1.38 #endif /* ALLOW_PTRACERS */
240 heimbach 1.28 c--
241 adcroft 1.21 #ifndef DISABLE_MULTIDIM_ADVECTION
242 heimbach 1.28 CADJ INIT comlev1_bibj_k_gad
243 heimbach 1.20 CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass
244 heimbach 1.28 CADJ INIT comlev1_bibj_k_gad_pass
245     CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass*maxcube
246 adcroft 1.21 #endif /* DISABLE_MULTIDIM_ADVECTION */
247 heimbach 1.28 c--
248 heimbach 1.45 #if (defined (ALLOW_EXF) && defined (ALLOW_BULKFORMULAE))
249 dimitri 1.31 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 heimbach 1.45 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 heimbach 1.36 c--
261     #endif /* ALLOW_AUTODIFF_TAMC */
262     c**************************************
263 heimbach 1.6
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 heimbach 1.56 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 heimbach 1.6
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 adcroft 1.19 & 'nchklev_0 = ', nchklev_0
290 heimbach 1.6 print*, ' not consistent with nTimeSteps = ',
291     & nTimeSteps
292     stop ' ... stopped in the_main_loop.'
293     endif
294    
295 adcroft 1.10 DO iloop = 1, nTimeSteps
296 heimbach 1.6
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 adcroft 1.10 DO iloop = 1, nTimeSteps
304 heimbach 1.6
305     #endif /* ALLOW_AUTODIFF_TAMC */
306    
307 adcroft 1.10 c-- >>> Loop body start <<<
308 heimbach 1.6
309 heimbach 1.56 #ifdef ALLOW_AUTODIFF_TAMC
310 heimbach 1.14 nIter0 = INT( startTime/deltaTClock )
311 heimbach 1.13 ikey_dynamics = ilev_1
312 heimbach 1.6 #endif
313 dimitri 1.31
314 edhill 1.44 #ifdef ALLOW_DEBUG
315 adcroft 1.37 IF (debugMode) CALL DEBUG_CALL('FORWARD_STEP',myThid)
316     #endif
317 heimbach 1.14
318 heimbach 1.13 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 adcroft 1.8
322 heimbach 1.13 c-- >>> Loop body end <<<
323 heimbach 1.6
324     #ifdef ALLOW_AUTODIFF_TAMC
325     #ifdef ALLOW_TAMC_CHECKPOINTING
326     endif
327     enddo
328     endif
329     enddo
330 heimbach 1.56 #ifndef AUTODIFF_2_LEVEL_CHECKPOINT
331 heimbach 1.6 endif
332     enddo
333 heimbach 1.56 #endif
334 heimbach 1.6 #else
335     enddo
336     #endif
337    
338     #else
339     enddo
340     #endif
341    
342 heimbach 1.12 #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 heimbach 1.6 _BARRIER
350 adcroft 1.10 CALL TIMER_STOP ('MAIN LOOP [THE_MAIN_LOOP]', mythid)
351 adcroft 1.37
352 edhill 1.44 #ifdef ALLOW_DEBUG
353 adcroft 1.37 IF (debugMode) CALL DEBUG_LEAVE('THE_MAIN_LOOP',myThid)
354     #endif
355 adcroft 1.1
356 adcroft 1.10 END

  ViewVC Help
Powered by ViewVC 1.1.22