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

Annotation of /manual/s_autodiff/doc_ad_examples.tex

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


Revision 1.4 - (hide annotations) (download) (as text)
Wed Apr 24 19:23:58 2002 UTC (23 years, 2 months ago) by adcroft
Branch: MAIN
Changes since 1.3: +2 -1 lines
File MIME type: application/x-tex
Re-created labels for tutorials but down one section level

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

  ViewVC Help
Powered by ViewVC 1.1.22