Table of Contents
Compile CP2K on macOS
This page describes how CP2K can be installed under macOS (Monterey, Ventura). This howto has been tested on an Apple M1 under macOS Ventura 13.4 (Darwin Kernel Version 22.5.0, Homebrew 4.0.19). For further details check the corresponding Darwin-gnu-arm64 arch file and regression tester. This howto assumes that your default shell is bash
.
1. Install Homebrew
Open a Terminal and run the command
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
which will install the latest Homebrew version. This howto was tested with Homebrew 3.6.11 as well as with newer versions up to 4.0.19.
a) The easy way
If you are only interested in testing CP2K under macOS, then you can install a pre-compiled CP2K binary providing all basic features via
brew install cp2k
using this Homebrew formula. You can ignore the rest of this how-to, in case you are already happy with that CP2K installation.
b) Compile CP2K under macOS from scratch
If you installed CP2K with brew
in the previous step, then make sure that you uninstall first cp2k
and its dependencies fftw
, libxc
, openblas
, open-mpi
, and scalapack
before you continue to avoid any interference with these Homebrew packages during the installation of the CP2K toolchain.
Create the following links
ln -s /opt/homebrew/bin/gcc-12 /opt/homebrew/bin/gcc ln -s /opt/homebrew/bin/g++-12 /opt/homebrew/bin/g++
to make Homebrew's latest gcc
and g++
compilers the default instead of the clang versions in /usr/bin
.
2. Obtain CP2K
Checkout the latest CP2K version available from the CP2K GitHub repository using
git clone --recursive https://github.com/cp2k/cp2k.git cp2k
3. Build the CP2K toolchain
Change to the folder cp2k
cd cp2k
and run the command
source arch/Darwin-gnu-arm64.ssmp
to build the toolchain for a serial CP2K executable. Alternatively, you can build the toolchain for an MPI parallelised CP2K executable with
source arch/Darwin-gnu-arm64.psmp
4. Compile CP2K
Check the output from the toolchain build in the previous step and if there is no error, run
make -j ARCH=Darwin-gnu-arm64 VERSION=ssmp
or
make -j ARCH=Darwin-gnu-arm64 VERSION=psmp
as suggested depending on the selected toolchain build.
5. Test the CP2K executable
You can run a CP2K regression test using
make -j ARCH=Darwin-arm64 VERSION=psmp TESTOPTS+="--mpiranks 2 --ompthreads 2 --maxtasks 12" test
to validate the generated CP2K executable.
Enjoy CP2K under macOS!