/[MITgcm]/MITgcm/tools/OAD_support/ad_template.revolve.F
ViewVC logotype

Annotation of /MITgcm/tools/OAD_support/ad_template.revolve.F

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


Revision 1.3 - (hide annotations) (download)
Fri Jun 21 16:14:04 2013 UTC (10 years, 10 months ago) by heimbach
Branch: MAIN
Changes since 1.2: +10 -0 lines
Slightly improved packaging

1 heimbach 1.3 #include "PACKAGES_CONFIG.h"
2    
3 utke 1.1 subroutine template()
4     use OAD_cp
5     use OAD_tape
6     use OAD_rev
7     use revolve
8    
9     c we may need these for the checkpointing
10     use SIZE_mod
11     use EEPARAMS_mod
12     use PARAMS_mod
13     use BAR2_mod
14     use BARRIER_mod
15 heimbach 1.3 #ifdef ALLOW_CD_CODE
16 utke 1.1 use CD_CODE_VARS_mod
17 heimbach 1.3 #endif
18 utke 1.1 use CG2D_mod
19     use CG3D_mod
20     use DYNVARS_mod
21     use EESUPPORT_mod
22     use EOS_mod
23     use EXCH_mod
24     use FC_NAMEMANGLE_mod
25     use FFIELDS_mod
26     use GAD_mod
27     use GLOBAL_MAX_mod
28     use GLOBAL_SUM_mod
29 heimbach 1.3 #ifdef ALLOW_GMREDI
30 utke 1.1 use GMREDI_mod
31     use GMREDI_TAVE_mod
32 heimbach 1.3 #endif
33 utke 1.1 use GRID_mod
34 heimbach 1.3 use MOM_VISC_mod
35 utke 1.1 use MPI_INFO_mod
36 heimbach 1.3 #ifdef ALLOW_SHAP_FILT
37     use SHAP_FILT_mod
38     #endif
39 utke 1.1 use SOLVE_FOR_PRESSURE3D_mod
40     use SOLVE_FOR_PRESSURE_mod
41     use SURFACE_mod
42     use tamc_mod
43     use tamc_keys_mod
44     use cost_mod
45     use g_cost_mod
46     use ctrl_mod
47     use ctrl_dummy_mod
48     use ctrl_weights_mod
49     use optim_mod
50     use grdchk_mod
51    
52     !$TEMPLATE_PRAGMA_DECLARATIONS
53     LOGICAL :: initialized=.FALSE.
54     TYPE(rvAction),save :: theAction
55 utke 1.2 CHARACTER(80) :: errorMsg
56 utke 1.1 integer, save :: jointCPCount
57     integer, save :: currIter
58    
59     integer :: cp_loop_variable_1,cp_loop_variable_2,
60     + cp_loop_variable_3,cp_loop_variable_4,cp_loop_variable_5
61    
62     type(modeType) :: our_orig_mode
63    
64     integer iaddr
65     external iaddr
66    
67     #ifdef OAD_DEBUG_JOINT
68     character*(80):: indentation='
69     + '
70     our_indent=our_indent+1
71    
72     write(standardmessageunit, '(A,A,A)', ADVANCE='NO')
73     +'OAD:',indentation(1:our_indent), 'enter __SRNAME__:'
74     call oad_dump_revmod(); call oad_dump_tapestats()
75     write(standardmessageunit,*)
76     #endif
77    
78     nIter0 = NINT( (startTime-baseTime)/deltaTClock )
79     if (our_rev_mode%arg_store) then
80     call cp_write_open()
81     #ifdef OAD_DEBUG_JOINT
82     write(standardmessageunit,'(A,A,A)')
83     +'OAD:',indentation(1:our_indent),
84     +' __SRNAME__: entering arg store'
85     #endif
86     !$PLACEHOLDER_PRAGMA$ id=8
87     call cp_close()
88     end if
89     if (our_rev_mode%arg_restore) then
90     #ifdef OAD_DEBUG_JOINT
91     write(standardmessageunit,'(A,A,A)')
92     +'OAD:',indentation(1:our_indent),
93     +' __SRNAME__: entering arg restore'
94     #endif
95     call cp_read_open()
96     !$PLACEHOLDER_PRAGMA$ id=9
97     call cp_close()
98     end if
99     if (our_rev_mode%plain) then
100     #ifdef OAD_DEBUG_JOINT
101     write(standardmessageunit,'(A,A,A)')
102     +'OAD:',indentation(1:our_indent),
103     +' __SRNAME__: run plain, down plain'
104     #endif
105     DO iloop = 1, nTimeSteps
106     CALL OpenAD_forward_step( iloop, mytime, myiter, mythid )
107     enddo
108     end if
109     if (our_rev_mode%tape) then
110     #ifdef OAD_DEBUG_JOINT
111     write(standardmessageunit,'(A,A,A)')
112     +'OAD:',indentation(1:our_indent),
113     +' __SRNAME__: run tape, down revolve until first U turn'
114     #endif
115     currIter=0
116     jointCPcount=cp_fNumber()
117     initialized=rvInit(nTimeSteps,120,
118     + errorMsg,theAction)
119     IF (.NOT.initialized) WRITE(*,'(A,A)') 'Error: ', errorMsg
120     do while (theAction%actionFlag/=rvDone)
121     theAction=rvNextAction()
122     select case (theAction%actionFlag)
123     case (rvStore)
124     call cp_write_open(theAction%cpNum+jointCPCount)
125     !$PLACEHOLDER_PRAGMA$ id=8
126     call cp_close
127     case (rvForward)
128     call OAD_revPlain
129     do currIter=currIter,theAction%iteration-1
130     CALL OpenAD_forward_step( currIter+1, mytime,
131     +myiter, mythid )
132     end do
133     call OAD_revTape
134     case (rvFirstUTurn)
135     CALL OpenAD_forward_step( currIter+1, mytime, myiter,
136     +mythid )
137     ! get out now ...
138     exit
139     end select
140     end do
141     end if
142     if (our_rev_mode%adjoint) then
143     IF (.NOT.initialized) WRITE(*,'(A)') 'Error: not initialized'
144     do while (theAction%actionFlag/=rvDone)
145     select case (theAction%actionFlag)
146     case (rvFirstUTurn)
147     !we taped already ... see above
148     CALL OpenAD_forward_step( currIter+1, mytime, myiter,
149     +mythid )
150     case (rvStore)
151     call cp_write_open(theAction%cpNum+jointCPCount)
152     !$PLACEHOLDER_PRAGMA$ id=8
153     call cp_close
154     case (rvRestore)
155     call cp_read_open(theAction%cpNum+jointCPCount)
156     !$PLACEHOLDER_PRAGMA$ id=9
157     currIter=theAction%iteration
158     call cp_close
159     case (rvForward)
160     call OAD_revPlain
161     do currIter=currIter,theAction%iteration-1
162     CALL OpenAD_forward_step( currIter+1, mytime, myiter,
163     + mythid )
164     end do
165     call OAD_revAdjoint
166     case (rvUTurn)
167     call OAD_revTape
168     CALL OpenAD_forward_step( currIter+1, mytime, myiter,
169     +mythid )
170     call OAD_revAdjoint
171     CALL OpenAD_forward_step( currIter+1, mytime, myiter,
172     +mythid )
173     end select
174     theAction=rvNextAction()
175     end do
176     end if
177    
178     #ifdef OAD_DEBUG_JOINT
179     write(standardmessageunit,'(A,A,A)', ADVANCE='NO')
180     +'OAD:',indentation(1:our_indent), 'leave __SRNAME__:'
181     call oad_dump_revmod(); call oad_dump_tapestats()
182     write(standardmessageunit,*)
183    
184     our_indent=our_indent-1
185     #endif
186    
187     end subroutine template

  ViewVC Help
Powered by ViewVC 1.1.22