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