/[MITgcm]/manual/s_getstarted/text/customization.tex
ViewVC logotype

Diff of /manual/s_getstarted/text/customization.tex

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

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

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

  ViewVC Help
Powered by ViewVC 1.1.22