953ee9f442217506e0e164db1273770adfa131b5
[alexxy/gromacs.git] / admin / installguide / installguide.tex
1 %
2 % This file is part of the GROMACS molecular simulation package.
3 %
4 % Copyright (c) 2013, by the GROMACS development team, led by
5 % Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 % and including many others, as listed in the AUTHORS file in the
7 % top-level source directory and at http://www.gromacs.org.
8 %
9 % GROMACS is free software; you can redistribute it and/or
10 % modify it under the terms of the GNU Lesser General Public License
11 % as published by the Free Software Foundation; either version 2.1
12 % of the License, or (at your option) any later version.
13 %
14 % GROMACS is distributed in the hope that it will be useful,
15 % but WITHOUT ANY WARRANTY; without even the implied warranty of
16 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 % Lesser General Public License for more details.
18 %
19 % You should have received a copy of the GNU Lesser General Public
20 % License along with GROMACS; if not, see
21 % http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 % Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 %
24 % If you want to redistribute modifications to GROMACS, please
25 % consider that scientific software is very special. Version
26 % control is crucial - bugs must be traceable. We will be happy to
27 % consider code for inclusion in the official distribution, but
28 % derived work must not be called official GROMACS. Details are found
29 % in the README & COPYING files - if they are missing, get the
30 % official version at http://www.gromacs.org.
31 %
32 % To help us fund GROMACS development, we humbly ask that you cite
33 % the research papers on the package. Check out http://www.gromacs.org.
34
35 % Process from LaTeX via XML to XHTML with
36 % latexml --destination installguide.xml --xml installguide.tex
37 % latexmlpost --destination installguide.xhtml --format=xhtml installguide.xml
38 %
39 % Crude hack to remove ugly symbols:
40 % sed -e 's/[§]//g' -i installguide.xhtml
41 %
42 % Strip off header for pasting into the website at
43 % http://www.gromacs.org/Documentation/Installation_Instructions:
44 %
45 % grep -A 99999 "class=\"main\"" installguide.xhtml > installguide_web.xhtml
46
47 \documentclass{article}[12pt,a4paper,twoside]
48 \usepackage{hyperref}
49 % haven't made these work with LaTeXML yet...
50 %\usepackage[strings]{underscore}
51 %\usepackage[english]{babel}
52
53 \title{GROMACS installation guide}
54
55 % macros to keep style uniform
56 \newcommand{\gromacs}{GROMACS}
57 \newcommand{\nvidia}{NVIDIA}
58 \newcommand{\cuda}{CUDA}
59 \newcommand{\fftw}{FFTW}
60 \newcommand{\mkl}{MKL}
61 \newcommand{\mpi}{MPI}
62 \newcommand{\threadmpi}{ThreadMPI}
63 \newcommand{\openmpi}{OpenMPI}
64 \newcommand{\openmp}{OpenMP}
65 \newcommand{\lammpi}{LAM/MPI}
66 \newcommand{\mpich}{MPICH}
67 \newcommand{\cmake}{CMake}
68 \newcommand{\sse}{SSE}
69 \newcommand{\ssetwo}{SSE2}
70 \newcommand{\avx}{AVX}
71 \newcommand{\fft}{FFT}
72 \newcommand{\blas}{BLAS}
73 \newcommand{\lapack}{LAPACK}
74 \newcommand{\vmd}{VMD}
75 \newcommand{\pymol}{PyMOL}
76 \newcommand{\grace}{Grace}
77 \newcommand{\libxmltwo}{LibXML2}
78 %\newcommand{\}{}
79
80 % later, make CMake keep this version current for us
81 \newcommand{\fftwversion}{3.3.2}
82 \newcommand{\cmakeversion}{2.8.8}
83 \newcommand{\cudaversion}{3.2}
84 \newcommand{\gromacsversion}{5.0}
85
86 \begin{document}
87 \section{Building GROMACS}
88
89 These instructions pertain to building \gromacs{} \gromacsversion{}
90 and newer releases. For installations instructions for old \gromacs{}
91 versions, see the documentation at
92 \url{http://www.gromacs.org/Documentation/Installation_Instructions_4.5}.
93
94 \section{Quick and dirty installation}
95
96 \begin{enumerate}
97 \item Get the latest version of your compiler.
98 \item Check you have \cmake{} version \cmakeversion{} or later.
99 \item Unpack the \gromacs{} tarball.
100 \item Make a separate build directory and change to it. 
101 \item Run \cmake{} with the path to the source as an argument
102 \item Run make and make install
103 \end{enumerate}
104 Or, as a sequence of commands to execute:
105 \begin{verbatim}
106 tar xfz gromacs-5.0-beta1.tar.gz
107 cd gromacs-gromacs-5.0-beta1
108 mkdir build
109 cd build
110 cmake .. -DGMX_BUILD_OWN_FFTW=ON
111 make
112 sudo make install
113 \end{verbatim}
114 This will download and build first the prerequisite FFT library followed by \gromacs{}. If you already have
115 FFTW installed, you can remove that argument to cmake. Overall, this build 
116 of \gromacs{} will be correct and reasonably fast on the
117 machine upon which \cmake{} ran. If you want to get the maximum value
118 for your hardware with \gromacs{}, you'll have to read further.
119 Sadly, the interactions of hardware, libraries, and compilers
120 are only going to continue to get more complex. 
121
122 \section{Prerequisites}
123 \subsection{Platform}
124 \gromacs{} can be compiled for any distribution of Linux, Mac OS X,
125 Windows (native, Cygwin or MinGW), BlueGene, Cray and many other
126 architectures. Technically, it can be compiled on any platform with
127 an ANSI C99 compiler, an ISO C++98 compiler, and supporting libraries,
128 such as the GNU C library. However, \gromacs{} also comes with many
129 hardware-specific extensions to provide very high performance on those
130 platforms, and to enable these we have slightly more specific
131 requirements since old compilers do not support new features, or they
132 can be buggy. Not all of the C99 standard is required and some C89
133 compilers (including Microsoft Visual C) will also be able to compile
134 Gromacs.
135
136 \subsection{Compiler}
137
138 \gromacs{} requires an ANSI C compiler that complies with the C89
139 standard, and an ISO C++98 compiler. For best performance, the
140 \gromacs{} team strongly recommends you get the most recent version of
141 your preferred compiler for your platform (e.g. GCC 4.8 or Intel 14.0
142 or newer on x86 hardware). There is a large amount of \gromacs{} code
143 introduced in version 4.6 that depends on effective compiler
144 optimization to get high performance - the old raw assembly-language
145 kernel routines are all gone.  Unfortunately this makes \gromacs{} performance
146 more sensitive to the compiler used, and the binary will only work on
147 the hardware for which it is compiled.
148
149 \begin{itemize}
150 \item On Intel-based x86 hardware, there is very little difference in
151   mdrun performance between the Intel and gcc compilers.
152 \item On AMD-based x86 hardware up through the Magny-Cours architecture
153 (e.g. Opteron 6100-series processors), it is worth using the Intel compiler for
154 better performance, but gcc-4.7 and later are also reasonable.
155 \item On the AMD Bulldozer architecture (Opteron 6200), AMD introduced fused multiply-add
156 instructions and an "FMA4" instruction format not available on Intel x86 processors. Thus,
157 on the most recent AMD processors you want to use gcc-4.7 or later for better performance!
158 icc will only generate code for the subset also supported by Intel processors, and that
159 is significantly slower right now.
160 \item If you are running on Mac OS X, the best option is the Intel compiler.
161 Both clang and gcc will work, but they produce lower performance and each have some
162 shortcomings. Clang before 3.4 does not fully support OpenMP, and the current gcc ports do not
163 support \avx{} instructions.
164 \item For all non-x86 platforms, your best option is typically to use the vendor's 
165 default or recommended compiler, and check for specialized information below.
166 \end{itemize}
167
168 \subsubsection{Running in parallel}
169
170 \gromacs{} can run in parallel on multiple cores of a single
171 workstation using its built-in \threadmpi. No user action is required
172 in order to enable this.
173
174 If you wish to use the excellent native GPU support in \gromacs,
175 \nvidia{}'s \cuda{}
176 \url{http://www.nvidia.com/object/cuda_home_new.html} version
177 \cudaversion{} software development kit is required, and the latest
178 version is strongly encouraged. \nvidia{} GPUs with at least \nvidia{}
179 compute capability 2.0 are required, e.g. Fermi or Kepler cards. CUDA
180 version 3.2 is required, although you are strongly recommended to get
181 the latest version and driver supported by your hardware.
182
183 If you wish to run in parallel on multiple machines across a network,
184 you will need to have
185 \begin{itemize}
186 \item an \mpi{} library installed that supports the \mpi{} 1.3
187   standard, and
188 \item wrapper compilers that will compile code using that library.
189 \end{itemize}
190 The \gromacs{} team recommends \openmpi{}
191 \url{http://www.open-mpi.org/} version 1.4.1 (or higher), \mpich{}
192 \url{http://www.mpich.org/} version 1.4.1 (or higher), or your
193 hardware vendor's \mpi{} installation. The most recent version of
194 either of this is likely to be the best. More specialized networks
195 might depend on accelerations only available in the vendor's library.
196  \lammpi{}
197 \url{http://www.lam-mpi.org/} might work, but since it has been
198 deprecated for years, it is not supported.
199
200 Often \openmp{} parallelism is an advantage for \gromacs{},
201 but support for this is generally built into your compiler and detected
202 automatically. The one common exception is Mac OS X, where the default
203 clang compiler currently does not fully support OpenMP. You can install
204 gcc-4.7 instead, but the currently available binary distribution of gcc 
205 uses an old system assembler that does not support \avx{} acceleration
206 instructions. There are some examples on the internet where people have
207 hacked this to work, but presently the only straightforward way to get
208 both OpenMP and \avx{} support on Mac OS X is to get the Intel compiler.
209 This may change when clang 3.4 becomes available.
210
211 In summary, for maximum performance you will need to 
212 examine how you will use \gromacs{}, what hardware you plan to run
213 on, and whether you can afford a non-free compiler for slightly better
214 performance. The only way to find out is unfortunately to test different
215 options and parallelization schemes for the actual simulations you
216 want to run. You will still get {\em good}\, performance with the default
217 build and runtime options, but if you truly want to push your hardware
218 to the performance limit, the days of just blindly starting programs
219 with '\verb+mdrun+' are gone.
220
221 \subsection{CMake}
222
223 \gromacs{} \gromacsversion{} uses the \cmake{} build system, and
224 requires version \cmakeversion{} or higher.
225
226 \gromacs{} requires \cmake{} version \cmakeversion{} or higher. Lower
227 versions will not work. You can check whether \cmake{} is installed,
228 and what version it is, with \verb+cmake --version+. If you need to
229 install \cmake{}, then first check whether your platform's package
230 management system provides a suitable version, or visit
231 \url{http://www.cmake.org/cmake/help/install.html} for pre-compiled
232 binaries, source code and installation instructions. The \gromacs{}
233 team recommends you install the most recent version of \cmake{} you
234 can.
235
236 \subsection{Fast Fourier Transform library}
237
238 Many simulations in \gromacs{} make extensive use of fast Fourier transforms,
239 and a software library to perform these is always required. We
240 recommend \fftw{} \url{http://www.fftw.org/} (version 3 or higher
241 only) or Intel's \mkl{} \url{http://software.intel.com/en-us/intel-mkl}. 
242
243 \subsubsection{\fftw{}}
244
245 \fftw{} is likely to be available for your platform via its package
246 management system, but there can be compatibility and significant
247 performance issues associated with these packages. In particular,
248 \gromacs{} simulations are normally run in single floating-point
249 precision whereas the default \fftw{} package is normally in double
250 precision, and good compiler options to use for \fftw{} when linked to
251 \gromacs{} may not have been used. Accordingly, the \gromacs{} team
252 recommends either
253 \begin{itemize}
254 \item that you permit the \gromacs{} installation to download and
255   build \fftw{} \fftwversion{} from source automatically for you (use
256   \verb+cmake -DGMX_BUILD_OWN_FFTW=ON+), or
257 \item that you build \fftw{} from the source code.
258 Note that the GROMACS-managed download of the FFTW tarball has a
259 slight chance of posing a security risk. If you use this option, you
260 will see a warning that advises how you can eliminate this risk
261 (before the opportunity has arisen).
262 \end{itemize}
263
264 If you build \fftw{} from source yourself, get the most recent version
265 and follow its installation guide available from \url{http://www.fftw.org}.
266 Choose the precision (i.e. single or float vs.\ double) to match what you will
267 later require for \gromacs{}. There is no need to compile with
268 threading or \mpi{} support, but it does no harm. On x86 hardware,
269 compile \emph{only} with \verb+--enable-sse2+ (regardless of
270 precision) even if your processors can take advantage of \avx{}
271 extensions. Since \gromacs{} uses fairly short transform lengths we
272 do not benefit from the \fftw{} \avx{} acceleration, and because of
273 memory system performance limitations, it can even degrade \gromacs{}
274 performance by around 20\%. There is no way for \gromacs{} to
275 limit the use to \ssetwo{} acceleration at run time if \avx{}
276 support has been compiled into \fftw{}, so you need to set this at compile time.
277
278 \subsubsection{\mkl{}}
279
280 Using \mkl{} with icc 11 or higher is very simple. Set up your
281 compiler environment correctly, perhaps with a command like
282 \verb+source /path/to/compilervars.sh intel64+ (or consult your local
283 documentation). Then set \verb+-DGMX_FFT_LIBRARY=mkl+ when you run
284 \cmake{}. In this case, \gromacs{} will also use \mkl{} for \blas{}
285 and \lapack{} (see \hyperref{linear-algebra}{here}).
286
287 Otherwise, you can get your hands dirty and configure \mkl{} by setting
288 \verb+-DGMX_FFT_LIBRARY=mkl
289 -DMKL_LIBRARIES="/full/path/to/libone.so;/full/path/to/libtwo.so"
290 -DMKL_INCLUDE_DIR="/full/path/to/mkl/include"+,
291 where the full list (and order!) of libraries you require are found in
292 Intel's \mkl{} documentation for your system.
293
294 \subsection{Optional build components}
295
296 \begin{itemize}
297 \item Compiling to run on Nvidia GPUs requires \cuda{}
298 \item Hardware-optimized \blas{} and \lapack{} libraries are useful
299   for a few of the \gromacs{} utilities focused on normal modes and
300   matrix manipulation, but they do not provide any benefits for normal
301   simulations. Configuring these are discussed
302   \hyperlink{linear-algebra}{here}.
303 \item The built-in \gromacs{} trajectory viewer \verb+gmx view+ requires
304   X11 and Motif/Lesstif libraries and header files. You may prefer
305   to use third-party software for visualization, such as \vmd{}
306   \url{http://www.ks.uiuc.edu/Research/vmd/} or \pymol{}
307   \url{http://www.pymol.org/}.
308 \item A few \gromacs{} tools get some extra functionality when linked with the
309 GNU scientific library GSL.
310 \item Running the \gromacs{} test suite requires \libxmltwo{}
311 \item Building the \gromacs{} manual requires ImageMagick, pdflatex
312   and bibtex
313 \item The \gromacs{} utility programs often write data files in
314   formats suitable for the \grace{} plotting tool, but it is
315   straightforward to use these files in other plotting programs, too.
316 \end{itemize}
317
318 \section{Doing a build of \gromacs}
319
320 This section will cover a general build of \gromacs{} with \cmake{},
321 but it is not an exhaustive discussion of how to use \cmake{}. There
322 are many resources available on the web, which we suggest you search
323 for when you encounter problems not covered here. The material below
324 applies specifically to builds on Unix-like systems, including Linux,
325 Mac OS X, MinGW and Cygwin. For other platforms, see the specialist
326 instructions below.
327
328 \subsection{Configuring with \cmake{}}
329
330 \cmake{} will run many tests on your system and do its best to work
331 out how to build \gromacs{} for you. If you are building \gromacs{} on
332 hardware that is identical to that where you will run \verb+mdrun+,
333 then you can be sure that the defaults will be pretty good. The build
334 configuration will for instance attempt to detect the specific hardware
335 instructions available in your processor. However, if
336 you want to control aspects of the build, there are plenty of things you
337 can set manually.
338
339 The best way to use \cmake{} to configure \gromacs{} is to do an
340 ``out-of-source'' build, by making another directory from which you
341 will run \cmake{}. This can be a subdirectory or not, it doesn't
342 matter. It also means you can never corrupt your source code by trying
343 to build it! So, the only required argument on the \cmake{} command
344 line is the name of the directory containing the
345 \verb+CMakeLists.txt+ file of the code you want to build. For
346 example, download the source tarball and use
347 % TODO: keep up to date with new releases!
348 \begin{verbatim}
349 $ tar xfz gromacs-5.0-beta1.tgz
350 $ cd gromacs-5.0-beta1
351 $ mkdir build-cmake
352 $ cd build-cmake
353 $ cmake ..
354 \end{verbatim}
355
356 You will see \verb+cmake+ report the results of a large number of
357 tests on your system made by \cmake{} and by \gromacs{}. These are
358 written to the \cmake{} cache, kept in \verb+CMakeCache.txt+. You
359 can edit this file by hand, but this is not recommended because it is
360 easy to reach an inconsistent state. You should not attempt to move or
361 copy this file to do another build, because file paths are hard-coded
362 within it. If you mess things up, just delete this file and start
363 again with '\verb+cmake+'.
364
365 If there's a serious problem detected at this stage, then you will see
366 a fatal error and some suggestions for how to overcome it. If you're
367 not sure how to deal with that, please start by searching on the web
368 (most computer problems already have known solutions!) and then
369 consult the gmx-users mailing list. There are also informational
370 warnings that you might like to take on board or not. Piping the
371 output of \verb+cmake+ through \verb+less+ or \verb+tee+ can be
372 useful, too.
373
374 \cmake{} works in an iterative fashion, re-running each time a setting
375 is changed to try to make sure other things are consistent. Once
376 things seem consistent, the iterations stop. Once \verb+cmake+
377 returns, you can see all the settings that were chosen and information
378 about them by using e.g. the curses interface
379 \begin{verbatim}
380 $ ccmake ..
381 \end{verbatim}
382 You can actually use \verb+ccmake+ directly in the first step, but then
383 most of the status messages will merely blink in the lower part
384 of the terminal rather than be written to standard out. Some platforms
385 like Windows or Mac even have native graphical user interfaces for
386 \cmake{}, and it can create project files for almost any build environment
387 you want (including Visual Studio or Xcode).
388 Check out \url{http://www.cmake.org/cmake/help/runningcmake.html} for
389 general advice on what you are seeing and how to navigate and change
390 things. The settings you might normally want to change are already
391 presented. If you make any changes, then \verb+ccmake+ will notice
392 that and require that you re-configure (using '\verb+c+'), so that it
393 gets a chance to make changes that depend on yours and perform more
394 checking. This might require several configuration stages when you are
395 using \verb+ccmake+ - when you are using \verb+cmake+ the
396 iteration is done behind the scenes.
397
398 A key thing to consider here is the setting of
399 \verb+CMAKE_INSTALL_PREFIX+. You will need to be able to write to this
400 directory in order to install \gromacs{} later, and if you change your
401 mind later, changing it in the cache triggers a full re-build,
402 unfortunately. So if you do not have super-user privileges on your
403 machine, then you will need to choose a sensible location within your
404 home directory for your \gromacs{} installation. Even if you do have
405 super-user privileges, you should use them only for the installation
406 phase, and never for configuring, building, or running \gromacs{}!
407
408 When \verb+cmake+ or \verb+ccmake+ have completed iterating, the
409 cache is stable and a build tree can be generated, with '\verb+g+' in
410 \verb+ccmake+ or automatically with \verb+cmake+.
411
412 You cannot attempt to change compilers after the initial run of
413 \cmake{}. If you need to change, clean up and start again.
414
415 \subsection{Using CMake command-line options}
416 Once you become comfortable with setting and changing options, you
417 may know in advance how you will configure \gromacs{}. If so, you can
418 speed things up by invoking \verb+cmake+ with a command like:
419 \begin{verbatim}
420 $ cmake .. -DGMX_GPU=ON -DGMX_MPI=ON -DCMAKE_INSTALL_PREFIX=/home/marydoe/programs
421 \end{verbatim}
422 to build with GPUs, MPI and install in a custom location. You can even
423 save that in a shell script to make it even easier next time. You can
424 also do this kind of thing with \verb+ccmake+, but you should avoid
425 this, because the options set with '\verb+-D+' will not be able to be
426 changed interactively in that run of \verb+ccmake+.
427
428 \subsection{CMake advanced options}
429 The options that can be seen with \verb+ccmake+ are ones that we
430 think a reasonable number of users might want to consider
431 changing. There are a lot more options available, which you can see by
432 toggling the advanced mode in \verb+ccmake+ on and off with
433 '\verb+t+'. Even there, most of the variables that you might want to
434 change have a '\verb+CMAKE_+' or '\verb+GMX_+' prefix. There are also
435 some options that will be visible or not according to whether
436 their preconditions are satisfied.
437
438 \subsection{Helping CMake find the right libraries/headers/programs}
439
440 If libraries are installed in non-default locations their location can
441 be specified using the following environment variables:
442 \begin{itemize}
443 \item \verb+CMAKE_INCLUDE_PATH+ for header files
444 \item \verb+CMAKE_LIBRARY_PATH+ for libraries
445 \item \verb+CMAKE_PREFIX_PATH+ for header, libraries and binaries
446   (e.g. '\verb+/usr/local+').
447 \end{itemize}
448 The respective '\verb+include+', '\verb+lib+', or '\verb+bin+' is
449 appended to the path. For each of these variables, a list of paths can
450 be specified (on Unix separated with ":"). Note that these are
451 enviroment variables (and not \cmake{} command-line arguments) and in
452 a '\verb+bash+' shell are used like:
453 \begin{verbatim}
454 $ CMAKE_PREFIX_PATH=/opt/fftw:/opt/cuda cmake ..
455 \end{verbatim}
456
457 The \verb+CC+ and \verb+CXX+ environment variables are also useful
458 for indicating to \cmake{} which compilers to use, which can be very
459 important for maximising \gromacs{} performance. Similarly,
460 \verb+CFLAGS+/\verb+CXXFLAGS+ can be used to pass compiler
461 options, but note that these will be appended to those set by
462 \gromacs{} for your build platform and build type. You can customize
463 some of this with advanced options such as \verb+CMAKE_C_FLAGS+
464 and its relatives.
465
466 See also: \url{http://cmake.org/Wiki/CMake_Useful_Variables#Environment_Variables}
467
468 \subsection{Linear algebra libraries}\hypertarget{linear-algebra}
469 As mentioned above, sometimes vendor \blas{} and \lapack{} libraries
470 can provide performance enhancements for \gromacs{} when doing
471 normal-mode analysis or covariance analysis. For simplicity, the text
472 below will refer only to \blas{}, but the same options are available
473 for \lapack{}. By default, CMake will search for \blas{}, use it if it
474 is found, and otherwise fall back on a version of \blas{} internal to
475 \gromacs{}. The \cmake{} option \verb+GMX_EXTERNAL_BLAS+ will be set
476 accordingly. The internal versions are fine for normal use. If you
477 need to specify a non-standard path to search, use
478 \verb+-DCMAKE_PREFIX_PATH=/path/to/search+. If you need to specify a
479 library with a non-standard name (e.g. ESSL on AIX or BlueGene), then
480 set \verb+-DGMX_BLAS_USER=/path/to/reach/lib/libwhatever.a+.
481
482 If you are using Intel's \mkl{} for \fft{}, then the \blas{} and
483 \lapack{} it provides are used automatically. This could be
484 over-ridden with \verb+GMX_BLAS_USER+, etc.
485
486 On Apple platforms where the Accelerate Framework is available, these
487 will be automatically used for \blas{} and \lapack{}. This could be
488 over-ridden with \verb+GMX_BLAS_USER+, etc.
489
490 \subsection{Native GPU acceleration}
491 If you have the \cuda{} Software Development Kit installed, you can
492 use \cmake{} with:
493 \begin{verbatim}
494 cmake .. -DGMX_GPU=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda
495 \end{verbatim}
496 (or whichever path has your installation). Note that this will require
497 a working C++ compiler, and in some cases you might need to handle
498 this manually, e.g. with the advanced option
499 \verb+CUDA_HOST_COMPILER+.
500
501 Historically, Linux GPU builds have received most testing, but we want
502 to support GPU builds both under x86 Linux, Windows, Mac OS X and in
503 the future ARM. Any feedback on this build process (and particularly
504 fixes!) are very welcome.
505
506 \subsection{Static linking}
507 Dynamic linking of the \gromacs{} executables will lead to a
508 smaller disk footprint when installed, and so is the default on
509 platforms where we believe it has been tested repeatedly and found to work.
510 In general, this includes Linux, Windows, Mac OS X and BSD systems.
511 Static binaries take much more space, but on some hardware and/or under
512 some conditions they are necessary, most commonly when you are running a parallel
513 simulation using MPI libraries (e.g. BlueGene, Cray).
514
515 \begin{itemize}
516 \item To link \gromacs{} binaries
517 statically against the internal \gromacs{} libraries, set
518 \verb+BUILD_SHARED_LIBS=OFF+.
519 \item To link statically against external
520 libraries as well, the \verb+GMX_PREFER_STATIC_LIBS=ON+ option can be
521 used. Note, that in general \cmake{} picks up whatever is available,
522 so this option only instructs \cmake{} to prefer static libraries when
523 both static and shared are available. If no static version of an
524 external library is available, even when the aforementioned option is
525 \verb+ON+, the shared library will be used. Also note, that the resulting
526 binaries will still be dynamically linked against system libraries if
527 that is all that is available (common on Mac OS X).
528 \end{itemize}
529
530 \subsection{Changing the names of GROMACS binaries and libraries}
531 It is sometimes convenient to have different versions of the same
532 \gromacs{} libraries installed. The most common use cases have been
533 single and double precision, and with and without \mpi{}. By default,
534 \gromacs{} will suffix binaries and libraries for such builds with
535 '\verb+_d+' for double precision and/or '\verb+_mpi+' for \mpi{} (and
536 nothing otherwise). This can be controlled manually with
537 \verb+GMX_DEFAULT_SUFFIX (ON/OFF)+, \verb+GMX_BINARY_SUFFIX+ (takes 
538 a string) and \verb+GMX_LIBS_SUFFIX+ (also takes a string). 
539 This can also be useful for resolving libary-naming conflicts with 
540 existing packges (\verb+GMX_PREFIX_LIBMD+ also can be useful).
541 For instance, to set a custom suffix for binaries and libraries, 
542 one might specify:
543
544 \begin{verbatim}
545 cmake .. -DGMX_DEFAULT_SUFFIX=OFF -DGMX_BINARY_SUFFIX=_mod -DGMX_LIBS_SUFFIX=_mod
546 \end{verbatim}
547
548 Thus the names of all binaries and libraries will be appended with
549 "\_mod."
550
551 \subsection{Building \gromacs{}}
552
553 Once you have a stable cache, you can build \gromacs{}. If you're not
554 sure the cache is stable, you can re-run \verb+cmake ..+ or
555 \verb+ccmake ..+' to see. Then you can run \verb+make+ to start the
556 compilation. Before actual compilation starts, \verb+make+ checks
557 that the cache is stable, so if it isn't you will see \cmake{} run
558 again.
559
560 So long as any changes you've made to the configuration are sensible,
561 it is expected that the \verb+make+ procedure will always complete
562 successfully, and give few or no warnings. The tests \gromacs{} makes
563 on the settings you chooseare pretty extensive, but there are probably
564 a few cases we haven't thought of yet. Search the web first for
565 solutions to problems, but if you need help, ask on gmx-users, being
566 sure to provide as much information as possible about what you did,
567 the system you are building on, and what went wrong. This may mean
568 scrolling back a long way through the output of \verb+make+ to find
569 the first error message!
570
571 If you have a multi-core or multi-CPU machine with \verb+N+
572 processors, then using
573 \begin{verbatim}
574 $ make -j N
575 \end{verbatim}
576 will generally speed things up by quite a bit. Other make systems
577 supported by \cmake{} (e.g. ninja) also work well.
578
579 \subsubsection{Building only mdrun}
580
581 Past versions of \gromacs{} had the ability to \verb+make mdrun+ to
582 build just mdrun (and a matching install instruction). Such a build is
583 useful when the configuration is only relevant for mdrun (such as with
584 \mpi{} and/or GPUs, or on BlueGene or Cray), or the length of time for
585 the compile-link-install cycle is relevant when developing. This is
586 now supported with the \cmake{} option
587 \verb+-DGMX_BUILD_MDRUN_ONLY=ON+, which will build a cut-down version
588 of \verb+libgromacs+ and/or the \verb+mdrun+ binary (according to
589 whether shared or static). Naturally, now \verb+make install+ acts
590 only those binaries.
591
592 \subsection{Installing \gromacs{}}
593
594 Finally, \verb+make install+ will install \gromacs{} in the
595 directory given in \verb+CMAKE_INSTALL_PREFIX+. If this is an system
596 directory, then you will need permission to write there, and you
597 should use super-user privileges only for \verb+make install+ and
598 not the whole procedure.
599
600 \subsection{Getting access to \gromacs{} after installation}
601
602 \gromacs{} installs the script \verb+GMXRC+ in the \verb+bin+
603 subdirectory of the installation directory
604 (e.g. \verb+/usr/local/gromacs/bin/GMXRC+), which you should source
605 from your shell:
606 \begin{verbatim}
607 $ source /your/installation/prefix/here/bin/GMXRC
608 \end{verbatim}
609
610 It will detect what kind of shell you are running and set up your
611 environment for using \gromacs{}. You may wish to arrange for your
612 login scripts to do this automatically; please search the web for
613 instructions on how to do this for your shell. 
614
615 Many of the \gromacs{} programs rely on data installed in the
616 \verb+share/gromacs+ subdirectory of the installation directory. By
617 default, the programs will use the environment variables set in the
618 \verb+GMXRC+ script, and if this is not available they will try to guess the
619 path based on their own location.  This usually works well unless you
620 change the names of directories inside the install tree. If you still
621 need to do that, you might want to recompile with the new install
622 location properly set, or edit the \verb+GMXRC+ script.
623
624 \subsection{Testing \gromacs{} for correctness}\label{testing}
625 Since 2011, the \gromacs{} development uses an automated system where
626 every new patch is subject to regression testing. While this improves
627 reliability quite a lot, not everything is tested, and since we
628 increasingly rely on cutting edge compiler features there is
629 non-negligible risk that the default compiler on your system could
630 have bugs. We have tried our best to test and refuse to use known bad
631 versions in \cmake{}, but we strongly recommend that you run through
632 the tests yourself. It only takes a few minutes, after which you can
633 trust your build.
634
635 The simplest way to run the checks is to build \gromacs{} with
636 \verb+-DREGRESSIONTEST_DOWNLOAD+, and run \verb+make check+.
637 \gromacs{} will automatically download and run the tests for you.
638 Alternatively, you can download and unpack the tarball yourself from
639 \url{http://gerrit.gromacs.org/download/regressiontests-5.0-beta1.tar.gz},
640 and use the advanced \cmake{} option \verb+REGRESSIONTEST_PATH+ to
641 specify the path to the unpacked tarball, which will then be used for
642 testing. If the above doesn't work, then please read on.
643
644 The regression tests are available from the \gromacs{} website and ftp
645 site.  Once you have downloaded them, unpack the tarball, source
646 \verb+GMXRC+ as described above, and run \verb+./gmxtest.pl all+
647 inside the regression tests folder. You can find more options
648 (e.g. adding \verb+double+ when using double precision, or
649 \verb+-only expanded+ to run just the tests whose names match
650 ``expanded'') if you just execute the script without options.
651
652 Hopefully, you will get a report that all tests have passed. If there
653 are individual failed tests it could be a sign of a compiler bug, or
654 that a tolerance is just a tiny bit too tight. Check the output files
655 the script directs you too, and try a different or newer compiler if
656 the errors appear to be real. If you cannot get it to pass the
657 regression tests, you might try dropping a line to the gmx-users
658 mailing list, but then you should include a detailed description of
659 your hardware, and the output of \verb+mdrun -version+ (which contains
660 valuable diagnostic information in the header).
661
662 A build with \verb+-DGMX_BUILD_MDRUN_ONLY+ cannot be tested with
663 \verb+make check+ from the build tree, because most of the tests
664 require a full build to run things like \verb+grompp+. To test such an
665 mdrun fully requires installing it to the same location as a normal
666 build of \gromacs{}, downloading the regression tests tarball manually
667 as described above, sourcing the correct \verb+GMXRC+ and running the
668 perl script manually. For example, from your \gromacs{} source
669 directory:
670 \begin{verbatim}
671 mkdir build-normal
672 cd build-normal
673 cmake .. -DCMAKE_INSTALL_PREFIX=/your/installation/prefix/here
674 make -j 4
675 make install
676 cd ..
677 mkdir build-mdrun-only
678 cd build-mdrun-only
679 cmake .. -DGMX_MPI=ON -DGMX_GPU=ON -DGMX_BUILD_MDRUN_ONLY=ON -DCMAKE_INSTALL_PREFIX=/your/installation/prefix/here
680 make -j 4
681 make install
682 cd /to/your/unpacked/regressiontests
683 source /your/installation/prefix/here/bin/GMXRC
684 ./gmxtest.pl all -np 2
685 \end{verbatim}
686
687 \subsection{Testing \gromacs{} for performance}
688 We are still working on a set of benchmark systems for testing
689 the performance of \gromacs{}. Until that is ready, we recommend that
690 you try a few different parallelization options, and experiment with
691 tools such as \verb+gmx tune_pme+.
692
693 \subsection{Having difficulty?}
694 You're not alone - this can be a complex task! If you encounter a
695 problem with installing \gromacs{}, then there are a number of
696 locations where you can find assistance. It is recommended that you
697 follow these steps to find the solution:
698
699 \begin{enumerate}
700 \item Read the installation instructions again, taking note that you
701   have followed each and every step correctly.
702 \item Search the \gromacs{} website and users emailing list for
703   information on the error.
704 \item Search the internet using a search engine such as Google.
705 \item Post to the \gromacs{} users emailing list gmx-users for
706   assistance. Be sure to give a full description of what you have done
707   and why you think it didn't work. Give details about the system on
708   which you are installing. 
709   Copy and paste your command line and as
710   much of the output as you think might be relevant - certainly from
711   the first indication of a problem. In particular, please try to include at
712   least the header from the mdrun logfile, and preferably the entire file.
713   People who might volunteer to
714   help you do not have time to ask you interactive detailed follow-up
715   questions, so you will get an answer faster if you provide as much
716   information as you think could possibly help. High quality bug reports 
717   tend to receive rapid high quality answers.
718 \end{enumerate}
719
720 \section{Special instructions for some platforms}
721
722 \subsection{Building on Windows}
723 Building on Cygwin/MinGW/etc. works just like Unix. Please see the
724 instructions above.
725
726 Building on Windows using native compilers is rather similar to
727 building on Unix, so please start by reading the above. Then, download
728 and unpack the GROMACS source archive. The UNIX-standard .tar.gz
729 format can be managed on Windows, but you may prefer to browse
730 \url{ftp://ftp.gromacs.org/pub/gromacs} to obtain a zip format file,
731 which doesn't need any external tools to unzip on recent Windows
732 systems. Make a folder in which to do the out-of-source build of
733 \gromacs{}. For example, make it within the folder unpacked from the
734 source archive, and call it ``build-cmake''. 
735
736 For \cmake{}, you can either use the graphical user interface provided
737 on Windows, or you can use a command line shell with instructions
738 similar to the UNIX ones above. If you open a shell from within
739 your IDE (e.g. Microsoft Visual Studio), it will configure the
740 environment for you, but you might need to tweak this in order to 
741 get either a 32-bit or 64-bit build environment. The latter provides the
742 fastest executable. If you use a normal Windows command shell, then
743 you will need to either set up the environment to find your compilers
744 and libraries yourself, or run the \verb+vcvarsall.bat+ batch script
745 provided by MSVC (just like sourcing a bash script under
746 Unix). 
747
748 With the graphical user interface you will be asked about what compilers
749 to use at the initial configuration stage, and if you use the command line
750 they can be set in a similar way as under UNIX.
751 You will probably make your life easier and faster by using the
752 new facility to download and install \fftw{} automatically. 
753
754 For the build, you can either load the generated solutions file into
755 e.g. Visual Studio, or use the command line with \verb+cmake --build .+ 
756 so the right tools get used.
757
758 \subsection{Building on Cray}
759
760 \gromacs{} builds mostly out of the box on modern Cray machines,
761 but you want to use static libraries due to the peculiarities with
762 parallel job execution.
763
764 \subsection{Building on BlueGene}
765
766 \subsubsection{BlueGene/P}
767
768 There is currently no native acceleration on this platform and no
769 plans to make one. The default plain C kernels will work.
770
771 \subsubsection{BlueGene/Q}
772
773 There is currently native acceleration on this platform for the Verlet
774 cut-off scheme. There are no plans to provide accelerated kernels for
775 the group cut-off scheme, but the default plain C kernels will work.
776
777 Only static linking with XL compilers is supported by \gromacs{}. Dynamic
778 linking would be supported by the architecture and \gromacs{}, but has no
779 advantages other than disk space, and is generally discouraged on
780 BlueGene for performance reasons.
781
782 Computation on BlueGene floating-point units is always done in
783 double-precision. However, single-precision builds of \gromacs{} are
784 still normal and encouraged since they use cache more efficiently. 
785 The BlueGene hardware automatically
786 converts values stored in single precision in memory to double
787 precision in registers for computation, converts the results back to
788 single precision correctly, and does so for no additional cost. As
789 with other platforms, doing the whole computation in double precision
790 normally shows no improvement in accuracy and costs twice as much time
791 moving memory around.
792
793 You need to arrange for FFTW to be installed correctly, following the
794 above instructions.
795
796 mpicc is used for compiling and linking. This can make it awkward to
797 attempt to use IBM's optimized BLAS/LAPACK called ESSL (see the
798 section on linear algebra). Since mdrun is the only part of \gromacs{}
799 that should normally run on the compute nodes, and there is nearly no
800 need for linear algebra support for mdrun, it is recommended to use
801 the \gromacs{} built-in linear algebra routines - it is rare for this
802 to be a bottleneck.
803
804 The recommended configuration is to use
805 \begin{verbatim}
806 cmake .. -DCMAKE_TOOLCHAIN_FILE=Platform/BlueGeneQ-static-XL-CXX \
807          -DCMAKE_PREFIX_PATH=/your/fftw/installation/prefix \
808          -DGMX_MPI=ON \
809          -DGMX_BUILD_MDRUN_ONLY=ON
810 make
811 make install
812 \end{verbatim}
813 which will build a statically-linked \mpi{}-enabled mdrun for the back
814 end. Otherwise, GROMACS default configuration behaviour applies.
815
816 It is possible to configure and make the remaining \gromacs{} tools
817 with the compute-node toolchain, but as none of those tools are
818 \mpi{}-aware and could then only run on the compute nodes, this
819 would not normally be useful. Instead, these should be planned
820 to run on the login node, and a separate \gromacs{} installation
821 performed for that using the login node's toolchain - not the
822 above platform file, or any other compute-node toolchain.
823
824 Note that only the MPI build is available for the compute-node
825 toolchains. The GROMACS thread-MPI or no-MPI builds are not useful at
826 all on BlueGene/Q.
827
828 \subsubsection{Fujitsu PRIMEHPC}
829
830 This is the architecture of the K computer, which uses Fujitsu
831 Sparc64viiifx chips. On this platform \gromacs{} \gromacsversion{} has
832 accelerated group kernels, no accelerated Verlet kernels, and a custom
833 build toolchain.
834
835 \section{Tested platforms}
836
837 While it is our best belief that \gromacs{} will build and run pretty
838 much everywhere, it's important that we tell you where we really know
839 it works because we've tested it. We do test on Linux, Windows, and
840 Mac with a range of compilers and libraries for a range of our
841 configuration options. Every commit in our git source code
842 repository is currently tested on x86 with gcc versions ranging
843 from 4.1 through 4.8, and versions 12 and 13 of the Intel compiler.
844 Under Windows, we test both the Visual Studio and Intel compilers.
845
846 We test irregularly on BlueGene/Q, Cray,
847 Fujitsu PRIMEHPC, Google nativeclient and other environments. In 
848 the future we expect ARM to be an important test target too, but this
849 is currently not included.
850
851 Contributions to this section are welcome.
852
853 If there is interest, we might set up the ability for users to
854 contribute test results to Jenkins.
855
856 \end{document}