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" |
32 |
#include "DYNVARS.h" |
#include "DYNVARS.h" |
|
#include "CG2D.h" |
|
33 |
#ifdef ALLOW_NONHYDROSTATIC |
#ifdef ALLOW_NONHYDROSTATIC |
34 |
#include "CG3D.h" |
#include "CG3D.h" |
35 |
#endif |
#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. |
45 |
INTEGER myThid |
INTEGER myThid |
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 |
_RL 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 |
#ifdef ALLOW_ADJOINT_RUN |
|
CALL TIMER_START('I/O (WRITE) [SPIN-UP]',myThid) |
|
|
CALL WRITE_STATE( .TRUE., myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('I/O (WRITE) [SPIN-UP]',myThid) |
|
|
|
|
|
CALL TIMER_STOP ('SPIN-UP',myThid) |
|
|
|
|
|
C-- Begin time stepping loop |
|
|
CALL TIMER_START('MAIN LOOP',myThid) |
|
|
DO I=1, nTimeSteps |
|
|
|
|
|
C-- Load forcing/external data fields |
|
|
CALL TIMER_START('I/O (READ) [MAIN LOOP]',myThid) |
|
|
CALL LOAD_EXTERNAL_FIELDS( myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('I/O (READ) [MAIN LOOP]',myThid) |
|
|
|
|
|
#ifdef INCLUDE_SHAPIRO_FILTER_CODE |
|
|
C-- Step forward all tiles, filter and exchange. |
|
|
CALL TIMER_START('SHAP_FILT [MAIN LOOP]',myThid) |
|
|
CALL SHAP_FILT( myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('SHAP_FILT [MAIN LOOP]',myThid) |
|
|
#endif |
|
71 |
|
|
72 |
C-- Step forward fields and calculate time tendency terms |
_BEGIN_MASTER( mythid ) |
73 |
CALL TIMER_START('DYNAMICS [MAIN LOOP]',myThid) |
IF (myProcId .eq. 0) THEN |
74 |
CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) |
CALL CTRL_UNPACK( mycurrentiter, mycurrenttime, mythid ) |
75 |
CALL TIMER_STOP ('DYNAMICS [MAIN LOOP]',myThid) |
ENDIF |
76 |
|
_END_MASTER( mythid ) |
77 |
|
_BARRIER |
78 |
|
|
79 |
#ifdef ALLOW_NONHYDROSTATIC |
fc = 0.0 |
80 |
C-- Step forward W field in N-H algorithm |
adfc = 1.0 |
81 |
IF ( nonHydrostatic ) THEN |
CALL TIMER_START('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) |
82 |
CALL TIMER_START('CALC_GW [MAIN LOOP]',myThid) |
CALL ADTHE_MAIN_LOOP ( mythid ) |
83 |
CALL CALC_GW( myThid) |
CALL TIMER_STOP ('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) |
84 |
CALL TIMER_STOP ('CALC_GW [MAIN LOOP]',myThid) |
_BARRIER |
85 |
ENDIF |
|
86 |
#endif |
_BEGIN_MASTER( mythid ) |
87 |
|
IF (myProcId .eq. 0) THEN |
88 |
|
call CTRL_PACK( mycurrentiter, mycurrenttime, mythid ) |
89 |
|
ENDIF |
90 |
|
_END_MASTER( mythid ) |
91 |
|
_BARRIER |
92 |
|
|
93 |
C-- Do time averages |
#ifdef ALLOW_GRADIENT_CHECK |
94 |
#ifdef INCLUDE_DIAGNOSTICS_INTERFACE_CODE |
if (useGrdchk) then |
95 |
CALL TIMER_START('I/O (WRITE) [MAIN LOOP]',myThid) |
CALL TIMER_START('GRDCHK_MAIN [ADJOINT RUN]', mythid) |
96 |
IF (taveFreq.GT.0.) THEN |
CALL GRDCHK_MAIN( mythid ) |
97 |
CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid ) |
CALL TIMER_STOP ('GRDCHK_MAIN [ADJOINT RUN]', mythid) |
98 |
ENDIF |
_BARRIER |
99 |
CALL TIMER_STOP ('I/O (WRITE) [MAIN LOOP]',myThid) |
end if |
100 |
#endif |
#endif |
101 |
|
|
102 |
|
#else /* ALLOW_ADJOINT_RUN undef */ |
103 |
|
|
104 |
|
C-- Call time stepping loop of full model |
105 |
|
CALL TIMER_START('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
106 |
|
CALL THE_MAIN_LOOP(myCurrentTime, myCurrentIter, myThid ) |
107 |
|
CALL TIMER_STOP ('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
108 |
|
|
109 |
C-- Do IO if needed. |
#endif /* ALLOW_ADJOINT_RUN */ |
|
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) |
|
110 |
|
|
111 |
C-- Final checkpoint (incase the in-loop checkpoint was missed) |
C-- Final checkpoint (incase the in-loop checkpoint was missed) |
112 |
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
CALL TIMER_START('WRITE_CHECKPOINT [THE_MODEL_MAIN]',myThid) |
113 |
CALL |
CALL WRITE_CHECKPOINT( |
114 |
& WRITE_CHECKPOINT( .TRUE., myCurrentTime, myCurrentIter, myThid ) |
& .TRUE., myCurrentTime, myCurrentIter, myThid ) |
115 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
CALL TIMER_STOP ('WRITE_CHECKPOINT [THE_MODEL_MAIN]',myThid) |
|
|
|
|
C-- Step-forward U/V/Theta/Salt for purposes of final I/O dump |
|
|
CALL TIMER_START('DYNAMICS [SPIN-DOWN]',myThid) |
|
|
CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('DYNAMICS [SPIN-DOWN]',myThid) |
|
|
|
|
|
#ifdef ALLOW_NONHYDROSTATIC |
|
|
IF ( nonHydrostatic ) THEN |
|
|
C-- Step forward W field in N-H algorithm |
|
|
CALL TIMER_START('CALC_GW [SPIN-DOWN]',myThid) |
|
|
CALL CALC_GW( myThid) |
|
|
CALL TIMER_STOP ('CALC_GW [SPIN-DOWN]',myThid) |
|
|
ENDIF |
|
|
#endif |
|
|
|
|
|
C-- Do time averages |
|
|
#ifdef INCLUDE_DIAGNOSTICS_INTERFACE_CODE |
|
|
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 |
|
|
|
|
|
C-- Dump for end state |
|
|
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
|
|
CALL WRITE_STATE( .FALSE., myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
|
116 |
|
|
117 |
CALL TIMER_STOP ('SPIN-DOWN',myThid) |
CALL TIMER_STOP ('ALL [THE_MODEL_MAIN]',myThid) |
|
CALL TIMER_STOP ('ALL',myThid) |
|
118 |
|
|
119 |
C-- Write timer statistics |
C-- Write timer statistics |
120 |
IF ( myThid .EQ. 1 ) THEN |
IF ( myThid .EQ. 1 ) THEN |