| 1 |
utke |
1.1 |
subroutine template() |
| 2 |
|
|
use OAD_cp |
| 3 |
|
|
use OAD_tape |
| 4 |
|
|
use OAD_rev |
| 5 |
|
|
|
| 6 |
|
|
c we may need these for the checkpointing |
| 7 |
|
|
use SIZE_mod |
| 8 |
|
|
use EEPARAMS_mod |
| 9 |
|
|
use PARAMS_mod |
| 10 |
|
|
use BAR2_mod |
| 11 |
|
|
use BARRIER_mod |
| 12 |
|
|
use CD_CODE_VARS_mod |
| 13 |
|
|
use CG2D_mod |
| 14 |
|
|
use CG3D_mod |
| 15 |
|
|
use DFILE_mod |
| 16 |
|
|
use DYNVARS_mod |
| 17 |
|
|
use EESUPPORT_mod |
| 18 |
|
|
use EOS_mod |
| 19 |
|
|
use EXCH_JAM_mod |
| 20 |
|
|
use EXCH_mod |
| 21 |
|
|
use FC_NAMEMANGLE_mod |
| 22 |
|
|
use FFIELDS_mod |
| 23 |
|
|
use GAD_mod |
| 24 |
|
|
use GLOBAL_MAX_mod |
| 25 |
|
|
use GLOBAL_SUM_mod |
| 26 |
|
|
use GMREDI_mod |
| 27 |
|
|
use GMREDI_TAVE_mod |
| 28 |
|
|
use GRID_mod |
| 29 |
|
|
use MPI_INFO_mod |
| 30 |
|
|
use SOLVE_FOR_PRESSURE3D_mod |
| 31 |
|
|
use SOLVE_FOR_PRESSURE_mod |
| 32 |
|
|
use SURFACE_mod |
| 33 |
|
|
use tamc_mod |
| 34 |
|
|
use tamc_keys_mod |
| 35 |
|
|
use cost_mod |
| 36 |
|
|
use g_cost_mod |
| 37 |
|
|
use ctrl_mod |
| 38 |
|
|
use ctrl_dummy_mod |
| 39 |
|
|
use ctrl_weights_mod |
| 40 |
|
|
use optim_mod |
| 41 |
|
|
use grdchk_mod |
| 42 |
|
|
|
| 43 |
|
|
!$TEMPLATE_PRAGMA_DECLARATIONS |
| 44 |
|
|
|
| 45 |
|
|
integer :: cp_loop_variable_1,cp_loop_variable_2, |
| 46 |
|
|
+ cp_loop_variable_3,cp_loop_variable_4,cp_loop_variable_5 |
| 47 |
|
|
|
| 48 |
|
|
type(modeType) :: our_orig_mode |
| 49 |
|
|
|
| 50 |
|
|
integer iaddr |
| 51 |
|
|
external iaddr |
| 52 |
|
|
|
| 53 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 54 |
utke |
1.1 |
character*(80):: indentation=' |
| 55 |
|
|
+ ' |
| 56 |
|
|
our_indent=our_indent+1 |
| 57 |
|
|
|
| 58 |
utke |
1.3 |
write(standardmessageunit, '(A,A,A)', ADVANCE='NO') |
| 59 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), 'enter __SRNAME__:' |
| 60 |
utke |
1.1 |
call oad_dump_revmod(); call oad_dump_tapestats() |
| 61 |
utke |
1.3 |
write(standardmessageunit,*) |
| 62 |
utke |
1.2 |
#endif |
| 63 |
utke |
1.1 |
|
| 64 |
|
|
if (our_rev_mode%switchedToCheckpoint) then |
| 65 |
|
|
|
| 66 |
|
|
if (our_rev_mode%arg_store) then |
| 67 |
|
|
call cp_write_open() |
| 68 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 69 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)') |
| 70 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 71 |
utke |
1.1 |
+' __SRNAME__: entering arg store' |
| 72 |
utke |
1.2 |
#endif |
| 73 |
utke |
1.1 |
!$PLACEHOLDER_PRAGMA$ id=8 |
| 74 |
|
|
call cp_close() |
| 75 |
|
|
end if |
| 76 |
|
|
if (our_rev_mode%arg_restore) then |
| 77 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 78 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)') |
| 79 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 80 |
utke |
1.1 |
+' __SRNAME__: entering arg restore' |
| 81 |
utke |
1.2 |
#endif |
| 82 |
utke |
1.1 |
call cp_read_open() |
| 83 |
|
|
!$PLACEHOLDER_PRAGMA$ id=9 |
| 84 |
|
|
call cp_close() |
| 85 |
|
|
end if |
| 86 |
|
|
if (our_rev_mode%plain) then |
| 87 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 88 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)') |
| 89 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 90 |
|
|
+' __SRNAME__: run plain, down plain' |
| 91 |
|
|
#endif |
| 92 |
utke |
1.1 |
our_orig_mode=our_rev_mode |
| 93 |
|
|
our_rev_mode%arg_store=.FALSE. |
| 94 |
|
|
!$PLACEHOLDER_PRAGMA$ id=1 |
| 95 |
|
|
our_rev_mode=our_orig_mode |
| 96 |
|
|
end if |
| 97 |
|
|
if (our_rev_mode%tape) then |
| 98 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 99 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)') |
| 100 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 101 |
|
|
+' __SRNAME__: run tape, down arg store/plain' |
| 102 |
|
|
#endif |
| 103 |
utke |
1.1 |
our_orig_mode=our_rev_mode |
| 104 |
|
|
our_rev_mode%arg_store=.TRUE. |
| 105 |
|
|
our_rev_mode%arg_restore=.FALSE. |
| 106 |
|
|
our_rev_mode%plain=.TRUE. |
| 107 |
|
|
our_rev_mode%tape=.FALSE. |
| 108 |
|
|
our_rev_mode%adjoint=.FALSE. |
| 109 |
|
|
!$PLACEHOLDER_PRAGMA$ id=2 |
| 110 |
|
|
our_rev_mode%arg_store=.FALSE. |
| 111 |
|
|
our_rev_mode%arg_restore=.TRUE. |
| 112 |
|
|
our_rev_mode%plain=.FALSE. |
| 113 |
|
|
our_rev_mode%tape=.TRUE. |
| 114 |
|
|
our_rev_mode%adjoint=.FALSE. |
| 115 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 116 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)') |
| 117 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 118 |
utke |
1.1 |
+' __SRNAME__: following with adjoint, down arg restor/tape' |
| 119 |
utke |
1.2 |
#endif |
| 120 |
utke |
1.1 |
!$PLACEHOLDER_PRAGMA$ id=3 |
| 121 |
|
|
our_rev_mode=our_orig_mode |
| 122 |
|
|
end if |
| 123 |
|
|
|
| 124 |
|
|
else |
| 125 |
|
|
|
| 126 |
|
|
our_rev_mode%switchedToCheckpoint = .TRUE. |
| 127 |
|
|
|
| 128 |
|
|
if (our_rev_mode%arg_store) then |
| 129 |
utke |
1.3 |
write(errorMessageUnit,'(A)') |
| 130 |
utke |
1.2 |
+'OAD ERROR __SRNAME__: s2c arg store is the wrong logic' |
| 131 |
utke |
1.1 |
stop |
| 132 |
|
|
end if |
| 133 |
|
|
if (our_rev_mode%arg_restore) then |
| 134 |
utke |
1.3 |
write(errorMessageUnit,'(A)') |
| 135 |
utke |
1.2 |
+'OAD ERROR __SRNAME__: s2c arg restore is the wrong logic' |
| 136 |
utke |
1.1 |
stop |
| 137 |
|
|
end if |
| 138 |
|
|
if (our_rev_mode%plain) then |
| 139 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 140 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)') |
| 141 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 142 |
utke |
1.1 |
+' __SRNAME__: s2c entering plain' |
| 143 |
utke |
1.2 |
#endif |
| 144 |
utke |
1.1 |
our_orig_mode=our_rev_mode |
| 145 |
|
|
!$PLACEHOLDER_PRAGMA$ id=1 |
| 146 |
|
|
our_rev_mode=our_orig_mode |
| 147 |
|
|
end if |
| 148 |
|
|
if (our_rev_mode%tape) then |
| 149 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 150 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)') |
| 151 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 152 |
utke |
1.1 |
+' __SRNAME__: s2c entering as tape' |
| 153 |
utke |
1.2 |
#endif |
| 154 |
utke |
1.1 |
c we have to switch from split to checkpointing mode |
| 155 |
|
|
c i.e. outside taping means top level checkpointing here |
| 156 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 157 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)') |
| 158 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 159 |
utke |
1.1 |
+' __SRNAME__: s2c store argument cp' |
| 160 |
utke |
1.2 |
#endif |
| 161 |
utke |
1.1 |
call cp_write_open() |
| 162 |
|
|
!$PLACEHOLDER_PRAGMA$ id=8 |
| 163 |
|
|
call cp_close() |
| 164 |
|
|
c now do the forward run down a plain |
| 165 |
|
|
our_orig_mode=our_rev_mode |
| 166 |
|
|
our_rev_mode%arg_store=.FALSE. |
| 167 |
|
|
our_rev_mode%arg_restore=.FALSE. |
| 168 |
|
|
our_rev_mode%plain=.TRUE. |
| 169 |
|
|
our_rev_mode%tape=.FALSE. |
| 170 |
|
|
our_rev_mode%adjoint=.FALSE. |
| 171 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 172 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)') |
| 173 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), ' __SRNAME__: s2c run plain' |
| 174 |
|
|
#endif |
| 175 |
utke |
1.1 |
!$PLACEHOLDER_PRAGMA$ id=1 |
| 176 |
|
|
our_rev_mode=our_orig_mode |
| 177 |
|
|
end if |
| 178 |
|
|
if (our_rev_mode%adjoint) then |
| 179 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 180 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)') |
| 181 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 182 |
utke |
1.1 |
+' __SRNAME__: s2c entering as adjoint' |
| 183 |
utke |
1.2 |
#endif |
| 184 |
utke |
1.1 |
c we have to switch from split to checkpointing mode |
| 185 |
|
|
c i.e. outside adjoint means argument restore, taping and then adjoint here |
| 186 |
|
|
c argument restore |
| 187 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 188 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)') |
| 189 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 190 |
utke |
1.1 |
+' __SRNAME__: s2c restore argument cp' |
| 191 |
utke |
1.2 |
#endif |
| 192 |
utke |
1.1 |
call cp_read_open() |
| 193 |
|
|
!$PLACEHOLDER_PRAGMA$ id=9 |
| 194 |
|
|
call cp_close() |
| 195 |
|
|
c setup checkpointing downwards |
| 196 |
|
|
our_orig_mode=our_rev_mode |
| 197 |
|
|
our_rev_mode%arg_store=.TRUE. |
| 198 |
|
|
our_rev_mode%arg_restore=.FALSE. |
| 199 |
|
|
our_rev_mode%plain=.TRUE. |
| 200 |
|
|
our_rev_mode%tape=.FALSE. |
| 201 |
|
|
our_rev_mode%adjoint=.FALSE. |
| 202 |
|
|
c taping this level |
| 203 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 204 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A,A)') |
| 205 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 206 |
utke |
1.1 |
+' __SRNAME__: s2c run tape, down arg store/plain' |
| 207 |
utke |
1.2 |
#endif |
| 208 |
utke |
1.1 |
!$PLACEHOLDER_PRAGMA$ id=2 |
| 209 |
|
|
c setting up for taping downwards |
| 210 |
|
|
our_rev_mode%arg_store=.FALSE. |
| 211 |
|
|
our_rev_mode%arg_restore=.TRUE. |
| 212 |
|
|
our_rev_mode%plain=.FALSE. |
| 213 |
|
|
our_rev_mode%tape=.TRUE. |
| 214 |
|
|
our_rev_mode%adjoint=.TRUE. |
| 215 |
|
|
c adjoining this level |
| 216 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 217 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A,A)') |
| 218 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), |
| 219 |
utke |
1.1 |
+' __SRNAME__: s2c run adjoint, down arg restore/tape' |
| 220 |
utke |
1.2 |
#endif |
| 221 |
utke |
1.1 |
!$PLACEHOLDER_PRAGMA$ id=3 |
| 222 |
|
|
our_rev_mode=our_orig_mode |
| 223 |
|
|
end if |
| 224 |
|
|
|
| 225 |
|
|
our_rev_mode%switchedToCheckpoint=.FALSE. |
| 226 |
|
|
|
| 227 |
|
|
end if |
| 228 |
|
|
|
| 229 |
utke |
1.2 |
#ifdef OAD_DEBUG_JOINT |
| 230 |
utke |
1.3 |
write(standardmessageunit,'(A,A,A)', ADVANCE='NO') |
| 231 |
utke |
1.2 |
+'OAD:',indentation(1:our_indent), 'leave __SRNAME__:' |
| 232 |
utke |
1.1 |
call oad_dump_revmod(); call oad_dump_tapestats() |
| 233 |
utke |
1.3 |
write(standardmessageunit,*) |
| 234 |
utke |
1.1 |
|
| 235 |
|
|
our_indent=our_indent-1 |
| 236 |
utke |
1.2 |
#endif |
| 237 |
|
|
|
| 238 |
utke |
1.1 |
end subroutine template |