/[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.7 - (hide annotations) (download)
Fri Jul 3 21:33:55 2015 UTC (8 years, 10 months ago) by heimbach
Branch: MAIN
Changes since 1.6: +56 -4 lines
Merge and update from Krishna Narayanan's contrib area:
o genmake2 flag -diva (but only for OpenAD)
o required modifs for OAD_support

1 heimbach 1.3 #include "PACKAGES_CONFIG.h"
2 heimbach 1.7 #include "OPENAD_OPTIONS.h"
3 heimbach 1.3
4 utke 1.1 subroutine template()
5     use OAD_cp
6     use OAD_tape
7     use OAD_rev
8     use revolve
9    
10     c we may need these for the checkpointing
11     use SIZE_mod
12     use EEPARAMS_mod
13     use PARAMS_mod
14     use BAR2_mod
15     use BARRIER_mod
16 heimbach 1.3 #ifdef ALLOW_CD_CODE
17 utke 1.1 use CD_CODE_VARS_mod
18 heimbach 1.3 #endif
19 utke 1.1 use CG2D_mod
20     use CG3D_mod
21     use DYNVARS_mod
22     use EESUPPORT_mod
23     use EOS_mod
24     use EXCH_mod
25     use FC_NAMEMANGLE_mod
26     use FFIELDS_mod
27 utke 1.5 #ifdef ALLOW_GENERIC_ADVDIFF
28 utke 1.1 use GAD_mod
29 utke 1.5 #endif
30 utke 1.1 use GLOBAL_MAX_mod
31     use GLOBAL_SUM_mod
32 heimbach 1.6 #ifdef ALLOW_GGL90
33     use GGL90_mod
34     use GGL90_TAVE_mod
35     #endif
36 heimbach 1.3 #ifdef ALLOW_GMREDI
37 utke 1.1 use GMREDI_mod
38     use GMREDI_TAVE_mod
39 heimbach 1.3 #endif
40 utke 1.1 use GRID_mod
41 utke 1.5 #ifdef ALLOW_MOM_COMMON
42 heimbach 1.3 use MOM_VISC_mod
43 utke 1.5 #endif
44 utke 1.1 use MPI_INFO_mod
45 heimbach 1.3 #ifdef ALLOW_SHAP_FILT
46     use SHAP_FILT_mod
47     #endif
48 heimbach 1.4 #ifdef ALLOW_STREAMICE
49     use STREAMICE_mod
50     use STREAMICE_ADV_mod
51     use STREAMICE_BDRY_mod
52     use STREAMICE_CG_mod
53     #endif
54 utke 1.1 use SOLVE_FOR_PRESSURE3D_mod
55     use SOLVE_FOR_PRESSURE_mod
56     use SURFACE_mod
57     use tamc_mod
58     use tamc_keys_mod
59     use cost_mod
60     use g_cost_mod
61     use ctrl_mod
62     use ctrl_dummy_mod
63     use ctrl_weights_mod
64     use optim_mod
65     use grdchk_mod
66    
67     !$TEMPLATE_PRAGMA_DECLARATIONS
68     LOGICAL :: initialized=.FALSE.
69     TYPE(rvAction),save :: theAction
70 utke 1.2 CHARACTER(80) :: errorMsg
71 utke 1.1 integer, save :: jointCPCount
72     integer, save :: currIter
73    
74     integer :: cp_loop_variable_1,cp_loop_variable_2,
75     + cp_loop_variable_3,cp_loop_variable_4,cp_loop_variable_5
76    
77     type(modeType) :: our_orig_mode
78    
79     integer iaddr
80     external iaddr
81    
82     #ifdef OAD_DEBUG_JOINT
83     character*(80):: indentation='
84     + '
85     our_indent=our_indent+1
86    
87     write(standardmessageunit, '(A,A,A)', ADVANCE='NO')
88     +'OAD:',indentation(1:our_indent), 'enter __SRNAME__:'
89     call oad_dump_revmod(); call oad_dump_tapestats()
90     write(standardmessageunit,*)
91     #endif
92    
93     nIter0 = NINT( (startTime-baseTime)/deltaTClock )
94     if (our_rev_mode%arg_store) then
95     call cp_write_open()
96     #ifdef OAD_DEBUG_JOINT
97     write(standardmessageunit,'(A,A,A)')
98     +'OAD:',indentation(1:our_indent),
99     +' __SRNAME__: entering arg store'
100     #endif
101     !$PLACEHOLDER_PRAGMA$ id=8
102     call cp_close()
103     end if
104     if (our_rev_mode%arg_restore) then
105     #ifdef OAD_DEBUG_JOINT
106     write(standardmessageunit,'(A,A,A)')
107     +'OAD:',indentation(1:our_indent),
108     +' __SRNAME__: entering arg restore'
109     #endif
110     call cp_read_open()
111     !$PLACEHOLDER_PRAGMA$ id=9
112     call cp_close()
113     end if
114     if (our_rev_mode%plain) then
115     #ifdef OAD_DEBUG_JOINT
116     write(standardmessageunit,'(A,A,A)')
117     +'OAD:',indentation(1:our_indent),
118     +' __SRNAME__: run plain, down plain'
119     #endif
120 heimbach 1.7 #ifdef ALLOW_OPENAD_DIVA
121     DO iloop1 = 1, nTimeSteps
122     PROD = (ILOOP1 + NTIMESTEPS_L2 *(ILOOP +(-1)))
123     print *, 'DIVA Revolve Plain PROD = ', PROD
124     CALL OpenAD_forward_step( PROD, mytime, myiter, mythid )
125     enddo
126     #else
127 utke 1.1 DO iloop = 1, nTimeSteps
128     CALL OpenAD_forward_step( iloop, mytime, myiter, mythid )
129     enddo
130 heimbach 1.7 #endif
131 utke 1.1 end if
132     if (our_rev_mode%tape) then
133     #ifdef OAD_DEBUG_JOINT
134     write(standardmessageunit,'(A,A,A)')
135     +'OAD:',indentation(1:our_indent),
136     +' __SRNAME__: run tape, down revolve until first U turn'
137     #endif
138     currIter=0
139     jointCPcount=cp_fNumber()
140     initialized=rvInit(nTimeSteps,120,
141     + errorMsg,theAction)
142     IF (.NOT.initialized) WRITE(*,'(A,A)') 'Error: ', errorMsg
143     do while (theAction%actionFlag/=rvDone)
144     theAction=rvNextAction()
145     select case (theAction%actionFlag)
146     case (rvStore)
147     call cp_write_open(theAction%cpNum+jointCPCount)
148     !$PLACEHOLDER_PRAGMA$ id=8
149     call cp_close
150     case (rvForward)
151     call OAD_revPlain
152     do currIter=currIter,theAction%iteration-1
153 heimbach 1.7 #ifdef ALLOW_OPENAD_DIVA
154     PROD = (currIter+1 + NTIMESTEPS_L2 *(ILOOP +(-1)))
155     print *, 'DIVA Revolve Tape rvForward PROD = ', PROD
156     CALL OpenAD_forward_step( PROD, mytime,
157 utke 1.1 +myiter, mythid )
158 heimbach 1.7 #else
159     CALL OpenAD_forward_step( currIter+1, mytime,
160     +myiter, mythid )
161     #endif
162 utke 1.1 end do
163     call OAD_revTape
164     case (rvFirstUTurn)
165 heimbach 1.7 #ifdef ALLOW_OPENAD_DIVA
166     PROD = (currIter+1 + NTIMESTEPS_L2 *(ILOOP +(-1)))
167     print *, 'DIVA Revolve Tape rvFirstUTurn PROD = ', PROD
168     CALL OpenAD_forward_step( PROD, mytime, myiter,
169     +mythid )
170     #else
171     CALL OpenAD_forward_step( currIter+1, mytime, myiter,
172 utke 1.1 +mythid )
173 heimbach 1.7 #endif
174 utke 1.1 ! get out now ...
175     exit
176     end select
177     end do
178     end if
179     if (our_rev_mode%adjoint) then
180     IF (.NOT.initialized) WRITE(*,'(A)') 'Error: not initialized'
181     do while (theAction%actionFlag/=rvDone)
182     select case (theAction%actionFlag)
183     case (rvFirstUTurn)
184     !we taped already ... see above
185 heimbach 1.7 #ifdef ALLOW_OPENAD_DIVA
186     PROD = (currIter+1 + NTIMESTEPS_L2 *(ILOOP +(-1)))
187     print *, 'DIVA Revolve Adjoint rvFirstUTurn PROD = ', PROD
188     CALL OpenAD_forward_step( PROD, mytime, myiter,
189     +mythid )
190     #else
191 utke 1.1 CALL OpenAD_forward_step( currIter+1, mytime, myiter,
192     +mythid )
193 heimbach 1.7 #endif
194 utke 1.1 case (rvStore)
195     call cp_write_open(theAction%cpNum+jointCPCount)
196     !$PLACEHOLDER_PRAGMA$ id=8
197     call cp_close
198     case (rvRestore)
199     call cp_read_open(theAction%cpNum+jointCPCount)
200     !$PLACEHOLDER_PRAGMA$ id=9
201     currIter=theAction%iteration
202     call cp_close
203     case (rvForward)
204     call OAD_revPlain
205     do currIter=currIter,theAction%iteration-1
206 heimbach 1.7 #ifdef ALLOW_OPENAD_DIVA
207     PROD = (currIter+1 + NTIMESTEPS_L2 *(ILOOP +(-1)))
208     print *, 'DIVA Revolve Adjoint rvForward PROD = ', PROD
209     CALL OpenAD_forward_step( PROD, mytime, myiter,
210     + mythid )
211     #else
212 utke 1.1 CALL OpenAD_forward_step( currIter+1, mytime, myiter,
213     + mythid )
214 heimbach 1.7 #endif
215 utke 1.1 end do
216     call OAD_revAdjoint
217     case (rvUTurn)
218 heimbach 1.7 #ifdef ALLOW_OPENAD_DIVA
219     PROD = (currIter+1 + NTIMESTEPS_L2 *(ILOOP +(-1)))
220     #endif
221 utke 1.1 call OAD_revTape
222 heimbach 1.7 #ifdef ALLOW_OPENAD_DIVA
223     print *, 'DIVA Revolve Adjoint rvUTurn tp PROD = ', PROD
224     CALL OpenAD_forward_step( PROD, mytime, myiter,
225     +mythid )
226     #else
227     CALL OpenAD_forward_step( currIter+1, mytime, myiter,
228 utke 1.1 +mythid )
229 heimbach 1.7 #endif
230 utke 1.1 call OAD_revAdjoint
231 heimbach 1.7 #ifdef ALLOW_OPENAD_DIVA
232     print *, 'DIVA Revolve Adjoint rvUTurn ad PROD = ', PROD
233     CALL OpenAD_forward_step( PROD, mytime, myiter,
234     +mythid )
235     #else
236     CALL OpenAD_forward_step( currIter+1, mytime, myiter,
237 utke 1.1 +mythid )
238 heimbach 1.7 #endif
239 utke 1.1 end select
240     theAction=rvNextAction()
241     end do
242     end if
243    
244     #ifdef OAD_DEBUG_JOINT
245     write(standardmessageunit,'(A,A,A)', ADVANCE='NO')
246     +'OAD:',indentation(1:our_indent), 'leave __SRNAME__:'
247     call oad_dump_revmod(); call oad_dump_tapestats()
248     write(standardmessageunit,*)
249    
250     our_indent=our_indent-1
251     #endif
252    
253     end subroutine template

  ViewVC Help
Powered by ViewVC 1.1.22