/[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.14 - (show annotations) (download)
Mon Jul 30 20:39:18 2001 UTC (22 years, 10 months ago) by heimbach
Branch: MAIN
CVS Tags: checkpoint40pre4, checkpoint40pre5
Changes since 1.13: +4 -1 lines
Added a few re-initialisations for TAF.

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

  ViewVC Help
Powered by ViewVC 1.1.22