2026-01-09 10:24:07 +01:00
#!/usr/bin/env bash
# Purpose: Build CP2K using Spack and CMake locally within the folder CP2K_ROOT
# which defaults to the current working directory. This should be a
2026-03-11 15:32:57 +01:00
# "cp2k/" folder containing the CP2K source tree which can be download with
2026-01-09 10:24:07 +01:00
#
2026-03-11 15:32:57 +01:00
# > git clone https://github.com/cp2k/cp2k.git cp2k
2026-01-09 10:24:07 +01:00
#
2026-03-11 15:32:57 +01:00
# and after
2026-01-09 10:24:07 +01:00
#
2026-03-11 15:32:57 +01:00
# > cd cp2k
2026-01-09 10:24:07 +01:00
#
2026-03-11 15:32:57 +01:00
# this script can be run in subshell using the default options with
2026-01-09 10:24:07 +01:00
#
2026-03-11 15:32:57 +01:00
# > ./make_cp2k.sh
2026-02-26 22:32:29 +01:00
#
2026-01-09 10:24:07 +01:00
# The flags -h or --help print the available options.
#
# The first run will take longer as it will build all CP2K dependencies
# with Spack. The Spack installation is kept fully local in the subfolder
# cp2k/spack which corresponds to the tools/toolchain/install folder
# created by the CP2K toolchain.
#
# Subsequent runs of the script will use the software stack from that
# cp2k/spack/ folder.
#
# A rebuild of all CP2K dependencies can be enforced simply by removing
# or renaming the folder cp2k/spack. The latter allows for keeping different
2026-01-30 15:02:48 +01:00
# software stacks (see also -bd and -bd_only flags).
2026-01-09 10:24:07 +01:00
#
2026-05-08 09:59:03 +02:00
# It is recommended to store already compiled packages in a cache (default).
2026-01-30 15:02:48 +01:00
# This will accelerate the (re)build of the CP2K dependencies with Spack
2026-05-08 09:59:03 +02:00
# significantly (see -uc flag).
2026-01-09 10:24:07 +01:00
#
# After the CP2K dependencies are built with Spack, CP2K itself is built
2026-01-30 15:02:48 +01:00
# and installed using CMake in the subfolders cp2k/build and cp2k/install,
# respectively.
2026-01-09 10:24:07 +01:00
#
# Subsequent runs of the script will use the CMake configuration in the
# subfolder cp2k/build. A rebuild of CP2K from scratch can be enforced
# by removing or renaming that subfolder.
#
# A CP2K regression run can be launched automatically by adding the flag
# -t "" (or --test ""). This flag expects a string with the TESTOPTS, e.g.
#
2026-02-26 22:32:29 +01:00
# > ./make_cp2k.sh -t "--maxtasks 8 --restrictdir QS/regtest-gpw-1"
2026-01-09 10:24:07 +01:00
#
2026-03-11 15:32:57 +01:00
# Alternatively, the script cp2k/install/bin/run_tests can be launched
# after a successful CP2K build. Usage examples are printed at the end.
2026-01-09 10:24:07 +01:00
# Authors: Matthias Krack (MK)
2026-07-06 16:12:20 +02:00
# Version: 2.0
2026-01-09 10:24:07 +01:00
2026-01-30 15:02:48 +01:00
# Facilitate the deugging of this script
2026-01-28 18:10:13 +01:00
set -uo pipefail
2026-01-09 11:16:14 +01:00
2026-01-30 15:02:48 +01:00
# Retrieve script name
2026-01-09 11:16:14 +01:00
SCRIPT_NAME = " $( basename " ${ BASH_SOURCE [0] } " ) "
2026-01-09 10:24:07 +01:00
# Check if the script is sourced or run in a subshell
if [ [ " ${ BASH_SOURCE [0] } " != " ${ 0 } " ] ] ; then
echo " ${ SCRIPT_NAME } : Running script in sourcing mode "
echo " ${ SCRIPT_NAME } : All changes from this script will become effective within the current shell "
EXIT_CMD = "return"
else
echo " ${ SCRIPT_NAME } : Running script in subshell mode "
echo " ${ SCRIPT_NAME } : Changes from this script in the shell environment are lost after completion "
EXIT_CMD = "exit"
fi
2026-05-09 21:45:11 +02:00
# Check platform
if [ [ " $( uname -s) " = = "Darwin" ] ] ; then
echo "ERROR: A build for Apple macOS (Darwin, Homebrew) is not supported yet,"
echo " but CP2K can be built within a container using podman."
echo " Check the Dockerfiles in the folder cp2k/tools/docker like"
echo " Dockerfile.test_spack_openmpi-psmp and the usage description in their header"
${ EXIT_CMD } 1
fi
2026-02-22 08:55:25 +01:00
# Help finding ldconfig
if ! command -v ldconfig & > /dev/null; then
PATH = " ${ PATH } :/sbin "
fi
2026-01-22 11:13:28 +01:00
# Check if all mandatory packages are installed in the environment
2026-02-22 08:55:25 +01:00
for package in awk bzip2 find g++ gcc gfortran git gzip ldconfig make patch python3 tar wget xz; do
2026-01-22 11:13:28 +01:00
if ! command -v " ${ package } " & > /dev/null; then
echo " ERROR: The package \" ${ package } \" is mandatory to build CP2K with Spack/CMake "
echo " Install the missing package and re-run the script"
${ EXIT_CMD } 1
fi
done
2026-05-20 13:31:36 +02:00
# Disable python bytecode generation to suppress __pycache__ folder creation
export PYTHONDONTWRITEBYTECODE = 1
2026-03-25 18:20:15 +01:00
# Print OS info if available
if [ [ -f /etc/os-release ] ] ; then
echo ""
cat /etc/os-release
fi
2026-01-21 11:01:04 +01:00
# Check bash version
if ( ( BASH_VERSINFO < 4) ) ; then
2026-03-25 18:20:15 +01:00
echo ""
2026-01-21 11:01:04 +01:00
echo " ERROR: The employed bash version ${ BASH_VERSION } is too old (from 2004) "
echo " Install a newer bash version"
if [ [ " $( uname -s) " = = "Darwin" ] ] ; then
echo "HINT: Use the bash command provided by Homebrew with Apple"
echo " /opt/homebrew/bin should precede /bin/bash in the PATH"
echo " In sourcing mode, run /opt/homebrew/bin/bash first before sourcing this script"
fi
${ EXIT_CMD } 1
elif ( ( BASH_VERSINFO < 5) ) ; then
2026-03-25 18:20:15 +01:00
echo -e " \nWARNING: The employed bash version ${ BASH_VERSION } is quite old (from 2009) "
2026-01-21 11:01:04 +01:00
else
2026-03-25 18:20:15 +01:00
echo -e " \nINFO: Using bash version ${ BASH_VERSION } "
2026-01-21 11:01:04 +01:00
fi
2026-01-22 11:13:28 +01:00
# Check if the python3 version is new enough for spack
2026-02-17 15:26:03 +01:00
if ! python3 -c 'import sys; sys.exit(not(sys.version_info >= (3, 10)))' ; then
2026-03-25 18:20:15 +01:00
echo ""
2026-02-17 15:26:03 +01:00
echo "ERROR: Python version is NOT >= 3.10 (needed for Spack)"
2026-01-22 11:13:28 +01:00
echo " Found only $( python3 -V) "
${ EXIT_CMD } 1
2026-02-17 15:26:03 +01:00
else
2026-03-25 18:20:15 +01:00
echo -e " \nINFO: Found $( python3 -V) "
2026-01-22 11:13:28 +01:00
fi
2026-01-09 10:24:07 +01:00
# Default values
2026-01-29 22:25:39 +01:00
BUILD_DEPS = "if_needed"
2026-01-29 17:12:11 +01:00
BUILD_DEPS_ONLY = "no"
2026-03-25 13:47:09 +01:00
BUILD_SHARED_LIBS = " ${ BUILD_SHARED_LIBS :- ON } "
2026-03-03 17:54:40 +01:00
CP2K_BUILD_TYPE = " ${ CP2K_BUILD_TYPE :- Release } "
DEPS_BUILD_TYPE = " ${ DEPS_BUILD_TYPE :- Release } "
2026-02-16 08:14:16 +01:00
CMAKE_FEATURE_FLAG_ALL = "-DCP2K_USE_EVERYTHING=ON" # all features are activated by default
CMAKE_FEATURE_FLAGS = "-DCP2K_BLAS_VENDOR=OpenBLAS" # LAPACK/BLAS from OpenBLAS by default
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_FFTW3=ON" # FFTW3 is always activated unless explicitly disabled
CMAKE_FEATURE_FLAG_MPI = "-DCP2K_USE_MPI=ON" # MPI is switched on by default
CMAKE_FEATURE_FLAGS_GPU = "-DCP2K_USE_SPLA_GEMM_OFFLOADING=ON"
2026-02-13 15:42:41 +01:00
CRAY = "no"
2026-02-27 13:51:52 +01:00
CUDA_SM_CODE = 0
2026-02-02 16:16:11 +01:00
GCC_VERSION = "auto"
2026-02-10 12:15:01 +01:00
GPU_MODEL = "none"
2026-01-09 10:24:07 +01:00
HELP = "no"
INSTALL_MESSAGE = "NEVER"
2026-01-28 00:13:27 +01:00
MPI_MODE = "mpich"
2026-02-20 15:50:32 +01:00
if command -v nproc & > /dev/null; then
MAX_PROCS = $( nproc)
2026-01-22 11:13:28 +01:00
NUM_PROCS = ${ NUM_PROCS :- ${ MAX_PROCS } }
2026-01-09 10:24:07 +01:00
else
2026-01-22 11:13:28 +01:00
MAX_PROCS = -1
2026-01-09 10:24:07 +01:00
NUM_PROCS = ${ NUM_PROCS :- 8 }
fi
2026-03-08 06:44:57 +01:00
NUM_PACKAGES = 2
2026-02-27 13:51:52 +01:00
NVCC_VERSION = 0
2026-02-07 13:12:03 +01:00
REBUILD_CP2K = "no"
2026-01-09 10:24:07 +01:00
RUN_TEST = "no"
2026-02-16 08:14:16 +01:00
SED_PATTERN_LIST = ""
2026-01-09 10:24:07 +01:00
TESTOPTS = ""
2026-05-08 09:59:03 +02:00
USE_CACHE = "folder"
2026-01-27 18:12:08 +01:00
USE_EXTERNALS = "no"
2026-07-01 16:13:06 +02:00
USE_OPENCL = "no"
2026-01-09 10:24:07 +01:00
VERBOSE = 0
2026-01-21 11:01:04 +01:00
VERBOSE_FLAG = "--quiet"
2026-01-09 10:24:07 +01:00
VERBOSE_MAKEFILE = "OFF"
2026-03-06 10:40:13 +01:00
VERBOSE_SPACK = ""
2026-01-09 10:24:07 +01:00
export CP2K_ENV = "cp2k_env"
2026-01-24 15:26:39 +01:00
export CP2K_ROOT = ${ CP2K_ROOT :- ${ PWD } }
2026-01-09 10:24:07 +01:00
export CP2K_VERSION = " ${ CP2K_VERSION :- psmp } "
2026-06-28 22:19:02 +02:00
export BUILD_PATH = " ${ BUILD_PATH :- ${ CP2K_ROOT } } "
2026-01-09 10:24:07 +01:00
export INSTALL_PREFIX = " ${ INSTALL_PREFIX :- ${ CP2K_ROOT } /install } "
# Parse flags
while [ [ $# -gt 0 ] ] ; do
case " $1 " in
2026-01-29 17:12:11 +01:00
-bd | --build_deps | --build_dependencies)
2026-01-29 22:25:39 +01:00
BUILD_DEPS = "always"
2026-01-22 11:34:15 +01:00
shift 1
2026-01-09 10:24:07 +01:00
; ;
2026-01-29 17:12:11 +01:00
-bd_only | --build_deps_only | --build_dependencies_only)
2026-01-29 22:25:39 +01:00
BUILD_DEPS = "always"
2026-01-29 17:12:11 +01:00
BUILD_DEPS_ONLY = "yes"
shift 1
; ;
2026-06-28 22:19:02 +02:00
-bp | --build_path)
if ( ( $# > 1) ) ; then
BUILD_PATH = " $( realpath " ${ 2 } " ) "
else
echo " ERROR: No build path argument found for flag \" ${ 1 } \" "
${ EXIT_CMD } 1
fi
shift 2
; ;
2026-03-25 13:47:09 +01:00
-bsl | --build_static_libcp2k)
BUILD_SHARED_LIBS = "OFF"
shift 1
; ;
2026-01-21 11:01:04 +01:00
-bt | --build_type)
2026-03-03 17:54:40 +01:00
CP2K_BUILD_TYPE = " ${ 2 } "
case " ${ CP2K_BUILD_TYPE } " in
Debug)
CP2K_VERSION = " ${ CP2K_VERSION /smp/dbg } "
; ;
Release | RelWithDebInfo)
CP2K_VERSION = " ${ CP2K_VERSION /dbg/smp } "
; ;
esac
2026-01-21 11:01:04 +01:00
shift 2
; ;
2026-02-01 18:50:49 +01:00
-cray)
CRAY = "yes"
shift 1
; ;
2026-01-09 10:24:07 +01:00
-cv | --cp2k_version)
2026-01-27 18:12:08 +01:00
if ( ( $# > 1) ) ; then
2026-02-16 08:14:16 +01:00
case " ${ 2 ,, } " in
2026-03-03 17:54:40 +01:00
pdbg | psmp | sdbg | ssmp | ssmp-static)
2026-02-16 08:14:16 +01:00
CP2K_VERSION = " ${ 2 ,, } "
2026-03-03 17:54:40 +01:00
# Set build type
case " ${ CP2K_VERSION } " in
pdbg | sdbg)
CP2K_BUILD_TYPE = "Debug"
DEPS_BUILD_TYPE = "RelWithDebInfo"
; ;
psmp | ssmp | ssmp-static)
CP2K_BUILD_TYPE = "Release"
DEPS_BUILD_TYPE = "Release"
; ;
esac
# Disable MPI for a serial CP2K binary
case " ${ CP2K_VERSION } " in
sdbg | ssmp | ssmp-static)
MPI_MODE = "no"
CMAKE_FEATURE_FLAG_MPI = "-DCP2K_USE_MPI=OFF"
; ;
esac
2026-03-11 15:32:57 +01:00
# Apply specific package selection for statically linked binaries
2026-03-03 17:54:40 +01:00
case " ${ CP2K_VERSION } " in
ssmp-static)
CMAKE_FEATURE_FLAG_ALL = "-DCP2K_USE_EVERYTHING=ON"
2026-07-09 16:58:20 +02:00
for package in libfci libint2 libxc libxs spglib vori tblite; do
2026-03-03 17:54:40 +01:00
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_ ${ package ^^ } =ON "
done
2026-07-09 16:58:20 +02:00
for package in ace deepmd gauxc greenx hdf5 libgint libtorch pexsi trexio; do
2026-03-03 17:54:40 +01:00
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_ ${ package ^^ } =OFF "
done
; ;
esac
2026-02-07 13:12:03 +01:00
; ;
*)
2026-03-03 17:54:40 +01:00
echo " ERROR: Invalid CP2K version \" ${ 2 } \" specified (choose pdbg, psmp, sdbg, ssmp, or ssmp-static) "
2026-02-10 12:15:01 +01:00
${ EXIT_CMD } 1
2026-02-07 13:12:03 +01:00
; ;
esac
2026-01-27 18:12:08 +01:00
else
2026-03-11 15:32:57 +01:00
echo " ERROR: No argument found for flag \" ${ 1 } \" (choose pdbg, psmp, sdbg, ssmp, or ssmp-static) "
2026-01-27 18:12:08 +01:00
${ EXIT_CMD } 1
fi
2026-02-16 08:14:16 +01:00
shift 2
; ;
-df | --disable | --disable_feature | -ef | --enable | --enable_feature)
if ( ( $# > 1) ) ; then
case " ${ 1 } " in
-df | --disable | --disable_feature)
ON_OFF = "OFF"
SUBST = "s/^ /#/'"
; ;
-ef | --enable | --enable_feature)
ON_OFF = "ON"
SUBST = "s/#/ /'"
; ;
esac
case " ${ 2 ,, } " in
all)
2026-03-30 14:35:21 +02:00
# Enable or disable all features
2026-02-16 08:14:16 +01:00
CMAKE_FEATURE_FLAG_ALL = " -DCP2K_USE_EVERYTHING= ${ ON_OFF } "
2026-05-13 18:00:49 +02:00
for package in adios2 cosma deepmdkit dla-future dla-future-fortran elpa \
2026-07-06 16:12:20 +02:00
gauxc greenx hdf5 libfabric libfci libint libvdwxc libsmeagol libvori \
2026-07-11 16:53:23 +02:00
libxc libxs libxsmm mimic-mcl openpmd-api pace pexsi plumed py-torch sirius \
spfft spglib spla tblite trexio; do
2026-02-16 08:14:16 +01:00
SED_PATTERN_LIST += " -e '/\s*-\s+\" ${ package } @/ ${ SUBST } "
done
2026-06-06 23:20:56 +02:00
# dbcsr must use blas as fallback when libxs/libxsmm is disabled
2026-02-23 09:40:41 +01:00
if [ [ " ${ ON_OFF } " = = "OFF" ] ] ; then
2026-06-28 06:48:27 +02:00
SED_PATTERN_LIST += " -e '/\s*-\s+\"smm=libxs\"/ s/libxs/blas/'"
2026-02-23 09:40:41 +01:00
fi
2026-02-16 08:14:16 +01:00
; ;
2026-07-06 16:12:20 +02:00
ace | cosma | deepmd | dftd4 | dlaf | elpa | fftw3 | gauxc | greenx | hdf5 | libfci | \
libgint | libint2 | libsmeagol | libtorch | libxc | libxs | mimic | openpmd | pexsi | \
plumed | spglib | tblite | trexio | vori)
2026-02-16 08:14:16 +01:00
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_ ${ 2 ^^ } = ${ ON_OFF } "
# Translate package selection to sed pattern
case " ${ 2 ,, } " in
ace)
SED_PATTERN_LIST += " -e '/\s*-\s+\"p ${ 2 ,, } @/ ${ SUBST } "
; ;
2026-07-06 16:12:20 +02:00
cosma | elpa | greenx | hdf5 | libfci | libsmeagol | libxc | pexsi | plumed | \
spglib | trexio)
2026-02-16 08:14:16 +01:00
SED_PATTERN_LIST += " -e '/\s*-\s+\" ${ 2 ,, } @/ ${ SUBST } "
; ;
2026-03-27 23:32:53 +01:00
deepmd)
2026-02-16 08:14:16 +01:00
SED_PATTERN_LIST += " -e '/\s*-\s+\" ${ 2 ,, } kit@/ ${ SUBST } "
2026-03-27 23:32:53 +01:00
if [ [ " ${ ON_OFF } " = = "ON" ] ] ; then
# DeePMD-kit requires libtorch
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_LIBTORCH= ${ ON_OFF } "
SED_PATTERN_LIST += " -e '/\s*-\s+\"py-torch@/ ${ SUBST } "
fi
2026-02-16 08:14:16 +01:00
; ;
2026-03-30 14:35:21 +02:00
dftd4)
SED_PATTERN_LIST += " -e '/\s*-\s+\" ${ 2 ,, } @/ ${ SUBST } "
if [ [ " ${ ON_OFF } " = = "ON" ] ] ; then
echo "INFO: tblite is disabled to avoid conflicts when dftd4 is used"
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_TBLITE=OFF"
SED_PATTERN_LIST += " -e '/\s*-\s+\"tblite@/ s/^ /#/'"
fi
; ;
2026-02-16 08:14:16 +01:00
dlaf)
2026-02-25 22:50:05 +08:00
SED_PATTERN_LIST += " -e '/\s*-\s+\"dla-future.*@/ ${ SUBST } "
2026-07-02 00:37:51 +08:00
if [ [ " ${ ON_OFF } " = = "ON" ] ] ; then
2026-07-11 16:53:23 +02:00
SED_PATTERN_LIST += " -e 's/\~dlaf/\+dlaf/'"
2026-07-02 00:37:51 +08:00
else
2026-07-11 16:53:23 +02:00
SED_PATTERN_LIST += " -e 's/\+dlaf/\~dlaf/'"
2026-07-02 00:37:51 +08:00
fi
2026-02-16 08:14:16 +01:00
; ;
fftw3)
SED_PATTERN_LIST += " -e '/\s*-\s+\"fftw@/ ${ SUBST } "
; ;
2026-06-03 17:24:08 +02:00
gauxc)
SED_PATTERN_LIST += " -e '/\s*-\s+\" ${ 2 ,, } @/ ${ SUBST } "
if [ [ " ${ ON_OFF } " = = "ON" ] ] ; then
# GauXC requires libtorch
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_LIBTORCH= ${ ON_OFF } "
SED_PATTERN_LIST += " -e '/\s*-\s+\"py-torch@/ ${ SUBST } "
fi
; ;
2026-02-16 08:14:16 +01:00
libint2)
SED_PATTERN_LIST += " -e '/\s*-\s+\"libint@/ ${ SUBST } "
; ;
2026-03-27 23:32:53 +01:00
libtorch)
SED_PATTERN_LIST += " -e '/\s*-\s+\"py-torch@/ ${ SUBST } "
if [ [ " ${ ON_OFF } " = = "OFF" ] ] ; then
2026-06-03 17:24:08 +02:00
# DeePMD-kit and GauXC require libtorch
2026-03-27 23:32:53 +01:00
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_DEEPMD= ${ ON_OFF } "
SED_PATTERN_LIST += " -e '/\s*-\s+\"deepmdkit@/ ${ SUBST } "
2026-06-03 17:24:08 +02:00
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_GAUXC= ${ ON_OFF } "
SED_PATTERN_LIST += " -e '/\s*-\s+\"gauxc@/ ${ SUBST } "
2026-03-27 23:32:53 +01:00
fi
; ;
2026-06-06 23:20:56 +02:00
libxs)
2026-07-11 16:53:23 +02:00
SED_PATTERN_LIST += " -e '/\s*-\s+\"libxs@/ ${ SUBST } "
2026-06-06 23:20:56 +02:00
SED_PATTERN_LIST += " -e '/\s*-\s+\"libxsmm@/ ${ SUBST } "
2026-02-16 08:14:16 +01:00
if [ [ " ${ ON_OFF } " = = "OFF" ] ] ; then
SED_PATTERN_LIST += " -e '/\s*-\s+\"smm= ${ 2 ,, } \"/ s/ ${ 2 ,, } /blas/' "
fi
; ;
2026-02-17 12:40:58 +08:00
mimic)
2026-02-16 08:14:16 +01:00
SED_PATTERN_LIST += " -e '/\s*-\s+\"mimic-mcl@/ ${ SUBST } "
; ;
openpmd | adios2)
SED_PATTERN_LIST += " -e '/\s*-\s+\"adios2@/ ${ SUBST } "
SED_PATTERN_LIST += " -e '/\s*-\s+\"openpmd-api@/ ${ SUBST } "
; ;
2026-03-30 14:35:21 +02:00
tblite)
SED_PATTERN_LIST += " -e '/\s*-\s+\" ${ 2 ,, } @/ ${ SUBST } "
if [ [ " ${ ON_OFF } " = = "ON" ] ] ; then
echo "INFO: dftd4 is disabled to avoid conflicts when tblite is used"
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_DFTD4=OFF"
SED_PATTERN_LIST += " -e '/\s*-\s+\"dftd4@/ s/^ /#/'"
fi
; ;
2026-02-17 12:40:58 +08:00
vori)
2026-02-16 08:14:16 +01:00
SED_PATTERN_LIST += " -e '/\s*-\s+\"lib ${ 2 ,, } @/ ${ SUBST } "
; ;
esac
; ;
2026-02-17 12:40:58 +08:00
libvdwxc | spfft | spla | sirius)
2026-02-20 15:50:32 +01:00
echo "WARNING: You have enabled or disabled one of the packages libvdwxc, spfft, spla, sirius"
echo " which means that the other packages will also be enabled or disabled"
2026-02-17 12:40:58 +08:00
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_LIBVDWXC= ${ ON_OFF } -DCP2K_USE_SpFFT= ${ ON_OFF } "
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_SPLA= ${ ON_OFF } -DCP2K_USE_SIRIUS= ${ ON_OFF } "
SED_PATTERN_LIST += " -e '/\s*-\s+\"libvdwxc@/ ${ SUBST } "
SED_PATTERN_LIST += " -e '/\s*-\s+\"spfft@/ ${ SUBST } "
SED_PATTERN_LIST += " -e '/\s*-\s+\"spla@/ ${ SUBST } "
SED_PATTERN_LIST += " -e '/\s*-\s+\"sirius@/ ${ SUBST } "
; ;
2026-02-16 08:14:16 +01:00
cray_pm_accel_energy | cusolver_mp | spla_gemm_offloading | unified_memory)
CMAKE_FEATURE_FLAGS_GPU += " -DCP2K_USE_ ${ 2 ^^ } = ${ ON_OFF } "
; ;
dbm_gpu | elpa_gpu | grid_gpu | pw_gpu)
CMAKE_FEATURE_FLAGS_GPU += " -DCP2K_ENABLE_ ${ 2 ^^ } = ${ ON_OFF } "
; ;
none)
# do nothing
; ;
*)
echo " ERROR: Unknown CP2K feature \" ${ 2 } \" specified "
${ EXIT_CMD } 1
; ;
esac
else
echo " ERROR: No feature found for flag \" ${ 1 } \" "
${ EXIT_CMD } 1
fi
2026-01-09 10:24:07 +01:00
shift 2
; ;
2026-02-02 16:16:11 +01:00
-gv | --gcc_version)
if ( ( $# > 1) ) ; then
case " ${ 2 } " in
2026-02-09 13:37:38 +01:00
1[ 0-6] )
2026-02-02 16:16:11 +01:00
GCC_VERSION = " ${ 2 } "
; ;
*)
2026-02-09 13:37:38 +01:00
echo " ERROR: Invalid GCC version \" ${ 2 } \" specified (choose from 10 to 16) "
2026-02-02 16:16:11 +01:00
${ EXIT_CMD } 1
; ;
esac
else
echo " ERROR: No argument found for flag \" ${ 1 } \" (choose a GCC version) "
${ EXIT_CMD } 1
fi
shift 2
; ;
2026-02-10 12:15:01 +01:00
-gm | -gpu | --gpu_model)
if ( ( $# > 1) ) ; then
case " ${ 2 ^^ } " in
2026-03-01 09:06:41 +01:00
P100 | V100 | T400 | A100 | A40 | H100 | H200 | GH200)
2026-02-10 12:15:01 +01:00
GPU_MODEL = " ${ 2 ^^ } "
case " ${ GPU_MODEL } " in
P100)
2026-02-27 13:51:52 +01:00
CUDA_SM_CODE = 60
2026-02-10 12:15:01 +01:00
; ;
V100)
2026-02-27 13:51:52 +01:00
CUDA_SM_CODE = 70
2026-02-10 12:15:01 +01:00
; ;
2026-03-01 09:06:41 +01:00
T400)
2026-02-27 13:51:52 +01:00
CUDA_SM_CODE = 75
2026-02-24 17:51:24 +01:00
; ;
2026-02-10 12:15:01 +01:00
A100)
2026-02-27 13:51:52 +01:00
CUDA_SM_CODE = 80
2026-02-10 12:15:01 +01:00
; ;
2026-02-27 13:51:52 +01:00
A40)
CUDA_SM_CODE = 86
; ;
H100 | H200 | GH200)
CUDA_SM_CODE = 90
2026-02-10 12:15:01 +01:00
; ;
esac
2026-02-26 22:32:29 +01:00
; ;
2026-02-27 13:51:52 +01:00
60 | 70 | 75 | 80 | 86 | 87 | 89 | 90 | 120 | 121)
CUDA_SM_CODE = ${ 2 }
2026-02-10 12:15:01 +01:00
; ;
NONE)
GPU_MODEL = " ${ 2 ,, } "
; ;
*)
2026-03-01 09:06:41 +01:00
echo -e " \nERROR: Unknown GPU model \" ${ 2 } \" specified (choose <CUDA SM code>, P100, V100, T400, A100, A40, H100, H200, GH200 or none)\n "
2026-02-10 12:15:01 +01:00
${ EXIT_CMD } 1
; ;
esac
else
2026-03-01 09:06:41 +01:00
echo -e " \nERROR: No argument found for flag \" ${ 1 } \" (choose <CUDA SM code>, P100, V100, T400, A100, A40, H100, H200, GH200 or none)\n "
2026-02-10 12:15:01 +01:00
${ EXIT_CMD } 1
fi
shift 2
; ;
2026-01-09 10:24:07 +01:00
-h | --help)
HELP = "yes"
shift 1
; ;
2026-01-22 11:13:28 +01:00
-ip | --install_path | --install_prefix)
2026-01-27 18:12:08 +01:00
if ( ( $# > 1) ) ; then
2026-06-29 14:26:35 +02:00
INSTALL_PREFIX = " $( realpath " ${ 2 } " ) "
2026-01-27 18:12:08 +01:00
else
echo " ERROR: No install path argument found for flag \" ${ 1 } \" "
${ EXIT_CMD } 1
fi
2026-01-09 10:24:07 +01:00
shift 2
; ;
2026-01-22 11:13:28 +01:00
-j)
2026-02-02 10:25:44 +01:00
if ( ( $# > 1) ) ; then
case " ${ 2 } " in
-*)
2026-02-02 16:16:11 +01:00
shift 1
2026-02-02 10:25:44 +01:00
; ;
[ 0-9] *)
NUM_PROCS = " ${ 2 } "
shift 2
; ;
*)
echo " ERROR: The -j flag can only be followed by an integer number, found \" ${ 2 } \" "
${ EXIT_CMD } 1
; ;
esac
else
shift 1
fi
2026-01-22 11:13:28 +01:00
; ;
-j[ 0-9] *)
NUM_PROCS = " ${ 1 #-j } "
shift 1
; ;
2026-01-27 18:12:08 +01:00
-mpi | --mpi_mode)
if ( ( $# > 1) ) ; then
2026-02-16 08:14:16 +01:00
case " ${ 2 ,, } " in
mpich | openmpi)
CMAKE_FEATURE_FLAG_MPI = "-DCP2K_USE_MPI=ON"
MPI_MODE = " ${ 2 ,, } "
; ;
no | none | off)
CMAKE_FEATURE_FLAG_MPI = "-DCP2K_USE_MPI=OFF"
MPI_MODE = "no"
; ;
*)
echo " ERROR: Unknown MPI mode \" ${ 2 } \" specified (choose mpich, openmpi, or no) "
${ EXIT_CMD } 1
; ;
esac
2026-01-27 18:12:08 +01:00
else
echo " ERROR: No argument found for flag \" ${ 1 } \" "
2026-02-16 08:14:16 +01:00
echo " The MPI mode is required (choose mpich, openmpi, or no)"
2026-01-27 18:12:08 +01:00
${ EXIT_CMD } 1
fi
shift 2
2026-01-09 10:24:07 +01:00
; ;
2026-03-06 10:40:13 +01:00
-np | --num_packages)
2026-03-05 18:41:31 +01:00
if ( ( $# > 1) ) ; then
case " ${ 2 } " in
-*)
shift 1
; ;
[ 0-9] *)
NUM_PACKAGES = " ${ 2 } "
shift 2
; ;
*)
echo " ERROR: The -np flag can only be followed by an integer number, found \" ${ 2 } \" "
${ EXIT_CMD } 1
; ;
esac
else
shift 1
fi
; ;
2026-07-01 16:13:06 +02:00
-opencl)
USE_OPENCL = "yes"
shift 1
; ;
2026-02-07 13:12:03 +01:00
-rc | --rebuild_cp2k)
REBUILD_CP2K = "yes"
shift 1
; ;
2026-01-09 10:24:07 +01:00
-t | --test)
RUN_TEST = "yes"
2026-01-27 18:12:08 +01:00
if ( ( $# > 1) ) ; then
TESTOPTS = " ${ 2 } "
else
echo " ERROR: No argument found for flag \" ${ 1 } \" "
echo " A string argument with the TESTOPTS (even an empty one \"\") is required"
${ EXIT_CMD } 1
fi
2026-01-09 10:24:07 +01:00
shift 2
; ;
2026-05-08 09:59:03 +02:00
-uc | --use_cache)
if ( ( $# > 1) ) ; then
case " ${ 2 ,, } " in
folder | minio | no | none)
USE_CACHE = " ${ 2 ,, } "
; ;
*)
echo " ERROR: Invalid cache mode \" ${ 2 } \" specified (choose folder, minio or no) "
${ EXIT_CMD } 1
; ;
esac
else
echo " ERROR: No argument found for flag \" ${ 1 } \" (choose folder, minio or no) "
${ EXIT_CMD } 1
fi
shift 2
; ;
2026-01-27 18:12:08 +01:00
-ue | --use_externals)
USE_EXTERNALS = "yes"
shift 1
; ;
2026-01-09 10:24:07 +01:00
-v | --verbose)
VERBOSE = 1
INSTALL_MESSAGE = "LAZY"
2026-01-21 11:01:04 +01:00
VERBOSE_FLAG = "--verbose"
2026-01-09 10:24:07 +01:00
VERBOSE_MAKEFILE = "ON"
2026-03-06 10:40:13 +01:00
VERBOSE_SPACK = "--verbose"
2026-01-09 10:24:07 +01:00
shift 1
; ;
--)
2026-01-27 18:12:08 +01:00
shift 1
2026-01-09 10:24:07 +01:00
break
; ;
-*)
2026-01-27 18:12:08 +01:00
echo " ERROR: Unknown option \" ${ 1 } \" specified "
2026-01-09 10:24:07 +01:00
${ EXIT_CMD } 1
; ;
*)
break
; ;
esac
done
2026-03-05 18:41:31 +01:00
# Remove leading zeros from NUM_PACKAGES and NUM_PROCS
NUM_PACKAGES = $( awk '{print $1+0}' <<< " ${ NUM_PACKAGES } " )
2026-01-22 11:13:28 +01:00
NUM_PROCS = $( awk '{print $1+0}' <<< " ${ NUM_PROCS } " )
2026-01-28 18:10:13 +01:00
# Check if we are working within a docker or podman container
[ [ -f /.dockerenv || -f /run/.containerenv ] ] && IN_CONTAINER = "yes" || IN_CONTAINER = "no"
2026-02-16 08:14:16 +01:00
# Assemble CMake feature flag list
2026-06-03 17:24:08 +02:00
CMAKE_FEATURE_FLAGS = " ${ CMAKE_FEATURE_FLAG_ALL } ${ CMAKE_FEATURE_FLAG_MPI } ${ CMAKE_FEATURE_FLAGS } "
2026-02-16 08:14:16 +01:00
2026-07-11 16:53:23 +02:00
# DLA-Future does not work with MPICH yet
case " ${ MPI_MODE } " in
mpich | openmpi)
if [ [ " ${ CMAKE_FEATURE_FLAGS } " = = *"-DCP2K_USE_EVERYTHING=ON" * ] ] ||
[ [ " ${ CMAKE_FEATURE_FLAGS } " = = *"-DCP2K_USE_DLAF=ON" * ] ] ; then
echo -e " \nINFO: DLA-Future does not work with ${ MPI_MODE ^^ } yet and is disabled "
CMAKE_FEATURE_FLAGS += " -DCP2K_USE_DLAF=OFF"
SED_PATTERN_LIST += " -e '/\s*-\s+\"dla-future.*@/ s/^ /#/'"
SED_PATTERN_LIST += " -e 's/\+dlaf/\~dlaf/'"
fi
; ;
esac
2026-03-30 14:35:21 +02:00
# Clean CMake feature flag list from repeated entries and keep only the last definition
declare -A last = ( )
order = ( )
# First pass: record the last occurrence of each flag
for flag in ${ CMAKE_FEATURE_FLAGS } ; do
name = ${ flag %=* }
last[ ${ name } ] = ${ flag }
order += ( " ${ name } " )
done
# Second pass: output only the last definition per flag
# but respecting original order of last appearance
2026-02-16 08:14:16 +01:00
declare -A seen = ( )
out = ( )
2026-03-30 14:35:21 +02:00
for name in " ${ order [@] } " ; do
if [ [ -z ${ seen [ ${ name } ]+_ } ] ] ; then
seen[ ${ name } ] = 1
out += ( " ${ last [ ${ name } ] } " )
fi
2026-02-16 08:14:16 +01:00
done
CMAKE_FEATURE_FLAGS = " $( printf '%s\n' " ${ out [*] } " ) "
2026-03-25 13:47:09 +01:00
export BUILD_DEPS BUILD_DEPS_ONLY BUILD_SHARED_LIBS CMAKE_FEATURE_FLAGS CMAKE_FEATURE_FLAGS_GPU CP2K_BUILD_TYPE \
2026-05-08 09:59:03 +02:00
CRAY CUDA_SM_CODE DEPS_BUILD_TYPE GCC_VERSION GPU_MODEL IN_CONTAINER INSTALL_MESSAGE MPI_MODE NUM_PACKAGES \
2026-07-01 16:13:06 +02:00
NUM_PROCS REBUILD_CP2K RUN_TEST TESTOPTS USE_CACHE USE_OPENCL VERBOSE VERBOSE_FLAG VERBOSE_MAKEFILE VERBOSE_SPACK
2026-01-09 10:24:07 +01:00
# Show help if requested
if [ [ " ${ HELP } " = = "yes" ] ] ; then
echo ""
2026-01-29 17:12:11 +01:00
echo " Usage: ${ SCRIPT_NAME } [-bd | --build_deps] "
echo " [-bd_only | --build_deps_only]"
2026-06-28 22:19:02 +02:00
echo " [-bp | --build_path PATH]"
2026-03-25 13:47:09 +01:00
echo " [-bsl | --build_static_libcp2k]"
2026-01-29 17:12:11 +01:00
echo " [-bt | --build_type (Debug | Release | RelWithDebInfo)]"
2026-02-01 18:50:49 +01:00
echo " [-cray]"
2026-03-11 15:32:57 +01:00
echo " [-cv | --cp2k_version (pdbg | psmp | sdbg | ssmp | ssmp-static)]"
2026-02-16 08:14:16 +01:00
echo " [-df | --disable | --disable_feature (all | FEATURE | PACKAGE | none)"
echo " [-ef | --enable | --enable_feature (all | FEATURE | PACKAGE | none)"
2026-03-01 09:06:41 +01:00
echo " [-gm | -gpu | --gpu_model (<CUDA SM code> | P100 | V100 | T400 | A100 | H100 | H200 | GH200 | none)]"
2026-02-09 13:37:38 +01:00
echo " [-gv | --gcc_version (10 | 11 | 12 | 13 | 14 | 15 | 16)]"
2026-01-29 17:12:11 +01:00
echo " [-h | --help]"
echo " [-ip | --install_path PATH]"
2026-01-27 18:12:08 +01:00
echo " [-j #PROCESSES]"
2026-01-29 17:12:11 +01:00
echo " [-mpi | --mpi_mode (mpich | no | openmpi)]"
2026-03-06 10:40:13 +01:00
echo " [-np | --num_packages #PACKAGES]"
2026-02-07 13:12:03 +01:00
echo " [-rc | --rebuild_cp2k]"
2026-07-08 11:06:37 +02:00
echo " [-t | --test \"TESTOPTS\"]"
2026-05-08 09:59:03 +02:00
echo " [-uc | --use_cache (folder | minio | no | none)]"
2026-01-29 17:12:11 +01:00
echo " [-ue | --use_externals]"
echo " [-v | --verbose]"
2026-01-22 11:13:28 +01:00
echo ""
echo "Flags:"
2026-03-25 13:47:09 +01:00
echo " --build_deps : Force a rebuild of all CP2K dependencies from scratch (removes the spack folder)"
echo " --build_deps_only : Rebuild ONLY the CP2K dependencies from scratch (removes the spack folder)"
2026-06-28 22:19:02 +02:00
echo " --build_path : Define the CP2K build path (default: ${ CP2K_ROOT } ) "
2026-03-25 13:47:09 +01:00
echo " --build_static_libcp2k: Build a static CP2K library libcp2k.a instead of the default shared one libcp2k.so"
echo " --build_type : Set preferred CMake build type for CP2K (default: \"Release\")"
echo " --cp2k_version : CP2K version to be built (default: \"psmp\")"
echo " -cray : Use Cray specific spack configuration"
echo " --enable_feature : Enable feature or package (default: all)"
echo " --disable_feature : Disable feature or package"
echo " --help : Print this help information"
echo " --gcc_version : Use the specified GCC version (default: automatically decided by spack)"
echo " --gpu_model : Select GPU model (default: none)"
echo " --install_path : Define the CP2K installation path (default: ./install)"
echo " -j : Maximum number of processes used in parallel"
echo " --mpi_mode : Set preferred MPI mode (default: \"mpich\")"
echo " --num_packages : Maximum number of packages built by spack in parallel (default: 4)"
2026-07-01 16:13:06 +02:00
echo " -opencl : Perform build with OpenCL support"
2026-03-25 13:47:09 +01:00
echo " --rebuild_cp2k : Rebuild CP2K: removes the build folder (default: no)"
echo " --test : Perform a regression test run after a successful build"
2026-05-08 09:59:03 +02:00
echo " --use_cache : Use a \"folder\", a \"MinIO\" object storage container (requires podman) or \"no\" cache"
echo " Set the environment variable SPACK_CACHE to specify the folder name, e.g."
echo " SPACK_CACHE=\"file:// ${ CP2K_ROOT } /spack_cache\" (default) "
2026-03-25 13:47:09 +01:00
echo " --use_externals : Use external packages installed on the host system. This results in much"
echo " faster build times, but it can also cause conflicts with outdated packages"
echo " pulled in from the host system, e.g. old python or gcc versions"
echo " --verbose : Write verbose output"
2026-01-09 10:24:07 +01:00
echo ""
echo "Hints:"
echo " - Remove the folder ${ CP2K_ROOT } /build to (re)build CP2K from scratch "
2026-02-07 13:12:03 +01:00
echo " (see also --rebuild_cp2k flag)"
2026-01-30 15:02:48 +01:00
echo " - Remove the folder ${ CP2K_ROOT } /spack to (re)build CP2K and all its dependencies from scratch "
2026-02-07 13:12:03 +01:00
echo " (see also --build_deps flag)"
2026-01-09 10:24:07 +01:00
echo " - The folder ${ CP2K_ROOT } /install is updated after each successful run "
echo ""
2026-06-03 17:24:08 +02:00
echo "Packages: all | ace | cosma | deepmd | dftd4 | dlaf | elpa | fftw3 | gauxc | greenx | hdf5 | libfci |"
2026-07-06 16:12:20 +02:00
echo " libgint | libint | libsmeagol | libtorch | libvdwxc | libxs | mimic | openpmd | pexsi | plumed |"
2026-06-03 17:24:08 +02:00
echo " sirius | spfft | spglib | spla | tblite | trexio | vori "
2026-02-16 08:14:16 +01:00
echo ""
echo "Features: cray_pm_accel_energy | cusolver_mp | dbm_gpu | elpa_gpu | grid_gpu | pw_gpu |"
echo " spla_gemm_offloading | unified_memory"
echo ""
2026-01-29 17:12:11 +01:00
${ EXIT_CMD }
2026-01-09 10:24:07 +01:00
fi
2026-01-27 18:12:08 +01:00
echo ""
2026-01-30 15:02:48 +01:00
echo " BUILD_DEPS = ${ BUILD_DEPS } "
echo " BUILD_DEPS_ONLY = ${ BUILD_DEPS_ONLY } "
2026-06-28 22:19:02 +02:00
echo " BUILD_PATH = ${ BUILD_PATH } "
2026-03-25 13:47:09 +01:00
echo " BUILD_SHARED_LIBS = ${ BUILD_SHARED_LIBS } "
2026-03-03 17:54:40 +01:00
echo " CP2K_BUILD_TYPE = ${ CP2K_BUILD_TYPE } "
2026-01-30 15:02:48 +01:00
echo " CP2K_VERSION = ${ CP2K_VERSION } "
2026-02-13 15:42:41 +01:00
echo " CRAY = ${ CRAY } "
2026-03-03 17:54:40 +01:00
echo " DEPS_BUILD_TYPE = ${ DEPS_BUILD_TYPE } "
2026-02-02 16:16:11 +01:00
echo " GCC_VERSION = ${ GCC_VERSION } "
2026-02-27 13:51:52 +01:00
if ( ( CUDA_SM_CODE > 0) ) ; then
echo " GPU = ${ GPU_MODEL } (CUDA SM code: ${ CUDA_SM_CODE } ) "
2026-02-10 12:15:01 +01:00
else
echo " GPU = ${ GPU_MODEL } "
fi
2026-01-30 15:02:48 +01:00
echo " INSTALL_PREFIX = ${ INSTALL_PREFIX } "
echo " INSTALL_MESSAGE = ${ INSTALL_MESSAGE } "
echo " IN_CONTAINER = ${ IN_CONTAINER } "
echo " MPI_MODE = ${ MPI_MODE } "
2026-03-05 18:41:31 +01:00
echo " NUM_PACKAGES = ${ NUM_PACKAGES } (packages are built by spack concurrently) "
2026-01-30 15:02:48 +01:00
echo " NUM_PROCS = ${ NUM_PROCS } (processes) "
2026-02-22 19:51:33 +01:00
echo " Physical cores = $( lscpu -p= Core,Socket | grep -v '#' | sort -u | wc -l) (host view) "
2026-02-07 13:12:03 +01:00
echo " REBUILD_CP2K = ${ REBUILD_CP2K } "
2026-01-30 15:02:48 +01:00
echo " RUN_TEST = ${ RUN_TEST } "
2026-01-09 10:24:07 +01:00
if [ [ " ${ RUN_TEST } " = = "yes" ] ] ; then
2026-01-30 15:02:48 +01:00
echo " TESTOPTS = \" ${ TESTOPTS } \" "
2026-01-09 10:24:07 +01:00
fi
2026-05-08 09:59:03 +02:00
echo " USE_CACHE = ${ USE_CACHE } "
2026-01-30 15:02:48 +01:00
echo " USE_EXTERNALS = ${ USE_EXTERNALS } "
2026-07-01 16:13:06 +02:00
echo " USE_OPENCL = ${ USE_OPENCL } "
2026-01-30 15:02:48 +01:00
echo " VERBOSE_FLAG = ${ VERBOSE_FLAG } "
echo " VERBOSE_MAKEFILE = ${ VERBOSE_MAKEFILE } "
echo " VERBOSE = ${ VERBOSE } "
2026-01-09 11:16:14 +01:00
if ( ( $# > 0) ) ; then
2026-01-22 11:13:28 +01:00
echo "Remaining args =" " $@ " "(not used)"
fi
2026-01-27 18:12:08 +01:00
echo ""
2026-02-16 08:14:16 +01:00
echo " LD_LIBRARY_PATH = ${ LD_LIBRARY_PATH :- } "
echo ""
echo " PATH = ${ PATH :- } "
echo ""
echo " CMAKE_FEATURE_FLAGS = ${ CMAKE_FEATURE_FLAGS } "
echo ""
2026-07-11 16:53:23 +02:00
( ( VERBOSE > 0) ) && echo -e " SED_PATTERN_LIST = ${ SED_PATTERN_LIST } \n "
2026-01-22 11:13:28 +01:00
2026-03-05 18:41:31 +01:00
# Check if a valid number for the packages to be built by spack in parallel is given
if ( ( NUM_PACKAGES < 1) ) ; then
2026-03-06 10:40:13 +01:00
echo -e " \nERROR: The requested number of packages to be built by spack in parallel should be larger than 0, found \" ${ NUM_PACKAGES } \" "
${ EXIT_CMD } 1
elif ( ( NUM_PROCS > 0) ) && ( ( NUM_PACKAGES > NUM_PROCS) ) ; then
echo -e " \nERROR: The requested number of packages to be built in parallel by spack ( ${ NUM_PACKAGES } ) is larger than the requested number of processes ( ${ NUM_PROCS } ) "
2026-03-05 18:41:31 +01:00
${ EXIT_CMD } 1
fi
2026-01-22 11:13:28 +01:00
# Check if a valid number of processes is requested
if ( ( NUM_PROCS < 1) ) ; then
echo " ERROR: The requested number of processes should be larger than 0, found \" ${ NUM_PROCS } \" "
${ EXIT_CMD } 1
elif ( ( MAX_PROCS > 0) ) && ( ( NUM_PROCS > MAX_PROCS) ) ; then
echo " WARNING: The requested number of processes ( ${ NUM_PROCS } ) is larger than the detected number of CPU cores ( ${ MAX_PROCS } ) "
2026-01-09 10:24:07 +01:00
fi
2026-03-03 17:54:40 +01:00
# Check if a valid CMake build type is selected for the dependencies
case " ${ DEPS_BUILD_TYPE ^ } " in
Release | RelWithDebInfo)
true
; ;
Debug)
echo " ERROR: The CMake build type \" ${ DEPS_BUILD_TYPE } \" is not supported for building the dependencies "
${ EXIT_CMD } 1
; ;
*)
echo " ERROR: Invalid CMake build type \" ${ DEPS_BUILD_TYPE } \" selected for building the dependencies "
${ EXIT_CMD } 1
; ;
esac
# Check if a valid CMake build type is selected for CP2K
case " ${ CP2K_BUILD_TYPE ^ } " in
2026-01-22 11:13:28 +01:00
Debug | Release | RelWithDebInfo)
2026-01-21 11:01:04 +01:00
true
; ;
*)
2026-03-03 17:54:40 +01:00
echo " ERROR: Invalid CMake build type \" ${ CP2K_BUILD_TYPE } \" selected for building CP2K "
2026-01-27 18:12:08 +01:00
${ EXIT_CMD } 1
; ;
esac
# Check if a valid MPI type is selected
case " ${ MPI_MODE } " in
mpich | openmpi)
2026-02-07 13:12:03 +01:00
if [ [ " ${ CP2K_VERSION } " = = "ssmp" * ] ] ; then
2026-01-27 18:12:08 +01:00
echo " ERROR: MPI type \" ${ MPI_MODE } \" specified for building a serial CP2K binary "
${ EXIT_CMD } 1
fi
; ;
no)
if [ [ " ${ CP2K_VERSION } " = = "psmp" ] ] ; then
echo " ERROR: MPI type \" ${ MPI_MODE } \" specified for building an MPI-parallel CP2K binary "
${ EXIT_CMD } 1
fi
; ;
*)
echo " ERROR: Invalid MPI type \" ${ MPI_MODE } \" selected "
echo " Choose from (mpich | no | openmpi)"
2026-01-21 11:01:04 +01:00
${ EXIT_CMD } 1
; ;
esac
2026-01-09 10:24:07 +01:00
2026-02-24 13:37:16 +01:00
# Check if CP2K_VERSION and the selected features are compatible
case " ${ CP2K_VERSION } " in
ssmp | ssmp-static)
for package in cosma dlaf elpa libfabric libsmeagol mimic openpmd pexsi plumed sirius spla; do
if [ [ " ${ CMAKE_FEATURE_FLAGS } " = = *" -DCP2K_USE_ ${ package ^^ } =ON " * ] ] ; then
echo -e " ERROR: The feature ${ package ^^ } is not available for building serial CP2K binaries ( ${ CP2K_VERSION } )\n "
${ EXIT_CMD } 1
fi
done
2026-02-25 10:27:33 +01:00
# Further exclusions are needed for statically linked serial CP2K binaries
if [ [ " ${ CP2K_VERSION } " = = "ssmp-static" ] ] ; then
2026-07-06 16:12:20 +02:00
for package in ace deepmd greenx hdf5 libgint libtorch trexio; do
2026-02-25 10:27:33 +01:00
if [ [ " ${ CMAKE_FEATURE_FLAGS } " = = *" -DCP2K_USE_ ${ package ^^ } =ON " * ] ] ; then
echo -e " ERROR: The feature ${ package ^^ } is not available for building statically linked serial CP2K binaries ( ${ CP2K_VERSION } )\n "
${ EXIT_CMD } 1
fi
done
fi
2026-02-24 13:37:16 +01:00
; ;
esac
2026-02-10 12:15:01 +01:00
# Perform CUDA GPU related settings
2026-02-27 13:51:52 +01:00
if ( ( CUDA_SM_CODE > 0) ) ; then
2026-02-24 10:24:55 +01:00
if command -v nvcc & > /dev/null; then
CUDA_VERSION = $( nvcc -V | sed -n 's/.*release \([0-9.]*\).*/\1/p' )
2026-02-27 13:51:52 +01:00
NVCC_VERSION = $( awk -v x = " ${ CUDA_VERSION } " 'BEGIN{print 10*x}' )
2026-02-24 10:24:55 +01:00
else
echo -e "\nERROR: No CUDA toolkit installation found (nvcc compiler not found)\n"
${ EXIT_CMD } 1
fi
2026-02-27 13:51:52 +01:00
# Check if the selected CUDA SM code is valid when the nvidia-smi command is available
2026-02-10 19:00:08 +01:00
if command -v nvidia-smi & > /dev/null; then
2026-02-24 10:24:55 +01:00
echo -e "NVIDIA driver installation found:\n"
2026-02-16 17:51:39 +01:00
nvidia-smi
2026-02-27 13:51:52 +01:00
HOST_CUDA_SM_CODE = $( nvidia-smi --query-gpu= compute_cap --format= csv,noheader | tail -n 1 | awk '{print 10*$1}' )
if ( ( CUDA_SM_CODE > HOST_CUDA_SM_CODE) ) ; then
2026-02-24 17:51:24 +01:00
echo ""
2026-02-27 13:51:52 +01:00
echo " ERROR: The requested CUDA SM code ( ${ CUDA_SM_CODE } ) is larger than the maximum "
echo " CUDA SM code ( ${ HOST_CUDA_SM_CODE } ) supported by the host system "
2026-02-24 17:51:24 +01:00
echo ""
2026-02-10 19:00:08 +01:00
${ EXIT_CMD } 1
fi
2026-02-24 10:24:55 +01:00
else
echo "INFO: No NVIDIA driver installation found (nvidia-smi not found)"
2026-02-10 19:00:08 +01:00
fi
2026-02-27 13:51:52 +01:00
# Check GPU support by the CUDA SDK
if ( ( NVCC_VERSION < 128) ) && ( ( CUDA_SM_CODE > 90) ) ; then
echo ""
echo " ERROR: The CUDA SDK version ${ NVCC_VERSION } does not support GPUs with a "
echo " CUDA SM code larger than 90 (found ${ CUDA_SM_CODE } ) "
echo ""
${ EXIT_CMD } 1
fi
if ( ( NVCC_VERSION > 129) ) && ( ( CUDA_SM_CODE < 75) ) ; then
echo ""
echo " ERROR: The CUDA SDK version ${ NVCC_VERSION } does not support GPUs with a "
echo " CUDA SM code smaller than 75 (found ${ CUDA_SM_CODE } ) "
echo ""
${ EXIT_CMD } 1
fi
2026-02-10 19:00:08 +01:00
CMAKE_CUDA_FLAGS = "-DCP2K_USE_ACCEL=CUDA"
CMAKE_CUDA_FLAGS += " -DCP2K_WITH_GPU= ${ GPU_MODEL } "
2026-02-27 13:51:52 +01:00
CMAKE_CUDA_FLAGS += " -DCMAKE_CUDA_ARCHITECTURES= ${ CUDA_SM_CODE } "
2026-02-16 08:14:16 +01:00
CMAKE_CUDA_FLAGS += " ${ CMAKE_FEATURE_FLAGS_GPU } "
out = ( )
for flag in ${ CMAKE_CUDA_FLAGS } ; do
[ [ ${ seen [ ${ flag } ]+_ } ] ] || {
seen[ ${ flag } ] = 1
out += ( " ${ flag } " )
}
done
CMAKE_CUDA_FLAGS = " $( printf '%s\n' " ${ out [*] } " ) "
2026-02-24 10:24:55 +01:00
echo -e " \nCMAKE_CUDA_FLAGS = ${ CMAKE_CUDA_FLAGS } "
[ [ -n " ${ CUDA_VERSION :- } " ] ] && echo -e " \nCUDA_VERSION = ${ CUDA_VERSION } (nvcc compiler) "
[ [ -n " ${ CUDA_HOME :- } " ] ] && echo -e " \nCUDA_HOME = ${ CUDA_HOME } "
2026-02-11 12:08:26 +01:00
echo ""
2026-02-10 12:15:01 +01:00
else
CMAKE_CUDA_FLAGS = "-DCP2K_USE_ACCEL=OFF"
fi
export CMAKE_CUDA_FLAGS
2026-03-27 23:32:53 +01:00
# Retrieve and print available resources
free -h
echo ""
ulimit -c 0 -s unlimited
ulimit -a
echo ""
2026-03-03 17:54:40 +01:00
2026-01-09 10:24:07 +01:00
### Build CP2K dependencies with Spack if needed or requested ###
2026-02-12 11:24:17 +01:00
# Spack version
2026-07-08 18:39:19 +08:00
export SPACK_VERSION = " ${ SPACK_VERSION :- 1 .2.1 } "
2026-06-28 22:19:02 +02:00
export SPACK_BUILD_PATH = " ${ BUILD_PATH } /spack "
2026-02-12 11:24:17 +01:00
export SPACK_ROOT = " ${ SPACK_BUILD_PATH } /spack "
2026-01-09 10:24:07 +01:00
2026-05-20 11:58:28 +02:00
# Isolate user configuration for spack
export SPACK_DISABLE_LOCAL_CONFIG = true
export SPACK_USER_CONFIG_PATH = " ${ SPACK_BUILD_PATH } "
export SPACK_USER_CACHE_PATH = " ${ SPACK_BUILD_PATH } /cache "
2026-02-08 21:54:23 +01:00
# Define the CP2K spack configuration file
2026-03-03 17:54:40 +01:00
export CP2K_CONFIG_FILE = " ${ SPACK_BUILD_PATH } /cp2k_deps_ ${ CP2K_VERSION : 0 : 1 } ${ CP2K_VERSION : 4 } .yaml "
2026-02-08 21:54:23 +01:00
2026-02-07 13:12:03 +01:00
# If requested, remove the spack folder for (re)building all CP2K dependencies
2026-02-02 10:36:37 +01:00
if [ [ " ${ BUILD_DEPS } " = = "always" ] ] ; then
2026-06-29 14:26:35 +02:00
for folder in ${ SPACK_BUILD_PATH } ${ BUILD_PATH } /build ${ INSTALL_PREFIX } ; do
2026-02-07 13:12:03 +01:00
if [ [ -d " ${ folder } " ] ] ; then
echo " Removing folder \" ${ folder } \" "
rm -rf " ${ folder } "
fi
done
fi
# If requested, remove the build folder for (re)building CP2K
if [ [ " ${ REBUILD_CP2K } " = = "yes" ] ] ; then
2026-06-29 14:26:35 +02:00
for folder in ${ BUILD_PATH } /build ${ INSTALL_PREFIX } ; do
2026-02-02 10:36:37 +01:00
if [ [ -d " ${ folder } " ] ] ; then
echo " Removing folder \" ${ folder } \" "
rm -rf " ${ folder } "
fi
done
fi
2026-01-09 14:26:01 +01:00
2026-07-01 17:08:40 +08:00
# An incomplete build already contains the Spack installation, source cache,
# environment, and every successfully installed dependency. Re-enter the
# setup/install path until the completion marker is written.
if [ [ ! -f " ${ SPACK_BUILD_PATH } /BUILD_DEPENDENCIES_COMPLETED " ] ] ; then
2026-01-09 10:24:07 +01:00
2026-07-01 17:08:40 +08:00
if [ [ -d " ${ SPACK_BUILD_PATH } " ] ] ; then
echo " INFO: Resuming incomplete CP2K dependency build in ${ SPACK_BUILD_PATH } "
else
echo " INFO: Creating local Spack build directory ${ SPACK_BUILD_PATH } "
fi
2026-01-21 11:01:04 +01:00
mkdir -p " ${ SPACK_BUILD_PATH } "
2026-01-09 11:16:14 +01:00
cd " ${ SPACK_BUILD_PATH } " || ${ EXIT_CMD } 1
2026-01-09 10:24:07 +01:00
2026-01-27 18:12:08 +01:00
# Reset the spack environment
unset SPACK_ENV
2026-07-01 17:08:40 +08:00
# Install Spack only when the local bootstrap is absent. wget --continue
# also retains a partially downloaded release archive across interruptions.
2026-01-22 11:34:15 +01:00
if [ [ ! -d " ${ SPACK_ROOT } " ] ] ; then
2026-02-12 11:24:17 +01:00
echo " Installing Spack ${ SPACK_VERSION } "
2026-07-01 17:08:40 +08:00
if ! wget -q -c " https://github.com/spack/spack/archive/v ${ SPACK_VERSION } .tar.gz " ; then
echo " ERROR: Downloading Spack ${ SPACK_VERSION } failed "
${ EXIT_CMD } 1
fi
if ! tar -xzf " v ${ SPACK_VERSION } .tar.gz " ; then
echo " ERROR: Extracting Spack ${ SPACK_VERSION } failed "
${ EXIT_CMD } 1
fi
if ! mv -f " ${ SPACK_BUILD_PATH } /spack- ${ SPACK_VERSION } " " ${ SPACK_ROOT } " ; then
echo " ERROR: Installing Spack ${ SPACK_VERSION } failed "
${ EXIT_CMD } 1
fi
rm -f " v ${ SPACK_VERSION } .tar.gz "
2026-01-22 11:34:15 +01:00
fi
export PATH = " ${ SPACK_ROOT } /bin: ${ PATH } "
2026-05-20 11:58:28 +02:00
# Create cache folder for user configuration
2026-01-22 11:34:15 +01:00
mkdir -p " ${ SPACK_USER_CACHE_PATH } "
2026-05-08 09:59:03 +02:00
# Set Spack cache (folder is the default)
export SPACK_CACHE = " ${ SPACK_CACHE :- file : // ${ CP2K_ROOT } /spack_cache } "
# Prepare for package caching
if [ [ " ${ USE_CACHE } " = = @( "folder" | "minio" ) ] ] ; then
2026-07-01 17:08:40 +08:00
# Create the venv only once, then reuse it on a resumed dependency build.
if [ [ ! -x " ${ SPACK_BUILD_PATH } /venv/bin/python3 " ] ] ; then
if command -v python3 -m venv --help & > /dev/null; then
echo "Installing virtual environment for Python packages"
if ! python3 -m venv " ${ SPACK_BUILD_PATH } /venv " ; then
echo "ERROR: The creation of a virtual environment (venv) for Python packages failed"
${ EXIT_CMD } 1
fi
else
echo "ERROR: python3 -m venv was not found"
2026-01-30 15:02:48 +01:00
${ EXIT_CMD } 1
fi
fi
2026-07-01 17:08:40 +08:00
export PATH = " ${ SPACK_BUILD_PATH } /venv/bin: ${ PATH } "
# Avoid contacting PyPI again when the previously prepared venv is intact.
if ! python3 -c 'from importlib.metadata import version; assert version("boto3") == "1.38.11"; assert version("google-cloud-storage") == "3.1.0"' & > /dev/null; then
if ! python3 -m pip --version & > /dev/null; then
echo "ERROR: python3 -m pip was not found"
${ EXIT_CMD } 1
fi
if ! python3 -m pip install " ${ VERBOSE_FLAG } " --upgrade pip \
2026-06-21 05:47:26 +08:00
boto3 = = 1.38.11 google-cloud-storage= = 3.1.0; then
echo "ERROR: The installation of Python packages for the Spack cache failed"
${ EXIT_CMD } 1
fi
2026-01-24 15:26:39 +01:00
fi
fi
2026-05-08 09:59:03 +02:00
# Prepare for using an MinIO object storage as cache
if [ [ " ${ USE_CACHE } " = = "minio" ] ] ; then
if [ [ " ${ IN_CONTAINER } " = = "yes" ] ] ; then
echo "ERROR: An external MinIO object storage container cannot be used as cache within a container"
echo " Use \"folder\" or \"no\" caching instead of \"MinIO\""
${ EXIT_CMD } 1
fi
# MinIO requires podman
2026-01-24 15:26:39 +01:00
if command -v podman & > /dev/null; then
# Check podman version
( ( VERBOSE > 0) ) && podman version
PODMAN_VERSION = $( podman version --format '{{.Client.Version}}' | awk -F'[.-]' '{print $1}' )
if ( ( PODMAN_VERSION < 4) ) ; then
echo " WARNING: Outdated podman version $( podman version --format '{{.Client.Version}}' ) found "
2026-01-22 15:50:50 +01:00
fi
2026-05-08 09:59:03 +02:00
export SPACK_CACHE = " ${ SPACK_CACHE :- s3 : //spack-cache --s3-endpoint-url=http : //localhost : 9000 } "
2026-01-30 15:02:48 +01:00
if ! " ${ CP2K_ROOT } " /tools/docker/spack_cache_start.sh; then
echo "ERROR: Could not start (new) spack cache"
echo ""
echo "An error message starting with \"Error: initial journal cursor: ...\" indicates that the"
echo "journald logging does not work. Try to switch podman (3.x) to file-based logs by creating"
echo "the file \"~/.config/containers/containers.conf\" with the following two lines:"
echo "[containers]"
echo "log_driver = \"k8s-file\""
${ EXIT_CMD } 1
fi
2026-05-08 09:59:03 +02:00
else
echo "INFO: podman was not found"
echo " Install the package podman to use an MinIO object storage as cache"
echo " This accelerates a rebuild of the CP2K dependencies, significantly"
echo " The folder ${ SPACK_CACHE } will be used as cache "
USE_CACHE = "folder"
2026-01-22 15:50:50 +01:00
fi
2026-01-09 10:24:07 +01:00
fi
2026-05-08 09:59:03 +02:00
# Initialize Spack shell hooks
# shellcheck source=/dev/null
source " ${ SPACK_ROOT } /share/spack/setup-env.sh "
# Add spack cache as mirror if possible
if [ [ " ${ USE_CACHE } " = = @( "folder" | "minio" ) ] ] ; then
2026-01-30 15:02:48 +01:00
echo " SPACK_CACHE = \" ${ SPACK_CACHE } \" "
2026-02-20 15:50:32 +01:00
spack mirror list
if ! spack mirror list | grep -q "local-cache" ; then
2026-05-08 09:59:03 +02:00
echo "Setting up spack cache"
2026-02-20 15:50:32 +01:00
if ( ( VERBOSE > 0) ) ; then
" ${ CP2K_ROOT } " /tools/docker/scripts/setup_spack_cache.sh
else
" ${ CP2K_ROOT } " /tools/docker/scripts/setup_spack_cache.sh & > /dev/null
fi
2026-02-04 16:59:36 +01:00
fi
2026-01-22 11:13:28 +01:00
else
2026-05-08 09:59:03 +02:00
echo "INFO: A spack cache is NOT used"
2026-01-22 11:13:28 +01:00
fi
# Prepare the CP2K spack configuration file
2026-03-03 17:54:40 +01:00
CP2K_DEPS_FILE = " ${ CP2K_ROOT } /tools/spack/cp2k_deps_ ${ CP2K_VERSION : 0 : 1 } ${ CP2K_VERSION : 4 } .yaml "
if [ [ -f " ${ CP2K_DEPS_FILE } " ] ] ; then
sed -E \
-e " s|root: /opt/spack|root: ${ SPACK_ROOT } /opt/spack| " \
-e " /\"build_type=/s|build_type=[^\"]*|build_type= ${ DEPS_BUILD_TYPE } | " \
" ${ CP2K_DEPS_FILE } " > " ${ CP2K_CONFIG_FILE } "
else
echo -e " \nERROR: The spack configuration file ${ CP2K_DEPS_FILE } was not found\n "
${ EXIT_CMD } 1
fi
2026-01-09 10:24:07 +01:00
2026-01-27 18:12:08 +01:00
# Apply selected MPI type if needed
# MPICH is selected by default for psmp and no change needed for ssmp
if [ [ " ${ MPI_MODE } " = = "openmpi" ] ] ; then
2026-02-16 08:14:16 +01:00
sed -E \
-e '/\s*-\s+"mpich@/ s/^ /#/' \
-e '/\s*#\s*-\s+"openmpi@/ s/#/ /' \
-e '/\s*-\s+mpich/ s/mpich$/openmpi/' \
2026-01-27 18:12:08 +01:00
-i " ${ CP2K_CONFIG_FILE } "
fi
2026-02-10 12:15:01 +01:00
# Activate CUDA in the spack configuration file if requested
2026-02-27 13:51:52 +01:00
if ( ( CUDA_SM_CODE > 0) ) ; then
2026-02-24 10:24:55 +01:00
sed -E \
2026-02-27 13:51:52 +01:00
-e " 0,/~cuda/s//+cuda cuda_arch= ${ CUDA_SM_CODE } / " \
2026-02-25 13:50:19 +01:00
-e 's/"~cuda\s+~gpu_direct"/"\+cuda \+gpu_direct"/' \
2026-02-25 09:19:26 +01:00
-e '/\s*#\s*-\s+"fabrics=efa,ucx"/ s/#/ /' \
2026-07-01 16:13:06 +02:00
-e '/\s*#\s*-\s+"libxstream@/ s/#/ /' \
2026-02-24 10:24:55 +01:00
-i " ${ CP2K_CONFIG_FILE } "
2026-02-27 13:51:52 +01:00
# Building libfabric with CUDA causes problems
# sed -E -e 's/"~cuda\s+~gdrcopy"/"\+cuda \+gdrcopy"/' -i "${CP2K_CONFIG_FILE}"
2026-02-28 10:52:41 +01:00
sed -E -e 's/"~cuda\s+~gdrcopy"/"\~cuda"/' -i " ${ CP2K_CONFIG_FILE } "
2026-02-22 19:51:33 +01:00
if [ [ -n " ${ CUDA_VERSION :- } " ] ] ; then
2026-02-27 13:51:52 +01:00
# Set CUDA SM code
2026-02-22 19:51:33 +01:00
sed -E -e " s/spec:\s+cuda@[.0-9]*/spec: cuda@ ${ CUDA_VERSION } / " -i " ${ CP2K_CONFIG_FILE } "
fi
if [ [ -n " ${ CUDA_HOME :- } " ] ] ; then
sed -E -e " s|prefix: /usr/local/cuda|prefix: ${ CUDA_HOME } | " -i " ${ CP2K_CONFIG_FILE } "
fi
2026-02-25 13:50:19 +01:00
else
sed -E -e 's/"~cuda\s+~gdrcopy"/"\~cuda"/' -i " ${ CP2K_CONFIG_FILE } "
2026-02-10 12:15:01 +01:00
fi
2026-07-06 16:12:20 +02:00
# CUDA is required for libgint is requested
if [ [ " ${ CMAKE_CUDA_FLAGS } " = = *"-DCP2K_USE_ACCEL=CUDA" * ] ] ; then
if [ [ " ${ CMAKE_FEATURE_FLAGS } " = = *"-DCP2K_USE_EVERYTHING=ON" * ] ] ||
[ [ " ${ CMAKE_FEATURE_FLAGS } " = = *"-DCP2K_USE_LIBGINT=ON" * ] ] ; then
sed -E \
-e '/\s*#\s*-\s+"libgint@/ s/#/ /' \
-i " ${ CP2K_CONFIG_FILE } "
fi
fi
2026-07-01 16:13:06 +02:00
# Activate OpenCL support if requested
if [ [ " ${ USE_OPENCL } " = = "yes" ] ] ; then
sed -E \
-e 's/"~opencl"/"+opencl"/' \
-e '/\s*#\s*-\s+"libxstream@/ s/#/ /' \
-i " ${ CP2K_CONFIG_FILE } "
fi
2026-02-22 08:55:25 +01:00
# Apply Cray specific adaptation of the spack configuration if requested (CSCS)
2026-02-01 18:50:49 +01:00
if [ [ " ${ CRAY } " = = "yes" ] ] ; then
2026-02-22 08:55:25 +01:00
sed -E \
2026-02-23 09:40:41 +01:00
-e '/\s*#\s*-\s+"netmod=ofi"/ s/#/ /' \
2026-02-22 08:55:25 +01:00
-e 's/~xpmem/+xpmem/' \
-e 's/"libfabric@[.0-9]*"/"libfabric@1.22.0"/' \
-i " ${ CP2K_CONFIG_FILE } "
2026-02-01 18:50:49 +01:00
fi
2026-02-16 08:14:16 +01:00
# Apply feature selection to spack configuration file
2026-02-17 16:58:55 +01:00
if [ [ -n " ${ SED_PATTERN_LIST } " ] ] ; then
eval sed -E " ${ SED_PATTERN_LIST } " -i " ${ CP2K_CONFIG_FILE } "
fi
2026-02-16 08:14:16 +01:00
2026-02-04 11:08:43 +01:00
# Find all compilers
2026-02-20 15:50:32 +01:00
echo "Searching for GCC compilers"
2026-02-17 16:58:55 +01:00
if ! spack compiler find & > /dev/null; then
2026-02-04 11:08:43 +01:00
echo "ERROR: The compiler detection of spack failed"
${ EXIT_CMD } 1
fi
2026-02-20 15:50:32 +01:00
spack compiler list
2026-02-04 11:08:43 +01:00
# Retrieve the newest compiler version found by spack
2026-07-08 18:39:19 +08:00
GCC_VERSION_NEWEST = " $( spack compilers | sed -nE 's/.*gcc@([0-9]+(\.[0-9]+)*).*/\1/p' | sort -V | tail -n 1) "
2026-02-04 11:08:43 +01:00
echo " The newest GCC compiler version found by spack is ${ GCC_VERSION_NEWEST } "
2026-02-17 16:58:55 +01:00
GCC_VERSION_NEWEST = " $( echo " ${ GCC_VERSION_NEWEST } " | sed -E -e 's/.*@([0-9]+).*/\1/' | cut -d. -f1) "
2026-02-04 11:08:43 +01:00
# Check if the newest compiler version found on the host system is new enough
GCC_VERSION_MINIMUM = "10"
if ( ( GCC_VERSION_NEWEST < GCC_VERSION_MINIMUM) ) ; then
echo " INFO: The newest GCC compiler version ${ GCC_VERSION_NEWEST } is too old, "
echo " because at least version ${ GCC_VERSION_MINIMUM } is required "
GCC_VERSION = "14"
echo " INFO: The lastest stable GCC version ${ GCC_VERSION } will be built and used by spack "
fi
2026-02-04 13:28:23 +01:00
# Add a specific GCC version to the spack configuration if requested
if [ [ " ${ GCC_VERSION } " = = "auto" ] ] ; then
echo "Spack will automatically select the GCC version which is not necessarily the newest one found"
else
sed -E -e " s/gcc@10:/gcc@ ${ GCC_VERSION } / " -i " ${ CP2K_CONFIG_FILE } "
2026-02-04 11:08:43 +01:00
fi
2026-03-11 17:21:29 +01:00
# Disable PEXSI because of an issue with SuperLU using GCC version 15
if ( ( CUDA_SM_CODE > 0) ) || ( ( GCC_VERSION_NEWEST > 14) ) ; then
2026-02-08 21:54:23 +01:00
sed -E -e '/\s*-\s+"pexsi@/ s/^ /#/' -i " ${ CP2K_CONFIG_FILE } "
2026-02-15 10:55:18 +01:00
echo "INFO: PEXSI has been disabled because CUDA or GCC 15 is used"
2026-02-08 21:54:23 +01:00
fi
2026-01-27 18:12:08 +01:00
# Create CP2K environment if needed
2026-01-09 10:24:07 +01:00
if spack env list | grep -q " ${ CP2K_ENV } " ; then
2026-07-01 22:31:07 +08:00
echo " The Spack environment \" ${ CP2K_ENV } \" exists already "
2026-01-09 10:24:07 +01:00
else
2026-02-12 11:24:17 +01:00
cat " ${ CP2K_CONFIG_FILE } "
2026-01-22 11:13:28 +01:00
echo " The Spack environment \" ${ CP2K_ENV } \" does NOT exist "
2026-01-28 13:30:15 +01:00
if spack env create " ${ CP2K_ENV } " " ${ CP2K_CONFIG_FILE } " & > /dev/null; then
echo " The Spack environment \" ${ CP2K_ENV } \" has been created "
else
2026-01-27 18:12:08 +01:00
echo " ERROR: The creation of the Spack environment \" ${ CP2K_ENV } \" failed "
${ EXIT_CMD } 1
fi
fi
# Activate CP2K environment if needed
2026-01-28 13:30:15 +01:00
if spack env activate " ${ CP2K_ENV } " & > /dev/null; then
2026-01-27 18:12:08 +01:00
echo " The Spack environment \" ${ CP2K_ENV } \" has been activated "
else
echo " ERROR: The activation of the Spack environment \" ${ CP2K_ENV } \" failed "
${ EXIT_CMD } 1
2026-01-09 10:24:07 +01:00
fi
2026-02-12 17:37:55 +01:00
# Update the repo builtin
if ! spack repo update; then
echo "ERROR: The update of the repo builtin failed"
${ EXIT_CMD } 1
2026-01-09 10:24:07 +01:00
fi
# Add the local CP2K development Spack repository when missing
export CP2K_REPO = "cp2k_dev"
if ! spack repo list | grep -q " ${ CP2K_REPO } " ; then
2026-01-21 11:01:04 +01:00
spack repo add --scope " env: ${ CP2K_ENV } " " ${ CP2K_ROOT } /tools/spack/spack_repo/ ${ CP2K_REPO } "
2026-01-09 10:24:07 +01:00
else
echo " The CP2K development repo ${ CP2K_REPO } is already present ... skipping add "
fi
spack -e ${ CP2K_ENV } repo list
# Find all external packages
2026-01-22 11:13:28 +01:00
if [ [ " ${ USE_EXTERNALS } " = = "yes" ] ] ; then
2026-02-17 15:26:03 +01:00
if ! spack -C " ${ SPACK_USER_CONFIG_PATH } " external find; then
2026-01-27 18:12:08 +01:00
echo -e "\nERROR: The detection of externals by spack failed"
2026-01-22 11:13:28 +01:00
${ EXIT_CMD } 1
fi
2026-02-04 13:28:23 +01:00
# Concretize CP2K dependencies
2026-07-08 18:39:19 +08:00
if ! spack -e " ${ CP2K_ENV } " concretize --fresh --jobs " ${ NUM_PROCS } " ; then
2026-02-04 13:28:23 +01:00
echo -e " \nERROR: The spack concretize for environment \" ${ CP2K_ENV } \" failed "
2026-01-30 10:47:23 +01:00
echo ""
echo "HINT: The (-ue | --use_externals) flags can cause conflicts with outdated"
echo " packages on the host system, e.g. old python or gcc versions"
echo ""
2026-02-04 13:28:23 +01:00
${ EXIT_CMD } 1
fi
else
2026-02-07 13:12:03 +01:00
# If the installation of a specific GCC version for building CP2K is requested,
# then an installation of the same GCC version on the host system has to be removed
# from the configuration for a static build of CP2K
if [ [ " ${ CP2K_VERSION } " = = *"-static" ] ] ; then
2026-02-07 15:34:19 +01:00
if spack compilers | grep -q " gcc@ ${ GCC_VERSION } " ; then
echo " INFO: A static build of CP2K with GCC ${ GCC_VERSION } is requested without using "
echo " any externals which requires to build that GCC version with spack"
echo " while removing a gcc@ ${ GCC_VERSION } installed on the host from the spack "
echo " configuration at the same time"
if ! spack compiler remove " gcc@ ${ GCC_VERSION } " ; then
echo -e " \nERROR: Removing the gcc@ ${ GCC_VERSION } compiler failed "
${ EXIT_CMD } 1
2026-05-22 15:05:42 +02:00
else
echo -e " \nINFO: gcc@ ${ GCC_VERSION } compiler removed "
2026-02-07 15:34:19 +01:00
fi
2026-05-22 15:05:42 +02:00
spack compiler list
2026-02-07 13:12:03 +01:00
fi
fi
2026-07-08 18:39:19 +08:00
if ! spack -e " ${ CP2K_ENV } " concretize --fresh --jobs " ${ NUM_PROCS } " ; then
2026-02-04 13:28:23 +01:00
echo -e " \nERROR: The spack concretize for environment \" ${ CP2K_ENV } \" failed "
${ EXIT_CMD } 1
2026-01-30 10:47:23 +01:00
fi
2026-01-22 11:13:28 +01:00
fi
2026-02-04 14:49:49 +01:00
( ( VERBOSE > 0) ) && spack find -c
2026-02-04 13:28:23 +01:00
2026-01-09 10:24:07 +01:00
# Install CP2K dependencies via Spack
2026-07-08 18:39:19 +08:00
if ! spack -e " ${ CP2K_ENV } " install -j " ${ NUM_PROCS } " -p " ${ NUM_PACKAGES } " " ${ VERBOSE_SPACK } " ; then
2026-01-22 11:13:28 +01:00
echo "ERROR: Building the CP2K dependencies with spack failed"
2026-01-25 11:04:01 +01:00
if [ [ " ${ USE_EXTERNALS } " = = "yes" ] ] ; then
2026-02-26 22:32:29 +01:00
echo "HINT: Try to re-run the build without the (-ue | --use_externals) flag which avoids"
echo " errors or conflicts caused by externals from the host system"
2026-01-25 11:04:01 +01:00
fi
2026-01-22 11:13:28 +01:00
${ EXIT_CMD } 1
fi
2026-01-09 10:24:07 +01:00
2026-02-04 16:59:36 +01:00
# Find all compilers
if ! spack compiler find; then
echo "ERROR: The compiler detection of spack failed"
${ EXIT_CMD } 1
fi
2026-02-15 07:31:18 +01:00
# Fix Libs list in elpa pkg-config file when CUDA is used
2026-02-27 13:51:52 +01:00
if ( ( CUDA_SM_CODE > 0) ) ; then
2026-02-15 07:31:18 +01:00
ELPA_PKG_CONFIG_FILE = " $( find -L " ${ SPACK_ROOT } /opt/spack/view " -name "elpa*.pc" ) "
if [ [ -f " ${ ELPA_PKG_CONFIG_FILE } " ] ] ; then
sed -E -e 's|Libs: |Libs: -L/usr/local/cuda/lib64 |' -i " ${ ELPA_PKG_CONFIG_FILE } "
fi
fi
2026-01-29 17:12:11 +01:00
# Return from spack folder after all installations are done
cd " ${ CP2K_ROOT } " || ${ EXIT_CMD } 1
2026-02-02 13:36:18 +01:00
# Make a note of the successful build
touch " ${ SPACK_BUILD_PATH } /BUILD_DEPENDENCIES_COMPLETED "
2026-01-29 17:12:11 +01:00
echo -e '\n*** Installation of CP2K dependencies completed ***\n'
2026-01-09 10:24:07 +01:00
else
# Initialize Spack shell hooks
2026-01-28 18:10:13 +01:00
# shellcheck source=/dev/null
2026-01-09 11:16:14 +01:00
source " ${ SPACK_ROOT } " /share/spack/setup-env.sh
2026-01-09 10:24:07 +01:00
fi
2026-01-29 17:12:11 +01:00
# Quit after (re)building all CP2K dependencies if requested
if [ [ " ${ BUILD_DEPS_ONLY } " = = "yes" ] ] ; then
${ EXIT_CMD }
fi
2026-01-09 10:24:07 +01:00
### End of build CP2K dependencies ###
### Build CP2K ###
2026-01-29 17:12:11 +01:00
if spack env list | grep -q " ${ CP2K_ENV } " ; then
spack env list
else
2026-01-27 18:12:08 +01:00
echo " ERROR: No Spack environment \" ${ CP2K_ENV } \" found "
${ EXIT_CMD } 1
fi
# Activate spack environment
2026-02-04 16:59:36 +01:00
eval " $( spack env activate --sh ${ CP2K_ENV } ) "
2026-01-09 10:24:07 +01:00
2026-01-29 17:12:11 +01:00
spack env status
2026-01-09 10:24:07 +01:00
# CMake configuration step
2026-06-28 22:19:02 +02:00
export CMAKE_BUILD_PATH = " ${ BUILD_PATH } /build "
2026-01-09 10:24:07 +01:00
# PyTorch's TorchConfig.cmake is buried in the Python site-packages directory
2026-01-09 11:16:14 +01:00
Torch_DIR = " $( dirname " $( find " ${ SPACK_ROOT } " ! -type l -name TorchConfig.cmake | tail -n 1) " ) "
export Torch_DIR
2026-01-09 10:24:07 +01:00
2026-02-08 21:54:23 +01:00
# Check if PEXSI was built
2026-02-10 09:34:58 +01:00
if [ [ " ${ MPI_MODE } " != "no" ] ] ; then
2026-03-03 17:54:40 +01:00
CP2K_USE_PEXSI = " $( grep -Eq '\s*#\s*-\s+"pexsi@' " ${ CP2K_CONFIG_FILE } " && echo OFF || echo ON) "
2026-02-10 09:34:58 +01:00
else
CP2K_USE_PEXSI = "ON"
fi
2026-02-08 21:54:23 +01:00
export CP2K_USE_PEXSI
2026-01-09 11:16:14 +01:00
if [ [ ! -d " ${ CMAKE_BUILD_PATH } " ] ] ; then
mkdir -p " ${ CMAKE_BUILD_PATH } "
2026-01-09 10:24:07 +01:00
case " ${ CP2K_VERSION } " in
2026-03-03 17:54:40 +01:00
pdbg | psmp)
2026-02-10 19:00:08 +01:00
# shellcheck disable=SC2086
2026-01-09 11:16:14 +01:00
cmake -S " ${ CP2K_ROOT } " -B " ${ CMAKE_BUILD_PATH } " \
2026-01-09 10:24:07 +01:00
-GNinja \
2026-03-25 13:47:09 +01:00
-DBUILD_SHARED_LIBS= ${ BUILD_SHARED_LIBS } \
2026-03-03 17:54:40 +01:00
-DCMAKE_BUILD_TYPE= " ${ CP2K_BUILD_TYPE } " \
2026-01-09 10:24:07 +01:00
-DCMAKE_INSTALL_PREFIX= " ${ INSTALL_PREFIX } " \
-DCMAKE_INSTALL_MESSAGE= " ${ INSTALL_MESSAGE } " \
2026-03-25 13:47:09 +01:00
-DCMAKE_SKIP_RPATH= "ON" \
2026-01-09 10:24:07 +01:00
-DCMAKE_VERBOSE_MAKEFILE= " ${ VERBOSE_MAKEFILE } " \
2026-02-16 08:14:16 +01:00
${ CMAKE_FEATURE_FLAGS } \
2026-02-08 21:54:23 +01:00
-DCP2K_USE_PEXSI= " ${ CP2K_USE_PEXSI } " \
2026-02-10 19:00:08 +01:00
${ CMAKE_CUDA_FLAGS } \
2026-01-09 11:16:14 +01:00
-Werror= dev | &
tee " ${ CMAKE_BUILD_PATH } /cmake.log "
2026-01-21 11:01:04 +01:00
EXIT_CODE = $?
2026-01-09 10:24:07 +01:00
; ;
2026-03-03 17:54:40 +01:00
sdbg | ssmp)
2026-02-10 19:00:08 +01:00
# shellcheck disable=SC2086
2026-01-09 11:16:14 +01:00
cmake -S " ${ CP2K_ROOT } " -B " ${ CMAKE_BUILD_PATH } " \
2026-01-09 10:24:07 +01:00
-GNinja \
2026-03-25 13:47:09 +01:00
-DBUILD_SHARED_LIBS= ${ BUILD_SHARED_LIBS } \
2026-03-03 17:54:40 +01:00
-DCMAKE_BUILD_TYPE= " ${ CP2K_BUILD_TYPE } " \
2026-01-09 10:24:07 +01:00
-DCMAKE_INSTALL_PREFIX= " ${ INSTALL_PREFIX } " \
-DCMAKE_INSTALL_MESSAGE= " ${ INSTALL_MESSAGE } " \
2026-03-25 13:47:09 +01:00
-DCMAKE_SKIP_RPATH= "ON" \
2026-01-09 10:24:07 +01:00
-DCMAKE_VERBOSE_MAKEFILE= " ${ VERBOSE_MAKEFILE } " \
2026-02-16 08:14:16 +01:00
${ CMAKE_FEATURE_FLAGS } \
2026-02-10 19:00:08 +01:00
${ CMAKE_CUDA_FLAGS } \
2026-01-09 11:16:14 +01:00
-Werror= dev | &
tee " ${ CMAKE_BUILD_PATH } /cmake.log "
2026-01-21 11:01:04 +01:00
EXIT_CODE = $?
2026-01-09 10:24:07 +01:00
; ;
2026-03-11 15:32:57 +01:00
ssmp-static)
2026-02-07 13:12:03 +01:00
# Find some static libraries in advance
LIBOPENBLAS = $( find -L " ${ SPACK_ROOT } " /opt/spack/view -name libopenblas.a)
LIBM = " $( find /usr -name libm.a 2> /dev/null) "
2026-02-25 10:27:33 +01:00
# shellcheck disable=SC2086
2026-02-07 13:12:03 +01:00
cmake -S " ${ CP2K_ROOT } " -B " ${ CMAKE_BUILD_PATH } " \
-GNinja \
2026-03-25 13:47:09 +01:00
-DBUILD_SHARED_LIBS= "OFF" \
2026-03-03 17:54:40 +01:00
-DCMAKE_BUILD_TYPE= " ${ CP2K_BUILD_TYPE } " \
2026-02-07 13:12:03 +01:00
-DCMAKE_EXE_LINKER_FLAGS= "-static" \
-DCMAKE_FIND_LIBRARY_SUFFIXES= ".a" \
-DCMAKE_INSTALL_PREFIX= " ${ INSTALL_PREFIX } " \
-DCMAKE_INSTALL_MESSAGE= " ${ INSTALL_MESSAGE } " \
2026-03-25 13:47:09 +01:00
-DCMAKE_SKIP_RPATH= "ON" \
2026-02-07 13:12:03 +01:00
-DCMAKE_VERBOSE_MAKEFILE= " ${ VERBOSE_MAKEFILE } " \
-DCP2K_BLAS_LINK_LIBRARIES= " ${ LIBOPENBLAS } ; ${ LIBM } " \
-DCP2K_LAPACK_LINK_LIBRARIES= " ${ LIBOPENBLAS } ; ${ LIBM } " \
2026-02-25 10:27:33 +01:00
${ CMAKE_FEATURE_FLAGS } \
2026-02-07 13:12:03 +01:00
-Werror= dev | &
tee " ${ CMAKE_BUILD_PATH } /cmake.log "
EXIT_CODE = $?
# It is almost impossible to avoid that shared libraries are pulled in
# when the CP2K dependencies are built and thus just change all shared
# to static libraries hoping that these are also available
sed -E -e "s/\.so/.a/g" -i build/build.ninja
; ;
2026-01-09 10:24:07 +01:00
*)
echo " ERROR: Unknown CP2K version ${ CP2K_VERSION } specified "
${ EXIT_CMD } 1
; ;
esac
2026-01-22 15:50:50 +01:00
if ( ( EXIT_CODE != 0) ) ; then
echo " ERROR: The CMake configuration step failed with the error code ${ EXIT_CODE } "
2026-02-04 16:20:27 +01:00
echo " You can try to remove the build folder with 'rm -rf build' and re-run"
2026-02-02 13:36:18 +01:00
echo " or even start the whole CP2K installation from scratch with the \"-bd\" flag"
2026-01-22 15:50:50 +01:00
${ EXIT_CMD } " ${ EXIT_CODE } "
fi
2026-01-21 11:01:04 +01:00
fi
2026-01-09 10:24:07 +01:00
# CMake build step
echo -e '\n*** Compiling CP2K ***\n'
2026-01-22 17:28:20 +01:00
cmake --build " ${ CMAKE_BUILD_PATH } " --parallel " ${ NUM_PROCS } " -- " ${ VERBOSE_FLAG } " | & tee " ${ CMAKE_BUILD_PATH } " /ninja.log
EXIT_CODE = ${ PIPESTATUS [0] }
if ( ( EXIT_CODE != 0) ) ; then
2026-01-21 11:01:04 +01:00
echo " ERROR: The CMake build step failed with the error code ${ EXIT_CODE } "
${ EXIT_CMD } " ${ EXIT_CODE } "
fi
2026-01-09 10:24:07 +01:00
# CMake install step
echo -e '\n*** Installing CP2K ***\n'
2026-01-22 17:28:20 +01:00
cmake --install " ${ CMAKE_BUILD_PATH } " | & tee " ${ CMAKE_BUILD_PATH } " /install.log
EXIT_CODE = ${ PIPESTATUS [0] }
if ( ( EXIT_CODE != 0) ) ; then
2026-01-27 18:12:08 +01:00
echo -e " \nERROR: The CMake installation step failed with the error code ${ EXIT_CODE } "
2026-01-21 11:01:04 +01:00
${ EXIT_CMD } " ${ EXIT_CODE } "
fi
2026-01-09 10:24:07 +01:00
2026-06-03 17:24:08 +02:00
# Install Skala resource files if needed
export GAUXC_SKALA_MODEL = "(not available)"
2026-07-01 08:48:46 +02:00
if spack location -i gauxc & > /dev/null; then
GAUXC_PATH = "share/gauxc/onedft_models"
GAUXC_PREFIX = " $( spack location -i gauxc) "
GAUXC_MODEL_SOURCE_PATH = " ${ GAUXC_PREFIX %/ } / ${ GAUXC_PATH } "
if [ [ -d " ${ GAUXC_MODEL_SOURCE_PATH } " ] ] ; then
GAUXC_MODEL_TARGET_PATH = " ${ INSTALL_PREFIX %/ } / ${ GAUXC_PATH } "
mkdir -p " ${ GAUXC_MODEL_TARGET_PATH } "
if compgen -G " ${ GAUXC_MODEL_SOURCE_PATH } /*.fun " > /dev/null; then
cp " ${ GAUXC_MODEL_SOURCE_PATH } " /*.fun " ${ GAUXC_MODEL_TARGET_PATH } / "
else
echo -e " \nERROR: No GauXC model files found in source folder ${ GAUXC_MODEL_SOURCE_PATH } "
${ EXIT_CMD } 1
fi
shopt -s nullglob
MATCHES = ( " ${ GAUXC_MODEL_TARGET_PATH } " /skala*)
shopt -u nullglob
if ( ( ${# MATCHES [@] } > 0) ) ; then
export GAUXC_SKALA_MODEL = " ${ MATCHES [ ${# MATCHES [@] } - 1] } "
else
echo -e " \nERROR: Failed to resolve GAUXC_SKALA_MODEL in target path ${ GAUXC_MODEL_TARGET_PATH } "
${ EXIT_CMD } 1
fi
2026-06-03 17:24:08 +02:00
fi
fi
echo -e " \nGAUXC_SKALA_MODEL = ${ GAUXC_SKALA_MODEL } "
2026-01-29 17:12:11 +01:00
# Collect and compress all log files when building within a container
if [ [ " ${ IN_CONTAINER } " = = "yes" ] ] ; then
if ! cat " ${ CMAKE_BUILD_PATH } " /cmake.log \
" ${ CMAKE_BUILD_PATH } " /ninja.log \
" ${ CMAKE_BUILD_PATH } " /install.log |
gzip > " ${ CP2K_ROOT } " /install/build_cp2k.log.gz; then
echo -e "\nERROR: The compressed log file generation failed"
${ EXIT_CMD } 1
fi
fi
2026-02-07 13:12:03 +01:00
# Cut extension from the CP2K version (e.g. ssmp-static -> ssmp)
export VERSION = ${ CP2K_VERSION %%-* }
2026-02-20 15:50:32 +01:00
# Add CP2K lib folder to the LD_LIBRARY_PATH
export LD_LIBRARY_PATH = " ${ INSTALL_PREFIX } /lib: ${ LD_LIBRARY_PATH } "
2026-02-16 17:51:39 +01:00
2026-02-20 15:50:32 +01:00
# Assemble search paths for libraries
search_paths = " ${ SPACK_ROOT } /opt/spack/view ${ INSTALL_PREFIX } /lib "
# Retrieve paths to all libraries needed by the CP2k binary
2026-02-20 18:40:50 +01:00
for library in $( readelf -d " ${ INSTALL_PREFIX } /bin/cp2k. ${ VERSION } " " ${ INSTALL_PREFIX } " /lib/libcp2k.* | awk '/NEEDED/{print $5}' | tr -d '[]' | sort | uniq) ; do
2026-02-20 15:50:32 +01:00
# Search for missing library path
if ! ldconfig -p | grep -qE " / ${ library } $" ; then
2026-02-10 19:00:08 +01:00
# shellcheck disable=SC2086
2026-02-20 15:50:32 +01:00
library_with_path = $( find -L ${ search_paths } -name " ${ library } " | tail -n 1)
if [ [ -n " ${ library_with_path } " ] ] ; then
library_path = " $( dirname " ${ library_with_path } " ) "
2026-01-09 10:24:07 +01:00
case " : ${ LD_LIBRARY_PATH } : " in
*" : ${ library_path } : " *)
2026-02-20 15:50:32 +01:00
( ( VERBOSE > 1) ) && echo " The library path ${ library_path } is already present ... skipping "
2026-01-09 10:24:07 +01:00
; ;
*)
LD_LIBRARY_PATH = " ${ LD_LIBRARY_PATH : + ${ LD_LIBRARY_PATH } : } ${ library_path } "
2026-02-20 15:50:32 +01:00
( ( VERBOSE > 0) ) && echo " The library path ${ library_path } was appended to LD_LIBRARY_PATH "
2026-01-09 10:24:07 +01:00
; ;
esac
fi
fi
2026-02-20 15:50:32 +01:00
done
export LD_LIBRARY_PATH
echo -e " \nLD_LIBRARY_PATH = \" ${ LD_LIBRARY_PATH } \" "
# Create an ld configuration file for CP2K because LD_LIBRARY_PATH is fragile
if [ [ " ${ IN_CONTAINER } " = = "yes" ] ] ; then
CP2K_LD_CONF_FILE = "/etc/ld.so.conf.d/cp2k.conf"
else
CP2K_LD_CONF_FILE = " ${ INSTALL_PREFIX } /bin/cp2k.conf "
fi
# Either read LD_LIBRARY_PATH from an existing configuration file or write a new one
if [ [ -f " ${ CP2K_LD_CONF_FILE } " ] ] ; then
# Load LD_LIBRARY_PATH from an existing configuration file
LD_LIBRARY_PATH = " $( grep -E '^/' " ${ CP2K_LD_CONF_FILE } " | paste -sd ':' -) "
else
# Write LD_LIBRARY_PATH to a new configuration file
echo " ${ LD_LIBRARY_PATH } " | tr ':' '\n' | grep '^/' > " ${ CP2K_LD_CONF_FILE } "
2026-01-09 10:24:07 +01:00
fi
2026-02-20 15:50:32 +01:00
2026-01-24 15:26:39 +01:00
export LD_LIBRARY_PATH
2026-01-09 10:24:07 +01:00
2026-01-27 18:12:08 +01:00
# Create links to CP2K binaries
cd " ${ INSTALL_PREFIX } " /bin || ${ EXIT_CMD } 1
2026-02-07 13:12:03 +01:00
for binary in *." ${ VERSION } " ; do
if ! ln -sf " ${ binary } " " ${ binary %%. " ${ VERSION } " } " ; then
2026-02-03 11:41:04 +01:00
echo " ERROR: The creation of a symbolic link for the binary ${ binary } failed "
${ EXIT_CMD }
fi
done
2026-02-07 13:12:03 +01:00
ln -sf cp2k." ${ VERSION } " cp2k_shell
2026-01-27 18:12:08 +01:00
cd " ${ CP2K_ROOT } " || ${ EXIT_CMD } 1
2026-07-02 22:08:38 +08:00
# Configure Open MPI environment for local CP2K runs
2026-02-25 22:50:05 +08:00
if [ [ " ${ MPI_MODE } " = = "openmpi" ] ] ; then
2026-07-02 22:08:38 +08:00
OMPI_VARS = "export OMPI_MCA_plm_rsh_agent=/bin/false PRTE_MCA_hwloc_default_binding_policy=none"
2026-03-24 17:00:35 +08:00
if [ [ " ${ IN_CONTAINER } " = = "yes" ] ] ; then
2026-07-02 22:08:38 +08:00
OMPI_VARS = " ${ OMPI_VARS } OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 "
2026-03-24 17:00:35 +08:00
OMPI_VARS = " ${ OMPI_VARS } OMPI_MCA_mpi_yield_when_idle=1 OMPI_MCA_btl=self,sm OMPI_MCA_pml=ob1 "
fi
2026-02-26 17:32:47 +08:00
else
OMPI_VARS = ""
2026-02-03 11:41:04 +01:00
fi
2026-02-09 15:29:23 +01:00
export OMPI_VARS
2026-02-03 11:41:04 +01:00
# MPICH and OpenMPI have different flags for exporting environment variables to MPI ranks
if [ [ " ${ MPI_MODE } " = = "openmpi" ] ] ; then
ENV_VAR_FLAG = "-x"
else
ENV_VAR_FLAG = "-genv"
2026-01-27 18:12:08 +01:00
fi
2026-02-09 15:29:23 +01:00
export ENV_VAR_FLAG
2026-01-27 18:12:08 +01:00
2026-03-03 17:54:40 +01:00
# Install LSAN suppressions (only needed for dbg binaries)
cp " ${ CP2K_ROOT } " /tools/spack/lsan.supp " ${ INSTALL_PREFIX } " /bin
2026-01-27 18:12:08 +01:00
# Assemble flags for running the regression tests
2026-01-09 10:24:07 +01:00
TESTOPTS = " --cp2kdatadir ${ INSTALL_PREFIX } /share/cp2k/data --maxtasks ${ NUM_PROCS } --workbasedir ${ INSTALL_PREFIX } /regtesting ${ TESTOPTS } "
2026-02-09 15:29:23 +01:00
export TESTOPTS
2026-01-27 18:12:08 +01:00
2026-02-09 15:29:23 +01:00
# Create launch script for environment setup
LAUNCH_SCRIPT = " ${ INSTALL_PREFIX } " /bin/launch
export LAUNCH_SCRIPT
cat << *** > " ${ LAUNCH_SCRIPT } "
2026-01-27 18:12:08 +01:00
#!/bin/bash
ulimit -c 0 -s unlimited
2026-04-24 11:31:27 +02:00
export ASAN_OPTIONS = "detect_leaks=1"
export LSAN_OPTIONS = " suppressions= ${ INSTALL_PREFIX } /bin/lsan.supp "
2026-01-27 18:12:08 +01:00
export PATH = ${ INSTALL_PREFIX } /bin:${ PATH }
2026-02-16 17:51:39 +01:00
export LD_LIBRARY_PATH = ${ LD_LIBRARY_PATH }
2026-02-22 08:55:25 +01:00
export OMP_NUM_THREADS = \$ { OMP_NUM_THREADS:-2}
2026-02-20 15:50:32 +01:00
export OMP_STACKSIZE = 256M
2026-02-03 11:41:04 +01:00
${ OMPI_VARS }
2026-06-03 17:24:08 +02:00
export GAUXC_SKALA_MODEL = ${ GAUXC_SKALA_MODEL }
2026-02-03 11:41:04 +01:00
exec "\$@"
2026-01-27 18:12:08 +01:00
***
2026-02-09 15:29:23 +01:00
chmod 750 " ${ LAUNCH_SCRIPT } "
2026-01-27 18:12:08 +01:00
# Create shortcut for launching the regression tests
2026-02-03 11:41:04 +01:00
cat << *** > " ${ INSTALL_PREFIX } " /bin/run_tests
2026-04-24 11:31:27 +02:00
#!/bin/bash
if [ [ " ${ VERSION } " = ~ ^( s| p) dbg$ ] ] ; then
echo "ASAN_OPTIONS = \${ASAN_OPTIONS}"
echo "LSAN_OPTIONS = \${LSAN_OPTIONS}"
fi
2026-02-13 17:12:42 +01:00
ldd -- ${ INSTALL_PREFIX } /bin/cp2k.${ VERSION } 2>& 1 | grep -E 'not ' | sort | uniq
2026-06-03 17:24:08 +02:00
export GAUXC_SKALA_MODEL = ${ GAUXC_SKALA_MODEL }
2026-02-07 13:12:03 +01:00
${ CP2K_ROOT } /tests/do_regtest.py ${ TESTOPTS } \$ * ${ INSTALL_PREFIX } /bin ${ VERSION }
2026-01-09 10:24:07 +01:00
***
2026-01-27 18:12:08 +01:00
chmod 750 " ${ INSTALL_PREFIX } " /bin/run_tests
2026-01-09 10:24:07 +01:00
2026-04-24 11:31:27 +02:00
# Set image tag if available
export IMAGE_TAG = ${ IMAGE_TAG :- <IMAGE ID> }
2026-01-09 10:24:07 +01:00
# Optionally, launch test run
if [ [ " ${ RUN_TEST } " = = "yes" ] ] ; then
echo -e " \n*** Launching regression test run using the script ${ INSTALL_PREFIX } /bin/run_tests\n "
2026-02-09 15:29:23 +01:00
${ LAUNCH_SCRIPT } run_tests
2026-01-21 11:01:04 +01:00
EXIT_CODE = $?
if ( ( EXIT_CODE != 0) ) ; then
echo " ERROR: The regression test run failed with the error code ${ EXIT_CODE } "
${ EXIT_CMD } " ${ EXIT_CODE } "
fi
2026-01-09 10:24:07 +01:00
else
2026-02-03 11:41:04 +01:00
if [ [ " ${ IN_CONTAINER } " = = "yes" ] ] ; then
2026-02-27 13:51:52 +01:00
if ( ( CUDA_SM_CODE > 0) ) ; then
2026-02-20 15:50:32 +01:00
DEVICE_FLAG = " --device nvidia.com/gpu=all"
else
DEVICE_FLAG = ""
fi
2026-02-03 11:41:04 +01:00
echo ""
echo "*** A regression test run can be launched with"
2026-04-24 11:31:27 +02:00
echo " podman run -it ${ DEVICE_FLAG } --rm ${ IMAGE_TAG } run_tests "
2026-02-03 11:41:04 +01:00
echo ""
2026-05-05 14:24:47 +02:00
if [ [ " ${ VERSION } " = = @( sdbg| ssmp) ] ] ; then
2026-05-06 09:56:12 +02:00
echo "*** A CP2K run using 2 OpenMP threads (default) can be launched with"
2026-04-24 11:31:27 +02:00
echo " podman run -it ${ DEVICE_FLAG } --rm ${ IMAGE_TAG } cp2k ${ CP2K_ROOT } /benchmarks/CI/H2O-32_md.inp "
2026-02-03 11:41:04 +01:00
else
echo "*** An MPI-parallel CP2K run using 2 OpenMP threads for each of the 4 MPI ranks can be launched with"
2026-04-24 11:31:27 +02:00
echo " podman run -it ${ DEVICE_FLAG } --rm ${ IMAGE_TAG } mpiexec -n 4 ${ ENV_VAR_FLAG } OMP_NUM_THREADS=2 cp2k ${ CP2K_ROOT } /benchmarks/CI/H2O-32_md.inp "
2026-02-03 11:41:04 +01:00
fi
echo ""
else
echo ""
echo "*** A regression test run can be launched with"
2026-02-10 09:34:58 +01:00
echo " ${ LAUNCH_SCRIPT } run_tests "
2026-02-03 11:41:04 +01:00
echo ""
2026-05-05 14:24:47 +02:00
if [ [ " ${ VERSION } " = = @( sdbg| ssmp) ] ] ; then
echo "*** A CP2K run using 2 OpenMP threads (default) can be launched with"
2026-02-09 15:29:23 +01:00
echo " ${ LAUNCH_SCRIPT } cp2k ${ CP2K_ROOT } /benchmarks/CI/H2O-32_md.inp "
2026-02-03 11:41:04 +01:00
echo ""
echo "*** A CP2K run using only 4 OpenMP threads can be launched with"
2026-02-09 15:29:23 +01:00
echo " export OMP_NUM_THREADS=4; ${ LAUNCH_SCRIPT } cp2k ${ CP2K_ROOT } /benchmarks/CI/H2O-32_md.inp "
2026-02-03 11:41:04 +01:00
else
echo "*** An MPI-parallel CP2K run using 2 OpenMP threads for each of the 4 MPI ranks can be launched with"
2026-02-26 18:03:05 +01:00
echo " export OMP_NUM_THREADS=2; ${ LAUNCH_SCRIPT } mpiexec -n 4 cp2k ${ CP2K_ROOT } /benchmarks/CI/H2O-32_md.inp "
2026-02-03 11:41:04 +01:00
fi
echo ""
fi
2026-01-09 10:24:07 +01:00
fi