/[MITgcm]/MITgcm/model/src/the_model_main.F
ViewVC logotype

Diff of /MITgcm/model/src/the_model_main.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.25 by adcroft, Fri Mar 12 16:44:04 1999 UTC revision 1.38 by heimbach, Tue Apr 10 22:35:26 2001 UTC
# Line 1  Line 1 
1  C $Header$  C $Header$
2    C $Name$
3    
4  #include "CPP_OPTIONS.h"  #include "CPP_OPTIONS.h"
5    
# Line 43  C       |  |               of this codes Line 44  C       |  |               of this codes
44  C       |  |               and/or instance. Each instance manages  C       |  |               and/or instance. Each instance manages
45  C       |  |               a specifc set of tiles.                C       |  |               a specifc set of tiles.              
46  C       |  |  C       |  |
47  C       |  |--INITIALISE  C       |  |--INITIALISE_FIXED
48  C       |  |   o Set initial conditions and model configuration  C       |  |   o Set model configuration (fixed arrays)
49  C       |  |     Topography, hydrography, timestep, grid, etc..  C       |  |     Topography, hydrography, timestep, grid, etc..
50  C       |  |  C       |  |
51  C  ==>  |  | ** Time stepping loop starts here **  C       |  |--THE_MAIN_LOOP
52  C  |    |  |  C       |  |  |
53  C /|\   |  |  C       |  |  |--INITIALISE_VARIA
54  C  |    |  |--LOAD_EXTERNAL_DATA  C       |  |  |   o Set initial conditions (variable arrays)
55  C /|\   |  |   o Load and/or set time dependent forcing fields  C       |  |  |
56  C  |    |  |  C  ==>  |  |  | ** Time stepping loop starts here **
57  C /|\   |  |--DYNAMICS  C  |    |  |  |
58  C  |    |  |   o Evaluate "forward" terms  C /|\   |  |  |
59  C /|\   |  |  C  |    |  |  |--FORWARD_STEP
60  C  |    |  |--DO_THE_MODEL_IO  C /|\   |  |  |  |  o Does a single forward step of the model
61  C /|\   |  |   o Write model state  C  |    |  |  |  |
62  C  |    |  |  C /|\   |  |  |  |
63  C /|\   |  |--SOLVE_FOR_PRESSURE  C  |    |  |  |  |--LOAD_EXTERNAL_DATA
64  C  |    |  |   o Find pressure field to keep flow non-divergent  C /|\   |  |  |  |   o Load and/or set time dependent forcing fields
65  C /|\   |  |  C  |    |  |  |  |
66  C  |    |  |--DO_GTERM_BLOCKING_EXCHANGES  C /|\   |  |  |  |--DYNAMICS
67  C /|\   |  |   o Update overlap regions  C  |    |  |  |  |   o Evaluate "forward" terms
68  C  |    |  |  C /|\   |  |  |  |
69  C /|\   |  |--WRITE_CHECKPOINT  C  |    |  |  |  |--SOLVE_FOR_PRESSURE
70  C  |    |  |   o Write restart file(s)  C /|\   |  |  |  |   o Find pressure field to keep flow non-divergent
71  C /|\   |  |  C  |    |  |  |  |
72  C  |    |  |  C /|\   |  |  |  |--THE_CORRECTION_STEP
73  C  |<== |  | ** Time stepping loop finishes here **  C  |    |  |  |  |   o Correct flow field with and cycle time-stepping arrays
74    C /|\   |  |  |  |
75    C  |    |  |  |  |--DO_GTERM_BLOCKING_EXCHANGES
76    C /|\   |  |  |  |   o Update overlap regions
77    C  |    |  |  |  |
78    C /|\   |  |  |  |--DO_THE_MODEL_IO
79    C  |    |  |  |  |   o Write model state
80    C /|\   |  |  |  |
81    C  |    |  |  |  |--WRITE_CHECKPOINT
82    C /|\   |  |  |  |   o Write restart file(s)
83    C  |    |  |  |
84    C /|\   |  |  |
85    C  |<== |  |  | ** Time stepping loop finishes here **
86    C       |  |  |
87    C       |  |  |--
88  C       |  |  C       |  |
89  C       |  |--WRITE_STATE  C       |  |--WRITE_STATE
90  C       |  |--WRITE_CHECKPOINT  C       |  |--WRITE_CHECKPOINT
# Line 85  C     == Global variables === Line 100  C     == Global variables ===
100  #include "SIZE.h"  #include "SIZE.h"
101  #include "EEPARAMS.h"  #include "EEPARAMS.h"
102  #include "PARAMS.h"  #include "PARAMS.h"
 #include "CG2D.h"  
103  #include "DYNVARS.h"  #include "DYNVARS.h"
104    #ifdef ALLOW_NONHYDROSTATIC
105    #include "CG3D.h"
106    #endif
107    
108    #ifdef ALLOW_AUTODIFF_TAMC
109    #include "tamc.h"
110    #include "cost.h"
111    #include "adcost.h"
112    #endif
113    
114  C     == Routine arguments ==  C     == Routine arguments ==
115  C     myThid - Thread number for this instance of the routine.  C     myThid - Thread number for this instance of the routine.
# Line 98  C           myCurrentTime are local vari Line 121  C           myCurrentTime are local vari
121  C           arguments. Although this is fiddly it saves the need to  C           arguments. Although this is fiddly it saves the need to
122  C           impose additional synchronisation points when they are  C           impose additional synchronisation points when they are
123  C           updated.  C           updated.
 C     myCurrentIter - Iteration counter for this thread  
124  C     myCurrentTime - Time counter for this thread  C     myCurrentTime - Time counter for this thread
125  C     I             - Loop counter  C     myCurrentIter - Iteration counter for this thread
126        INTEGER I, myCurrentIter        INTEGER myCurrentIter
127        REAL    myCurrentTime        _RL     myCurrentTime
128    
129  C--   This timer encompasses the whole code  C--   This timer encompasses the whole code
130        CALL TIMER_START('ALL',myThid)        CALL TIMER_START('ALL                [THE_MODEL_MAIN]',myThid)
131    
132    
133        CALL TIMER_START('SPIN-UP',myThid)  C--   Set model configuration (fixed arrays)
134          CALL TIMER_START('INITIALISE_FIXED   [THE_MODEL_MAIN]',myThid)
135          CALL INITIALISE_FIXED( myThid )
136          CALL TIMER_STOP ('INITIALISE_FIXED   [THE_MODEL_MAIN]',myThid)
137    
 C--   Set model initial conditions  
       CALL TIMER_START('INITIALISE          [SPIN-UP]',myThid)  
       CALL INITIALISE( myThid )  
138        myCurrentTime = startTime        myCurrentTime = startTime
139        myCurrentIter = nIter0        myCurrentIter = nIter0
       CALL TIMER_STOP ('INITIALISE          [SPIN-UP]',myThid)  
   
 C--   Dump for start state  
       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  
140    
141  C--    Set Open Boundaries Values  #ifdef ALLOW_MIT_ADJOINT_RUN
        IF (openBoundaries) THEN  
         CALL TIMER_START('OBCS               [MAIN LOOP]',myThid)  
         CALL SET_OBCS( myCurrentTime, myThid )  
         CALL TIMER_STOP ('OBCS               [MAIN LOOP]',myThid)  
        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)  
   
 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)  
142    
143  C--   Final checkpoint (incase the in-loop checkpoint was missed)        _BEGIN_MASTER( mythid )
144        CALL TIMER_START('I/O (WRITE)         [SPIN-DOWN]',myThid)        IF (myProcId .eq. 0) THEN
145        CALL           CALL CTRL_UNPACK( mycurrentiter, mycurrenttime, mythid )
      & WRITE_CHECKPOINT( .TRUE., myCurrentTime, myCurrentIter, 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)  
146        ENDIF        ENDIF
147          _END_MASTER( mythid )
148          _BARRIER
149    
150  C--   Step-forward U/V/Theta/Salt for purposes of final I/O dump        fc   = 0.0
151        CALL TIMER_START('DYNAMICS            [SPIN-DOWN]',myThid)        adfc = 1.0
152        CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid )        CALL TIMER_START('ADTHE_MAIN_LOOP          [ADJOINT RUN]', mythid)
153        CALL TIMER_STOP ('DYNAMICS            [SPIN-DOWN]',myThid)        call ADTHE_MAIN_LOOP ( mythid )
154          call TIMER_STOP ('ADTHE_MAIN_LOOP          [ADJOINT RUN]', mythid)
155  C--   Do time averages        _BARRIER
156  #ifdef ALLOW_DIAGNOSTICS  
157        IF (taveFreq.GT.0.) THEN        _BEGIN_MASTER( mythid )
158         CALL TIMER_START('I/O (WRITE)        [SPIN-DOWN]',myThid)        IF (myProcId .eq. 0) THEN
159         CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid )           call CTRL_PACK( mycurrentiter, mycurrenttime, mythid )
        CALL TIMER_STOP ('I/O (WRITE)        [SPIN-DOWN]',myThid)  
160        ENDIF        ENDIF
161  #endif        _END_MASTER( mythid )
162          _BARRIER
163    
164  C--   Dump for end state  #else /* ALLOW_MIT_ADJOINT_RUN undef */
165        CALL TIMER_START('I/O (WRITE)         [SPIN-DOWN]',myThid)  
166        CALL WRITE_STATE( .FALSE., myCurrentTime, myCurrentIter, myThid )  C--   Call time stepping loop of full model
167        CALL TIMER_STOP ('I/O (WRITE)         [SPIN-DOWN]',myThid)        CALL TIMER_START('THE_MAIN_LOOP      [THE_MODEL_MAIN]',myThid)
168          CALL THE_MAIN_LOOP(myCurrentTime, myCurrentIter, myThid )
169          CALL TIMER_STOP ('THE_MAIN_LOOP      [THE_MODEL_MAIN]',myThid)
170    
171    #endif /* ALLOW_MIT_ADJOINT_RUN */
172    
173    C--   Final checkpoint (incase the in-loop checkpoint was missed)
174          CALL TIMER_START('WRITE_CHECKPOINT   [THE_MODEL_MAIN]',myThid)
175          CALL WRITE_CHECKPOINT(
176         &        .TRUE., myCurrentTime, myCurrentIter, myThid )
177          CALL TIMER_STOP ('WRITE_CHECKPOINT   [THE_MODEL_MAIN]',myThid)
178    
179        CALL TIMER_STOP ('SPIN-DOWN',myThid)        CALL TIMER_STOP ('ALL                [THE_MODEL_MAIN]',myThid)
       CALL TIMER_STOP ('ALL',myThid)  
180    
181  C--   Write timer statistics  C--   Write timer statistics
182        IF ( myThid .EQ. 1 ) THEN        IF ( myThid .EQ. 1 ) THEN

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.38

  ViewVC Help
Powered by ViewVC 1.1.22