====== 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 [[https://apps.microsoft.com/|Microsoft App Store]] for [[https://apps.microsoft.com/search?query=ubuntu+22.04|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 suggested to increase the ''OMP_STACKSIZE'' to at least 16 MB export OMP_STACKSIZE=16M ulimit -s 65000 and the ''stacksize'' to 65 MB (check with ''ulimit -a''). ==== 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 All data generated by ''test'' can be removed with make ARCH=local VERSION=ssmp testclean whereas make ARCH=local VERSION=ssmp realclean and make distclean will remove all data from ''make ARCH=local VERSION=ssmp'' and from any ''make'', respectively. ==== 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''. CP2K MPI/OpenMP parallel runs are launched with ''mpirun'' or ''mpiexec'', e.g. mpiexec -n 4 -genv OMP_NUM_THREADS=2 cp2k.psmp H2O-32.inp will use 4 MPI ranks with 2 OpenMP threads each (i.e. it will consume 8 CPU cores) to run the input file ''H2O-32.inp'' which can be found in the cp2k folder ''benchmarks/QS''. The ''cp2k.popt'' binary is only MPI parallel and will run just one thread per MPI rank automatically (like ''cp2k.sopt'') which is usually the most efficient usage of CP2K performance-wise if no memory limitation per MPI rank come into play. Therefore, the following commands mpiexec -n 4 -genv OMP_NUM_THREADS=1 cp2k.psmp H2O-32.inp mpiexec -n 4 cp2k.popt H2O-32.inp are basically equivalent. **Enjoy CP2K under Windows!**