a4137de01283079c5edaae63594b540fb8809b4d
[alexxy/gromacs.git] / admin / installguide / installguide.tex
1 %
2 % This file is part of the GROMACS molecular simulation package.
3 %
4 % Copyright (c) 2013,2014, 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, 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, we recommend you to use
151 the GNU compilers version 4.7 or later or Intel compilers version 12 or later
152 for best performance. The Intel compiler has historically been better at
153 instruction scheduling, but recent gcc versions have proved to be as fast or
154 sometimes faster than Intel.
155 \item On AMD-based x86 hardware up through the ``K10'' microarchitecture (``Family 10h'')
156 Thuban/Magny-Cours architecture (e.g. Opteron 6100-series processors), it is worth using the Intel compiler for
157 better performance, but gcc version 4.7 and later are also reasonable.
158 \item On the AMD Bulldozer architecture (Opteron 6200), AMD introduced fused multiply-add
159 instructions and an "FMA4" instruction format not available on Intel x86 processors. Thus,
160 on the most recent AMD processors you want to use gcc version 4.7 or later for better performance!
161 The Intel compiler will only generate code for the subset also supported by Intel processors, and that
162 is significantly slower right now.
163 \item If you are running on Mac OS X, the best option is the Intel compiler.
164 Both clang and gcc will work, but they produce lower performance and each have some
165 shortcomings. Current Clang does not support OpenMP, and the current gcc ports do not
166 support \avx{} instructions.
167 \item For all non-x86 platforms, your best option is typically to use the vendor's 
168 default or recommended compiler, and check for specialized information below.
169 \end{itemize}
170
171 \subsubsection{Running in parallel}
172
173 \gromacs{} can run in parallel on multiple cores of a single
174 workstation using its built-in \threadmpi. No user action is required
175 in order to enable this.
176
177 If you wish to use the excellent native GPU support in \gromacs,
178 \nvidia{}'s \cuda{}
179 \url{http://www.nvidia.com/object/cuda_home_new.html} version
180 \cudaversion{} software development kit is required, and the latest
181 version is strongly encouraged. \nvidia{} GPUs with at least \nvidia{}
182 compute capability 2.0 are required, e.g. Fermi or Kepler cards. CUDA
183 version 3.2 is required, although you are strongly recommended to get
184 the latest version and driver supported by your hardware.
185
186 If you wish to run in parallel on multiple machines across a network,
187 you will need to have
188 \begin{itemize}
189 \item an \mpi{} library installed that supports the \mpi{} 1.3
190   standard, and
191 \item wrapper compilers that will compile code using that library.
192 \end{itemize}
193 The \gromacs{} team recommends \openmpi{}
194 \url{http://www.open-mpi.org/} version 1.4.1 (or higher), \mpich{}
195 \url{http://www.mpich.org/} version 1.4.1 (or higher), or your
196 hardware vendor's \mpi{} installation. The most recent version of
197 either of this is likely to be the best. More specialized networks
198 might depend on accelerations only available in the vendor's library.
199  \lammpi{}
200 \url{http://www.lam-mpi.org/} might work, but since it has been
201 deprecated for years, it is not supported.
202
203 Often \openmp{} parallelism is an advantage for \gromacs{},
204 but support for this is generally built into your compiler and detected
205 automatically. The one common exception is Mac OS X, where the default
206 clang compiler currently does not fully support OpenMP. You can install
207 gcc version 4.7 instead, but the currently available binary distribution of gcc 
208 uses an old system assembler that does not support \avx{} acceleration
209 instructions. There are some examples on the Internet where people have
210 hacked this to work, but presently the only straightforward way to get
211 both OpenMP and \avx{} support on Mac OS X is to get the Intel compiler.
212 This may change when clang 3.4 becomes available.
213
214 In summary, for maximum performance you will need to 
215 examine how you will use \gromacs{}, what hardware you plan to run
216 on, and whether you can afford a non-free compiler for slightly better
217 performance. The only way to find out is unfortunately to test different
218 options and parallelization schemes for the actual simulations you
219 want to run. You will still get {\em good}\, performance with the default
220 build and runtime options, but if you truly want to push your hardware
221 to the performance limit, the days of just blindly starting programs
222 with '\verb+mdrun+' are gone.
223
224 \subsection{CMake}
225
226 \gromacs{} \gromacsversion{} uses the \cmake{} build system, and
227 requires version \cmakeversion{} or higher.
228
229 \gromacs{} requires \cmake{} version \cmakeversion{} or higher. Lower
230 versions will not work. You can check whether \cmake{} is installed,
231 and what version it is, with \verb+cmake --version+. If you need to
232 install \cmake{}, then first check whether your platform's package
233 management system provides a suitable version, or visit
234 \url{http://www.cmake.org/cmake/help/install.html} for pre-compiled
235 binaries, source code and installation instructions. The \gromacs{}
236 team recommends you install the most recent version of \cmake{} you
237 can.
238
239 \subsection{Fast Fourier Transform library}
240
241 Many simulations in \gromacs{} make extensive use of fast Fourier transforms,
242 and a software library to perform these is always required. We
243 recommend \fftw{} \url{http://www.fftw.org/} (version 3 or higher
244 only) or Intel's \mkl{} \url{http://software.intel.com/en-us/intel-mkl}. 
245
246 \subsubsection{\fftw{}}
247
248 \fftw{} is likely to be available for your platform via its package
249 management system, but there can be compatibility and significant
250 performance issues associated with these packages. In particular,
251 \gromacs{} simulations are normally run in single floating-point
252 precision whereas the default \fftw{} package is normally in double
253 precision, and good compiler options to use for \fftw{} when linked to
254 \gromacs{} may not have been used. Accordingly, the \gromacs{} team
255 recommends either
256 \begin{itemize}
257 \item that you permit the \gromacs{} installation to download and
258   build \fftw{} \fftwversion{} from source automatically for you (use
259   \verb+cmake -DGMX_BUILD_OWN_FFTW=ON+), or
260 \item that you build \fftw{} from the source code.
261 Note that the GROMACS-managed download of the FFTW tarball has a
262 slight chance of posing a security risk. If you use this option, you
263 will see a warning that advises how you can eliminate this risk
264 (before the opportunity has arisen).
265 \end{itemize}
266
267 If you build \fftw{} from source yourself, get the most recent version
268 and follow its installation guide available from \url{http://www.fftw.org}.
269 Choose the precision (i.e. single or float vs.\ double) to match what you will
270 later require for \gromacs{}. There is no need to compile with
271 threading or \mpi{} support, but it does no harm. On x86 hardware,
272 compile \emph{only} with \verb+--enable-sse2+ (regardless of
273 precision) even if your processors can take advantage of \avx{}
274 extensions. Since \gromacs{} uses fairly short transform lengths we
275 do not benefit from the \fftw{} \avx{} acceleration, and because of
276 memory system performance limitations, it can even degrade \gromacs{}
277 performance by around 20\%. There is no way for \gromacs{} to
278 limit the use to \ssetwo{} acceleration at run time if \avx{}
279 support has been compiled into \fftw{}, so you need to set this at compile time.
280
281 \subsubsection{\mkl{}}
282
283 Using \mkl{} with the Intel Compilers version 11 or higher is very simple. Set up your
284 compiler environment correctly, perhaps with a command like
285 \verb+source /path/to/compilervars.sh intel64+ (or consult your local
286 documentation). Then set \verb+-DGMX_FFT_LIBRARY=mkl+ when you run
287 \cmake{}. In this case, \gromacs{} will also use \mkl{} for \blas{}
288 and \lapack{} (see \hyperref{linear-algebra}{here}).
289
290 Otherwise, you can get your hands dirty and configure \mkl{} by setting
291 \verb+-DGMX_FFT_LIBRARY=mkl
292 -DMKL_LIBRARIES="/full/path/to/libone.so;/full/path/to/libtwo.so"
293 -DMKL_INCLUDE_DIR="/full/path/to/mkl/include"+,
294 where the full list (and order!) of libraries you require are found in
295 Intel's \mkl{} documentation for your system.
296
297 \subsection{Optional build components}
298
299 \begin{itemize}
300 \item Compiling to run on Nvidia GPUs requires \cuda{}
301 \item Hardware-optimized \blas{} and \lapack{} libraries are useful
302   for a few of the \gromacs{} utilities focused on normal modes and
303   matrix manipulation, but they do not provide any benefits for normal
304   simulations. Configuring these are discussed
305   \hyperlink{linear-algebra}{here}.
306 \item The built-in \gromacs{} trajectory viewer \verb+gmx view+ requires
307   X11 and Motif/Lesstif libraries and header files. You may prefer
308   to use third-party software for visualization, such as \vmd{}
309   \url{http://www.ks.uiuc.edu/Research/vmd/} or \pymol{}
310   \url{http://www.pymol.org/}.
311 \item A few \gromacs{} tools get some extra functionality when linked with the
312 GNU scientific library GSL.
313 \item Running the \gromacs{} test suite requires \libxmltwo{}
314 \item Building the \gromacs{} manual requires ImageMagick, pdflatex
315   and bibtex
316 \item The \gromacs{} utility programs often write data files in
317   formats suitable for the \grace{} plotting tool, but it is
318   straightforward to use these files in other plotting programs, too.
319 \end{itemize}
320
321 \section{Doing a build of \gromacs}
322
323 This section will cover a general build of \gromacs{} with \cmake{},
324 but it is not an exhaustive discussion of how to use \cmake{}. There
325 are many resources available on the web, which we suggest you search
326 for when you encounter problems not covered here. The material below
327 applies specifically to builds on Unix-like systems, including Linux,
328 and Mac OS X. For other platforms, see the specialist
329 instructions below.
330
331 \subsection{Configuring with \cmake{}}
332
333 \cmake{} will run many tests on your system and do its best to work
334 out how to build \gromacs{} for you. If you are building \gromacs{} on
335 hardware that is identical to that where you will run \verb+mdrun+,
336 then you can be sure that the defaults will be pretty good. The build
337 configuration will for instance attempt to detect the specific hardware
338 instructions available in your processor. However, if
339 you want to control aspects of the build, there are plenty of things you
340 can set manually.
341
342 The best way to use \cmake{} to configure \gromacs{} is to do an
343 ``out-of-source'' build, by making another directory from which you
344 will run \cmake{}. This can be a subdirectory or not, it doesn't
345 matter. It also means you can never corrupt your source code by trying
346 to build it! So, the only required argument on the \cmake{} command
347 line is the name of the directory containing the
348 \verb+CMakeLists.txt+ file of the code you want to build. For
349 example, download the source tarball and use
350 % TODO: keep up to date with new releases!
351 \begin{verbatim}
352 $ tar xfz gromacs-5.0-beta1.tgz
353 $ cd gromacs-5.0-beta1
354 $ mkdir build-cmake
355 $ cd build-cmake
356 $ cmake ..
357 \end{verbatim}
358
359 You will see \verb+cmake+ report the results of a large number of
360 tests on your system made by \cmake{} and by \gromacs{}. These are
361 written to the \cmake{} cache, kept in \verb+CMakeCache.txt+. You
362 can edit this file by hand, but this is not recommended because it is
363 easy to reach an inconsistent state. You should not attempt to move or
364 copy this file to do another build, because file paths are hard-coded
365 within it. If you mess things up, just delete this file and start
366 again with '\verb+cmake+'.
367
368 If there's a serious problem detected at this stage, then you will see
369 a fatal error and some suggestions for how to overcome it. If you're
370 not sure how to deal with that, please start by searching on the web
371 (most computer problems already have known solutions!) and then
372 consult the gmx-users mailing list. There are also informational
373 warnings that you might like to take on board or not. Piping the
374 output of \verb+cmake+ through \verb+less+ or \verb+tee+ can be
375 useful, too.
376
377 \cmake{} works in an iterative fashion, re-running each time a setting
378 is changed to try to make sure other things are consistent. Once
379 things seem consistent, the iterations stop. Once \verb+cmake+
380 returns, you can see all the settings that were chosen and information
381 about them by using e.g. the curses interface
382 \begin{verbatim}
383 $ ccmake ..
384 \end{verbatim}
385 You can actually use \verb+ccmake+ (available on most Unix platforms,
386 if the curses library is supported) directly in the first step, but then
387 most of the status messages will merely blink in the lower part
388 of the terminal rather than be written to standard out. Most platforms
389 including Linux, Windows, and Mac OS X even have native graphical user interfaces for
390 \cmake{}, and it can create project files for almost any build environment
391 you want (including Visual Studio or Xcode).
392 Check out \url{http://www.cmake.org/cmake/help/runningcmake.html} for
393 general advice on what you are seeing and how to navigate and change
394 things. The settings you might normally want to change are already
395 presented. If you make any changes, then \verb+ccmake+ will notice
396 that and require that you re-configure (using '\verb+c+'), so that it
397 gets a chance to make changes that depend on yours and perform more
398 checking. This might require several configuration stages when you are
399 using \verb+ccmake+ - when you are using \verb+cmake+ the
400 iteration is done behind the scenes.
401
402 A key thing to consider here is the setting of
403 \verb+CMAKE_INSTALL_PREFIX+. You will need to be able to write to this
404 directory in order to install \gromacs{} later, and if you change your
405 mind later, changing it in the cache triggers a full re-build,
406 unfortunately. So if you do not have super-user privileges on your
407 machine, then you will need to choose a sensible location within your
408 home directory for your \gromacs{} installation. Even if you do have
409 super-user privileges, you should use them only for the installation
410 phase, and never for configuring, building, or running \gromacs{}!
411
412 When \verb+cmake+ or \verb+ccmake+ have completed iterating, the
413 cache is stable and a build tree can be generated, with '\verb+g+' in
414 \verb+ccmake+ or automatically with \verb+cmake+.
415
416 You cannot attempt to change compilers after the initial run of
417 \cmake{}. If you need to change, clean up and start again.
418
419 \subsection{Using CMake command-line options}
420 Once you become comfortable with setting and changing options, you
421 may know in advance how you will configure \gromacs{}. If so, you can
422 speed things up by invoking \verb+cmake+ with a command like:
423 \begin{verbatim}
424 $ cmake .. -DGMX_GPU=ON -DGMX_MPI=ON -DCMAKE_INSTALL_PREFIX=/home/marydoe/programs
425 \end{verbatim}
426 to build with GPUs, MPI and install in a custom location. You can even
427 save that in a shell script to make it even easier next time. You can
428 also do this kind of thing with \verb+ccmake+, but you should avoid
429 this, because the options set with '\verb+-D+' will not be able to be
430 changed interactively in that run of \verb+ccmake+.
431
432 \subsection{SIMD support}
433 \gromacs{} has extensive support for detecting and using the SIMD
434 capabilities of nearly all modern HPC CPUs. If you are building
435 \gromacs{} on the same hardware you will run it on, then you don't
436 need to read more about this. Otherwise, you may wish to choose the
437 value of \verb+GMX_SIMD+ to much the execution environment. If you
438 make no choice, the default will be based on the computer on which you
439 are running \cmake{}. Valid values are listed below, and the
440 applicable value lowest on the list is generally the one you should
441 choose:
442 \begin{enumerate}
443 \item \verb+None+ For use only on an architecture either lacking SIMD,
444   or to which \gromacs{} has not yet been ported and none of the
445   options below are applicable.
446 \item \verb+SSE2+ Essentially all x86 machines in existence have this
447 \item \verb+SSE4.1+ More recent x86 have this
448 \item \verb+AVX_128_FMA+ More recent AMD x86 have this
449 \item \verb+AVX_256+ More recent Intel x86 have this
450 \item \verb+AVX2_256+ Yet more recent Intel x86 have this
451 \item \verb+IBM_QPX + BlueGene/Q A2 cores have this
452 \item \verb+Sparc64_HPC_ACE+ Fujitsu machines like the K computer have this
453 \end{enumeration}
454 The \cmake{} configure system will check that the compiler you have
455 chosen can target the architecture you have chosen. mdrun will check
456 further at runtime, so if in doubt, choose the lowest setting you
457 think might work, and see what mdrun says. The configure system also
458 works around many known issues in many versions of common HPC
459 compilers.
460
461 A further \verb+GMX_SIMD=Reference+ option exists, which is a special
462 SIMD-like implementation written in plain C that developers can use
463 when developing support in GROMACS for new SIMD architectures. It is
464 not designed for use in production simulations, but if you are using
465 an architecture with SIMD support to which \gromacs{} has not yet been
466 ported, you may wish to try the performance of this option, in case
467 the auto-vectorization in your compiler does a good job. And post on
468 the \gromacs{} mailing lists, because \gromacs{} can probably be
469 ported for new SIMD architectures in a few days.
470
471 \subsection{CMake advanced options}
472 The options that can be seen with \verb+ccmake+ are ones that we
473 think a reasonable number of users might want to consider
474 changing. There are a lot more options available, which you can see by
475 toggling the advanced mode in \verb+ccmake+ on and off with
476 '\verb+t+'. Even there, most of the variables that you might want to
477 change have a '\verb+CMAKE_+' or '\verb+GMX_+' prefix. There are also
478 some options that will be visible or not according to whether
479 their preconditions are satisfied.
480
481 \subsubsection{Portability aspects}
482 Here, we consider portability aspects related to CPU instruction sets,
483 for details on other topics like binaries with statical vs dynamic linking
484 please consult the relevant parts of this documentation or other non-\gromacs{} specific
485 resources.
486
487 Most often a \gromacs{} build will by default not be portable,
488 not even across hardware with the same base instruction set like x86.
489 The reason for this is that hardware-specific optimizations are selected
490 at configure-time, like the SIMD instruction set used in the compute-kernels.
491 This selection will be done by the build system based on the capabilities
492 of the build host machine or based on cross-compilation information provided
493 to \cmake{} at configuration.
494
495 Often it is possible to ensure portability by choosing the
496 least common denominator of SIMD support, e.g. SSE2 for x86
497 and ensuring the \cmake{} option \verb+GMX_USE_RDTSCP+ is off if any of the
498 target CPU architectures does not support the \verb+RDTSCP+ instruction.
499 However, we discourage attempts to use a single \gromacs{}
500 installation when the execution environment is heterogeneous, such as
501 a mix of \avx{} and earlier hardware, because this will lead to slow
502 binaries (especially \verb+mdrun+), on the new hardware.
503 Building two full installations and locally managing how to
504 call the correct one (e.g. using the module system) is the recommended
505 approach.
506 Alternatively, as at the moment the \gromacs{} tools do not make
507 strong use of SIMD acceleration, it can be convenient to create an installation
508 with tools portable across different x86 machines, but with separate \verb+mdrun+
509 binaries for each architecture.
510 To achieve this, one can first build a full installation with the least common
511 denominator SIMD instruction set, e.g. SSE2, then build separate \verb+mdrun+
512 binaries for each architecture present in the heterogeneous environment.
513 By using custom binary and library suffixes for the \verb+mdrun+-only builds,
514 these can be installed to the same location as the ''generic`` tools installation.
515
516
517 \subsection{Helping CMake find the right libraries/headers/programs}
518
519 If libraries are installed in non-default locations their location can
520 be specified using the following environment variables:
521 \begin{itemize}
522 \item \verb+CMAKE_INCLUDE_PATH+ for header files
523 \item \verb+CMAKE_LIBRARY_PATH+ for libraries
524 \item \verb+CMAKE_PREFIX_PATH+ for header, libraries and binaries
525   (e.g. '\verb+/usr/local+').
526 \end{itemize}
527 The respective '\verb+include+', '\verb+lib+', or '\verb+bin+' is
528 appended to the path. For each of these variables, a list of paths can
529 be specified (on Unix separated with ":"). Note that these are
530 enviroment variables (and not \cmake{} command-line arguments) and in
531 a '\verb+bash+' shell are used like:
532 \begin{verbatim}
533 $ CMAKE_PREFIX_PATH=/opt/fftw:/opt/cuda cmake ..
534 \end{verbatim}
535
536 The \verb+CC+ and \verb+CXX+ environment variables are also useful
537 for indicating to \cmake{} which compilers to use, which can be very
538 important for maximising \gromacs{} performance. Similarly,
539 \verb+CFLAGS+/\verb+CXXFLAGS+ can be used to pass compiler
540 options, but note that these will be appended to those set by
541 \gromacs{} for your build platform and build type. You can customize
542 some of this with advanced options such as \verb+CMAKE_C_FLAGS+
543 and its relatives.
544
545 See also: \url{http://cmake.org/Wiki/CMake_Useful_Variables#Environment_Variables}
546
547 \subsection{Linear algebra libraries}\hypertarget{linear-algebra}
548 As mentioned above, sometimes vendor \blas{} and \lapack{} libraries
549 can provide performance enhancements for \gromacs{} when doing
550 normal-mode analysis or covariance analysis. For simplicity, the text
551 below will refer only to \blas{}, but the same options are available
552 for \lapack{}. By default, CMake will search for \blas{}, use it if it
553 is found, and otherwise fall back on a version of \blas{} internal to
554 \gromacs{}. The \cmake{} option \verb+GMX_EXTERNAL_BLAS+ will be set
555 accordingly. The internal versions are fine for normal use. If you
556 need to specify a non-standard path to search, use
557 \verb+-DCMAKE_PREFIX_PATH=/path/to/search+. If you need to specify a
558 library with a non-standard name (e.g. ESSL on AIX or BlueGene), then
559 set \verb+-DGMX_BLAS_USER=/path/to/reach/lib/libwhatever.a+.
560
561 If you are using Intel's \mkl{} for \fft{}, then the \blas{} and
562 \lapack{} it provides are used automatically. This could be
563 over-ridden with \verb+GMX_BLAS_USER+, etc.
564
565 On Apple platforms where the Accelerate Framework is available, these
566 will be automatically used for \blas{} and \lapack{}. This could be
567 over-ridden with \verb+GMX_BLAS_USER+, etc.
568
569 \subsection{Native GPU acceleration}
570 If you have the \cuda{} Software Development Kit installed, you can
571 use \cmake{} with:
572 \begin{verbatim}
573 cmake .. -DGMX_GPU=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda
574 \end{verbatim}
575 (or whichever path has your installation). Note that this will require
576 a working C++ compiler, and in some cases you might need to handle
577 this manually, e.g. with the advanced option
578 \verb+CUDA_HOST_COMPILER+.
579
580 Historically, Linux GPU builds have received most testing, but we want
581 to support GPU builds both under x86 Linux, Windows, Mac OS X and in
582 the future ARM. Any feedback on this build process (and particularly
583 fixes!) are very welcome.
584
585 \subsection{Static linking}
586 Dynamic linking of the \gromacs{} executables will lead to a
587 smaller disk footprint when installed, and so is the default on
588 platforms where we believe it has been tested repeatedly and found to work.
589 In general, this includes Linux, Windows, Mac OS X and BSD systems.
590 Static binaries take much more space, but on some hardware and/or under
591 some conditions they are necessary, most commonly when you are running a parallel
592 simulation using MPI libraries (e.g. BlueGene, Cray).
593
594 \begin{itemize}
595 \item To link \gromacs{} binaries
596 statically against the internal \gromacs{} libraries, set
597 \verb+BUILD_SHARED_LIBS=OFF+.
598 \item To link statically against external
599 libraries as well, the \verb+GMX_PREFER_STATIC_LIBS=ON+ option can be
600 used. Note, that in general \cmake{} picks up whatever is available,
601 so this option only instructs \cmake{} to prefer static libraries when
602 both static and shared are available. If no static version of an
603 external library is available, even when the aforementioned option is
604 \verb+ON+, the shared library will be used. Also note, that the resulting
605 binaries will still be dynamically linked against system libraries if
606 that is all that is available (common on Mac OS X).
607 \end{itemize}
608
609 \subsection{Changing the names of GROMACS binaries and libraries}
610 It is sometimes convenient to have different versions of the same
611 \gromacs{} libraries installed. The most common use cases have been
612 single and double precision, and with and without \mpi{}. By default,
613 \gromacs{} will suffix binaries and libraries for such builds with
614 '\verb+_d+' for double precision and/or '\verb+_mpi+' for \mpi{} (and
615 nothing otherwise). This can be controlled manually with
616 \verb+GMX_DEFAULT_SUFFIX (ON/OFF)+, \verb+GMX_BINARY_SUFFIX+ (takes 
617 a string) and \verb+GMX_LIBS_SUFFIX+ (also takes a string). 
618 This can also be useful for resolving libary-naming conflicts with 
619 existing packges (\verb+GMX_PREFIX_LIBMD+ also can be useful).
620 For instance, to set a custom suffix for binaries and libraries, 
621 one might specify:
622
623 \begin{verbatim}
624 cmake .. -DGMX_DEFAULT_SUFFIX=OFF -DGMX_BINARY_SUFFIX=_mod -DGMX_LIBS_SUFFIX=_mod
625 \end{verbatim}
626
627 Thus the names of all binaries and libraries will be appended with
628 "\_mod."
629
630 \subsection{Building \gromacs{}}
631
632 Once you have a stable cache, you can build \gromacs{}. If you're not
633 sure the cache is stable, you can re-run \verb+cmake ..+ or
634 \verb+ccmake ..+' to see. Then you can run \verb+make+ to start the
635 compilation. Before actual compilation starts, \verb+make+ checks
636 that the cache is stable, so if it isn't you will see \cmake{} run
637 again.
638
639 So long as any changes you've made to the configuration are sensible,
640 it is expected that the \verb+make+ procedure will always complete
641 successfully, and give few or no warnings. The tests \gromacs{} makes
642 on the settings you chooseare pretty extensive, but there are probably
643 a few cases we haven't thought of yet. Search the web first for
644 solutions to problems, but if you need help, ask on gmx-users, being
645 sure to provide as much information as possible about what you did,
646 the system you are building on, and what went wrong. This may mean
647 scrolling back a long way through the output of \verb+make+ to find
648 the first error message!
649
650 If you have a multi-core or multi-CPU machine with \verb+N+
651 processors, then using
652 \begin{verbatim}
653 $ make -j N
654 \end{verbatim}
655 will generally speed things up by quite a bit. Other make systems
656 supported by \cmake{} (e.g. ninja) also work well.
657
658 \subsubsection{Building only mdrun}
659
660 Past versions of \gromacs{} had the ability to \verb+make mdrun+ to
661 build just mdrun (and a matching install instruction). Such a build is
662 useful when the configuration is only relevant for mdrun (such as with
663 \mpi{} and/or GPUs, or on BlueGene or Cray), or the length of time for
664 the compile-link-install cycle is relevant when developing. This is
665 now supported with the \cmake{} option
666 \verb+-DGMX_BUILD_MDRUN_ONLY=ON+, which will build a cut-down version
667 of \verb+libgromacs+ and/or the \verb+mdrun+ binary (according to
668 whether shared or static). Naturally, now \verb+make install+ acts
669 only those binaries.
670
671 \subsection{Installing \gromacs{}}
672
673 Finally, \verb+make install+ will install \gromacs{} in the
674 directory given in \verb+CMAKE_INSTALL_PREFIX+. If this is an system
675 directory, then you will need permission to write there, and you
676 should use super-user privileges only for \verb+make install+ and
677 not the whole procedure.
678
679 \subsection{Getting access to \gromacs{} after installation}
680
681 \gromacs{} installs the script \verb+GMXRC+ in the \verb+bin+
682 subdirectory of the installation directory
683 (e.g. \verb+/usr/local/gromacs/bin/GMXRC+), which you should source
684 from your shell:
685 \begin{verbatim}
686 $ source /your/installation/prefix/here/bin/GMXRC
687 \end{verbatim}
688
689 It will detect what kind of shell you are running and set up your
690 environment for using \gromacs{}. You may wish to arrange for your
691 login scripts to do this automatically; please search the web for
692 instructions on how to do this for your shell. 
693
694 Many of the \gromacs{} programs rely on data installed in the
695 \verb+share/gromacs+ subdirectory of the installation directory. By
696 default, the programs will use the environment variables set in the
697 \verb+GMXRC+ script, and if this is not available they will try to guess the
698 path based on their own location.  This usually works well unless you
699 change the names of directories inside the install tree. If you still
700 need to do that, you might want to recompile with the new install
701 location properly set, or edit the \verb+GMXRC+ script.
702
703 \subsection{Testing \gromacs{} for correctness}\label{testing}
704 Since 2011, the \gromacs{} development uses an automated system where
705 every new patch is subject to regression testing. While this improves
706 reliability quite a lot, not everything is tested, and since we
707 increasingly rely on cutting edge compiler features there is
708 non-negligible risk that the default compiler on your system could
709 have bugs. We have tried our best to test and refuse to use known bad
710 versions in \cmake{}, but we strongly recommend that you run through
711 the tests yourself. It only takes a few minutes, after which you can
712 trust your build.
713
714 The simplest way to run the checks is to build \gromacs{} with
715 \verb+-DREGRESSIONTEST_DOWNLOAD+, and run \verb+make check+.
716 \gromacs{} will automatically download and run the tests for you.
717 Alternatively, you can download and unpack the tarball yourself from
718 \url{http://gerrit.gromacs.org/download/regressiontests-5.0-beta1.tar.gz},
719 and use the advanced \cmake{} option \verb+REGRESSIONTEST_PATH+ to
720 specify the path to the unpacked tarball, which will then be used for
721 testing. If the above doesn't work, then please read on.
722
723 The regression tests are available from the \gromacs{} website and ftp
724 site.  Once you have downloaded them, unpack the tarball, source
725 \verb+GMXRC+ as described above, and run \verb+./gmxtest.pl all+
726 inside the regression tests folder. You can find more options
727 (e.g. adding \verb+double+ when using double precision, or
728 \verb+-only expanded+ to run just the tests whose names match
729 ``expanded'') if you just execute the script without options.
730
731 Hopefully, you will get a report that all tests have passed. If there
732 are individual failed tests it could be a sign of a compiler bug, or
733 that a tolerance is just a tiny bit too tight. Check the output files
734 the script directs you too, and try a different or newer compiler if
735 the errors appear to be real. If you cannot get it to pass the
736 regression tests, you might try dropping a line to the gmx-users
737 mailing list, but then you should include a detailed description of
738 your hardware, and the output of \verb+mdrun -version+ (which contains
739 valuable diagnostic information in the header).
740
741 A build with \verb+-DGMX_BUILD_MDRUN_ONLY+ cannot be tested with
742 \verb+make check+ from the build tree, because most of the tests
743 require a full build to run things like \verb+grompp+. To test such an
744 mdrun fully requires installing it to the same location as a normal
745 build of \gromacs{}, downloading the regression tests tarball manually
746 as described above, sourcing the correct \verb+GMXRC+ and running the
747 perl script manually. For example, from your \gromacs{} source
748 directory:
749 \begin{verbatim}
750 mkdir build-normal
751 cd build-normal
752 cmake .. -DCMAKE_INSTALL_PREFIX=/your/installation/prefix/here
753 make -j 4
754 make install
755 cd ..
756 mkdir build-mdrun-only
757 cd build-mdrun-only
758 cmake .. -DGMX_MPI=ON -DGMX_GPU=ON -DGMX_BUILD_MDRUN_ONLY=ON -DCMAKE_INSTALL_PREFIX=/your/installation/prefix/here
759 make -j 4
760 make install
761 cd /to/your/unpacked/regressiontests
762 source /your/installation/prefix/here/bin/GMXRC
763 ./gmxtest.pl all -np 2
764 \end{verbatim}
765
766 \subsection{Testing \gromacs{} for performance}
767 We are still working on a set of benchmark systems for testing
768 the performance of \gromacs{}. Until that is ready, we recommend that
769 you try a few different parallelization options, and experiment with
770 tools such as \verb+gmx tune_pme+.
771
772 \subsection{Having difficulty?}
773 You're not alone - this can be a complex task! If you encounter a
774 problem with installing \gromacs{}, then there are a number of
775 locations where you can find assistance. It is recommended that you
776 follow these steps to find the solution:
777
778 \begin{enumerate}
779 \item Read the installation instructions again, taking note that you
780   have followed each and every step correctly.
781 \item Search the \gromacs{} website and users emailing list for
782   information on the error.
783 \item Search the internet using a search engine such as Google.
784 \item Post to the \gromacs{} users emailing list gmx-users for
785   assistance. Be sure to give a full description of what you have done
786   and why you think it didn't work. Give details about the system on
787   which you are installing. 
788   Copy and paste your command line and as
789   much of the output as you think might be relevant - certainly from
790   the first indication of a problem. In particular, please try to include at
791   least the header from the mdrun logfile, and preferably the entire file.
792   People who might volunteer to
793   help you do not have time to ask you interactive detailed follow-up
794   questions, so you will get an answer faster if you provide as much
795   information as you think could possibly help. High quality bug reports 
796   tend to receive rapid high quality answers.
797 \end{enumerate}
798
799 \section{Special instructions for some platforms}
800
801 \subsection{Building on Windows}
802 Building on Windows using native compilers is rather similar to
803 building on Unix, so please start by reading the above. Then, download
804 and unpack the GROMACS source archive. The UNIX-standard .tar.gz
805 format can be managed on Windows, but you may prefer to browse
806 \url{ftp://ftp.gromacs.org/pub/gromacs} to obtain a zip format file,
807 which doesn't need any external tools to unzip on recent Windows
808 systems. Make a folder in which to do the out-of-source build of
809 \gromacs{}. For example, make it within the folder unpacked from the
810 source archive, and call it ``build-cmake''. 
811
812 For \cmake{}, you can either use the graphical user interface provided
813 on Windows, or you can use a command line shell with instructions
814 similar to the UNIX ones above. If you open a shell from within
815 your IDE (e.g. Microsoft Visual Studio), it will configure the
816 environment for you, but you might need to tweak this in order to 
817 get either a 32-bit or 64-bit build environment. The latter provides the
818 fastest executable. If you use a normal Windows command shell, then
819 you will need to either set up the environment to find your compilers
820 and libraries yourself, or run the \verb+vcvarsall.bat+ batch script
821 provided by MSVC (just like sourcing a bash script under
822 Unix). 
823
824 With the graphical user interface you will be asked about what compilers
825 to use at the initial configuration stage, and if you use the command line
826 they can be set in a similar way as under UNIX.
827 You will probably make your life easier and faster by using the
828 new facility to download and install \fftw{} automatically. 
829
830 For the build, you can either load the generated solutions file into
831 e.g. Visual Studio, or use the command line with \verb+cmake --build .+ 
832 so the right tools get used.
833
834 \subsection{Building on Cray}
835
836 \gromacs{} builds mostly out of the box on modern Cray machines,
837 but you want to use static libraries due to the peculiarities with
838 parallel job execution.
839
840 \subsection{Building on BlueGene}
841
842 \subsubsection{BlueGene/P}
843
844 There is currently no SIMD support on this platform and no plans to
845 add it. The default plain C kernels will work.
846
847 \subsubsection{BlueGene/Q}
848
849 There is currently native acceleration on this platform for the Verlet
850 cut-off scheme. There are no plans to provide accelerated kernels for
851 the group cut-off scheme, but the default plain C kernels will work.
852
853 Only static linking with XL compilers is supported by \gromacs{}. Dynamic
854 linking would be supported by the architecture and \gromacs{}, but has no
855 advantages other than disk space, and is generally discouraged on
856 BlueGene for performance reasons.
857
858 Computation on BlueGene floating-point units is always done in
859 double-precision. However, single-precision builds of \gromacs{} are
860 still normal and encouraged since they use cache more efficiently. 
861 The BlueGene hardware automatically
862 converts values stored in single precision in memory to double
863 precision in registers for computation, converts the results back to
864 single precision correctly, and does so for no additional cost. As
865 with other platforms, doing the whole computation in double precision
866 normally shows no improvement in accuracy and costs twice as much time
867 moving memory around.
868
869 You need to arrange for FFTW to be installed correctly, following the
870 above instructions.
871
872 mpicc is used for compiling and linking. This can make it awkward to
873 attempt to use IBM's optimized BLAS/LAPACK called ESSL (see the
874 section on linear algebra). Since mdrun is the only part of \gromacs{}
875 that should normally run on the compute nodes, and there is nearly no
876 need for linear algebra support for mdrun, it is recommended to use
877 the \gromacs{} built-in linear algebra routines - it is rare for this
878 to be a bottleneck.
879
880 The recommended configuration is to use
881 \begin{verbatim}
882 cmake .. -DCMAKE_TOOLCHAIN_FILE=Platform/BlueGeneQ-static-XL-CXX \
883          -DCMAKE_PREFIX_PATH=/your/fftw/installation/prefix \
884          -DGMX_MPI=ON \
885          -DGMX_BUILD_MDRUN_ONLY=ON
886 make
887 make install
888 \end{verbatim}
889 which will build a statically-linked \mpi{}-enabled mdrun for the back
890 end. Otherwise, GROMACS default configuration behaviour applies.
891
892 It is possible to configure and make the remaining \gromacs{} tools
893 with the compute-node toolchain, but as none of those tools are
894 \mpi{}-aware and could then only run on the compute nodes, this
895 would not normally be useful. Instead, these should be planned
896 to run on the login node, and a separate \gromacs{} installation
897 performed for that using the login node's toolchain - not the
898 above platform file, or any other compute-node toolchain.
899
900 Note that only the MPI build is available for the compute-node
901 toolchains. The GROMACS thread-MPI or no-MPI builds are not useful at
902 all on BlueGene/Q.
903
904 \subsubsection{Fujitsu PRIMEHPC}
905
906 This is the architecture of the K computer, which uses Fujitsu
907 Sparc64viiifx chips. On this platform \gromacs{} \gromacsversion{} has
908 accelerated group kernels, no accelerated Verlet kernels, and a custom
909 build toolchain.
910
911 \subsubsection{Intel Xeon Phi}
912
913 \gromacs{} 5.0 has preliminary support for Intel Xeon Phi. Only symmetric
914 (aka native) mode is supported. \gromacs{} is functional on Xeon Phi,
915 but it has so far not been optimized to the same level as other
916 architectures have. The performance depends among other factors on the
917 system size (see ``Running in parallel''), and for now the performance
918 might not be faster than CPUs. Building for Xeon Phi works almost as any
919 other Unix. See the instructions above for details. The recommended
920 configuration is
921 \begin{verbatim}
922 cmake .. -DCMAKE_TOOLCHAIN_FILE=Platform/XeonPhi
923 make
924 make install
925 \end{verbatim}
926
927 \section{Tested platforms}
928
929 While it is our best belief that \gromacs{} will build and run pretty
930 much everywhere, it's important that we tell you where we really know
931 it works because we've tested it. We do test on Linux, Windows, and
932 Mac with a range of compilers and libraries for a range of our
933 configuration options. Every commit in our git source code
934 repository is currently tested on x86 with gcc versions ranging
935 from 4.4 through 4.8, and versions 12 and 13 of the Intel compiler as 
936 well as Clang version 3.1 through 3.3. For this we use a variety of GNU/Linux
937 flavors and versions as well as recent version of Mac OS X.
938 Under Windows we test both MSVC and the Intel compiler. For details, you can
939 have a look at the continuous integration server at \url{http://jenkins.gromacs.org}.
940
941 We test irregularly on BlueGene/Q, Cray,
942 Fujitsu PRIMEHPC, Google Native Client and other environments. In
943 the future we expect ARM to be an important test target too, but this
944 is currently not included.
945
946 Contributions to this section are welcome.
947
948 If there is interest, we might set up the ability for users to
949 contribute test results to Jenkins.
950
951 \end{document}