1 |
C $Header$ |
C $Header$ |
2 |
C $Name$ |
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 |
|
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_FIXED |
|
|
C | | o Set model configuration (fixed arrays) |
|
|
C | | Topography, hydrography, timestep, grid, etc.. |
|
|
C | | |
|
|
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 |
|
|
C | |
|
|
C . |
|
|
C . |
|
|
C . Generic environment termination ( see eesupp/src and |
|
|
C . eesupp/inc ) |
|
|
C . |
|
|
C . |
|
29 |
|
|
30 |
|
C !DESCRIPTION: \bv |
31 |
|
C *==========================================================* |
32 |
|
C | SUBROUTINE THE_MODEL_MAIN |
33 |
|
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 | |
60 |
|
C |--CTRL_UNPACK o Derivative mode. Unpack control vector. |
61 |
|
C | |
62 |
|
C |--ADTHE_MAIN_LOOP o Main timestepping loop for combined |
63 |
|
C | prognostic and reverse mode integration. |
64 |
|
C | |
65 |
|
C |--CTRL_PACK o Derivative mode. Unpack control vector. |
66 |
|
C | |
67 |
|
C |--GRDCHK_MAIN o Gradient check control routine. |
68 |
|
C | |
69 |
|
C |--THE_MAIN_LOOP o Main timestepping loop for pure prognostic |
70 |
|
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" |
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 |
107 |
C myCurrentIter - Iteration counter for this thread |
C myCurrentIter - Iteration counter for this thread |
108 |
INTEGER myCurrentIter |
INTEGER myCurrentIter |
109 |
_RL myCurrentTime |
_RL myCurrentTime |
110 |
|
CEOP |
111 |
|
|
112 |
C-- This timer encompasses the whole code |
C-- This timer encompasses the whole code |
113 |
CALL TIMER_START('ALL [THE_MODEL_MAIN]',myThid) |
CALL TIMER_START('ALL [THE_MODEL_MAIN]',myThid) |
118 |
CALL INITIALISE_FIXED( myThid ) |
CALL INITIALISE_FIXED( myThid ) |
119 |
CALL TIMER_STOP ('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) |
CALL TIMER_STOP ('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) |
120 |
|
|
|
|
|
121 |
myCurrentTime = startTime |
myCurrentTime = startTime |
122 |
myCurrentIter = nIter0 |
myCurrentIter = nIter0 |
123 |
|
|
124 |
|
#if ( defined (ALLOW_ADJOINT_RUN) || \ |
125 |
|
defined (ALLOW_GRADIENT_CHECK) || \ |
126 |
|
defined (ALLOW_ECCO_OPTIMIZATION) ) |
127 |
|
|
128 |
|
_BEGIN_MASTER( mythid ) |
129 |
|
IF (myProcId .eq. 0) THEN |
130 |
|
CALL CTRL_UNPACK( mycurrentiter, mycurrenttime, mythid ) |
131 |
|
ENDIF |
132 |
|
_END_MASTER( mythid ) |
133 |
|
_BARRIER |
134 |
|
|
135 |
|
fc = 0.0 |
136 |
|
adfc = 1.0 |
137 |
|
CALL TIMER_START('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) |
138 |
|
CALL ADTHE_MAIN_LOOP ( mythid ) |
139 |
|
CALL TIMER_STOP ('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid) |
140 |
|
_BARRIER |
141 |
|
|
142 |
|
_BEGIN_MASTER( mythid ) |
143 |
|
IF (myProcId .eq. 0) THEN |
144 |
|
call CTRL_PACK( mycurrentiter, mycurrenttime, mythid ) |
145 |
|
ENDIF |
146 |
|
_END_MASTER( mythid ) |
147 |
|
_BARRIER |
148 |
|
|
149 |
|
#ifdef ALLOW_GRADIENT_CHECK |
150 |
|
if (useGrdchk) then |
151 |
|
CALL TIMER_START('GRDCHK_MAIN [ADJOINT RUN]', mythid) |
152 |
|
CALL GRDCHK_MAIN( mythid ) |
153 |
|
CALL TIMER_STOP ('GRDCHK_MAIN [ADJOINT RUN]', mythid) |
154 |
|
_BARRIER |
155 |
|
end if |
156 |
|
#endif |
157 |
|
|
158 |
|
#else /* ALLOW_ADJOINT_RUN undef */ |
159 |
|
|
160 |
C-- Call time stepping loop of full model |
C-- Call time stepping loop of full model |
161 |
CALL TIMER_START('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
CALL TIMER_START('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
162 |
CALL THE_MAIN_LOOP(myCurrentTime, myCurrentIter, myThid ) |
CALL THE_MAIN_LOOP(myCurrentTime, myCurrentIter, myThid ) |
163 |
CALL TIMER_STOP ('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
CALL TIMER_STOP ('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid) |
164 |
|
|
165 |
|
#endif /* ALLOW_ADJOINT_RUN */ |
166 |
|
|
167 |
|
C-- Final checkpoint (incase the in-loop checkpoint was missed) |
168 |
|
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 ('ALL [THE_MODEL_MAIN]',myThid) |
CALL TIMER_STOP ('ALL [THE_MODEL_MAIN]',myThid) |
174 |
|
|