User Tools

Site Tools


howto:compile_on_windows

This is an old revision of the document!


How to Compile CP2K on Windows

This howto has been tested under Windows10 (22H2) using the Windows Subsystem for Linux (WSL).

Install Linux base system

Search in the Microsoft App Store for Ubuntu 22.04 and download that app. Follow the installation instructions from Windows, define a Linux username and password. Your user will have administrator (root) rights via sudo command. These rights are required for the installation of system packages but not for the CP2K installation further down.

Install required packages

Update the Ubuntu installation

sudo apt update
sudo apt -y upgrade

Install additional software packages required to build CP2K which are not included in the base system like make and the GNU compiler

sudo apt -y install make
sudo apt -y install gcc g++ gfortran

You can also install all these packages just with one sudo apt install command.

Download CP2K

Create an installation folder for CP2K and move to the new folder

mkdir -p github/cp2k
cd github/cp2k

Either download CP2K by cloning the GitHub repository of the current master (development) CP2K version

git clone --recursive https://github.com/cp2k/cp2k.git cp2k

or download a CP2K release version like 2023.2

git clone --recursive -b support/v2023.2 https://github.com/cp2k/cp2k.git cp2k

Build CP2K toolchain for a serial CP2K binary

Build the CP2K toolchain with

cd cp2k/tools/toolchain
./install_cp2k_toolchain.sh --mpi-mode=no

This build step will take a while depending on the number of available CPU cores. Once the step is completed, follow the instructions printed. Alternatively, run the more specifically

cd ../../
cp tools/toolchain/install/arch/local.ssmp arch/

Build a serial CP2K binary

Now, everything should be ready to compile CP2K with

make -j ARCH=local VERSION=ssmp

The making of CP2K will take a while again and a lot of output is printed. After a successful make step, you should find the CP2K binaries in the folder exe/local/ which can be listed with

ls -al exe/local

and the command

exe/local/cp2k.ssmp -v

will show the details of the just installed CP2K binary. A small CP2K help is display by

exe/local/cp2k.ssmp -h

The binaries with the extension ssmp are OpenMP parallel and will run by default with a number of OpenMP threads corresponding to number of detected CPU cores (including hyperthreading if available). The number of OpenMP threads employed can be adjusted for instance to 2 with

export OMP_NUM_THREADS=2

The binaries with the file extension sopt are automatically run with only one OpenMP thread. It is also suggest to use an increased OMP_STACKSIZE of at least 16 MB

export OMP_STACKSIZE=16M

Test the serial CP2K binary

As a final check, you can run a CP2K regression test with

make -j ARCH=local VERSION=ssmp test

This will more than 4000 test cases. At the end of that test, a summary is printed which should indicate that there are no FAILED or WRONG tests. Instead or running the all tests, you can also restrict the testing to certain test folders in ~/github/cp2k/cp2k/tests by passing TESTOPTS with the make command like

make -j ARCH=local VERSION=ssmp TESTOPTS="--restrictdir QS/regtest-gpw-1" test

which will only run the test cases in the folder ~/github/cp2k/cp2k/tests/QS/regtest-1. You can list all available TESTOPTS with

~/github/cp2k/cp2k/tests/do_regtest.py -h

Build and test a parallel CP2K binary

An MPI parallel CP2K binary including all features can be built in a very similar way as the serial one. In principle, this makes only sense, if larger number of CPU cores (8 or more) is available. The VERSION extension ssmp has to be replaced everywhere by psmp. First reset the CP2K repository to the state of a fresh git clone if needed with

git clean -fdx

Install additional packages needed for an MPI/OpenMP parallel CP2K binary. Here we use the MPI implementation MPICH

sudo apt -y install mpich bzip2 unzip zlib1g-dev

and some system packages for data compression have to be installed as well. The CP2K toolchain for a cp2k.psmp binary can then be built with

cd tools/toolchain
./install_cp2k_toolchain.sh --install-all --with-gcc=system --with-mpich=system --with-sirius=no

The commands for compiling

cd ../..
cp tools/toolchain/install/arch/local.psmp arch/
make -j ARCH=local VERSION=psmp

and testing

source ~/github/cp2k/cp2k/tools/toolchain/install/setup
make -j ARCH=local VERSION=psmp test

the CP2K binaries are the same as above as for ssmp after replacing ssmp with psmp.

Last but not least

After loading the WSL and before using CP2K, do not forget to source always the setup file with

source ~/github/cp2k/cp2k/tools/toolchain/install/setup

Adding the cp2k/exe/local folder to your binary search PATH

export PATH=$PATH:$HOME/github/cp2k/cp2k/exe/local

will allow for running CP2K just with

cp2k.ssmp

and likewise with cp2k.sopt or cp2k.psmp.

Enjoy CP2K !

howto/compile_on_windows.1701421059.txt.gz · Last modified: 2023/12/01 08:57 by krack