/[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.34 - (hide annotations) (download)
Tue Feb 18 05:33:54 2003 UTC (21 years, 3 months ago) by dimitri
Branch: MAIN
CVS Tags: checkpoint48i_post, checkpoint48f_post, checkpoint48h_post, checkpoint48g_post
Changes since 1.33: +1 -3 lines
Merging from release1_p12:
o Modifications for using pkg/exf with pkg/seaice
  - improved description of the various forcing configurations
  - added basic radiation bulk formulae to pkg/exf
  - units/sign fix for evap computation in exf_getffields.F
  - updated verification/global_with_exf/results/output.txt
o Added pkg/sbo for computing IERS Special Bureau for the Oceans
  (SBO) core products, including oceanic mass, center-of-mass,
  angular, and bottom pressure (see pkg/sbo/README.sbo).
o Lower bound for viscosity/diffusivity in pkg/kpp/kpp_routines.F
  to avoid negative values in shallow regions.
  - updated verification/natl_box/results/output.txt
  - updated verification/lab_sea/results/output.txt
o MPI gather, scatter: eesupp/src/gather_2d.F and scatter_2d.F
o Added useSingleCpuIO option (see PARAMS.h).
o Updated useSingleCpuIO option in mdsio_writefield.F to
  work with multi-field files, e.g., for single-file pickup.
o pkg/seaice:
  - bug fix in growth.F: QNET for no shortwave case
  - added HeffFile for specifying initial sea-ice thickness
  - changed SEAICE_EXTERNAL_FLUXES wind stress implementation
o Added missing /* */ to CPP comments in pkg/seaice, pkg/exf,
  kpp_transport_t.F, forward_step.F, and the_main_loop.F
o pkg/seaice:
  - adjoint-friendly modifications
  - added a SEAICE_WRITE_PICKUP at end of the_model_main.F

1 dimitri 1.34 C $Header: /u/gcmpack/MITgcm/model/src/the_main_loop.F,v 1.33 2003/02/06 22:42:11 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 heimbach 1.32 # include "GRID.h"
39 heimbach 1.16 # include "DYNVARS.h"
40     # include "FFIELDS.h"
41 heimbach 1.29 # include "EOS.h"
42 adcroft 1.21 # include "GAD.h"
43 heimbach 1.16 # ifdef ALLOW_PASSIVE_TRACER
44     # include "TR1.h"
45     # endif
46     # ifdef ALLOW_NONHYDROSTATIC
47     # include "CG3D.h"
48     # endif
49 heimbach 1.22 # ifdef EXACT_CONSERV
50     # include "SURFACE.h"
51     # endif
52 heimbach 1.6 #endif
53    
54 cnh 1.18 C !INPUT/OUTPUT PARAMETERS:
55     C == Routine arguments ==
56     C note: under the multi-threaded model myiter and
57     C mytime are local variables passed around as routine
58     C arguments. Although this is fiddly it saves the need to
59     C impose additional synchronisation points when they are
60     C updated.
61     C myIter - iteration counter for this thread
62     C myTime - time counter for this thread
63     C myThid - thread number for this instance of the routine.
64     INTEGER myThid
65     INTEGER myIter
66     _RL myTime
67 heimbach 1.6
68 cnh 1.18 C !LOCAL VARIABLES:
69     C == Local variables ==
70 heimbach 1.6 integer iloop
71     #ifdef ALLOW_TAMC_CHECKPOINTING
72     integer ilev_1
73     integer ilev_2
74     integer ilev_3
75     integer max_lev2
76     integer max_lev3
77     #endif
78 cnh 1.18 CEOP
79 adcroft 1.1
80 heimbach 1.6 #ifdef ALLOW_AUTODIFF_TAMC
81     c-- Initialize storage for the cost function evaluation.
82     CADJ INIT dummytape = common, 1
83     c-- Initialize storage for the outermost loop.
84     CADJ INIT tapelev3 = USER
85 heimbach 1.27 CADJ INIT tapelev_ini_bibj_k = USER
86 heimbach 1.7 #ifdef ALLOW_TAMC_CHECKPOINTING
87 heimbach 1.13 nIter0 = INT( startTime/deltaTClock )
88 heimbach 1.7 ikey_dynamics = 1
89     #endif
90 adcroft 1.10 CALL TIMER_START('ADJOINT SPIN-UP', mythid)
91 heimbach 1.6 #endif
92    
93 adcroft 1.1 C-- Set initial conditions (variable arrays)
94 adcroft 1.10 CALL TIMER_START('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid)
95 heimbach 1.6 CALL INITIALISE_VARIA( mythid )
96 adcroft 1.10 CALL TIMER_STOP ('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid)
97 heimbach 1.6
98     #ifndef ALLOW_AUTODIFF_TAMC
99     c-- Dump for start state.
100 adcroft 1.10 CALL TIMER_START('WRITE_STATE [THE_MAIN_LOOP]', mythid)
101 heimbach 1.6 CALL WRITE_STATE( mytime, myiter, mythid )
102 adcroft 1.10 CALL TIMER_STOP ('WRITE_STATE [THE_MAIN_LOOP]', mythid)
103 heimbach 1.6 #endif
104 adcroft 1.9
105     #ifndef EXCLUDE_MONITOR
106     C-- Check status of solution (statistics, cfl, etc...)
107 adcroft 1.10 CALL TIMER_START('MONITOR [THE_MAIN_LOOP]', mythid)
108 adcroft 1.9 CALL MONITOR( myIter, myTime, myThid )
109 adcroft 1.10 CALL TIMER_STOP ('MONITOR [THE_MAIN_LOOP]', mythid)
110 adcroft 1.9 #endif /* EXCLUDE_MONITOR */
111 heimbach 1.6
112 adcroft 1.10 #ifdef ALLOW_AUTODIFF_TAMC
113 heimbach 1.6 CALL TIMER_STOP ('ADJOINT SPIN-UP', mythid)
114     _BARRIER
115 adcroft 1.10 #endif
116 heimbach 1.6
117     c-- Do the model integration.
118 adcroft 1.10 CALL TIMER_START('MAIN LOOP [THE_MAIN_LOOP]', mythid)
119 heimbach 1.6
120     c >>>>>>>>>>>>>>>>>>>>>>>>>>> LOOP <<<<<<<<<<<<<<<<<<<<<<<<<<<<
121     c >>>>>>>>>>>>>>>>>>>>>>>>>>> STARTS <<<<<<<<<<<<<<<<<<<<<<<<<<<<
122    
123     #ifdef ALLOW_AUTODIFF_TAMC
124     #ifdef ALLOW_TAMC_CHECKPOINTING
125     c-- Implement a three level checkpointing. For a two level
126     c-- checkpointing delete the middle loop; for n levels (n > 3)
127     c-- insert more loops.
128    
129     c-- Check the choice of the checkpointing parameters in relation
130     c-- to nTimeSteps: (nchklev_1*nchklev_2*nchklev_3 .ge. nTimeSteps)
131     if (nchklev_1*nchklev_2*nchklev_3 .lt. nTimeSteps) then
132     print*
133     print*, ' the_main_loop: TAMC checkpointing parameters'
134     print*, ' nchklev_1*nchklev_2*nchklev_3 = ',
135     & nchklev_1*nchklev_2*nchklev_3
136     print*, ' are not consistent with nTimeSteps = ',
137     & nTimeSteps
138     stop ' ... stopped in the_main_loop.'
139     endif
140     max_lev3=nTimeSteps/(nchklev_1*nchklev_2)+1
141     max_lev2=nTimeSteps/nchklev_1+1
142 heimbach 1.26
143     c**************************************
144     #ifdef ALLOW_DIVIDED_ADJOINT
145     CADJ loop = divided
146     #endif
147     c**************************************
148 heimbach 1.6
149     do ilev_3 = 1,nchklev_3
150     if(ilev_3.le.max_lev3) then
151 heimbach 1.24 c**************************************
152     #include "checkpoint_lev3_directives.h"
153     c**************************************
154 heimbach 1.6
155     c-- Initialise storage for the middle loop.
156     CADJ INIT tapelev2 = USER
157    
158     do ilev_2 = 1,nchklev_2
159     if(ilev_2.le.max_lev2) then
160 heimbach 1.24 c**************************************
161     #include "checkpoint_lev2_directives.h"
162     c**************************************
163 heimbach 1.6
164     c-- Initialize storage for the innermost loop.
165     c-- Always check common block sizes for the checkpointing!
166     CADJ INIT comlev1 = COMMON,nchklev_1
167     CADJ INIT comlev1_bibj = COMMON,nchklev_1*nsx*nsy*nthreads_chkpt
168     CADJ INIT comlev1_bibj_k = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt
169 heimbach 1.28 c--
170     #ifdef ALLOW_KPP
171 heimbach 1.6 CADJ INIT comlev1_kpp = COMMON,nchklev_1*nsx*nsy
172 heimbach 1.28 #endif /* ALLOW_KPP */
173     c--
174     #ifdef ALLOW_GMREDI
175     CADJ INIT comlev1_gmredi_k_gad
176     CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass
177     #endif /* ALLOW_GMREDI */
178     c--
179 adcroft 1.21 #ifndef DISABLE_MULTIDIM_ADVECTION
180 heimbach 1.28 CADJ INIT comlev1_bibj_k_gad
181 heimbach 1.20 CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass
182 heimbach 1.28 CADJ INIT comlev1_bibj_k_gad_pass
183     CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass*maxcube
184 adcroft 1.21 #endif /* DISABLE_MULTIDIM_ADVECTION */
185 heimbach 1.28 c--
186 cheisey 1.30 #ifdef ALLOW_BULK_FORCE
187 heimbach 1.20 CADJ INIT comlev1_exf_1
188     CADJ & = COMMON,nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt
189     CADJ INIT comlev1_exf_2
190     CADJ & = COMMON,niter_bulk*nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt
191 cheisey 1.30 #endif /* ALLOW_BULK_FORCE */
192 dimitri 1.31 #ifdef ALLOW_BULKFORMULAE
193     CADJ INIT comlev1_exf_1
194     CADJ & = COMMON,nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt
195     CADJ INIT comlev1_exf_2
196     CADJ & = COMMON,niter_bulk*nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt
197     #endif /* ALLOW_BULKFORMULAE */
198 heimbach 1.6
199     do ilev_1 = 1,nchklev_1
200    
201     c-- The if-statement below introduces a some flexibility in the
202     c-- choice of the 3-tupel ( nchklev_1, nchklev_2, nchklev_3 ).
203     c--
204     c-- Requirement: nchklev_1*nchklev_2*nchklev_3 .ge. nTimeSteps .
205    
206     iloop = (ilev_3 - 1)*nchklev_2*nchklev_1 +
207     & (ilev_2 - 1)*nchklev_1 + ilev_1
208    
209     if ( iloop .le. nTimeSteps ) then
210    
211     #else /* ALLOW_TAMC_CHECKPOINTING undefined */
212     c-- Initialise storage for reference trajectory without TAMC check-
213     c-- pointing.
214     CADJ INIT history = USER
215     CADJ INIT comlev1_bibj = COMMON,nchklev_0*nsx*nsy*nthreads_chkpt
216     CADJ INIT comlev1_bibj_k = COMMON,nchklev_0*nsx*nsy*nr*nthreads_chkpt
217     CADJ INIT comlev1_kpp = COMMON,nchklev_0*nsx*nsy
218    
219     C-- RG replace 2 by max of num_v_smooth_Ri
220     CADJ INIT comlev1_kpp_sm = COMMON,nchklev_0*nsx*nsy*2
221    
222     c-- Check the choice of the checkpointing parameters in relation
223     c-- to nTimeSteps: (nchklev_0 .ge. nTimeSteps)
224     if (nchklev_0 .lt. nTimeSteps) then
225     print*
226     print*, ' the_main_loop: TAMC checkpointing parameter ',
227 adcroft 1.19 & 'nchklev_0 = ', nchklev_0
228 heimbach 1.6 print*, ' not consistent with nTimeSteps = ',
229     & nTimeSteps
230     stop ' ... stopped in the_main_loop.'
231     endif
232    
233 adcroft 1.10 DO iloop = 1, nTimeSteps
234 heimbach 1.6
235     #endif /* ALLOW_TAMC_CHECKPOINTING */
236    
237     #else /* ALLOW_AUTODIFF_TAMC undefined */
238    
239     c-- Start the main loop of adjoint_Objfunc. Automatic differentiation
240     c-- NOT enabled.
241 adcroft 1.10 DO iloop = 1, nTimeSteps
242 heimbach 1.6
243     #endif /* ALLOW_AUTODIFF_TAMC */
244    
245 adcroft 1.10 c-- >>> Loop body start <<<
246 heimbach 1.6
247     #ifdef ALLOW_TAMC_CHECKPOINTING
248 heimbach 1.14 nIter0 = INT( startTime/deltaTClock )
249 heimbach 1.13 ikey_dynamics = ilev_1
250 heimbach 1.6 #endif
251 dimitri 1.31
252 heimbach 1.14
253 heimbach 1.13 CALL TIMER_START('FORWARD_STEP [THE_MAIN_LOOP]',mythid)
254     CALL FORWARD_STEP( iloop, mytime, myiter, mythid )
255     CALL TIMER_STOP ('FORWARD_STEP [THE_MAIN_LOOP]',mythid)
256 adcroft 1.8
257 heimbach 1.12 #ifdef ALLOW_COST
258 heimbach 1.13 C-- compare model with data and compute cost function
259     C-- this is done after exchanges to allow interpolation
260     CALL TIMER_START('COST_TILE [THE_MAIN_LOOP]',myThid)
261     CALL COST_TILE ( myThid )
262     CALL TIMER_STOP ('COST_TILE [THE_MAIN_LOOP]',myThid)
263 heimbach 1.12 #endif
264    
265 heimbach 1.13 c-- >>> Loop body end <<<
266 heimbach 1.6
267     #ifdef ALLOW_AUTODIFF_TAMC
268     #ifdef ALLOW_TAMC_CHECKPOINTING
269     endif
270     enddo
271     endif
272     enddo
273     endif
274     enddo
275     #else
276     enddo
277     #endif
278    
279     #else
280     enddo
281     #endif
282    
283 heimbach 1.12 #ifdef ALLOW_COST
284     c-- Sum all cost function contributions.
285     call TIMER_START('COST_FINAL [ADJOINT SPIN-DOWN]', mythid)
286     call COST_FINAL ( mythid )
287     call TIMER_STOP ('COST_FINAL [ADJOINT SPIN-DOWN]', mythid)
288     #endif
289    
290 heimbach 1.6 _BARRIER
291 adcroft 1.10 CALL TIMER_STOP ('MAIN LOOP [THE_MAIN_LOOP]', mythid)
292 adcroft 1.1
293 adcroft 1.10 END

  ViewVC Help
Powered by ViewVC 1.1.22