Gromacs

Cmake

    CMake (cross-platform make) is a relatively new build system that is gaining in popularity. One of the biggest selling points is its ability to manage native builds on MS Windows. Starting with the 4.5 release, it is possible to configure and compile the source code with it. With the 4.6 release CMake is the deafult and only build system, while autoconf/automake is deprecated. The information below pertains to the way GROMACS 4.5.x used CMake. For 4.6, consult the Installation Instructions

    Getting CMake

    Packages for various platforms can be found on the project's download page. Most of the Linux distributions come with packages available through the corresponding package manager. Make sure the installed version is 2.8 or later, while for building GROMACS-GPU version 2.6.4 or later is required.

    Don't use cmake 2.8.3. It has a bug (link also provides a work around).

    Using CMake

    Please read carefully the documentation on the CMake website and also check out the FAQ. Developers may want to look at some of the online tutorials as well. 

    For a quick start here are the different ways one can run CMake to configure a build:

    command line interface

    The cmake tool can be used to configure projects on the command line of from scripts. Settings can be specified with the -D option.

    $ cmake ../gromacs-src
    

    Alternatively, one can use the wizard/interactive mode which will prompt for settings on the command line:

    $ cmake -i ../gromacs-src
    ccmake text-based user interface
    $ ccmake ../gromacs-src
    CMake GUI
    $ cmake-gui ../gromacs-src

    Explanation about the different options will be presented when using any of the interactive, curses or GUI methods.

    Configuring with default settings

    It is strongly advisable that the builds are done out-of-source, meaning that the build tree is located outside the source tree. On Linux/Mac, the following commands will configure a build with the default settings:

    $ tar xvfz gromacs-src.tar.gz
    $ ls
    gromacs-src
    $ mkdir build
    $ cd build
    $ cmake ../gromacs-src
    $ make

    On multi-core CPU systems (very likely nowadays), the parallel make will do the job much faster:

    $ make -j N

    Substitute N with the number of available cores.

    In GROMACS 4.6 the default configuration enables OpenMP and native GPU acceleration with CUDA. OpenMP will work out of the box with any modern compiler (e.g. gcc >v4.1). The native GPU acceleration requires the NVIDIA CUDA toolkit and to run a comatible graphics card (Fermi or Kepler series, compute capability >=2.0) has to be present in the system. Note that compiling with GPU acceleration does not produce a GPU-only mdrun, CPU or GPU acceleration for non-bonded calculation can be selected at run-time. Therefore, compiling without GPU acceleration is advised only in case if no compatible GPU is (planned to be) present in the system.

    Configuring with custom options

    Custom options can be set in a few different ways. A list of the more commonly used ones can be found here.

    command line settings

    The project configuration options can be passed using the -D command line option in the form of -DOPTION=VALUE or -D OPTION=VALUE. Note that the source path should be the last argument (otherwise don't put the spaces between -D and OPTION)!

    double precision build
    $ cmake -DGMX_DOUBLE=ON ../gromacs-src
    

    Note that GPU acceleration is not compatible with double precision builds.

    custom C/C++ compiler

    To use a custom compiler other than the system-wide default, the path to the C and C++ compiler needs to be specified using the CC and CXX environment variables, respectively:

    $ CC=/opt/intel/bin/icc CXX=/opt/intel/bin/icpc cmake ../gromacs-src
    thread-MPI build (default)
    $ cmake -DGMX_THREAD_MPI=ON ../gromacs-src
    OpenMP enabled build (default)
    $ cmake -DGMX_OPENMP=ON ../gromacs-src
    MPI build
    $ CC=mpicc CXX=mpiCC cmake -DGMX_MPI=ON ../gromacs-src
    

    or

    $ cmake -DGMX_MPI=ON ../gromacs-src

    The second option tries to auto-detect the installed MPI library. If auto-detection fails the first option should be used.

    native GPU acceleration
    $ cmake -DGMX_GPU=ON [-DCUDA_TOOLKIT_ROOT_DIR=/path/to/cuda] ../gromacs-src
    

    If the CUDA toolkit is not installed in the default location (/usr/local/cuda on Linux), its location needs to be specified using the CUDA_TOOLKIT_ROOT_DIR CMake variable. Note, that the NVIDIA GPU compiler (nvcc) requires a C++ compiler to compile host-code -- the part of the code .cu files contain which runs on the CPU. Whenever considered safe, the build system will automatically pass the used C++ compiler for nvcc to be used as host-compiler. To manually set the nvcc compiler wrapper configure with passing the full path to a C++ compiler using CUDA_NVCC_HOST_COMPILER.

    When configuring with both MPI and GPU support, the default CMake-based MPI detections should be preferred. This is becauise when the MPI compiler-wrapper approach is used, as nvcc can not reliably use compiler wrappers, the nvcc host compiler needs to be set manually.

    When using a C++ compiler which is not officially supported by CUDA (e.g. clang), whenever possible the the build scripts will detect this and avoid passing this unsupported compiler to nvcc. In this case nvcc  will use the platform-default assumed to be in the path (e.g. the default gcc on Linux). Although mixing compilers is not advised, this will most probably work, but if sich a setup fails, a CPU compiler supported by nvcc should be used.

    The compilers officially compatible with nvcc are gcc and Intel on Linux, gcc on Mac OS X, and msvc on Windows; for more detailed information on version compatibilities consult the NVIDIA documentation (or just try).

     

     

    CMakeCache.txt

    All configure options are saved in the CMakeCache.txt file in the build directory. The file can be edited using a text editor, but after that cmake should be run again.

    $ vim CMakeCache.txt
    $ cmake ../gromacs-4.5

    Alternatively, the text-based user interface ccmake or the GUI interface can also be used to directly modify the configuration options. Note that the build has to be reconfigured to commit any changes.

    CMake Options

    This is a list of commonly used options for configuring the GROMACS source code.

    Custom library locations

    If libraries are installed in non-default locations their location can be specified using:

    • CMAKE_INCLUDE_PATH for header files
    • CMAKE_LIBRARY_PATH for libraries
    • CMAKE_PREFIX_PATH  for header, libraries and binaries. The respective include, lib, or bin is appended to the path.

    For each option a list of paths can be specified (on Unix seperated with ":"). These are enviroment variables (and not command line arguments) and are used as e.g.:

    $ CMAKE_PREFIX_PATH=/opt/fftw:/opt/cuda cmake

    See also: http://cmake.org/Wiki/CMake_Useful_Variables#Environment_Variables

    Custom compilation flags (CFLAGS)

    The CMake build system will honour the CFLAGS/CXXFLAGS environmental variables, if they are set. However, these flags will be appended to the predefined flags for the corresponding platform and build type such as Debug or Release. All settings can be found in CMakeCache.txt in the build directory.

    Pay attention that variables are called CMAKE_C_FLAGS, CMAKE_C_FLAGS_RELEASE, CMAKE_XX_FLAGS etc., and those are the ones that have to be modified for full custom control.

    FFTW libraries

    If the FFTW libraries are installed in a non-default location, e.g. /home/joe/local/fftw3, use the CMAKE_PREFIX_PATH environment variable to hint search locations to CMake:

    $ CMAKE_PREFIX_PATH=/home/joe/local/fftw3 cmake ../gromacs-src

    Alternatively it is possible to manyally specify the include directory and library: 

    $ cmake -DFFTW_INCLUDE_DIR=/home/joe/local/fftw3/include \
            -DFFTW_LIBRARY=/home/joe/local/fftw3/lib/libfftw3f.so ../gromacs-src

    Binary and library suffixes

    Suffixes are meant to enable installing double precision and/or MPI build of GROMACS to the same location. The default behavior (GMX_DEFAULT_SUFFIX=ON) is that the build system appends to every binary and library the "_d" and "_mpi" to the double precision and MPI builds, respectively, and "_mpi_d" in case of double precision MPI builds.

    To use custom suffixes, turn of the default suffixing behavior by setting GMX_DEFAULT_SUFFIX=OFF and set the desired values for GMX_BINARY_SUFFIX and GMX_LIBS_SUFFIX variables.

    Suffixing can be completely turned off by setting GMX_DEFAULT_SUFFIX=OFF, GMX_BINARY_SUFFIX="", and GMX_LIBS_SUFFIX="".

    Static linking

    To link GROMACS binaries statically against the internal libraries, set BUILD_SHARED_LIBS=OFF. To link statically against external libraries as well, the GMX_PREFER_STATIC_LIBS=ON option can be used. Note, that in general CMake picks up whatever is available, so this option only instructs CMake to prefer static libraries when both static and shared are available. If no static version of an external library is available, even when the aforementioned option is ON, the shared library will be used. Also note, that the resulting binaries will still be dynamically linked against system libraries.

    To build completely static binaries, one can use the -static linker option (supported by GNU, Intel Compilers, and possibly other compilers), by adding it to the CMAKE_EXE_LINKER_FLAGS CMake variable in combination with GMX_PREFER_STATIC_LIBS=ON. However, in order to make this work one has to make sure that every external library is available and detected as static (to check this either use ccmake or look in CMakeCache.txt).

    An example installation

    Note that the information below is only valid for GROMACS 4.5, it is outdated and incorrect for 4.6.

    serial

    This is just one example of a successful installation of single precision serial gromacs. Note that the mdrun produced by this compilation will be able to run parallel over threads on many cores as long as it is within the same box (confirmation requested).

    ## set up any variables that are required for cmake or your compiler (this will be different on your cluster)
    module purge
    module load intel
    module load cmake
    export CCDIR=/scinet/gpc/intel/Compiler/11.1/072/bin/intel64
    
    ## set the location of the single precision FFTW installation
    export FFTW_LOCATION=/project/pomes/cneale/GPC/exe/intel/fftw-3.1.2/exec
    
    ##### Nothing below this line usually needs to be changed
    
    export CXX=icpc
    export CC=icc
    
    gunzip gromacs-4.5.3.tar.gz
    tar -xf gromacs-4.5.3.tar
    cd gromacs-4.5.3
    mkdir exec
    cd exec
    
    cmake ../ \
          -DFFTW3F_INCLUDE_DIR=$FFTW_LOCATION/include \
          -DFFTW3F_LIBRARIES=$FFTW_LOCATION/lib/libfftw3f.a \
          -DCMAKE_INSTALL_PREFIX=$(pwd) \
          -DGMX_X11=OFF \
          -DCMAKE_CXX_COMPILER=${CCDIR}/icpc \
          -DCMAKE_C_COMPILER=${CCDIR}/icc \
          -DGMX_MPI=OFF \
          -DGMX_PREFER_STATIC_LIBS=ON
    
    make
    
    make install

     

    parallel mdrun

    This is just one example of a successful installation of single precision parallel gromacs. The changes for using MPI are highlighted in yellow.

    ## set up any variables that are required for cmake or your compiler (this will be different on your cluster)
    module purge
    module load intel
    module load cmake
    export CCDIR=/scinet/gpc/intel/Compiler/11.1/072/bin/intel64
    export MPICCDIR=/software/MPI/openmpi-1.4.3_intel/bin
    
    ## set the location of the single precision FFTW installation
    export FFTW_LOCATION=/project/pomes/cneale/GPC/exe/intel/fftw-3.1.2/exec
    
    ##### Nothing below this line usually needs to be changed
    
    export CXX=mpicxx
    export CC=mpicc
    
    gunzip gromacs-4.5.3.tar.gz
    tar -xf gromacs-4.5.3.tar
    cd gromacs-4.5.3
    mkdir exec
    cd exec
    
    cmake ../ \
          -DFFTW3F_INCLUDE_DIR=$FFTW_LOCATION/include \
          -DFFTW3F_LIBRARIES=$FFTW_LOCATION/lib/libfftw3f.a \
          -DCMAKE_INSTALL_PREFIX=$(pwd) \
          -DGMX_X11=OFF \
          -DCMAKE_CXX_COMPILER=${MPICCDIR}/mpicxx \
          -DCMAKE_C_COMPILER=${MPICCDIR}/mpicc \
          -DGMX_MPI=ON \
          -DGMX_PREFER_STATIC_LIBS=ON
    
    make
    
    make install-mdrun
    Page last modified 16:15, 9 Mar 2013 by mabraham