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 |
20 |
There are numerous ways that one can specify compile--time package |
There are numerous ways that one can specify compile--time package |
21 |
inclusion or exclusion and they are all implemented by the |
inclusion or exclusion and they are all implemented by the |
22 |
\texttt{genmake2} program which was previously described in Section |
\texttt{genmake2} program which was previously described in Section |
23 |
\ref{sect:buildingCode}. The options are as follows: |
\ref{sec:buildingCode}. The options are as follows: |
24 |
\begin{enumerate} |
\begin{enumerate} |
25 |
\item Setting the \texttt{genamake2} options \texttt{--enable PKG} |
\item Setting the \texttt{genamake2} options \texttt{--enable PKG} |
26 |
and/or \texttt{--disable PKG} specifies inclusion or exclusion. |
and/or \texttt{--disable PKG} specifies inclusion or exclusion. |
41 |
automatically obtains all packages in that group. |
automatically obtains all packages in that group. |
42 |
|
|
43 |
\item By default (that is, if a \texttt{packages.conf} file is not |
\item By default (that is, if a \texttt{packages.conf} file is not |
44 |
found), the \texttt{genmake2} program will use the contents of the |
found), the \texttt{genmake2} program will use the |
45 |
\texttt{pkg/pkg\_default} file to obtain a list of packages. |
package group default ``\texttt{default\_pkg\_list}'' as defined |
46 |
|
in \texttt{pkg/pkg\_groups} file. |
47 |
|
|
48 |
\item To help prevent users from creating unusable package groups, the |
\item To help prevent users from creating unusable package groups, the |
49 |
\texttt{genmake2} program will parse the contents of the |
\texttt{genmake2} program will parse the contents of the |
80 |
still be aware of the dependency. |
still be aware of the dependency. |
81 |
|
|
82 |
|
|
83 |
\section{Package Coding Standards} |
\subsection{Package Coding Standards} |
84 |
|
|
85 |
The following sections describe how to modify and/or create new MITgcm |
The following sections describe how to modify and/or create new MITgcm |
86 |
packages. |
packages. |
87 |
|
|
88 |
\subsection{Packages are Not Libraries} |
\subsubsection{Packages are Not Libraries} |
89 |
|
|
90 |
To a beginner, the MITgcm packages may resemble libraries as used in |
To a beginner, the MITgcm packages may resemble libraries as used in |
91 |
myriad software projects. While future versions are likely to |
myriad software projects. While future versions are likely to |
93 |
the current packages (FORTRAN77) are \textbf{not} based upon any |
the current packages (FORTRAN77) are \textbf{not} based upon any |
94 |
concept of libraries. |
concept of libraries. |
95 |
|
|
96 |
\subsubsection{File ``Hiding'' Rules} |
\subsubsection{File Inclusion Rules} |
97 |
|
|
98 |
Instead, packages should be viewed only as directories containing |
Instead, packages should be viewed only as directories containing |
99 |
``sets of source files'' that are built using some simple mechanisms |
``sets of source files'' that are built using some simple mechanisms |
116 |
previously encountered) then the file within the newer (more |
previously encountered) then the file within the newer (more |
117 |
recently visited) package will superseed (or ``hide'') any |
recently visited) package will superseed (or ``hide'') any |
118 |
previous file(s) with the same name. |
previous file(s) with the same name. |
119 |
|
|
120 |
\item Packages are visited (and thus files discovered) {\it in the |
\item Packages are visited (and thus files discovered) {\it in the |
121 |
order that the packages are enabled} within \texttt{genmake2}. |
order that the packages are enabled} within \texttt{genmake2}. |
122 |
Thus, the files in \texttt{PackB} may superseed the files in |
Thus, the files in \texttt{PackB} may superseed the files in |
123 |
\texttt{PackA} if \texttt{PackA} is enabled before |
\texttt{PackA} if \texttt{PackA} is enabled before \texttt{PackB}. |
124 |
\texttt{PackB}. Thus, package ordering can be significant! |
Thus, package ordering can be significant! For this reason, |
125 |
|
\texttt{genmake2} honors the order in which packages are |
126 |
|
specified. |
127 |
\end{enumerate} |
\end{enumerate} |
128 |
\end{enumerate} |
\end{enumerate} |
129 |
|
|
164 |
\end{verbatim} |
\end{verbatim} |
165 |
which is included from the file |
which is included from the file |
166 |
\filelink{calc\_diffusivity.F}{model-src-calc_diffusivity.F} |
\filelink{calc\_diffusivity.F}{model-src-calc_diffusivity.F} |
167 |
|
and shows how both the compile--time \texttt{ALLOW\_GMREDI} flag and the |
168 |
|
run--time \texttt{useGMRedi} are nested. |
169 |
|
|
170 |
There are some benefits to using this technique. The first is that |
There are some benefits to using the technique described here. The |
171 |
code snippets or subroutines associated with packages can be placed or |
first is that code snippets or subroutines associated with packages |
172 |
called from almost anywhere else within the code. The second benefit |
can be placed or called from almost anywhere else within the code. |
173 |
is related to the memory footprint and performance. Since unused code |
The second benefit is related to memory footprint and performance. |
174 |
can be removed, there is no performance penalty due to unnecessary |
Since unused code can be removed, there is no performance penalty due |
175 |
memory allocation or unused function calls. The major problems with |
to unnecessary memory allocation, unused function calls, or extra |
176 |
this approach are difficult-to-read and difficult-to-test code caused |
run-time \texttt{IF (...)} conditions. The major problems with this |
177 |
by the numerous CPP statements. Developers should exerecise some |
approach are the potentially difficult-to-read and difficult-to-debug |
178 |
discipline and avoid ``smearing'' implementation details across |
code caused by an overuse of CPP statements. So while it can be done, |
179 |
numerous files in a haphazard fashion. |
developers should exerecise some discipline and avoid unnecesarily |
180 |
|
``smearing'' their package implementation details across numerous |
181 |
|
files. |
182 |
|
|
183 |
|
|
184 |
|
\subsubsection{Package Startup or Boot Sequence} |
185 |
|
|
186 |
|
Calls to package routines within the core code timestepping loop can |
187 |
|
vary. However, all packages should follow a required "boot" sequence |
188 |
|
outlined here: |
189 |
|
|
190 |
|
{\footnotesize |
191 |
\subsection{Interfaces} |
\begin{verbatim} |
192 |
|
1. S/R PACKAGES_BOOT() |
193 |
|
: |
194 |
|
CALL OPEN_COPY_DATA_FILE( 'data.pkg', 'PACKAGES_BOOT', ... ) |
195 |
|
|
196 |
|
|
197 |
|
2. S/R PACKAGES_READPARMS() |
198 |
|
: |
199 |
|
#ifdef ALLOW_${PKG} |
200 |
|
if ( use${Pkg} ) |
201 |
|
& CALL ${PKG}_READPARMS( retCode ) |
202 |
|
#endif |
203 |
|
|
204 |
|
3. S/R PACKAGES_INIT_FIXED() |
205 |
|
: |
206 |
|
#ifdef ALLOW_${PKG} |
207 |
|
if ( use${Pkg} ) |
208 |
|
& CALL ${PKG}_INIT_FIXED( retCode ) |
209 |
|
#endif |
210 |
|
|
211 |
|
4. S/R PACKAGES_CHECK() |
212 |
|
: |
213 |
|
#ifdef ALLOW_${PKG} |
214 |
|
if ( use${Pkg} ) |
215 |
|
& CALL ${PKG}_CHECK( retCode ) |
216 |
|
#else |
217 |
|
if ( use${Pkg} ) |
218 |
|
& CALL PACKAGES_CHECK_ERROR('${PKG}') |
219 |
|
#endif |
220 |
|
|
221 |
|
5. S/R PACKAGES_INIT_VARIABLES() |
222 |
|
: |
223 |
|
#ifdef ALLOW_${PKG} |
224 |
|
if ( use${Pkg} ) |
225 |
|
& CALL ${PKG}_INIT_VARIA( ) |
226 |
|
#endif |
227 |
|
|
228 |
|
6. S/R DO_THE_MODEL_IO |
229 |
|
|
230 |
|
#ifdef ALLOW_${PKG} |
231 |
|
if ( use${Pkg} ) |
232 |
|
& CALL ${PKG}_OUTPUT( ) |
233 |
|
#endif |
234 |
|
|
235 |
|
7. S/R PACKAGES_WRITE_PICKUP() |
236 |
|
|
237 |
|
#ifdef ALLOW_${PKG} |
238 |
|
if ( use${Pkg} ) |
239 |
|
& CALL ${PKG}_WRITE_PICKUP( ) |
240 |
|
#endif\end{verbatim} |
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
|
\subsubsection{Adding a package to PARAMS.h and packages\_boot()} |
245 |
|
|
246 |
|
An MITgcm package directory contains all the code needed for that package apart |
247 |
|
from one variable for each package. This variable is the {\it use\$\{Pkg\} } |
248 |
|
flag. This flag, which is of type logical, {\bf must} be declared in the |
249 |
|
shared header file {\it PARAMS.h} in the {\it PARM\_PACKAGES} block. This |
250 |
|
convention is used to support a single runtime control file {\it data.pkg} |
251 |
|
which is read by the startup routine {\it packages\_boot()} and that sets a |
252 |
|
flag controlling the runtime use of a package. This routine needs to be able to |
253 |
|
read the flags for packages that were not built at compile time. Therefore |
254 |
|
when adding a new package, in addition to creating the per-package directory |
255 |
|
in the {\it pkg/} subdirectory a developer should add a {\it use\$\{Pkg\} } |
256 |
|
flag to {\it PARAMS.h} and a {\it use\$\{Pkg\} } entry to the |
257 |
|
{\it packages\_boot()} {\it PACKAGES} namelist. |
258 |
|
The only other package specific code that should appear outside the individual |
259 |
|
package directory are calls to the specific package API. |
260 |
|
|
261 |
|
|