Back to home page

MITgcm

 
 

    


File indexing completed on 2025-11-07 06:09:02 UTC

view on githubraw file Latest commit b7411f1a on 2025-11-06 19:05:26 UTC
279dc77b07 Patr*0001 #include "PACKAGES_CONFIG.h"
                0002 #include "OPENAD_OPTIONS.h"
                0003 
                0004       subroutine template()
                0005 #ifdef ALLOW_OPENAD_DIVA
                0006       use OAD_regular_cp
                0007       use OAD_tape
                0008       use OAD_rev
                0009 
                0010 c we may need these for the checkpointing
                0011       use SIZE_mod
                0012       use EEPARAMS_mod
                0013       use PARAMS_mod
                0014       use BAR2_mod
                0015       use BARRIER_mod
                0016 #ifdef ALLOW_CD_CODE
                0017       use CD_CODE_VARS_mod
                0018 #endif
                0019       use CG2D_mod
                0020       use CG3D_mod
                0021       use DYNVARS_mod
                0022       use EESUPPORT_mod
                0023       use EOS_mod
                0024       use EXCH_mod
                0025       use FC_NAMEMANGLE_mod
                0026       use FFIELDS_mod
                0027 #ifdef ALLOW_GENERIC_ADVDIFF
                0028       use GAD_mod
                0029 #endif
                0030       use GLOBAL_MAX_mod
                0031       use GLOBAL_SUM_mod
                0032 #ifdef ALLOW_GMREDI
                0033       use GMREDI_mod
                0034 #endif
                0035       use GRID_mod
                0036 #ifdef ALLOW_MOM_COMMON
                0037       use MOM_VISC_mod
                0038 #endif
                0039       use MPI_INFO_mod
                0040 #ifdef ALLOW_SHAP_FILT
                0041       use SHAP_FILT_mod
                0042 #endif
                0043 #ifdef ALLOW_STREAMICE
                0044       use STREAMICE_mod
                0045       use STREAMICE_ADV_mod
                0046       use STREAMICE_BDRY_mod
                0047       use STREAMICE_CG_mod
                0048 #endif
                0049       use SURFACE_mod
                0050       use cost_mod
                0051       use g_cost_mod
4d72283393 Mart*0052       use CTRL_mod
edcd27be69 Mart*0053       use CTRL_DUMMY_mod
65754df434 Mart*0054       use OPTIMCYCLE_mod
444da61630 Mart*0055       use GRDCHK_mod
7c50f07931 Mart*0056 
279dc77b07 Patr*0057 !$TEMPLATE_PRAGMA_DECLARATIONS
                0058       integer, save :: currcp, curradjointcp
                0059       integer :: cp_loop_variable_1,cp_loop_variable_2,
                0060      +     cp_loop_variable_3,cp_loop_variable_4,cp_loop_variable_5
                0061 
                0062       double precision, dimension(:), allocatable, save :: theArgFStack
                0063       integer, save :: theArgFStackoffset=0, theArgFStackSize=0
                0064       integer, dimension(:), allocatable, save :: theArgIStack
                0065       integer, save :: theArgIStackoffset=0, theArgIStackSize=0
                0066       type(modeType) :: our_orig_mode
                0067       integer nt
                0068 
                0069       integer iaddr
                0070       external iaddr
7c50f07931 Mart*0071       if (our_rev_mode%arg_store) then
279dc77b07 Patr*0072         call cp_write_open()
                0073 !$PLACEHOLDER_PRAGMA$ id=8
                0074         call cp_close()
7c50f07931 Mart*0075       end if
279dc77b07 Patr*0076       if (our_rev_mode%arg_restore) then
                0077         call cp_read_open()
                0078 !$PLACEHOLDER_PRAGMA$ id=9
                0079         call cp_close()
                0080       end if
                0081       if (our_rev_mode%plain) then
                0082         do nt=1,nTimeSteps_l2
                0083           CALL OpenAD_inner_do_loop(nt, MYTIME, MYITER, MYTHID)
                0084         enddo
                0085       end if
                0086       if (our_rev_mode%tape) then
                0087         print *, 'DIVA Running Regular Plain nTimeSteps_l2 ', nTimeSteps
                0088      +_l2
                0089         currcp = 0
                0090         do nt=1,nTimeSteps_l2
                0091           print *, 'DIVA Checkpointing currcp  and running plain', currc
                0092      +p
                0093             call cp_write_open(currcp)
                0094 !$PLACEHOLDER_PRAGMA$ id=8
                0095             call cp_close
                0096             currcp=currcp+1
                0097           call OAD_revPlain
                0098           CALL OpenAD_inner_do_loop(nt, MYTIME, MYITER, MYTHID)
                0099           call OAD_revTape
                0100         end do
                0101         currcp = currcp -1
                0102       end if
                0103       if (our_rev_mode%adjoint) then
                0104         curradjointcp = currcp
                0105         print *, 'DIVA Reading plain checkpoint currcp ', currcp
                0106         call cp_read_open(currcp)
                0107 !$PLACEHOLDER_PRAGMA$ id=9
                0108         call cp_close
                0109         call OAD_revTape
                0110         print *, 'DIVA Running First Tape'
                0111         CALL OpenAD_inner_do_loop(nTimeSteps_l2, MYTIME, MYITER, MYTHID)
                0112         print *, 'DIVA Running First Adjoint '
                0113         call OAD_revAdjoint
                0114         CALL OpenAD_inner_do_loop(nTimeSteps_l2, MYTIME, MYITER, MYTHID)
                0115         print *, 'DIVA Writing adjoint checkpoint curradjointcp ', curra
                0116      +djointcp
                0117         call cp_write_open(curradjointcp)
                0118 !$PLACEHOLDER_PRAGMA$ id=12
                0119         call cp_close
                0120         do nt=nTimeSteps_l2-1,1,-1
                0121           currcp = currcp -1
                0122           print *, 'DIVA Running TA pairs'
                0123           print *, 'DIVA Reading plain checkpoint currcp ', currcp
                0124           call cp_read_open(currcp)
                0125 !$PLACEHOLDER_PRAGMA$ id=9
                0126           call cp_close
                0127           call OAD_revTape
                0128           print *, 'DIVA Running Tape'
                0129           CALL OpenAD_inner_do_loop(nt, MYTIME, MYITER, MYTHID)
                0130           print *, 'DIVA Reading adjoint checkpoint curradjointcp ', cur
                0131      +radjointcp
                0132           call cp_read_open(curradjointcp)
                0133 !$PLACEHOLDER_PRAGMA$ id=13
                0134           call cp_close
                0135           print *, 'DIVA Running adjoint '
                0136           call OAD_revAdjoint
                0137           CALL OpenAD_inner_do_loop(nt, MYTIME, MYITER, MYTHID)
                0138           print *, 'DIVA Writing adjoint checkpoint curradjointcp ', cur
                0139      +radjointcp-1
                0140          call cp_write_open(curradjointcp-1)
                0141 !$PLACEHOLDER_PRAGMA$ id=12
                0142           curradjointcp = curradjointcp-1
                0143           call cp_close
                0144         end do
                0145       end if
                0146 #endif
                0147       end subroutine template