Build from Source
CP2K uses the CMake build system, which detects dependencies and controls the compilation process. The dependencies have to be installed in advance.
Currently, CP2K offers three convenient methods for building CP2K from source with its dependencies.
One is to use the classic toolchain scripts to customize and install the required dependencies in a
single step, thereby preparing the environment for compiling CP2K. A more modern and automated
approach is via make_cp2k.sh, which leverages Spack to install the
dependencies and subsequently build CP2K. Alternatively, one can use Spack directly to install all
the dependencies and setup the build environment, as described in
Developer Workflow.
Dependencies and build options
At a minimum CP2K requirements a modern C and Fortran compiler, DBCSR, BLAS, and LAPACK. For parallel builds it also needs at least MPI and ScaLAPACK.
For currently supported compilers, see here.
Detailed descriptions of most build options can be found in the technologies section:
There are some other important general options you may want to know:
-G <Generator>Specifies which type of build files would be generated. Default isUnix Makefiles, which generates a GNU Makefile and allows you to build with runningmakein the build directory. For GPU-accelerated builds, it is strongly advised to useNinjaas generator, which is also used bymake_cp2k.sh; in this case, please ensure that Ninja is installed on your host system.-DCMAKE_BUILD_TYPEValid vaules areRelease(default) andDebug(enables debug settings and generatespdbgorsdbginstead ofpsmporssmp; recommended for development).-DCMAKE_INSTALL_PREFIXSpecifies the installation path of CP2K. Assuming it is set to/path/to/installation, there will be several subdirectories:binfor binaries likecp2k.psmp,includefor module files and headers,lib/lib64for libraries, andsharefor some other files such as basis data. Default is/usr/local.-DBUILD_SHARED_LIBSSpecifies if shared libraries are built. Default isON; if setOFF, a static library will be built instead.-DCMAKE_POSITION_INDEPENDENT_CODESpecifies if position-independent code is enabled.
Along with some options with CP2K:
-DCP2K_USE_EVERYTHINGEnables all dependencies or not.-DCP2K_DATA_DIRSpecifies the location of the data of basis and potentials. Default is/path/to/installation/share/cp2k/data.-DCP2K_ENABLE_CONSISTENCY_CHECKSOnly used for testing.-DCP2K_USE_CRAY_PM_ENERGYEnables power monitoring on Cray systems.-DCP2K_USE_CRAY_PM_ACCEL_ENERGYEnables power monitoring of accelerators on Cray systems.-DCP2K_USE_DBCSR_CONFIGMake dbcsr cmake options (DBCSR_USE_BLA) available.
Note that CMake is typically run out-of-tree in a seperate build/ directory. We don’t allow
in-source builds; if you run CMake in the root directory, it will give error.
Example
The following example builds CP2K with CUDA acceleration for Nvidia A100 GPUs and a few optional dependencies :
cd <CP2K_REPOSITORY>
mkdir build/
cmake -S . -B build \
-GNinja \
-DCP2K_USE_LIBXC=ON \
-DCP2K_USE_LIBINT2=ON \
-DCP2K_USE_SPGLIB=ON \
-DCP2K_USE_ELPA=ON \
-DCP2K_USE_SPLA=ON \
-DCP2K_USE_SIRIUS=ON \
-DCP2K_USE_COSMA=ON \
-DCP2K_USE_ACCEL=CUDA -DCP2K_WITH_GPU=A100
cmake --build build -j 32
cmake --install build
The commands
cmake --build build -j 32andcmake --install buildcan be replaced by a single commandcmake --build build --target install -j 32
Cleaning build cache
If you want to clean your build cache after installing in order to save space, simply run:
cmake --build build --target clean