/[MITgcm]/manual/s_phys_pkgs/text/packages.tex
ViewVC logotype

Diff of /manual/s_phys_pkgs/text/packages.tex

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

revision 1.1 by edhill, Wed Feb 11 18:09:17 2004 UTC revision 1.5 by cnh, Wed Oct 13 12:27:57 2004 UTC
# Line 2  Line 2 
2  % $Name$  % $Name$
3    
4  \section{Using MITgcm Packages}  \section{Using MITgcm Packages}
5    \label{sec:pkg:using}
6    \begin{rawhtml}
7    <!-- CMIREDIR:package_using: -->
8    \end{rawhtml}
9    
10  The set of packages that will be used within a partiucular model can  The set of packages that will be used within a partiucular model can
11  be configured using a combination of both ``compile--time'' and  be configured using a combination of both ``compile--time'' and
# Line 63  inclusion or exclusion and they are all Line 67  inclusion or exclusion and they are all
67    
68  For run--time package control, MITgcm uses flags set through a  For run--time package control, MITgcm uses flags set through a
69  \texttt{data.pkg} file.  While some packages (\textit{eg.}  \texttt{data.pkg} file.  While some packages (\textit{eg.}
70  \texttt{debug}, \texttt{mnc}, \texttt{cost}) may have their own  \texttt{debug}, \texttt{mnc}, \texttt{exch2}) may have their own usage
71  conventions, most follow a simple flag naming convention of the  conventions, most follow a simple flag naming convention of the form:
 form:  
72  \begin{verbatim}  \begin{verbatim}
73    usePackageName=.TRUE.    usePackageName=.TRUE.
74  \end{verbatim}  \end{verbatim}
75  where the \texttt{usePackageName} variable can activate or disable the  where the \texttt{usePackageName} variable can activate or disable the
76  package at runtime.  package at runtime.  As mentioned previously, packages must be
77    included in order to be activated.  Generally, such mistakes will be
78    detected and reported as errors by the code.  However, users should
79    still be aware of the dependency.
80    
81    
82  %\subsection{Modifying or Creating Packages}  \section{Package Coding Standards}
83    
84    The following sections describe how to modify and/or create new MITgcm
85    packages.
86    
87    \subsection{Packages are Not Libraries}
88    
89    To a beginner, the MITgcm packages may resemble libraries as used in
90    myriad software projects.  While future versions are likely to
91    implement packages as libraries (perhaps using FORTRAN90/95 syntax)
92    the current packages (FORTRAN77) are \textbf{not} based upon any
93    concept of libraries.
94    
95    \subsubsection{File Inclusion Rules}
96    
97    Instead, packages should be viewed only as directories containing
98    ``sets of source files'' that are built using some simple mechanisms
99    provided by \texttt{genmake2}.  Conceptually, the build process adds
100    files as they are found and proceeds according to the following rules:
101    \begin{enumerate}
102    \item \texttt{genmake2} locates a ``core'' or main set of source files
103      (the \texttt{-standarddirs} option sets these locations and the
104      default value contains the directories \texttt{eesupp} and
105      \texttt{model}).
106      
107    \item \texttt{genmake2} then finds additional source files by
108      inspecting the contents of each of the package directories:
109      \begin{enumerate}
110      \item As the new files are found, they are added to a list of source
111        files.
112    
113      \item If there is a file name ``collision'' (that is, if one of the
114        files in a package has the same name as one of the files
115        previously encountered) then the file within the newer (more
116        recently visited) package will superseed (or ``hide'') any
117        previous file(s) with the same name.
118        
119      \item Packages are visited (and thus files discovered) {\it in the
120          order that the packages are enabled} within \texttt{genmake2}.
121        Thus, the files in \texttt{PackB} may superseed the files in
122        \texttt{PackA} if \texttt{PackA} is enabled before \texttt{PackB}.
123        Thus, package ordering can be significant!  For this reason,
124        \texttt{genmake2} honors the order in which packages are
125        specified.
126      \end{enumerate}
127    \end{enumerate}
128    
129    These rules were adopted since they provide a relatively simple means
130    for rapidly including (or ``hiding'') existing files with modified
131    versions.
132    
133    \subsubsection{Conditional Compilation and \texttt{PACKAGES\_CONFIG.h}}
134    
135    Given that packages are simply groups of files that may be added or
136    removed to form a whole, one may wonder how linking (that is, FORTRAN
137    symbol resolution) is handled.  This is the second way that
138    \texttt{genmake2} supports the concept of packages.  Basically,
139    \texttt{genmake2} creates a \texttt{Makefile} that, in turn, is able
140    to create a file called \texttt{PACKAGES\_CONFIG.h} that contains a set
141    of C pre-processor (or ``CPP'') directives such as:
142    \begin{verbatim}
143       #undef  ALLOW_KPP
144       #undef  ALLOW_LAND
145       ...
146       #define ALLOW_GENERIC_ADVDIFF
147       #define ALLOW_MDSIO
148       ...
149    \end{verbatim}
150    These CPP symbols are then used throughout the code to conditionally
151    isolate variable definitions, function calls, or any other code that
152    depends upon the presence or absence of any particular package.
153    
154    An example illustrating the use of these defines is:
155    \begin{verbatim}
156       #ifdef ALLOW_GMREDI
157             IF (useGMRedi) CALL GMREDI_CALC_DIFF(
158            I        bi,bj,iMin,iMax,jMin,jMax,K,
159            I        maskUp,
160            O        KappaRT,KappaRS,
161            I        myThid)
162       #endif
163    \end{verbatim}
164    which is included from the file
165    \filelink{calc\_diffusivity.F}{model-src-calc_diffusivity.F}
166    and shows how both the compile--time \texttt{ALLOW\_GMREDI} flag and the
167    run--time \texttt{useGMRedi} are nested.
168    
169    There are some benefits to using the technique described here.  The
170    first is that code snippets or subroutines associated with packages
171    can be placed or called from almost anywhere else within the code.
172    The second benefit is related to memory footprint and performance.
173    Since unused code can be removed, there is no performance penalty due
174    to unnecessary memory allocation, unused function calls, or extra
175    run-time \texttt{IF (...)} conditions.  The major problems with this
176    approach are the potentially difficult-to-read and difficult-to-debug
177    code caused by an overuse of CPP statements.  So while it can be done,
178    developers should exerecise some discipline and avoid unnecesarily
179    ``smearing'' their package implementation details across numerous
180    files.
181    
182    
183    \subsubsection{Package Startup or Boot Sequence}
184    
185    Calls to package routines within the core code timestepping loop can
186    vary.  However, all packages should follow a required "boot" sequence
187    outlined here:
188    
189    {\footnotesize
190    \begin{verbatim}
191        1. S/R PACKAGES_BOOT()
192                :
193            CALL OPEN_COPY_DATA_FILE( 'data.pkg', 'PACKAGES_BOOT', ... )
194    
195    
196        2. S/R PACKAGES_READPARMS()
197                :
198            #ifdef ALLOW_${PKG}
199              if ( use${Pkg} )
200         &       CALL ${PKG}_READPARMS( retCode )
201            #endif
202    
203        3. S/R PACKAGES_INIT_FIXED()
204                :
205            #ifdef ALLOW_${PKG}
206              if ( use${Pkg} )
207         &       CALL ${PKG}_INIT_FIXED( retCode )
208            #endif
209    
210        4. S/R PACKAGES_CHECK()
211                :
212            #ifdef ALLOW_${PKG}
213              if ( use${Pkg} )
214         &       CALL ${PKG}_CHECK( retCode )
215            #else
216              if ( use${Pkg} )
217         &       CALL PACKAGES_CHECK_ERROR('${PKG}')
218            #endif
219    
220        5. S/R PACKAGES_INIT_VARIABLES()
221                :
222            #ifdef ALLOW_${PKG}
223              if ( use${Pkg} )
224         &       CALL ${PKG}_INIT_VARIA( )
225            #endif
226    
227         6. S/R DO_THE_MODEL_IO
228    
229            #ifdef ALLOW_${PKG}
230              if ( use${Pkg} )
231         &       CALL ${PKG}_DIAGS( )
232            #endif
233    
234         7. S/R PACKAGES_WRITE_PICKUP()
235    
236            #ifdef ALLOW_${PKG}
237              if ( use${Pkg} )
238         &       CALL ${PKG}_WRITE_PICKUP( )
239            #endif\end{verbatim}
240    }
241    
242    
243    \subsubsection{Adding a package to PARAMS.h and  packages\_boot()}
244    
245    An MITgcm package directory contains all the code needed for that package apart
246    from one variable for each package. This variable is the {\tt use\$\{Pkg\} }
247    flag. This flag, which is of type logical, {\bf must} be declared in the
248    shared header file {\it PARAMS.h} in the {\it PARM\_PACKAGES} block. This
249    convention is used to support a single runtime control file {\it data.pkg}
250    which is read by the startup routine {\it packages\_boot()} and that sets a
251    flag controlling the runtime use of a package. This routine needs to be able to
252    read the flags for packages that were not built at compile time. Therefore
253    when adding a new package, in addition to creating the per-package directory
254    in the {\it pkg/} subdirectory a developer should add a {\tt use\$\{Pkg\} }
255    flag to {\it PARAMS.h} and a {\tt use\$\{Pkg\} } entry to the
256    {\it packages\_boot()} {\it PACKAGES} namelist.
257    The only other package specific code that should appear outside the individual
258    package directory are calls to the specific package API.
259    
260    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.22