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