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 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.

Last but not least

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.1701391016.txt.gz · Last modified: 2023/12/01 00:36 by krack