/[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.28 by adcroft, Mon May 24 15:42:23 1999 UTC revision 1.39 by heimbach, Fri Jul 13 14:26:57 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 24  C     |      presently being developed. Line 25  C     |      presently being developed.
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  
# Line 101  C           myCurrentTime are local vari Line 50  C           myCurrentTime are local vari
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
       CHARACTER*(30) suff  
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    
61    
62        CALL TIMER_START('SPIN-UP',myThid)  C--   Set model configuration (fixed arrays)
63          CALL TIMER_START('INITIALISE_FIXED   [THE_MODEL_MAIN]',myThid)
64          CALL INITIALISE_FIXED( myThid )
65          CALL TIMER_STOP ('INITIALISE_FIXED   [THE_MODEL_MAIN]',myThid)
66    
 C--   Set model initial conditions  
       CALL TIMER_START('INITIALISE          [SPIN-UP]',myThid)  
       CALL INITIALISE( myThid )  
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  
   
 #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  
71    
72  C--    Do time averages        _BEGIN_MASTER( mythid )
73  #ifdef INCLUDE_DIAGNOSTICS_INTERFACE_CODE        IF (myProcId .eq. 0) THEN
74         CALL TIMER_START('I/O (WRITE)        [MAIN LOOP]',myThid)           CALL CTRL_UNPACK( mycurrentiter, mycurrenttime, 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)  
75        ENDIF        ENDIF
76  #endif        _END_MASTER( mythid )
77          _BARRIER
 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)  
78    
79  #ifdef ALLOW_NONHYDROSTATIC        fc   = 0.0
80        IF ( nonHydrostatic ) THEN        adfc = 1.0
81  C--    Step forward W field in N-H algorithm        CALL TIMER_START('ADTHE_MAIN_LOOP          [ADJOINT RUN]', mythid)
82         CALL TIMER_START('CALC_GW            [SPIN-DOWN]',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            [SPIN-DOWN]',myThid)        _BARRIER
85    
86          _BEGIN_MASTER( mythid )
87          IF (myProcId .eq. 0) THEN
88             call CTRL_PACK( mycurrentiter, mycurrenttime, mythid )
89        ENDIF        ENDIF
90  #endif        _END_MASTER( mythid )
91          _BARRIER
92    
93  C--   Do time averages  #ifdef ALLOW_GRADIENT_CHECK
94  #ifdef ALLOW_DIAGNOSTICS        if (useGrdchk) then
95        IF (taveFreq.GT.0.) THEN           CALL TIMER_START('GRDCHK_MAIN          [ADJOINT RUN]', mythid)
96         CALL TIMER_START('I/O (WRITE)        [SPIN-DOWN]',myThid)           CALL GRDCHK_MAIN( mythid )
97         CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid )           CALL TIMER_STOP ('GRDCHK_MAIN          [ADJOINT RUN]', mythid)
98         CALL TIMER_STOP ('I/O (WRITE)        [SPIN-DOWN]',myThid)           _BARRIER
99        ENDIF        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    #endif /* ALLOW_ADJOINT_RUN */
110    
111  C--   Dump for end state  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 WRITE_STATE( .FALSE., myCurrentTime, myCurrentIter, myThid )        CALL WRITE_CHECKPOINT(
114        CALL TIMER_STOP ('I/O (WRITE)         [SPIN-DOWN]',myThid)       &        .TRUE., myCurrentTime, myCurrentIter, myThid )
115          CALL TIMER_STOP ('WRITE_CHECKPOINT   [THE_MODEL_MAIN]',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

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.39

  ViewVC Help
Powered by ViewVC 1.1.22