--- MITgcm/model/src/the_model_main.F 1998/07/01 19:49:36 1.17 +++ MITgcm/model/src/the_model_main.F 2001/04/10 22:35:26 1.38 @@ -1,6 +1,7 @@ -C $Header: /home/ubuntu/mnt/e9_copy/MITgcm/model/src/the_model_main.F,v 1.17 1998/07/01 19:49:36 adcroft Exp $ +C $Header: /home/ubuntu/mnt/e9_copy/MITgcm/model/src/the_model_main.F,v 1.38 2001/04/10 22:35:26 heimbach Exp $ +C $Name: $ -#include "CPP_EEOPTIONS.h" +#include "CPP_OPTIONS.h" SUBROUTINE THE_MODEL_MAIN(myThid) C /==========================================================\ @@ -22,6 +23,7 @@ C | C*P* comments indicating place holders for which code is | C | presently being developed. | C \==========================================================/ + IMPLICIT NONE C C Call Tree C ========= @@ -42,33 +44,47 @@ C | | and/or instance. Each instance manages C | | a specifc set of tiles. C | | -C | |--INITIALISE -C | | o Set initial conditions and model configuration +C | |--INITIALISE_FIXED +C | | o Set model configuration (fixed arrays) C | | Topography, hydrography, timestep, grid, etc.. C | | -C ==> | | ** Time stepping loop starts here ** -C | | | -C /|\ | | -C | | |--LOAD_EXTERNAL_DATA -C /|\ | | o Load and/or set time dependent forcing fields -C | | | -C /|\ | |--DYNAMICS -C | | | o Evaluate "forward" terms -C /|\ | | -C | | |--DO_THE_MODEL_IO -C /|\ | | o Write model state -C | | | -C /|\ | |--SOLVE_FOR_PRESSURE -C | | | o Find pressure field to keep flow non-divergent -C /|\ | | -C | | |--DO_GTERM_BLOCKING_EXCHANGES -C /|\ | | o Update overlap regions -C | | | -C /|\ | |--WRITE_CHECKPOINT -C | | | o Write restart file(s) -C /|\ | | -C | | | -C |<== | | ** Time stepping loop finishes here ** +C | |--THE_MAIN_LOOP +C | | | +C | | |--INITIALISE_VARIA +C | | | o Set initial conditions (variable arrays) +C | | | +C ==> | | | ** Time stepping loop starts here ** +C | | | | +C /|\ | | | +C | | | |--FORWARD_STEP +C /|\ | | | | o Does a single forward step of the model +C | | | | | +C /|\ | | | | +C | | | | |--LOAD_EXTERNAL_DATA +C /|\ | | | | o Load and/or set time dependent forcing fields +C | | | | | +C /|\ | | | |--DYNAMICS +C | | | | | o Evaluate "forward" terms +C /|\ | | | | +C | | | | |--SOLVE_FOR_PRESSURE +C /|\ | | | | o Find pressure field to keep flow non-divergent +C | | | | | +C /|\ | | | |--THE_CORRECTION_STEP +C | | | | | o Correct flow field with and cycle time-stepping arrays +C /|\ | | | | +C | | | | |--DO_GTERM_BLOCKING_EXCHANGES +C /|\ | | | | o Update overlap regions +C | | | | | +C /|\ | | | |--DO_THE_MODEL_IO +C | | | | | o Write model state +C /|\ | | | | +C | | | | |--WRITE_CHECKPOINT +C /|\ | | | | o Write restart file(s) +C | | | | +C /|\ | | | +C |<== | | | ** Time stepping loop finishes here ** +C | | | +C | | |-- C | | C | |--WRITE_STATE C | |--WRITE_CHECKPOINT @@ -84,9 +100,16 @@ #include "SIZE.h" #include "EEPARAMS.h" #include "PARAMS.h" -#include "CG2D.h" #include "DYNVARS.h" -#include "AVER.h" +#ifdef ALLOW_NONHYDROSTATIC +#include "CG3D.h" +#endif + +#ifdef ALLOW_AUTODIFF_TAMC +#include "tamc.h" +#include "cost.h" +#include "adcost.h" +#endif C == Routine arguments == C myThid - Thread number for this instance of the routine. @@ -98,88 +121,68 @@ C arguments. Although this is fiddly it saves the need to C impose additional synchronisation points when they are C updated. -C myCurrentIter - Iteration counter for this thread C myCurrentTime - Time counter for this thread -C I - Loop counter - INTEGER I, myCurrentIter - REAL myCurrentTime +C myCurrentIter - Iteration counter for this thread + INTEGER myCurrentIter + _RL myCurrentTime + +C-- This timer encompasses the whole code + CALL TIMER_START('ALL [THE_MODEL_MAIN]',myThid) + + +C-- Set model configuration (fixed arrays) + CALL TIMER_START('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) + CALL INITIALISE_FIXED( myThid ) + CALL TIMER_STOP ('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) -C-- Set model initial conditions - CALL INITIALISE( myThid ) myCurrentTime = startTime myCurrentIter = nIter0 -C-- Dump for start state - CALL WRITE_STATE( .TRUE., myCurrentTime, myCurrentIter, myThid ) +#ifdef ALLOW_MIT_ADJOINT_RUN -C-- Begin time stepping loop - DO I=1, nTimeSteps + _BEGIN_MASTER( mythid ) + IF (myProcId .eq. 0) THEN + CALL CTRL_UNPACK( mycurrentiter, mycurrenttime, mythid ) + ENDIF + _END_MASTER( mythid ) + _BARRIER -C-- Load forcing/external data fields - CALL LOAD_EXTERNAL_FIELDS( myCurrentTime, myCurrentIter, myThid ) + fc = 0.0 + adfc = 1.0 + CALL TIMER_START('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) + call ADTHE_MAIN_LOOP ( mythid ) + call TIMER_STOP ('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) + _BARRIER + + _BEGIN_MASTER( mythid ) + IF (myProcId .eq. 0) THEN + call CTRL_PACK( mycurrentiter, mycurrenttime, mythid ) + ENDIF + _END_MASTER( mythid ) + _BARRIER -C-- Step forward fields and calculate time tendency terms - CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) - -C-- Do time averages -#ifdef ALLOW_DIAGNOSTICS - IF (taveFreq.GT.0.) THEN - CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid ) - ENDIF -#endif +#else /* ALLOW_MIT_ADJOINT_RUN undef */ -C-- Do IO if needed. -C Note: -C ===== -C At this point model arrays hold U,V,T,S at "time-level" N -C and cg2d_x at "time-level" N-1/2 where N = I+timeLevBase-1. -C By convention this is taken to be the model "state". - CALL DO_THE_MODEL_IO( myCurrentTime, myCurrentIter, myThid ) - -C-- Solve elliptic equation(s). -C Two-dimensional only for conventional hydrostatic or -C three-dimensional for non-hydrostatic and/or IGW scheme. - CALL SOLVE_FOR_PRESSURE( myThid ) - -C-- Do "blocking" sends and receives for tendency "overlap" terms - CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) - - myCurrentIter = myCurrentIter + 1 - myCurrentTime = myCurrentTime + deltaTClock - -C-- Save state for restarts -C Note: -C ===== -C Because of the ordering of the timestepping code and -C tendency term code at end of loop model arrays hold -C U,V,T,S at "time-level" N but gu, gv, gs, gt, guNM1,... -C at "time-level" N+1/2 (guNM1 at "time-level" N+1/2 is -C gu at "time-level" N-1/2) and cg2d_x at "time-level" N+1/2. -C where N = I+timeLevBase-1 -C Thus a checkpoint contains U.0000000000, GU.0000000001 and -C cg2d_x.0000000001 in the indexing scheme used for the model -C "state" files. This example is referred to as a checkpoint -C at time level 1 - CALL WRITE_CHECKPOINT( .FALSE., myCurrentTime, myCurrentIter, myThid ) +C-- Call time stepping loop of full model + CALL TIMER_START('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) + CALL THE_MAIN_LOOP(myCurrentTime, myCurrentIter, myThid ) + CALL TIMER_STOP ('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) - ENDDO +#endif /* ALLOW_MIT_ADJOINT_RUN */ C-- Final checkpoint (incase the in-loop checkpoint was missed) - CALL WRITE_CHECKPOINT( .TRUE., myCurrentTime, myCurrentIter, myThid ) - -C-- Step-forward U/V/Theta/Salt for purposes of final I/O dump - CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) - -C-- Do time averages -#ifdef ALLOW_DIAGNOSTICS - IF (taveFreq.GT.0.) THEN - CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid ) + CALL TIMER_START('WRITE_CHECKPOINT [THE_MODEL_MAIN]',myThid) + CALL WRITE_CHECKPOINT( + & .TRUE., myCurrentTime, myCurrentIter, myThid ) + CALL TIMER_STOP ('WRITE_CHECKPOINT [THE_MODEL_MAIN]',myThid) + + CALL TIMER_STOP ('ALL [THE_MODEL_MAIN]',myThid) + +C-- Write timer statistics + IF ( myThid .EQ. 1 ) THEN + CALL TIMER_PRINTALL( myThid ) + CALL COMM_STATS ENDIF -#endif - -C-- Dump for end state - CALL WRITE_STATE( .FALSE., myCurrentTime, myCurrentIter, myThid ) - RETURN END