/[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.25 - (hide annotations) (download)
Thu Jan 17 16:58:53 2002 UTC (22 years, 4 months ago) by heimbach
Branch: MAIN
CVS Tags: chkpt44a_post, chkpt44a_pre, checkpoint44b_pre, checkpoint44
Changes since 1.24: +2 -2 lines
* Updated adjoint/makefile
  o removed "_ecco" from names
  o added/modified forward mode options
  o added dependent vector option
  o tried SVD matrix computation (doesn't work;
    too much memory use by TAF)
* Updated flow directives related to FTL
* removed global_sum__g.F (not necessary)
* initialise forward mode anomalies in ctrl_unpack.F
  (so far "crude" initialization only).
* Added flag ALLOW_TANGENTLINEAR_RUN complememting
  ALLOW_ADJOINT_RUN
* driver routine the_model_main.F needs separate call
  to FTL routine G_THE_MAIN_LOOP with parameter list
  identical to THE_MAIN_LOOP (TAF doesn't remove arguments).
* added template file tangentlinear_model.F
  for forward mode.

1 heimbach 1.25 C $Header: /u/gcmpack/MITgcm/model/src/the_main_loop.F,v 1.24 2002/01/11 19:00:43 heimbach Exp $
2 adcroft 1.1
3     #include "CPP_OPTIONS.h"
4    
5 cnh 1.18 CBOP
6     C !ROUTINE: THE_MAIN_LOOP
7     C !INTERFACE:
8     SUBROUTINE THE_MAIN_LOOP( mytime, myiter, mythid )
9    
10     C !DESCRIPTION: \bv
11     C *================================================================*
12     C | SUBROUTINE the_main_loop
13     C | o Run the ocean model and evaluate the specified cost function.
14     C *================================================================*
15     C |
16     C | THE_MAIN_LOOP is the toplevel routine for the Tangent Linear and
17     C | Adjoint Model Compiler (TAMC). For this purpose the initialization
18     C | of the model was split into two parts. Those parameters that do
19     C | not depend on a specific model run are set in INITIALISE_FIXED,
20     C | whereas those that do depend on the specific realization are
21     C | initialized in INITIALISE_VARIA.
22     C | This routine is to be used in conjuction with the MITgcmuv
23     C | checkpoint 37.
24     C *================================================================*
25     C \ev
26    
27     C !USES:
28     IMPLICIT NONE
29     C == Global variables ==
30 adcroft 1.1 #include "SIZE.h"
31     #include "EEPARAMS.h"
32     #include "PARAMS.h"
33 heimbach 1.6 #ifdef ALLOW_AUTODIFF_TAMC
34 heimbach 1.16 # include "tamc.h"
35     # include "ctrl.h"
36     # include "ctrl_dummy.h"
37     # include "cost.h"
38     # include "DYNVARS.h"
39     # include "FFIELDS.h"
40 adcroft 1.21 # include "GAD.h"
41 heimbach 1.16 # ifdef ALLOW_PASSIVE_TRACER
42     # include "TR1.h"
43     # endif
44     # ifdef ALLOW_NONHYDROSTATIC
45     # include "CG3D.h"
46     # endif
47 heimbach 1.22 # ifdef EXACT_CONSERV
48     # include "SURFACE.h"
49     # endif
50 heimbach 1.6 #endif
51    
52 cnh 1.18 C !INPUT/OUTPUT PARAMETERS:
53     C == Routine arguments ==
54     C note: under the multi-threaded model myiter and
55     C mytime are local variables passed around as routine
56     C arguments. Although this is fiddly it saves the need to
57     C impose additional synchronisation points when they are
58     C updated.
59     C myIter - iteration counter for this thread
60     C myTime - time counter for this thread
61     C myThid - thread number for this instance of the routine.
62     INTEGER myThid
63     INTEGER myIter
64     _RL myTime
65 heimbach 1.6
66 cnh 1.18 C !LOCAL VARIABLES:
67     C == Local variables ==
68 heimbach 1.6 integer iloop
69     #ifdef ALLOW_TAMC_CHECKPOINTING
70     integer ilev_1
71     integer ilev_2
72     integer ilev_3
73     integer max_lev2
74     integer max_lev3
75     #endif
76 cnh 1.18 CEOP
77 adcroft 1.1
78 heimbach 1.6 #ifdef ALLOW_AUTODIFF_TAMC
79     c-- Initialize storage for the cost function evaluation.
80     CADJ INIT dummytape = common, 1
81     c-- Initialize storage for the outermost loop.
82     CADJ INIT tapelev3 = USER
83 heimbach 1.7 #ifdef ALLOW_TAMC_CHECKPOINTING
84 heimbach 1.13 nIter0 = INT( startTime/deltaTClock )
85 heimbach 1.7 ikey_dynamics = 1
86     #endif
87 adcroft 1.10 CALL TIMER_START('ADJOINT SPIN-UP', mythid)
88 heimbach 1.6 #endif
89    
90 adcroft 1.1 C-- Set initial conditions (variable arrays)
91 adcroft 1.10 CALL TIMER_START('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid)
92 heimbach 1.6 CALL INITIALISE_VARIA( mythid )
93 adcroft 1.10 CALL TIMER_STOP ('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid)
94 heimbach 1.6
95     #ifndef ALLOW_AUTODIFF_TAMC
96     c-- Dump for start state.
97 adcroft 1.10 CALL TIMER_START('WRITE_STATE [THE_MAIN_LOOP]', mythid)
98 heimbach 1.6 CALL WRITE_STATE( mytime, myiter, mythid )
99 adcroft 1.10 CALL TIMER_STOP ('WRITE_STATE [THE_MAIN_LOOP]', mythid)
100 heimbach 1.6 #endif
101 adcroft 1.9
102     #ifndef EXCLUDE_MONITOR
103     C-- Check status of solution (statistics, cfl, etc...)
104 adcroft 1.10 CALL TIMER_START('MONITOR [THE_MAIN_LOOP]', mythid)
105 adcroft 1.9 CALL MONITOR( myIter, myTime, myThid )
106 adcroft 1.10 CALL TIMER_STOP ('MONITOR [THE_MAIN_LOOP]', mythid)
107 adcroft 1.9 #endif /* EXCLUDE_MONITOR */
108 heimbach 1.6
109 heimbach 1.25 #if (defined (ALLOW_ADJOINT_RUN) || defined (ALLOW_TANGENTLINEAR_RUN))
110 heimbach 1.6 c-- Add control vector for forcing and parameter fields
111     CALL CTRL_MAP_FORCING (mythid)
112     #endif
113    
114 adcroft 1.10 #ifdef ALLOW_AUTODIFF_TAMC
115 heimbach 1.6 CALL TIMER_STOP ('ADJOINT SPIN-UP', mythid)
116     _BARRIER
117 adcroft 1.10 #endif
118 heimbach 1.6
119     c-- Do the model integration.
120 adcroft 1.10 CALL TIMER_START('MAIN LOOP [THE_MAIN_LOOP]', mythid)
121 heimbach 1.6
122     c >>>>>>>>>>>>>>>>>>>>>>>>>>> LOOP <<<<<<<<<<<<<<<<<<<<<<<<<<<<
123     c >>>>>>>>>>>>>>>>>>>>>>>>>>> STARTS <<<<<<<<<<<<<<<<<<<<<<<<<<<<
124    
125     #ifdef ALLOW_AUTODIFF_TAMC
126     #ifdef ALLOW_TAMC_CHECKPOINTING
127     c-- Implement a three level checkpointing. For a two level
128     c-- checkpointing delete the middle loop; for n levels (n > 3)
129     c-- insert more loops.
130    
131     c-- Check the choice of the checkpointing parameters in relation
132     c-- to nTimeSteps: (nchklev_1*nchklev_2*nchklev_3 .ge. nTimeSteps)
133     if (nchklev_1*nchklev_2*nchklev_3 .lt. nTimeSteps) then
134     print*
135     print*, ' the_main_loop: TAMC checkpointing parameters'
136     print*, ' nchklev_1*nchklev_2*nchklev_3 = ',
137     & nchklev_1*nchklev_2*nchklev_3
138     print*, ' are not consistent with nTimeSteps = ',
139     & nTimeSteps
140     stop ' ... stopped in the_main_loop.'
141     endif
142     max_lev3=nTimeSteps/(nchklev_1*nchklev_2)+1
143     max_lev2=nTimeSteps/nchklev_1+1
144    
145     do ilev_3 = 1,nchklev_3
146     if(ilev_3.le.max_lev3) then
147 heimbach 1.24 c**************************************
148     #include "checkpoint_lev3_directives.h"
149     c**************************************
150 heimbach 1.6
151     c-- Initialise storage for the middle loop.
152     CADJ INIT tapelev2 = USER
153    
154     do ilev_2 = 1,nchklev_2
155     if(ilev_2.le.max_lev2) then
156 heimbach 1.24 c**************************************
157     #include "checkpoint_lev2_directives.h"
158     c**************************************
159 heimbach 1.6
160     c-- Initialize storage for the innermost loop.
161     c-- Always check common block sizes for the checkpointing!
162     CADJ INIT comlev1 = COMMON,nchklev_1
163     CADJ INIT comlev1_bibj = COMMON,nchklev_1*nsx*nsy*nthreads_chkpt
164     CADJ INIT comlev1_bibj_k = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt
165     CADJ INIT comlev1_kpp = COMMON,nchklev_1*nsx*nsy
166 adcroft 1.21 #ifndef DISABLE_MULTIDIM_ADVECTION
167 heimbach 1.20 CADJ INIT comlev1_bibj_pass
168     CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass
169 adcroft 1.21 #endif /* DISABLE_MULTIDIM_ADVECTION */
170 heimbach 1.20 #ifdef ALLOW_BULKFORMULAE
171     CADJ INIT comlev1_exf_1
172     CADJ & = COMMON,nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt
173     CADJ INIT comlev1_exf_2
174     CADJ & = COMMON,niter_bulk*nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt
175     #endif
176 heimbach 1.6
177     do ilev_1 = 1,nchklev_1
178    
179     c-- The if-statement below introduces a some flexibility in the
180     c-- choice of the 3-tupel ( nchklev_1, nchklev_2, nchklev_3 ).
181     c--
182     c-- Requirement: nchklev_1*nchklev_2*nchklev_3 .ge. nTimeSteps .
183    
184     iloop = (ilev_3 - 1)*nchklev_2*nchklev_1 +
185     & (ilev_2 - 1)*nchklev_1 + ilev_1
186    
187     if ( iloop .le. nTimeSteps ) then
188    
189     #else /* ALLOW_TAMC_CHECKPOINTING undefined */
190     c-- Initialise storage for reference trajectory without TAMC check-
191     c-- pointing.
192     CADJ INIT history = USER
193     CADJ INIT comlev1_bibj = COMMON,nchklev_0*nsx*nsy*nthreads_chkpt
194     CADJ INIT comlev1_bibj_k = COMMON,nchklev_0*nsx*nsy*nr*nthreads_chkpt
195     CADJ INIT comlev1_kpp = COMMON,nchklev_0*nsx*nsy
196    
197     C-- RG replace 2 by max of num_v_smooth_Ri
198     CADJ INIT comlev1_kpp_sm = COMMON,nchklev_0*nsx*nsy*2
199    
200     c-- Check the choice of the checkpointing parameters in relation
201     c-- to nTimeSteps: (nchklev_0 .ge. nTimeSteps)
202     if (nchklev_0 .lt. nTimeSteps) then
203     print*
204     print*, ' the_main_loop: TAMC checkpointing parameter ',
205 adcroft 1.19 & 'nchklev_0 = ', nchklev_0
206 heimbach 1.6 print*, ' not consistent with nTimeSteps = ',
207     & nTimeSteps
208     stop ' ... stopped in the_main_loop.'
209     endif
210    
211 adcroft 1.10 DO iloop = 1, nTimeSteps
212 heimbach 1.6
213     #endif /* ALLOW_TAMC_CHECKPOINTING */
214    
215     #else /* ALLOW_AUTODIFF_TAMC undefined */
216    
217     c-- Start the main loop of adjoint_Objfunc. Automatic differentiation
218     c-- NOT enabled.
219 adcroft 1.10 DO iloop = 1, nTimeSteps
220 heimbach 1.6
221     #endif /* ALLOW_AUTODIFF_TAMC */
222    
223 adcroft 1.10 c-- >>> Loop body start <<<
224 heimbach 1.6
225     #ifdef ALLOW_TAMC_CHECKPOINTING
226 heimbach 1.14 nIter0 = INT( startTime/deltaTClock )
227 heimbach 1.13 ikey_dynamics = ilev_1
228 heimbach 1.6 #endif
229 heimbach 1.14
230    
231 heimbach 1.13 CALL TIMER_START('FORWARD_STEP [THE_MAIN_LOOP]',mythid)
232     CALL FORWARD_STEP( iloop, mytime, myiter, mythid )
233     CALL TIMER_STOP ('FORWARD_STEP [THE_MAIN_LOOP]',mythid)
234 adcroft 1.8
235 heimbach 1.12 #ifdef ALLOW_COST
236 heimbach 1.13 C-- compare model with data and compute cost function
237     C-- this is done after exchanges to allow interpolation
238     CALL TIMER_START('COST_TILE [THE_MAIN_LOOP]',myThid)
239     CALL COST_TILE ( myThid )
240     CALL TIMER_STOP ('COST_TILE [THE_MAIN_LOOP]',myThid)
241 heimbach 1.12 #endif
242    
243 heimbach 1.13 c-- >>> Loop body end <<<
244 heimbach 1.6
245     #ifdef ALLOW_AUTODIFF_TAMC
246     #ifdef ALLOW_TAMC_CHECKPOINTING
247     endif
248     enddo
249     endif
250     enddo
251     endif
252     enddo
253     #else
254     enddo
255     #endif
256    
257     #else
258     enddo
259     #endif
260    
261 heimbach 1.12 #ifdef ALLOW_COST
262     c-- Sum all cost function contributions.
263     call TIMER_START('COST_FINAL [ADJOINT SPIN-DOWN]', mythid)
264     call COST_FINAL ( mythid )
265     call TIMER_STOP ('COST_FINAL [ADJOINT SPIN-DOWN]', mythid)
266     #endif
267    
268 heimbach 1.6 _BARRIER
269 adcroft 1.10 CALL TIMER_STOP ('MAIN LOOP [THE_MAIN_LOOP]', mythid)
270 adcroft 1.1
271 adcroft 1.10 END

  ViewVC Help
Powered by ViewVC 1.1.22