Declare __STDC_*_MACROS in gmxpre.h
[alexxy/gromacs.git] / docs / install-guide / install-guide.md
1 % Installation guide for GROMACS @PROJECT_VERSION@
2
3 # Introduction to building GROMACS #
4
5 These instructions pertain to building GROMACS
6 @PROJECT_VERSION@. Up-to-date installation instructions may be found
7 at <http://www.gromacs.org/Documentation/Installation_Instructions>.
8
9 ## Quick and dirty installation ##
10
11 1. Get the latest version of your C and C++ compilers.
12 2. Check that you have CMake version @GMX_CMAKE_MINIMUM_REQUIRED_VERSION@ or later.
13 3. Get and unpack the latest version of the GROMACS tarball.
14 4. Make a separate build directory and change to it. 
15 5. Run `cmake` with the path to the source as an argument
16 6. Run `make`, `make check`, and `make install`
17
18 Or, as a sequence of commands to execute:
19
20     tar xfz gromacs-@PROJECT_VERSION@.tar.gz
21     cd gromacs-@PROJECT_VERSION@
22     mkdir build
23     cd build
24     cmake .. -DGMX_BUILD_OWN_FFTW=ON -DREGRESSIONTEST_DOWNLOAD=ON
25     make
26     make check
27     sudo make install
28     source /usr/local/gromacs/bin/GMXRC
29
30 This will download and build first the prerequisite FFT library
31 followed by GROMACS. If you already have FFTW installed, you can
32 remove that argument to `cmake`. Overall, this build of GROMACS will
33 be correct and reasonably fast on the machine upon which `cmake`
34 ran. If you want to get the maximum value for your hardware with
35 GROMACS, you will have to read further. Sadly, the interactions of
36 hardware, libraries, and compilers are only going to continue to get
37 more complex.
38
39 ## Typical GROMACS installation ##
40
41 As above, and with further details below, but you should consider
42 using the following [CMake options](#using-cmake-command-line-options) with the
43 appropriate value instead of `xxx` :
44
45 * `-DCMAKE_C_COMPILER=xxx` equal to the name of the C99 [compiler](#compiler) you wish to use (or the environment variable `CC`)
46 * `-DCMAKE_CXX_COMPILER=xxx` equal to the name of the C++98 [compiler](#compiler) you wish to use (or the environment variable `CXX`)
47 * `-DGMX_MPI=on` to build using an [MPI](#mpi-support) wrapper compiler
48 * `-DGMX_GPU=on` to build using nvcc to run with an NVIDIA [GPU](#native-gpu-acceleration)
49 * `-DGMX_SIMD=xxx` to specify the level of [SIMD support](#simd-support) of the node on which `mdrun` will run
50 * `-DGMX_BUILD_MDRUN_ONLY=on` to [build only the `mdrun` binary](#building-only-mdrun), e.g. for compute cluster back-end nodes
51 * `-DGMX_DOUBLE=on` to run GROMACS in double precision (slower, and not normally useful)
52 * `-DCMAKE_PREFIX_PATH=xxx` to add a non-standard location for CMake to [search for libraries](#helping-cmake-find-the-right-librariesheadersprograms)
53 * `-DCMAKE_INSTALL_PREFIX=xxx` to install GROMACS to a non-standard location (default `/usr/local/gromacs`)
54 * `-DBUILD_SHARED_LIBS=off` to turn off the building of [shared libraries](#static-linking)
55 * `-DGMX_FFT_LIBRARY=xxx` to select whether to use `fftw`, `mkl` or `fftpack` libraries for [FFT support](#fast-fourier-transform-library)
56 * `-DCMAKE_BUILD_TYPE=Debug` to build GROMACS in debug mode
57
58 ## Building older GROMACS versions ##
59
60 For installation instructions for old GROMACS versions, see the
61 documentation at
62 <http://www.gromacs.org/Documentation/Installation_Instructions_4.5>
63 and
64 <http://www.gromacs.org/Documentation/Installation_Instructions_4.6>
65
66 # Prerequisites #
67
68 ## Platform ##
69
70 GROMACS can be compiled for many operating systems and architectures.
71 These include any distribution of Linux, Mac OS X or Windows, and
72 architectures including x86, AMD64/x86-64, PPC, ARM v7 and SPARC VIII.
73
74 ## Compiler ##
75
76 Technically, GROMACS can be compiled on any platform with an ANSI C99
77 and C++98 compiler, and their respective standard C/C++ libraries.
78 We use only a few C99 features, but note that the C++ compiler also needs to
79 support these C99 features (notably, int64_t and related things), which are not
80 part of the C++98 standard.
81 Getting good performance on an OS and architecture requires choosing a
82 good compiler. In practice, many compilers struggle to do a good job
83 optimizing the GROMACS architecture-optimized SIMD kernels.
84
85 For best performance, the GROMACS team strongly recommends you get the
86 most recent version of your preferred compiler for your platform.
87 There is a large amount of GROMACS code that depends on effective
88 compiler optimization to get high performance. This makes GROMACS
89 performance sensitive to the compiler used, and the binary will often
90 only work on the hardware for which it is compiled.
91
92 * In particular, GROMACS includes a lot of explicit SIMD
93 (single instruction, multiple data) optimization that can use
94 assembly instructions available on most modern processors. This
95 can have a substantial effect on performance, but for recent
96 processors you also need a similarly recent compiler that includes
97 support for the corresponding SIMD instruction set to get this
98 benefit. The configuration does a good job at detecting this,
99 and you will usually get warnings if GROMACS and your hardware
100 support a more recent instruction set than your compiler.
101
102 * On Intel-based x86 hardware, we recommend you to use the GNU
103 compilers version 4.7 or later or Intel compilers version 12 or later
104 for best performance. The Intel compiler has historically been better
105 at instruction scheduling, but recent gcc versions have proved to be
106 as fast or sometimes faster than Intel.
107
108 * The Intel and GNU compilers produce much faster GROMACS executables
109 than the PGI and Cray compilers.
110
111 * On AMD-based x86 hardware up through the "K10" microarchitecture
112 ("Family 10h") Thuban/Magny-Cours architecture (e.g. Opteron
113 6100-series processors), it is worth using the Intel compiler for
114 better performance, but gcc version 4.7 and later are also reasonable.
115
116 * On the AMD Bulldozer architecture (Opteron 6200), AMD introduced
117 fused multiply-add instructions and an "FMA4" instruction format not
118 available on Intel x86 processors. Thus, on the most recent AMD
119 processors you want to use gcc version 4.7 or later for best
120 performance! The Intel compiler will only generate code for the subset
121 also supported by Intel processors, and that is significantly slower.
122
123 * If you are running on Mac OS X, the best option is the Intel
124 compiler. Both clang and gcc will work, but they produce lower
125 performance and each have some shortcomings. Current Clang does not
126 support OpenMP. This may change when clang 3.5 becomes available.
127
128 * For all non-x86 platforms, your best option is typically to use the
129 vendor's default or recommended compiler, and check for specialized
130 information below.
131
132 ## Compiling with parallelization options ##
133
134 GROMACS can run in parallel on multiple cores of a single
135 workstation using its built-in thread-MPI. No user action is required
136 in order to enable this.
137
138 ### GPU support ###
139
140 If you wish to use the excellent native GPU support in GROMACS,
141 NVIDIA's [CUDA](http://www.nvidia.com/object/cuda_home_new.html)
142 version @REQUIRED_CUDA_VERSION@ software development kit is required,
143 and the latest version is strongly encouraged. NVIDIA GPUs with at
144 least NVIDIA compute capability @REQUIRED_CUDA_COMPUTE_CAPABILITY@ are
145 required, e.g. Fermi or Kepler cards. You are strongly recommended to
146 get the latest CUDA version and driver supported by your hardware, but
147 beware of possible performance regressions in newer CUDA versions on
148 older hardware. Note that while some CUDA compilers (nvcc) might not
149 officially support recent versions of gcc as the back-end compiler, we
150 still recommend that you at least use a gcc version recent enough to
151 get the best SIMD support for your CPU, since GROMACS always runs some
152 code on the CPU. It is most reliable to use the same C++ compiler
153 version for GROMACS code as used as the back-end compiler for nvcc,
154 but it could be faster to mix compiler versions to suit particular
155 contexts.
156
157 ### MPI support ###
158
159 If you wish to run in parallel on multiple machines across a network,
160 you will need to have
161
162 * an MPI library installed that supports the MPI 1.3
163   standard, and
164 * wrapper compilers that will compile code using that library.
165
166 The GROMACS team recommends [OpenMPI](http://www.open-mpi.org) version
167 1.6 (or higher), [MPICH](http://www.mpich.org) version 1.4.1 (or
168 higher), or your hardware vendor's MPI installation. The most recent
169 version of either of these is likely to be the best. More specialized
170 networks might depend on accelerations only available in the vendor's
171 library. [LAMMPI](http://www.lam-mpi.org) might work, but since it has
172 been deprecated for years, it is not supported.
173
174 Often [OpenMP](http://en.wikipedia.org/wiki/OpenMP) parallelism is an
175 advantage for GROMACS, but support for this is generally built into
176 your compiler and detected automatically.
177
178 In summary, for maximum performance you will need to examine how you
179 will use GROMACS, what hardware you plan to run on, and whether you
180 can afford a non-free compiler for slightly better
181 performance. Unfortunately, the only way to find out is to test
182 different options and parallelization schemes for the actual
183 simulations you want to run. You will still get *good*,
184 performance with the default build and runtime options, but if you
185 truly want to push your hardware to the performance limit, the days of
186 just blindly starting programs with `mdrun` are gone.
187
188 ## CMake ##
189
190 GROMACS @PROJECT_VERSION@ uses the CMake build system, and requires
191 version @GMX_CMAKE_MINIMUM_REQUIRED_VERSION@ or higher. Lower versions
192 will not work. You can check whether CMake is installed, and what
193 version it is, with `cmake --version`. If you need to install CMake,
194 then first check whether your platform's package management system
195 provides a suitable version, or visit
196 <http://www.cmake.org/cmake/help/install.html> for pre-compiled
197 binaries, source code and installation instructions. The GROMACS team
198 recommends you install the most recent version of CMake you can.
199
200 ## Fast Fourier Transform library ##
201
202 Many simulations in GROMACS make extensive use of fast Fourier
203 transforms, and a software library to perform these is always
204 required. We recommend [FFTW](http://www.fftw.org) (version 3 or
205 higher only) or
206 [Intel MKL](https://software.intel.com/en-us/intel-mkl). The choice of
207 library can be set with `cmake -DGMX_FFT_LIBRARY=<name>`, where
208 `<name>` is one of `fftw`, `mkl`, or `fftpack`. FFTPACK is bundled
209 with GROMACS as a fallback, and is acceptable if mdrun performance is
210 not a priority.
211
212 ### FFTW ###
213
214 FFTW is likely to be available for your platform via its package
215 management system, but there can be compatibility and significant
216 performance issues associated with these packages. In particular,
217 GROMACS simulations are normally run in "mixed" floating-point
218 precision, which is suited for the use of single precision in
219 FFTW. The default FFTW package is normally in double
220 precision, and good compiler options to use for FFTW when linked to
221 GROMACS may not have been used. Accordingly, the GROMACS team
222 recommends either
223
224 * that you permit the GROMACS installation to download and
225   build FFTW from source automatically for you (use
226   `cmake -DGMX_BUILD_OWN_FFTW=ON`), or
227 * that you build FFTW from the source code.
228
229 If you build FFTW from source yourself, get the most recent version
230 and follow its [installation
231 guide](http://www.fftw.org/doc/Installation-and-Customization.html#Installation-and-Customization).
232 Choose the precision for FFTW (i.e. single or float vs. double) to
233 match whether you will later use mixed or double precision for
234 GROMACS. There is no need to compile FFTW with
235 threading or MPI support, but it does no harm. On x86 hardware,
236 compile *only* with `--enable-sse2` (regardless of precision) even if
237 your processors can take advantage of AVX extensions. Since GROMACS
238 uses fairly short transform lengths we do not benefit from the FFTW
239 AVX acceleration, and because of memory system performance
240 limitations, it can even degrade GROMACS performance by around
241 20%. There is no way for GROMACS to limit the use to SSE2 SIMD at run
242 time if AVX support has been compiled into FFTW, so you need to set
243 this at compile time.
244
245 ### MKL ###
246
247 Using MKL with the Intel Compilers version 11 or higher is very
248 simple. Set up your compiler environment correctly, perhaps with a
249 command like `source /path/to/compilervars.sh intel64` (or consult
250 your local documentation). Then set `-DGMX_FFT_LIBRARY=mkl` when you
251 run cmake. In this case, GROMACS will also use MKL for BLAS and LAPACK
252 (see
253 [linear algebra libraries](#linear-algebra-libraries)). Generally,
254 there is no advantage in using MKL with GROMACS, and FFTW is often
255 faster.
256
257 Otherwise, you can get your hands dirty and configure MKL by setting
258
259     -DGMX_FFT_LIBRARY=mkl
260     -DMKL_LIBRARIES="/full/path/to/libone.so;/full/path/to/libtwo.so"
261     -DMKL_INCLUDE_DIR="/full/path/to/mkl/include"
262
263 where the full list (and order!) of libraries you require are found in
264 Intel's MKL documentation for your system.
265
266 ## Optional build components ##
267
268 * Compiling to run on NVIDIA GPUs requires CUDA
269 * An external Boost library can be used to provide better
270   implementation support for smart pointers and exception handling,
271   but the GROMACS source bundles a subset of Boost 1.55.0 as a fallback
272 * Hardware-optimized BLAS and LAPACK libraries are useful
273   for a few of the GROMACS utilities focused on normal modes and
274   matrix manipulation, but they do not provide any benefits for normal
275   simulations. Configuring these are discussed at
276   [linear algebra libraries](#linear-algebra-libraries).
277 * The built-in GROMACS trajectory viewer `gmx view` requires X11 and
278   Motif/Lesstif libraries and header files. You may prefer to use
279   third-party software for visualization, such as
280   [VMD](http://www.ks.uiuc.edu/Research/vmd) or
281   [PyMOL](http://www.pymol.org).
282 * An external TNG library for trajectory-file handling can be used,
283   but TNG 1.6 is bundled in the GROMACS source already
284 * zlib is used by TNG for compressing some kinds of trajectory data
285 * Running the GROMACS test suite requires libxml2
286 * Building the GROMACS documentation requires ImageMagick, pdflatex,
287   bibtex, doxygen and pandoc.
288 * The GROMACS utility programs often write data files in formats
289   suitable for the Grace plotting tool, but it is straightforward to
290   use these files in other plotting programs, too.
291
292 # Doing a build of GROMACS #
293
294 This section will cover a general build of GROMACS with CMake, but it
295 is not an exhaustive discussion of how to use CMake. There are many
296 resources available on the web, which we suggest you search for when
297 you encounter problems not covered here. The material below applies
298 specifically to builds on Unix-like systems, including Linux, and Mac
299 OS X. For other platforms, see the specialist instructions below.
300
301 ## Configuring with CMake ##
302
303 CMake will run many tests on your system and do its best to work out
304 how to build GROMACS for you. If your build machine is the same as
305 your target machine, then you can be sure that the defaults will be
306 pretty good. The build configuration will for instance attempt to
307 detect the specific hardware instructions available in your
308 processor. However, if you want to control aspects of the build, or
309 you are compiling on a cluster head node for back-end nodes with a
310 different architecture, there are plenty of things you can set
311 manually.
312
313 The best way to use CMake to configure GROMACS is to do an
314 "out-of-source" build, by making another directory from which you will
315 run CMake. This can be outside the source directory, or a subdirectory
316 of it. It also means you can never corrupt your source code by trying
317 to build it! So, the only required argument on the CMake command line
318 is the name of the directory containing the `CMakeLists.txt` file of
319 the code you want to build. For example, download the source tarball
320 and use
321
322     $ tar xfz gromacs-@PROJECT_VERSION@.tgz
323     $ cd gromacs-@PROJECT_VERSION@
324     $ mkdir build-gromacs
325     $ cd build-gromacs
326     $ cmake ..
327
328 You will see `cmake` report a sequence of results of tests and
329 detections done by the GROMACS build system. These are written to the
330 `cmake` cache, kept in `CMakeCache.txt`. You can edit this file by
331 hand, but this is not recommended because you could make a mistake.
332 You should not attempt to move or copy this file to do another build,
333 because file paths are hard-coded within it. If you mess things up,
334 just delete this file and start again with `cmake`.
335
336 If there is a serious problem detected at this stage, then you will see
337 a fatal error and some suggestions for how to overcome it. If you are
338 not sure how to deal with that, please start by searching on the web
339 (most computer problems already have known solutions!) and then
340 consult the gmx-users mailing list. There are also informational
341 warnings that you might like to take on board or not. Piping the
342 output of `cmake` through `less` or `tee` can be
343 useful, too.
344
345 Once `cmake` returns, you can see all the settings that were chosen
346 and information about them by using e.g. the curses interface
347
348     $ ccmake ..
349
350 You can actually use `ccmake` (available on most Unix platforms,
351 if the curses library is supported) directly in the first step, but then
352 most of the status messages will merely blink in the lower part
353 of the terminal rather than be written to standard out. Most platforms
354 including Linux, Windows, and Mac OS X even have native graphical user interfaces for
355 `cmake`, and it can create project files for almost any build environment
356 you want (including Visual Studio or Xcode).
357 Check out <http://www.cmake.org/cmake/help/runningcmake.html> for
358 general advice on what you are seeing and how to navigate and change
359 things. The settings you might normally want to change are already
360 presented. You may make changes, then re-configure (using `c`), so that it
361 gets a chance to make changes that depend on yours and perform more
362 checking. It may take several configuration passes to reach the desired
363 configuration, in particular if you need to resolve errors.
364
365 A key thing to consider here is the setting of
366 `CMAKE_INSTALL_PREFIX`. You will need to be able to write to this
367 directory in order to install GROMACS later, and if you change your
368 mind later, changing it in the cache triggers a full re-build,
369 unfortunately. So if you do not have super-user privileges on your
370 machine, then you will need to choose a sensible location within your
371 home directory for your GROMACS installation. Even if you do have
372 super-user privileges, you should use them only for the installation
373 phase, and never for configuring, building, or running GROMACS!
374
375 When you have reached the desired configuration with `ccmake`, the
376 build system can be generated by pressing `g`.  This requires that the previous
377 configuration pass did not reveal any additional settings (if it did, you need
378 to configure once more with `c`).  With `cmake`, the build system is generated
379 after each pass that does not produce errors.
380
381 You cannot attempt to change compilers after the initial run of
382 `cmake`. If you need to change, clean up, and start again.
383
384 ### Using CMake command-line options ###
385
386 Once you become comfortable with setting and changing options, you may
387 know in advance how you will configure GROMACS. If so, you can speed
388 things up by invoking `cmake` and passing the various options at once
389 on the command line. This can be done by setting cache variable at the
390 cmake invocation using the `-DOPTION=VALUE`; note that some
391 environment variables are also taken into account, in particular
392 variables like CC, CXX, FCC (which may be familiar to autoconf users).
393
394 For example, the following command line
395
396     $ cmake .. -DGMX_GPU=ON -DGMX_MPI=ON -DCMAKE_INSTALL_PREFIX=/home/marydoe/programs
397
398 can be used to build with GPUs, MPI and install in a custom
399 location. You can even save that in a shell script to make it even
400 easier next time. You can also do this kind of thing with `ccmake`,
401 but you should avoid this, because the options set with `-D` will not
402 be able to be changed interactively in that run of `ccmake`.
403
404 ### SIMD support ###
405
406 GROMACS has extensive support for detecting and using the SIMD
407 capabilities of many modern HPC CPU architectures. If you are building
408 GROMACS on the same hardware you will run it on, then you don't need
409 to read more about this, unless you are getting configuration warnings
410 you do not understand. By default, the GROMACS build system will
411 detect the SIMD instruction set supported by the CPU architecture (on
412 which the configuring is done), and thus pick the best
413 available SIMD parallelization supported by GROMACS. The build system
414 will also check that the compiler and linker used also support the
415 selected SIMD instruction set and issue a fatal error if they
416 do not.
417
418 Valid values are listed below, and the
419 applicable value lowest on the list is generally the one you should
420 choose:
421
422 1. `None` For use only on an architecture either lacking SIMD,
423   or to which GROMACS has not yet been ported and none of the
424   options below are applicable.
425 2. `SSE2` This SIMD instruction set was introduced in Intel
426    processors in 2001, and AMD in 2003. Essentially all x86
427    machines in existence have this, so it might be a good choice if
428    you need to support dinosaur x86 computers too.
429 3. `SSE4.1` Present in all Intel core processors since 2007,
430    but notably not in AMD magny-cours. Still, almost all recent
431    processors support this, so this can also be considered a good
432    baseline if you are content with portability between reasonably
433    modern processors.
434 4. `AVX_128_FMA` AMD bulldozer processors (2011) have this.
435    Unfortunately Intel and AMD have diverged the last few years;
436    If you want good performance on modern AMD processors
437    you have to use this since it also allows the reset of the
438    code to use AMD 4-way fused multiply-add instructions. The drawback
439    is that your code will not run on Intel processors at all.
440 5. `AVX_256` This instruction set is present on Intel processors
441    since Sandy Bridge (2011), where it is the best choice unless
442    you have an even more recent CPU that supports AVX2. While this
443    code will work on recent AMD processors, it is significantly
444    less efficient than the AVX_128_FMA choice above - do not be
445    fooled to assume that 256 is better than 128 in this case.
446 6. `AVX2_256` Present on Intel Haswell processors released in 2013,
447    and it will also enable Intel 3-way fused multiply-add instructions.
448    This code will not work on AMD CPUs.
449 7. `IBM_QPX ` BlueGene/Q A2 cores have this.
450 8. `Sparc64_HPC_ACE` Fujitsu machines like the K computer have this.
451
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. However, since the options also enable general compiler
458 flags for the platform in question, you can end up in situations
459 where e.g. an `AVX_128_FMA` binary will just crash on any
460 Intel machine, since the code will try to execute general illegal
461 instructions (inserted by the compiler) before `mdrun` gets to the
462 architecture detection routines.
463
464 A further `GMX_SIMD=Reference` option exists, which is a special
465 SIMD-like implementation written in plain C that developers can use
466 when developing support in GROMACS for new SIMD architectures. It is
467 not designed for use in production simulations, but if you are using
468 an architecture with SIMD support to which GROMACS has not yet been
469 ported, you may wish to try this option instead of the default
470 `GMX_SIMD=None`, as it can often out-perform this when the
471 auto-vectorization in your compiler does a good job. And post on the
472 GROMACS mailing lists, because GROMACS can probably be ported for new
473 SIMD architectures in a few days.
474
475 ### CMake advanced options ###
476
477 The options that are displayed in the default view of `ccmake` are
478 ones that we think a reasonable number of users might want to consider
479 changing. There are a lot more options available, which you can see by
480 toggling the advanced mode in `ccmake` on and off with `t`. Even
481 there, most of the variables that you might want to change have a
482 `CMAKE_` or `GMX_` prefix. There are also some options that will be
483 visible or not according to whether their preconditions are satisfied.
484
485 ### Helping CMake find the right libraries/headers/programs ###
486
487 If libraries are installed in non-default locations their location can
488 be specified using the following environment variables:
489
490 * `CMAKE_INCLUDE_PATH` for header files
491 * `CMAKE_LIBRARY_PATH` for libraries
492 * `CMAKE_PREFIX_PATH` for header, libraries and binaries
493   (e.g. `/usr/local`).
494
495 The respective `include`, `lib`, or `bin` is
496 appended to the path. For each of these variables, a list of paths can
497 be specified (on Unix, separated with ":"). Note that these are
498 enviroment variables (and not `cmake` command-line arguments) and in
499 a `bash` shell are used like:
500
501     $ CMAKE_PREFIX_PATH=/opt/fftw:/opt/cuda cmake ..
502
503 Alternatively, these variables are also `cmake` options, so they can
504 be set like `-DCMAKE_PREFIX_PATH=/opt/fftw:/opt/cuda`.
505
506 The `CC` and `CXX` environment variables are also useful
507 for indicating to `cmake` which compilers to use, which can be very
508 important for maximising GROMACS performance. Similarly,
509 `CFLAGS`/`CXXFLAGS` can be used to pass compiler
510 options, but note that these will be appended to those set by
511 GROMACS for your build platform and build type. You can customize
512 some of this with advanced options such as `CMAKE_C_FLAGS`
513 and its relatives.
514
515 See also: <http://cmake.org/Wiki/CMake_Useful_Variables#Environment_Variables>
516
517 ### Native GPU acceleration ###
518 If you have the CUDA Toolkit installed, you can use `cmake` with:
519
520     $ cmake .. -DGMX_GPU=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda
521
522 (or whichever path has your installation). In some cases, you might
523 need to specify manually which of your C++ compilers should be used,
524 e.g. with the advanced option `CUDA_HOST_COMPILER`.
525
526 The GPU acceleration has been tested on AMD64/x86-64 platforms with
527 Linux, Mac OS X and Windows operating systems, but Linux is the
528 best-tested and supported of these. Linux running on ARM v7 (32 bit)
529 CPUs also works.
530
531 ### Static linking ###
532 Dynamic linking of the GROMACS executables will lead to a
533 smaller disk footprint when installed, and so is the default on
534 platforms where we believe it has been tested repeatedly and found to work.
535 In general, this includes Linux, Windows, Mac OS X and BSD systems.
536 Static binaries take much more space, but on some hardware and/or under
537 some conditions they are necessary, most commonly when you are running a parallel
538 simulation using MPI libraries (e.g. BlueGene, Cray).
539
540 * To link GROMACS binaries
541 statically against the internal GROMACS libraries, set
542 `-DBUILD_SHARED_LIBS=OFF`.
543 * To link statically against external (non-system) libraries as well,
544 the `-DGMX_PREFER_STATIC_LIBS=ON` option can be used. Note, that in
545 general `cmake` picks up whatever is available, so this option only
546 instructs `cmake` to prefer static libraries when both static and
547 shared are available. If no static version of an external library is
548 available, even when the aforementioned option is `ON`, the shared
549 library will be used. Also note, that the resulting binaries will
550 still be dynamically linked against system libraries on platforms
551 where that is the default. To use static system libraries, additional
552 compiler/linker flags are necessary, e.g. `-static-libgcc
553 -static-libstdc++`.
554
555 ### Portability aspects ###
556
557 Here, we consider portability aspects related to CPU instruction sets,
558 for details on other topics like binaries with statical vs dynamic
559 linking please consult the relevant parts of this documentation or
560 other non-GROMACS specific resources.
561
562 A GROMACS build will normally not be portable, not even across
563 hardware with the same base instruction set like x86. Non-portable
564 hardware-specific optimizations are selected at configure-time, such
565 as the SIMD instruction set used in the compute-kernels. This
566 selection will be done by the build system based on the capabilities
567 of the build host machine or based on cross-compilation information
568 provided to `cmake` at configuration.
569
570 Often it is possible to ensure portability by choosing the least
571 common denominator of SIMD support, e.g. SSE2 for x86, and ensuring
572 the you use `cmake -DGMX_USE_RDTSCP=off` if any of the target CPU
573 architectures does not support the `RDTSCP` instruction.  However, we
574 discourage attempts to use a single GROMACS installation when the
575 execution environment is heterogeneous, such as a mix of AVX and
576 earlier hardware, because this will lead to programs (especially
577 `mdrun`) that run slowly on the new hardware. Building two full
578 installations and locally managing how to call the correct one
579 (e.g. using the module system) is the recommended
580 approach. Alternatively, as at the moment the GROMACS tools do not
581 make strong use of SIMD acceleration, it can be convenient to create
582 an installation with tools portable across different x86 machines, but
583 with separate `mdrun` binaries for each architecture. To achieve this,
584 one can first build a full installation with the
585 least-common-denominator SIMD instruction set, e.g. `-DGMX_SIMD=SSE2`,
586 then build separate `mdrun` binaries for each architecture present in
587 the heterogeneous environment. By using custom binary and library
588 suffixes for the `mdrun`-only builds, these can be installed to the
589 same location as the "generic" tools installation. Building [only the
590 `mdrun` binary](#building-only-mdrun) is possible by setting the `-DGMX_BUILD_MDRUN_ONLY=ON`
591 option.
592
593 ### Linear algebra libraries ###
594
595 As mentioned above, sometimes vendor BLAS and LAPACK libraries
596 can provide performance enhancements for GROMACS when doing
597 normal-mode analysis or covariance analysis. For simplicity, the text
598 below will refer only to BLAS, but the same options are available
599 for LAPACK. By default, CMake will search for BLAS, use it if it
600 is found, and otherwise fall back on a version of BLAS internal to
601 GROMACS. The `cmake` option `-DGMX_EXTERNAL_BLAS=on` will be set
602 accordingly. The internal versions are fine for normal use. If you
603 need to specify a non-standard path to search, use
604 `-DCMAKE_PREFIX_PATH=/path/to/search`. If you need to specify a
605 library with a non-standard name (e.g. ESSL on AIX or BlueGene), then
606 set `-DGMX_BLAS_USER=/path/to/reach/lib/libwhatever.a`.
607
608 If you are using Intel MKL for FFT, then the BLAS and
609 LAPACK it provides are used automatically. This could be
610 over-ridden with `GMX_BLAS_USER`, etc.
611
612 On Apple platforms where the Accelerate Framework is available, these
613 will be automatically used for BLAS and LAPACK. This could be
614 over-ridden with `GMX_BLAS_USER`, etc.
615
616 ### Changing the names of GROMACS binaries and libraries ###
617
618 It is sometimes convenient to have different versions of the same
619 GROMACS programs installed. The most common use cases have been single
620 and double precision, and with and without MPI. This mechanism can
621 also be used to install side-by-side multiple versions of `mdrun`
622 optimized for different CPU architectures, as mentioned previously.
623
624 By default, GROMACS will suffix programs and libraries for such builds
625 with `_d` for double precision and/or `_mpi` for MPI (and nothing
626 otherwise). This can be controlled manually with `GMX_DEFAULT_SUFFIX
627 (ON/OFF)`, `GMX_BINARY_SUFFIX` (takes a string) and `GMX_LIBS_SUFFIX`
628 (also takes a string). For instance, to set a custom suffix for
629 programs and libraries, one might specify:
630
631     cmake .. -DGMX_DEFAULT_SUFFIX=OFF -DGMX_BINARY_SUFFIX=_mod -DGMX_LIBS_SUFFIX=_mod
632
633 Thus the names of all programs and libraries will be appended with
634 `_mod`.
635
636 ### Changing installation tree structure ###
637
638 By default, a few different directories under `CMAKE_INSTALL_PREFIX` are used
639 when when GROMACS is installed. Some of these can be changed, which is mainly
640 useful for packaging GROMACS for various distributions. The directories are
641 listed below, with additional notes about some of them. Unless otherwise noted,
642 the directories can be renamed by editing the installation paths in the main
643 CMakeLists.txt.
644
645 `bin/`
646   : The standard location for executables, some scripts, and some symlinks.
647     Some of the scripts hardcode the absolute installation prefix, which needs
648     to be changed if the scripts are relocated.
649 `include/gromacs/`
650   : The standard location for installed headers.
651 `lib/`
652   : The standard location for libraries. The default depends on the system, and
653     is determined by CMake.
654     The name of the directory can be changed using `GMX_LIB_INSTALL_DIR` CMake
655     variable.
656 `lib/pkgconfig/`
657   : Information about the installed `libgromacs` library for `pkg-config` is
658     installed here.  The `lib/` part adapts to the installation location of the
659     libraries.  The installed files contain the installation prefix as absolute
660     paths.
661 `share/cmake/`
662   : CMake package configuration files are installed here.
663 `share/gromacs/`
664   : Various data files and some documentation go here.
665     The `gromacs` part can be changed using `GMX_DATA_INSTALL_DIR`. Using this
666     CMake variable is the preferred way of changing the installation path for
667     `share/gromacs/top/`, since the path to this directory is built into
668     `libgromacs` as well as some scripts, both as a relative and as an absolute
669     path (the latter as a fallback if everything else fails).
670 `share/man/`
671   : Installed man pages go here.
672
673 ## Compiling and linking ##
674
675 Once you have configured with `cmake`, you can build GROMACS with `make`.
676 It is expected that this will always complete successfully, and
677 give few or no warnings. The CMake-time tests GROMACS makes on the settings
678 you choose are pretty extensive, but there are probably a few cases we
679 have not thought of yet. Search the web first for solutions to
680 problems, but if you need help, ask on gmx-users, being sure to
681 provide as much information as possible about what you did, the system
682 you are building on, and what went wrong. This may mean scrolling back
683 a long way through the output of `make` to find the first error
684 message!
685
686 If you have a multi-core or multi-CPU machine with `N`
687 processors, then using
688
689     $ make -j N
690
691 will generally speed things up by quite a bit. Other build generator systems
692 supported by `cmake` (e.g. `ninja`) also work well.
693
694 ### Building only mdrun ###
695
696 Past versions of the build system offered "mdrun" and "install-mdrun"
697 targets (similarly for other programs too) to build and install only
698 the mdrun program, respectively. Such a build is useful when the
699 configuration is only relevant for `mdrun` (such as with
700 parallelization options for MPI, SIMD, GPUs, or on BlueGene or Cray),
701 or the length of time for the compile-link-install cycle is relevant
702 when developing.
703
704 This is now supported with the `cmake` option
705 `-DGMX_BUILD_MDRUN_ONLY=ON`, which will build a cut-down version of
706 `libgromacs` and/or the `mdrun` program (according to whether shared
707 or static). Naturally, now `make install` installs only those
708 products. By default, mdrun-only builds will default to static linking
709 against GROMACS libraries, because this is generally a good idea for
710 the targets for which an mdrun-only build is desirable. If you re-use
711 a build tree and change to the mdrun-only build, then you will inherit
712 the setting for `BUILD_SHARED_LIBS` from the old build, and will be
713 warned that you may wish to manage `BUILD_SHARED_LIBS` yourself.
714
715 ## Installing GROMACS ##
716
717 Finally, `make install` will install GROMACS in the
718 directory given in `CMAKE_INSTALL_PREFIX`. If this is a system
719 directory, then you will need permission to write there, and you
720 should use super-user privileges only for `make install` and
721 not the whole procedure.
722
723 ## Getting access to GROMACS after installation ##
724
725 GROMACS installs the script `GMXRC` in the `bin`
726 subdirectory of the installation directory
727 (e.g. `/usr/local/gromacs/bin/GMXRC`), which you should source
728 from your shell:
729
730     $ source /your/installation/prefix/here/bin/GMXRC
731
732 It will detect what kind of shell you are running and set up your
733 environment for using GROMACS. You may wish to arrange for your
734 login scripts to do this automatically; please search the web for
735 instructions on how to do this for your shell. 
736
737 Many of the GROMACS programs rely on data installed in the
738 `share/gromacs` subdirectory of the installation directory. By
739 default, the programs will use the environment variables set in the
740 `GMXRC` script, and if this is not available they will try to guess the
741 path based on their own location.  This usually works well unless you
742 change the names of directories inside the install tree. If you still
743 need to do that, you might want to recompile with the new install
744 location properly set, or edit the `GMXRC` script.
745
746 ## Testing GROMACS for correctness ##
747
748 Since 2011, the GROMACS development uses an automated system where
749 every new code change is subject to regression testing on a number of
750 platforms and software combinations. While this improves
751 reliability quite a lot, not everything is tested, and since we
752 increasingly rely on cutting edge compiler features there is
753 non-negligible risk that the default compiler on your system could
754 have bugs. We have tried our best to test and refuse to use known bad
755 versions in `cmake`, but we strongly recommend that you run through
756 the tests yourself. It only takes a few minutes, after which you can
757 trust your build.
758
759 The simplest way to run the checks is to build GROMACS with
760 `-DREGRESSIONTEST_DOWNLOAD`, and run `make check`.
761 GROMACS will automatically download and run the tests for you.
762 Alternatively, you can download and unpack the tarball yourself from
763 <http://gerrit.gromacs.org/download/regressiontests-@REGRESSIONTEST_VERSION@.tar.gz>,
764 and use the advanced `cmake` option `REGRESSIONTEST_PATH` to
765 specify the path to the unpacked tarball, which will then be used for
766 testing. If the above does not work, then please read on.
767
768 The regression tests are available from the GROMACS website and ftp
769 site.  Once you have downloaded them, unpack the tarball, source
770 `GMXRC` as described above, and run `./gmxtest.pl all`
771 inside the regression tests folder. You can find more options
772 (e.g. adding `double` when using double precision, or
773 `-only expanded` to run just the tests whose names match
774 "expanded") if you just execute the script without options.
775
776 Hopefully, you will get a report that all tests have passed. If there
777 are individual failed tests it could be a sign of a compiler bug, or
778 that a tolerance is just a tiny bit too tight. Check the output files
779 the script directs you too, and try a different or newer compiler if
780 the errors appear to be real. If you cannot get it to pass the
781 regression tests, you might try dropping a line to the gmx-users
782 mailing list, but then you should include a detailed description of
783 your hardware, and the output of `mdrun -version` (which contains
784 valuable diagnostic information in the header).
785
786 A build with `-DGMX_BUILD_MDRUN_ONLY` cannot be tested with
787 `make check` from the build tree, because most of the tests
788 require a full build to run things like `grompp`. To test such an
789 mdrun fully requires installing it to the same location as a normal
790 build of GROMACS, downloading the regression tests tarball manually
791 as described above, sourcing the correct `GMXRC` and running the
792 perl script manually. For example, from your GROMACS source
793 directory:
794
795     $ mkdir build-normal
796     $ cd build-normal
797     $ cmake .. -DCMAKE_INSTALL_PREFIX=/your/installation/prefix/here
798     $ make -j 4
799     $ make install
800     $ cd ..
801     $ mkdir build-mdrun-only
802     $ cd build-mdrun-only
803     $ cmake .. -DGMX_MPI=ON -DGMX_GPU=ON -DGMX_BUILD_MDRUN_ONLY=ON -DCMAKE_INSTALL_PREFIX=/your/installation/prefix/here
804     $ make -j 4
805     $ make install
806     $ cd /to/your/unpacked/regressiontests
807     $ source /your/installation/prefix/here/bin/GMXRC
808     $ ./gmxtest.pl all -np 2
809
810 If your `mdrun` program has been suffixed in a non-standard way, then
811 the `./gmxtest.pl -mdrun` option will let you specify that name to the
812 test machinery. You can use `./gmxtest.pl -double` to test the
813 double-precision version. You can use `./gmxtest.pl -crosscompiling`
814 to stop the test harness attempting to check that the programs can
815 be run.
816
817
818 ## Testing GROMACS for performance ##
819 We are still working on a set of benchmark systems for testing
820 the performance of GROMACS. Until that is ready, we recommend that
821 you try a few different parallelization options, and experiment with
822 tools such as `gmx tune_pme`.
823
824 ## Having difficulty? ##
825 You are not alone - this can be a complex task! If you encounter a
826 problem with installing GROMACS, then there are a number of
827 locations where you can find assistance. It is recommended that you
828 follow these steps to find the solution:
829
830 1. Read the installation instructions again, taking note that you
831    have followed each and every step correctly.
832
833 2. Search the GROMACS website and users emailing list for information
834    on the error. Adding
835    "site:https://mailman-1.sys.kth.se/pipermail/gromacs.org_gmx-users"
836    to a Google search may help filter better results.
837
838 3. Search the internet using a search engine such as Google.
839
840 4. Post to the GROMACS users emailing list gmx-users for
841    assistance. Be sure to give a full description of what you have
842    done and why you think it did not work. Give details about the
843    system on which you are installing.  Copy and paste your command
844    line and as much of the output as you think might be relevant -
845    certainly from the first indication of a problem. In particular,
846    please try to include at least the header from the mdrun logfile,
847    and preferably the entire file.  People who might volunteer to help
848    you do not have time to ask you interactive detailed follow-up
849    questions, so you will get an answer faster if you provide as much
850    information as you think could possibly help. High quality bug
851    reports tend to receive rapid high quality answers.
852
853 # Special instructions for some platforms #
854
855 ## Building on Windows ##
856
857 Building on Windows using native compilers is rather similar to
858 building on Unix, so please start by reading the above. Then, download
859 and unpack the GROMACS source archive. Make a folder in which to do
860 the out-of-source build of GROMACS. For example, make it within the
861 folder unpacked from the source archive, and call it `build-gromacs`.
862
863 For CMake, you can either use the graphical user interface provided on
864 Windows, or you can use a command line shell with instructions similar
865 to the UNIX ones above. If you open a shell from within your IDE
866 (e.g. Microsoft Visual Studio), it will configure the environment for
867 you, but you might need to tweak this in order to get either a 32-bit
868 or 64-bit build environment. The latter provides the fastest
869 executable. If you use a normal Windows command shell, then you will
870 need to either set up the environment to find your compilers and
871 libraries yourself, or run the `vcvarsall.bat` batch script provided
872 by MSVC (just like sourcing a bash script under Unix).
873
874 With the graphical user interface, you will be asked about what
875 compilers to use at the initial configuration stage, and if you use
876 the command line they can be set in a similar way as under UNIX. You
877 will probably make your life easier and faster by using the new
878 facility to download and install FFTW automatically.
879
880 For the build, you can either load the generated solutions file into
881 e.g. Visual Studio, or use the command line with `cmake --build` so
882 the right tools get used.
883
884 ## Building on Cray ##
885
886 GROMACS builds mostly out of the box on modern Cray machines, but
887 * you may need to specify the use of static or dynamic libraries
888   (depending on the machine) with `-DBUILD_SHARED_LIBS=off`,
889 * you may need to set the F77 environmental variable to `ftn` when
890   compiling FFTW,
891 * you may need to use `-DCMAKE_SKIP_RPATH=YES`, and
892 * you may need to modify the CMakeLists.txt files to specify the
893   `BUILD_SEARCH_END_STATIC` target property.
894
895 ## Building on BlueGene ##
896
897 ### BlueGene/Q ###
898
899 There is currently native acceleration on this platform for the Verlet
900 cut-off scheme. There are no plans to provide accelerated kernels for
901 the group cut-off scheme, but the default plain C kernels will work
902 (slowly).
903
904 Only static linking with XL compilers is supported by GROMACS. Dynamic
905 linking would be supported by the architecture and GROMACS, but has no
906 advantages other than disk space, and is generally discouraged on
907 BlueGene for performance reasons.
908
909 Computation on BlueGene floating-point units is always done in
910 double-precision. However, mixed-precision builds of GROMACS are still
911 normal and encouraged since they use cache more efficiently. The
912 BlueGene hardware automatically converts values stored in single
913 precision in memory to double precision in registers for computation,
914 converts the results back to single precision correctly, and does so
915 for no additional cost. As with other platforms, doing the whole
916 computation in double precision normally shows no improvement in
917 accuracy and costs twice as much time moving memory around.
918
919 You need to arrange for FFTW to be installed correctly, following the
920 above instructions.
921
922 MPI wrapper compilers should be used for compiling and linking. Both
923 xlc and bgclang are supported back ends - either might prove to be
924 faster in practice. The MPI wrapper compilers can make it awkward to
925 attempt to use IBM's optimized BLAS/LAPACK called ESSL (see the
926 section on [linear algebra
927 libraries](#linear-algebra-libraries)). Since mdrun is the only part
928 of GROMACS that should normally run on the compute nodes, and there is
929 nearly no need for linear algebra support for mdrun, it is recommended
930 to use the GROMACS built-in linear algebra routines - this is never
931 a problem for normal simulations.
932
933 The recommended configuration is to use
934
935     cmake .. -DCMAKE_C_COMPILER=mpicc \
936              -DCMAKE_CXX_COMPILER=mpicxx \
937              -DCMAKE_TOOLCHAIN_FILE=Platform/BlueGeneQ-static-XL-CXX.cmake \
938              -DCMAKE_PREFIX_PATH=/your/fftw/installation/prefix \
939              -DGMX_MPI=ON \
940              -DGMX_BUILD_MDRUN_ONLY=ON
941     make
942     make install
943
944 which will build a statically-linked MPI-enabled mdrun for the compute
945 nodes. Or use the Platform/BlueGeneQ-static-bgclang-cxx
946 toolchain file if compiling with bgclang. Otherwise, GROMACS default configuration
947 behaviour applies.
948
949 It is possible to configure and make the remaining GROMACS tools with
950 the compute-node toolchain, but as none of those tools are MPI-aware
951 and could then only run on the compute nodes, this would not normally
952 be useful. Instead, these should be planned to run on the login node,
953 and a separate GROMACS installation performed for that using the login
954 node's toolchain - not the above platform file, or any other
955 compute-node toolchain.
956
957 Note that only the MPI build is available for the compute-node
958 toolchains. The GROMACS thread-MPI or no-MPI builds are not useful at
959 all on BlueGene/Q.
960
961 ### BlueGene/P ###
962
963 There is currently no SIMD support on this platform and no plans to
964 add it. The default plain C kernels will work.
965
966 ### Fujitsu PRIMEHPC ###
967
968 This is the architecture of the K computer, which uses Fujitsu
969 `Sparc64VIIIfx` chips. On this platform, GROMACS @PROJECT_VERSION@ has
970 accelerated group kernels using the HPC-ACE instructions, no
971 accelerated Verlet kernels, and a custom build toolchain. Since this
972 particular chip only does double precision SIMD, the default setup
973 is to build Gromacs in double. Since most users only need single, we have added
974 an option GMX_RELAXED_DOUBLE_PRECISION to accept single precision square root
975 accuracy in the group kernels; unless you know that you really need 15 digits
976 of accuracy in each individual force, we strongly recommend you use this. Note
977 that all summation and other operations are still done in double.
978
979 The recommended configuration is to use
980
981     cmake .. -DCMAKE_TOOLCHAIN_FILE=Toolchain-Fujitsu-Sparc64-mpi.cmake \
982              -DCMAKE_PREFIX_PATH=/your/fftw/installation/prefix \
983              -DCMAKE_INSTALL_PREFIX=/where/gromacs/should/be/installed \
984              -DGMX_MPI=ON \
985              -DGMX_BUILD_MDRUN_ONLY=ON \
986              -DGMX_RELAXED_DOUBLE_PRECISION=ON
987     make
988     make install
989
990 ### Intel Xeon Phi ###
991
992 GROMACS @PROJECT_VERSION@ has preliminary support for Intel Xeon Phi. Only symmetric
993 (aka native) mode is supported. GROMACS is functional on Xeon Phi, but
994 it has so far not been optimized to the same level as other
995 architectures have. The performance depends among other factors on the
996 system size, and for
997 now the performance might not be faster than CPUs. Building for Xeon
998 Phi works almost as any other Unix. See the instructions above for
999 details. The recommended configuration is
1000
1001     cmake .. -DCMAKE_TOOLCHAIN_FILE=Platform/XeonPhi
1002     make
1003     make install
1004
1005 # Tested platforms #
1006
1007 While it is our best belief that GROMACS will build and run pretty
1008 much everywhere, it is important that we tell you where we really know
1009 it works because we have tested it. We do test on Linux, Windows, and
1010 Mac with a range of compilers and libraries for a range of our
1011 configuration options. Every commit in our git source code repository
1012 is currently tested on x86 with gcc versions ranging from 4.4 through
1013 4.7, and versions 12 and 13 of the Intel compiler as well as Clang
1014 version 3.1 through 3.4. For this, we use a variety of GNU/Linux
1015 flavors and versions as well as recent version of Mac OS X.  Under
1016 Windows we test both MSVC and the Intel compiler. For details, you can
1017 have a look at the continuous integration server at
1018 <http://jenkins.gromacs.org>.
1019
1020 We test irregularly on ARM v7, BlueGene/Q, Cray, Fujitsu PRIMEHPC, Google
1021 Native Client and other environments, and with other compilers and
1022 compiler versions, too.