1 |
C $Header$ |
C $Header$ |
2 |
|
C $Name$ |
3 |
|
|
4 |
|
CBOI |
5 |
|
C |
6 |
|
C !TITLE: MITGCM KERNEL CODE SYNOPSIS |
7 |
|
C !AUTHORS: mitgcm developers ( support@mitgcm.org ) |
8 |
|
C !AFFILIATION: Massachussetts Institute of Technology |
9 |
|
C !DATE: |
10 |
|
C !INTRODUCTION: model/ subdirectory |
11 |
|
C Routines in the subdirectories under model/ ( src/ and inc/ ) are most of |
12 |
|
C the core routines for the baseline forms of the kernel equations in the |
13 |
|
C MITgcm algorithm. |
14 |
|
C Code for auxilliary equations and alternate dicretizations of the fundamental |
15 |
|
C equations can be found in the pkg/ directory tree. |
16 |
|
C |
17 |
|
CEOI |
18 |
|
|
19 |
|
|
20 |
#include "CPP_OPTIONS.h" |
#include "CPP_OPTIONS.h" |
21 |
|
|
22 |
|
CBOP |
23 |
|
|
24 |
|
C !ROUTINE: THE_MODEL_MAIN |
25 |
|
|
26 |
|
C !INTERFACE: |
27 |
SUBROUTINE THE_MODEL_MAIN(myThid) |
SUBROUTINE THE_MODEL_MAIN(myThid) |
|
C /==========================================================\ |
|
|
C | SUBROUTINE THE_MODEL_MAIN | |
|
|
C | o Master controlling routine for model using the MITgcm | |
|
|
C | UV parallel wrapper. | |
|
|
C |==========================================================| |
|
|
C | THE_MODEL_MAIN is invoked by the MITgcm UV parallel | |
|
|
C | wrapper with a single integer argument "myThid". This | |
|
|
C | variable identifies the thread number of an instance of | |
|
|
C | THE_MODEL_MAIN. Each instance of THE_MODEL_MAIN works | |
|
|
C | on a particular region of the models domain and | |
|
|
C | synchronises with other instances as necessary. The | |
|
|
C | routine has to "understand" the MITgcm parallel | |
|
|
C | environment and the numerical algorithm. Editing this | |
|
|
C | routine is best done with some knowledge of both aspects.| |
|
|
C | Notes | |
|
|
C | ===== | |
|
|
C | C*P* comments indicating place holders for which code is | |
|
|
C | presently being developed. | |
|
|
C \==========================================================/ |
|
28 |
IMPLICIT NONE |
IMPLICIT NONE |
29 |
C |
|
30 |
C Call Tree |
C !DESCRIPTION: \bv |
31 |
C ========= |
C *==========================================================* |
32 |
C |
C | SUBROUTINE THE_MODEL_MAIN |
33 |
C main ( eesupp ) |
C | o Master controlling routine for model using the MITgcm |
34 |
|
C | UV parallel wrapper. |
35 |
|
C *==========================================================* |
36 |
|
C | THE_MODEL_MAIN is invoked by the MITgcm UV parallel |
37 |
|
C | wrapper with a single integer argument "myThid". This |
38 |
|
C | variable identifies the thread number of an instance of |
39 |
|
C | THE_MODEL_MAIN. Each instance of THE_MODEL_MAIN works |
40 |
|
C | on a particular region of the models domain and |
41 |
|
C | synchronises with other instances as necessary. The |
42 |
|
C | routine has to "understand" the MITgcm parallel |
43 |
|
C | environment and the numerical algorithm. Editing this |
44 |
|
C | routine is best done with some knowledge of both aspects. |
45 |
|
C | Notes |
46 |
|
C | ===== |
47 |
|
C | C*P* comments indicating place holders for which code is |
48 |
|
C | presently being developed. |
49 |
|
C *==========================================================* |
50 |
|
C \ev |
51 |
|
|
52 |
|
C !CALLING SEQUENCE: |
53 |
|
C THE_MODEL_MAIN() |
54 |
|
C | |
55 |
|
C | |
56 |
|
C |--INITIALISE_FIXED |
57 |
|
C | o Set model configuration (fixed arrays) |
58 |
|
C | Topography, hydrography, timestep, grid, etc.. |
59 |
C | |
C | |
60 |
C . |
C |--CTRL_UNPACK o Derivative mode. Unpack control vector. |
|
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 . |
|
61 |
C | |
C | |
62 |
C |-THE_MODEL_MAIN - Begin specific model. One instance |
C |--ADTHE_MAIN_LOOP o Main timestepping loop for combined |
63 |
C | | of this codes exists for each thread |
C | prognostic and reverse mode integration. |
|
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 |
|
64 |
C | |
C | |
65 |
C . |
C |--CTRL_PACK o Derivative mode. Unpack control vector. |
66 |
C . |
C | |
67 |
C . Generic environment termination ( see eesupp/src and |
C |--GRDCHK_MAIN o Gradient check control routine. |
68 |
C . eesupp/inc ) |
C | |
69 |
C . |
C |--THE_MAIN_LOOP o Main timestepping loop for pure prognostic |
70 |
C . |
C | integration. |
71 |
|
C | |
72 |
|
C |--WRITE_CHECKPOINT o Write retsart information. |
73 |
|
C | |
74 |
|
C |--TIMER_PRINTALL o Print out timing statistics. |
75 |
|
C | |
76 |
|
C |--COMM_STATS o Print out communication statistics. |
77 |
|
|
78 |
|
C !USES: |
79 |
C == Global variables === |
C == Global variables === |
80 |
#include "SIZE.h" |
#include "SIZE.h" |
81 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
82 |
#include "PARAMS.h" |
#include "PARAMS.h" |
83 |
#include "DYNVARS.h" |
#include "DYNVARS.h" |
|
#include "CG2D.h" |
|
84 |
#ifdef ALLOW_NONHYDROSTATIC |
#ifdef ALLOW_NONHYDROSTATIC |
85 |
#include "CG3D.h" |
#include "CG3D.h" |
86 |
#endif |
#endif |
87 |
|
|
88 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
89 |
|
#include "tamc.h" |
90 |
|
#include "cost.h" |
91 |
|
#include "adcost.h" |
92 |
|
#endif |
93 |
|
|
94 |
|
C !INPUT/OUTPUT PARAMETERS: |
95 |
C == Routine arguments == |
C == Routine arguments == |
96 |
C myThid - Thread number for this instance of the routine. |
C myThid - Thread number for this instance of the routine. |
97 |
INTEGER myThid |
INTEGER myThid |
98 |
|
|
99 |
|
C !LOCAL VARIABLES: |
100 |
C == Local variables == |
C == Local variables == |
101 |
C Note: Under the multi-threaded model myCurrentIter and |
C Note: Under the multi-threaded model myCurrentIter and |
102 |
C myCurrentTime are local variables passed around as routine |
C myCurrentTime are local variables passed around as routine |
103 |
C arguments. Although this is fiddly it saves the need to |
C arguments. Although this is fiddly it saves the need to |
104 |
C impose additional synchronisation points when they are |
C impose additional synchronisation points when they are |
105 |
C updated. |
C updated. |
|
C myCurrentIter - Iteration counter for this thread |
|
106 |
C myCurrentTime - Time counter for this thread |
C myCurrentTime - Time counter for this thread |
107 |
C I - Loop counter |
C myCurrentIter - Iteration counter for this thread |
108 |
INTEGER I, myCurrentIter |
INTEGER myCurrentIter |
109 |
REAL myCurrentTime |
_RL myCurrentTime |
110 |
CHARACTER*(30) suff |
CEOP |
111 |
|
|
112 |
C-- This timer encompasses the whole code |
C-- This timer encompasses the whole code |
113 |
CALL TIMER_START('ALL',myThid) |
CALL TIMER_START('ALL [THE_MODEL_MAIN]',myThid) |
114 |
|
|
115 |
|
|
116 |
CALL TIMER_START('SPIN-UP',myThid) |
C-- Set model configuration (fixed arrays) |
117 |
|
CALL TIMER_START('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) |
118 |
|
CALL INITIALISE_FIXED( myThid ) |
119 |
|
CALL TIMER_STOP ('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) |
120 |
|
|
|
C-- Set model initial conditions |
|
|
CALL TIMER_START('INITIALISE [SPIN-UP]',myThid) |
|
|
CALL INITIALISE( myThid ) |
|
121 |
myCurrentTime = startTime |
myCurrentTime = startTime |
122 |
myCurrentIter = nIter0 |
myCurrentIter = nIter0 |
|
CALL TIMER_STOP ('INITIALISE [SPIN-UP]',myThid) |
|
123 |
|
|
124 |
C-- Dump for start state |
#if ( defined (ALLOW_ADJOINT_RUN) || \ |
125 |
CALL TIMER_START('I/O (WRITE) [SPIN-UP]',myThid) |
defined (ALLOW_GRADIENT_CHECK) || \ |
126 |
CALL WRITE_STATE( .TRUE., myCurrentTime, myCurrentIter, myThid ) |
defined (ALLOW_ECCO_OPTIMIZATION) ) |
127 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-UP]',myThid) |
|
128 |
|
_BEGIN_MASTER( mythid ) |
129 |
CALL TIMER_STOP ('SPIN-UP',myThid) |
IF (myProcId .eq. 0) THEN |
130 |
|
CALL CTRL_UNPACK( mycurrentiter, mycurrenttime, 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 |
|
|
|
|
|
#ifdef ALLOW_OBCS |
|
|
C-- Set Open Boundaries Values |
|
|
IF (openBoundaries) THEN |
|
|
CALL TIMER_START('OBCS [MAIN LOOP]',myThid) |
|
|
CALL SET_OBCS( myCurrentTime, myThid ) |
|
|
CALL TIMER_STOP ('OBCS [MAIN LOOP]',myThid) |
|
|
ENDIF |
|
|
#endif |
|
|
|
|
|
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) |
|
|
|
|
|
#ifdef ALLOW_NONHYDROSTATIC |
|
|
C-- Step forward W field in N-H algorithm |
|
|
IF ( nonHydrostatic ) THEN |
|
|
CALL TIMER_START('CALC_GW [MAIN LOOP]',myThid) |
|
|
CALL CALC_GW( myThid) |
|
|
CALL TIMER_STOP ('CALC_GW [MAIN LOOP]',myThid) |
|
|
ENDIF |
|
|
#endif |
|
|
|
|
|
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) |
|
|
#endif |
|
|
|
|
|
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 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) |
|
|
|
|
|
C-- Final checkpoint (incase the in-loop checkpoint was missed) |
|
|
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
|
|
CALL |
|
|
& WRITE_CHECKPOINT( .TRUE., myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
|
|
|
|
|
#ifdef ALLOW_OBCS |
|
|
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) |
|
131 |
ENDIF |
ENDIF |
132 |
#endif |
_END_MASTER( mythid ) |
133 |
|
_BARRIER |
134 |
|
|
135 |
C-- Step-forward U/V/Theta/Salt for purposes of final I/O dump |
fc = 0.0 |
136 |
CALL TIMER_START('DYNAMICS [SPIN-DOWN]',myThid) |
adfc = 1.0 |
137 |
CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) |
CALL TIMER_START('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) |
138 |
CALL TIMER_STOP ('DYNAMICS [SPIN-DOWN]',myThid) |
CALL ADTHE_MAIN_LOOP ( mythid ) |
139 |
|
CALL TIMER_STOP ('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) |
140 |
#ifdef ALLOW_NONHYDROSTATIC |
_BARRIER |
141 |
IF ( nonHydrostatic ) THEN |
|
142 |
C-- Step forward W field in N-H algorithm |
_BEGIN_MASTER( mythid ) |
143 |
CALL TIMER_START('CALC_GW [SPIN-DOWN]',myThid) |
IF (myProcId .eq. 0) THEN |
144 |
CALL CALC_GW( myThid) |
call CTRL_PACK( mycurrentiter, mycurrenttime, mythid ) |
|
CALL TIMER_STOP ('CALC_GW [SPIN-DOWN]',myThid) |
|
145 |
ENDIF |
ENDIF |
146 |
#endif |
_END_MASTER( mythid ) |
147 |
|
_BARRIER |
148 |
|
|
149 |
C-- Do time averages |
#ifdef ALLOW_GRADIENT_CHECK |
150 |
#ifdef ALLOW_DIAGNOSTICS |
if (useGrdchk) then |
151 |
IF (taveFreq.GT.0.) THEN |
CALL TIMER_START('GRDCHK_MAIN [ADJOINT RUN]', mythid) |
152 |
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
CALL GRDCHK_MAIN( mythid ) |
153 |
CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid ) |
CALL TIMER_STOP ('GRDCHK_MAIN [ADJOINT RUN]', mythid) |
154 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
_BARRIER |
155 |
ENDIF |
end if |
156 |
#endif |
#endif |
157 |
|
|
158 |
|
#else /* ALLOW_ADJOINT_RUN undef */ |
159 |
|
|
160 |
|
C-- Call time stepping loop of full model |
161 |
|
CALL TIMER_START('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
162 |
|
CALL THE_MAIN_LOOP(myCurrentTime, myCurrentIter, myThid ) |
163 |
|
CALL TIMER_STOP ('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
164 |
|
|
165 |
C-- Dump for end state |
#endif /* ALLOW_ADJOINT_RUN */ |
166 |
CALL TIMER_START('I/O (WRITE) [SPIN-DOWN]',myThid) |
|
167 |
CALL WRITE_STATE( .FALSE., myCurrentTime, myCurrentIter, myThid ) |
C-- Final checkpoint (incase the in-loop checkpoint was missed) |
168 |
CALL TIMER_STOP ('I/O (WRITE) [SPIN-DOWN]',myThid) |
CALL TIMER_START('WRITE_CHECKPOINT [THE_MODEL_MAIN]',myThid) |
169 |
|
CALL WRITE_CHECKPOINT( |
170 |
|
& .TRUE., myCurrentTime, myCurrentIter, myThid ) |
171 |
|
CALL TIMER_STOP ('WRITE_CHECKPOINT [THE_MODEL_MAIN]',myThid) |
172 |
|
|
173 |
CALL TIMER_STOP ('SPIN-DOWN',myThid) |
CALL TIMER_STOP ('ALL [THE_MODEL_MAIN]',myThid) |
|
CALL TIMER_STOP ('ALL',myThid) |
|
174 |
|
|
175 |
C-- Write timer statistics |
C-- Write timer statistics |
176 |
IF ( myThid .EQ. 1 ) THEN |
IF ( myThid .EQ. 1 ) THEN |