1 |
\section[Customizing MITgcm]{Doing it yourself: customizing the code} |
\section[Customizing MITgcm]{Doing it yourself: customizing the code} |
2 |
|
\label{sect:customize} |
3 |
|
\begin{rawhtml} |
4 |
|
<!-- CMIREDIR:customizing_mitgcm: --> |
5 |
|
\end{rawhtml} |
6 |
|
|
7 |
When you are ready to run the model in the configuration you want, the |
When you are ready to run the model in the configuration you want, the |
8 |
easiest thing is to use and adapt the setup of the case studies |
easiest thing is to use and adapt the setup of the case studies |
13 |
part is covered in the parallel implementation section) and on the |
part is covered in the parallel implementation section) and on the |
14 |
variables and parameters that you are likely to change. |
variables and parameters that you are likely to change. |
15 |
|
|
16 |
|
|
17 |
|
\subsection{Building/compiling the code elsewhere} |
18 |
|
|
19 |
|
In the example above (section \ref{sect:buildingCode}) we built the |
20 |
|
executable in the {\em input} directory of the experiment for |
21 |
|
convenience. You can also configure and compile the code in other |
22 |
|
locations, for example on a scratch disk with out having to copy the |
23 |
|
entire source tree. The only requirement to do so is you have {\tt |
24 |
|
genmake2} in your path or you know the absolute path to {\tt |
25 |
|
genmake2}. |
26 |
|
|
27 |
|
The following sections outline some possible methods of organizing |
28 |
|
your source and data. |
29 |
|
|
30 |
|
\subsubsection{Building from the {\em ../code directory}} |
31 |
|
|
32 |
|
This is just as simple as building in the {\em input/} directory: |
33 |
|
\begin{verbatim} |
34 |
|
% cd verification/exp2/code |
35 |
|
% ../../../tools/genmake2 |
36 |
|
% make depend |
37 |
|
% make |
38 |
|
\end{verbatim} |
39 |
|
However, to run the model the executable ({\em mitgcmuv}) and input |
40 |
|
files must be in the same place. If you only have one calculation to make: |
41 |
|
\begin{verbatim} |
42 |
|
% cd ../input |
43 |
|
% cp ../code/mitgcmuv ./ |
44 |
|
% ./mitgcmuv > output.txt |
45 |
|
\end{verbatim} |
46 |
|
or if you will be making multiple runs with the same executable: |
47 |
|
\begin{verbatim} |
48 |
|
% cd ../ |
49 |
|
% cp -r input run1 |
50 |
|
% cp code/mitgcmuv run1 |
51 |
|
% cd run1 |
52 |
|
% ./mitgcmuv > output.txt |
53 |
|
\end{verbatim} |
54 |
|
|
55 |
|
\subsubsection{Building from a new directory} |
56 |
|
|
57 |
|
Since the {\em input} directory contains input files it is often more |
58 |
|
useful to keep {\em input} pristine and build in a new directory |
59 |
|
within {\em verification/exp2/}: |
60 |
|
\begin{verbatim} |
61 |
|
% cd verification/exp2 |
62 |
|
% mkdir build |
63 |
|
% cd build |
64 |
|
% ../../../tools/genmake2 -mods=../code |
65 |
|
% make depend |
66 |
|
% make |
67 |
|
\end{verbatim} |
68 |
|
This builds the code exactly as before but this time you need to copy |
69 |
|
either the executable or the input files or both in order to run the |
70 |
|
model. For example, |
71 |
|
\begin{verbatim} |
72 |
|
% cp ../input/* ./ |
73 |
|
% ./mitgcmuv > output.txt |
74 |
|
\end{verbatim} |
75 |
|
or if you tend to make multiple runs with the same executable then |
76 |
|
running in a new directory each time might be more appropriate: |
77 |
|
\begin{verbatim} |
78 |
|
% cd ../ |
79 |
|
% mkdir run1 |
80 |
|
% cp build/mitgcmuv run1/ |
81 |
|
% cp input/* run1/ |
82 |
|
% cd run1 |
83 |
|
% ./mitgcmuv > output.txt |
84 |
|
\end{verbatim} |
85 |
|
|
86 |
|
\subsubsection{Building on a scratch disk} |
87 |
|
|
88 |
|
Model object files and output data can use up large amounts of disk |
89 |
|
space so it is often the case that you will be operating on a large |
90 |
|
scratch disk. Assuming the model source is in {\em ~/MITgcm} then the |
91 |
|
following commands will build the model in {\em /scratch/exp2-run1}: |
92 |
|
\begin{verbatim} |
93 |
|
% cd /scratch/exp2-run1 |
94 |
|
% ~/MITgcm/tools/genmake2 -rootdir=~/MITgcm \ |
95 |
|
-mods=~/MITgcm/verification/exp2/code |
96 |
|
% make depend |
97 |
|
% make |
98 |
|
\end{verbatim} |
99 |
|
To run the model here, you'll need the input files: |
100 |
|
\begin{verbatim} |
101 |
|
% cp ~/MITgcm/verification/exp2/input/* ./ |
102 |
|
% ./mitgcmuv > output.txt |
103 |
|
\end{verbatim} |
104 |
|
|
105 |
|
As before, you could build in one directory and make multiple runs of |
106 |
|
the one experiment: |
107 |
|
\begin{verbatim} |
108 |
|
% cd /scratch/exp2 |
109 |
|
% mkdir build |
110 |
|
% cd build |
111 |
|
% ~/MITgcm/tools/genmake2 -rootdir=~/MITgcm \ |
112 |
|
-mods=~/MITgcm/verification/exp2/code |
113 |
|
% make depend |
114 |
|
% make |
115 |
|
% cd ../ |
116 |
|
% cp -r ~/MITgcm/verification/exp2/input run2 |
117 |
|
% cd run2 |
118 |
|
% ./mitgcmuv > output.txt |
119 |
|
\end{verbatim} |
120 |
|
|
121 |
|
|
122 |
|
\subsection{Using \texttt{genmake2}} |
123 |
|
\label{sect:genmake} |
124 |
|
|
125 |
|
To compile the code, first use the program \texttt{genmake2} (located |
126 |
|
in the \texttt{tools} directory) to generate a Makefile. |
127 |
|
\texttt{genmake2} is a shell script written to work with all |
128 |
|
``sh''--compatible shells including bash v1, bash v2, and Bourne. |
129 |
|
Internally, \texttt{genmake2} determines the locations of needed |
130 |
|
files, the compiler, compiler options, libraries, and Unix tools. It |
131 |
|
relies upon a number of ``optfiles'' located in the |
132 |
|
\texttt{tools/build\_options} directory. |
133 |
|
|
134 |
|
The purpose of the optfiles is to provide all the compilation options |
135 |
|
for particular ``platforms'' (where ``platform'' roughly means the |
136 |
|
combination of the hardware and the compiler) and code configurations. |
137 |
|
Given the combinations of possible compilers and library dependencies |
138 |
|
({\it eg.} MPI and NetCDF) there may be numerous optfiles available |
139 |
|
for a single machine. The naming scheme for the majority of the |
140 |
|
optfiles shipped with the code is |
141 |
|
\begin{center} |
142 |
|
{\bf OS\_HARDWARE\_COMPILER } |
143 |
|
\end{center} |
144 |
|
where |
145 |
|
\begin{description} |
146 |
|
\item[OS] is the name of the operating system (generally the |
147 |
|
lower-case output of the {\tt 'uname'} command) |
148 |
|
\item[HARDWARE] is a string that describes the CPU type and |
149 |
|
corresponds to output from the {\tt 'uname -m'} command: |
150 |
|
\begin{description} |
151 |
|
\item[ia32] is for ``x86'' machines such as i386, i486, i586, i686, |
152 |
|
and athlon |
153 |
|
\item[ia64] is for Intel IA64 systems (eg. Itanium, Itanium2) |
154 |
|
\item[amd64] is AMD x86\_64 systems |
155 |
|
\item[ppc] is for Mac PowerPC systems |
156 |
|
\end{description} |
157 |
|
\item[COMPILER] is the compiler name (generally, the name of the |
158 |
|
FORTRAN executable) |
159 |
|
\end{description} |
160 |
|
|
161 |
|
In many cases, the default optfiles are sufficient and will result in |
162 |
|
usable Makefiles. However, for some machines or code configurations, |
163 |
|
new ``optfiles'' must be written. To create a new optfile, it is |
164 |
|
generally best to start with one of the defaults and modify it to suit |
165 |
|
your needs. Like \texttt{genmake2}, the optfiles are all written |
166 |
|
using a simple ``sh''--compatible syntax. While nearly all variables |
167 |
|
used within \texttt{genmake2} may be specified in the optfiles, the |
168 |
|
critical ones that should be defined are: |
169 |
|
|
170 |
|
\begin{description} |
171 |
|
\item[FC] the FORTRAN compiler (executable) to use |
172 |
|
\item[DEFINES] the command-line DEFINE options passed to the compiler |
173 |
|
\item[CPP] the C pre-processor to use |
174 |
|
\item[NOOPTFLAGS] options flags for special files that should not be |
175 |
|
optimized |
176 |
|
\end{description} |
177 |
|
|
178 |
|
For example, the optfile for a typical Red Hat Linux machine (``ia32'' |
179 |
|
architecture) using the GCC (g77) compiler is |
180 |
|
\begin{verbatim} |
181 |
|
FC=g77 |
182 |
|
DEFINES='-D_BYTESWAPIO -DWORDLENGTH=4' |
183 |
|
CPP='cpp -traditional -P' |
184 |
|
NOOPTFLAGS='-O0' |
185 |
|
# For IEEE, use the "-ffloat-store" option |
186 |
|
if test "x$IEEE" = x ; then |
187 |
|
FFLAGS='-Wimplicit -Wunused -Wuninitialized' |
188 |
|
FOPTIM='-O3 -malign-double -funroll-loops' |
189 |
|
else |
190 |
|
FFLAGS='-Wimplicit -Wunused -ffloat-store' |
191 |
|
FOPTIM='-O0 -malign-double' |
192 |
|
fi |
193 |
|
\end{verbatim} |
194 |
|
|
195 |
|
If you write an optfile for an unrepresented machine or compiler, you |
196 |
|
are strongly encouraged to submit the optfile to the MITgcm project |
197 |
|
for inclusion. Please send the file to the |
198 |
|
\begin{rawhtml} <A href="mail-to:MITgcm-support@mitgcm.org"> \end{rawhtml} |
199 |
|
\begin{center} |
200 |
|
MITgcm-support@mitgcm.org |
201 |
|
\end{center} |
202 |
|
\begin{rawhtml} </A> \end{rawhtml} |
203 |
|
mailing list. |
204 |
|
|
205 |
|
In addition to the optfiles, \texttt{genmake2} supports a number of |
206 |
|
helpful command-line options. A complete list of these options can be |
207 |
|
obtained from: |
208 |
|
\begin{verbatim} |
209 |
|
% genmake2 -h |
210 |
|
\end{verbatim} |
211 |
|
|
212 |
|
The most important command-line options are: |
213 |
|
\begin{description} |
214 |
|
|
215 |
|
\item[\texttt{--optfile=/PATH/FILENAME}] specifies the optfile that |
216 |
|
should be used for a particular build. |
217 |
|
|
218 |
|
If no "optfile" is specified (either through the command line or the |
219 |
|
MITGCM\_OPTFILE environment variable), genmake2 will try to make a |
220 |
|
reasonable guess from the list provided in {\em |
221 |
|
tools/build\_options}. The method used for making this guess is |
222 |
|
to first determine the combination of operating system and hardware |
223 |
|
(eg. "linux\_ia32") and then find a working FORTRAN compiler within |
224 |
|
the user's path. When these three items have been identified, |
225 |
|
genmake2 will try to find an optfile that has a matching name. |
226 |
|
|
227 |
|
\item[\texttt{--pdefault='PKG1 PKG2 PKG3 ...'}] specifies the default |
228 |
|
set of packages to be used. The normal order of precedence for |
229 |
|
packages is as follows: |
230 |
|
\begin{enumerate} |
231 |
|
\item If available, the command line (\texttt{--pdefault}) settings |
232 |
|
over-rule any others. |
233 |
|
|
234 |
|
\item Next, \texttt{genmake2} will look for a file named |
235 |
|
``\texttt{packages.conf}'' in the local directory or in any of the |
236 |
|
directories specified with the \texttt{--mods} option. |
237 |
|
|
238 |
|
\item Finally, if neither of the above are available, |
239 |
|
\texttt{genmake2} will use the \texttt{/pkg/pkg\_default} file. |
240 |
|
\end{enumerate} |
241 |
|
|
242 |
|
\item[\texttt{--pdepend=/PATH/FILENAME}] specifies the dependency file |
243 |
|
used for packages. |
244 |
|
|
245 |
|
If not specified, the default dependency file {\em pkg/pkg\_depend} |
246 |
|
is used. The syntax for this file is parsed on a line-by-line basis |
247 |
|
where each line containes either a comment ("\#") or a simple |
248 |
|
"PKGNAME1 (+|-)PKGNAME2" pairwise rule where the "+" or "-" symbol |
249 |
|
specifies a "must be used with" or a "must not be used with" |
250 |
|
relationship, respectively. If no rule is specified, then it is |
251 |
|
assumed that the two packages are compatible and will function |
252 |
|
either with or without each other. |
253 |
|
|
254 |
|
\item[\texttt{--adof=/path/to/file}] specifies the "adjoint" or |
255 |
|
automatic differentiation options file to be used. The file is |
256 |
|
analogous to the ``optfile'' defined above but it specifies |
257 |
|
information for the AD build process. |
258 |
|
|
259 |
|
The default file is located in {\em |
260 |
|
tools/adjoint\_options/adjoint\_default} and it defines the "TAF" |
261 |
|
and "TAMC" compilers. An alternate version is also available at |
262 |
|
{\em tools/adjoint\_options/adjoint\_staf} that selects the newer |
263 |
|
"STAF" compiler. As with any compilers, it is helpful to have their |
264 |
|
directories listed in your {\tt \$PATH} environment variable. |
265 |
|
|
266 |
|
\item[\texttt{--mods='DIR1 DIR2 DIR3 ...'}] specifies a list of |
267 |
|
directories containing ``modifications''. These directories contain |
268 |
|
files with names that may (or may not) exist in the main MITgcm |
269 |
|
source tree but will be overridden by any identically-named sources |
270 |
|
within the ``MODS'' directories. |
271 |
|
|
272 |
|
The order of precedence for this "name-hiding" is as follows: |
273 |
|
\begin{itemize} |
274 |
|
\item ``MODS'' directories (in the order given) |
275 |
|
\item Packages either explicitly specified or provided by default |
276 |
|
(in the order given) |
277 |
|
\item Packages included due to package dependencies (in the order |
278 |
|
that that package dependencies are parsed) |
279 |
|
\item The "standard dirs" (which may have been specified by the |
280 |
|
``-standarddirs'' option) |
281 |
|
\end{itemize} |
282 |
|
|
283 |
|
\item[\texttt{--mpi}] This option enables certain MPI features (using |
284 |
|
CPP \texttt{\#define}s) within the code and is necessary for MPI |
285 |
|
builds (see Section \ref{sect:mpi-build}). |
286 |
|
|
287 |
|
\item[\texttt{--make=/path/to/gmake}] Due to the poor handling of |
288 |
|
soft-links and other bugs common with the \texttt{make} versions |
289 |
|
provided by commercial Unix vendors, GNU \texttt{make} (sometimes |
290 |
|
called \texttt{gmake}) should be preferred. This option provides a |
291 |
|
means for specifying the make executable to be used. |
292 |
|
|
293 |
|
\item[\texttt{--bash=/path/to/sh}] On some (usually older UNIX) |
294 |
|
machines, the ``bash'' shell is unavailable. To run on these |
295 |
|
systems, \texttt{genmake2} can be invoked using an ``sh'' (that is, |
296 |
|
a Bourne, POSIX, or compatible) shell. The syntax in these |
297 |
|
circumstances is: |
298 |
|
\begin{center} |
299 |
|
\texttt{\% /bin/sh genmake2 -bash=/bin/sh [...options...]} |
300 |
|
\end{center} |
301 |
|
where \texttt{/bin/sh} can be replaced with the full path and name |
302 |
|
of the desired shell. |
303 |
|
|
304 |
|
\end{description} |
305 |
|
|
306 |
|
|
307 |
|
\subsection{Building with MPI} |
308 |
|
\label{sect:mpi-build} |
309 |
|
|
310 |
|
Building MITgcm to use MPI libraries can be complicated due to the |
311 |
|
variety of different MPI implementations available, their dependencies |
312 |
|
or interactions with different compilers, and their often ad-hoc |
313 |
|
locations within file systems. For these reasons, its generally a |
314 |
|
good idea to start by finding and reading the documentation for your |
315 |
|
machine(s) and, if necessary, seeking help from your local systems |
316 |
|
administrator. |
317 |
|
|
318 |
|
The steps for building MITgcm with MPI support are: |
319 |
|
\begin{enumerate} |
320 |
|
|
321 |
|
\item Determine the locations of your MPI-enabled compiler and/or MPI |
322 |
|
libraries and put them into an options file as described in Section |
323 |
|
\ref{sect:genmake}. One can start with one of the examples in: |
324 |
|
\begin{rawhtml} <A |
325 |
|
href="http://mitgcm.org/cgi-bin/viewcvs.cgi/MITgcm/tools/build_options/"> |
326 |
|
\end{rawhtml} |
327 |
|
\begin{center} |
328 |
|
\texttt{MITgcm/tools/build\_options/} |
329 |
|
\end{center} |
330 |
|
\begin{rawhtml} </A> \end{rawhtml} |
331 |
|
such as \texttt{linux\_ia32\_g77+mpi\_cg01} or |
332 |
|
\texttt{linux\_ia64\_efc+mpi} and then edit it to suit the machine at |
333 |
|
hand. You may need help from your user guide or local systems |
334 |
|
administrator to determine the exact location of the MPI libraries. |
335 |
|
If libraries are not installed, MPI implementations and related |
336 |
|
tools are available including: |
337 |
|
\begin{itemize} |
338 |
|
\item \begin{rawhtml} <A |
339 |
|
href="http://www-unix.mcs.anl.gov/mpi/mpich/"> |
340 |
|
\end{rawhtml} |
341 |
|
MPICH |
342 |
|
\begin{rawhtml} </A> \end{rawhtml} |
343 |
|
|
344 |
|
\item \begin{rawhtml} <A |
345 |
|
href="http://www.lam-mpi.org/"> |
346 |
|
\end{rawhtml} |
347 |
|
LAM/MPI |
348 |
|
\begin{rawhtml} </A> \end{rawhtml} |
349 |
|
|
350 |
|
\item \begin{rawhtml} <A |
351 |
|
href="http://www.osc.edu/~pw/mpiexec/"> |
352 |
|
\end{rawhtml} |
353 |
|
MPIexec |
354 |
|
\begin{rawhtml} </A> \end{rawhtml} |
355 |
|
\end{itemize} |
356 |
|
|
357 |
|
\item Build the code with the \texttt{genmake2} \texttt{-mpi} option |
358 |
|
(see Section \ref{sect:genmake}) using commands such as: |
359 |
|
{\footnotesize \begin{verbatim} |
360 |
|
% ../../../tools/genmake2 -mods=../code -mpi -of=YOUR_OPTFILE |
361 |
|
% make depend |
362 |
|
% make |
363 |
|
\end{verbatim} } |
364 |
|
|
365 |
|
\item Run the code with the appropriate MPI ``run'' or ``exec'' |
366 |
|
program provided with your particular implementation of MPI. |
367 |
|
Typical MPI packages such as MPICH will use something like: |
368 |
|
\begin{verbatim} |
369 |
|
% mpirun -np 4 -machinefile mf ./mitgcmuv |
370 |
|
\end{verbatim} |
371 |
|
Sightly more complicated scripts may be needed for many machines |
372 |
|
since execution of the code may be controlled by both the MPI |
373 |
|
library and a job scheduling and queueing system such as PBS, |
374 |
|
LoadLeveller, Condor, or any of a number of similar tools. A few |
375 |
|
example scripts (those used for our \begin{rawhtml} <A |
376 |
|
href="http://mitgcm.org/testing.html"> \end{rawhtml}regular |
377 |
|
verification runs\begin{rawhtml} </A> \end{rawhtml}) are available |
378 |
|
at: |
379 |
|
\begin{rawhtml} <A |
380 |
|
href="http://mitgcm.org/cgi-bin/viewcvs.cgi/MITgcm_contrib/test_scripts/"> |
381 |
|
\end{rawhtml} |
382 |
|
{\footnotesize \tt |
383 |
|
http://mitgcm.org/cgi-bin/viewcvs.cgi/MITgcm\_contrib/test\_scripts/ } |
384 |
|
\begin{rawhtml} </A> \end{rawhtml} |
385 |
|
|
386 |
|
\end{enumerate} |
387 |
|
|
388 |
|
An example of the above process on the MITgcm cluster (``cg01'') using |
389 |
|
the GNU g77 compiler and the mpich MPI library is: |
390 |
|
|
391 |
|
{\footnotesize \begin{verbatim} |
392 |
|
% cd MITgcm/verification/exp5 |
393 |
|
% mkdir build |
394 |
|
% cd build |
395 |
|
% ../../../tools/genmake2 -mpi -mods=../code \ |
396 |
|
-of=../../../tools/build_options/linux_ia32_g77+mpi_cg01 |
397 |
|
% make depend |
398 |
|
% make |
399 |
|
% cd ../input |
400 |
|
% /usr/local/pkg/mpi/mpi-1.2.4..8a-gm-1.5/g77/bin/mpirun.ch_gm \ |
401 |
|
-machinefile mf --gm-kill 5 -v -np 2 ../build/mitgcmuv |
402 |
|
\end{verbatim} } |
403 |
|
|
404 |
\subsection{Configuration and setup} |
\subsection{Configuration and setup} |
405 |
|
|
406 |
The CPP keys relative to the ``numerical model'' part of the code are |
The CPP keys relative to the ``numerical model'' part of the code are |