/[MITgcm]/MITgcm/verification/OpenAD/code_ad_openad/the_main_loop.F
ViewVC logotype

Contents of /MITgcm/verification/OpenAD/code_ad_openad/the_main_loop.F

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


Revision 1.2 - (show annotations) (download)
Wed Dec 29 21:10:51 2010 UTC (13 years, 4 months ago) by utke
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
FILE REMOVED
cleanup

1 C $Header: /u/gcmpack/MITgcm/verification/OpenAD/code_ad_openad/the_main_loop.F,v 1.1 2006/07/13 19:39:05 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 #ifdef ALLOW_SEAICE
10 # include "SEAICE_OPTIONS.h"
11 #endif
12 #ifdef ALLOW_GMREDI
13 # include "GMREDI_OPTIONS.h"
14 #endif
15
16 CBOP
17 C !ROUTINE: THE_MAIN_LOOP
18 C !INTERFACE:
19 SUBROUTINE THE_MAIN_LOOP( myTime, myIter, myThid )
20
21 C !DESCRIPTION: \bv
22 C *================================================================*
23 C | SUBROUTINE the_main_loop
24 C | o Run the ocean model and evaluate the specified cost function.
25 C *================================================================*
26 C |
27 C | THE_MAIN_LOOP is the toplevel routine for the Tangent Linear and
28 C | Adjoint Model Compiler (TAMC). For this purpose the initialization
29 C | of the model was split into two parts. Those parameters that do
30 C | not depend on a specific model run are set in INITIALISE_FIXED,
31 C | whereas those that do depend on the specific realization are
32 C | initialized in INITIALISE_VARIA.
33 C | This routine is to be used in conjuction with the MITgcmuv
34 C | checkpoint 37.
35 C *================================================================*
36 C \ev
37
38 C !USES:
39 IMPLICIT NONE
40 C == Global variables ==
41 #include "SIZE.h"
42 #include "EEPARAMS.h"
43 #include "PARAMS.h"
44
45 c**************************************
46 #ifdef ALLOW_AUTODIFF_TAMC
47
48 c These includes are needed for
49 c AD-checkpointing.
50 c They provide the fields to be stored.
51
52 # include "GRID.h"
53 # include "DYNVARS.h"
54 # include "FFIELDS.h"
55 # include "EOS.h"
56 # include "GAD.h"
57 # ifdef ALLOW_CD_CODE
58 # include "CD_CODE_VARS.h"
59 # endif
60 # ifdef ALLOW_PTRACERS
61 # include "PTRACERS_SIZE.h"
62 # include "PTRACERS.h"
63 # endif
64 # ifdef EXACT_CONSERV
65 # include "SURFACE.h"
66 # endif
67 # ifdef ALLOW_OBCS
68 # include "OBCS.h"
69 # endif
70 # ifdef ALLOW_EXF
71 # include "exf_fields.h"
72 # include "exf_clim_fields.h"
73 # ifdef ALLOW_BULKFORMULAE
74 # include "exf_constants.h"
75 # endif
76 # endif /* ALLOW_EXF */
77 # ifdef ALLOW_SEAICE
78 # include "SEAICE.h"
79 # endif
80 # ifdef ALLOW_EBM
81 # include "EBM.h"
82 # endif
83 # ifdef ALLOW_DIVIDED_ADJOINT_MPI
84 # include "mpif.h"
85 # endif
86
87 # include "tamc.h"
88 # include "ctrl.h"
89 # include "ctrl_dummy.h"
90 # include "cost.h"
91
92 #endif /* ALLOW_AUTODIFF_TAMC */
93 c**************************************
94
95 C !INPUT/OUTPUT PARAMETERS:
96 C == Routine arguments ==
97 C note: under the multi-threaded model myiter and
98 C mytime are local variables passed around as routine
99 C arguments. Although this is fiddly it saves the need to
100 C impose additional synchronisation points when they are
101 C updated.
102 C myIter - iteration counter for this thread
103 C myTime - time counter for this thread
104 C myThid - thread number for this instance of the routine.
105 INTEGER myThid
106 INTEGER myIter
107 _RL myTime
108
109 C !FUNCTIONS:
110 C == Functions ==
111 #ifdef ALLOW_RUNCLOCK
112 LOGICAL RUNCLOCK_CONTINUE
113 LOGICAL RC_CONT
114 #endif
115
116 C !LOCAL VARIABLES:
117 C == Local variables ==
118 integer leftOvers
119 integer uCheckLev1, uCheckLev2, uCheckLev3,uCheckLev4
120
121 integer ilev_1
122 CEOP
123
124 uCheckLev1=0
125 uCheckLev2=0
126 uCheckLev3=0
127 uCheckLev4=0
128
129 #ifdef ALLOW_DEBUG
130 IF (debugMode) CALL DEBUG_ENTER('THE_MAIN_LOOP',myThid)
131 #endif
132
133 nIter0 = NINT( (startTime-baseTime)/deltaTClock )
134 ikey_dynamics = 1
135
136 CALL TIMER_START('ADJOINT SPIN-UP', mythid)
137
138 #ifdef ALLOW_DEBUG
139 IF (debugMode) CALL DEBUG_CALL('INITIALISE_VARIA',myThid)
140 #endif
141
142 C-- Set initial conditions (variable arrays)
143 CALL TIMER_START('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid)
144 CALL INITIALISE_VARIA( mythid )
145 CALL TIMER_STOP ('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid)
146
147 #ifdef ALLOW_MONITOR
148 #ifdef ALLOW_DEBUG
149 IF (debugMode) CALL DEBUG_CALL('MONITOR',myThid)
150 #endif
151 C-- Check status of solution (statistics, cfl, etc...)
152 CALL TIMER_START('MONITOR [THE_MAIN_LOOP]', mythid)
153 CALL MONITOR( myIter, myTime, myThid )
154 CALL TIMER_STOP ('MONITOR [THE_MAIN_LOOP]', mythid)
155 #endif /* ALLOW_MONITOR */
156
157 C-- Do IO if needed (Dump for start state).
158 #ifdef ALLOW_DEBUG
159 IF (debugMode) CALL DEBUG_CALL('DO_THE_MODEL_IO',myThid)
160 #endif
161
162 #ifdef ALLOW_OFFLINE
163 CALL TIMER_START('OFFLINE_MODEL_IO [FORWARD_STEP]',myThid)
164 CALL OFFLINE_MODEL_IO( myTime, myIter, myThid )
165 CALL TIMER_STOP ('OFFLINE_MODEL_IO [FORWARD_STEP]',myThid)
166 #else
167 CALL TIMER_START('DO_THE_MODEL_IO [THE_MAIN_LOOP]', mythid)
168 CALL DO_THE_MODEL_IO( myTime, myIter, mythid )
169 CALL TIMER_STOP ('DO_THE_MODEL_IO [THE_MAIN_LOOP]', mythid)
170 #endif
171
172
173 #ifdef ALLOW_AUTODIFF_TAMC
174 CALL TIMER_STOP ('ADJOINT SPIN-UP', mythid)
175 _BARRIER
176 #endif
177
178 c-- Do the model integration.
179 CALL TIMER_START('MAIN LOOP [THE_MAIN_LOOP]', mythid)
180
181 c >>>>>>>>>>>>>>>>>>>>>>>>>>> LOOP <<<<<<<<<<<<<<<<<<<<<<<<<<<<
182 c >>>>>>>>>>>>>>>>>>>>>>>>>>> STARTS <<<<<<<<<<<<<<<<<<<<<<<<<<<<
183
184
185 c**************************************
186 c$openad INDEPENDENT(xx_theta_dummy)
187 c$openad DEPENDENT(xx_salt_dummy)
188
189 #ifndef ALLOW_TAMC_CHECKPOINTING
190 #error "not set up for undefined ALLOW_TAMC_CHECKPOINTING "
191 #endif
192
193 #ifndef ALLOW_AUTODIFF_TAMC
194 #error "not set up for undefined ALLOW_AUTODIFF_TAMC "
195 #endif
196
197 cju compute the actual checkpoint counts:
198 leftOvers = nTimeSteps
199 if (leftOvers .lt. nchklev_1 ) then
200 uCheckLev1=leftOvers
201 else
202 uCheckLev1 = nchklev_1
203 end if
204 leftOvers = leftOvers - uCheckLev1
205
206 if ((leftOvers/uCheckLev1) .lt. nchklev_2 ) then
207 uCheckLev2=(leftOvers/uCheckLev1)
208 else
209 uCheckLev2 = nchklev_2
210 end if
211 if (uCheckLev1*uCheckLev2 .gt. leftOvers) then
212 leftOvers=0
213 else
214 leftOvers = leftOvers - uCheckLev1*uCheckLev2
215 end if
216
217 if ((leftOvers/(uCheckLev1*uCkeckLev2)) .lt. nchklev_3 ) then
218 uCheckLev3=(leftOvers/(uCheckLev1*uCkeckLev2))
219 else
220 uCheckLev3 = nchklev_3
221 end if
222 if (uCheckLev1*uCheckLev2*uCheckLev3 .gt. leftOvers) then
223 leftOvers=0
224 else
225 leftOvers = leftOvers - uCheckLev1*uCheckLev2*uCheckLev3
226 end if
227
228 if ((leftOvers/(uCheckLev1*uCkeckLev2*uCkeckLev3))
229 &.lt. nchklev_4 ) then
230 uCheckLev4=
231 &(leftOvers/(uCheckLev1*uCkeckLev2*uCkeckLev3))
232 else
233 uCheckLev4 = nchklev_4
234 end if
235 leftOvers = leftOvers-uCheckLev1*uCheckLev2*uCheckLev3*uCheckLev4
236 if (leftOvers .gt. 0) then
237 print *, 'JU: error, not enough checkpoints allowed'
238 end if
239
240 print* ,'JU: main_loop: ',uCheckLev1, uCheckLev2,
241 +uCheckLev3, uCheckLev4
242
243 if (uCheckLev4 .gt. 0 ) then
244 do ilev_1 = 0, uCheckLev4-1
245
246 c-- >>> Loop body start <<<
247 cju not sure what the following two lines are good for:
248
249 nIter0 = NINT( (startTime-baseTime)/deltaTClock )
250 ikey_dynamics = ilev_1
251
252 #ifdef ALLOW_DEBUG
253 IF (debugMode) CALL DEBUG_CALL('THE_FIRST_LEVEL_LOOP',myThid)
254 #endif
255
256 CALL THE_FOURTH_LEVEL_LOOP( ilev_4,
257 +uCheckLev1, uCheckLev2, uCheckLev3,uCheckLev4,
258 +myTime, myIter, myThid )
259
260 #ifdef ALLOW_RUNCLOCK
261 IF (useRunClock) THEN
262 RC_CONT=RUNCLOCK_CONTINUE( myThid )
263 IF (.NOT.RC_CONT) RETURN
264 ENDIF
265 #endif /* ALLOW_RUNCLOCK */
266
267 c-- >>> Loop body end <<<
268
269 end do
270 else
271 c-- >>> Loop body start <<
272 cju not sure what the following two lines are good for:
273
274 nIter0 = NINT( (startTime-baseTime)/deltaTClock )
275 ikey_dynamics = ilev_1
276
277 #ifdef ALLOW_DEBUG
278 IF (debugMode) CALL DEBUG_CALL('THE_FIRST_LEVEL_PLAIN',myThid)
279 #endif
280
281 CALL THE_FOURTH_LEVEL_PLAIN(
282 +uCheckLev1, uCheckLev2, uCheckLev3,uCheckLev4,
283 +myTime, myIter, myThid )
284
285 #ifdef ALLOW_RUNCLOCK
286 IF (useRunClock) THEN
287 RC_CONT=RUNCLOCK_CONTINUE( myThid )
288 IF (.NOT.RC_CONT) RETURN
289 ENDIF
290 #endif /* ALLOW_RUNCLOCK */
291
292 c-- >>> Loop body end <<<
293
294 end if
295
296 #ifdef ALLOW_COST
297 c-- Sum all cost function contributions.
298 call TIMER_START('COST_FINAL [ADJOINT SPIN-DOWN]', mythid)
299 call COST_FINAL ( mythid )
300 call TIMER_STOP ('COST_FINAL [ADJOINT SPIN-DOWN]', mythid)
301 #endif
302
303 c$openad DEPENDENT(fc)
304
305 _BARRIER
306 CALL TIMER_STOP ('MAIN LOOP [THE_MAIN_LOOP]', mythid)
307
308 #ifdef ALLOW_DEBUG
309 IF (debugMode) CALL DEBUG_LEAVE('THE_MAIN_LOOP',myThid)
310 #endif
311
312 END
313

  ViewVC Help
Powered by ViewVC 1.1.22