2018-10-02 14:27:08 +02:00
|
|
|
# How to compile the CP2K code
|
2015-01-18 21:51:29 +00:00
|
|
|
|
2020-08-24 23:11:31 +02:00
|
|
|
## 1. Acquire the code
|
2015-01-18 21:51:29 +00:00
|
|
|
|
2021-09-15 14:27:19 +05:30
|
|
|
For users, the preferred method is to [download a release](https://github.com/cp2k/cp2k/releases/)
|
2023-11-14 12:10:42 +01:00
|
|
|
(use the versioned tarballs, `cp2k-X.Y.tar.bz2`). For developers, the preferred method is to
|
|
|
|
|
[download from Git](./README.md#downloading-cp2k-source-code).
|
2018-12-13 12:26:38 +00:00
|
|
|
|
2020-08-24 23:11:31 +02:00
|
|
|
For more details on downloading CP2K, see <https://www.cp2k.org/download>.
|
2018-10-02 14:27:08 +02:00
|
|
|
|
2018-12-13 15:55:10 +01:00
|
|
|
## 2. Install prerequisites
|
2015-01-18 21:51:29 +00:00
|
|
|
|
2026-03-01 00:38:26 +08:00
|
|
|
### Method 1: make_cp2k.sh
|
2026-02-17 17:25:20 +08:00
|
|
|
|
2026-03-01 00:38:26 +08:00
|
|
|
The easiest way to build CP2K with its dependencies is via the `make_cp2k.sh` script, which builds
|
|
|
|
|
CP2K using Spack and CMake locally within the CP2K_ROOT folder.
|
2022-02-25 19:05:07 +01:00
|
|
|
|
2026-01-20 12:16:14 +00:00
|
|
|
The script can either be sourced with:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
source ./make_cp2k.sh
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
or run in a subshell with:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
./make_cp2k.sh
|
|
|
|
|
```
|
|
|
|
|
|
2026-03-01 00:38:26 +08:00
|
|
|
You can run the following command to get information about how to use this script:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
./make_cp2k.sh --help
|
|
|
|
|
```
|
|
|
|
|
|
2026-01-20 12:16:14 +00:00
|
|
|
Note: it is recommended to install podman to take advantage of a spack cache. This will accelerate
|
|
|
|
|
the build of the CP2K dependencies with Spack significantly.
|
2025-12-08 14:14:37 -06:00
|
|
|
|
2026-02-17 17:25:20 +08:00
|
|
|
### Method 2: Toolchain
|
|
|
|
|
|
2023-11-14 12:10:42 +01:00
|
|
|
Alternatively, the [toolchain script](./tools/toolchain/install_cp2k_toolchain.sh) can also be run
|
|
|
|
|
directly.
|
2018-12-13 15:55:10 +01:00
|
|
|
|
2020-12-05 08:57:50 +01:00
|
|
|
For a complete introduction to the toolchain script, see the [README](./tools/toolchain/README.md).
|
2018-12-13 15:55:10 +01:00
|
|
|
|
|
|
|
|
The basic steps are:
|
|
|
|
|
|
|
|
|
|
- Read toolchain installation options:
|
2018-12-18 22:40:06 +01:00
|
|
|
|
2020-08-24 23:11:31 +02:00
|
|
|
```shell
|
|
|
|
|
cd tools/toolchain/
|
|
|
|
|
./install_cp2k_toolchain.sh --help
|
2018-12-13 15:55:10 +01:00
|
|
|
```
|
|
|
|
|
|
2026-01-20 12:16:14 +00:00
|
|
|
CP2K supports GPU acceleration via CUDA (for NVIDIA GPUs), HIP/ROCm (for AMD GPUs), and OpenCL (for
|
|
|
|
|
a range of devices). If you wish to build with GPU support, please see the
|
|
|
|
|
[manual](https://manual.cp2k.org/trunk/technologies/accelerators/index.html).
|
|
|
|
|
|
2025-12-08 14:14:37 -06:00
|
|
|
- Launch toolchain script (example option choice for NVIDIA/CUDA):
|
2018-12-18 22:40:06 +01:00
|
|
|
|
2020-08-24 23:11:31 +02:00
|
|
|
```shell
|
|
|
|
|
./install_cp2k_toolchain.sh --with-libxsmm=install --with-openblas=system \
|
2026-02-17 17:25:20 +08:00
|
|
|
--with-fftw=system --enable-cuda
|
2018-12-13 12:28:24 +00:00
|
|
|
```
|
|
|
|
|
|
2025-12-08 14:14:37 -06:00
|
|
|
- For AMD/ROCm/HIP support, use:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
./install_cp2k_toolchain.sh --with-libxsmm=install --with-openblas=system \
|
2026-02-17 17:25:20 +08:00
|
|
|
--with-fftw=system --enable-hip
|
2025-12-08 14:14:37 -06:00
|
|
|
```
|
2026-04-26 18:40:37 +08:00
|
|
|
|
|
|
|
|
- Build and install CP2K with prepared toolchain environment:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
./build_cp2k.sh
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
It is also available to make installed program and dependencies outside the source tree:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
./install_cp2k_toolchain.sh --install-dir=/opt/cp2k/toolchain
|
|
|
|
|
./build_cp2k.sh --prefix /opt/cp2k
|
|
|
|
|
```
|
2025-12-08 14:14:37 -06:00
|
|
|
|
2018-10-02 14:27:08 +02:00
|
|
|
## 3. Compile
|
2015-01-18 21:51:29 +00:00
|
|
|
|
2025-12-28 13:19:01 +01:00
|
|
|
This section has been moved to the
|
|
|
|
|
[manual](https://manual.cp2k.org/trunk/getting-started/build-from-source.html).
|
2020-08-24 23:11:31 +02:00
|
|
|
|
|
|
|
|
## 4. If it doesn't work
|
|
|
|
|
|
2025-12-27 16:23:33 +01:00
|
|
|
If things fail, take a break... go back to step 2.
|
2015-01-18 21:51:29 +00:00
|
|
|
|
2018-10-02 14:27:08 +02:00
|
|
|
## 5. Regtesting
|
2015-01-18 21:51:29 +00:00
|
|
|
|
2023-11-14 12:10:42 +01:00
|
|
|
If compilation works fine, it is recommended to test the generated binary, to exclude errors in
|
|
|
|
|
libraries, or miscompilations, etc.
|
2020-08-24 23:11:31 +02:00
|
|
|
|
|
|
|
|
```shell
|
2025-12-27 16:23:33 +01:00
|
|
|
./tests/do_regtest.py ./build/bin/ ${VERSION}
|
2018-10-06 13:13:53 +02:00
|
|
|
```
|
2015-09-01 07:51:55 +00:00
|
|
|
|
2022-04-19 13:31:01 +02:00
|
|
|
should work if you can locally execute CP2K without the need for, e.g., batch submission.
|
2015-09-01 07:51:55 +00:00
|
|
|
|
2023-11-14 12:10:42 +01:00
|
|
|
In the other case, you might need to configure the underlying testing script as described more
|
|
|
|
|
systematically at <https://www.cp2k.org/dev:regtesting>
|
2015-01-18 21:51:29 +00:00
|
|
|
|
2018-10-02 14:27:08 +02:00
|
|
|
## 6. Talk to us
|
2020-08-24 23:11:31 +02:00
|
|
|
|
2023-11-14 12:10:42 +01:00
|
|
|
In any case please tell us your comments, praise, criticism, thanks, etc. see
|
|
|
|
|
<https://www.cp2k.org>.
|
2015-01-18 21:51:29 +00:00
|
|
|
|
2018-10-02 14:27:08 +02:00
|
|
|
## 7. Manual
|
2015-01-18 21:51:29 +00:00
|
|
|
|
2023-11-14 12:10:42 +01:00
|
|
|
A reference manual of CP2K can be found on the web: <https://manual.cp2k.org> or can be generated
|
2025-01-08 18:35:40 +01:00
|
|
|
using the cp2k binary, see <https://manual.cp2k.org/trunk/generate_manual_howto.html>
|
2020-08-24 23:11:31 +02:00
|
|
|
|
|
|
|
|
## 8. Happy computing
|
2001-06-26 16:46:41 +00:00
|
|
|
|
2022-11-05 22:42:32 +01:00
|
|
|
The CP2K team.
|