1 |
C $Header$ |
C $Header$ |
2 |
|
C $Name$ |
3 |
|
|
4 |
#include "CPP_OPTIONS.h" |
#include "CPP_OPTIONS.h" |
5 |
|
|
25 |
C \==========================================================/ |
C \==========================================================/ |
26 |
IMPLICIT NONE |
IMPLICIT NONE |
27 |
C |
C |
|
C Call Tree |
|
|
C ========= |
|
|
C |
|
|
C main ( eesupp ) |
|
|
C | |
|
|
C . |
|
|
C . |
|
|
C . Generic environment initialisation ( see eesupp/src and |
|
|
C . eesupp/inc ) |
|
|
C . multiple threads and/or processes are created in here |
|
|
C . |
|
|
C . |
|
|
C . |
|
|
C | |
|
|
C |-THE_MODEL_MAIN - Begin specific model. One instance |
|
|
C | | of this codes exists for each thread |
|
|
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 | | 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 | | |
|
|
C | |--WRITE_STATE |
|
|
C | |--WRITE_CHECKPOINT |
|
|
C | |
|
|
C . |
|
|
C . |
|
|
C . Generic environment termination ( see eesupp/src and |
|
|
C . eesupp/inc ) |
|
|
C . |
|
|
C . |
|
|
|
|
28 |
C == Global variables === |
C == Global variables === |
29 |
#include "SIZE.h" |
#include "SIZE.h" |
30 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
31 |
#include "PARAMS.h" |
#include "PARAMS.h" |
|
#include "CG2D.h" |
|
32 |
#include "DYNVARS.h" |
#include "DYNVARS.h" |
33 |
|
#ifdef ALLOW_NONHYDROSTATIC |
34 |
|
#include "CG3D.h" |
35 |
|
#endif |
36 |
|
|
37 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
38 |
|
#include "tamc.h" |
39 |
|
#include "cost.h" |
40 |
|
#include "adcost.h" |
41 |
|
#endif |
42 |
|
|
43 |
C == Routine arguments == |
C == Routine arguments == |
44 |
C myThid - Thread number for this instance of the routine. |
C myThid - Thread number for this instance of the routine. |
50 |
C arguments. Although this is fiddly it saves the need to |
C arguments. Although this is fiddly it saves the need to |
51 |
C impose additional synchronisation points when they are |
C impose additional synchronisation points when they are |
52 |
C updated. |
C updated. |
|
C myCurrentIter - Iteration counter for this thread |
|
53 |
C myCurrentTime - Time counter for this thread |
C myCurrentTime - Time counter for this thread |
54 |
C I - Loop counter |
C myCurrentIter - Iteration counter for this thread |
55 |
INTEGER I, myCurrentIter |
INTEGER myCurrentIter |
56 |
REAL myCurrentTime |
_RL myCurrentTime |
57 |
|
|
58 |
C-- This timer encompasses the whole code |
C-- This timer encompasses the whole code |
59 |
CALL TIMER_START('ALL',myThid) |
CALL TIMER_START('ALL [THE_MODEL_MAIN]',myThid) |
60 |
|
|
|
CALL TIMER_START('SPIN-UP',myThid) |
|
61 |
|
|
62 |
C-- Set model initial conditions |
C-- Set model configuration (fixed arrays) |
63 |
CALL TIMER_START('INITIALISE [SPIN-UP]',myThid) |
CALL TIMER_START('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) |
64 |
CALL INITIALISE( myThid ) |
CALL INITIALISE_FIXED( myThid ) |
65 |
|
CALL TIMER_STOP ('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) |
66 |
|
|
67 |
myCurrentTime = startTime |
myCurrentTime = startTime |
68 |
myCurrentIter = nIter0 |
myCurrentIter = nIter0 |
|
CALL TIMER_STOP ('INITIALISE [SPIN-UP]',myThid) |
|
69 |
|
|
70 |
C-- Dump for start state |
#if ( defined (ALLOW_ADJOINT_RUN) || \ |
71 |
CALL TIMER_START('I/O (WRITE) [SPIN-UP]',myThid) |
defined (ALLOW_GRADIENT_CHECK) || \ |
72 |
CALL WRITE_STATE( .TRUE., myCurrentTime, myCurrentIter, myThid ) |
defined (ALLOW_ECCO_OPTIMIZATION) ) |
73 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-UP]',myThid) |
|
74 |
|
_BEGIN_MASTER( mythid ) |
75 |
CALL TIMER_STOP ('SPIN-UP',myThid) |
IF (myProcId .eq. 0) THEN |
76 |
|
CALL CTRL_UNPACK( mycurrentiter, mycurrenttime, mythid ) |
77 |
C-- Begin time stepping loop |
ENDIF |
78 |
CALL TIMER_START('MAIN LOOP',myThid) |
_END_MASTER( mythid ) |
79 |
DO I=1, nTimeSteps |
_BARRIER |
80 |
|
|
81 |
C-- Load forcing/external data fields |
fc = 0.0 |
82 |
CALL TIMER_START('I/O (READ) [MAIN LOOP]',myThid) |
adfc = 1.0 |
83 |
CALL LOAD_EXTERNAL_FIELDS( myCurrentTime, myCurrentIter, myThid ) |
CALL TIMER_START('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) |
84 |
CALL TIMER_STOP ('I/O (READ) [MAIN LOOP]',myThid) |
CALL ADTHE_MAIN_LOOP ( mythid ) |
85 |
|
CALL TIMER_STOP ('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) |
86 |
#ifdef INCLUDE_SHAPIRO_FILTER_CODE |
_BARRIER |
87 |
C-- Step forward all tiles, filter and exchange. |
|
88 |
CALL TIMER_START('SHAP_FILT [MAIN LOOP]',myThid) |
_BEGIN_MASTER( mythid ) |
89 |
CALL SHAP_FILT( myCurrentTime, myCurrentIter, myThid ) |
IF (myProcId .eq. 0) THEN |
90 |
CALL TIMER_STOP ('SHAP_FILT [MAIN LOOP]',myThid) |
call CTRL_PACK( mycurrentiter, mycurrenttime, mythid ) |
91 |
#endif |
ENDIF |
92 |
|
_END_MASTER( mythid ) |
93 |
|
_BARRIER |
94 |
|
|
95 |
C-- Set Open Boundaries Values |
#ifdef ALLOW_GRADIENT_CHECK |
96 |
IF (openBoundaries) THEN |
if (useGrdchk) then |
97 |
CALL TIMER_START('OBCS [MAIN LOOP]',myThid) |
CALL TIMER_START('GRDCHK_MAIN [ADJOINT RUN]', mythid) |
98 |
CALL SET_OBCS( myCurrentTime, myThid ) |
CALL GRDCHK_MAIN( mythid ) |
99 |
CALL TIMER_STOP ('OBCS [MAIN LOOP]',myThid) |
CALL TIMER_STOP ('GRDCHK_MAIN [ADJOINT RUN]', mythid) |
100 |
ENDIF |
_BARRIER |
101 |
|
end if |
|
C-- Step forward fields and calculate time tendency terms |
|
|
CALL TIMER_START('DYNAMICS [MAIN LOOP]',myThid) |
|
|
CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('DYNAMICS [MAIN LOOP]',myThid) |
|
|
|
|
|
C-- Do time averages |
|
|
#ifdef INCLUDE_DIAGNOSTICS_INTERFACE_CODE |
|
|
CALL TIMER_START('I/O (WRITE) [MAIN LOOP]',myThid) |
|
|
IF (taveFreq.GT.0.) THEN |
|
|
CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid ) |
|
|
ENDIF |
|
|
CALL TIMER_STOP ('I/O (WRITE) [MAIN LOOP]',myThid) |
|
102 |
#endif |
#endif |
103 |
|
|
104 |
C-- Do IO if needed. |
#else /* ALLOW_ADJOINT_RUN undef */ |
|
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 TIMER_START('I/O (WRITE) [MAIN LOOP]',myThid) |
|
|
CALL DO_THE_MODEL_IO( myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('I/O (WRITE) [MAIN LOOP]',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 TIMER_START('SOLVE_FOR_PRESSURE [MAIN LOOP]',myThid) |
|
|
CALL SOLVE_FOR_PRESSURE( myThid ) |
|
|
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [MAIN LOOP]',myThid) |
|
|
|
|
|
C-- Do "blocking" sends and receives for tendency "overlap" terms |
|
|
CALL TIMER_START('BLOCKING_EXCHANGES [MAIN LOOP]',myThid) |
|
|
CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
|
|
CALL TIMER_STOP ('BLOCKING_EXCHANGES [MAIN LOOP]',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 TIMER_START('I/O (WRITE) [MAIN LOOP]',myThid) |
|
|
CALL |
|
|
& WRITE_CHECKPOINT( .FALSE., myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('I/O (WRITE) [MAIN LOOP]',myThid) |
|
|
|
|
|
ENDDO |
|
|
CALL TIMER_STOP ('MAIN LOOP',myThid) |
|
|
CALL TIMER_START('SPIN-DOWN',myThid) |
|
105 |
|
|
106 |
C-- Final checkpoint (incase the in-loop checkpoint was missed) |
C-- Call time stepping loop of full model |
107 |
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
CALL TIMER_START('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
108 |
CALL |
CALL THE_MAIN_LOOP(myCurrentTime, myCurrentIter, myThid ) |
109 |
& WRITE_CHECKPOINT( .TRUE., myCurrentTime, myCurrentIter, myThid ) |
CALL TIMER_STOP ('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
|
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
|
|
|
|
|
C-- Set Open Boundaries Values |
|
|
IF (openBoundaries) THEN |
|
|
CALL TIMER_START('OBCS [SPIN_DOWN]',myThid) |
|
|
CALL SET_OBCS( myCurrentTime, myThid ) |
|
|
CALL TIMER_STOP ('OBCS [SPIN_DOWN]',myThid) |
|
|
ENDIF |
|
110 |
|
|
111 |
C-- Step-forward U/V/Theta/Salt for purposes of final I/O dump |
#endif /* ALLOW_ADJOINT_RUN */ |
|
CALL TIMER_START('DYNAMICS [SPIN-DOWN]',myThid) |
|
|
CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('DYNAMICS [SPIN-DOWN]',myThid) |
|
|
|
|
|
C-- Do time averages |
|
|
#ifdef ALLOW_DIAGNOSTICS |
|
|
IF (taveFreq.GT.0.) THEN |
|
|
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
|
|
CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
|
|
ENDIF |
|
|
#endif |
|
112 |
|
|
113 |
C-- Dump for end state |
C-- Final checkpoint (incase the in-loop checkpoint was missed) |
114 |
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
CALL TIMER_START('WRITE_CHECKPOINT [THE_MODEL_MAIN]',myThid) |
115 |
CALL WRITE_STATE( .FALSE., myCurrentTime, myCurrentIter, myThid ) |
CALL WRITE_CHECKPOINT( |
116 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
& .TRUE., myCurrentTime, myCurrentIter, myThid ) |
117 |
|
CALL TIMER_STOP ('WRITE_CHECKPOINT [THE_MODEL_MAIN]',myThid) |
118 |
|
|
119 |
CALL TIMER_STOP ('SPIN-DOWN',myThid) |
CALL TIMER_STOP ('ALL [THE_MODEL_MAIN]',myThid) |
|
CALL TIMER_STOP ('ALL',myThid) |
|
120 |
|
|
121 |
C-- Write timer statistics |
C-- Write timer statistics |
122 |
IF ( myThid .EQ. 1 ) THEN |
IF ( myThid .EQ. 1 ) THEN |