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