Home Contact Us Site Map  
 
       
    next up previous contents
Next: 3.20 Offline Example Up: 3.19 Sensitivity of Air-Sea Previous: 3.19.2 Code configuration   Contents

Subsections

3.19.3 Compiling the model and its adjoint

The built process of the adjoint model is slightly more complex than that of compiling the forward code. The main reason is that the adjoint code generation requires a specific list of routines that are to be differentiated (as opposed to the automatic generation of a list of files to be compiled by genmake). This list excludes routines that don't have to be or must not be differentiated. For some of the latter routines flow directives may be necessary, a list of which has to be given as well. For this reason, a separate makefile is currently maintained in the directory adjoint/. This makefile is responsible for the adjoint code generation.

In the following we describe the build process step by step, assuming you are in the directory bin/. A summary of steps to follow is given at the end.

3.19.3.0.1 Adjoint code generation and compilation - step by step

  1. ln -s ../verification/???/code/.genmakerc .
    ln -s ../verification/???/code/*.[Fh] .
    Link your customized genmake options, header files, and modified code to the compile directory.
  2. ../tools/genmake -makefile
    Generate your Makefile (cf. Section ???).
  3. make depend
    Dependency analysis for the CPP pre-compiler (cf. Section ???).
  4. cd ../adjoint
    make adtaf or make adtamc
    Depending on whether you have TAF or TAMC at your disposal, you'll choose adtaf or adtamc as your make target for the makefile in the directory adjoint/. Several things happen at this stage.
    1. make adrestore, make ftlrestore
      The initial template files adjoint_model.F and tangentlinear_model.F in pkg/autodiff which are part of the compiling list created by genmake are restored.
    2. make depend, make small_f
      The bin/ directory is brought up to date, i.e. for recent changes in header or source code .[Fh], corresponding .f routines are generated or re-generated. Note that here, only CPP precompiling is performed; no object code .o is generated as yet. Precompiling is necessary for TAMC to see the full code.
    3. make allcode
      All Fortran routines *.f in bin/ are concatenated into a single file called tamc_code.f.
    4. make admodeltaf/admodeltamc
      Adjoint code is generated by TAMC or TAF. The adjoint code is written to the file tamc_code_ad.f. It contains all adjoint routines of the forward routines concatenated in tamc_code.f. For a given forward routines subroutine routinename the adjoint routine is named adsubroutine routinename by default (that default can be changed via the flag -admark <markname>). Furthermore, it may contain modified code which incorporates the translation of adjoint store directives into specific Fortran code. For a given forward routines subroutine routinename the modified routine is named mdsubroutine routinename. TAMC or TAF info is written to file tamc_code.prot or taf.log, respectively.
    5. make adchange
      The multi-threading capability of MITgcm requires a slight change in the parameter list of some routines that are related to to active file handling. This post-processing invokes the sed script adjoint_ecco_sed.com to insert the threading counter myThId into the parameter list of those subroutines. The resulting code is written to file tamc_code_sed_ad.f and appended to the file adjoint_model.F. This concludes the adjoint code generation.
  5. cd ../bin
    make
    The file adjoint_model.F now contains the full adjoint code. All routines are now compiled.

N.B.: The targets make adtaf/adtamc now comprise a series of targets that in previous versions had to be invoked separarely. This was probably preferable at a more experimental stage, but has now been dropped in favour of a more straightforward build process.

3.19.3.0.2 Adjoint code generation and compilation - summary

 

\begin{equation*}
\boxed{
\begin{aligned}
~ & \mbox{\tt cd bin} \\
~ & \mbox{...
...\mbox{\tt cd ../bin} \\
~ & \mbox{\tt make} \\
\end{aligned}}
\end{equation*}


next up previous contents
Next: 3.20 Offline Example Up: 3.19 Sensitivity of Air-Sea Previous: 3.19.2 Code configuration   Contents
mitgcm-support@mitgcm.org
Copyright © 2006 Massachusetts Institute of Technology Last update 2011-01-09