/[MITgcm]/manual/s_autodiff/doc_ad_examples.tex
ViewVC logotype

Contents of /manual/s_autodiff/doc_ad_examples.tex

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


Revision 1.8 - (show annotations) (download) (as text)
Tue Jun 27 15:58:30 2006 UTC (17 years, 10 months ago) by molod
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +1 -1 lines
File MIME type: application/x-tex
FILE REMOVED
moved example to chap 3, commented out file input in part5.tex

1 % $Header: /u/gcmpack/manual/part5/doc_ad_examples.tex,v 1.7 2006/04/05 02:27:33 edhill Exp $
2 % $Name: $
3
4 %**********************************************************************
5 \section{Sensitivity of Air-Sea Exchange to Tracer Injection Site }
6 \label{www:tutorials}
7 \label{sect:eg-simple-tracer-adjoint}
8 \label{sec_ad_setup_ex}
9 \label{sect:tutorialIII}
10 \begin{rawhtml}
11 <!-- CMIREDIR:sec_ad_setup_ex: -->
12 \end{rawhtml}
13 %**********************************************************************
14
15 MITgcm has been adapted to enable AD using TAMC or TAF.
16 The present description, therefore, is specific to the
17 use of TAMC or TAF as AD tool.
18 The following sections describe the steps which are necessary to
19 generate a tangent linear or adjoint model of MITgcm.
20 We take as an example the sensitivity of carbon sequestration
21 in the ocean.
22 The AD-relevant hooks in the code are sketched in
23 \ref{fig:adthemodel}, \ref{fig:adthemain}.
24
25 \subsection{Overview of the experiment}
26 \label{www:tutorials}
27
28 We describe an adjoint sensitivity analysis of out-gassing from
29 the ocean into the atmosphere of a carbon-like tracer injected
30 into the ocean interior (see \cite{hil-eta:01}).
31
32 \subsubsection{Passive tracer equation}
33 \label{www:tutorials}
34
35 For this work MITgcm was augmented with a thermodynamically
36 inactive tracer, $C$. Tracer residing in the ocean
37 model surface layer is out-gassed according to a relaxation time scale,
38 $\mu$. Within the ocean interior, the tracer is passively advected
39 by the ocean model currents. The full equation for the time evolution
40 %
41 \begin{equation}
42 \label{carbon_ddt}
43 \frac{\partial C}{\partial t} \, = \,
44 -U\cdot \nabla C \, - \, \mu C \, + \, \Gamma(C) \,+ \, S
45 \end{equation}
46 %
47 also includes a source term $S$. This term
48 represents interior sources of $C$ such as would arise due to
49 direct injection.
50 The velocity term, $U$, is the sum of the
51 model Eulerian circulation and an eddy-induced velocity, the latter
52 parameterized according to Gent/McWilliams
53 (\cite{gen-mcw:90, gen-eta:95}).
54 The convection function, $\Gamma$, mixes $C$ vertically wherever the
55 fluid is locally statically unstable.
56
57 The out-gassing time scale, $\mu$, in eqn. (\ref{carbon_ddt})
58 is set so that \( 1/\mu \sim 1 \ \mathrm{year} \) for the surface
59 ocean and $\mu=0$ elsewhere. With this value, eqn. (\ref{carbon_ddt})
60 is valid as a prognostic equation for small perturbations in oceanic
61 carbon concentrations. This configuration provides a
62 powerful tool for examining the impact of large-scale ocean circulation
63 on $ CO_2 $ out-gassing due to interior injections.
64 As source we choose a constant in time injection of
65 $ S = 1 \,\, {\rm mol / s}$.
66
67 \subsubsection{Model configuration}
68 \label{www:tutorials}
69
70 The model configuration employed has a constant
71 $4^\circ \times 4^\circ$ resolution horizontal grid and realistic
72 geography and bathymetry. Twenty vertical layers are used with
73 vertical spacing ranging
74 from 50 m near the surface to 815 m at depth.
75 Driven to steady-state by climatological wind-stress, heat and
76 fresh-water forcing the model reproduces well known large-scale
77 features of the ocean general circulation.
78
79 \subsubsection{Out-gassing cost function}
80 \label{www:tutorials}
81
82 To quantify and understand out-gassing due to injections of $C$
83 in eqn. (\ref{carbon_ddt}),
84 we define a cost function $ {\cal J} $ that measures the total amount of
85 tracer out-gassed at each timestep:
86 %
87 \begin{equation}
88 \label{cost_tracer}
89 {\cal J}(t=T)=\int_{t=0}^{t=T}\int_{A} \mu C \, dA \, dt
90 \end{equation}
91 %
92 Equation(\ref{cost_tracer}) integrates the out-gassing term, $\mu C$,
93 from (\ref{carbon_ddt})
94 over the entire ocean surface area, $A$, and accumulates it
95 up to time $T$.
96 Physically, ${\cal J}$ can be thought of as representing the amount of
97 $CO_2$ that our model predicts would be out-gassed following an
98 injection at rate $S$.
99 The sensitivity of ${\cal J}$ to the spatial location of $S$,
100 $\frac{\partial {\cal J}}{\partial S}$,
101 can be used to identify regions from which circulation
102 would cause $CO_2$ to rapidly out-gas following injection
103 and regions in which $CO_2$ injections would remain effectively
104 sequestered within the ocean.
105
106 \subsection{Code configuration}
107 \label{www:tutorials}
108
109 The model configuration for this experiment resides under the
110 directory {\it verification/carbon/}.
111 The code customization routines are in {\it verification/carbon/code/}:
112 %
113 \begin{itemize}
114 %
115 \item {\it .genmakerc}
116 %
117 \item {\it COST\_CPPOPTIONS.h}
118 %
119 \item {\it CPP\_EEOPTIONS.h}
120 %
121 \item {\it CPP\_OPTIONS.h}
122 %
123 \item {\it CTRL\_OPTIONS.h}
124 %
125 \item {\it ECCO\_OPTIONS.h}
126 %
127 \item {\it SIZE.h}
128 %
129 \item {\it adcommon.h}
130 %
131 \item {\it tamc.h}
132 %
133 \end{itemize}
134 %
135 The runtime flag and parameters settings are contained in
136 {\it verification/carbon/input/},
137 together with the forcing fields and and restart files:
138 %
139 \begin{itemize}
140 %
141 \item {\it data}
142 %
143 \item {\it data.cost}
144 %
145 \item {\it data.ctrl}
146 %
147 \item {\it data.gmredi}
148 %
149 \item {\it data.grdchk}
150 %
151 \item {\it data.optim}
152 %
153 \item {\it data.pkg}
154 %
155 \item {\it eedata}
156 %
157 \item {\it topog.bin}
158 %
159 \item {\it windx.bin, windy.bin}
160 %
161 \item {\it salt.bin, theta.bin}
162 %
163 \item {\it SSS.bin, SST.bin}
164 %
165 \item {\it pickup*}
166 %
167 \end{itemize}
168 %
169 Finally, the file to generate the adjoint code resides in
170 $ adjoint/ $:
171 %
172 \begin{itemize}
173 %
174 \item {\it makefile}
175 %
176 \end{itemize}
177 %
178
179 Below we describe the customizations of this files which are
180 specific to this experiment.
181
182 \subsubsection{File {\it .genmakerc}}
183 \label{www:tutorials}
184 This file overwrites default settings of {\it genmake}.
185 In the present example it is used to switch on the following
186 packages which are related to automatic differentiation
187 and are disabled by default: \\
188 \hspace*{4ex} {\tt set ENABLE=( autodiff cost ctrl ecco gmredi grdchk kpp )} \\
189 Other packages which are not needed are switched off: \\
190 \hspace*{4ex} {\tt set DISABLE=( aim obcs zonal\_filt shap\_filt cal exf )}
191
192 \subsubsection{File {\it COST\_CPPOPTIONS.h, CTRL\_OPTIONS.h}}
193 \label{www:tutorials}
194
195 These files used to contain package-specific CPP-options
196 (see Section \ref{???}).
197 For technical reasons those options have been grouped together
198 in the file {\it ECCO\_OPTIONS.h}.
199 To retain the modularity, the files have been kept and contain
200 the standard include of the {\it CPP\_OPTIONS.h} file.
201
202 \subsubsection{File {\it CPP\_EEOPTIONS.h}}
203 \label{www:tutorials}
204
205 This file contains 'wrapper'-specific CPP options.
206 It only needs to be changed if the code is to be run
207 in a parallel environment (see Section \ref{???}).
208
209 \subsubsection{File {\it CPP\_OPTIONS.h}}
210 \label{www:tutorials}
211
212 This file contains model-specific CPP options
213 (see Section \ref{???}).
214 Most options are related to the forward model setup.
215 They are identical to the global steady circulation setup of
216 {\it verification/global\_ocean.90x40x15/}.
217 The three options specific to this experiment are \\
218 \hspace*{4ex} {\tt \#define ALLOW\_PASSIVE\_TRACER} \\
219 This flag enables the code to carry through the
220 advection/diffusion of a passive tracer along the
221 model integration. \\
222 \hspace*{4ex} {\tt \#define ALLOW\_MIT\_ADJOINT\_RUN} \\
223 This flag enables the inclusion of some AD-related fields
224 concerning initialization, link between control variables
225 and forward model variables, and the call to the top-level
226 forward/adjoint subroutine {\it adthe\_main\_loop}
227 instead of {\it the\_main\_loop}. \\
228 \hspace*{4ex} {\tt \#define ALLOW\_GRADIENT\_CHECK} \\
229 This flag enables the gradient check package.
230 After computing the unperturbed cost function and its gradient,
231 a series of computations are performed for which \\
232 $\bullet$ an element of the control vector is perturbed \\
233 $\bullet$ the cost function w.r.t. the perturbed element is
234 computed \\
235 $\bullet$ the difference between the perturbed and unperturbed
236 cost function is computed to compute the finite difference gradient \\
237 $\bullet$ the finite difference gradient is compared with the
238 adjoint-generated gradient.
239 The gradient check package is further described in Section ???.
240
241 \subsubsection{File {\it ECCO\_OPTIONS.h}}
242 \label{www:tutorials}
243
244 The CPP options of several AD-related packages are grouped
245 in this file:
246 %
247 \begin{itemize}
248 %
249 \item
250 Overall ECCO-related execution modus: \\
251 These determine whether a pure forward run,
252 a sensitivity run or an iteration of optimization is
253 performed. These options are not needed in the present context.
254 %
255 \item
256 Adjoint support package: {\it pkg/autodiff/} \\
257 This package contains hand-written adjoint code such as
258 active file handling, flow directives for files which must not
259 be differentiated, and TAMC-specific header files. \\
260 %
261 \hspace*{4ex} {\tt \#define ALLOW\_AUTODIFF\_TAMC} \\
262 defines TAMC-related features in the code. \\
263 %
264 \hspace*{4ex} {\tt \#define ALLOW\_TAMC\_CHECKPOINTING} \\
265 enables the checkpointing feature of TAMC
266 (see Section \ref{???}).
267 In the present example a 3-level checkpointing is implemented.
268 The code contains the relevant store directives, common block
269 and tape initializations, storing key computation,
270 and loop index handling.
271 The checkpointing length at each level is defined in
272 file {\it tamc.h}, cf. below.
273 The out and intermediate loop directivs are contained
274 in the files {\it checkpoint\_lev3\_directives.h},
275 {\it checkpoint\_lev2\_directives.h} (package {\it pkg/autodiff}). \\
276 %
277 \hspace*{4ex} {\tt \#define ALLOW\_AUTODIFF\_MONITOOR} \\
278 enables the monitoring of intermediate adjoint variables
279 (see Section \ref{???}). \\
280 %
281 \hspace*{4ex} {\tt \#define ALLOW\_DIVIDED\_ADJOINT} \\
282 enables adjoint dump and restart
283 (see Section \ref{???}).
284 %
285 \item Cost function package: {\it pkg/cost/} \\
286 This package contains all relevant routines for
287 initializing, accumulating and finalizing the cost function
288 (see Section \ref{???}). \\
289 \hspace*{4ex} {\tt \#define ALLOW\_COST} \\
290 enables all general aspects of the cost function handling,
291 in particular the hooks in the forward code for
292 initializing, accumulating and finalizing the cost function. \\
293 \hspace*{4ex} {\tt \#define ALLOW\_COST\_TRACER} \\
294 includes the call to the cost function for this
295 particular experiment, eqn. (\ref{cost_tracer}).
296 %
297 \item Control variable package: {\it pkg/ctrl/} \\
298 This package contains all relevant routines for
299 the handling of the control vector.
300 Each control variable can be enabled/disabled with its own flag: \\
301 \begin{tabular}{ll}
302 \hspace*{2ex} {\tt \#define ALLOW\_THETA0\_CONTROL} &
303 initial temperature \\
304 \hspace*{2ex} {\tt \#define ALLOW\_SALT0\_CONTROL} &
305 initial salinity \\
306 \hspace*{2ex} {\tt \#define ALLOW\_TR0\_CONTROL} &
307 initial passive tracer concentration \\
308 \hspace*{2ex} {\tt \#define ALLOW\_TAUU0\_CONTROL} &
309 zonal wind stress \\
310 \hspace*{2ex} {\tt \#define ALLOW\_TAUV0\_CONTROL} &
311 meridional wind stress \\
312 \hspace*{2ex} {\tt \#define ALLOW\_SFLUX0\_CONTROL} &
313 freshwater flux \\
314 \hspace*{2ex} {\tt \#define ALLOW\_HFLUX0\_CONTROL} &
315 heat flux \\
316 \hspace*{2ex} {\tt \#define ALLOW\_DIFFKR\_CONTROL} &
317 diapycnal diffusivity \\
318 \hspace*{2ex} {\tt \#undef ALLOW\_KAPPAGM\_CONTROL} &
319 isopycnal diffusivity \\
320 \end{tabular}
321 %
322 \end{itemize}
323
324 \subsubsection{File {\it SIZE.h}}
325 \label{www:tutorials}
326
327 The file contains the grid point dimensions of the forward
328 model. It is identical to the {\it verification/exp2/}: \\
329 \hspace*{4ex} {\tt sNx = 90} \\
330 \hspace*{4ex} {\tt sNy = 40} \\
331 \hspace*{4ex} {\tt Nr = 20} \\
332 It corresponds to a single-tile/single-processor setup:
333 {\tt nSx = nSy = 1, nPx = nPy = 1},
334 with standard overlap dimensioning
335 {\tt OLx = OLy = 3}.
336
337 \subsubsection{File {\it adcommon.h}}
338 \label{www:tutorials}
339
340 This file contains common blocks of some adjoint variables
341 that are generated by TAMC.
342 The common blocks are used by the adjoint support routine
343 {\it addummy\_in\_stepping} which needs to access those variables:
344
345 \begin{tabular}{ll}
346 \hspace*{4ex} {\tt common /addynvars\_r/} &
347 \hspace*{4ex} is related to {\it DYNVARS.h} \\
348 \hspace*{4ex} {\tt common /addynvars\_cd/} &
349 \hspace*{4ex} is related to {\it DYNVARS.h} \\
350 \hspace*{4ex} {\tt common /addynvars\_diffkr/} &
351 \hspace*{4ex} is related to {\it DYNVARS.h} \\
352 \hspace*{4ex} {\tt common /addynvars\_kapgm/} &
353 \hspace*{4ex} is related to {\it DYNVARS.h} \\
354 \hspace*{4ex} {\tt common /adtr1\_r/} &
355 \hspace*{4ex} is related to {\it TR1.h} \\
356 \hspace*{4ex} {\tt common /adffields/} &
357 \hspace*{4ex} is related to {\it FFIELDS.h}\\
358 \end{tabular}
359
360 Note that if the structure of the common block changes in the
361 above header files of the forward code, the structure
362 of the adjoint common blocks will change accordingly.
363 Thus, it has to be made sure that the structure of the
364 adjoint common block in the hand-written file {\it adcommon.h}
365 complies with the automatically generated adjoint common blocks
366 in {\it adjoint\_model.F}.
367 The header file is enabled via the CPP-option
368 {\bf ALLOW\_AUTODIFF\_MONITOR}.
369
370 \subsubsection{File {\it tamc.h}}
371 \label{www:tutorials}
372
373 This routine contains the dimensions for TAMC checkpointing
374 and some indices relevant for storing ky computations.
375 %
376 \begin{itemize}
377 %
378 \item {\tt \#ifdef ALLOW\_TAMC\_CHECKPOINTING} \\
379 3-level checkpointing is enabled, i.e. the timestepping
380 is divided into three different levels (see Section \ref{???}).
381 The model state of the outermost ({\tt nchklev\_3}) and the
382 intermediate ({\tt nchklev\_2}) timestepping loop are stored to file
383 (handled in {\it the\_main\_loop}).
384 The innermost loop ({\tt nchklev\_1})
385 avoids I/O by storing all required variables
386 to common blocks. This storing may also be necessary if
387 no checkpointing is chosen
388 (nonlinear functions, if-statements, iterative loops, ...).
389 In the present example the dimensions are chosen as follows: \\
390 \hspace*{4ex} {\tt nchklev\_1 = 36 } \\
391 \hspace*{4ex} {\tt nchklev\_2 = 30 } \\
392 \hspace*{4ex} {\tt nchklev\_3 = 60 } \\
393 To guarantee that the checkpointing intervals span the entire
394 integration period the following relation must be satisfied: \\
395 \hspace*{4ex} {\tt nchklev\_1*nchklev\_2*nchklev\_3 $ \ge $ nTimeSteps} \\
396 where {\tt nTimeSteps} is either specified in {\it data}
397 or computed via \\
398 \hspace*{4ex} {\tt nTimeSteps = (endTime-startTime)/deltaTClock }.
399 %
400 \item {\tt \#undef ALLOW\_TAMC\_CHECKPOINTING} \\
401 No checkpointing is enabled.
402 In this case the relevant counter is {\tt nchklev\_0}.
403 Similar to above, the following relation has to be satisfied \\
404 \hspace*{4ex} {\tt nchklev\_0 $ \ge $ nTimeSteps}.
405 %
406 \end{itemize}
407
408 The following parameters may be worth describing: \\
409 %
410 \hspace*{4ex} {\tt isbyte} \\
411 \hspace*{4ex} {\tt maxpass} \\
412 ~
413
414 \subsubsection{File {\it makefile}}
415 \label{www:tutorials}
416
417 This file contains all relevant parameter flags and
418 lists to run TAMC or TAF.
419 It is assumed that TAMC is available to you, either locally,
420 being installed on your network, or remotely through the 'TAMC Utility'.
421 TAMC is called with the command {\tt tamc} followed by a
422 number of options. They are described in detail in the
423 TAMC manual \cite{gie:99}.
424 Here we briefly discuss the main flags used in the {\it makefile}.
425 The standard output for TAF is written to file
426 {\it taf.log}.
427 %
428 \begin{itemize}
429 \item [{\tt tamc}] {\tt
430 -input <variable names>
431 -output <variable name> -i4 -r4 ... \\
432 -toplevel <S/R name> -reverse <file names>
433 }
434 \item [{\tt taf}] {\tt
435 -input <variable names>
436 -output <variable name> -i4 -r4 ... \\
437 -toplevel <S/R name> -reverse <file names> \\
438 -flow taf\_flow.log -nonew\_arg
439 }
440 \end{itemize}
441 %
442 \begin{itemize}
443 %
444 \item {\tt -toplevel <S/R name>} \\
445 Name of the toplevel routine, with respect to which the
446 control flow analysis is performed.
447 %
448 \item {\tt -input <variable names>} \\
449 List of independent variables $ u $ with respect to which the
450 dependent variable $ J $ is differentiated.
451 %
452 \item {\tt -output <variable name>} \\
453 Dependent variable $ J $ which is to be differentiated.
454 %
455 \item {\tt -reverse <file names>} \\
456 Adjoint code is generated to compute the sensitivity of an
457 independent variable w.r.t. many dependent variables.
458 In the discussion of Section ???
459 the generated adjoint top-level routine computes the product
460 of the transposed Jacobian matrix $ M^T $ times
461 the gradient vector $ \nabla_v J $.
462 \\
463 {\tt <file names>} refers to the list of files {\it .f} which are to be
464 analyzed by TAMC. This list is generally smaller than the full list
465 of code to be compiled. The files not contained are either
466 above the top-level routine (some initializations), or are
467 deliberately hidden from TAMC, either because hand-written
468 adjoint routines exist, or the routines must not (or don't have to)
469 be differentiated. For each routine which is part of the flow tree
470 of the top-level routine, but deliberately hidden from TAMC
471 (or for each package which contains such routines),
472 a corresponding file {\it .flow} exists containing flow directives
473 for TAMC.
474 %
475 \item {\tt -i4 -r4} \\
476 ~
477 %
478 \item {\tt -flow taf\_flow.log} \\
479 Will cause TAF to produce a flow listing file
480 named {\it taf\_flow.log} in which
481 the set of active and passive variables are identified
482 for each subroutine.
483 %
484 \item {\tt -nonew\_arg} \\
485 The default in the order of the parameter list of
486 adjoint routines has changed.
487 Before TAF 1.3 the default was compatible with the
488 TAMC-generated list. As of TAF 1.3 the order of adjoint
489 routine parameter lists is no longer copatible with TAMC.
490 To restore compatibility when using TAF 1.3 and higher,
491 this argument is needed.
492 It is currently crucial to use since all hand-written
493 adjoint routines refer to the TAMC default.
494 %
495 \end{itemize}
496
497
498 \subsubsection{The input parameter files}
499 \label{www:tutorials}
500
501 \paragraph{File {\it data}}
502
503 \paragraph{File {\it data.cost}}
504
505 \paragraph{File {\it data.ctrl}}
506
507 \paragraph{File {\it data.gmredi}}
508
509 \paragraph{File {\it data.grdchk}}
510
511 \paragraph{File {\it data.optim}}
512
513 \paragraph{File {\it data.pkg}}
514
515 \paragraph{File {\it eedata}}
516
517 \paragraph{File {\it topog.bin}} ~ \\
518 %
519 Contains two-dimendional bathymetry information
520
521 \paragraph{File {\it windx.bin, windy.bin, salt.bin, theta.bin,
522 SSS.bin, SST.bin}} ~ \\
523 %
524 These contain the initial values
525 (salinity, temperature, {\it salt.bin, theta.bin}),
526 surface boundary values (surface wind stresses,
527 ({\it windx.bin, windy.bin}), and surface restoring fields
528 ({\it SSS.bin, SST.bin}).
529
530 \paragraph{File {\it pickup*}} ~ \\
531 %
532 Contains model state after model spinup.
533
534 \subsection{Compiling the model and its adjoint}
535 \label{www:tutorials}
536
537 The built process of the adjoint model is slightly more
538 complex than that of compiling the forward code.
539 The main reason is that the adjoint code generation requires
540 a specific list of routines that are to be differentiated
541 (as opposed to the automatic generation of a list of
542 files to be compiled by genmake).
543 This list excludes routines that don't have to be or must not be
544 differentiated. For some of the latter routines flow directives
545 may be necessary, a list of which has to be given as well.
546 For this reason, a separate {\it makefile} is currently
547 maintained in the directory {\tt adjoint/}. This
548 makefile is responsible for the adjoint code generation.
549
550 In the following we describe the build process step by step,
551 assuming you are in the directory {\tt bin/}.
552 A summary of steps to follow is given at the end.
553
554 \paragraph{Adjoint code generation and compilation -- step by step}
555
556 \begin{enumerate}
557 %
558 \item
559 {\tt ln -s ../verification/???/code/.genmakerc .} \\
560 {\tt ln -s ../verification/???/code/*.[Fh] .} \\
561 Link your customized genmake options, header files,
562 and modified code to the compile directory.
563 %
564 \item
565 {\tt ../tools/genmake -makefile} \\
566 Generate your Makefile (cf. Section ???).
567 %
568 \item
569 {\tt make depend} \\
570 Dependency analysis for the CPP pre-compiler (cf. Section ???).
571 %
572 \item
573 {\tt cd ../adjoint} \\
574 {\tt make adtaf} or {\tt make adtamc} \\
575 Depending on whether you have TAF or TAMC at your disposal,
576 you'll choose {\tt adtaf} or {\tt adtamc} as your
577 make target for the {\it makefile} in the directory {\tt adjoint/}.
578 Several things happen at this stage.
579 %
580 \begin{enumerate}
581 %
582 \item
583 {\tt make adrestore, make ftlrestore} \\
584 The initial template files {\it adjoint\_model.F}
585 and {\it tangentlinear\_model.F} in {\it pkg/autodiff}
586 which are part
587 of the compiling list created by {\it genmake} are restored.
588 %
589 \item {\tt make depend, make small\_f} \\
590 The {\tt bin/} directory is brought up to date,
591 i.e. for recent changes in header or source code
592 {\it .[Fh]}, corresponding {\it .f} routines are generated
593 or re-generated.
594 Note that here, only CPP precompiling is performed;
595 no object code {\it .o} is generated as yet.
596 Precompiling is necessary for TAMC to see the full code.
597 %
598 \item
599 {\tt make allcode} \\
600 All Fortran routines {\tt *.f} in {\tt bin/} are
601 concatenated into a single file called
602 {\it tamc\_code.f}.
603 %
604 \item
605 {\tt make admodeltaf/admodeltamc} \\
606 Adjoint code is generated by TAMC or TAF.
607 The adjoint code is written to the file {\it tamc\_code\_ad.f}.
608 It contains all adjoint routines of the forward routines
609 concatenated in {\it tamc\_code.f}.
610 For a given forward routines {\tt subroutine routinename}
611 the adjoint routine is named {\tt adsubroutine routinename}
612 by default (that default can be changed via the flag
613 {\tt -admark <markname>}).
614 Furthermore, it may contain modified code which
615 incorporates the translation of adjoint store directives
616 into specific Fortran code.
617 For a given forward routines {\tt subroutine routinename}
618 the modified routine is named {\tt mdsubroutine routinename}.
619 TAMC or TAF info is written to file
620 {\it tamc\_code.prot} or {\it taf.log}, respectively.
621 %
622 \item
623 {\tt make adchange} \\
624 The multi-threading capability of MITgcm requires a slight
625 change in the parameter list of some routines that are related to
626 to active file handling.
627 This post-processing invokes the sed script {\it adjoint\_ecco\_sed.com}
628 to insert the threading counter {\bf myThId} into the parameter list
629 of those subroutines.
630 The resulting code is written to file {\it tamc\_code\_sed\_ad.f}
631 and appended to the file {\it adjoint\_model.F}.
632 This concludes the adjoint code generation.
633 %
634 \end{enumerate}
635 %
636 \item
637 {\tt cd ../bin} \\
638 {\tt make} \\
639 The file {\it adjoint\_model.F} now contains the full adjoint code.
640 All routines are now compiled.
641 %
642 \end{enumerate}
643
644 N.B.: The targets {\tt make adtaf/adtamc} now comprise a
645 series of targets that in previous versions had to be
646 invoked separarely. This was probably preferable at a more
647 experimental stage, but has now been dropped in favour of
648 a more straightforward build process.
649
650
651 \paragraph{Adjoint code generation and compilation -- summary}
652 ~ \\
653
654 {\small
655 \[
656 \boxed{
657 \begin{split}
658 ~ & \mbox{\tt cd bin} \\
659 ~ & \mbox{\tt ln -s ../verification/my\_experiment/code/.genmakerc .} \\
660 ~ & \mbox{\tt ln -s ../verification/my\_experiment/code/*.[Fh] .} \\
661 ~ & \mbox{\tt ../tools/genmake -makefile} \\
662 ~ & \mbox{\tt make depend} \\
663 ~ & \mbox{\tt cd ../adjoint} \\
664 ~ & \mbox{\tt make adtaf <OR: make adtamc>} \\
665 ~ & \hspace*{6ex} \mbox{\tt contains the targets:} \\
666 ~ & \hspace*{6ex} \mbox{\tt adrestore small\_f allcode admodeltaf/admodeltamc adchange} \\
667 ~ & \mbox{\tt cd ../bin} \\
668 ~ & \mbox{\tt make} \\
669 \end{split}
670 }
671 \]
672 }

  ViewVC Help
Powered by ViewVC 1.1.22