| 1 |
jscott |
1.1 |
C $Header: /u/gcmpack/MITgcm/model/src/the_main_loop.F,v 1.76 2006/06/13 21:17:22 jmc 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 |
|
|
# include "MOM_FLUXFORM.h" |
| 58 |
|
|
# ifdef ALLOW_CD_CODE |
| 59 |
|
|
# include "CD_CODE_VARS.h" |
| 60 |
|
|
# endif |
| 61 |
|
|
# ifdef ALLOW_PTRACERS |
| 62 |
|
|
# include "PTRACERS_SIZE.h" |
| 63 |
|
|
# include "PTRACERS.h" |
| 64 |
|
|
# endif |
| 65 |
|
|
# if (defined (EXACT_CONSERV) || defined (NONLIN_FRSURF)) |
| 66 |
|
|
# include "SURFACE.h" |
| 67 |
|
|
# endif |
| 68 |
|
|
# ifdef ALLOW_OBCS |
| 69 |
|
|
# include "OBCS.h" |
| 70 |
|
|
# ifdef ALLOW_PTRACERS |
| 71 |
|
|
# include "OBCS_PTRACERS.h" |
| 72 |
|
|
# endif |
| 73 |
|
|
# endif |
| 74 |
|
|
# ifdef ALLOW_EXF |
| 75 |
|
|
# include "exf_fields.h" |
| 76 |
|
|
# include "exf_clim_fields.h" |
| 77 |
|
|
# ifdef ALLOW_BULKFORMULAE |
| 78 |
|
|
# include "exf_constants.h" |
| 79 |
|
|
# endif |
| 80 |
|
|
# endif /* ALLOW_EXF */ |
| 81 |
|
|
# ifdef ALLOW_SEAICE |
| 82 |
|
|
# include "SEAICE.h" |
| 83 |
|
|
# endif |
| 84 |
|
|
# ifdef ALLOW_THSICE |
| 85 |
|
|
# include "THSICE_VARS.h" |
| 86 |
|
|
# endif |
| 87 |
|
|
# ifdef ALLOW_EBM |
| 88 |
|
|
# include "EBM.h" |
| 89 |
|
|
# endif |
| 90 |
|
|
# ifdef ALLOW_DIVIDED_ADJOINT_MPI |
| 91 |
|
|
# include "mpif.h" |
| 92 |
|
|
# endif |
| 93 |
|
|
|
| 94 |
|
|
# include "tamc.h" |
| 95 |
|
|
# include "ctrl.h" |
| 96 |
|
|
# include "ctrl_dummy.h" |
| 97 |
|
|
# include "cost.h" |
| 98 |
|
|
|
| 99 |
|
|
#endif /* ALLOW_AUTODIFF_TAMC */ |
| 100 |
|
|
c************************************** |
| 101 |
|
|
|
| 102 |
|
|
C !INPUT/OUTPUT PARAMETERS: |
| 103 |
|
|
C == Routine arguments == |
| 104 |
|
|
C note: under the multi-threaded model myiter and |
| 105 |
|
|
C mytime are local variables passed around as routine |
| 106 |
|
|
C arguments. Although this is fiddly it saves the need to |
| 107 |
|
|
C impose additional synchronisation points when they are |
| 108 |
|
|
C updated. |
| 109 |
|
|
C myIter - iteration counter for this thread |
| 110 |
|
|
C myTime - time counter for this thread |
| 111 |
|
|
C myThid - thread number for this instance of the routine. |
| 112 |
|
|
INTEGER myThid |
| 113 |
|
|
INTEGER myIter |
| 114 |
|
|
_RL myTime |
| 115 |
|
|
|
| 116 |
|
|
C !FUNCTIONS: |
| 117 |
|
|
C == Functions == |
| 118 |
|
|
#ifdef ALLOW_RUNCLOCK |
| 119 |
|
|
LOGICAL RUNCLOCK_CONTINUE |
| 120 |
|
|
LOGICAL RC_CONT |
| 121 |
|
|
#endif |
| 122 |
|
|
|
| 123 |
|
|
C !LOCAL VARIABLES: |
| 124 |
|
|
C == Local variables == |
| 125 |
|
|
integer iloop |
| 126 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
| 127 |
|
|
integer ilev_1 |
| 128 |
|
|
integer ilev_2 |
| 129 |
|
|
integer ilev_3 |
| 130 |
|
|
integer ilev_4 |
| 131 |
|
|
integer max_lev2 |
| 132 |
|
|
integer max_lev3 |
| 133 |
|
|
integer max_lev4 |
| 134 |
|
|
#endif |
| 135 |
|
|
CEOP |
| 136 |
|
|
#if defined(TIME_PER_TIMESTEP) || defined(USE_PAPI_FLOPS) || defined(USE_PCL_FLOPS) |
| 137 |
|
|
CHARACTER*(MAX_LEN_MBUF) msgBuf |
| 138 |
|
|
#ifdef TIME_PER_TIMESTEP |
| 139 |
|
|
CCE107 common block for per timestep timing |
| 140 |
|
|
C !TIMING VARIABLES |
| 141 |
|
|
C == Timing variables == |
| 142 |
|
|
REAL*8 utnew, utold, stnew, stold, wtnew, wtold |
| 143 |
|
|
DATA utnew, utold, stnew, stold, wtnew, wtold /6*0.0D0/ |
| 144 |
|
|
#endif |
| 145 |
|
|
#ifdef USE_PAPI_FLOPS |
| 146 |
|
|
CCE107 common block for PAPI summary performance |
| 147 |
|
|
#include <fpapi.h> |
| 148 |
|
|
INTEGER*8 flpops, instr |
| 149 |
|
|
DATA flpops, instr /2*0/ |
| 150 |
|
|
INTEGER check |
| 151 |
|
|
REAL*4 real_time, proc_time, mflops, ipc |
| 152 |
|
|
DATA real_time, proc_time, mflops, ipc /4*0.0E0/ |
| 153 |
|
|
#else |
| 154 |
|
|
#ifdef USE_PCL_FLOPS |
| 155 |
|
|
CCE107 common block for PCL summary performance |
| 156 |
|
|
#include <pclh.f> |
| 157 |
|
|
INTEGER pcl_counter_list(5), flags, nevents, res, ipcl |
| 158 |
|
|
INTEGER*8 i_result(5), descr |
| 159 |
|
|
REAL*8 fp_result(5) |
| 160 |
|
|
COMMON /pclvars/ i_result, descr, fp_result, pcl_counter_list, |
| 161 |
|
|
$ flags, nevents |
| 162 |
|
|
INTEGER nmaxevents |
| 163 |
|
|
PARAMETER (nmaxevents = 61) |
| 164 |
|
|
CHARACTER*22 pcl_counter_name(0:nmaxevents-1) |
| 165 |
|
|
COMMON /pclnames/ pcl_counter_name |
| 166 |
|
|
#endif |
| 167 |
|
|
#endif |
| 168 |
|
|
#endif |
| 169 |
|
|
|
| 170 |
|
|
#ifdef ALLOW_DEBUG |
| 171 |
|
|
IF (debugMode) CALL DEBUG_ENTER('THE_MAIN_LOOP',myThid) |
| 172 |
|
|
#endif |
| 173 |
|
|
|
| 174 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
| 175 |
|
|
c-- Initialize storage for the cost function evaluation. |
| 176 |
|
|
CADJ INIT dummytape = common, 1 |
| 177 |
|
|
c-- Initialize storage for the outermost loop. |
| 178 |
|
|
CADJ INIT tapelev_ini_bibj_k = USER |
| 179 |
|
|
CADJ INIT tapelev_init = USER |
| 180 |
|
|
c |
| 181 |
|
|
#if (defined (AUTODIFF_2_LEVEL_CHECKPOINT)) |
| 182 |
|
|
CADJ INIT tapelev2 = USER |
| 183 |
|
|
#elif (defined (AUTODIFF_4_LEVEL_CHECKPOINT)) |
| 184 |
|
|
CADJ INIT tapelev4 = USER |
| 185 |
|
|
#else |
| 186 |
|
|
CADJ INIT tapelev3 = USER |
| 187 |
|
|
#endif |
| 188 |
|
|
|
| 189 |
|
|
nIter0 = NINT( (startTime-baseTime)/deltaTClock ) |
| 190 |
|
|
ikey_dynamics = 1 |
| 191 |
|
|
|
| 192 |
|
|
CALL TIMER_START('ADJOINT SPIN-UP', mythid) |
| 193 |
|
|
#endif |
| 194 |
|
|
|
| 195 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
| 196 |
|
|
# ifdef NONLIN_FRSURF |
| 197 |
|
|
CADJ STORE hFacC = tapelev_init, key = 1 |
| 198 |
|
|
# endif |
| 199 |
|
|
#endif |
| 200 |
|
|
|
| 201 |
|
|
#ifdef ALLOW_DEBUG |
| 202 |
|
|
IF (debugMode) CALL DEBUG_CALL('INITIALISE_VARIA',myThid) |
| 203 |
|
|
#endif |
| 204 |
|
|
C-- Set initial conditions (variable arrays) |
| 205 |
|
|
CALL TIMER_START('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid) |
| 206 |
|
|
CALL INITIALISE_VARIA( mythid ) |
| 207 |
|
|
CALL TIMER_STOP ('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid) |
| 208 |
|
|
|
| 209 |
|
|
#ifdef ALLOW_MONITOR |
| 210 |
|
|
#ifdef ALLOW_DEBUG |
| 211 |
|
|
IF (debugMode) CALL DEBUG_CALL('MONITOR',myThid) |
| 212 |
|
|
#endif |
| 213 |
|
|
C-- Check status of solution (statistics, cfl, etc...) |
| 214 |
|
|
c CALL TIMER_START('MONITOR [THE_MAIN_LOOP]', mythid) |
| 215 |
|
|
CALL MONITOR( myIter, myTime, myThid ) |
| 216 |
|
|
c CALL TIMER_STOP ('MONITOR [THE_MAIN_LOOP]', mythid) |
| 217 |
|
|
#endif /* ALLOW_MONITOR */ |
| 218 |
|
|
|
| 219 |
|
|
C-- Do IO if needed (Dump for start state). |
| 220 |
|
|
#ifdef ALLOW_DEBUG |
| 221 |
|
|
IF (debugMode) CALL DEBUG_CALL('DO_THE_MODEL_IO',myThid) |
| 222 |
|
|
#endif |
| 223 |
|
|
c CALL TIMER_START('DO_THE_MODEL_IO [THE_MAIN_LOOP]', mythid) |
| 224 |
|
|
CALL DO_THE_MODEL_IO( myTime, myIter, mythid ) |
| 225 |
|
|
c CALL TIMER_STOP ('DO_THE_MODEL_IO [THE_MAIN_LOOP]', mythid) |
| 226 |
|
|
|
| 227 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
| 228 |
|
|
CALL TIMER_STOP ('ADJOINT SPIN-UP', mythid) |
| 229 |
|
|
_BARRIER |
| 230 |
|
|
#endif |
| 231 |
|
|
|
| 232 |
|
|
#ifdef TIME_PER_TIMESTEP |
| 233 |
|
|
CCE107 Initial call for timers |
| 234 |
|
|
_BEGIN_MASTER( myThid ) |
| 235 |
|
|
CALL TIMER_GET_TIME( utold, stold, wtold ) |
| 236 |
|
|
_END_MASTER( myThid ) |
| 237 |
|
|
#endif |
| 238 |
|
|
#ifdef USE_PAPI_FLOPS |
| 239 |
|
|
CCE107 Initial call for PAPI |
| 240 |
|
|
_BEGIN_MASTER( myThid ) |
| 241 |
|
|
#ifdef USE_FLIPS |
| 242 |
|
|
call PAPIF_flips(real_time, proc_time, flpops, mflops, check) |
| 243 |
|
|
#else |
| 244 |
|
|
call PAPIF_flops(real_time, proc_time, flpops, mflops, check) |
| 245 |
|
|
#endif |
| 246 |
|
|
WRITE(msgBuf,'(A34,F10.6,A,F10.6)') |
| 247 |
|
|
$ 'Mflop/s before timestepping:', mflops, ' ', mflops*proc_time |
| 248 |
|
|
$ /(real_time + 1E-36) |
| 249 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1) |
| 250 |
|
|
#ifdef PAPI_VERSION |
| 251 |
|
|
call PAPIF_ipc(real_time, proc_time, instr, ipc, check) |
| 252 |
|
|
WRITE(msgBuf,'(A34,F10.6,A,F10.6)') |
| 253 |
|
|
$ 'IPC before timestepping:', ipc, ' ', ipc*proc_time |
| 254 |
|
|
$ /(real_time + 1E-36) |
| 255 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1) |
| 256 |
|
|
#endif |
| 257 |
|
|
_END_MASTER( myThid ) |
| 258 |
|
|
#else |
| 259 |
|
|
#ifdef USE_PCL_FLOPS |
| 260 |
|
|
CCE107 Initial call for PCL |
| 261 |
|
|
_BEGIN_MASTER( myThid ) |
| 262 |
|
|
res = PCLstop(descr, i_result, fp_result, nevents) |
| 263 |
|
|
do ipcl = 1, nevents |
| 264 |
|
|
WRITE(msgBuf,'(A22,A26,F10.6)'), |
| 265 |
|
|
$ pcl_counter_name(pcl_counter_list(ipcl)), |
| 266 |
|
|
$ 'before timestepping:', fp_result(ipcl) |
| 267 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1) |
| 268 |
|
|
enddo |
| 269 |
|
|
res = PCLstart(descr, pcl_counter_list, nevents, flags) |
| 270 |
|
|
_END_MASTER( myThid ) |
| 271 |
|
|
#endif |
| 272 |
|
|
#endif |
| 273 |
|
|
|
| 274 |
|
|
c-- Do the model integration. |
| 275 |
|
|
CALL TIMER_START('MAIN LOOP [THE_MAIN_LOOP]', mythid) |
| 276 |
|
|
|
| 277 |
|
|
c >>>>>>>>>>>>>>>>>>>>>>>>>>> LOOP <<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 278 |
|
|
c >>>>>>>>>>>>>>>>>>>>>>>>>>> STARTS <<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 279 |
|
|
|
| 280 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
| 281 |
|
|
#ifdef ALLOW_TAMC_CHECKPOINTING |
| 282 |
|
|
|
| 283 |
|
|
max_lev4=nTimeSteps/(nchklev_1*nchklev_2*nchklev_3)+1 |
| 284 |
|
|
max_lev3=nTimeSteps/(nchklev_1*nchklev_2)+1 |
| 285 |
|
|
max_lev2=nTimeSteps/nchklev_1+1 |
| 286 |
|
|
|
| 287 |
|
|
c************************************** |
| 288 |
|
|
#ifdef ALLOW_DIVIDED_ADJOINT |
| 289 |
|
|
CADJ loop = divided |
| 290 |
|
|
#endif |
| 291 |
|
|
c************************************** |
| 292 |
|
|
|
| 293 |
|
|
#ifdef AUTODIFF_4_LEVEL_CHECKPOINT |
| 294 |
|
|
do ilev_4 = 1,nchklev_4 |
| 295 |
|
|
if(ilev_4.le.max_lev4) then |
| 296 |
|
|
c************************************** |
| 297 |
|
|
#include "checkpoint_lev4_directives.h" |
| 298 |
|
|
c************************************** |
| 299 |
|
|
c-- Initialise storage for the middle loop. |
| 300 |
|
|
CADJ INIT tapelev3 = USER |
| 301 |
|
|
#endif /* AUTODIFF_4_LEVEL_CHECKPOINT */ |
| 302 |
|
|
|
| 303 |
|
|
#ifndef AUTODIFF_2_LEVEL_CHECKPOINT |
| 304 |
|
|
do ilev_3 = 1,nchklev_3 |
| 305 |
|
|
if(ilev_3.le.max_lev3) then |
| 306 |
|
|
c************************************** |
| 307 |
|
|
#include "checkpoint_lev3_directives.h" |
| 308 |
|
|
c************************************** |
| 309 |
|
|
c-- Initialise storage for the middle loop. |
| 310 |
|
|
CADJ INIT tapelev2 = USER |
| 311 |
|
|
#endif /* AUTODIFF_2_LEVEL_CHECKPOINT */ |
| 312 |
|
|
|
| 313 |
|
|
do ilev_2 = 1,nchklev_2 |
| 314 |
|
|
if(ilev_2.le.max_lev2) then |
| 315 |
|
|
c************************************** |
| 316 |
|
|
#include "checkpoint_lev2_directives.h" |
| 317 |
|
|
c************************************** |
| 318 |
|
|
|
| 319 |
|
|
c************************************** |
| 320 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
| 321 |
|
|
c-- Initialize storage for the innermost loop. |
| 322 |
|
|
c-- Always check common block sizes for the checkpointing! |
| 323 |
|
|
c-- |
| 324 |
|
|
CADJ INIT comlev1 = COMMON,nchklev_1 |
| 325 |
|
|
CADJ INIT comlev1_bibj = COMMON,nchklev_1*nsx*nsy*nthreads_chkpt |
| 326 |
|
|
CADJ INIT comlev1_bibj_k = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt |
| 327 |
|
|
c-- |
| 328 |
|
|
#ifdef ALLOW_KPP |
| 329 |
|
|
CADJ INIT comlev1_kpp = COMMON,nchklev_1*nsx*nsy |
| 330 |
|
|
CADJ INIT comlev1_kpp_k = COMMON,nchklev_1*nsx*nsy*nr |
| 331 |
|
|
#endif /* ALLOW_KPP */ |
| 332 |
|
|
c-- |
| 333 |
|
|
#ifdef ALLOW_GMREDI |
| 334 |
|
|
CADJ INIT comlev1_gmredi_k_gad |
| 335 |
|
|
CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass |
| 336 |
|
|
#endif /* ALLOW_GMREDI */ |
| 337 |
|
|
c-- |
| 338 |
|
|
#ifdef ALLOW_PTRACERS |
| 339 |
|
|
CADJ INIT comlev1_bibj_ptracers = COMMON, |
| 340 |
|
|
CADJ & nchklev_1*nsx*nsy*nthreads_chkpt*PTRACERS_num |
| 341 |
|
|
CADJ INIT comlev1_bibj_k_ptracers = COMMON, |
| 342 |
|
|
CADJ & nchklev_1*nsx*nsy*nthreads_chkpt*PTRACERS_num*nr |
| 343 |
|
|
#endif /* ALLOW_PTRACERS */ |
| 344 |
|
|
c-- |
| 345 |
|
|
#ifndef DISABLE_MULTIDIM_ADVECTION |
| 346 |
|
|
CADJ INIT comlev1_bibj_k_gad |
| 347 |
|
|
CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass |
| 348 |
|
|
CADJ INIT comlev1_bibj_k_gad_pass |
| 349 |
|
|
CADJ & = COMMON,nchklev_1*nsx*nsy*nr*nthreads_chkpt*maxpass*maxcube |
| 350 |
|
|
#endif /* DISABLE_MULTIDIM_ADVECTION */ |
| 351 |
|
|
c-- |
| 352 |
|
|
#if (defined (ALLOW_EXF) && defined (ALLOW_BULKFORMULAE)) |
| 353 |
|
|
CADJ INIT comlev1_exf_1 |
| 354 |
|
|
CADJ & = COMMON,nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt |
| 355 |
|
|
CADJ INIT comlev1_exf_2 |
| 356 |
|
|
CADJ & = COMMON,niter_bulk*nchklev_1*snx*nsx*sny*nsy*nthreads_chkpt |
| 357 |
|
|
#endif /* ALLOW_BULKFORMULAE */ |
| 358 |
|
|
c-- |
| 359 |
|
|
#ifdef ALLOW_SEAICE |
| 360 |
|
|
# ifdef SEAICE_ALLOW_DYNAMICS |
| 361 |
|
|
CADJ INIT comlev1_lsr = COMMON,nchklev_1*2 |
| 362 |
|
|
# endif |
| 363 |
|
|
#endif /* ALLOW_SEAICE */ |
| 364 |
|
|
c-- |
| 365 |
|
|
#ifdef ALLOW_DEPTH_CONTROL |
| 366 |
|
|
CADJ INIT comlev1_cg2d |
| 367 |
|
|
CADJ & = COMMON,nchklev_1*nthreads_chkpt |
| 368 |
|
|
CADJ INIT comlev1_cg2d_iter |
| 369 |
|
|
CADJ & = COMMON,nchklev_1*nthreads_chkpt*numItersMax |
| 370 |
|
|
#endif |
| 371 |
|
|
c-- |
| 372 |
|
|
#endif /* ALLOW_AUTODIFF_TAMC */ |
| 373 |
|
|
c************************************** |
| 374 |
|
|
|
| 375 |
|
|
do ilev_1 = 1,nchklev_1 |
| 376 |
|
|
|
| 377 |
|
|
c-- The if-statement below introduces a some flexibility in the |
| 378 |
|
|
c-- choice of the 3-tupel ( nchklev_1, nchklev_2, nchklev_3 ). |
| 379 |
|
|
|
| 380 |
|
|
iloop = (ilev_2 - 1)*nchklev_1 + ilev_1 |
| 381 |
|
|
#ifndef AUTODIFF_2_LEVEL_CHECKPOINT |
| 382 |
|
|
& + (ilev_3 - 1)*nchklev_2*nchklev_1 |
| 383 |
|
|
#endif |
| 384 |
|
|
#ifdef AUTODIFF_4_LEVEL_CHECKPOINT |
| 385 |
|
|
& + (ilev_4 - 1)*nchklev_3*nchklev_2*nchklev_1 |
| 386 |
|
|
#endif |
| 387 |
|
|
|
| 388 |
|
|
if ( iloop .le. nTimeSteps ) then |
| 389 |
|
|
|
| 390 |
|
|
#else /* ALLOW_TAMC_CHECKPOINTING undefined */ |
| 391 |
|
|
c-- Initialise storage for reference trajectory without TAMC check- |
| 392 |
|
|
c-- pointing. |
| 393 |
|
|
CADJ INIT history = USER |
| 394 |
|
|
CADJ INIT comlev1_bibj = COMMON,nchklev_0*nsx*nsy*nthreads_chkpt |
| 395 |
|
|
CADJ INIT comlev1_bibj_k = COMMON,nchklev_0*nsx*nsy*nr*nthreads_chkpt |
| 396 |
|
|
CADJ INIT comlev1_kpp = COMMON,nchklev_0*nsx*nsy |
| 397 |
|
|
|
| 398 |
|
|
c-- Check the choice of the checkpointing parameters in relation |
| 399 |
|
|
c-- to nTimeSteps: (nchklev_0 .ge. nTimeSteps) |
| 400 |
|
|
if (nchklev_0 .lt. nTimeSteps) then |
| 401 |
|
|
print* |
| 402 |
|
|
print*, ' the_main_loop: TAMC checkpointing parameter ', |
| 403 |
|
|
& 'nchklev_0 = ', nchklev_0 |
| 404 |
|
|
print*, ' not consistent with nTimeSteps = ', |
| 405 |
|
|
& nTimeSteps |
| 406 |
|
|
stop ' ... stopped in the_main_loop.' |
| 407 |
|
|
endif |
| 408 |
|
|
|
| 409 |
|
|
DO iloop = 1, nTimeSteps |
| 410 |
|
|
|
| 411 |
|
|
#endif /* ALLOW_TAMC_CHECKPOINTING */ |
| 412 |
|
|
|
| 413 |
|
|
#else /* ALLOW_AUTODIFF_TAMC undefined */ |
| 414 |
|
|
|
| 415 |
|
|
c-- Start the main loop of adjoint_Objfunc. Automatic differentiation |
| 416 |
|
|
c-- NOT enabled. |
| 417 |
|
|
DO iloop = 1, nTimeSteps |
| 418 |
|
|
|
| 419 |
|
|
#endif /* ALLOW_AUTODIFF_TAMC */ |
| 420 |
|
|
|
| 421 |
|
|
c-- >>> Loop body start <<< |
| 422 |
|
|
|
| 423 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
| 424 |
|
|
nIter0 = NINT( (startTime-baseTime)/deltaTClock ) |
| 425 |
|
|
ikey_dynamics = ilev_1 |
| 426 |
|
|
CALL AUTODIFF_INADMODE_UNSET( myThid ) |
| 427 |
|
|
#endif |
| 428 |
|
|
|
| 429 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
| 430 |
|
|
CALL AUTODIFF_INADMODE_UNSET( myThid ) |
| 431 |
|
|
#endif |
| 432 |
|
|
|
| 433 |
|
|
#ifdef ALLOW_PROFILES |
| 434 |
|
|
#ifdef ALLOW_DEBUG |
| 435 |
|
|
IF (debugMode) CALL DEBUG_CALL('',myThid) |
| 436 |
|
|
#endif |
| 437 |
|
|
c-- Accumulate in-situ time averages of temperature, salinity, and SSH. |
| 438 |
|
|
call TIMER_START('PROFILES_INLOOP [THE_MAIN_LOOP]', mythid) |
| 439 |
|
|
call PROFILES_INLOOP( mytime, mythid ) |
| 440 |
|
|
call TIMER_STOP ('PROFILES_INLOOP [THE_MAIN_LOOP]', mythid) |
| 441 |
|
|
#endif |
| 442 |
|
|
|
| 443 |
|
|
#ifdef ALLOW_DEBUG |
| 444 |
|
|
IF (debugMode) CALL DEBUG_CALL('FORWARD_STEP',myThid) |
| 445 |
|
|
#endif |
| 446 |
|
|
|
| 447 |
|
|
#ifdef ALLOW_ATM2D |
| 448 |
|
|
CALL TIMER_START('FORWARD_STEP_ATM2D [THE_MAIN_LOOP]',mythid) |
| 449 |
|
|
CALL FORWARD_STEP_ATM2D( iloop, mytime, myiter, mythid ) |
| 450 |
|
|
CALL TIMER_STOP ('FORWARD_STEP_ATM2D [THE_MAIN_LOOP]',mythid) |
| 451 |
|
|
#else |
| 452 |
|
|
CALL TIMER_START('FORWARD_STEP [THE_MAIN_LOOP]',mythid) |
| 453 |
|
|
CALL FORWARD_STEP( iloop, mytime, myiter, mythid ) |
| 454 |
|
|
CALL TIMER_STOP ('FORWARD_STEP [THE_MAIN_LOOP]',mythid) |
| 455 |
|
|
#endif |
| 456 |
|
|
|
| 457 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
| 458 |
|
|
CALL AUTODIFF_INADMODE_SET( myThid ) |
| 459 |
|
|
#endif |
| 460 |
|
|
|
| 461 |
|
|
#ifdef ALLOW_RUNCLOCK |
| 462 |
|
|
IF (useRunClock) THEN |
| 463 |
|
|
RC_CONT=RUNCLOCK_CONTINUE( myThid ) |
| 464 |
|
|
IF (.NOT.RC_CONT) RETURN |
| 465 |
|
|
ENDIF |
| 466 |
|
|
#endif /* ALLOW_RUNCLOCK */ |
| 467 |
|
|
#ifdef TIME_PER_TIMESTEP |
| 468 |
|
|
CCE107 Time per timestep information |
| 469 |
|
|
_BEGIN_MASTER( myThid ) |
| 470 |
|
|
CALL TIMER_GET_TIME( utnew, stnew, wtnew ) |
| 471 |
|
|
WRITE(msgBuf,'(A34,3F10.6,I8)') |
| 472 |
|
|
$ 'User, system and wallclock time:', utnew - utold, |
| 473 |
|
|
$ stnew - stold, wtnew - wtold, iloop |
| 474 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1) |
| 475 |
|
|
utold = utnew |
| 476 |
|
|
stold = stnew |
| 477 |
|
|
wtold = wtnew |
| 478 |
|
|
_END_MASTER( myThid ) |
| 479 |
|
|
#endif |
| 480 |
|
|
#ifdef USE_PAPI_FLOPS |
| 481 |
|
|
CCE107 PAPI summary performance |
| 482 |
|
|
_BEGIN_MASTER( myThid ) |
| 483 |
|
|
#ifdef USE_FLIPS |
| 484 |
|
|
call PAPIF_flips(real_time, proc_time, flpops, mflops, check) |
| 485 |
|
|
#else |
| 486 |
|
|
call PAPIF_flops(real_time, proc_time, flpops, mflops, check) |
| 487 |
|
|
#endif |
| 488 |
|
|
WRITE(msgBuf,'(F10.6,A,F10.6,A34,I8)') |
| 489 |
|
|
$ mflops, ' ', mflops*proc_time/(real_time + 1E-36), |
| 490 |
|
|
$ 'Mflop/s during timestep ', iloop |
| 491 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1) |
| 492 |
|
|
#ifdef PAPI_VERSION |
| 493 |
|
|
call PAPIF_ipc(real_time, proc_time, instr, ipc, check) |
| 494 |
|
|
WRITE(msgBuf,'(F10.6,A,F10.6,A34,I8)') |
| 495 |
|
|
$ ipc, ' ', ipc*proc_time/(real_time + 1E-36), |
| 496 |
|
|
$ 'IPC during timestep ', iloop |
| 497 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1) |
| 498 |
|
|
#endif |
| 499 |
|
|
_END_MASTER( myThid ) |
| 500 |
|
|
#else |
| 501 |
|
|
#ifdef USE_PCL_FLOPS |
| 502 |
|
|
CCE107 PCL summary performance |
| 503 |
|
|
_BEGIN_MASTER( myThid ) |
| 504 |
|
|
res = PCLstop(descr, i_result, fp_result, nevents) |
| 505 |
|
|
do ipcl = 1, nevents |
| 506 |
|
|
WRITE(msgBuf,'(F10.6,A2,A22,A17,I8)'), fp_result(ipcl), |
| 507 |
|
|
$ ' ', pcl_counter_name(pcl_counter_list(ipcl)), |
| 508 |
|
|
$ 'during timestep ', iloop |
| 509 |
|
|
CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1) |
| 510 |
|
|
enddo |
| 511 |
|
|
res = PCLstart(descr, pcl_counter_list, nevents, flags) |
| 512 |
|
|
_END_MASTER( myThid ) |
| 513 |
|
|
#endif |
| 514 |
|
|
#endif |
| 515 |
|
|
|
| 516 |
|
|
c-- >>> Loop body end <<< |
| 517 |
|
|
|
| 518 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
| 519 |
|
|
CALL AUTODIFF_INADMODE_SET( myThid ) |
| 520 |
|
|
#ifdef ALLOW_TAMC_CHECKPOINTING |
| 521 |
|
|
endif |
| 522 |
|
|
enddo |
| 523 |
|
|
endif |
| 524 |
|
|
enddo |
| 525 |
|
|
#ifndef AUTODIFF_2_LEVEL_CHECKPOINT |
| 526 |
|
|
endif |
| 527 |
|
|
enddo |
| 528 |
|
|
#endif |
| 529 |
|
|
#ifdef AUTODIFF_4_LEVEL_CHECKPOINT |
| 530 |
|
|
endif |
| 531 |
|
|
enddo |
| 532 |
|
|
#endif |
| 533 |
|
|
#else /* ndef ALLOW_TAMC_CHECKPOINTING */ |
| 534 |
|
|
enddo |
| 535 |
|
|
#endif /* ALLOW_TAMC_CHECKPOINTING */ |
| 536 |
|
|
|
| 537 |
|
|
#else /* ndef ALLOW_AUTODIFF_TAMC */ |
| 538 |
|
|
enddo |
| 539 |
|
|
#endif /* ALLOW_AUTODIFF_TAMC */ |
| 540 |
|
|
|
| 541 |
|
|
#ifdef ALLOW_PROFILES |
| 542 |
|
|
c-- Accumulate in-situ time averages of temperature, salinity, and SSH. |
| 543 |
|
|
call TIMER_START('PROFILES_INLOOP [THE_MAIN_LOOP]', mythid) |
| 544 |
|
|
call PROFILES_INLOOP( mytime, mythid ) |
| 545 |
|
|
call TIMER_STOP ('PROFILES_INLOOP [THE_MAIN_LOOP]', mythid) |
| 546 |
|
|
#endif |
| 547 |
|
|
|
| 548 |
|
|
#ifdef ALLOW_COST |
| 549 |
|
|
c-- Sum all cost function contributions. |
| 550 |
|
|
call TIMER_START('COST_FINAL [THE_MAIN_LOOP]', mythid) |
| 551 |
|
|
call COST_FINAL ( mythid ) |
| 552 |
|
|
call TIMER_STOP ('COST_FINAL [THE_MAIN_LOOP]', mythid) |
| 553 |
|
|
#endif |
| 554 |
|
|
|
| 555 |
|
|
_BARRIER |
| 556 |
|
|
CALL TIMER_STOP ('MAIN LOOP [THE_MAIN_LOOP]', mythid) |
| 557 |
|
|
|
| 558 |
|
|
#ifdef ALLOW_DEBUG |
| 559 |
|
|
IF (debugMode) CALL DEBUG_LEAVE('THE_MAIN_LOOP',myThid) |
| 560 |
|
|
#endif |
| 561 |
|
|
|
| 562 |
|
|
END |
| 563 |
|
|
|