diff --git a/.gitignore b/.gitignore index 36454ff..e69de29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +0,0 @@ -/install/ -/build/ -!/scripts/ - -.DS_Store diff --git a/generic_install.sh b/generic_install.sh deleted file mode 100644 index 3096606..0000000 --- a/generic_install.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -BUILD_LOCATION=/avfs/backend -INSTALL_LOCATION=/avfs/projects/ops -mkdir -p ${BUILD_LOCATION} -mkdir -p ${INSTALL_LOCATION} - -## INSTALL ${PROGRAM} FROM SOURCE -PROGRAM_BUILD_DIR=${BUILD_LOCATION}/${PROGRAM} -PROGRAM_INSTALL_DIR=${INSTALL_LOCATION}/${PROGRAM} -mkdir -p ${PROGRAM_BUILD_DIR} -mkdir -p ${PROGRAM_INSTALL_DIR} - -PROGRAM_VERSION=1.1.1w - -cd ${PROGRAM_BUILD_DIR} -wget -c [website] -tar -xf ${PROGRAM}-${PROGRAM_VERSION}.tar.gz -cd ${PROGRAM}-${PROGRAM_VERSION} -mkdir build && cd build -../config --prefix=${PROGRAM_INSTALL_DIR}/${PROGRAM_VERSION} -make -j$(nproc) -make -j$(nproc) test -make install \ No newline at end of file diff --git a/install_script.sh b/install_script.sh deleted file mode 100644 index 8cc3e7e..0000000 --- a/install_script.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -# ------------------------------------------------------------------------ -# PACKAGE LIST: register all new dependent tools and libs here. Order -# is important, the first in the list gets installed first -# ------------------------------------------------------------------------ -tool_list="gcc intel cmake" -mpi_list="mpich openmpi intelmpi" -math_list="mkl acml openblas" -lib_list="fftw libint libxc libgrpp libxsmm cosma scalapack elpa cusolvermp plumed \ - spfft spla ptscotch superlu pexsi quip gsl spglib hdf5 libvdwxc sirius - libvori libtorch deepmd" -package_list="${tool_list} ${mpi_list} ${math_list} ${lib_list}" -# ------------------------------------------------------------------------ - -# first set everything to __DONTUSE__ -for ii in ${package_list}; do - eval with_${ii}="__DONTUSE__" -done - -# ------------------------------------------------------------------------ -# Work out default settings -# ------------------------------------------------------------------------ - -# tools to turn on by default: -with_gcc="__SYSTEM__" - -if [ "COMPILER" = intel ]; then - ./install_intel.sh -elif [ "COMPILER" = llvm ]; then - ./install_llvm.sh -elif [ "COMPILER" = clang]; then - ./install_llvm.sh -else - ./install_gcc.sh -fi - - diff --git a/install_toolchain.sh b/install_toolchain.sh new file mode 100755 index 0000000..9c488ed --- /dev/null +++ b/install_toolchain.sh @@ -0,0 +1,1011 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")" && pwd -P)" + +# +---------------------------------------------------------------------------+ +# | CP2K: A general program to perform molecular dynamics simulations | +# | Copyright 2000-2022 CP2K developers group | +# | | +# | SPDX-License-Identifier: GPL-2.0-or-later | +# +---------------------------------------------------------------------------+ +# +# +# ***************************************************************************** +#> \brief This script will compile and install or link existing tools and +#> libraries CP2K depends on and generate a set of ARCH files which +#> can be used to compile CP2K +#> \history Created on Friday, 2016/02/05 +# Update for Intel (17.01.2022, MK) +#> \author Lianheng Tong (ltong) lianheng.tong@kcl.ac.uk +# ***************************************************************************** + +# ------------------------------------------------------------------------ +# Work directories and used files +# ------------------------------------------------------------------------ +export ROOTDIR="${PWD}" +export SCRIPTDIR="${ROOTDIR}/scripts" +export BUILDDIR="/avfs/backend" +export INSTALLDIR="/avfs/projects/ops" +export SETUPFILE="${INSTALLDIR}/setup" +export SHA256_CHECKSUM="${SCRIPTDIR}/checksums.sha256" +export ARCH_FILE_TEMPLATE="${SCRIPTDIR}/arch_base.tmpl" + +# ------------------------------------------------------------------------ +# Make a copy of all options for $SETUPFILE +# ------------------------------------------------------------------------ +TOOLCHAIN_OPTIONS="$@" + +# ------------------------------------------------------------------------ +# Load common variables and tools +# ------------------------------------------------------------------------ +source "${SCRIPTDIR}"/common_vars.sh +source "${SCRIPTDIR}"/tool_kit.sh + +# ------------------------------------------------------------------------ +# Documentation +# ------------------------------------------------------------------------ +show_help() { + cat << EOF +This script will help you compile and install, or link libraries +CP2K depends on and setup a set of ARCH files that you can use +to compile CP2K. + +USAGE: + +$(basename $SCRIPT_NAME) [options] + +OPTIONS: + +-h, --help Show this message. +-j Number of processors to use for compilation, if + this option is not present, then the script + automatically tries to determine the number of + processors you have and try to use all of the + processors. +--no-check-certificate If you encounter "certificate verification" errors + from wget or ones saying that "common name doesn't + match requested host name" while at tarball downloading + stage, then the recommended solution is to install + the newest wget release. Alternatively, you can use + this option to bypass the verification and proceed with + the download. Security wise this should still be okay + as the installation script will check file checksums + after every tarball download. Nevertheless use this + option at your own risk. +--install-all This option will set value of all --with-PKG + options to "install". You can selectively set + --with-PKG to another value again by having the + --with-PKG option placed AFTER this option on the + command line. +--mpi-mode Selects which MPI flavour to use. Available options + are: mpich, openmpi, intelmpi, and no. By selecting "no", + MPI is not supported and disabled. By default the script + will try to determine the flavour based on the MPI library + currently available in your system path. For CRAY (CLE) + systems, the default flavour is mpich. Note that explicitly + setting --with-mpich, --with-openmpi or --with-intelmpi + options to values other than no will also switch --mpi-mode + to the respective mode. +--math-mode Selects which core math library to use. Available options + are: acml, cray, mkl, and openblas. The option "cray" + corresponds to cray libsci, and is the default for CRAY + (CLE) systems. For non-CRAY systems, if env variable MKLROOT + exists then mkl will be default, otherwise openblas is the + default option. Explicitly setting --with-acml, --with-mkl, + or --with-openblas options will switch --math-mode to the + respective modes. +--gpu-ver Selects the GPU architecture for which to compile. Available + options are: K20X, K40, K80, P100, V100, Mi50, Mi100, Mi250, + and no. + This setting determines the value of nvcc's '-arch' flag. + Default = no. +--libint-lmax Maximum supported angular momentum by libint. + Higher values will increase build time and library size. + Default = 5 +--log-lines Number of log file lines dumped in case of a non-zero exit code. + Default = 200 +--target-cpu Compile for the specified target CPU (e.g. haswell or generic), i.e. + do not optimize for the actual host system which is the default (native) +--no-arch-files Do not generate arch files +--dry-run Write only config files, but don't actually build packages. + +The --enable-FEATURE options follow the rules: + --enable-FEATURE=yes Enable this particular feature + --enable-FEATURE=no Disable this particular feature + --enable-FEATURE The option keyword alone is equivalent to + --enable-FEATURE=yes + + --enable-cuda Turn on GPU (CUDA) support (can be combined + with --enable-opencl). + Default = no + --enable-hip Turn on GPU (HIP) support. + Default = no + --enable-opencl Turn on OpenCL (GPU) support. Requires the OpenCL + development packages and runtime. If combined with + --enable-cuda, OpenCL alongside of CUDA is used. + Default = no + --enable-cray Turn on or off support for CRAY Linux Environment + (CLE) manually. By default the script will automatically + detect if your system is CLE, and provide support + accordingly. + +The --with-PKG options follow the rules: + --with-PKG=install Will download the package in \$PWD/build and + install the library package in \$PWD/install. + --with-PKG=system The script will then try to find the required + libraries of the package from the system path + variables such as PATH, LD_LIBRARY_PATH and + CPATH etc. + --with-PKG=no Do not use the package. + --with-PKG= The package will be assumed to be installed in + the given , and be linked accordingly. + --with-PKG The option keyword alone will be equivalent to + --with-PKG=install + + --with-gcc The GCC compiler to use to compile CP2K. + Default = system + --with-intel Use the Intel compiler to compile CP2K. + Default = system + --with-intel-classic Use the classic Intel compiler to compile CP2K. + Default = no + --with-cmake Cmake utilities + Default = install + --with-env-modules Environment Modules, used to load modules + Default = system + --with-python Python, used to generate CP2K input files + Default = system + --with-openmpi OpenMPI, important if you want a parallel version of CP2K. + Default = system + --with-mpich MPICH, MPI library like OpenMPI. one should + use only one of OpenMPI, MPICH or Intel MPI. + Default = system + --with-mpich-device Select the MPICH device, implies the use of MPICH as MPI library + Default = ch4 + --with-intelmpi Intel MPI, MPI library like OpenMPI. one should + use only one of OpenMPI, MPICH or Intel MPI. + Default = system + --with-libxc libxc, exchange-correlation library. Needed for + QuickStep DFT and hybrid calculations. + Default = install + --with-libint libint, library for evaluation of two-body molecular + integrals, needed for hybrid functional calculations + Default = install + --with-libgrpp libgrpp, library for the evaluation of ECP integrals, needed + for any calculations with semi-local ECP pseudopotentials + Default = install + --with-fftw FFTW3, library for fast fourier transform + Default = install + --with-acml AMD core maths library, which provides LAPACK and BLAS + Default = system + --with-mkl Intel Math Kernel Library, which provides LAPACK, and BLAS. + If MKL's FFTW3 interface is suitable (no FFTW-MPI support), + it replaces the FFTW library. If the ScaLAPACK component is + found, it replaces the one specified by --with-scalapack. + Default = system + --with-openblas OpenBLAS is a free high performance LAPACK and BLAS library, + the successor to GotoBLAS. + Default = install + --with-scalapack Parallel linear algebra library, needed for parallel + calculations. + Default = install + --with-libxsmm Small matrix multiplication library. + Default = install + --with-elpa Eigenvalue SoLvers for Petaflop-Applications library. + Fast library for large parallel jobs. + Default = install + --with-cusolvermp NVIDIA cusolverMp: CUDA library for distributed dense linear algebra. + Default = no + --with-ptscotch PT-SCOTCH, only used if PEXSI is used + Default = no + --with-superlu SuperLU DIST, used only if PEXSI is used + Default = no + --with-pexsi Enable interface to PEXSI library + Default = no + --with-quip Enable interface to QUIP library + Default = no + --with-plumed Enable interface to the PLUMED library. + Default = no + --with-sirius Enable interface to the plane wave SIRIUS library. + This package requires: gsl, libspg, elpa, scalapack, hdf5 and libxc. + Default = install + --with-gsl Enable the gnu scientific library (required for PLUMED and SIRIUS) + Default = install + --with-libvdwxc Enable support of Van der Waals interactions in SIRIUS. Support provided by libvdwxc + Default = install + --with-spglib Enable the spg library (search of symmetry groups) + This package depends on cmake. + Default = install + --with-hdf5 Enable the hdf5 library (used by the sirius library) + Default = install + --with-spfft Enable the spare fft used in SIRIUS (hard dependency) + Default = install + --with-spla Enable the Specialized Parallel Linear Algebra library (required by SIRIUS) + Default = install + --with-cosma Enable cosma as a replacement for scalapack matrix multiplication + Default = install + --with-libvori Enable libvori for the Voronoi integration (and the BQB compressed trajectory format) + Default = install + --with-libtorch Enable libtorch the machine learning framework needed for NequIP and Allegro + Default = no + +FURTHER INSTRUCTIONS + +All packages to be installed locally will be downloaded and built inside +./build, and then installed into package specific directories inside +./install. + +Both ./build and ./install are safe to delete, as they contain +only the files and directories that are generated by this script. However, +once all the packages are installed, and you compile CP2K using the arch +files provided by this script, then you must keep ./install in exactly +the same location as it was first created, as it contains tools and libraries +your version of CP2K binary will depend on. + +It should be safe to terminate running of this script in the middle of a +build process. The script will know if a package has been successfully +installed, and will just carry on and recompile and install the last +package it is working on. This is true even if you lose the content of +the entire ./build directory. + + +----------------------------------------------------------------+ + | YOU SHOULD ALWAYS SOURCE ./install/setup BEFORE YOU RUN CP2K | + | COMPILED WITH THIS TOOLCHAIN | + +----------------------------------------------------------------+ + +EOF +} + +# ------------------------------------------------------------------------ +# PACKAGE LIST: register all new dependent tools and libs here. Order +# is important, the first in the list gets installed first +# ------------------------------------------------------------------------ +tool_list="gcc intel cmake modules python" +mpi_list="mpich openmpi intelmpi" +math_list="mkl acml openblas" +lib_list="fftw libint libxc libgrpp libxsmm cosma scalapack elpa cusolvermp plumed \ + spfft spla ptscotch superlu pexsi quip gsl spglib hdf5 libvdwxc sirius + libvori libtorch openssl" +package_list="${tool_list} ${mpi_list} ${math_list} ${lib_list}" +# ------------------------------------------------------------------------ + +# first set everything to __DONTUSE__ +for ii in ${package_list}; do + eval with_${ii}="__DONTUSE__" +done + +# ------------------------------------------------------------------------ +# Work out default settings +# ------------------------------------------------------------------------ + +# tools to turn on by default: +with_gcc="__SYSTEM__" +with_python="__SYSTEM__" +with_modules="__SYSTEM__" + +# libs to turn on by default, the math and mpi libraries are chosen by there respective modes: +with_fftw="__INSTALL__" +with_libint="__INSTALL__" +with_libgrpp="__INSTALL__" +with_libxsmm="__INSTALL__" +with_libxc="__INSTALL__" +with_scalapack="__INSTALL__" +# default math library settings, MATH_MODE picks the math library +# to use, and with_* defines the default method of installation if it +# is picked. For non-CRAY systems defaults to mkl if $MKLROOT is +# available, otherwise defaults to openblas +if [ "${MKLROOT}" ]; then + export MATH_MODE="mkl" + with_mkl="__SYSTEM__" +else + export MATH_MODE="openblas" +fi +with_acml="__SYSTEM__" +with_openblas="__INSTALL__" + +# sirius is activated by default +with_sirius="__INSTALL__" +with_gsl="__DONTUSE__" +with_spglib="__INSTALL__" +with_hdf5="__DONTUSE__" +with_elpa="__INSTALL__" +with_cusolvermp="__DONTUSE__" +with_libvdwxc="__DONTUSE__" +with_spfft="__DONTUSE__" +with_spla="__DONTUSE__" +with_cosma="__INSTALL__" +with_libvori="__INSTALL__" +with_libtorch="__DONTUSE__" +# for MPI, we try to detect system MPI variant +if (command -v mpiexec > /dev/null 2>&1); then + # check if we are dealing with openmpi, mpich or intelmpi + if (mpiexec --version 2>&1 | grep -s -q "HYDRA"); then + echo "MPI is detected and it appears to be MPICH" + export MPI_MODE="mpich" + with_mpich="__SYSTEM__" + elif (mpiexec --version 2>&1 | grep -s -q "OpenRTE"); then + echo "MPI is detected and it appears to be OpenMPI" + export MPI_MODE="openmpi" + with_openmpi="__SYSTEM__" + elif (mpiexec --version 2>&1 | grep -s -q "Intel"); then + echo "MPI is detected and it appears to be Intel MPI" + with_gcc="__DONTUSE__" + with_intel="__SYSTEM__" + with_intelmpi="__SYSTEM__" + export MPI_MODE="intelmpi" + else # default to mpich + echo "MPI is detected and defaults to MPICH" + export MPI_MODE="mpich" + with_mpich="__SYSTEM__" + fi +else + report_warning $LINENO "No MPI installation detected (ignore this message in Cray Linux Environment or when MPI installation was requested)." + export MPI_MODE="no" +fi + +# default enable options +dry_run="__FALSE__" +no_arch_files="__FALSE__" +enable_tsan="__FALSE__" +enable_opencl="__FALSE__" +enable_cuda="__FALSE__" +enable_hip="__FALSE__" +export intel_classic="no" +export GPUVER="no" +export MPICH_DEVICE="ch4" +export TARGET_CPU="native" + +# default for libint +export LIBINT_LMAX="5" + +# default for log file dump size +export LOG_LINES="200" + +# defaults for CRAY Linux Environment +if [ "${CRAY_LD_LIBRARY_PATH}" ]; then + enable_cray="__TRUE__" + export MATH_MODE="cray" + # Default MPI used by CLE is assumed to be MPICH, in any case + # do not use the installers for the MPI libraries + with_mpich="__DONTUSE__" + with_openmpi="__DONTUSE__" + with_intelmpi="__DONTUSE__" + export MPI_MODE="mpich" + # set default value for some installers appropriate for CLE + with_gcc="__DONTUSE__" + with_intel="__DONTUSE__" + with_fftw="__SYSTEM__" + with_scalapack="__DONTUSE__" + with_modules="__DONTUSE__" + with_python="__DONTUSE__" +else + enable_cray="__FALSE__" +fi + +# ------------------------------------------------------------------------ +# parse user options +# ------------------------------------------------------------------------ +while [ $# -ge 1 ]; do + case ${1} in + -j) + case "${2}" in + -*) + export NPROCS_OVERWRITE="$(get_nprocs)" + ;; + [0-9]*) + shift + export NPROCS_OVERWRITE="${1}" + ;; + *) + report_error ${LINENO} \ + "The -j flag can only be followed by an integer number, found ${2}." + exit 1 + ;; + esac + ;; + -j[0-9]*) + export NPROCS_OVERWRITE="${1#-j}" + ;; + --no-check-certificate) + export DOWNLOADER_FLAGS="--no-check-certificate" + ;; + --install-all) + # set all package to the default installation status + for ii in ${package_list}; do + if [ "${ii}" != "intel" ] && [ "${ii}" != "intelmpi" ]; then + eval with_${ii}="__INSTALL__" + fi + done + # Use MPICH as default + export MPI_MODE="mpich" + ;; + --mpi-mode=*) + user_input="${1#*=}" + case "$user_input" in + mpich) + export MPI_MODE="mpich" + ;; + openmpi) + export MPI_MODE="openmpi" + ;; + intelmpi) + export MPI_MODE="intelmpi" + ;; + no) + export MPI_MODE="no" + ;; + *) + report_error ${LINENO} \ + "--mpi-mode currently only supports openmpi, mpich, intelmpi and no as options" + exit 1 + ;; + esac + ;; + --math-mode=*) + user_input="${1#*=}" + case "$user_input" in + cray) + export MATH_MODE="cray" + ;; + mkl) + export MATH_MODE="mkl" + ;; + acml) + export MATH_MODE="acml" + ;; + openblas) + export MATH_MODE="openblas" + ;; + *) + report_error ${LINENO} \ + "--math-mode currently only supports mkl, acml, and openblas as options" + ;; + esac + ;; + --gpu-ver=*) + user_input="${1#*=}" + case "${user_input}" in + K20X | K40 | K80 | P100 | V100 | A100 | Mi50 | Mi100 | Mi250 | no) + export GPUVER="${user_input}" + ;; + *) + report_error ${LINENO} \ + "--gpu-ver currently only supports K20X, K40, K80, P100, V100, A100, Mi50, Mi100, Mi250, and no as options" + exit 1 + ;; + esac + ;; + --target-cpu=*) + user_input="${1#*=}" + export TARGET_CPU="${user_input}" + ;; + --log-lines=*) + user_input="${1#*=}" + export LOG_LINES="${user_input}" + ;; + --libint-lmax=*) + user_input="${1#*=}" + export LIBINT_LMAX="${user_input}" + ;; + --no-arch-files) + no_arch_files="__TRUE__" + ;; + --dry-run) + dry_run="__TRUE__" + ;; + --enable-tsan*) + enable_tsan=$(read_enable $1) + if [ "${enable_tsan}" = "__INVALID__" ]; then + report_error "invalid value for --enable-tsan, please use yes or no" + exit 1 + fi + ;; + --enable-cuda*) + enable_cuda=$(read_enable $1) + if [ $enable_cuda = "__INVALID__" ]; then + report_error "invalid value for --enable-cuda, please use yes or no" + exit 1 + fi + ;; + --enable-hip*) + enable_hip=$(read_enable $1) + if [ "${enable_hip}" = "__INVALID__" ]; then + report_error "invalid value for --enable-hip, please use yes or no" + exit 1 + fi + ;; + --enable-opencl*) + enable_opencl=$(read_enable $1) + if [ $enable_opencl = "__INVALID__" ]; then + report_error "invalid value for --enable-opencl, please use yes or no" + exit 1 + fi + ;; + --enable-cray*) + enable_cray=$(read_enable $1) + if [ "${enable_cray}" = "__INVALID__" ]; then + report_error "invalid value for --enable-cray, please use yes or no" + exit 1 + fi + ;; + --with-gcc*) + with_gcc=$(read_with "${1}") + ;; + --with-cmake*) + with_cmake=$(read_with "${1}") + ;; + --with-env-modules*) + with_modules=$(read_with "${1}") + ;; + --with-python*) + with_python=$(read_with "${1}") + ;; + --with-mpich-device=*) + user_input="${1#*=}" + export MPICH_DEVICE="${user_input}" + export MPI_MODE=mpich + ;; + --with-mpich*) + with_mpich=$(read_with "${1}") + if [ "${with_mpich}" != "__DONTUSE__" ]; then + export MPI_MODE=mpich + fi + ;; + --with-openmpi*) + with_openmpi=$(read_with "${1}") + if [ "${with_openmpi}" != "__DONTUSE__" ]; then + export MPI_MODE=openmpi + fi + ;; + --with-intelmpi*) + with_intelmpi=$(read_with "${1}" "__SYSTEM__") + if [ "${with_intelmpi}" != "__DONTUSE__" ]; then + export MPI_MODE=intelmpi + fi + ;; + --with-intel-classic*) + intel_classic=$(read_with "${1}" "yes") + ;; + --with-intel*) + with_intel=$(read_with "${1}" "__SYSTEM__") + ;; + --with-libint*) + with_libint=$(read_with "${1}") + ;; + --with-libxc*) + with_libxc=$(read_with "${1}") + ;; + --with-libgrpp*) + with_libgrpp=$(read_with "${1}") + ;; + --with-fftw*) + with_fftw=$(read_with "${1}") + ;; + --with-mkl*) + with_mkl=$(read_with "${1}" "__SYSTEM__") + if [ "${with_mkl}" != "__DONTUSE__" ]; then + export MATH_MODE="mkl" + fi + ;; + --with-acml*) + with_acml=$(read_with "${1}") + if [ "${with_acml}" != "__DONTUSE__" ]; then + export MATH_MODE="acml" + fi + ;; + --with-openblas*) + with_openblas=$(read_with "${1}") + if [ "${with_openblas}" != "__DONTUSE__" ]; then + export MATH_MODE="openblas" + fi + ;; + --with-scalapack*) + with_scalapack=$(read_with "${1}") + ;; + --with-libxsmm*) + with_libxsmm=$(read_with "${1}") + ;; + --with-elpa*) + with_elpa=$(read_with "${1}") + ;; + --with-cusolvermp*) + with_cusolvermp=$(read_with "${1}") + ;; + --with-ptscotch*) + with_ptscotch=$(read_with "${1}") + ;; + --with-superlu*) + with_superlu=$(read_with "${1}") + ;; + --with-pexsi*) + with_pexsi=$(read_with "${1}") + ;; + --with-quip*) + with_quip=$(read_with "${1}") + ;; + --with-plumed*) + with_plumed=$(read_with "${1}") + ;; + --with-sirius*) + with_sirius=$(read_with "${1}") + ;; + --with-gsl*) + with_gsl=$(read_with "${1}") + ;; + --with-spglib*) + with_spglib=$(read_with "${1}") + ;; + --with-hdf5*) + with_hdf5=$(read_with "${1}") + ;; + --with-libvdwxc*) + with_libvdwxc=$(read_with "${1}") + ;; + --with-spfft*) + with_spfft=$(read_with "${1}") + ;; + --with-cosma*) + with_cosma=$(read_with "${1}") + ;; + --with-libvori*) + with_libvori=$(read_with "${1}") + ;; + --with-libtorch*) + with_libtorch=$(read_with "${1}") + ;; + --with-spla*) + with_spla=$(read_with "${1}") + ;; + --help*) + show_help + exit 0 + ;; + -h*) + show_help + exit 0 + ;; + *) + report_error "Unknown flag: $1" + exit 1 + ;; + esac + shift +done + +# consolidate settings after user input +export ENABLE_TSAN="${enable_tsan}" +export ENABLE_CUDA="${enable_cuda}" +export ENABLE_HIP="${enable_hip}" +export ENABLE_OPENCL="${enable_opencl}" +export ENABLE_CRAY="${enable_cray}" + +# ------------------------------------------------------------------------ +# Check and solve known conflicts before installations proceed +# ------------------------------------------------------------------------ +# Compiler conflicts +if [ "${with_intel}" != "__DONTUSE__" ] && [ "${with_gcc}" = "__INSTALL__" ]; then + echo "You have chosen to use the Intel compiler, therefore the installation of the GCC compiler will be skipped." + with_gcc="__SYSTEM__" +fi +# MPI library conflicts +if [ "${MPI_MODE}" = "no" ]; then + if [ "${with_scalapack}" != "__DONTUSE__" ]; then + echo "Not using MPI, so scalapack is disabled." + with_scalapack="__DONTUSE__" + fi + if [ "${with_elpa}" != "__DONTUSE__" ]; then + echo "Not using MPI, so ELPA is disabled." + with_elpa="__DONTUSE__" + fi + if [ "${with_pexsi}" != "__DONTUSE__" ]; then + echo "Not using MPI, so PEXSI is disabled." + with_pexsi="__DONTUSE__" + fi + if [ "${with_sirius}" != "__DONTUSE__" ]; then + echo "Not using MPI, so sirius is disabled" + with_sirius="__DONTUSE__" + fi + if [ "${with_spfft}" != "__DONTUSE__" ]; then + echo "Not using MPI, so spfft is disabled" + with_spfft="__DONTUSE__" + fi + if [ "${with_spla}" != "__DONTUSE__" ]; then + echo "Not using MPI, so spla is disabled" + with_spla="__DONTUSE__" + fi + if [ "${with_cosma}" != "__DONTUSE__" ]; then + echo "Not using MPI, so cosma is disabled" + with_cosma="__DONTUSE__" + fi +else + # if gcc is installed, then mpi needs to be installed too + if [ "${with_gcc}" = "__INSTALL__" ]; then + echo "You have chosen to install the GCC compiler, therefore MPI libraries have to be installed too" + case ${MPI_MODE} in + mpich) + with_mpich="__INSTALL__" + with_openmpi="__DONTUSE__" + ;; + openmpi) + with_mpich="__DONTUSE__" + with_openmpi="__INSTALL__" + ;; + esac + echo "and the use of the Intel compiler and Intel MPI will be disabled." + with_intel="__DONTUSE__" + with_intelmpi="__DONTUSE__" + fi + # Enable only one MPI implementation + case ${MPI_MODE} in + mpich) + with_openmpi="__DONTUSE__" + with_intelmpi="__DONTUSE__" + ;; + openmpi) + with_mpich="__DONTUSE__" + with_intelmpi="__DONTUSE__" + ;; + intelmpi) + with_mpich="__DONTUSE__" + with_openmpi="__DONTUSE__" + ;; + esac +fi + +# Python and its dependencies +if [ "${with_python}" = "__INSTALL__" ]; then + [ "${with_openssl}" = "__DONTUSE__" ] && with_openssl="__INSTALL__" +fi + +# If CUDA or HIP are enabled, make sure the GPU version has been defined. +if [ "${ENABLE_CUDA}" = "__TRUE__" ] || [ "${ENABLE_HIP}" = "__TRUE__" ]; then + if [ "${GPUVER}" = "no" ]; then + report_error "Please choose GPU architecture to compile for with --gpu-ver" + exit 1 + fi +fi + +# If OpenCL is enabled, make sure LIBXSMM is enabled as well. +if [ "${ENABLE_OPENCL}" = "__TRUE__" ]; then + if [ "${with_libxsmm}" = "__DONTUSE__" ]; then + report_error "LIBXSMM is necessary for the OpenCL backend (--with-libxsmm)" + exit 1 + fi +fi + +# PEXSI and its dependencies +if [ "${with_pexsi}" = "__DONTUSE__" ]; then + if [ "${with_ptscotch}" != "__DONTUSE__" ]; then + echo "Not using PEXSI, so PT-Scotch is disabled." + with_ptscotch="__DONTUSE__" + fi + if [ "${with_superlu}" != "__DONTUSE__" ]; then + echo "Not using PEXSI, so SuperLU-DIST is disabled." + with_superlu="__DONTUSE__" + fi +elif [ "${with_pexsi}" = "__INSTALL__" ]; then + [ "${with_ptscotch}" = "__DONTUSE__" ] && with_ptscotch="__INSTALL__" + [ "${with_superlu}" = "__DONTUSE__" ] && with_superlu="__INSTALL__" +else + if [ "${with_ptscotch}" = "__DONTUSE__" ]; then + report_error "For PEXSI to work you need a working PT-Scotch library use --with-ptscotch option to specify if you wish to install the library or specify its location." + exit 1 + fi + if [ "${with_superlu}" = "__DONTUSE__" ]; then + report_error "For PEXSI to work you need a working SuperLU-DIST library use --with-superlu option to specify if you wish to install the library or specify its location." + exit 1 + fi +fi + +# several packages require cmake. +if [ "${with_spglib}" = "__INSTALL__" ] || + [ "${with_libvori}" = "__INSTALL__" ] || + [ "${with_scalapack}" = "__INSTALL__" ] || + [ "${with_superlu}" = "__INSTALL__" ] || + [ "${with_sirius}" = "__INSTALL__" ] || + [ "${with_cosma}" = "__INSTALL__" ] || + [ "${with_spfft}" = "__INSTALL__" ] || + [ "${with_spla}" = "__INSTALL__" ]; then + [ "${with_cmake}" = "__DONTUSE__" ] && with_cmake="__INSTALL__" +fi + +# SIRIUS dependencies. Remove the gsl library from the dependencies if SIRIUS is not activated +if [ "${with_sirius}" = "__INSTALL__" ]; then + [ "${with_spfft}" = "__DONTUSE__" ] && with_spfft="__INSTALL__" + [ "${with_spla}" = "__DONTUSE__" ] && with_spla="__INSTALL__" + [ "${with_gsl}" = "__DONTUSE__" ] && with_gsl="__INSTALL__" + [ "${with_libxc}" = "__DONTUSE__" ] && with_libxc="__INSTALL__" + [ "${with_fftw}" = "__DONTUSE__" ] && with_fftw="__INSTALL__" + [ "${with_spglib}" = "__DONTUSE__" ] && with_spglib="__INSTALL__" + [ "${with_hdf5}" = "__DONTUSE__" ] && with_hdf5="__INSTALL__" + [ "${with_libvdwxc}" = "__DONTUSE__" ] && with_libvdwxc="__INSTALL__" + [ "${with_cosma}" = "__DONTUSE__" ] && with_cosma="__INSTALL__" +fi + +if [ "${with_plumed}" = "__INSTALL__" ]; then + [ "${with_gsl}" = "__DONTUSE__" ] && with_gsl="__INSTALL__" + [ "${with_fftw}" = "__DONTUSE__" ] && with_fftw="__INSTALL__" +fi + +# ------------------------------------------------------------------------ +# Preliminaries +# ------------------------------------------------------------------------ + +mkdir -p ${INSTALLDIR} + +# variables used for generating cp2k ARCH file +export CP_DFLAGS="" +export CP_LIBS="" +export CP_CFLAGS="" +export CP_LDFLAGS="-Wl,--enable-new-dtags" + +# ------------------------------------------------------------------------ +# Start writing setup file +# ------------------------------------------------------------------------ +cat << EOF > "$SETUPFILE" +#!/bin/bash +source "${SCRIPTDIR}/tool_kit.sh" +export CP2K_TOOLCHAIN_OPTIONS="${TOOLCHAIN_OPTIONS}" +EOF + +# ------------------------------------------------------------------------ +# Special settings for CRAY Linux Environment (CLE) +# TODO: CLE should be handle like gcc or Intel using a with_cray flag and +# this section should be moved to a separate file install_cray. +# ------------------------------------------------------------------------ +if [ "${ENABLE_CRAY}" = "__TRUE__" ]; then + echo "------------------------------------------------------------------------" + echo "CRAY Linux Environment (CLE) is detected" + echo "------------------------------------------------------------------------" + # add cray paths to system search path + export LIB_PATHS="CRAY_LD_LIBRARY_PATH ${LIB_PATHS}" + # set compilers to CLE wrappers + check_command cc + check_command ftn + check_command CC + export CC="cc" + export CXX="CC" + export FC="ftn" + export F90="${FC}" + export F77="${FC}" + export MPICC="${CC}" + export MPICXX="${CXX}" + export MPIFC="${FC}" + export MPIFORT="${MPIFC}" + export MPIF77="${MPIFC}" + # CRAY libsci should contains core math libraries, scalapack + # doesn't need LDFLAGS or CFLAGS, nor do the one need to + # explicitly link the math and scalapack libraries, as all is + # taken care of by the cray compiler wrappers. + if [ "$with_scalapack" = "__DONTUSE__" ]; then + export CP_DFLAGS="${CP_DFLAGS} IF_MPI(-D__SCALAPACK|)" + fi + case $MPI_MODE in + mpich) + if [ "$MPICH_DIR" ]; then + cray_mpich_include_path="$MPICH_DIR/include" + cray_mpich_lib_path="$MPICH_DIR/lib" + export INCLUDE_PATHS="$INCLUDE_PATHS cray_mpich_include_path" + export LIB_PATHS="$LIB_PATHS cray_mpich_lib_path" + fi + if [ "$with_mpich" = "__DONTUSE__" ]; then + add_include_from_paths MPI_CFLAGS "mpi.h" $INCLUDE_PATHS + add_include_from_paths MPI_LDFLAGS "libmpi.*" $LIB_PATHS + export MPI_CFLAGS + export MPI_LDFLAGS + export MPI_LIBS=" " + export CP_DFLAGS="${CP_DFLAGS} IF_MPI(-D__parallel|)" + fi + ;; + openmpi) + if [ "$with_openmpi" = "__DONTUSE__" ]; then + add_include_from_paths MPI_CFLAGS "mpi.h" $INCLUDE_PATHS + add_include_from_paths MPI_LDFLAGS "libmpi.*" $LIB_PATHS + export MPI_CFLAGS + export MPI_LDFLAGS + export MPI_LIBS="-lmpi -lmpi_cxx" + export CP_DFLAGS="${CP_DFLAGS} IF_MPI(-D__parallel|)" + fi + ;; + intelmpi) + if [ "$with_intelmpi" = "__DONTUSE__" ]; then + with_gcc="__DONTUSE__" + with_intel="__SYSTEM__" + add_include_from_paths MPI_CFLAGS "mpi.h" $INCLUDE_PATHS + add_include_from_paths MPI_LDFLAGS "libmpi.*" $LIB_PATHS + export MPI_CFLAGS + export MPI_LDFLAGS + export MPI_LIBS="-lmpi -lmpi_cxx" + export CP_DFLAGS="${CP_DFLAGS} IF_MPI(-D__parallel|)" + fi + ;; + esac + check_lib -lz + check_lib -ldl + export CRAY_EXTRA_LIBS="-lz -ldl" + # the space is intentional, so that the variable is non-empty and + # can pass require_env checks + export SCALAPACK_LDFLAGS=" " + export SCALAPACK_LIBS=" " +fi + +# ------------------------------------------------------------------------ +# Installing tools required for building CP2K and associated libraries +# ------------------------------------------------------------------------ + +echo "Compiling with $(get_nprocs) processes for target ${TARGET_CPU}." + +# Select the correct compute number based on the GPU architecture +case ${GPUVER} in + K20X) + export ARCH_NUM="35" + ;; + K40) + export ARCH_NUM="35" + ;; + K80) + export ARCH_NUM="37" + ;; + P100) + export ARCH_NUM="60" + ;; + V100) + export ARCH_NUM="70" + ;; + A100) + export ARCH_NUM="80" + ;; + Mi50) + # TODO: export ARCH_NUM= + ;; + Mi100) + # TODO: export ARCH_NUM= + ;; + Mi250) + # TODO: export ARCH_NUM= + ;; + no) + export ARCH_NUM="no" + ;; + *) + report_error ${LINENO} \ + "--gpu-ver currently only supports K20X, K40, K80, P100, V100, A100, Mi50, Mi100, Mi250, and no as options" + exit 1 + ;; +esac + +write_toolchain_env ${INSTALLDIR} + +# write toolchain config +echo "tool_list=\"${tool_list}\"" > ${INSTALLDIR}/toolchain.conf +for ii in ${package_list}; do + install_mode="$(eval echo \${with_${ii}})" + echo "with_${ii}=\"${install_mode}\"" >> ${INSTALLDIR}/toolchain.conf +done + +# ------------------------------------------------------------------------ +# Build packages unless dry-run mode is enabled. +# ------------------------------------------------------------------------ +if [ "${dry_run}" = "__TRUE__" ]; then + echo "Wrote only configuration files (--dry-run)." +else + echo "# Leak suppressions" > ${INSTALLDIR}/lsan.supp + ./scripts/stage0/install_stage0.sh + ./scripts/stage1/install_stage1.sh + ./scripts/stage2/install_stage2.sh + ./scripts/stage3/install_stage3.sh + ./scripts/stage4/install_stage4.sh + ./scripts/stage5/install_stage5.sh + ./scripts/stage6/install_stage6.sh + ./scripts/stage7/install_stage7.sh + ./scripts/stage8/install_stage8.sh + # Stage 9 is reserved for DBCSR. + if [ "${no_arch_files}" = "__FALSE__" ]; then + ./scripts/generate_arch_files.sh + fi +fi + +#EOF \ No newline at end of file diff --git a/make_cluster.sh b/make_cluster.sh deleted file mode 100644 index 303c3a4..0000000 --- a/make_cluster.sh +++ /dev/null @@ -1,268 +0,0 @@ -#!/bin/bash - -if [[ "$BASH_SOURCE" == "$0" ]]; then - echo "This script is the top-level bash file being run." - echo "Setting up the environment for the cluster." - BUILD_LOCATION=/avfs/backend - INSTALL_LOCATION=/avfs/projects/ops - mkdir -p ${BUILD_LOCATION} - mkdir -p ${INSTALL_LOCATION} - echo "Build location: ${BUILD_LOCATION}" - echo "Install location: ${INSTALL_LOCATION}" -else - echo "This script is not the top-level bash file being run." -fi - -./scripts/install_gcc.sh - -./scripts/install_env-modules.sh - -./scripts/install_openssl.sh - -./scripts/stage0/install_qt.sh - -./scripts/stage0/install_cmake.sh - -./scripts/stage0/install_git.sh - -./scripts/stage0/install_llvm.sh - -## INSTALL OPENMPI FROM SOURCE -module load gcc/${GCC_VERSION} cmake/${CMAKE_VERSION} - -OPENMPI_BUILD_DIR=${BUILD_LOCATION}/openmpi -OPENMPI_INSTALL_DIR=${INSTALL_LOCATION}/openmpi -mkdir -p ${OPENMPI_BUILD_DIR} -mkdir -p ${OPENMPI_INSTALL_DIR} - -OPENMPI_VERSION=4.1.1 - -cd ${OPENMPI_BUILD_DIR} -wget -c https://download.open-mpi.org/release/open-mpi/v${OPENMPI_VERSION%.*}/openmpi-${OPENMPI_VERSION}.tar.gz -tar -xf openmpi-${OPENMPI_VERSION}.tar.gz -cd openmpi-${OPENMPI_VERSION} -mkdir build && cd build - -if [ $(command -v srun) ]; then - echo "Slurm installation found. OpenMPI will be configured with --with-pmi." - EXTRA_CONFIGURE_FLAGS="--with-pmi" -else - EXTRA_CONFIGURE_FLAGS="" -fi - -pkg_install_dir=${OPENMPI_INSTALL_DIR}/${OPENMPI_VERSION}/${AVFS_COMPILER}/${AVFS_COMPILER_VERSION} - -../configure CFLAGS="${CFLAGS}" \ - --prefix=${pkg_install_dir} \ - --libdir="${pkg_install_dir}/lib" \ - --enable-mpi1-compatibility \ - ${EXTRA_CONFIGURE_FLAGS} -make -j$(nproc) -make -j$(nproc) install - -## INSTALL MPICH FROM SOURCE -module load gcc/${GCC_VERSION} cmake/${CMAKE_VERSION} - -MPICH_BUILD_DIR=${BUILD_LOCATION}/mpich -MPICH_INSTALL_DIR=${INSTALL_LOCATION}/mpich -mkdir -p ${MPICH_BUILD_DIR} -mkdir -p ${MPICH_INSTALL_DIR} - -MPICH_VERSION=4.0.3 - -cd ${MPICH_BUILD_DIR} -wget -c https://mpich.org/static/downloads/${MPICH_VERSION}/mpich-${MPICH_VERSION}.tar.gz -tar -xf mpich-${MPICH_VERSION}.tar.gz - -cd mpich-${MPICH_VERSION} -mkdir build && cd build - -if ("${FC}" --version | grep -q 'GNU'); then - compat_flag=$(allowed_gfortran_flags "-fallow-argument-mismatch") -else - compat_flag="" -fi - -pkg_install_dir=${MPICH_INSTALL_DIR}/${MPICH_VERSION}/${AVFS_COMPILER}/${AVFS_COMPILER_VERSION} - -../configure \ - --prefix="${pkg_install_dir}" \ - --libdir="${pkg_install_dir}/lib" \ - MPICC="" \ - FFLAGS="${FCFLAGS} ${compat_flag}" \ - FCFLAGS="${FCFLAGS} ${compat_flag}" \ - --without-x \ - --enable-gl=no \ - --with-device=${MPICH_DEVICE} -make -j$(nproc) -make -j$(nproc) install - - -MPIRUN="${pkg_install_dir}/bin/mpiexec" -MPICC="${pkg_install_dir}/bin/mpicc" -MPICXX="${pkg_install_dir}/bin/mpicxx" -MPIFC="${pkg_install_dir}/bin/mpifort" -MPIFORT="${MPIFC}" -MPIF77="${MPIFC}" -MPICH_CFLAGS="-I'${pkg_install_dir}/include'" -MPICH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - -export MPI_MODE="${MPI_MODE}" -export MPIRUN="${MPIRUN}" -export MPICC="${MPICC}" -export MPICXX="${MPICXX}" -export MPIFC="${MPIFC}" -export MPIFORT="${MPIFORT}" -export MPIF77="${MPIF77}" -export MPICH_CFLAGS="${MPICH_CFLAGS}" -export MPICH_LDFLAGS="${MPICH_LDFLAGS}" -export MPICH_LIBS="${MPICH_LIBS}" -export MPI_CFLAGS="${MPICH_CFLAGS}" -export MPI_LDFLAGS="${MPICH_LDFLAGS}" -export MPI_LIBS="${MPICH_LIBS}" -export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__parallel|)" -export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${MPICH_CFLAGS}|)" -export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${MPICH_LDFLAGS}|)" -export CP_LIBS="\${CP_LIBS} IF_MPI(${MPICH_LIBS}|)" - -## INSTALL OPENBLAS FROM SOURCE -OPENBLAS_BUILD_DIR=${BUILD_LOCATION}/openblas -OPENBLAS_INSTALL_DIR=${INSTALL_LOCATION}/openblas -mkdir -p ${OPENBLAS_BUILD_DIR} -mkdir -p ${OPENBLAS_INSTALL_DIR} - -OPENBLAS_VERSION=0.3.18 - -cd ${OPENBLAS_BUILD_DIR} -wget -c https://github.com/OpenMathLib/OpenBLAS/releases/download/v${OPENBLAS_VERSION}/OpenBLAS-${OPENBLAS_VERSION}.tar.gz -tar -xf OpenBLAS-${OPENBLAS_VERSION}.tar.gz -cd OpenBLAS-${OPENBLAS_VERSION} -pkg_install_dir=${OPENBLAS_INSTALL_DIR}/${OPENBLAS_VERSION} -make -j$(nproc) \ - MAKE_NB_JOBS=0 \ - TARGET=${TARGET} \ - NUM_THREADS=128 \ - USE_THREAD=1 \ - USE_OPENMP=1 \ - NO_AFFINITY=1 \ - CC="${CC}" \ - FC="${FC}" \ - PREFIX="${pkg_install_dir}" - - -make -j$(nproc) \ - MAKE_NB_JOBS=0 \ - TARGET=${TARGET} \ - NUM_THREADS=128 \ - USE_THREAD=1 \ - USE_OPENMP=1 \ - NO_AFFINITY=1 \ - CC="${CC}" \ - FC="${FC}" \ - PREFIX="${pkg_install_dir}" install - -## INSTALL FFTW FROM SOURCE -./scripts/install_fftw.sh - -## INSTALL HDF5 FROM SOURCE -module load gcc/8.1.0 openmpi/4.1.4 cmake/3.21.3 - -# Check if MPI is enabled -if [ -n "$MPI_ENABLED" ]; then - MPI_ENABLED=true -else - MPI_ENABLED=false -fi - -HDF5_BUILD_DIR=${BUILD_LOCATION}/hdf5 -HDF5_VERSION=1.12.1 - -# Use the MPI_ENABLED variable in your script -if [ "$MPI_ENABLED" = true ]; then - # MPI is enabled, do something - echo "MPI is enabled" - HDF5_INSTALL_DIR=${INSTALL_LOCATION}/hdf5-withmpi/${HDF5_VERSION}/${COMPILER}/${COMPILER_VERSION}/${MPI_NAME}/${MPI_VERSION} -else - # MPI is not enabled, do something else - echo "MPI is not enabled" - HDF5_INSTALL_DIR=${INSTALL_LOCATION}/hdf5/${HDF5_VERSION}/${COMPILER}/${COMPILER_VERSION} -fi - -## INSTALL NETCDF FROM SOURCE - -## INSTALL OPENMC FROM SOURCE -module load gcc/8.1.0 cmake/3.21.3 python/3.11.5 git/2.11.3 - -OPENMC_BUILD_DIR=${BUILD_LOCATION}/openmc -OPENMC_INSTALL_DIR=${INSTALL_LOCATION}/openmc - -mkdir -p ${OPENMC_BUILD_DIR} -mkdir -p ${OPENMC_INSTALL_DIR} - -PROJECT_FOLDER=/avfs/projects/openmc -cd ${PROJECT_FOLDER} -python3 -m venv .venv - -OPENMC_VERSION=0.14.0 - -cd ${OPENMC_BUILD_DIR} -git clone --recurse-submodules https://github.com/openmc-dev/openmc.git -cd openmc -git checkout v${OPENMC_VERSION} -mkdir build && cd build - -if [ "$MPI_ENABLED" = true ]; then - # MPI is enabled, do something - # HDF5_ROOT=/avfs/projects/hdf5-withmpi/gcc/8.1.0/openmpi/4.1.4 \ - # CC=/avfs/projects/openmpi/4.1.4/gcc/8.1.0/bin/mpicc \ - # CXX=/avfs/projects/openmpi/4.1.4/gcc/8.1.0/bin/mpicxx \ - module load hdf5-withmpi openmpi/4.1.4 - HDF5_ROOT=${HDF5_ROOT} CC=mpicc CXX=mpicxx \ - cmake .. -DCMAKE_INSTALL_PREFIX=${OPENMC_INSTALL_DIR}/${OPENMC_VERSION} -DOPENMC_USE_MPI=ON -DOPENMC_USE_OPENMP=ON -DCMAKE_BUILD_TYPE=Release -else - # MPI is not enabled, do something else - module load hdf5 - HDF5_ROOT=${HDF5_ROOT} - cmake .. -DCMAKE_INSTALL_PREFIX=${OPENMC_INSTALL_DIR}/${OPENMC_VERSION} -DOPENMC_USE_MPI=OFF -DOPENMC_USE_OPENMP=ON -DCMAKE_BUILD_TYPE=Release -fi - -make -j20 -make install -cd .. -source ${PROJECT_FOLDER}/.venv/bin/activate - -if [ "$MPI_ENABLED" = true ]; then - # MPI is enabled, do something - MPICC=/avfs/projects/openmpi/4.1.4/gcc/8.1.0/bin/mpicc \ - /avfs/projects/python/3.11.5/bin/python3 -m pip install mpi4py - CC=/avfs/projects/openmpi/4.1.4/gcc/8.1.0/bin/mpicc HDF5_MPI=ON \ - HDF5_DIR=/avfs/projects/hdf5-withmpi/gcc/8.1.0/openmpi/4.1.4 \ - ${PROJECT_FOLDER}/.venv/bin/python3 -m pip install --no-binary=h5py h5py - ${PROJECT_FOLDER}/.venv/bin/python3 -m pip install . -else - # MPI is not enabled, do something else - HDF5_DIR=${HDF5_ROOT} - ${PROJECT_FOLDER}/.venv/bin/python3 -m pip install . -fi - - - - - -# HDF5_ROOT=/share/apps/hdf5-withmpi/gcc/8.1.0/openmpi/4.1.4 CC=/share/apps/openmpi/4.1.4/gcc/8.1.0/bin/mpicc CXX=/share/apps/openmpi/4.1.4/gcc/8.1.0/bin/mpicxx cmake .. -DCMAKE_INSTALL_PREFIX=/qfs/people/parl703/openmc -DOPENMC_USE_MPI=ON -DOPENMC_USE_OPENMP=ON -DCMAKE_BUILD_TYPE=Release -# make -j20 -# make install -# cd .. -# MPICC=/share/apps/openmpi/4.1.4/gcc/8.1.0/bin/mpicc /share/apps/python/3.11.5/bin/python3 -m pip install mpi4py -# CC=/share/apps/openmpi/4.1.4/gcc/8.1.0/bin/mpicc HDF5_MPI=ON HDF5_DIR=/share/apps/hdf5-withmpi/gcc/8.1.0/openmpi/4.1.4 /rcfs/projects/sherlock/openmc/dwnld/.venv/bin/python3 -m pip install --no-binary=h5py h5py -# /rcfs/projects/sherlock/openmc/dwnld/.venv/bin/python3 -m pip install . - - - - - - - - - - diff --git a/scripts/VERSION b/scripts/VERSION new file mode 100644 index 0000000..5bd3d1e --- /dev/null +++ b/scripts/VERSION @@ -0,0 +1,2 @@ +# version file to force a rebuild of the entire toolchain +VERSION="2019.1" diff --git a/scripts/common_vars.sh b/scripts/common_vars.sh new file mode 100644 index 0000000..8c67afd --- /dev/null +++ b/scripts/common_vars.sh @@ -0,0 +1,35 @@ +# Common variables used by the installation scripts + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all +# shellcheck shell=bash + +# directories and files used by the installer +ROOTDIR=${ROOTDIR:-"$(pwd -P)"} +SCRIPTDIR=${SCRIPTDIR:-"${ROOTDIR}/scripts"} +INSTALLDIR=${INSTALLDIR:-"${ROOTDIR}/install"} +BUILDDIR=${BUILDDIR:-"${ROOTDIR}/build"} +SETUPFILE=${SETUPFILE:-"${INSTALLDIR}/setup"} +ARCH_FILE_TEMPLATE=${ARCH_FILE_TEMPLATE:-"${SCRIPTDIR}/arch_base.tmpl"} +VERSION_FILE=${VERSION_FILE:-"${SCRIPTDIR}/VERSION"} + +# system arch gotten from OpenBLAS prebuild +OPENBLAS_ARCH=${OPENBLAS_ARCH:-"x86_64"} +OPENBLAS_LIBCORE=${OPENBLAS_LIBCORE:-''} + +# search paths +SYS_INCLUDE_PATH=${SYS_INCLUDE_PATH:-'/usr/local/include:/usr/include'} +SYS_LIB_PATH=${SYS_LIB_PATHS:-'/usr/local/lib64:/usr/local/lib:/usr/lib64:/usr/lib:/lib64:/lib'} +INCLUDE_PATHS=${INCLUDE_PATHS:-"CPATH SYS_INCLUDE_PATH"} +LIB_PATHS=${LIB_PATHS:-'LD_LIBRARY_PATH LIBRARY_PATH LD_RUN_PATH SYS_LIB_PATH'} + +# mode flags +ENABLE_OMP=${ENABLE_OMP:-"__TRUE__"} +ENABLE_CUDA=${ENABLE_CUDA:-"__FALSE__"} +ENABLE_HIP=${ENABLE_HIP:-"__FALSE__"} +ENABLE_OPENCL=${ENABLE_OPENCL:-"__FALSE__"} +ENABLE_CRAY=${ENABLE_CRAY:-"__FALSE__"} +MPI_MODE=${MPI_MODE:-openmpi} +MATH_MODE=${MATH_MODE:-openblas} + +export NVCC=${NVCC:-nvcc} \ No newline at end of file diff --git a/scripts/get_openblas_arch.sh b/scripts/get_openblas_arch.sh new file mode 100755 index 0000000..a57195c --- /dev/null +++ b/scripts/get_openblas_arch.sh @@ -0,0 +1,61 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")" && pwd -P)" + +openblas_ver="0.3.25" # Keep in sync with install_openblas.sh +openblas_sha256="4c25cb30c4bb23eddca05d7d0a85997b8db6144f5464ba7f8c09ce91e2f35543" +openblas_pkg="OpenBLAS-${openblas_ver}.tar.gz" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +find_openblas_dir() { + local __dir='' + for __dir in *OpenBLAS*; do + if [ -d "$__dir" ]; then + echo "$__dir" + return 0 + fi + done + echo '' +} + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +echo "==================== Getting proc arch info using OpenBLAS tools ====================" +# find existing openblas source dir +openblas_dir="$(find_openblas_dir)" +# if cannot find openblas source dir, try download one +if ! [ "$openblas_dir" ]; then + if [ -f ${openblas_pkg} ]; then + echo "${openblas_pkg} is found" + else + download_pkg_from_cp2k_org "${openblas_sha256}" "${openblas_pkg}" + fi + tar -xzf ${openblas_pkg} + openblas_dir="$(find_openblas_dir)" +fi +openblas_conf="${openblas_dir}/Makefile.conf" +# try find Makefile.config, if not then generate one with make lapack_prebuild +if ! [ -f "$openblas_conf" ]; then + cd "$openblas_dir" + make lapack_prebuild + cd .. +fi +OPENBLAS_LIBCORE="$(grep 'LIBCORE=' $openblas_conf | cut -f2 -d=)" +OPENBLAS_ARCH="$(grep 'ARCH=' $openblas_conf | cut -f2 -d=)" +echo "OpenBLAS detected LIBCORE = $OPENBLAS_LIBCORE" +echo "OpenBLAS detected ARCH = $OPENBLAS_ARCH" +# output setup file +cat << EOF > "${BUILDDIR}/openblas_arch" +export OPENBLAS_LIBCORE="${OPENBLAS_LIBCORE}" +export OPENBLAS_ARCH="${OPENBLAS_ARCH}" +EOF \ No newline at end of file diff --git a/scripts/parse_if.py b/scripts/parse_if.py new file mode 100755 index 0000000..32c34ff --- /dev/null +++ b/scripts/parse_if.py @@ -0,0 +1,168 @@ +#!/usr/bin/env python3 + + +import sys +import argparse + + +class Parser: + "Parser for files with IF_XYZ(A|B) constructs" + + def __init__(self, switches): + self.mSwitches = switches + + def Switches(self): + "outputs the switches used by parser" + return self.mSwitches + + def SetSwitch(self, key, val): + "Set or add a (key,val) switch" + self.mSwitches[key] = val + + def ParseSingleIf(self, string, switch): + """ + switch should be a tuple (key, val) + ParseSingleIf(string, switch) will replace in string the + first occurrence of IF_key(A|B) with A if val = True; + B if val = False + """ + init = string.find("IF_" + switch[0]) + start = init + end = len(string) + mark = end + counter = 0 + ind = start + # determine the correct location for '|' + for cc in string[init:]: + if cc == "(": + if counter == 0: + start = ind + counter += 1 + elif cc == ")": + counter -= 1 + if counter == 0: + end = ind + break + elif cc == "|" and counter == 1: + mark = ind + ind += 1 + # resolve the option + if switch[1]: + result = ( + string[0:init] + + string[start + 1 : mark] + + string[end + 1 : len(string)] + ) + else: + result = ( + string[0:init] + string[mark + 1 : end] + string[end + 1 : len(string)] + ) + return result + + def ParseIf(self, string, switch): + """ + ParseIf(string, switch) will replace in string recursively + occurance of IF_key(A|B) statements with A if val = True; + B if val = False + """ + result = string + while result.find("IF_" + switch[0]) > -1: + result = self.ParseSingleIf(result, switch) + return result + + def ParseString(self, string): + """ + ParseString(string) will parse in string recursively + all of IF_key(A|B) statements for all (key, val) pairs + in dictionary self.mSwitches + """ + result = string + for switch in self.mSwitches.items(): + result = self.ParseIf(result, switch) + return result + + def ParseDocument(self, input_file, output_file): + """ + ParseDocument(input_file, output_fiel) will replace recursively + all of IF_key(A|B) statements for all (key, val) pairs + in dictionary self.mSwitches in the input_file stream and output + to the output_file stream. + """ + output = [] + for line in input_file: + output.append(self.ParseString(line)) + + if input_file == output_file: + output_file.seek(0) + output_file.truncate() + + # write to the same file + for line in output: + output_file.write(line) + + +# ------------------------------------------------------------------------ +# main program +# ------------------------------------------------------------------------ +if __name__ == "__main__": + argparser = argparse.ArgumentParser( + description="Resolve IF_*() macros based on given tags" + ) + argparser.add_argument( + "-f", + "--file", + metavar="FILENAME", + type=str, + help="read from given file instead of stdin", + ) + argparser.add_argument( + "-i", + "--inplace", + action="store_true", + help="do in-place replacement for the given file instead of echo to stdout", + ) + argparser.add_argument("--selftest", action="store_true", help="run self test") + argparser.add_argument( + "flags", + metavar="FLAG", + type=str, + nargs="*", + help="specified flags are set to true", + ) + + args = argparser.parse_args() + + # default list of switches used by the parser + switches = { + "MPI": False, + "CUDA": False, + "HIP": False, + "OPENCL": False, + "WARNALL": False, + "DEBUG": False, + "ASAN": False, + "STATIC": False, + "VALGRIND": False, + "COVERAGE": False, + } + + parser = Parser(switches) + + # set the list of switches given on the command line to True + for flag in args.flags: + parser.SetSwitch(flag, True) + + if args.selftest: + sys.exit(0) # TODO implement selftest + + # do parsing + + if not args.file: + parser.ParseDocument(sys.stdin, sys.stdout) + else: + if args.inplace: + with open(args.file, mode="r+") as fhandle: + parser.ParseDocument(fhandle, fhandle) + else: + with open(args.file, mode="r") as fhandle: + parser.ParseDocument(fhandle, sys.stdout) diff --git a/scripts/signal_trap.sh b/scripts/signal_trap.sh new file mode 100644 index 0000000..8fd7f94 --- /dev/null +++ b/scripts/signal_trap.sh @@ -0,0 +1,7 @@ +# signal trapping + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all +# shellcheck shell=bash + +trap 'error_handler ${LINENO}' ERR diff --git a/scripts/stage0/install_beegfs.sh b/scripts/stage0/install_beegfs.sh deleted file mode 100755 index 348e248..0000000 --- a/scripts/stage0/install_beegfs.sh +++ /dev/null @@ -1,101 +0,0 @@ -#!/bin/bash - -# node01: Management Server -# node02: Metadata Server -# node03: Storage Server -# node04: Client - -alias node01='172.17.2.101' -alias node02='172.17.2.102' -alias node03='172.17.2.103' -alias node04='172.17.2.104' - -for ((i = 1 ; i < 5 ; i++)); do - ssh-copy-id -i ~/.ssh/id_rsa root@node0$i - ssh root@node0$i - yum install -y wget fio - hostnamectl set-hostname node0$i - wget -O /etc/yum.repos.d/beegfs_rhel8.repo https://www.beegfs.io/release/beegfs_7.4.3/dists/beegfs-rhel8.repo - - systemctl disable firewalld - systemctl stop firewalld - sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux - sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config - - cat <> /etc/hosts - -10.0.1.2 node01 -10.0.1.3 node02 -10.0.1.4 node03 -10.0.1.5 node04 -EOF - reboot now -done - - -ssh root@node01 yum install -y beegfs-mgmtd # management service -ssh root@node02 yum install -y beegfs-meta #libbeegfs-ib # metadata service; libbeegfs-ib is only required for RDMA -ssh root@node03 yum install -y beegfs-storage #libbeegfs-ib # storage service; libbeegfs-ib is only required for RDMA -ssh root@node04 yum install -y kernel-devel beegfs-client beegfs-helperd beegfs-utils # client and command-line utils - -ssh root@node01 -/opt/beegfs/sbin/beegfs-setup-mgmtd -p /data/beegfs/beegfs_mgmtd -systemctl start beegfs-mgmtd -systemctl status beegfs-mgmtd - -ssh root@node02 -/opt/beegfs/sbin/beegfs-setup-meta -p /data/beegfs/beegfs_meta -s 2 -m node01 -systemctl start beegfs-meta -systemctl status beegfs-meta - -ssh root@node03 -mkdir -p /data/beegfs_storage{1..3} -mkfs.ext4 /dev/disk/by-id/scsi-0Linode_Volume_node01 -mkfs.ext4 /dev/disk/by-id/scsi-0Linode_Volume_node02 -mkfs.ext4 /dev/disk/by-id/scsi-0Linode_Volume_node03 - -mount /dev/disk/by-id/scsi-0Linode_Volume_node01 /data/beegfs_storage1 -mount /dev/disk/by-id/scsi-0Linode_Volume_node02 /data/beegfs_storage2 -mount /dev/disk/by-id/scsi-0Linode_Volume_node03 /data/beegfs_storage3 - -cat "/dev/disk/by-id/scsi-0Linode_Volume_node01 /data/beegfs_storage1" >> /etc/fstab -cat "/dev/disk/by-id/scsi-0Linode_Volume_node02 /data/beegfs_storage2" >> /etc/fstab -cat "/dev/disk/by-id/scsi-0Linode_Volume_node03 /data/beegfs_storage3" >> /etc/fstab - -/opt/beegfs/sbin/beegfs-setup-storage -p /data/beegfs_storage1 -s 3 -i 301 -m node01 -/opt/beegfs/sbin/beegfs-setup-storage -p /data/beegfs_storage2 -s 3 -i 302 -/opt/beegfs/sbin/beegfs-setup-storage -p /data/beegfs_storage3 -s 3 -i 303 - -systemctl start beegfs-storage -systemctl status beegfs-storage - -ssh root@node04 -/opt/beegfs/sbin/beegfs-setup-client -m node01 -systemctl start beegfs-helperd -systemctl status beegfs-helperd -systemctl start beegfs-client -systemctl status beegfs-client -vim /etc/beegfs/beegfs-mounts.conf - -# set connDisableAuthentication to true on all nodes. - -ssh node04 -beegfs-ctl --listnodes --nodetype=meta --nicdetails -beegfs-ctl --listnodes --nodetype=storage --nicdetails -beegfs-ctl --listnodes --nodetype=client --nicdetails -beegfs-net # Displays connections the client is actually using -beegfs-check-servers # Displays possible connectivity of the services -beegfs-df # Displays free space and inodes of storage and metadata targets - - -ssh root@node01 -fio --name=test --group_report --filename=/mnt/beegfs/testfile1 --ioengine=posixaio --time_based --runtime=180 --startdelay=10 --nrfiles=1 --size=1G --numjobs=1 --bs=128K --rw=read - -ssh root@node04 -fio --name=test --group_report --filename=/mnt/beegfs/testfile2 --ioengine=posixaio --time_based --runtime=180 --startdelay=10 --nrfiles=1 --size=1G --numjobs=1 --bs=128K --rw=read - - - - - - diff --git a/scripts/stage0/install_binutils.sh b/scripts/stage0/install_binutils.sh deleted file mode 100644 index 6f21ed1..0000000 --- a/scripts/stage0/install_binutils.sh +++ /dev/null @@ -1,5 +0,0 @@ - -BINUTILS_VERSION=2.35 - -wget -c https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.gz -tar -xf binutils-${BINUTILS_VERSION}.tar.gz \ No newline at end of file diff --git a/scripts/stage0/install_cmake.sh b/scripts/stage0/install_cmake.sh old mode 100644 new mode 100755 index 0007f5d..f61f675 --- a/scripts/stage0/install_cmake.sh +++ b/scripts/stage0/install_cmake.sh @@ -1,26 +1,100 @@ -## INSTALL CMAKE FROM SOURCE -CMAKE_BUILD_DIR=${BUILD_LOCATION}/cmake -CMAKE_INSTALL_DIR=${INSTALL_LOCATION}/cmake -mkdir -p ${CMAKE_BUILD_DIR} -mkdir -p ${CMAKE_INSTALL_DIR} +#!/bin/bash -e -VERSIONS=(3.5.2 -3.12.4 -3.17.5 -3.21.3 -3.24.4 -3.28.1) +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all -OPENSSL_ROOT_DIR=${SSL_INSTALL_DIR}/${SSL_VERSION} -for CMAKE_VERSION in "${strings[@]}"; do - # CMAKE_VERSION=3.21.3 - CMAKE_MAJOR_VERSION=$(echo ${CMAKE_VERSION} | cut -d. -f1-2) - cd ${CMAKE_BUILD_DIR} - wget -c http://www.cmake.org/files/v${CMAKE_MAJOR_VERSION}/cmake-${CMAKE_VERSION}.tar.gz - tar -xf cmake-${CMAKE_VERSION}.tar.gz - mkdir -p cmake-${CMAKE_VERSION}/build && cd cmake-${CMAKE_VERSION}/build +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" - ../configure --prefix=${CMAKE_INSTALL_DIR}/${CMAKE_VERSION} --parallel=$(nproc) - make -j$(nproc) - make install -done \ No newline at end of file +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_cmake" ] && rm "${BUILDDIR}/setup_cmake" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_cmake}" in + __INSTALL__) + echo "==================== Installing CMake ====================" + cmake_ver="3.28.1" + if [ "${OPENBLAS_ARCH}" = "arm64" ]; then + cmake_arch="linux-aarch64" + cmake_sha256="4ecba78ef9499a973d012a83feab5f888e86fc5388e9a768037ab4f7232cab16" + elif [ "${OPENBLAS_ARCH}" = "x86_64" ]; then + cmake_arch="linux-x86_64" + cmake_sha256="ada6a46be9da5f8cbeb00b9523ffe45ee6b36172eb81aaa5bdc6a2a8231b677c" + else + report_error ${LINENO} \ + "cmake installation for ARCH=${ARCH} is not supported. You can try to use the system installation using the flag --with-cmake=system instead." + exit 1 + fi + pkg_install_dir="${INSTALLDIR}/cmake/${cmake_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "cmake-${cmake_ver} is already installed, skipping it." + else + if [ -f cmake-${cmake_ver}-${cmake_arch}.sh ]; then + echo "cmake-${cmake_ver}-${cmake_arch}.sh is found" + else + download_pkg_from_cp2k_org "${cmake_sha256}" "cmake-${cmake_ver}-${cmake_arch}.sh" + fi + echo "Installing from scratch into ${pkg_install_dir}" + mkdir -p ${pkg_install_dir} + /bin/sh cmake-${cmake_ver}-${cmake_arch}.sh --prefix=${pkg_install_dir} --skip-license > install.log 2>&1 || tail -n ${LOG_LINES} install.log + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" + fi + ;; + __SYSTEM__) + echo "==================== Finding CMake from system paths ====================" + check_command cmake "cmake" + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking CMake to user paths ====================" + pkg_install_dir="$with_cmake" + check_dir "${with_cmake}/bin" + ;; +esac +if [ "${with_cmake}" != "__DONTUSE__" ]; then + if [ "${with_cmake}" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_cmake" +prepend_path PATH "${pkg_install_dir}/bin" +EOF + mkdir -p "${MODULEDIR}/tools/cmake" + cat << EOF > "${MODULEDIR}"/tools/cmake/${cmake_ver} +#%Module1.0 +## +## CMake modulefile +## +proc ModulesHelp { } { + global version + + puts stderr "\tThis loads the cmake environment." + puts stderr "\tModifies: PATH" +} + +module-whatis "load cmake environment" +module-whatis "Modifies: PATH" + +# for Tcl script use only + +set cmake_root ${pkg_install_dir} + +setenv CMAKE "\$cmake_root" +prepend-path PATH "\$cmake_root/bin" +EOF + cat "${BUILDDIR}/setup_cmake" >> $SETUPFILE + fi +fi + +load "${BUILDDIR}/setup_cmake" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "cmake" diff --git a/scripts/stage0/install_gcc.sh b/scripts/stage0/install_gcc.sh old mode 100644 new mode 100755 index 6522376..57c992f --- a/scripts/stage0/install_gcc.sh +++ b/scripts/stage0/install_gcc.sh @@ -1,45 +1,253 @@ #!/bin/bash -e +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + [ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" -VERSIONS=(4.4.7 -4.6.2 -4.8.5 -4.9.3 -5.1.0 -5.2.0 -5.4.0 -6.1.0 -6.3.0 -7.1.0 -7.5.0 -8.4.0 -9.1.0 -10.2.0 -10.3.0 -11.2.0 -12.3.0 -13.1.0) +gcc_ver="13.2.0" +gcc_sha256="8cb4be3796651976f94b9356fa08d833524f62420d6292c5033a9a26af315078" source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env -GCC_VERSION=7.5.0 +[ -f "${BUILDDIR}/setup_gcc" ] && rm "${BUILDDIR}/setup_gcc" -GCC_BUILD_DIR=${BUILD_LOCATION}/gcc -GCC_INSTALL_DIR=${INSTALL_LOCATION}/gcc -mkdir -p ${GCC_INSTALL_DIR} -mkdir gcc-${GCC_VERSION}-build +GCC_LDFLAGS="" +GCC_CFLAGS="" +TSANFLAGS="" +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" -cd ${GCC_BUILD_DIR} +case "${with_gcc}" in + __INSTALL__) + echo "==================== Installing GCC ====================" + pkg_install_dir="${INSTALLDIR}/gcc/${gcc_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "gcc-${gcc_ver} is already installed, skipping it." + else + if [ -f gcc-${gcc_ver}.tar.gz ]; then + echo "gcc-${gcc_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${gcc_sha256}" "gcc-${gcc_ver}.tar.gz" + fi + [ -d gcc-${gcc_ver} ] && rm -rf gcc-${gcc_ver} + tar -xzf gcc-${gcc_ver}.tar.gz -wget ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz -tar -xf gcc-${GCC_VERSION}.tar.gz -mv gcc-${GCC_VERSION} gcc-${GCC_VERSION}-source -cd gcc-${GCC_VERSION}-source -./contrib/download_prerequisites -cd ../gcc-${GCC_VERSION}-build -${GCC_BUILD_DIR}/gcc-${GCC_VERSION}-source/configure --prefix=${GCC_INSTALL_DIR}/${GCC_VERSION} --enable-languages=c,c++,fortran,go --enable-lto --disable-multilib --enable-checking=release --enable-threads=posix --enable-libstdcxx-debug --enable-__cxa_atexit --enable-plugins --enable-bootstrap -make -j$(nproc) -make -j$(nproc) check -make install \ No newline at end of file + echo "Installing GCC from scratch into ${pkg_install_dir}" + cd gcc-${gcc_ver} + + # Download prerequisites from cp2k.org because gcc.gnu.org returns 403 when queried from GCP. + sed -i 's|http://gcc.gnu.org/pub/gcc/infrastructure/|https://cp2k.org/static/downloads/|' ./contrib/download_prerequisites + ./contrib/download_prerequisites > prereq.log 2>&1 || tail -n ${LOG_LINES} prereq.log + GCCROOT=${PWD} + mkdir obj + cd obj + # TODO: Maybe use --disable-libquadmath-support to improve static linking: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539 + # + # TODO: Maybe use --disable-gnu-unique-object to improve static linking: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60348#c13 + # https://stackoverflow.com/questions/11931420 + # + # TODO: Unfortunately, we can not simply use --disable-shared, because + # it would break OpenBLAS build and probably others too. + COMMON_FLAGS="-O2 -fPIC -fno-omit-frame-pointer -fopenmp -g" + CFLAGS="${COMMON_FLAGS} -std=gnu99" + CXXFLAGS="${CFLAGS}" + FCFLAGS="${COMMON_FLAGS} -fbacktrace" + ${GCCROOT}/configure --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + --enable-languages=c,c++,fortran \ + --disable-multilib --disable-bootstrap \ + --enable-lto \ + --enable-plugins \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) \ + CFLAGS="${CFLAGS}" \ + CXXFLAGS="${CXXFLAGS}" \ + FCFLAGS="${FCFLAGS}" \ + > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + # thread sanitizer + if [ ${ENABLE_TSAN} = "__TRUE__" ]; then + # now the tricky bit... we need to recompile in particular + # libgomp with -fsanitize=thread.. there is not configure + # option for this (as far as I know). we need to go in + # the build tree and recompile / reinstall with proper + # options... this is likely to break for later version of + # gcc, tested with 5.1.0 based on + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55374#c10 + cd x86_64*/libgfortran + make clean > clean.log 2>&1 || tail -n ${LOG_LINES} clean.log + CFLAGS="${CFLAGS} -fsanitize=thread" + CXXFLAGS="${CXXFLAGS} -fsanitize=thread" + FCFLAGS="${FCFLAGS} -fsanitize=thread" + make -j $(get_nprocs) \ + CFLAGS="${CFLAGS}" \ + CXXFLAGS="${CXXFLAGS}" \ + FCFLAGS="${FCFLAGS}" \ + LDFLAGS="-B$(pwd)/../libsanitizer/tsan/.libs/ -Wl,-rpath,$(pwd)/../libsanitizer/tsan/.libs/ -fsanitize=thread" \ + > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd ../libgomp + make clean > clean.log 2>&1 || tail -n ${LOG_LINES} clean.log + make -j $(get_nprocs) \ + CFLAGS="${CFLAGS}" \ + CXXFLAGS="${CXXFLAGS}" \ + FCFLAGS="${FCFLAGS}" \ + LDFLAGS="-B$(pwd)/../libsanitizer/tsan/.libs/ -Wl,-rpath,$(pwd)/../libsanitizer/tsan/.libs/ -fsanitize=thread" \ + > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd ${GCCROOT}/obj/ + fi + cd ../.. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" + fi + check_install ${pkg_install_dir}/bin/gcc "gcc" && CC="${pkg_install_dir}/bin/gcc" || exit 1 + check_install ${pkg_install_dir}/bin/g++ "gcc" && CXX="${pkg_install_dir}/bin/g++" || exit 1 + check_install ${pkg_install_dir}/bin/gfortran "gcc" && FC="${pkg_install_dir}/bin/gfortran" || exit 1 + F90="${FC}" + F77="${FC}" + GCC_CFLAGS="-I'${pkg_install_dir}/include'" + GCC_LDFLAGS="-L'${pkg_install_dir}/lib64' -L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib64' -Wl,-rpath,'${pkg_install_dir}/lib64'" + ;; + __SYSTEM__) + echo "==================== Finding GCC from system paths ====================" + check_command gcc "gcc" && CC="$(command -v gcc)" || exit 1 + check_command g++ "gcc" && CXX="$(command -v g++)" || exit 1 + check_command gfortran "gcc" && FC="$(command -v gfortran)" || exit 1 + F90="${FC}" + F77="${FC}" + add_include_from_paths -p GCC_CFLAGS "c++" ${INCLUDE_PATHS} + add_lib_from_paths GCC_LDFLAGS "libgfortran.*" ${LIB_PATHS} + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking GCC to user paths ====================" + pkg_install_dir="${with_gcc}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/lib64" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/gcc "gcc" && CC="${pkg_install_dir}/bin/gcc" || exit 1 + check_command ${pkg_install_dir}/bin/g++ "gcc" && CXX="${pkg_install_dir}/bin/g++" || exit 1 + check_command ${pkg_install_dir}/bin/gfortran "gcc" && FC="${pkg_install_dir}/bin/gfortran" || exit 1 + F90="${FC}" + F77="${FC}" + GCC_CFLAGS="-I'${pkg_install_dir}/include'" + GCC_LDFLAGS="-L'${pkg_install_dir}/lib64' -L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib64' -Wl,-rpath,'${pkg_install_dir}/lib64'" + ;; +esac +if [ "${ENABLE_TSAN}" = "__TRUE__" ]; then + TSANFLAGS="-fsanitize=thread" +else + TSANFLAGS="" +fi +if [ "${with_gcc}" != "__DONTUSE__" ]; then + cat << EOF > "${BUILDDIR}/setup_gcc" +export CC="${CC}" +export CXX="${CXX}" +export FC="${FC}" +export F90="${F90}" +export F77="${F77}" +export AVFS_COMPILER="gcc" +export AVFS_COMPILER_VERSION="${gcc_ver}" +EOF + if [ "${with_gcc}" != "__SYSTEM__" ]; then + cat << EOF >> "${BUILDDIR}/setup_gcc" +# needs full path for mpich/openmpi builds, triggers openblas bug +prepend_path PATH "${pkg_install_dir}/bin" +prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib64" +prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" +prepend_path LD_RUN_PATH "${pkg_install_dir}/lib64" +prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path LIBRARY_PATH "${pkg_install_dir}/lib64" +prepend_path CPATH "${pkg_install_dir}/include" +EOF + mkdir -p "${MODULEDIR}/compilers/gcc" + cat << EOF > "${MODULEDIR}/compilers/gcc/${gcc_ver}" +#%Module1.0##################################################################### +## +## GNU compiler modulefile +## +proc ModulesHelp { } { + global version + + puts stderr "\tSets up GNU compiler environment" + puts stderr "\tModifies: MANPATH, LD_LIBRARY_PATH, PATH" +} + +module-whatis "load gnu environment" +module-whatis "Modifies: MANPATH, PATH, LD_LIBRARY_PATH" + +# for Tcl script use only +setenv AVFS_COMPILER "gcc" +setenv AVFS_COMPILER_VERSION "${gcc_ver}" + +set gcc_root ${pkg_install_dir} +prepend-path PATH "\$gcc_root/bin" +prepend-path LD_LIBRARY_PATH "\$gcc_root/lib:\$gcc_root/lib64" +prepend-path MANPATH "\$gcc_root/share/man" + +setenv CC gcc +setenv FC gfortran +setenv F90 gfortran +setenv CXX g++ +setenv F77 gfortran +EOF + fi + cat << EOF >> "${BUILDDIR}/setup_gcc" +export GCC_CFLAGS="${GCC_CFLAGS}" +export GCC_LDFLAGS="${GCC_LDFLAGS}" +export TSANFLAGS="${TSANFLAGS}" +EOF + cat "${BUILDDIR}/setup_gcc" >> ${SETUPFILE} +fi + +# ---------------------------------------------------------------------- +# Suppress reporting of known leaks +# ---------------------------------------------------------------------- + +# this might need to be adjusted for the versions of the software +# employed +cat << EOF >> ${INSTALLDIR}/lsan.supp +# known leak either related to mpi or scalapack (e.g. showing randomly for Fist/regtest-7-2/UO2-2x2x2-genpot_units.inp) +leak:__cp_fm_types_MOD_cp_fm_write_unformatted +# leak related to mpi or scalapack triggers sometimes for regtest-kp-2/cc2.inp +leak:Cblacs_gridmap +leak:blacs_gridmap_ +# leak due to compiler bug triggered by combination of OOP and ALLOCATABLE +leak:__dbcsr_tensor_types_MOD___copy_dbcsr_tensor_types_Dbcsr_tas_dist_t +leak:__dbcsr_tensor_types_MOD___copy_dbcsr_tensor_types_Dbcsr_tas_blk_size_t +EOF +cat << EOF >> ${INSTALLDIR}/tsan.supp +# tsan bugs likely related to gcc +# PR66756 +deadlock:_gfortran_st_open +mutex:_gfortran_st_open +# bugs related to removing/filtering blocks in DBCSR.. to be fixed +race:__dbcsr_block_access_MOD_dbcsr_remove_block +race:__dbcsr_operations_MOD_dbcsr_filter_anytype +race:__dbcsr_transformations_MOD_dbcsr_make_untransposed_blocks +EOF + +# need to also link to the .supp file in setup file +cat << EOF >> ${SETUPFILE} +export LSAN_OPTIONS=suppressions=${INSTALLDIR}/lsan.supp +export TSAN_OPTIONS=suppressions=${INSTALLDIR}/tsan.supp +EOF + +load "${BUILDDIR}/setup_gcc" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "gcc" \ No newline at end of file diff --git a/scripts/stage0/install_git.sh b/scripts/stage0/install_git.sh deleted file mode 100644 index fa3d615..0000000 --- a/scripts/stage0/install_git.sh +++ /dev/null @@ -1,17 +0,0 @@ -## INSTALL GIT FROM SOURCE -GIT_BUILD_DIR=${BUILD_LOCATION}/git -GIT_INSTALL_DIR=${INSTALL_LOCATION}/git -mkdir -p ${GIT_BUILD_DIR} -mkdir -p ${GIT_INSTALL_DIR} - -GIT_VERSION=2.11.3 - -cd ${GIT_BUILD_DIR} -wget -c https://mirrors.edge.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.gz -tar -xzf git-${GIT_VERSION}.tar.gz -cd git-${GIT_VERSION} -make configure -./configure --prefix=${GIT_INSTALL_DIR}/${GIT_VERSION} -make -j$(nproc) -make -j$(nproc) test -make install \ No newline at end of file diff --git a/scripts/stage0/install_intel.sh b/scripts/stage0/install_intel.sh old mode 100644 new mode 100755 index 44275ab..ee4bfec --- a/scripts/stage0/install_intel.sh +++ b/scripts/stage0/install_intel.sh @@ -6,39 +6,94 @@ [ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=${0} SCRIPT_DIR="$(cd "$(dirname "${SCRIPT_NAME}")/.." && pwd -P)" +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_intel" ] && rm "${BUILDDIR}/setup_intel" + INTEL_CFLAGS="" INTEL_LDFLAGS="" INTEL_LIBS="" +mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" -echo "==================== Finding Intel compiler from system paths ====================" -if [ "${intel_classic}" = "yes" ]; then - check_command icc "intel" && CC="$(realpath $(command -v icc))" || exit 1 - check_command icpc "intel" && CXX="$(realpath $(command -v icpc))" || exit 1 - check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 -else - check_command icx "intel" && CC="$(realpath $(command -v icx))" || exit 1 - check_command icpx "intel" && CXX="$(realpath $(command -v icpx))" || exit 1 - check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 -fi -F90="${FC}" -F77="${FC}" - -echo "CC is ${CC}" -echo "CXX is ${CXX}" -echo "FC is ${FC}" - +case "${with_intel}" in + __INSTALL__) + echo "==================== Installing the Intel compiler ====================" + echo "__INSTALL__ is not supported; please install the Intel compiler manually" + exit 1 + ;; + __SYSTEM__) + echo "==================== Finding Intel compiler from system paths ====================" + if [ "${intel_classic}" = "yes" ]; then + check_command icc "intel" && CC="$(realpath $(command -v icc))" || exit 1 + check_command icpc "intel" && CXX="$(realpath $(command -v icpc))" || exit 1 + check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 + else + check_command icx "intel" && CC="$(realpath $(command -v icx))" || exit 1 + check_command icpx "intel" && CXX="$(realpath $(command -v icpx))" || exit 1 + check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 + fi + F90="${FC}" + F77="${FC}" + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking Intel compiler to user paths ====================" + pkg_install_dir="${with_intel}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + if [ "${intel_classic}" = "yes" ]; then + check_command ${pkg_install_dir}/bin/icc "intel" && CC="${pkg_install_dir}/bin/icc" || exit 1 + check_command ${pkg_install_dir}/bin/icpc "intel" && CXX="${pkg_install_dir}/bin/icpc" || exit 1 + check_command ${pkg_install_dir}/bin/ifort "intel" && FC="${pkg_install_dir}/bin/ifort" || exit 1 + else + check_command ${pkg_install_dir}/bin/icx "intel" && CC="${pkg_install_dir}/bin/icx" || exit 1 + check_command ${pkg_install_dir}/bin/icpx "intel" && CXX="${pkg_install_dir}/bin/icpx" || exit 1 + check_command ${pkg_install_dir}/bin/ifort "intel" && FC="${pkg_install_dir}/bin/ifort" || exit 1 + fi + F90="${FC}" + F77="${FC}" + INTEL_CFLAGS="-I'${pkg_install_dir}/include'" + INTEL_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "${with_intel}" != "__DONTUSE__" ]; then + echo "CC is ${CC}" + echo "CXX is ${CXX}" + echo "FC is ${FC}" + cat << EOF > "${BUILDDIR}/setup_intel" export CC="${CC}" export CXX="${CXX}" export FC="${FC}" export F90="${F90}" export F77="${F77}" - -export PATH=${pkg_install_dir}/bin:${PATH} -export LD_LIBRARY_PATH=${pkg_install_dir}/lib:${LD_LIBRARY_PATH} -export LD_RUN_PATH=${pkg_install_dir}/lib:${LD_RUN_PATH} -export LIBRARY_PATH=${pkg_install_dir}/lib:${LIBRARY_PATH} -export CPATH=${pkg_install_dir}/include:${CPATH} - +EOF + if [ "${with_intel}" != "__SYSTEM__" ]; then + cat << EOF >> "${BUILDDIR}/setup_intel" +prepend_path PATH "${pkg_install_dir}/bin" +prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" +prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path CPATH "${pkg_install_dir}/include" +EOF + fi + cat << EOF >> "${BUILDDIR}/setup_intel" export INTEL_CFLAGS="${INTEL_CFLAGS}" export INTEL_LDFLAGS="${INTEL_LDFLAGS}" -export INTEL_LIBS="${INTEL_LIBS}" \ No newline at end of file +export INTEL_LIBS="${INTEL_LIBS}" +EOF + cat "${BUILDDIR}/setup_intel" >> ${SETUPFILE} +fi + +load "${BUILDDIR}/setup_intel" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "intel" diff --git a/scripts/stage0/install_llvm.sh b/scripts/stage0/install_llvm.sh old mode 100644 new mode 100755 index 94e9b67..e69de29 --- a/scripts/stage0/install_llvm.sh +++ b/scripts/stage0/install_llvm.sh @@ -1,18 +0,0 @@ -## INSTALL LLVM FROM SOURCE -LLVM_BUILD_DIR=${BUILD_LOCATION}/llvm -LLVM_INSTALL_DIR=${INSTALL_LOCATION}/llvm -mkdir -p ${LLVM_BUILD_DIR} -mkdir -p ${LLVM_INSTALL_DIR} - -LLVM_VERSION=13.0.0 - -git clone https://github.com/llvm/llvm-project.git ${LLVM_BUILD_DIR}/llvm-${LLVM_VERSION} -cd ${LLVM_BUILD_DIR}/llvm-${LLVM_VERSION} -git checkout llvmorg-${LLVM_VERSION} -mkdir build && cd build -cmake -S llvm -B build -G "Unix Makefiles" \ - -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;compiler-rt;libcxx;libcxxabi;libunwind;lld;lldb;openmp;parallel-libs;polly" \ - -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR}/${LLVM_VERSION} \ - -DLLVM_INSTALL_UTILS=ON llvm -make -j$(nproc) -make install diff --git a/scripts/stage0/install_lmod.sh b/scripts/stage0/install_lmod.sh deleted file mode 100755 index 7907720..0000000 --- a/scripts/stage0/install_lmod.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -e - -LUA_VERSION=5.1.4.9 - -wget https://sourceforge.net/projects/lmod/files/lua-${LUA_VERSION}.tar.bz2 -tar -xf lua-${LUA_VERSION}.tar.bz2 -cd lua-X.Y.Z -./configure --prefix=/avfs/projects/ops/lua/${LUA_VERSION} -make -j4 -make install -cd /avfs/projects/ops/lua -ln -s ${LUA_VERSION} lua - -LMOD_VERSION=8.7.37 - -wget https://sourceforge.net/projects/lmod/files/Lmod-${LMOD_VERSION}.tar.bz2 -tar -xf Lmod-${LMOD_VERSION}.tar.bz2 -# wget https://github.com/TACC/Lmod/archive/refs/tags/${LMOD_VERSION}.tar.gz -# tar -xf ${LMOD_VERSION}.tar.gz -cd Lmod-${LMOD_VERSION} -PATH=$PATH:/avfs/projects/ops/lua/lua/bin ./configure --prefix=/avfs/projects/ops/ \ - --with-spiderCacheDir=/avfs/projects/ops/lmod/cacheDir \ - --with-updateSystemFn=/avfs/projects/ops/lmod/cacheDir/system.txt -make install -ln -s /avfs/projects/ops/lmod/lmod/init/profile /etc/profile.d/z00_lmod.sh -ln -s /avfs/projects/ops/lmod/lmod/init/cshrc /etc/profile.d/z00_lmod.csh diff --git a/scripts/stage0/install_modules.sh b/scripts/stage0/install_modules.sh old mode 100644 new mode 100755 index ee08b75..15ef1eb --- a/scripts/stage0/install_modules.sh +++ b/scripts/stage0/install_modules.sh @@ -3,20 +3,84 @@ # TODO: Review and if possible fix shellcheck errors. # shellcheck disable=all -MODULES_VERSION=5.3.1 +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" -MODULES_BUILD_DIR=${BUILD_LOCATION} -MODULES_INSTALL_DIR=${INSTALL_LOCATION}/modules -mkdir -p ${MODULES_BUILD_DIR} -mkdir -p ${MODULES_INSTALL_DIR} +modules_ver="3.2.10" +modules_sha256="fb05c82a83477805a1d97737a9f0ca0db23f69b7bce504f1609ba99477b03955" +#modules_ver="5.3.1" +#modules_sha256="d02f9ce4f8baf6c99edceb7c73bfdd1e97d77bcc4725810b86efed9f58dda962" -cd ${MODULES_BUILD_DIR} -curl -LJO https://github.com/cea-hpc/modules/releases/download/v${MODULES_VERSION}/modules-${MODULES_VERSION}.tar.gz -tar -xf modules-${MODULES_VERSION}.tar.gz -cd modules-${MODULES_VERSION} -mkdir build && cd build -./configure --prefix=${MODULES_INSTALL_DIR}/Modules/${MODULES_VERSION} --modulefilesdir=${MODULES_INSTALL_DIR}/Modules/${MODULES_VERSION}/modulefiles -make -j$(nproc) -make install -ln -s ${MODULES_INSTALL_DIR}/Modules/${MODULES_VERSION}/init/profile.sh /etc/profile.d/modules.sh -ln -s ${MODULES_INSTALL_DIR}/Modules/${MODULES_VERSION}/init/profile.csh /etc/profile.d/modules.csh \ No newline at end of file +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_modules" ] && rm "${BUILDDIR}/setup_modules" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_modules}" in + __INSTALL__) + echo "============ Installing Environment Modules ============" + pkg_install_dir="${INSTALLDIR}/modules/Modules/${modules_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "modules-${modules_ver} is already installed, skipping it." + else + if [ -f modules-${modules_ver}.tar.gz ]; then + echo "modules-${modules_ver}.tar.gz is found" + else + wget -c https://github.com/cea-hpc/modules/releases/download/v${modules_ver}/modules-${modules_ver}.tar.gz + fi + [ -d modules-${modules_ver} ] && rm -rf modules-${modules_ver} + tar -xzf modules-${modules_ver}.tar.gz + + echo "Installing Environment Modules from scratch into ${pkg_install_dir}" + cd modules-${modules_ver} + + ./configure --prefix="${pkg_install_dir}" \ + --modulefilesdir="${pkg_install_dir}/modulefiles" \ + --enable-example-modulefiles \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) \ + > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + ln -s ${pkg_install_dir}/init/profile.sh /etc/profile.d/modules.sh + ln -s ${pkg_install_dir}/init/profile.csh /etc/profile.d/modules.csh + + mkdir "${pkg_install_dir}/modulefiles/apps" + mkdir "${pkg_install_dir}/modulefiles/compilers" + mkdir "${pkg_install_dir}/modulefiles/mpi" + mkdir "${pkg_install_dir}/modulefiles/science" + mkdir "${pkg_install_dir}/modulefiles/tools" + + cd ../.. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" + fi + # check_install ${pkg_install_dir}/bin/gcc "gcc" && CC="${pkg_install_dir}/bin/gcc" || exit 1 + + ;; + __SYSTEM__) + echo "==================== Finding GCC from system paths ====================" + + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + ;; +esac + +cat << EOF > "${BUILDDIR}/setup_modules" +export MODULEDIR=/avfs/projects/ops/modules/Modules/4.0.0/modulefiles +EOF +cat "${BUILDDIR}/setup_modules" >> ${SETUPFILE} + +load "${BUILDDIR}/setup_modules" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "modules" \ No newline at end of file diff --git a/scripts/stage0/install_openssl.sh b/scripts/stage0/install_openssl.sh deleted file mode 100644 index ed961da..0000000 --- a/scripts/stage0/install_openssl.sh +++ /dev/null @@ -1,16 +0,0 @@ -SSL_VERSION=1.1.1w - -SSL_BUILD_DIR=${BUILD_LOCATION}/openssl -SSL_INSTALL_DIR=${INSTALL_LOCATION}/openssl -mkdir -p ${SSL_BUILD_DIR} -mkdir -p ${SSL_INSTALL_DIR} - -cd ${SSL_BUILD_DIR} -wget -c https://www.openssl.org/source/openssl-${SSL_VERSION}.tar.gz -tar -xf openssl-${SSL_VERSION}.tar.gz -cd openssl-${SSL_VERSION} -mkdir build && cd build -../config --prefix=${SSL_INSTALL_DIR}/${SSL_VERSION} --openssldir=${SSL_INSTALL_DIR}/${SSL_VERSION} -make -j$(nproc) -make -j$(nproc) test -make install \ No newline at end of file diff --git a/scripts/stage0/install_python.sh b/scripts/stage0/install_python.sh new file mode 100755 index 0000000..9c8b6d7 --- /dev/null +++ b/scripts/stage0/install_python.sh @@ -0,0 +1,108 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +python_ver="3.11.7" +python_sha256="d96c7e134c35a8c46236f8a0e566b69c" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_python" ] && rm "${BUILDDIR}/setup_python" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_python}" in + __INSTALL__) + echo "================= Installing Python ====================" + pkg_install_dir="${INSTALLDIR}/python/${python_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "python-${python_ver} is already installed, skipping it." + else + if [ -f Python-${python_ver}.tar.xz ]; then + echo "Python-${python_ver}.tar.xz is found" + else + wget -c https://www.python.org/ftp/python/${python_ver}/Python-${python_ver}.tar.xz + fi + [ -d Python-${python_ver} ] && rm -rf Python-${python_ver} + tar -xf Python-${python_ver}.tar.xz + + echo "Installing Python from scratch into ${pkg_install_dir}" + cd Python-${python_ver} + + ./configure --prefix="${pkg_install_dir}" \ + --enable-optimizations \ + --with-ensurepip \ + --with-openssl=${SSLBASE} \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) \ + > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install \ + > install.log 2>&1 || tail -n ${LOG_LINES} install.log + + cd ../.. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" + fi + check_install ${pkg_install_dir}/bin/python3 "python3" || exit 1 + check_install ${pkg_install_dir}/bin/pip3 "pip3" || exit 1 + ;; + __SYSTEM__) + echo "================== Finding Python from system paths ===================" + check_command python3 "python3" || exit 1 + check_command pip3 "pip3" || exit 1 + + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "================== Linking Python to user paths ===================" +esac +if [ "${with_python}" != "__DONTUSE__" ]; then + cat << EOF > "${BUILDDIR}/setup_python" +export PYTHONHOME="${pkg_install_dir}" +export PATH="\${PYTHONHOME}/bin:\${PATH}" +export LD_LIBRARY_PATH="\${PYTHONHOME}/lib:\${LD_LIBRARY_PATH}" +EOF + if [ "${with_python}" != "__SYSTEM__" ]; then + mkdir -p "${MODULEDIR}/tools/python" + cat < "${MODULEDIR}/tools/python/${python_ver}" +#%Module1.0##################################################################### +## +## Python ${python_ver} modulefile +## +proc ModulesHelp { } { + puts stderr "\tSets up environment for Python v${python_ver}" +} + +module-whatis "sets up python environment" +module-whatis "Modifies: MANPATH, PATH, PYTHONHOME, LD_LIBRARY_PATH" + +# for Tcl script use only +set python_root ${pkg_install_dir} + +setenv PYTHONHOME "\$python_root" +prepend-path PATH \$python_root/bin +prepend-path LD_LIBRARY_PATH \$python_root/lib +prepend-path MANPATH \$python_root/man + +conflict python + +EOF + fi +fi + +load "${BUILDDIR}/setup_python" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "python" diff --git a/scripts/stage0/install_qt.sh b/scripts/stage0/install_qt.sh deleted file mode 100644 index bcfea9f..0000000 --- a/scripts/stage0/install_qt.sh +++ /dev/null @@ -1,21 +0,0 @@ -## INSTALL Qt FOR CMAKE-GUI -QT_BUILD_DIR=${BUILD_LOCATION}/qt -QT_INSTALL_DIR=${INSTALL_LOCATION}/qt -mkdir -p ${QT_BUILD_DIR} -mkdir -p ${QT_INSTALL_DIR} - -## SOME COMBINATION WILL INSTALL GL -# install build-essential libgl1-mesa-dev libglu1-mesa-dev libglut-dev libgl2-mesa-dev libdrm-dev - -# wget -c https://qt.mirror.constant.com/archive/online_installers/4.6/qt-unified-linux-x64-4.6.1-online.run - -QT_VERSION=5.15.12 -QT_MAJOR_VERSION=$(echo ${QT_VERSION} | cut -d. -f1-2) - -cd ${QT_BUILD_DIR} -wget -c https://download.qt.io/official_releases/qt/${QT_MAJOR_VERSION}/${QT_VERSION}/single/qt-everywhere-opensource-src-${QT_VERSION}.tar.xz -tar -xf qt-everywhere-opensource-src-${QT_VERSION}.tar.xz -cd qt-everywhere-opensource-src-${QT_VERSION} -mkdir build && cd build -../configure -prefix ${QT_INSTALL_DIR}/${QT_VERSION} -make tests -release -opensource -confirm-license -##### THIS COMMAND NEEDS TO BE FINISHED##### \ No newline at end of file diff --git a/scripts/stage0/install_ssl.sh b/scripts/stage0/install_ssl.sh new file mode 100755 index 0000000..de363e9 --- /dev/null +++ b/scripts/stage0/install_ssl.sh @@ -0,0 +1,101 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +ssl_ver="1.1.1w" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_ssl" ] && rm "${BUILDDIR}/setup_ssl" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_ssl}" in + __INSTALL__) + echo "================== Installing OpenSSL ==================" + pkg_install_dir="${INSTALLDIR}/openssl/${ssl_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "openssl-${ssl_ver} is already installed, skipping it." + else + if [ -f openssl-${ssl_ver}.tar.xz ]; then + echo "openssl-${ssl_ver}.tar.xz is found" + else + wget -c https://www.openssl.org/source/openssl-${ssl_ver}.tar.gz + fi + + [ -d openssl-${ssl_ver} ] && rm -rf openssl-${ssl_ver} + tar -xf openssl-${ssl_ver}.tar.gz + + echo "Installing OpenSSL from scratch into ${pkg_install_dir}" + cd openssl-${ssl_ver} + ./config --prefix="${pkg_install_dir}" \ + --openssldir=${pkg_install_dir} \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) \ + > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) test + make -j $(get_nprocs) install \ + > install.log 2>&1 || tail -n ${LOG_LINES} install.log + + cd ../.. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" + fi + check_install ${pkg_install_dir}/bin/openssl "openssl" || exit 1 + ;; + __SYSTEM__) + check_command openssl "openssl" || exit 1 + ;; + __DONTUSE__) + # Nothing to do + ;; + *) +esac +if [ "${with_ssl}" != "__DONTUSE__" ]; then + if [ "${with_python}" != "__SYSTEM__" ]; then + mkdir -p "${MODULEDIR}/tools/openssl" + cat << EOF > "${MODULEDIR}/tools/openssl/${ssl_ver}" +#%Module1.0##################################################################### +## +## OpenSSL ${ssl_ver} modulefile +## +proc ModulesHelp { } { + puts stderr "\tSets up environment for OpenSSL v${ssl_ver}" +} + +module-whatis "sets up python environment" +module-whatis "Modifies: MANPATH, PATH, PYTHONHOME, LD_LIBRARY_PATH" + +# for Tcl script use only +set openssl_root ${pkg_install_dir} + +setenv SSLHOME \$openssl_root +prepend-path PATH \$openssl_root/bin +prepend-path LD_LIBRARY_PATH \$openssl_root/lib + +conflict openssl +EOF + fi + cat << EOF >> "${BUILDDIR}/setup_ssl" +export PATH="${pkg_install_dir}/bin:\${PATH}" +export LD_LIBRARY_PATH="${pkg_install_dir}/lib:\${LD_LIBRARY_PATH}" +export SSLBASE="${pkg_install_dir}" +EOF + cat "${BUILDDIR}/setup_ssl" >> ${SETUPFILE} +fi + + +load "${BUILDDIR}/setup_ssl" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "openssl" diff --git a/scripts/stage0/install_stage0.sh b/scripts/stage0/install_stage0.sh old mode 100644 new mode 100755 index c2971cd..b59c422 --- a/scripts/stage0/install_stage0.sh +++ b/scripts/stage0/install_stage0.sh @@ -3,16 +3,12 @@ # TODO: Review and if possible fix shellcheck errors. # shellcheck disable=all -./scripts/stage0/install_gcc.sh -./scripts/stage0/install_beegfs.sh ./scripts/stage0/install_modules.sh -./scripts/stage0/install_binutils.sh -./scripts/stage0/install_llvm.sh +./scripts/stage0/install_gcc.sh ./scripts/stage0/install_intel.sh ./scripts/stage0/setup_buildtools.sh -./scripts/stage0/install_openssl.sh -./scripts/stage0/install_git.sh -./scripts/stage0/install_qt.sh ./scripts/stage0/install_cmake.sh +./scripts/stage0/install_ssl.sh +./scripts/stage0/install_python.sh -#EOF \ No newline at end of file +#EOF diff --git a/scripts/stage0/setup_buildtools.sh b/scripts/stage0/setup_buildtools.sh old mode 100644 new mode 100755 index 00ca109..1d6c7ed --- a/scripts/stage0/setup_buildtools.sh +++ b/scripts/stage0/setup_buildtools.sh @@ -69,4 +69,4 @@ load "${BUILDDIR}/openblas_arch" write_toolchain_env "${INSTALLDIR}" -#EOF \ No newline at end of file +#EOF diff --git a/scripts/stage1/install_intelmpi.sh b/scripts/stage1/install_intelmpi.sh new file mode 100755 index 0000000..0e06832 --- /dev/null +++ b/scripts/stage1/install_intelmpi.sh @@ -0,0 +1,129 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ ${MPI_MODE} != "intelmpi" ] && exit 0 +rm -f "${BUILDDIR}/setup_intelmpi" + +INTELMPI_CFLAGS="" +INTELMPI_LDFLAGS="" +INTELMPI_LIBS="" +mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_intelmpi}" in + __INSTALL__) + echo "==================== Installing Intel MPI ====================" + echo '__INSTALL__ is not supported; please manually install Intel MPI' + exit 1 + ;; + __SYSTEM__) + echo "==================== Finding Intel MPI from system paths ====================" + check_command mpiexec "intelmpi" && MPIRUN="$(realpath $(command -v mpiexec))" + if [ "${with_intel}" != "__DONTUSE__" ]; then + check_command mpiicc "intelmpi" && MPICC="$(realpath $(command -v mpiicc))" || exit 1 + check_command mpiicpc "intelmpi" && MPICXX="$(realpath $(command -v mpiicpc))" || exit 1 + check_command mpiifort "intelmpi" && MPIFC="$(realpath $(command -v mpiifort))" || exit 1 + else + echo "The use of Intel MPI is only supported with the Intel compiler" + exit 1 + fi + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + # include path is already handled by compiler wrapper scripts (can cause wrong mpi.mod with GNU Fortran) + # add_include_from_paths INTELMPI_CFLAGS "mpi.h" $INCLUDE_PATHS + add_lib_from_paths INTELMPI_LDFLAGS "libmpi.*" $LIB_PATHS + check_lib -lmpi "intelmpi" + check_lib -lmpicxx "intelmpi" + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking INTELMPI to user paths ====================" + pkg_install_dir="${with_intelmpi}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/mpiexec "intel" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + if [ "${with_intel}" != "__DONTUSE__" ]; then + check_command ${pkg_install_dir}/bin/mpiicc "intel" && MPICC="${pkg_install_dir}/bin/mpiicc" || exit 1 + check_command ${pkg_install_dir}/bin/mpiicpc "intel" && MPICXX="${pkg_install_dir}/bin/mpiicpc" || exit 1 + check_command ${pkg_install_dir}/bin/mpiifort "intel" && MPIFC="${pkg_install_dir}/bin/mpiifort" || exit 1 + else + echo "The use of Intel MPI is only supported with the Intel compiler" + exit 1 + fi + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + # include path is already handled by compiler wrapper scripts (can cause wrong mpi.mod with GNU Fortran) + #INTELMPI_CFLAGS="-I'${pkg_install_dir}/include'" + INTELMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "${with_intelmpi}" != "__DONTUSE__" ]; then + if [ "${intel_classic}" = "yes" ]; then + I_MPI_CXX="icpc" + I_MPI_CC="icc" + I_MPI_FC="ifort" + else + I_MPI_CXX="icpx" + I_MPI_CC="icx" + I_MPI_FC="ifort" + fi + INTELMPI_LIBS="-lmpi -lmpicxx" + echo "I_MPI_CXX is ${I_MPI_CXX}" + echo "I_MPI_CC is ${I_MPI_CC}" + echo "I_MPI_FC is ${I_MPI_FC}" + echo "MPICXX is ${MPICXX}" + echo "MPICC is ${MPICC}" + echo "MPIFC is ${MPIFC}" + cat << EOF > "${BUILDDIR}/setup_intelmpi" +export I_MPI_CXX="${I_MPI_CXX}" +export I_MPI_CC="${I_MPI_CC}" +export I_MPI_FC="${I_MPI_FC}" +export MPI_MODE="${MPI_MODE}" +export MPIRUN="${MPIRUN}" +export MPICC="${MPICC}" +export MPICXX="${MPICXX}" +export MPIFC="${MPIFC}" +export MPIFORT="${MPIFORT}" +export MPIF77="${MPIF77}" +export INTELMPI_CFLAGS="${INTELMPI_CFLAGS}" +export INTELMPI_LDFLAGS="${INTELMPI_LDFLAGS}" +export INTELMPI_LIBS="${INTELMPI_LIBS}" +export MPI_CFLAGS="${INTELMPI_CFLAGS}" +export MPI_LDFLAGS="${INTELMPI_LDFLAGS}" +export MPI_LIBS="${INTELMPI_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__parallel -D__MPI_F08|)" +export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${INTELMPI_CFLAGS}|)" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${INTELMPI_LDFLAGS}|)" +export CP_LIBS="\${CP_LIBS} IF_MPI(${INTELMPI_LIBS}|)" +EOF + if [ "${with_intelmpi}" != "__SYSTEM__" ]; then + cat << EOF >> "${BUILDDIR}/setup_intelmpi" +prepend_path PATH "${pkg_install_dir}/bin" +prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" +prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path CPATH "${pkg_install_dir}/include" +EOF + fi + cat "${BUILDDIR}/setup_intelmpi" >> ${SETUPFILE} +fi + +load "${BUILDDIR}/setup_intelmpi" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "intelmpi" diff --git a/scripts/stage1/install_mpich.sh b/scripts/stage1/install_mpich.sh new file mode 100755 index 0000000..c1354c3 --- /dev/null +++ b/scripts/stage1/install_mpich.sh @@ -0,0 +1,213 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +mpich_ver="4.0.3" +mpich_sha256="17406ea90a6ed4ecd5be39c9ddcbfac9343e6ab4f77ac4e8c5ebe4a3e3b6c501" +mpich_pkg="mpich-${mpich_ver}.tar.gz" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ ${MPI_MODE} != "mpich" ] && exit 0 +[ -f "${BUILDDIR}/setup_mpich" ] && rm "${BUILDDIR}/setup_mpich" + +MPICH_CFLAGS="" +MPICH_LDFLAGS="" +MPICH_LIBS="" +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_mpich}" in + __INSTALL__) + echo "==================== Installing MPICH ====================" + pkg_install_dir="${INSTALLDIR}/mpich/${mpich_ver}/${AVFS_COMPILER}/${AVFS_COMPILER_VERSION}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "mpich-${mpich_ver} is already installed, skipping it." + else + if [ -f ${mpich_pkg} ]; then + echo "${mpich_pkg} is found" + else + download_pkg_from_cp2k_org "${mpich_sha256}" "${mpich_pkg}" + fi + echo "Installing from scratch into ${pkg_install_dir} for MPICH device ${MPICH_DEVICE}" + [ -d mpich-${mpich_ver} ] && rm -rf mpich-${mpich_ver} + tar -xzf ${mpich_pkg} + cd mpich-${mpich_ver} + unset F90 + unset F90FLAGS + + # workaround for compilation with GCC >= 10, until properly fixed: + # https://github.com/pmodels/mpich/issues/4300 + if ("${FC}" --version | grep -q 'GNU'); then + compat_flag=$(allowed_gfortran_flags "-fallow-argument-mismatch") + fi + ./configure \ + --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + MPICC="" \ + FFLAGS="${FCFLAGS} ${compat_flag}" \ + FCFLAGS="${FCFLAGS} ${compat_flag}" \ + --without-x \ + --enable-gl=no \ + --with-device=${MPICH_DEVICE} \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage1/$(basename ${SCRIPT_NAME})" + fi + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_install ${pkg_install_dir}/bin/mpiexec "mpich" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_install ${pkg_install_dir}/bin/mpicc "mpich" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_install ${pkg_install_dir}/bin/mpicxx "mpich" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 + check_install ${pkg_install_dir}/bin/mpifort "mpich" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + MPICH_CFLAGS="-I'${pkg_install_dir}/include'" + MPICH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding MPICH from system paths ====================" + check_command mpiexec "mpich" && MPIRUN="$(command -v mpiexec)" + check_command mpicc "mpich" && MPICC="$(command -v mpicc)" || exit 1 + if [ $(command -v mpic++ > /dev/null 2>&1) ]; then + check_command mpic++ "mpich" && MPICXX="$(command -v mpic++)" || exit 1 + else + check_command mpicxx "mpich" && MPICXX="$(command -v mpicxx)" || exit 1 + fi + check_command mpifort "mpich" && MPIFC="$(command -v mpifort)" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + check_lib -lmpifort "mpich" + check_lib -lmpicxx "mpich" + check_lib -lmpi "mpich" + add_include_from_paths MPICH_CFLAGS "mpi.h" ${INCLUDE_PATHS} + add_lib_from_paths MPICH_LDFLAGS "libmpi.*" ${LIB_PATHS} + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking MPICH to user paths ====================" + pkg_install_dir="${with_mpich}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/mpiexec "mpich" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_command ${pkg_install_dir}/bin/mpicc "mpich" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_command ${pkg_install_dir}/bin/mpicxx "mpich" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 + check_command ${pkg_install_dir}/bin/mpifort "mpich" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + MPICH_CFLAGS="-I'${pkg_install_dir}/include'" + MPICH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "${with_mpich}" != "__DONTUSE__" ]; then + if [ "${with_mpich}" != "__SYSTEM__" ]; then + mpi_bin="${pkg_install_dir}/bin/mpiexec" + else + mpi_bin="mpiexec" + fi + MPICH_LIBS="-lmpifort -lmpicxx -lmpi" + cat << EOF > "${BUILDDIR}/setup_mpich" +export MPI_MODE="${MPI_MODE}" +export MPIRUN="${MPIRUN}" +export MPICC="${MPICC}" +export MPICXX="${MPICXX}" +export MPIFC="${MPIFC}" +export MPIFORT="${MPIFORT}" +export MPIF77="${MPIF77}" +export MPICH_CFLAGS="${MPICH_CFLAGS}" +export MPICH_LDFLAGS="${MPICH_LDFLAGS}" +export MPICH_LIBS="${MPICH_LIBS}" +export MPI_CFLAGS="${MPICH_CFLAGS}" +export MPI_LDFLAGS="${MPICH_LDFLAGS}" +export MPI_LIBS="${MPICH_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__parallel|)" +export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${MPICH_CFLAGS}|)" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${MPICH_LDFLAGS}|)" +export CP_LIBS="\${CP_LIBS} IF_MPI(${MPICH_LIBS}|)" +EOF + if [ "${with_mpich}" != "__SYSTEM__" ]; then + # Using append_path instead of prepend_path for compatibility with Shifter. + # See http://github.com/cp2k/cp2k/issues/2058 + cat << EOF >> "${BUILDDIR}/setup_mpich" +append_path PATH "${pkg_install_dir}/bin" +append_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" +append_path LD_RUN_PATH "${pkg_install_dir}/lib" +append_path LIBRARY_PATH "${pkg_install_dir}/lib" +append_path CPATH "${pkg_install_dir}/include" +EOF + mkdir -p "${MODULEDIR}/mpi/mpich" + cat << EOF > "${MODULEDIR}/mpi/mpich/${mpich_ver}" +#%Module1.0 +## +## MPICH ${mpich_ver} modulefile +## +proc ModulesHelp { } { + global version + + puts stderr "\tThis loads the MPICH ${mpich_ver} environment." + puts stderr "\tModifies: MPI_ROOT, MANPATH, PATH, LD_LIBRARY_PATH, AVFS_MPI, AVFS_MPI_VERSION, IBV_FORK_SAFE" +} + +module-whatis "load MPICH${mpich_ver} environment" +module-whatis "Modifies: MPI_ROOT, MANPATH, PATH, LD_LIBRARY_PATH, AVFS_MPI, AVFS_MPI_VERSION, IBV_FORK_SAFE" + + +# for Tcl script use only +if { [info exists env(AVFS_COMPILER) ] } { + set compiler_type \$env(AVFS_COMPILER) +} else { + puts stderr "\tNo compiler loaded." + exit +} +if { [info exists env(AVFS_COMPILER_VERSION) ] } { + set compiler_version \$env(AVFS_COMPILER_VERSION) +} else { + puts stderr "\tError in \$compiler_type module: AVFS_COMPILER_VERSION not set, please notify administrator" + exit +} + +set mpi_root "${INSTALLDIR}/mpich/${mpich_ver}/\${compiler_type}/\${compiler_version}" +if { ! [file exists \$mpi_root ] } { + puts stderr "\t The combination of compiler and MPI does not appear to be built yet" + exit +} + +setenv MPI_ROOT "\$mpi_root" +setenv AVFS_MPI "mvapich2" +setenv AVFS_MPI_VERSION "${mpich_ver}" +setenv IBV_FORK_SAFE 1 +prepend-path PATH "\$mpi_root/bin" +prepend-path LD_LIBRARY_PATH "\$mpi_root/lib" +prepend-path MANPATH "\$mpi_root/share/man" +EOF + fi + cat "${BUILDDIR}/setup_mpich" >> ${SETUPFILE} +fi + +# Update leak suppression file +cat << EOF >> ${INSTALLDIR}/lsan.supp +# MPICH 3.3.2 with GCC 10.3.0 +leak:MPIR_Find_local_and_external +leak:MPIU_Find_local_and_external +EOF + +load "${BUILDDIR}/setup_mpich" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "mpich" diff --git a/scripts/stage1/install_openmpi.sh b/scripts/stage1/install_openmpi.sh old mode 100644 new mode 100755 index c1c314b..722e4ba --- a/scripts/stage1/install_openmpi.sh +++ b/scripts/stage1/install_openmpi.sh @@ -1,46 +1,285 @@ -#!/bin/bash +#!/bin/bash -e -if [[ "$BASH_SOURCE" == "$0" ]]; then - BUILD_LOCATION=${PWD} - INSTALL_LOCATION=/people/parl703 - TARGET_CPU="native" - CFLAGS="-O2 -fPIC -fno-omit-frame-pointer -fopenmp -g -march=${TARGET_CPU} -mtune=${TARGET_CPU}" - FFLAGS="${CFLAGS} -fbacktrace" - CXXFLAGS="${CFLAGS}" - F77FLAGS="${FFLAGS}" - F90FLAGS="${FFLAGS}" - FCFLAGS="${FFLAGS}" - LOG_LINES=200 -else - source ${BUILD_LOCATION}/build.env - ROOT=${PWD} +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +openmpi_ver="4.1.5" +openmpi_sha256="c018b127619d2a2a30c1931f316fc8a245926d0f5b4ebed4711f9695e7f70925" +openmpi_pkg="openmpi-${openmpi_ver}.tar.gz" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ ${MPI_MODE} != "openmpi" ] && exit 0 +[ -f "${BUILDDIR}/setup_openmpi" ] && rm "${BUILDDIR}/setup_openmpi" + +OPENMPI_CFLAGS="" +OPENMPI_LDFLAGS="" +OPENMPI_LIBS="" +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_openmpi}" in + __INSTALL__) + echo "==================== Installing OpenMPI ====================" + pkg_install_dir="${INSTALLDIR}/openmpi/${openmpi_ver}/${AVFS_COMPILER}/${AVFS_COMPILER_VERSION}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "openmpi-${openmpi_ver} is already installed, skipping it." + else + if [ -f ${openmpi_pkg} ]; then + echo "${openmpi_pkg} is found" + else + download_pkg_from_cp2k_org "${openmpi_sha256}" "${openmpi_pkg}" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d openmpi-${openmpi_ver} ] && rm -rf openmpi-${openmpi_ver} + tar -xzf ${openmpi_pkg} + cd openmpi-${openmpi_ver} + if [ "${OPENBLAS_ARCH}" = "x86_64" ]; then + # can have issue with older glibc libraries, in which case + # we need to add the -fgnu89-inline to CFLAGS. We can check + # the version of glibc using ldd --version, as ldd is part of + # glibc package + glibc_version=$(ldd --version | awk '/ldd/{print $NF}') + glibc_major_ver=${glibc_version%%.*} + glibc_minor_ver=${glibc_version##*.} + if [ $glibc_major_ver -lt 2 ] || + [ $glibc_major_ver -eq 2 -a $glibc_minor_ver -lt 12 ]; then + CFLAGS="${CFLAGS} -fgnu89-inline" + fi + fi + if [ $(command -v srun) ]; then + echo "Slurm installation found. OpenMPI will be configured with --with-pmi." + EXTRA_CONFIGURE_FLAGS="--with-pmi" + else + EXTRA_CONFIGURE_FLAGS="" + fi + # We still require MPI-1.0-compatability for PTSCOTCH + ./configure CFLAGS="${CFLAGS}" \ + --prefix=${pkg_install_dir} \ + --libdir="${pkg_install_dir}/lib" \ + --enable-mpi1-compatibility \ + ${EXTRA_CONFIGURE_FLAGS} \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage1/$(basename ${SCRIPT_NAME})" + fi + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_install ${pkg_install_dir}/bin/mpiexec "openmpi" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_install ${pkg_install_dir}/bin/mpicc "openmpi" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_install ${pkg_install_dir}/bin/mpicxx "openmpi" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 + check_install ${pkg_install_dir}/bin/mpifort "openmpi" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + OPENMPI_CFLAGS="-I'${pkg_install_dir}/include'" + OPENMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding OpenMPI from system paths ====================" + check_command mpiexec "openmpi" && MPIRUN="$(command -v mpiexec)" + check_command mpicc "openmpi" && MPICC="$(command -v mpicc)" || exit 1 + check_command mpic++ "openmpi" && MPICXX="$(command -v mpic++)" || exit 1 + check_command mpifort "openmpi" && MPIFC="$(command -v mpifort)" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + # Fortran code in CP2K is built via the mpifort wrapper, but we may need additional + # libraries and linker flags for C/C++-based MPI codepaths, pull them in at this point. + OPENMPI_CFLAGS="$(mpicxx --showme:compile)" + OPENMPI_LDFLAGS="$(mpicxx --showme:link)" + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking OpenMPI to user paths ====================" + pkg_install_dir="${with_openmpi}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/mpiexec "openmpi" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_command ${pkg_install_dir}/bin/mpicc "openmpi" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_command ${pkg_install_dir}/bin/mpic++ "openmpi" && MPICXX="${pkg_install_dir}/bin/mpic++" || exit 1 + check_command ${pkg_install_dir}/bin/mpifort "openmpi" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + OPENMPI_CFLAGS="-I'${pkg_install_dir}/include'" + OPENMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "${with_openmpi}" != "__DONTUSE__" ]; then + if [ "${with_openmpi}" != "__SYSTEM__" ]; then + mpi_bin="${pkg_install_dir}/bin/mpiexec" + mpicxx_bin="${pkg_install_dir}/bin/mpicxx" + else + mpi_bin="mpiexec" + mpicxx_bin="mpicxx" + fi + # check openmpi version as reported by mpiexec + raw_version=$(${mpi_bin} --version 2>&1 | + grep "(Open MPI)" | awk '{print $4}') + major_version=$(echo ${raw_version} | cut -d '.' -f 1) + minor_version=$(echo ${raw_version} | cut -d '.' -f 2) + OPENMPI_LIBS="" + # grab additional runtime libs (for C/C++) from the mpicxx wrapper, + # and remove them from the LDFLAGS if present + for lib in $("${mpicxx_bin}" --showme:libs); do + OPENMPI_LIBS+=" -l${lib}" + OPENMPI_LDFLAGS="${OPENMPI_LDFLAGS//-l${lib}/}" + done + cat << EOF > "${BUILDDIR}/setup_openmpi" +export MPI_MODE="${MPI_MODE}" +export MPIRUN="${MPIRUN}" +export MPICC="${MPICC}" +export MPICXX="${MPICXX}" +export MPIFC="${MPIFC}" +export MPIFORT="${MPIFORT}" +export MPIF77="${MPIF77}" +export OPENMPI_CFLAGS="${OPENMPI_CFLAGS}" +export OPENMPI_LDFLAGS="${OPENMPI_LDFLAGS}" +export OPENMPI_LIBS="${OPENMPI_LIBS}" +export MPI_CFLAGS="${OPENMPI_CFLAGS}" +export MPI_LDFLAGS="${OPENMPI_LDFLAGS}" +export MPI_LIBS="${OPENMPI_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__parallel|)" +# For proper mpi_f08 support, we need at least GCC version 9 (asynchronous keyword) +# Other compilers should work + if ! [ "$(gfortran -dumpversion | cut -d. -f1)" -lt 9 ]; then + export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__MPI_F08|)" + fi +export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${OPENMPI_CFLAGS}|)" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${OPENMPI_LDFLAGS}|)" +export CP_LIBS="\${CP_LIBS} IF_MPI(${OPENMPI_LIBS}|)" +EOF + if [ "${with_openmpi}" != "__SYSTEM__" ]; then + cat << EOF >> "${BUILDDIR}/setup_openmpi" +prepend_path PATH "${pkg_install_dir}/bin" +prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" +prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path CPATH "${pkg_install_dir}/include" +EOF + mkdir -p "${MODULEDIR}/mpi/openmpi" + cat << EOF > "${MODULEDIR}/mpi/openmpi/${openmpi_ver}" +#%Module1.0 +## +## OpenMPI ${openmpi_ver} modulefile +## +proc ModulesHelp { } { + global version + + puts stderr "\tThis loads the OpenMPI ${openmpi_ver} environment." + puts stderr "\tModifies: MPI_ROOT, MANPATH, PATH, LD_LIBRARY_PATH, AVFS_MPI, AVFS_MPI_VERSION, IBV_FORK_SAFE" +} + +module-whatis "load OPENMPI${openmpi_ver} environment" +module-whatis "Modifies: MPI_ROOT, MANPATH, PATH, LD_LIBRARY_PATH, AVFS_MPI, AVFS_MPI_VERSION, IBV_FORK_SAFE" + + +# for Tcl script use only +if { [info exists env(AVFS_COMPILER) ] } { + set compiler_type \$env(AVFS_COMPILER) +} else { + puts stderr "\tNo compiler loaded." + exit +} +if { [info exists env(AVFS_COMPILER_VERSION) ] } { + set compiler_version \$env(AVFS_COMPILER_VERSION) +} else { + puts stderr "\tError in \$compiler_type module: AVFS_COMPILER_VERSION not set, please notify administrator" + exit +} + +set mpi_root "${INSTALLDIR}/openmpi/${openmpi_ver}/\${compiler_type}/\${compiler_version}" +if { ! [file exists \$mpi_root ] } { + puts stderr "\t The combination of compiler and MPI does not appear to be built yet" + exit +} + +setenv MPI_ROOT "\$mpi_root" +setenv AVFS_MPI "openmpi" +setenv AVFS_MPI_VERSION "${openmpi_ver}" +setenv IBV_FORK_SAFE 1 +prepend-path PATH "\$mpi_root/bin" +prepend-path LD_LIBRARY_PATH "\$mpi_root/lib" +prepend-path MANPATH "\$mpi_root/share/man" +EOF + fi + cat "${BUILDDIR}/setup_openmpi" >> ${SETUPFILE} fi -MPI_VERSION=4.1.5 +# ---------------------------------------------------------------------- +# Suppress reporting of known leaks +# ---------------------------------------------------------------------- +cat << EOF >> ${INSTALLDIR}/valgrind.supp +{ + + Memcheck:Leak + ... + fun:*alloc + ... + fun:ompi_mpi_init +} +{ + + Memcheck:Leak + ... + fun:*alloc + ... + fun:ompi_mpi_finalize +} +{ + + Memcheck:Leak + ... + fun:malloc + fun:opal_free_list_grow_st + ... + fun:mpi_alloc_mem +} +{ + + Memcheck:Leak + ... + fun:malloc + ... + fun:progress_engine + ... + fun:clone +} +{ + + Memcheck:Leak + ... + fun:malloc + ... + fun:query_2_0_0 + ... + fun:ompi_comm_activate +} +EOF +cat << EOF >> ${INSTALLDIR}/lsan.supp +# leaks related to OpenMPI +leak:query_2_0_0 +leak:ompi_init_f +leak:ompi_finalize_f +leak:ompi_file_open_f +leak:progress_engine +leak:__GI___strdup +EOF -OPENMPI_BUILD_DIR=${BUILD_LOCATION}/openmpi -OPENMPI_INSTALL_DIR=${INSTALL_LOCATION}/openmpi/${MPI_VERSION} -mkdir -p ${OPENMPI_BUILD_DIR} -mkdir -p ${OPENMPI_INSTALL_DIR} +load "${BUILDDIR}/setup_openmpi" +write_toolchain_env "${INSTALLDIR}" -cd ${OPENMPI_BUILD_DIR} -wget -c https://www.openmpi.org/openmpi-${MPI_VERSION}.tar.gz -tar -xf openmpi-${MPI_VERSION}.tar.gz -cd openmpi-${MPI_VERSION} -mkdir build && cd build - -if [ "MPI_ENABLED" = false ]; then - exit 1 -fi - -echo ${FFTW_INSTALL_DIR} -./configure --prefix=${FFTW_INSTALL_DIR} ${FFTW_FLAGS} -make -j$(nproc) -make -j$(nproc) check > check.log 2>&1 || tail -n ${LOG_LINES} check.log -make -j$(nproc) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log - -if [[ "$BASH_SOURCE" != "$0" ]]; then - cd ${ROOT} -else - echo "Exiting ..." -fi +cd "${ROOTDIR}" +report_timing "openmpi" diff --git a/scripts/stage1/install_stage1.sh b/scripts/stage1/install_stage1.sh new file mode 100755 index 0000000..e6d0e9f --- /dev/null +++ b/scripts/stage1/install_stage1.sh @@ -0,0 +1,10 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +./scripts/stage1/install_mpich.sh +./scripts/stage1/install_openmpi.sh +./scripts/stage1/install_intelmpi.sh + +#EOF diff --git a/scripts/stage2/install_acml.sh b/scripts/stage2/install_acml.sh new file mode 100755 index 0000000..1cd17cd --- /dev/null +++ b/scripts/stage2/install_acml.sh @@ -0,0 +1,70 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_acml" ] && rm "${BUILDDIR}/setup_acml" + +ACML_CFLAGS='' +ACML_LDFLAGS='' +ACML_LIBS='' +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_acml" in + __INSTALL__) + echo "==================== Installing ACML ====================" + report_error $LINENO "To install ACML you should either contact your system administrator or go to https://developer.amd.com/tools-and-sdks/archive/amd-core-math-library-acml/acml-downloads-resources/ and download the correct version for your system." + exit 1 + ;; + __SYSTEM__) + echo "==================== Finding ACML from system paths ====================" + check_lib -lacml "ACML" + add_include_from_paths ACML_CFLAGS "acml.h" $INCLUDE_PATHS + add_lib_from_paths ACML_LDFLAGS "libacml.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking ACML to user paths ====================" + pkg_install_dir="$with_acml" + check_dir "${pkg_install_dir}/lib" + ACML_CFLAGS="-I'${pkg_install_dir}/include'" + ACML_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_acml" != "__DONTUSE__" ]; then + ACML_LIBS="-lacml" + if [ "$with_acml" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_acml" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include" +EOF + cat "${BUILDDIR}/setup_acml" >> $SETUPFILE + fi + cat << EOF >> "${BUILDDIR}/setup_acml" +export ACML_CFLAGS="${ACML_CFLAGS}" +export ACML_LDFLAGS="${ACML_LDFLAGS}" +export ACML_LIBS="${ACML_LIBS}" +export MATH_CFLAGS="\${MATH_CFLAGS} ${ACML_CFLAGS}" +export MATH_LDFLAGS="\${MATH_LDFLAGS} ${ACML_LDFLAGS}" +export MATH_LIBS="\${MATH_LIBS} ${ACML_LIBS}" +EOF +fi + +load "${BUILDDIR}/setup_acml" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "acml" diff --git a/scripts/stage2/install_mathlibs.sh b/scripts/stage2/install_mathlibs.sh new file mode 100755 index 0000000..b4ed3df --- /dev/null +++ b/scripts/stage2/install_mathlibs.sh @@ -0,0 +1,48 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +export MATH_CFLAGS='' +export MATH_LDFLAGS='' +export MATH_LIBS='' + +write_toolchain_env "${INSTALLDIR}" + +case "$MATH_MODE" in + mkl) + "${SCRIPTDIR}"/stage2/install_mkl.sh "${with_mkl}" + load "${BUILDDIR}/setup_mkl" + ;; + acml) + "${SCRIPTDIR}"/stage2/install_acml.sh "${with_acml}" + load "${BUILDDIR}/setup_acml" + ;; + openblas) + "${SCRIPTDIR}"/stage2/install_openblas.sh "${with_openblas}" + load "${BUILDDIR}/setup_openblas" + ;; + cray) + # note the space is intentional so that the variable is + # non-empty and can pass require_env checks + export MATH_LDFLAGS="${MATH_LDFLAGS} " + export MATH_LIBS="${MATH_LIBS} ${CRAY_EXTRA_LIBS}" + ;; +esac + +export CP_CFLAGS="${CP_CFLAGS} ${MATH_CFLAGS}" +export CP_LDFLAGS="${CP_LDFLAGS} ${MATH_LDFLAGS}" +export CP_LIBS="${CP_LIBS} ${MATH_LIBS}" + +write_toolchain_env "${INSTALLDIR}" + +#EOF diff --git a/scripts/stage2/install_mkl.sh b/scripts/stage2/install_mkl.sh new file mode 100755 index 0000000..4fa9cae --- /dev/null +++ b/scripts/stage2/install_mkl.sh @@ -0,0 +1,139 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_mkl" ] && rm "${BUILDDIR}/setup_mkl" + +MKL_CFLAGS="" +MKL_LDFLAGS="" +MKL_LIBS="" + +MKL_FFTW="yes" +if [ "${with_libvdwxc}" != "__DONTUSE__" ] && [ "${MPI_MODE}" != "no" ]; then + report_warning ${LINENO} "MKL FFTW3 interface is present, but FFTW library is needed for FFTW-MPI wrappers." + MKL_FFTW="no" +fi + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_mkl}" in + __INSTALL__) + echo "==================== Installing MKL ====================" + report_error ${LINENO} "To install MKL, please contact your system administrator." + exit 1 + ;; + __SYSTEM__) + echo "==================== Finding MKL from system paths ====================" + if ! [ -z "${MKLROOT}" ]; then + echo "MKLROOT is found to be ${MKLROOT}" + else + report_error ${LINENO} "Cannot find env variable MKLROOT, the script relies on it being set. Please check in MKL installation and use --with-mkl= to pass the path to MKL root directory to this script." + exit 1 + fi + check_lib -lm + check_lib -ldl + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking MKL to user paths ====================" + check_dir "${with_mkl}" + MKLROOT="${with_mkl}" + ;; +esac +if [ "${with_mkl}" != "__DONTUSE__" ]; then + case ${OPENBLAS_ARCH} in + x86_64) + mkl_arch_dir="intel64" + MKL_CFLAGS="-m64" + ;; + i386) + mkl_arch_dir="ia32" + MKL_CFLAGS="-m32" + ;; + *) + report_error $LINENO "MKL only supports intel64 (x86_64) and ia32 (i386) at the moment, and your arch obtained from OpenBLAS prebuild is $OPENBLAS_ARCH" + exit 1 + ;; + esac + mkl_lib_dir="${MKLROOT}/lib/${mkl_arch_dir}" + # check we have required libraries + mkl_required_libs="libmkl_gf_lp64.so libmkl_sequential.so libmkl_core.so" + for ii in $mkl_required_libs; do + if [ ! -f "$mkl_lib_dir/${ii}" ]; then + report_error $LINENO "missing MKL library ${ii}" + exit 1 + fi + done + + case ${MPI_MODE} in + intelmpi | mpich) + mkl_scalapack_lib="IF_MPI(-lmkl_scalapack_lp64|)" + mkl_blacs_lib="IF_MPI(-lmkl_blacs_intelmpi_lp64|)" + ;; + openmpi) + mkl_scalapack_lib="IF_MPI(-lmkl_scalapack_lp64|)" + mkl_blacs_lib="IF_MPI(-lmkl_blacs_openmpi_lp64|)" + ;; + *) + echo "Not using MKL provided ScaLAPACK and BLACS" + mkl_scalapack_lib="" + mkl_blacs_lib="" + ;; + esac + + # set the correct lib flags from MLK link adviser + MKL_LIBS="-L${mkl_lib_dir} -Wl,-rpath,${mkl_lib_dir} ${mkl_scalapack_lib}" + MKL_LIBS+=" -Wl,--start-group -lmkl_gf_lp64 -lmkl_sequential -lmkl_core" + MKL_LIBS+=" ${mkl_blacs_lib} -Wl,--end-group -lpthread -lm -ldl" + # setup_mkl disables using separate FFTW library (see below) + MKL_CFLAGS="${MKL_CFLAGS} -I${MKLROOT}/include" + if [ "${MKL_FFTW}" != "no" ]; then + MKL_CFLAGS+=" -I${MKLROOT}/include/fftw" + fi + + # write setup files + cat << EOF > "${BUILDDIR}/setup_mkl" +export MKLROOT="${MKLROOT}" +export MKL_CFLAGS="${MKL_CFLAGS}" +export MKL_LIBS="${MKL_LIBS}" +export MATH_CFLAGS="\${MATH_CFLAGS} ${MKL_CFLAGS}" +export MATH_LIBS="\${MATH_LIBS} ${MKL_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} -D__MKL -D__FFTW3 IF_COVERAGE(IF_MPI(|-U__FFTW3)|)" +EOF + if [ -n "${mkl_scalapack_lib}" ]; then + cat << EOF >> "${BUILDDIR}/setup_mkl" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__SCALAPACK|)" +export with_scalapack="__DONTUSE__" +EOF + fi + if [ "${MKL_FFTW}" != "no" ]; then + cat << EOF >> "${BUILDDIR}/setup_mkl" +export with_fftw="__DONTUSE__" +export FFTW3_INCLUDES="${MKL_CFLAGS}" +export FFTW3_LIBS="${MKL_LIBS}" +export FFTW_CFLAGS="${MKL_CFLAGS}" +export FFTW_LDFLAGS="${MKL_LDFLAGS}" +export FFTW_LIBS="${MKL_LIBS}" +EOF + fi + cat "${BUILDDIR}/setup_mkl" >> ${SETUPFILE} +fi + +load "${BUILDDIR}/setup_mkl" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "mkl" diff --git a/scripts/stage2/install_openblas.sh b/scripts/stage2/install_openblas.sh new file mode 100755 index 0000000..b909130 --- /dev/null +++ b/scripts/stage2/install_openblas.sh @@ -0,0 +1,184 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +openblas_ver="0.3.25" # Keep in sync with get_openblas_arch.sh +openblas_sha256="4c25cb30c4bb23eddca05d7d0a85997b8db6144f5464ba7f8c09ce91e2f35543" +openblas_pkg="OpenBLAS-${openblas_ver}.tar.gz" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_openblas" ] && rm "${BUILDDIR}/setup_openblas" + +OPENBLAS_CFLAGS="" +OPENBLAS_LDFLAGS="" +OPENBLAS_LIBS="" +OPENBLAS_ROOT="" +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_openblas}" in + __INSTALL__) + echo "==================== Installing OpenBLAS ====================" + pkg_install_dir="${INSTALLDIR}/openblas/${openblas_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "openblas-${openblas_ver} is already installed, skipping it." + else + if [ -f ${openblas_pkg} ]; then + echo "${openblas_pkg} is found" + else + download_pkg_from_cp2k_org "${openblas_sha256}" "${openblas_pkg}" + fi + + echo "Installing from scratch into ${pkg_install_dir}" + [ -d OpenBLAS-${openblas_ver} ] && rm -rf OpenBLAS-${openblas_ver} + tar -zxf ${openblas_pkg} + cd OpenBLAS-${openblas_ver} + + # First attempt to make openblas using auto detected + # TARGET, if this fails, then make with forced + # TARGET=NEHALEM + # + # wrt NUM_THREADS=128: this is what the most common Linux distros seem to choose atm + # for a good compromise between memory usage and scalability + # + # Unfortunately, NO_SHARED=1 breaks ScaLAPACK build. + case "${TARGET_CPU}" in + "generic") + TARGET="NEHALEM" + ;; + "native") + TARGET=${OPENBLAS_LIBCORE} + ;; + "broadwell" | "skylake") + TARGET="HASWELL" + ;; + "skylake-avx512") + TARGET="SKYLAKEX" + ;; + "znver*") + TARGET="ZEN" + ;; + *) + TARGET=${TARGET_CPU} + ;; + esac + TARGET=$(echo ${TARGET} | tr '[:lower:]' '[:upper:]') + echo "Installing OpenBLAS library for target ${TARGET}" + ( + make -j $(get_nprocs) \ + MAKE_NB_JOBS=0 \ + TARGET=${TARGET} \ + NUM_THREADS=128 \ + USE_THREAD=1 \ + USE_OPENMP=1 \ + NO_AFFINITY=1 \ + CC="${CC}" \ + FC="${FC}" \ + PREFIX="${pkg_install_dir}" \ + > make.log 2>&1 || tail -n ${LOG_LINES} make.log + ) || ( + make -j $(get_nprocs) \ + MAKE_NB_JOBS=0 \ + TARGET=NEHALEM \ + NUM_THREADS=128 \ + USE_THREAD=1 \ + USE_OPENMP=1 \ + NO_AFFINITY=1 \ + CC="${CC}" \ + FC="${FC}" \ + PREFIX="${pkg_install_dir}" \ + > make.nehalem.log 2>&1 || tail -n ${LOG_LINES} make.nehalem.log + ) + make -j $(get_nprocs) \ + MAKE_NB_JOBS=0 \ + TARGET=${TARGET} \ + NUM_THREADS=128 \ + USE_THREAD=1 \ + USE_OPENMP=1 \ + NO_AFFINITY=1 \ + CC="${CC}" \ + FC="${FC}" \ + PREFIX="${pkg_install_dir}" \ + install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage2/$(basename ${SCRIPT_NAME})" + fi + OPENBLAS_CFLAGS="-I'${pkg_install_dir}/include'" + OPENBLAS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + OPENBLAS_ROOT="${pkg_install_dir}" + # Prefer static library if available + if [ -f "${pkg_install_dir}/lib/libopenblas.a" ]; then + OPENBLAS_LIBS="-l:libopenblas.a" + else + OPENBLAS_LIBS="-lopenblas" + fi + ;; + __SYSTEM__) + echo "==================== Finding LAPACK from system paths ====================" + # assume that system openblas is threaded + check_lib -lopenblas "OpenBLAS" + OPENBLAS_LIBS="-lopenblas" + # detect separate omp builds + check_lib -lopenblas_openmp 2> /dev/null && OPENBLAS_LIBS="-lopenblas_openmp" + check_lib -lopenblas_omp 2> /dev/null && OPENBLAS_LIBS="-lopenblas_omp" + add_include_from_paths OPENBLAS_CFLAGS "openblas_config.h" $INCLUDE_PATHS + add_lib_from_paths OPENBLAS_LDFLAGS "libopenblas.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking LAPACK to user paths ====================" + pkg_install_dir="$with_openblas" + check_dir "${pkg_install_dir}/include" + check_dir "${pkg_install_dir}/lib" + OPENBLAS_CFLAGS="-I'${pkg_install_dir}/include'" + OPENBLAS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + OPENBLAS_LIBS="-lopenblas" + # detect separate omp builds + (__libdir="${pkg_install_dir}/lib" LIB_PATHS="__libdir" check_lib -lopenblas_openmp 2> /dev/null) && + OPENBLAS_LIBS="-lopenblas_openmp" + (__libdir="${pkg_install_dir}/lib" LIB_PATHS="__libdir" check_lib -lopenblas_omp 2> /dev/null) && + OPENBLAS_LIBS="-lopenblas_omp" + ;; +esac +if [ "$with_openblas" != "__DONTUSE__" ]; then + if [ "$with_openblas" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_openblas" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +prepend_path CPATH "$pkg_install_dir/include" +export OPENBLAS_ROOT=${pkg_install_dir} +EOF + cat "${BUILDDIR}/setup_openblas" >> $SETUPFILE + fi + cat << EOF >> "${BUILDDIR}/setup_openblas" +export OPENBLAS_ROOT="${pkg_install_dir}" +export OPENBLAS_CFLAGS="${OPENBLAS_CFLAGS}" +export OPENBLAS_LDFLAGS="${OPENBLAS_LDFLAGS}" +export OPENBLAS_LIBS="${OPENBLAS_LIBS}" +export MATH_CFLAGS="\${MATH_CFLAGS} ${OPENBLAS_CFLAGS}" +export MATH_LDFLAGS="\${MATH_LDFLAGS} ${OPENBLAS_LDFLAGS}" +export MATH_LIBS="\${MATH_LIBS} ${OPENBLAS_LIBS}" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF +fi + +load "${BUILDDIR}/setup_openblas" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "openblas" \ No newline at end of file diff --git a/scripts/stage2/install_stage2.sh b/scripts/stage2/install_stage2.sh new file mode 100755 index 0000000..650c41f --- /dev/null +++ b/scripts/stage2/install_stage2.sh @@ -0,0 +1,8 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +./scripts/stage2/install_mathlibs.sh + +#EOF diff --git a/scripts/stage3/install_fftw.sh b/scripts/stage3/install_fftw.sh old mode 100644 new mode 100755 index b992a5a..1e9e979 --- a/scripts/stage3/install_fftw.sh +++ b/scripts/stage3/install_fftw.sh @@ -1,76 +1,136 @@ -#!/bin/bash +#!/bin/bash -e -if [[ "$BASH_SOURCE" == "$0" ]]; then - BUILD_LOCATION=${PWD} - INSTALL_LOCATION=/avfs/people/parl703 - LOG_LINES=200 -else - source ${BUILD_LOCATION}/build.env - ROOT=${PWD} -fi +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all -TARGET_CPU=${TARGET_CPU:-"native"} +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" -echo "==================== Installing FFTW ====================" -FFTW_VERSION=3.3.10 +fftw_ver="3.3.10" +fftw_sha256="56c932549852cddcfafdab3820b0200c7742675be92179e59e6215b340e26467" +fftw_pkg="fftw-${fftw_ver}.tar.gz" -FFTW_BUILD_DIR=${BUILD_LOCATION}/fftw -FFTW_INSTALL_DIR=${INSTALL_LOCATION}/fftw/${FFTW_VERSION} -mkdir -p ${FFTW_BUILD_DIR} -mkdir -p ${FFTW_INSTALL_DIR} +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env -cd ${FFTW_BUILD_DIR} -if [ -f fftw-${FFTW_VERSION}.tar.gz ]; then - echo "fftw-${FFTW_VERSION}.tar.gz is found" -else - wget -c ftp://ftp.fftw.org/pub/fftw/fftw-${FFTW_VERSION}.tar.gz -fi -#[ -d fftw-${FFTW_VERSION}/build ] && rm -rf fftw-${FFTW_VERSION}/build -#tar -xf fftw-${FFTW_VERSION}.tar.gz -cd fftw-${FFTW_VERSION} -mkdir -p build && cd build +[ -f "${BUILDDIR}/setup_fftw" ] && rm "${BUILDDIR}/setup_fftw" -FFTW_FLAGS="--enable-shared" +FFTW_CFLAGS='' +FFTW_LDFLAGS='' +FFTW_LIBS='' +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" -if [ "${TARGET_CPU}" = "native" ]; then - if [ -f /proc/cpuinfo ]; then - grep '\bavx\b' /proc/cpuinfo 1> /dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx" - grep '\bavx2\b' /proc/cpuinfo 1> /dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx2" - grep '\bavx512f\b' /proc/cpuinfo 1> /dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx512" +case "$with_fftw" in + __INSTALL__) + require_env MPI_LIBS + echo "==================== Installing FFTW ====================" + pkg_install_dir="${INSTALLDIR}/fftw/${fftw_ver}/omp" + [ "${MPI_MODE}" != "no" ] && pkg_install_dir="${INSTALLDIR}/fftw/${fftw_ver}/mpi" + install_lock_file="$pkg_install_dir/install_successful" + + if verify_checksums "${install_lock_file}"; then + echo "fftw-${fftw_ver} is already installed, skipping it." + else + if [ -f ${fftw_pkg} ]; then + echo "${fftw_pkg} is found" + else + download_pkg_from_cp2k_org "${fftw_sha256}" "${fftw_pkg}" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d fftw-${fftw_ver} ] && rm -rf fftw-${fftw_ver} + tar -xzf ${fftw_pkg} + cd fftw-${fftw_ver} + FFTW_FLAGS="--enable-openmp --disable-shared --enable-static" + # fftw has mpi support but not compiled by default. so compile it if we build with mpi. + # it will create a second library to link with if needed + [ "${MPI_MODE}" != "no" ] && FFTW_FLAGS="--enable-mpi ${FFTW_FLAGS}" + if [ "${TARGET_CPU}" = "native" ]; then + if [ -f /proc/cpuinfo ]; then + grep '\bavx\b' /proc/cpuinfo 1> /dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx" + grep '\bavx2\b' /proc/cpuinfo 1> /dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx2" + grep '\bavx512f\b' /proc/cpuinfo 1> /dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx512" + fi + fi + ./configure --prefix=${pkg_install_dir} --libdir="${pkg_install_dir}/lib" ${FFTW_FLAGS} \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" fi + FFTW_CFLAGS="-I'${pkg_install_dir}/include'" + FFTW_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding FFTW from system paths ====================" + check_lib -lfftw3 "FFTW" + check_lib -lfftw3_omp "FFTW" + [ "${MPI_MODE}" != "no" ] && check_lib -lfftw3_mpi "FFTW" + add_include_from_paths FFTW_CFLAGS "fftw3.h" FFTW_INC ${INCLUDE_PATHS} + add_lib_from_paths FFTW_LDFLAGS "libfftw3.*" ${LIB_PATHS} + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking FFTW to user paths ====================" + pkg_install_dir="$with_fftw" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + FFTW_CFLAGS="-I'${pkg_install_dir}/include'" + FFTW_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_fftw" != "__DONTUSE__" ]; then + [ "$MPI_MODE" != "no" ] && FFTW_LIBS="IF_MPI(-lfftw3_mpi|) " + FFTW_LIBS+="-lfftw3 -lfftw3_omp" + if [ "$with_fftw" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_fftw" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + fi + # we may also want to cover FFT_SG + cat << EOF >> "${BUILDDIR}/setup_fftw" +export FFTW3_INCLUDES="${FFTW_CFLAGS}" +export FFTW3_LIBS="${FFTW_LIBS}" +export FFTW_CFLAGS="${FFTW_CFLAGS}" +export FFTW_LDFLAGS="${FFTW_LDFLAGS}" +export FFTW_LIBS="${FFTW_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} -D__FFTW3 IF_COVERAGE(IF_MPI(|-U__FFTW3)|)" +export CP_CFLAGS="\${CP_CFLAGS} ${FFTW_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${FFTW_LDFLAGS}" +export CP_LIBS="${FFTW_LIBS} \${CP_LIBS}" +export FFTW_ROOT=${FFTW_ROOT:-${pkg_install_dir}} +export FFTW3_ROOT=${pkg_install_dir} +EOF + cat "${BUILDDIR}/setup_fftw" >> $SETUPFILE fi +cd "${ROOTDIR}" -if [ "$BUILD_SINGLE" = true ]; then - FFTW_FLAGS="--enable-float ${FFTW_FLAGS}" -fi +# ---------------------------------------------------------------------- +# Suppress reporting of known leaks +# ---------------------------------------------------------------------- +cat << EOF >> ${INSTALLDIR}/valgrind.supp +{ + + Memcheck:Addr32 + fun:cdot + ... + fun:invoke_solver + fun:search0 +} +EOF -if [ "$OPENMP_ENALBED" = true ]; then - FFTW_FLAGS="--enable-openmp ${FFTW_FLAGS}" - OTHER=openmp -else - FFTW_FLAGS="--enable-threads ${FFTW_FLAGS}" - OTHER=smp -fi +load "${BUILDDIR}/setup_fftw" +write_toolchain_env "${INSTALLDIR}" -if [ "$MPI_ENABLED" = true ]; then - FFTW_FLAGS="--enable-mpi ${FFTW_FLAGS}" - FFTW_INSTALL_DIR=${FFTW_INSTALL_DIR}/${MPI_MODE}/${MPI_VERSION} -else - FFTW_INSTALL_DIR=${FFTW_INSTALL_DIR}/${OTHER} -fi - -echo "Installing from scratch into ${FFTW_INSTALL_DIR}" -echo ${FFTW_FLAGS} -../configure --prefix=${FFTW_INSTALL_DIR} ${FFTW_FLAGS} > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log -make -j$(nproc) > make.log 2>&1 || tail -n ${LOG_LINES} make.log -if [ -z "$SKIP_CHECK" ]; then - echo -n "Checking that everything is working properly ... " - make -j$(nproc) check > check.log 2>&1 || tail -n ${LOG_LINES} check.log - echo "Success!" -fi -#make -j$(nproc) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log - -if [[ "$BASH_SOURCE" != "$0" ]]; then - cd ${ROOT} - echo "Exiting ..." -fi +report_timing "fftw" diff --git a/scripts/stage3/install_libgrpp.sh b/scripts/stage3/install_libgrpp.sh new file mode 100755 index 0000000..e7d160a --- /dev/null +++ b/scripts/stage3/install_libgrpp.sh @@ -0,0 +1,108 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +libgrpp_ver="20231215" +libgrpp_sha="3b0f55795a0c2699b81f403b1c81c56e26332f780a87655410745a0ccb51ef2f" +libgrpp_pkg="libgrpp-main-${libgrpp_ver}.zip" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_libgrpp" ] && rm "${BUILDDIR}/setup_libgrpp" + +LIBGRPP_CFLAGS="" +LIBGRPP_LDFLAGS="" +LIBGRPP_LIBS="" +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_libgrpp}" in + __INSTALL__) + echo "==================== Installing LIBGRPP ====================" + pkg_install_dir="${INSTALLDIR}/libgrpp/${libgrpp_ver}" + install_lock_file="$pkg_install_dir/install_successful" + + if verify_checksums "${install_lock_file}"; then + echo "libgrpp-main-${libgrpp_ver} is already installed, skipping it." + else + if [ -f ${libgrpp_pkg} ]; then + echo "${libgrpp_pkg} is found" + else + download_pkg_from_cp2k_org "${libgrpp_sha}" "${libgrpp_pkg}" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d libgrpp-main ] && rm -rf libgrpp-main + unzip -qq ${libgrpp_pkg} + cd libgrpp-main + mkdir build + cd build + CC=${CC} FC=${FC} cmake .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make > make.log 2>&1 || tail -n ${LOG_LINES} make.log + cd .. + + install -d "${pkg_install_dir}/lib" >> install.log 2>&1 + install -d "${pkg_install_dir}/include" >> install.log 2>&1 + install -m 644 build/libgrpp/liblibgrpp.a "${pkg_install_dir}/lib" >> install.log 2>&1 + install -m 644 build/libgrpp.mod "${pkg_install_dir}/include" >> install.log 2>&1 + + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" + fi + + LIBGRPP_CFLAGS="-I'${pkg_install_dir}/include'" + LIBGRPP_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding libgrpp from system paths ====================" + check_lib -llibgrpp "libgrpp" + add_include_from_paths -p LIBGRPP_CFLAGS "libgrpp" $INCLUDE_PATHS + add_lib_from_paths LIBGRPP_LDFLAGS "liblibgrpp.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking libgrpp to user paths ====================" + pkg_install_dir="$with_libgrpp" + check_dir "${pkg_install_dir}/include" + check_dir "${pkg_install_dir}/lib" + LIBGRPP_CFLAGS="-I'${pkg_install_dir}/include'" + LIBGRPP_LDFLAGS="-L'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_libgrpp" != "__DONTUSE__" ]; then + LIBGRPP_LIBS="-llibgrpp" + if [ "$with_libgrpp" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_libgrpp" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +export LIBGRPP_ROOT="${pkg_install_dir}" +EOF + cat "${BUILDDIR}/setup_libgrpp" >> $SETUPFILE + fi + cat << EOF >> "${BUILDDIR}/setup_libgrpp" +export LIBGRPP_CFLAGS="${LIBGRPP_CFLAGS}" +export LIBGRPP_LDFLAGS="${LIBGRPP_LDFLAGS}" +export LIBGRPP_LIBS="${LIBGRPP_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} -D__LIBGRPP" +export CP_CFLAGS="\${CP_CFLAGS} ${LIBGRPP_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${LIBGRPP_LDFLAGS}" +export CP_LIBS="${LIBGRPP_LIBS} \${CP_LIBS}" +EOF +fi + +load "${BUILDDIR}/setup_libgrpp" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "libgrpp" diff --git a/scripts/stage3/install_libint.sh b/scripts/stage3/install_libint.sh new file mode 100755 index 0000000..e5327ea --- /dev/null +++ b/scripts/stage3/install_libint.sh @@ -0,0 +1,145 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +libint_ver="2.6.0" +libint_pkg="libint-v${libint_ver}-cp2k-lmax-${LIBINT_LMAX}.tgz" + +case "$LIBINT_LMAX" in + 4) + libint_sha256="7c8d28bfb03920936231228b79686ba0fd87ea922c267199789bc131cf21ac08" + ;; + 5) + libint_sha256="1cd72206afddb232bcf2179c6229fbf6e42e4ba8440e701e6aa57ff1e871e9db" + ;; + 6) + libint_sha256="bea76a433cd32bde280879f73b5fc8228c78b62e3ea57ace4c6d74b65910b8af" + ;; + 7) + libint_sha256="3bcdcc55e1dbafe38a785d4af171df8e300bb8b7775894b57186cdf35807c334" + ;; + *) + report_error "Unsupported value --libint-lmax=${LIBINT_LMAX}." + exit 1 + ;; +esac + +[ -f "${BUILDDIR}/setup_libint" ] && rm "${BUILDDIR}/setup_libint" + +LIBINT_CFLAGS="" +LIBINT_LDFLAGS="" +LIBINT_LIBS="" +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_libint" in + __INSTALL__) + echo "==================== Installing LIBINT ====================" + pkg_install_dir="${INSTALLDIR}/libint/${libint_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "libint-${libint_ver} is already installed, skipping it." + else + if [ -f ${libint_pkg} ]; then + echo "${libint_pkg} is found" + else + download_pkg_from_cp2k_org "${libint_sha256}" "${libint_pkg}" + fi + + [ -d libint-v${libint_ver}-cp2k-lmax-${LIBINT_LMAX} ] && rm -rf libint-v${libint_ver}-cp2k-lmax-${LIBINT_LMAX} + tar -xzf ${libint_pkg} + + echo "Installing from scratch into ${pkg_install_dir}" + cd libint-v${libint_ver}-cp2k-lmax-${LIBINT_LMAX} + + # reduce debug information to level 1 since + # level 2 (default for -g flag) leads to very large binary size + LIBINT_CXXFLAGS="$CXXFLAGS -g1" + + # cmake build broken with libint 2.6, uncomment for libint 2.7 and above + #cmake . -DCMAKE_INSTALL_PREFIX=${pkg_install_dir} \ + # -DCMAKE_CXX_COMPILER="$CXX" \ + # -DLIBINT2_INSTALL_LIBDIR="${pkg_install_dir}/lib" \ + # -DENABLE_FORTRAN=ON \ + # -DCXXFLAGS="$LIBINT_CXXFLAGS" > configure.log 2>&1 + #cmake --build . > cmake.log 2>&1 + #cmake --build . --target install > install.log 2>&1 + ./configure --prefix=${pkg_install_dir} \ + --with-cxx="$CXX $LIBINT_CXXFLAGS" \ + --with-cxx-optflags="$LIBINT_CXXFLAGS" \ + --enable-fortran \ + --with-pic \ + --libdir="${pkg_install_dir}/lib" \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + + if [ "${MPI_MODE}" = "intelmpi" ]; then + # Fix bug in makefile for Fortran module + sed -i -e "s/\$(CXX) \$(CXXFLAGS)/\$(FC) \$(FCFLAGS)/g" -e "s/\$(FCLIBS) -o/\$(FCLIBS) -lstdc++ -o/" fortran/Makefile + fi + + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" + fi + + LIBINT_CFLAGS="-I'${pkg_install_dir}/include'" + LIBINT_LDFLAGS="-L'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding LIBINT from system paths ====================" + check_lib -lint2 "libint" + add_include_from_paths -p LIBINT_CFLAGS "libint" $INCLUDE_PATHS + add_lib_from_paths LIBINT_LDFLAGS "libint2.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking LIBINT to user paths ====================" + pkg_install_dir="$with_libint" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + LIBINT_CFLAGS="-I'${pkg_install_dir}/include'" + LIBINT_LDFLAGS="-L'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_libint" != "__DONTUSE__" ]; then + LIBINT_LIBS="-lint2" + if [ "$with_libint" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_libint" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +export LIBINT2_ROOT="${pkg_install_dir}" +EOF + cat "${BUILDDIR}/setup_libint" >> $SETUPFILE + fi + cat << EOF >> "${BUILDDIR}/setup_libint" +export LIBINT_CFLAGS="${LIBINT_CFLAGS}" +export LIBINT_LDFLAGS="${LIBINT_LDFLAGS}" +export LIBINT_LIBS="${LIBINT_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} -D__LIBINT" +export CP_CFLAGS="\${CP_CFLAGS} ${LIBINT_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${LIBINT_LDFLAGS}" +export CP_LIBS="${LIBINT_LIBS} \${CP_LIBS}" +EOF +fi + +load "${BUILDDIR}/setup_libint" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "libint" diff --git a/scripts/stage3/install_libxc.sh b/scripts/stage3/install_libxc.sh new file mode 100755 index 0000000..72e93ed --- /dev/null +++ b/scripts/stage3/install_libxc.sh @@ -0,0 +1,101 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +libxc_ver="6.2.2" +libxc_sha256="a0f6f1bba7ba5c0c85b2bfe65aca1591025f509a7f11471b4cd651a79491b045" +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_libxc" ] && rm "${BUILDDIR}/setup_libxc" + +LIBXC_CFLAGS="" +LIBXC_LDFLAGS="" +LIBXC_LIBS="" +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_libxc" in + __INSTALL__) + echo "==================== Installing LIBXC ====================" + pkg_install_dir="${INSTALLDIR}/libxc/${libxc_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "libxc-${libxc_ver} is already installed, skipping it." + else + if [ -f libxc-${libxc_ver}.tar.gz ]; then + echo "libxc-${libxc_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${libxc_sha256}" "libxc-${libxc_ver}.tar.gz" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d libxc-${libxc_ver} ] && rm -rf libxc-${libxc_ver} + tar -xzf libxc-${libxc_ver}.tar.gz + cd libxc-${libxc_ver} + + # CP2K does not make use of fourth derivatives, so skip their compilation with --disable-lxc + ./configure --prefix="${pkg_install_dir}" --libdir="${pkg_install_dir}/lib" --disable-lxc \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" + fi + LIBXC_CFLAGS="-I'${pkg_install_dir}/include'" + LIBXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding LIBXC from system paths ====================" + check_lib -lxcf03 "libxc" + check_lib -lxc "libxc" + add_include_from_paths LIBXC_CFLAGS "xc.h" $INCLUDE_PATHS + add_lib_from_paths LIBXC_LDFLAGS "libxc.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking LIBXC to user paths ====================" + pkg_install_dir="$with_libxc" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + LIBXC_CFLAGS="-I'${pkg_install_dir}/include'" + LIBXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_libxc" != "__DONTUSE__" ]; then + LIBXC_LIBS="-lxcf03 -lxc" + if [ "$with_libxc" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_libxc" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + cat "${BUILDDIR}/setup_libxc" >> $SETUPFILE + fi + cat << EOF >> "${BUILDDIR}/setup_libxc" +export LIBXC_CFLAGS="${LIBXC_CFLAGS}" +export LIBXC_LDFLAGS="${LIBXC_LDFLAGS}" +export LIBXC_LIBS="${LIBXC_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} -D__LIBXC" +export CP_CFLAGS="\${CP_CFLAGS} ${LIBXC_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${LIBXC_LDFLAGS}" +export CP_LIBS="${LIBXC_LIBS} \${CP_LIBS}" +export LIBXC_ROOT="$pkg_install_dir" +EOF +fi + +load "${BUILDDIR}/setup_libxc" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "libxc" diff --git a/scripts/stage3/install_stage3.sh b/scripts/stage3/install_stage3.sh new file mode 100755 index 0000000..a25e37e --- /dev/null +++ b/scripts/stage3/install_stage3.sh @@ -0,0 +1,11 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +./scripts/stage3/install_fftw.sh +./scripts/stage3/install_libint.sh +./scripts/stage3/install_libxc.sh +./scripts/stage3/install_libgrpp.sh + +#EOF diff --git a/scripts/stage4/install_cosma.sh b/scripts/stage4/install_cosma.sh new file mode 100755 index 0000000..bb1ccd7 --- /dev/null +++ b/scripts/stage4/install_cosma.sh @@ -0,0 +1,294 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +cosma_ver="2.6.6" +cosma_sha256="1604be101e77192fbcc5551236bc87888d336e402f5409bbdd9dea900401cc37" +costa_ver="2.2.2" +costa_sha256="e87bc37aad14ac0c5922237be5d5390145c9ac6aef0350ed17d86cb2d994e67c" +tiled_mm_ver="2.2" +tiled_mm_sha256="6d0b49c9588ece744166822fd44a7bc5bec3dc666b836de8bf4bf1a7bb675aac" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_cosma" ] && rm "${BUILDDIR}/setup_cosma" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_cosma" in + __INSTALL__) + require_env OPENBLAS_ROOT + require_env SCALAPACK_ROOT + + echo "==================== Installing COSMA ====================" + pkg_install_dir="${INSTALLDIR}/COSMA/${cosma_ver}" + install_lock_file="$pkg_install_dir/install_successful" + + if verify_checksums "${install_lock_file}"; then + echo "COSMA-${cosma_ver} is already installed, skipping it." + else + if [ -f COSMA-v${cosma_ver}.tar.gz ]; then + echo "COSMA-v${cosma_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${cosma_sha256}" "COSMA-v${cosma_ver}.tar.gz" + download_pkg_from_cp2k_org "${costa_sha256}" "COSTA-v${costa_ver}.tar.gz" + download_pkg_from_cp2k_org "${tiled_mm_sha256}" "Tiled-MM-v${tiled_mm_ver}.tar.gz" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d COSMA-${cosma_ver} ] && rm -rf COSMA-${cosma_ver} + tar -xzf COSMA-v${cosma_ver}.tar.gz + [ -d Tiled-MM-${tiled_mm_ver} ] && rm -rf Tiled-MM-${tiled_mm_ver} + tar -xzf Tiled-MM-v${tiled_mm_ver}.tar.gz + [ -d COSTA-${costa_ver} ] && rm -rf COSTA-${costa_ver} + tar -xzf COSTA-v${costa_ver}.tar.gz + + case "$MATH_MODE" in + mkl) + cosma_blas="MKL" + cosma_sl="MKL" + ;; + cray) + cosma_blas="CRAY_LIBSCI" + cosma_sl="CRAY_LIBSCI" + ;; + *) + cosma_blas="OPENBLAS" + cosma_sl="CUSTOM" + ;; + esac + + cd "COSTA-${costa_ver}" + [ -d build-cpu ] && rm -Rf build-cpu + mkdir build-cpu && cd build-cpu + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DBUILD_SHARED_LIBS=NO \ + -DCOSTA_SCALAPACK=${cosma_sl} \ + .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + + if [ "$ENABLE_CUDA" = "__TRUE__" ]; then + [ -d build-cuda ] && rm -Rf build-cuda + mkdir build-cuda && cd build-cuda + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}-cuda" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DBUILD_SHARED_LIBS=NO \ + -DCOSTA_SCALAPACK=${cosma_sl} \ + .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + fi + + if [ "$ENABLE_HIP" = "__TRUE__" ]; then + [ -d build-hip ] && rm -Rf build-hip + mkdir build-hip && cd build-hip + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}-hip" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DBUILD_SHARED_LIBS=NO \ + -DCOSTA_BLAS=${cosma_blas} \ + -DCOSTA_SCALAPACK=${cosma_sl} \ + .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + fi + cd .. + + cd Tiled-MM-${tiled_mm_ver} + if [ "$ENABLE_CUDA" = "__TRUE__" ]; then + mkdir build-cuda && cd build-cuda + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}-cuda" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DBUILD_SHARED_LIBS=NO \ + -DTILEDMM_GPU_BACKEND=CUDA \ + -DTILEDMM_WITH_EXAMPLES=OFF \ + -DTILEDMM_WITH_TESTS=OFF \ + .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + fi + + if [ "$ENABLE_HIP" = "__TRUE__" ]; then + mkdir build-hip && cd build-hip + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}-hip" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DBUILD_SHARED_LIBS=NO \ + -DTILEDMM_GPU_BACKEND=ROCM \ + -DTILEDMM_WITH_EXAMPLES=OFF \ + -DTILEDMM_WITH_TESTS=OFF \ + .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + fi + cd .. + + cd COSMA-${cosma_ver} && mkdir build-cpu && cd build-cpu + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DBUILD_SHARED_LIBS=NO \ + -DCOSMA_BLAS=${cosma_blas} \ + -DCOSMA_SCALAPACK=${cosma_sl} \ + -DCOSMA_WITH_TESTS=NO \ + -DCOSMA_WITH_APPS=NO \ + -DCOSMA_WITH_BENCHMARKS=NO .. \ + > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + + # Build CUDA version. + if [ "$ENABLE_CUDA" = "__TRUE__" ]; then + [ -d build-cuda ] && rm -rf "build-cuda" + mkdir build-cuda + cd build-cuda + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}-cuda" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DBUILD_SHARED_LIBS=NO \ + -DCOSMA_BLAS=CUDA \ + -DCOSMA_SCALAPACK=${cosma_sl} \ + -DCOSMA_WITH_TESTS=NO \ + -DCOSMA_WITH_APPS=NO \ + -DCOSMA_WITH_BENCHMARKS=NO .. \ + > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + fi + + # Build HIP version. + if [ "$ENABLE_HIP" = "__TRUE__" ] && $(check_lib -lrocblas "rocm" &> /dev/null); then + [ -d build-hip ] && rm -rf "build-hip" + mkdir build-hip + cd build-hip + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}-hip" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DBUILD_SHARED_LIBS=NO \ + -DCOSMA_BLAS=ROCM \ + -DCOSMA_SCALAPACK=${cosma_sl} \ + -DCOSMA_WITH_TESTS=NO \ + -DCOSMA_WITH_APPS=NO \ + -DCOSMA_WITH_BENCHMARKS=NO .. \ + > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + fi + + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + COSMA_ROOT="${pkg_install_dir}" + COSMA_CFLAGS="-I'${pkg_install_dir}/include'" + + # Check if COSMA is compiled with 64bits and set up COSMA_LIBDIR accordingly. + COSMA_LIBDIR="${pkg_install_dir}/lib" + COSMA_LDFLAGS="-L'${COSMA_LIBDIR}' -Wl,-rpath,'${COSMA_LIBDIR}'" + COSMA_CUDA_LIBDIR="${pkg_install_dir}-cuda/lib" + COSMA_CUDA_LDFLAGS="-L'${COSMA_CUDA_LIBDIR}' -Wl,-rpath,'${COSMA_CUDA_LIBDIR}'" + COSMA_HIP_LIBDIR="${pkg_install_dir}-hip/lib" + COSMA_HIP_LDFLAGS="-L'${COSMA_HIP_LIBDIR}' -Wl,-rpath,'${COSMA_HIP_LIBDIR}'" + ;; + __SYSTEM__) + echo "==================== Finding COSMA from system paths ====================" + check_command pkg-config --modversion cosma + add_include_from_paths COSMA_CFLAGS "cosma.h" $INCLUDE_PATHS + add_lib_from_paths COSMA_LDFLAGS "libcosma.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking COSMA to user paths ====================" + pkg_install_dir="$with_cosma" + + # use the lib64 directory if present (multi-abi distros may link lib/ to lib32/ instead) + COSMA_LIBDIR="${pkg_install_dir}/lib" + [ -d "${pkg_install_dir}/lib64" ] && COSMA_LIBDIR="${pkg_install_dir}/lib64" + + check_dir "$pkg_install_dir/lib" + check_dir "$pkg_install_dir/include" + + COSMA_CFLAGS="-I'${pkg_install_dir}/include'" + COSMA_LDFLAGS="-L'${COSMA_LIBDIR}' -Wl,-rpath,'${COSMA_LIBDIR}'" + ;; +esac +if [ "$with_cosma" != "__DONTUSE__" ]; then + COSMA_LIBS="-lcosma_prefixed_pxgemm -lcosma -lcosta IF_CUDA(-lTiled-MM|)" + if [ "$ENABLE_HIP" = "__TRUE__" ] && $(check_lib -lrocblas "rocm" &> /dev/null); then + COSMA_LIBS+=" IF_HIP(-lTiled-MM|)" + fi + if [ "$with_cosma" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_cosma" +prepend_path LD_LIBRARY_PATH "${COSMA_LIBDIR}" +prepend_path LD_RUN_PATH "${COSMA_LIBDIR}" +prepend_path LIBRARY_PATH "${COSMA_LIBDIR}" +prepend_path CPATH "$pkg_install_dir/include" +export COSMA_INCLUDE_DIR="$pkg_install_dir/include" +export COSMA_ROOT="${pkg_install_dir}" +export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${COSMA_LIBDIR}/pkgconfig" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + fi + cat << EOF >> "${BUILDDIR}/setup_cosma" +export COSMA_CFLAGS="${COSMA_CFLAGS}" +export COSMA_LDFLAGS="${COSMA_LDFLAGS}" +export COSMA_CUDA_LDFLAGS="${COSMA_CUDA_LDFLAGS}" +export COSMA_HIP_LDFLAGS="${COSMA_HIP_LDFLAGS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__COSMA|)" +export CP_CFLAGS="\${CP_CFLAGS} ${COSMA_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_CUDA(${COSMA_CUDA_LDFLAGS}|IF_HIP(${COSMA_HIP_LDFLAGS}|${COSMA_LDFLAGS}))" +export COSMA_LIBS="${COSMA_LIBS}" +export COSMA_ROOT="$pkg_install_dir" +export COSMA_INCLUDE_DIR="$pkg_install_dir/include" +export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${COSMA_LIBDIR}/pkgconfig" +export COSMA_VERSION=${cosma_ver} +export CP_LIBS="IF_MPI(${COSMA_LIBS}|) \${CP_LIBS}" +EOF + cat "${BUILDDIR}/setup_cosma" >> $SETUPFILE + + cat << EOF >> ${INSTALLDIR}/lsan.supp +# leaks related to COSMA (probably, only the last one is actually needed) +leak:cosma::communicator::communicator +leak:cosma::cosma_context::register_state +leak:cosma::pxgemm +leak:cosma::cosma_context >::register_state +EOF +fi + +load "${BUILDDIR}/setup_cosma" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "cosma" diff --git a/scripts/stage4/install_libxsmm.sh b/scripts/stage4/install_libxsmm.sh new file mode 100755 index 0000000..d533a20 --- /dev/null +++ b/scripts/stage4/install_libxsmm.sh @@ -0,0 +1,126 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +libxsmm_ver="1.17" +libxsmm_sha256="8b642127880e92e8a75400125307724635ecdf4020ca4481e5efe7640451bb92" +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_libxsmm" ] && rm "${BUILDDIR}/setup_libxsmm" + +LIBXSMM_CFLAGS='' +LIBXSMM_LDFLAGS='' +LIBXSMM_LIBS='' +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_libxsmm" in + __INSTALL__) + echo "==================== Installing Libxsmm ====================" + if [[ ("$OPENBLAS_ARCH" != "x86_64") && ("$OPENBLAS_ARCH" != "arm64") ]]; then + report_warning $LINENO "libxsmm is not supported on arch ${OPENBLAS_ARCH}" + cat << EOF > "${BUILDDIR}/setup_libxsmm" +with_libxsmm="__DONTUSE__" +EOF + exit 0 + fi + pkg_install_dir="${INSTALLDIR}/libxsmm/${libxsmm_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "libxsmm-${libxsmm_ver} is already installed, skipping it." + else + if [ -f libxsmm-${libxsmm_ver}.tar.gz ]; then + echo "libxsmm-${libxsmm_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${libxsmm_sha256}" "libxsmm-${libxsmm_ver}.tar.gz" + fi + [ -d libxsmm-${libxsmm_ver} ] && rm -rf libxsmm-${libxsmm_ver} + tar -xzf libxsmm-${libxsmm_ver}.tar.gz + + echo "Installing from scratch into ${pkg_install_dir}" + # note that we do not have to set -L flags to ld for the + # linked math libraries for the libxsmm build, as for a + # library this is not required, you just have to provide + # the appropriate -L flags (LDFLAGS) during the linking + # stage of building an executable that uses the libxsmm + # library + cd libxsmm-${libxsmm_ver} + # Avoid an unintended (incompatible) setting of FORTRAN + unset FORTRAN + make -j $(get_nprocs) \ + CXX=$CXX \ + CC=$CC \ + FC=$FC \ + INTRINSICS=1 \ + PREFIX=${pkg_install_dir} \ + > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) \ + CXX=$CXX \ + CC=$CC \ + FC=$FC \ + INTRINSICS=1 \ + PREFIX=${pkg_install_dir} \ + install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + mkdir ${pkg_install_dir}/lib/pkgconfig + cp ${pkg_install_dir}/lib/*.pc ${pkg_install_dir}/lib/pkgconfig + fi + LIBXSMM_CFLAGS="-I'${pkg_install_dir}/include'" + LIBXSMM_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding Libxsmm from system paths ====================" + check_lib -lxsmm "libxsmm" + check_lib -lxsmmf "libxsmm" + add_include_from_paths LIBXSMM_CFLAGS "libxsmm.h" $INCLUDE_PATHS + add_lib_from_paths LIBXSMM_LDFLAGS "libxsmm.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking Libxsmm to user paths ====================" + pkg_install_dir="$with_libxsmm" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/include" + check_dir "${pkg_install_dir}/lib" + LIBXSMM_CFLAGS="-I'${pkg_install_dir}/include'" + LIBXSMM_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_libxsmm" != "__DONTUSE__" ]; then + LIBXSMM_LIBS="-lxsmmf -lxsmm -ldl -lpthread" + if [ "$with_libxsmm" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_libxsmm" +prepend_path PATH "${pkg_install_dir}/bin" +prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" +prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +EOF + cat "${BUILDDIR}/setup_libxsmm" >> $SETUPFILE + fi + cat << EOF >> "${BUILDDIR}/setup_libxsmm" +export LIBXSMM_CFLAGS="${LIBXSMM_CFLAGS}" +export LIBXSMM_LDFLAGS="${LIBXSMM_LDFLAGS}" +export LIBXSMM_LIBS="${LIBXSMM_LIBS}" +export CP_DFLAGS="-D__LIBXSMM \${CP_DFLAGS}" +export CP_CFLAGS="\${CP_CFLAGS} ${LIBXSMM_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${LIBXSMM_LDFLAGS}" +export CP_LIBS="\${LIBXSMM_LIBS} \${CP_LIBS}" +EOF +fi +cd "${ROOTDIR}" + +load "${BUILDDIR}/setup_libxsmm" +write_toolchain_env "${INSTALLDIR}" + +report_timing "libxsmm" diff --git a/scripts/stage4/install_scalapack.sh b/scripts/stage4/install_scalapack.sh new file mode 100755 index 0000000..08349e2 --- /dev/null +++ b/scripts/stage4/install_scalapack.sh @@ -0,0 +1,117 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +scalapack_ver="2.2.1" +scalapack_sha256="4aede775fdb28fa44b331875730bcd5bab130caaec225fadeccf424c8fcb55aa" +scalapack_pkg="scalapack-${scalapack_ver}.tgz" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_scalapack" ] && rm "${BUILDDIR}/setup_scalapack" + +SCALAPACK_CFLAGS='' +SCALAPACK_LDFLAGS='' +SCALAPACK_LIBS='' +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_scalapack" in + __INSTALL__) + echo "==================== Installing ScaLAPACK ====================" + pkg_install_dir="${INSTALLDIR}/scalapack/${scalapack_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "scalapack-${scalapack_ver} is already installed, skipping it." + else + require_env MATH_LIBS + if [ -f ${scalapack_pkg} ]; then + echo "${scalapack_pkg} is found" + else + download_pkg_from_cp2k_org "${scalapack_sha256}" "${scalapack_pkg}" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d scalapack-${scalapack_ver} ] && rm -rf scalapack-${scalapack_ver} + tar -xzf ${scalapack_pkg} + + mkdir -p "scalapack-${scalapack_ver}/build" + pushd "scalapack-${scalapack_ver}/build" > /dev/null + + flags="" + if ("${FC}" --version | grep -q 'GNU'); then + flags=$(allowed_gfortran_flags "-fallow-argument-mismatch") + fi + FFLAGS=$flags cmake -DCMAKE_FIND_ROOT_PATH="$ROOTDIR" \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR="lib" \ + -DBUILD_SHARED_LIBS=NO \ + -DCMAKE_BUILD_TYPE=Release .. \ + -DBUILD_TESTING=NO \ + -DSCALAPACK_BUILD_TESTS=NO \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >> make.log 2>&1 || tail -n ${LOG_LINES} make.log + + popd > /dev/null + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + SCALAPACK_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding ScaLAPACK from system paths ====================" + check_lib -lscalapack "ScaLAPACK" + add_lib_from_paths SCALAPACK_LDFLAGS "libscalapack.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking ScaLAPACK to user paths ====================" + pkg_install_dir="$with_scalapack" + check_dir "${pkg_install_dir}/lib" + SCALAPACK_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_scalapack" != "__DONTUSE__" ]; then + SCALAPACK_LIBS="-lscalapack" + if [ "$with_scalapack" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_scalapack" +prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" +prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +export SCALAPACK_ROOT="${pkg_install_dir}" +EOF + cat "${BUILDDIR}/setup_scalapack" >> $SETUPFILE + fi + cat << EOF >> "${BUILDDIR}/setup_scalapack" +export SCALAPACK_LDFLAGS="${SCALAPACK_LDFLAGS}" +export SCALAPACK_LIBS="${SCALAPACK_LIBS}" +export SCALAPACK_ROOT="${pkg_install_dir}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__SCALAPACK|)" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${SCALAPACK_LDFLAGS}|)" +export CP_LIBS="IF_MPI(-lscalapack|) \${CP_LIBS}" +EOF +fi +cd "${ROOTDIR}" + +# ---------------------------------------------------------------------- +# Suppress reporting of known leaks +# ---------------------------------------------------------------------- +cat << EOF >> ${INSTALLDIR}/lsan.supp +# leaks related to SCALAPACK +leak:pdpotrf_ +EOF + +load "${BUILDDIR}/setup_scalapack" +write_toolchain_env "${INSTALLDIR}" + +report_timing "scalapack" diff --git a/scripts/stage4/install_stage4.sh b/scripts/stage4/install_stage4.sh new file mode 100755 index 0000000..b73e646 --- /dev/null +++ b/scripts/stage4/install_stage4.sh @@ -0,0 +1,10 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +./scripts/stage4/install_libxsmm.sh +./scripts/stage4/install_scalapack.sh +./scripts/stage4/install_cosma.sh + +#EOF diff --git a/scripts/stage5/install_elpa.sh b/scripts/stage5/install_elpa.sh new file mode 100755 index 0000000..57fac7d --- /dev/null +++ b/scripts/stage5/install_elpa.sh @@ -0,0 +1,203 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +# From https://elpa.mpcdf.mpg.de/software/tarball-archive/ELPA_TARBALL_ARCHIVE.html +elpa_ver="2023.05.001" +elpa_sha256="ec64be5d6522810d601a3b8e6a31720e3c3eb4af33a434d8a64570d76e6462b6" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_elpa" ] && rm "${BUILDDIR}/setup_elpa" + +ELPA_CFLAGS='' +ELPA_LDFLAGS='' +ELPA_LIBS='' +elpa_dir_openmp="_openmp" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +# elpa only works with MPI switched on +if [ $MPI_MODE = no ]; then + report_warning $LINENO "MPI is disabled, skipping elpa installation" + cat << EOF > "${BUILDDIR}/setup_elpa" +with_elpa="__FALSE__" +EOF + exit 0 +fi + +case "$with_elpa" in + __INSTALL__) + echo "==================== Installing ELPA ====================" + pkg_install_dir="${INSTALLDIR}/elpa/${elpa_ver}" + install_lock_file="$pkg_install_dir/install_successful" + enable_openmp="yes" + + # specific settings needed on CRAY Linux Environment + if [ "$ENABLE_CRAY" = "__TRUE__" ]; then + if [ ${CRAY_PRGENVCRAY} ]; then + # extra LDFLAGS needed + cray_ldflags="-dynamic" + fi + enable_openmp="no" + fi + + if verify_checksums "${install_lock_file}"; then + echo "elpa-${elpa_ver} is already installed, skipping it." + else + require_env MATH_LIBS + if [ -f elpa-${elpa_ver}.tar.gz ]; then + echo "elpa-${elpa_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${elpa_sha256}" "elpa-${elpa_ver}.tar.gz" + fi + [ -d elpa-${elpa_ver} ] && rm -rf elpa-${elpa_ver} + tar -xzf elpa-${elpa_ver}.tar.gz + + # elpa expect FC to be an mpi fortran compiler that is happy + # with long lines, and that a bunch of libs can be found + cd elpa-${elpa_ver} + + # ELPA-2017xxxx enables AVX2 by default, switch off if machine doesn't support it. + AVX_flag="" + AVX512_flags="" + FMA_flag="" + SSE4_flag="" + config_flags="--disable-avx --disable-avx2 --disable-avx512 --disable-sse --disable-sse-assembly" + if [ "${TARGET_CPU}" = "native" ]; then + if [ -f /proc/cpuinfo ] && [ "${OPENBLAS_ARCH}" = "x86_64" ]; then + has_AVX=$(grep '\bavx\b' /proc/cpuinfo 1> /dev/null && echo 'yes' || echo 'no') + [ "${has_AVX}" = "yes" ] && AVX_flag="-mavx" || AVX_flag="" + has_AVX2=$(grep '\bavx2\b' /proc/cpuinfo 1> /dev/null && echo 'yes' || echo 'no') + [ "${has_AVX2}" = "yes" ] && AVX_flag="-mavx2" + has_AVX512=$(grep '\bavx512f\b' /proc/cpuinfo 1> /dev/null && echo 'yes' || echo 'no') + [ "${has_AVX512}" = "yes" ] && AVX512_flags="-mavx512f" + FMA_flag=$(grep '\bfma\b' /proc/cpuinfo 1> /dev/null && echo '-mfma' || echo '-mno-fma') + SSE4_flag=$(grep '\bsse4_1\b' /proc/cpuinfo 1> /dev/null && echo '-msse4' || echo '-mno-sse4') + grep '\bavx512dq\b' /proc/cpuinfo 1> /dev/null && AVX512_flags+=" -mavx512dq" + grep '\bavx512cd\b' /proc/cpuinfo 1> /dev/null && AVX512_flags+=" -mavx512cd" + grep '\bavx512bw\b' /proc/cpuinfo 1> /dev/null && AVX512_flags+=" -mavx512bw" + grep '\bavx512vl\b' /proc/cpuinfo 1> /dev/null && AVX512_flags+=" -mavx512vl" + config_flags="--enable-avx=${has_AVX} --enable-avx2=${has_AVX2} --enable-avx512=${has_AVX512}" + fi + fi + for TARGET in "cpu" "nvidia"; do + [ "$TARGET" = "nvidia" ] && [ "$ENABLE_CUDA" != "__TRUE__" ] && continue + echo "Installing from scratch into ${pkg_install_dir}/${TARGET}" + + mkdir -p "build_${TARGET}" + cd "build_${TARGET}" + ../configure --prefix="${pkg_install_dir}/${TARGET}/" \ + --libdir="${pkg_install_dir}/${TARGET}/lib" \ + --enable-openmp=${enable_openmp} \ + --enable-shared=no \ + --enable-static=yes \ + --disable-c-tests \ + --disable-cpp-tests \ + ${config_flags} \ + --enable-nvidia-gpu=$([ "$TARGET" = "nvidia" ] && echo "yes" || echo "no") \ + --with-cuda-path=${CUDA_PATH:-${CUDA_HOME:-/CUDA_HOME-notset}} \ + --with-NVIDIA-GPU-compute-capability=$([ "$TARGET" = "nvidia" ] && echo "sm_$ARCH_NUM" || echo "sm_35") \ + CUDA_CFLAGS="-std=c++14 -allow-unsupported-compiler" \ + OMPI_MCA_plm_rsh_agent=/bin/false \ + FC=${MPIFC} \ + CC=${MPICC} \ + CXX=${MPICXX} \ + CPP="cpp -E" \ + FCFLAGS="${FCFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} -ffree-line-length-none ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ + CFLAGS="${CFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ + CXXFLAGS="${CXXFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ + LDFLAGS="-Wl,--allow-multiple-definition -Wl,--enable-new-dtags ${MATH_LDFLAGS} ${SCALAPACK_LDFLAGS} ${cray_ldflags}" \ + LIBS="${SCALAPACK_LIBS} $(resolve_string "${MATH_LIBS}" "MPI")" \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + done + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage5/$(basename ${SCRIPT_NAME})" + fi + [ "$enable_openmp" != "yes" ] && elpa_dir_openmp="" + ELPA_CFLAGS="-I'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/include/elpa${elpa_dir_openmp}-${elpa_ver}/modules' -I'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/include/elpa${elpa_dir_openmp}-${elpa_ver}/elpa'" + ELPA_LDFLAGS="-L'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/lib' -Wl,-rpath,'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/lib'" + ;; + __SYSTEM__) + echo "==================== Finding ELPA from system paths ====================" + check_lib -lelpa_openmp "ELPA" + # get the include paths + elpa_include="$(find_in_paths "elpa_openmp-*" $INCLUDE_PATHS)" + if [ "$elpa_include" != "__FALSE__" ]; then + echo "ELPA include directory threaded version is found to be $elpa_include" + ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" + else + echo "Cannot find elpa_openmp-${elpa_ver} from paths $INCLUDE_PATHS" + exit 1 + fi + # get the lib paths + add_lib_from_paths ELPA_LDFLAGS "libelpa.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking ELPA to user paths ====================" + pkg_install_dir="$with_elpa" + check_dir "${pkg_install_dir}/include" + check_dir "${pkg_install_dir}/lib" + user_include_path="$pkg_install_dir/include" + elpa_include="$(find_in_paths "elpa_openmp-*" user_include_path)" + if [ "$elpa_include" != "__FALSE__" ]; then + echo "ELPA include directory threaded version is found to be $elpa_include/modules" + check_dir "$elpa_include/modules" + ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" + else + echo "Cannot find elpa_openmp-* from path $user_include_path" + exit 1 + fi + ELPA_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_elpa" != "__DONTUSE__" ]; then + ELPA_LIBS="-lelpa${elpa_dir_openmp}" + cat << EOF > "${BUILDDIR}/setup_elpa" +prepend_path CPATH "$elpa_include" +EOF + if [ "$with_elpa" != "__SYSTEM__" ]; then + cat << EOF >> "${BUILDDIR}/setup_elpa" +prepend_path PATH "$pkg_install_dir/bin" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +export ELPA_ROOT="$pkg_install_dir" +EOF + fi + cat "${BUILDDIR}/setup_elpa" >> $SETUPFILE + cat << EOF >> "${BUILDDIR}/setup_elpa" +export ELPA_CFLAGS="${ELPA_CFLAGS}" +export ELPA_LDFLAGS="${ELPA_LDFLAGS}" +export ELPA_LIBS="${ELPA_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__ELPA IF_CUDA(-D__ELPA_NVIDIA_GPU|)|)" +export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${ELPA_CFLAGS}|)" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${ELPA_LDFLAGS}|)" +export CP_LIBS="IF_MPI(${ELPA_LIBS}|) \${CP_LIBS}" +export ELPA_ROOT="$pkg_install_dir" +export ELPA_VERSION="${elpa_ver}" +EOF + +fi + +load "${BUILDDIR}/setup_elpa" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "elpa" diff --git a/scripts/stage5/install_pexsi.sh b/scripts/stage5/install_pexsi.sh new file mode 100755 index 0000000..a78ae99 --- /dev/null +++ b/scripts/stage5/install_pexsi.sh @@ -0,0 +1,151 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +pexsi_ver="1.2.0" +pexsi_sha256="8bfad6ec6866c6a29e1cc87fb1c17a39809795e79ede98373c8ba9a3aaf820dd" +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_pexsi" ] && rm "${BUILDDIR}/setup_pexsi" + +PEXSI_CFLAGS='' +PEXSI_LDFLAGS='' +PEXSI_LIBS='' +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_pexsi" in + __INSTALL__) + echo "==================== Installing PEXSI ====================" + require_env SUPERLU_LDFLAGS + require_env SUPERLU_LIBS + require_env MATH_LIBS + require_env MPI_LDFLAGS + require_env MPI_LIBS + pkg_install_dir="${INSTALLDIR}/pexsi/${pexsi_ver}" + mkdir -p "${pkg_install_dir}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "pexsi_dist-${pexsi_ver} is already installed, skipping it." + else + if [ -f pexsi_v${pexsi_ver}.tar.gz ]; then + echo "pexsi_v${pexsi_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${pexsi_sha256}" "pexsi_v${pexsi_ver}.tar.gz" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d pexsi_v${pexsi_ver} ] && rm -rf pexsi_v${pexsi_ver} + tar -xzf pexsi_v${pexsi_ver}.tar.gz + cd pexsi_v${pexsi_ver} + cat config/make.inc.linux.gnu | + sed -e "s|\(CC *=\).*|\1 ${MPICC}|g" \ + -e "s|\(CXX *=\).*|\1 ${MPICXX}|g" \ + -e "s|\(FC *=\).*|\1 ${MPIFC}|g" \ + -e "s|\(LOADER *=\).*|\1 ${MPICXX}|g" \ + -e "s|\(USE_SYMPACK *=\).*|\1 0|g" \ + -e "s|\(PEXSI_DIR *=\).*|\1 ${PWD}|g" \ + -e "s|\(PEXSI_BUILD_DIR *=\).*|\1 ${pkg_install_dir}|g" \ + -e "s|\(CPP_LIB *=\).*|\1 -lstdc++ ${MPI_LDFLAGS} ${MPI_LIBS} |g" \ + -e "s|\(LAPACK_LIB *=\).*|\1 ${MATH_LDFLAGS} $(resolve_string "${MATH_LIBS}" "MPI")|g" \ + -e "s|\(BLAS_LIB *=\).*|\1|g" \ + -e "s|\(\bMETIS_LIB *=\).*|\1 ${METIS_LDFLAGS} ${METIS_LIBS}|g" \ + -e "s|\(PARMETIS_LIB *=\).*|\1 |g" \ + -e "s|\(DSUPERLU_LIB *=\).*|\1 ${SUPERLU_LDFLAGS} -lsuperlu_dist|g" \ + -e "s|\(SCOTCH_LIB *=\).*|\1 ${SCOTCH_LDFLAGS} -lscotchmetis -lscotch -lscotcherr|g" \ + -e "s|\(PTSCOTCH_LIB *=\).*|\1 ${SCOTCH_LDFLAGS} -lptscotchparmetis -lptscotch -lptscotcherr -lscotch|g" \ + -e "s|\(DSUPERLU_INCLUDE *=\).*|\1 ${SUPERLU_CFLAGS}|g" \ + -e "s|\(INCLUDES *=\).*|\1 ${MATH_CFLAGS} \${DSUPERLU_INCLUDE} \${PEXSI_INCLUDE}|g" \ + -e "s|\(COMPILE_FLAG *=\).*|\1 ${CFLAGS}|g" \ + -e "s|\(SUFFIX *=\).*|\1 ${OPENBLAS_ARCH}|g" \ + -e "s|\(DSUPERLU_DIR *=\).*|\1|g" \ + -e "s|\(METIS_DIR *=\).*|\1|g" \ + -e "s|\(PARMETIS_DIR *=\).*|\1|g" \ + -e "s|\(PTSCOTCH_DIR *=\).*|\1|g" \ + -e "s|\(LAPACK_DIR *=\).*|\1|g" \ + -e "s|\(BLAS_DIR *=\).*|\1|g" \ + -e "s|-DCOREDUMPER||g" \ + -e "s|\(COREDUMPER_LIB *=\).*||g" \ + -e "s|\(GFORTRAN_LIB *=\).*|\1 -lgfortran|g" > make.inc + + # Seemingly this should've been moved together with the other fortran files. + mv ./src/f_interface.f90 ./fortran/ + + # Patch to include explicitly as required by gcc >= 11. + sed -i '/^#include /a #include ' ./include/pexsi/utility_impl.hpp + + # Still issues with parallel make (fortran_examples target) + make finstall > make.log 2>&1 || tail -n ${LOG_LINES} make.log + + ln -sf "${pkg_install_dir}/lib/libpexsi_${OPENBLAS_ARCH}.a" \ + "${pkg_install_dir}/lib/libpexsi.a" + + cp -r ./include/* ${pkg_install_dir}/include/ # bug: make install neglects most header files + + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage5/$(basename ${SCRIPT_NAME})" + fi + PEXSI_CFLAGS="-I'${pkg_install_dir}/include'" + + PEXSI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding Pexsi_DIST from system paths ====================" + check_lib -lpexsi "PEXSI" + # add_include_from_paths PEXSI_CFLAGS "pexsi*" $INCLUDE_PATHS + add_lib_from_paths PEXSI_LDFLAGS "libpexsi.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking Pexsi_Dist to user paths ====================" + pkg_install_dir="$with_pexsi" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + ;; +esac +if [ "$with_pexsi" != "__DONTUSE__" ]; then + PEXSI_LIBS="-lpexsi" + if [ "$with_pexsi" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_pexsi" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + cat "${BUILDDIR}/setup_pexsi" >> $SETUPFILE + fi + cat << EOF >> "${BUILDDIR}/setup_pexsi" +export PEXSI_CFLAGS="${PEXSI_CFLAGS}" +export PEXSI_LDFLAGS="${PEXSI_LDFLAGS}" +export PEXSI_LIBS="${PEXSI_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__LIBPEXSI|)" +export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${PEXSI_CFLAGS}|)" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${PEXSI_LDFLAGS}|)" +export CP_LIBS="IF_MPI(${PEXSI_LIBS}|) \${CP_LIBS}" +EOF + cat << EOF >> ${INSTALLDIR}/lsan.supp +# leaks related to PEXSI +leak:PPEXSIDFTDriver +# leaks in MPICH triggered by PEXSI +leak:MPIR_Dataloop_alloc_and_copy +leak:MPIR_Type_contiguous_impl +leak:MPIR_Typerep_init +# leaks in SuperLU triggered by PEXSI +leak:symbfact_distributeMatrix +EOF +fi + +load "${BUILDDIR}/setup_pexsi" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "pexsi" diff --git a/scripts/stage5/install_ptscotch.sh b/scripts/stage5/install_ptscotch.sh new file mode 100755 index 0000000..eab91bc --- /dev/null +++ b/scripts/stage5/install_ptscotch.sh @@ -0,0 +1,117 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +scotch_ver="6.0.0" +scotch_sha256="e57e16c965bab68c1b03389005ecd8a03745ba20fd9c23081c0bb2336972d879" +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_ptscotch" ] && rm "${BUILDDIR}/setup_ptscotch" + +SCOTCH_CFLAGS="" +SCOTCH_LDFLAGS="" +SCOTCH_LIBS="" +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_ptscotch}" in + __INSTALL__) + echo "==================== Installing PT-Scotch ====================" + pkg_install_dir="${INSTALLDIR}/scotch/${scotch_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "scotch-${scotch_ver} is already installed, skipping it." + else + if [ -f scotch_${scotch_ver}.tar.gz ]; then + echo "scotch_${scotch_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${scotch_sha256}" "scotch_${scotch_ver}.tar.gz" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d scotch_${scotch_ver} ] && rm -rf scotch_${scotch_ver} + tar -xzf scotch_${scotch_ver}.tar.gz + cd scotch_${scotch_ver}/src + cat Make.inc/Makefile.inc.x86-64_pc_linux2 | + sed -e "s|\(^CCS\).*|\1 = ${MPICC}|g" \ + -e "s|\(^CCP\).*|\1 = ${MPICC}|g" \ + -e "s|\(^CCD\).*|\1 = ${MPICC}|g" \ + -e "s|\(^CFLAGS\).*|\1 = ${CFLAGS} -DCOMMON_RANDOM_FIXED_SEED -DSCOTCH_RENAME -Drestrict=__restrict -DIDXSIZE64 ${MPI_CFLAGS}|g" \ + > Makefile.inc + make scotch -j $(get_nprocs) > make-scotch.log 2>&1 || tail -n ${LOG_LINES} make-scotch.log + make ptscotch -j $(get_nprocs) > make-ptscotch.log 2>&1 || tail -n ${LOG_LINES} make-ptscotch.log + # PT-scotch make install is buggy in that it cannot create + # intermediate directories + ! [ -d "${pkg_install_dir}" ] && mkdir -p "${pkg_install_dir}" + make install prefix=${pkg_install_dir} > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + + # PEXSI also needs parmetis.h + cp ./include/parmetis.h "${pkg_install_dir}/include/" + sed -i "s|SCOTCH_Num|int|g" "${pkg_install_dir}/include/parmetis.h" + + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage5/$(basename ${SCRIPT_NAME})" + fi + SCOTCH_CFLAGS="-I'${pkg_install_dir}/include'" + SCOTCH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding PT-Scotch from system paths ====================" + check_lib -lptscotchparmetis "PT-Scotch" + check_lib -lptscotch "PT-Scotch" + check_lib -lptscotcherr "PT-Scotch" + check_lib -lscotchmetis "PT-Scotch" + check_lib -lscotch "PT-Scotch" + check_lib -lscotcherr "PT-Scotch" + check_lib -lptscotchparmetis "PT-Scotch" + add_include_from_paths SCOTCH_CFLAGS "ptscotch.h" $INCLUDE_PATHS + add_lib_from_paths SCOTCH_LDFLAGS "libptscotch.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking PT-Scotch to user paths ====================" + pkg_install_dir="$with_ptscotch" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + SCOTCH_CFLAGS="-I'${pkg_install_dir}/include'" + SCOTCH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_ptscotch" != "__DONTUSE__" ]; then + SCOTCH_LIBS="-lptscotchparmetis -lptscotch -lptscotcherr -lscotchmetis -lscotch -lscotcherr" + if [ "$with_ptscotch" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_ptscotch" +prepend_path PATH "$pkg_install_dir/bin" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + cat "${BUILDDIR}/setup_ptscotch" >> $SETUPFILE + fi + cat << EOF >> "${BUILDDIR}/setup_ptscotch" +export SCOTCH_CFLAGS="${SCOTCH_CFLAGS}" +export SCOTCH_LDFLAGS="${SCOTCH_LDFLAGS}" +export SCOTCH_LIBS="${SCOTCH_LIBS}" +export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${SCOTCH_CFLAGS}|)" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${SCOTCH_LDFLAGS}|)" +export CP_LIBS="IF_MPI(${SCOTCH_LIBS}|) \${CP_LIBS}" +export PTSCOTCH_ROOT="$pkg_install_dir" +EOF +fi + +load "${BUILDDIR}/setup_ptscotch" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "ptscotch" diff --git a/scripts/stage5/install_stage5.sh b/scripts/stage5/install_stage5.sh new file mode 100755 index 0000000..b7f4e17 --- /dev/null +++ b/scripts/stage5/install_stage5.sh @@ -0,0 +1,11 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +./scripts/stage5/install_elpa.sh +./scripts/stage5/install_ptscotch.sh +./scripts/stage5/install_superlu.sh +./scripts/stage5/install_pexsi.sh + +#EOF diff --git a/scripts/stage5/install_superlu.sh b/scripts/stage5/install_superlu.sh new file mode 100755 index 0000000..becddc4 --- /dev/null +++ b/scripts/stage5/install_superlu.sh @@ -0,0 +1,107 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +superlu_ver="6.1.0" # Newer versions don't work with PEXSI 1.2.0. +superlu_sha256="92c6d1424dd830ee2d1e7396a418a5f6645160aea8472e558c4e4bfe006593c4" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_superlu" ] && rm "${BUILDDIR}/setup_superlu" + +SUPERLU_CFLAGS='' +SUPERLU_LDFLAGS='' +SUPERLU_LIBS='' +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_superlu" in + __INSTALL__) + echo "==================== Installing SuperLU_DIST ====================" + require_env MATH_LIBS + pkg_install_dir="${INSTALLDIR}/superlu_dist/${superlu_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "superlu_dist-${superlu_ver} is already installed, skipping it." + else + if [ -f superlu_dist_${superlu_ver}.tar.gz ]; then + echo "superlu_dist_${superlu_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${superlu_sha256}" "superlu_dist_${superlu_ver}.tar.gz" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d superlu_dist-${superlu_ver} ] && rm -rf superlu_dist-${superlu_ver} + tar -xzf superlu_dist_${superlu_ver}.tar.gz + cd superlu_dist-${superlu_ver} + cd build + # Explicitly set LIBDIR to "lib", otherwise it sometimes defaults to "lib64". + cmake -DTPL_ENABLE_PARMETISLIB=FALSE \ + -DCMAKE_INSTALL_PREFIX=${pkg_install_dir} \ + -DCMAKE_INSTALL_LIBDIR=${pkg_install_dir}/lib \ + .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + + # PEXSI needs some more headers. + cp SRC/*.h "${pkg_install_dir}/include" + + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage5/$(basename ${SCRIPT_NAME})" + fi + SUPERLU_CFLAGS="-I'${pkg_install_dir}/include'" + SUPERLU_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding SuperLU_DIST from system paths ====================" + check_lib -lsuperlu_dist "SuperLU_DIST" + add_include_from_paths SUPERLU_CFLAGS "superlu*" $INCLUDE_PATHS + add_lib_from_paths SUPERLU_LDFLAGS "libsuperlu*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking Superlu_Dist to user paths ====================" + pkg_install_dir="$with_superlu" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + SUPERLU_CFLAGS="-I'${pkg_install_dir}/include'" + SUPERLU_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_superlu" != "__DONTUSE__" ]; then + SUPERLU_LIBS="-lsuperlu_dist" + if [ "$with_superlu" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_superlu" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + cat "${BUILDDIR}/setup_superlu" >> $SETUPFILE + fi + cat << EOF >> "${BUILDDIR}/setup_superlu" +export SUPERLU_CFLAGS="${SUPERLU_CFLAGS}" +export SUPERLU_LDFLAGS="${SUPERLU_LDFLAGS}" +export SUPERLU_LIBS="${SUPERLU_LIBS}" +export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${SUPERLU_CFLAGS}|)" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${SUPERLU_LDFLAGS}|)" +export CP_LIBS="IF_MPI(${SUPERLU_LIBS}|) \${CP_LIBS}" +export SUPERLU_ROOT="${pkg_install_dir}" +EOF +fi + +load "${BUILDDIR}/setup_superlu" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "superlu" diff --git a/scripts/stage6/install_gsl.sh b/scripts/stage6/install_gsl.sh new file mode 100755 index 0000000..b3c24ee --- /dev/null +++ b/scripts/stage6/install_gsl.sh @@ -0,0 +1,112 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +gsl_ver="2.7" +gls_sha256="efbbf3785da0e53038be7907500628b466152dbc3c173a87de1b5eba2e23602b" +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_gsl" ] && rm "${BUILDDIR}/setup_gsl" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_gsl" in + __INSTALL__) + echo "==================== Installing gsl ====================" + pkg_install_dir="${INSTALLDIR}/gsl/${gsl_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "gsl-${gsl_ver} is already installed, skipping it." + else + if [ -f gsl-${gsl_ver}.tar.gz ]; then + echo "gsl-${gsl_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${gls_sha256}" "gsl-${gsl_ver}.tar.gz" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d gsl-${gsl_ver} ] && rm -rf gsl-${gsl_ver} + tar -xzf gsl-${gsl_ver}.tar.gz + cd gsl-${gsl_ver} + ./configure --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + --disable-shared \ + --enable-static \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage6/$(basename ${SCRIPT_NAME})" + fi + + GSL_CFLAGS="-I'${pkg_install_dir}/include'" + GSL_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding gsl from system paths ====================" + check_command pkg-config --modversion gsl + add_include_from_paths GSL_CFLAGS "gsl.h" $INCLUDE_PATHS + add_lib_from_paths GSL_LDFLAGS "libgsl.*" $LIB_PATHS + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking gsl to user paths ====================" + pkg_install_dir="$with_gsl" + check_dir "$pkg_install_dir/lib" + check_dir "$pkg_install_dir/include" + GSL_CFLAGS="-I'${pkg_install_dir}/include'" + GSL_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_gsl" != "__DONTUSE__" ]; then + GSL_LIBS="-lgsl" + if [ "$with_gsl" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_gsl" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include" +export GSL_INCLUDE_DIR="$pkg_install_dir/include" +export GSL_LIBRARY="-lgsl" +EOF + fi + cat << EOF >> "${BUILDDIR}/setup_gsl" +export GSL_CFLAGS="${GSL_CFLAGS}" +export GSL_LDFLAGS="${GSL_LDFLAGS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__GSL|)" +export CP_CFLAGS="\${CP_CFLAGS} ${GSL_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${GSL_LDFLAGS}" +export GSL_LIBRARY="-lgsl" +export GSL_ROOT="$pkg_install_dir" +export GSL_INCLUDE_DIR="$pkg_install_dir/include" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib64/pkgconfig" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" + +########################################################## +# +# I only include the library when SIRIUS is activated +# which depends explicitly on MPI +# +########################################################## + + +export CP_LIBS="IF_MPI(${GSL_LIBS}|) \${CP_LIBS}" +EOF + cat "${BUILDDIR}/setup_gsl" >> $SETUPFILE +fi + +load "${BUILDDIR}/setup_gsl" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "gsl" diff --git a/scripts/stage6/install_plumed.sh b/scripts/stage6/install_plumed.sh new file mode 100755 index 0000000..f7cda47 --- /dev/null +++ b/scripts/stage6/install_plumed.sh @@ -0,0 +1,125 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +plumed_ver="2.9.0" +plumed_pkg="plumed-src-${plumed_ver}.tgz" +plumed_sha256="16e3fc77f2f4bc024bd279209e4dd49bfd8ed555325a0c868fe9c6b8fae19862" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_plumed" ] && rm "${BUILDDIR}/setup_plumed" + +PLUMED_LDFLAGS='' +PLUMED_LIBS='' + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_plumed" in + __INSTALL__) + echo "==================== Installing PLUMED ====================" + pkg_install_dir="${INSTALLDIR}/plumed/${plumed_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "plumed-${plumed_ver} is already installed, skipping it." + else + if [ -f ${plumed_pkg} ]; then + echo "${plumed_pkg} is found" + else + download_pkg_from_cp2k_org "${plumed_sha256}" "${plumed_pkg}" + fi + + [ -d plumed-${plumed_ver} ] && rm -rf plumed-${plumed_ver} + tar -xzf ${plumed_pkg} + + echo "Installing from scratch into ${pkg_install_dir}" + cd plumed-${plumed_ver} + # disable generating debugging infos for now to work around an issue in gcc-10.2: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96354 + # note: some MPI wrappers carry a -g forward, thus stripping is not enough + + case "$(uname -s)" in + Darwin) + libs="-lgomp" + ;; + *) + libs="" + ;; + esac + [ -n "${MKL_LIBS}" ] && libs+="$(resolve_string "${MKL_LIBS}" "MPI")" + + # Patch to include explicitly as required by gcc >= 11. + sed -i'' -e '/^#include /a\'$'\n''#include ' ./src/lepton/Operation.h + + ./configure \ + CXX="${MPICXX}" \ + CXXFLAGS="${CXXFLAGS//-g/-g0} ${GSL_CFLAGS}" \ + LDFLAGS="${LDFLAGS} ${GSL_LDFLAGS}" \ + LIBS="${libs}" \ + --prefix=${pkg_install_dir} \ + --libdir="${pkg_install_dir}/lib" \ + --enable-modules=all \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make VERBOSE=1 -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage6/$(basename ${SCRIPT_NAME})" + fi + PLUMED_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding PLUMED from system paths ====================" + check_lib -lplumed "PLUMED" + add_lib_from_paths PLUMED_LDFLAGS "libplumed*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking PLUMED to user paths ====================" + pkg_install_dir="$with_plumed" + check_dir "${pkg_install_dir}/lib" + PLUMED_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac + +if [ "$with_plumed" != "__DONTUSE__" ]; then + # Prefer static library if available + if [ -f "${pkg_install_dir}/lib/libplumed.a" ]; then + PLUMED_LIBS="-l:libplumed.a -ldl -lstdc++ -lz -ldl" + else + PLUMED_LIBS="-lplumed -ldl -lstdc++ -lz -ldl" + fi + if [ "$with_plumed" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_plumed" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + cat "${BUILDDIR}/setup_plumed" >> $SETUPFILE + fi + + cat << EOF >> "${BUILDDIR}/setup_plumed" +export PLUMED_LDFLAGS="${PLUMED_LDFLAGS}" +export PLUMED_LIBS="${PLUMED_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__PLUMED2|)" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${PLUMED_LDFLAGS}|)" +export CP_LIBS="IF_MPI(${PLUMED_LIBS}|) \${CP_LIBS}" +export PLUMED_ROOT=${pkg_install_dir} +EOF +fi + +load "${BUILDDIR}/setup_plumed" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "plumed" diff --git a/scripts/stage6/install_quip.sh b/scripts/stage6/install_quip.sh new file mode 100755 index 0000000..fa5a1d1 --- /dev/null +++ b/scripts/stage6/install_quip.sh @@ -0,0 +1,192 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +# Installing QUIP without GAP because its ASL licence is not GPL-compatible. +# See also https://github.com/libAtoms/QUIP/issues/481 + +quip_ver="0.9.10" +quip_sha256="c03505779634459ea0ba3f7ddc120ac17f0546d44dc9b5096f008f1c3c6620ef" + +fox_ver="b5b69ef9a46837bd944ba5c9bc1cf9d00a6198a7" +fox_sha256="a87dd7faf80612a0df94dc272474f37689c6213c6ac4705fb637644409c5cd4e" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_quip" ] && rm "${BUILDDIR}/setup_quip" + +if [ "${ENABLE_TSAN}" = "__TRUE__" ]; then + report_warning "QUIP is not compatible with the thread sanitizer. The QUIP package will not be installed." + cat << EOF > ${BUILDDIR}/setup_quip +with_quip="__DONTUSE__" +EOF + exit 0 +fi + +if [ "${with_quip}" != "__DONTUSE__" ] && [ "${with_intel}" != "__DONTUSE__" ]; then + report_warning "A QUIP installation using the Intel compiler is currently not supported. The QUIP package will not be installed." + exit 0 +fi + +QUIP_CFLAGS="" +QUIP_LDFLAGS="" +QUIP_LIBS="" +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_quip}" in + __INSTALL__) + echo "==================== Installing QUIP ====================" + require_env MATH_LIBS + pkg_install_dir="${INSTALLDIR}/quip/${quip_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "quip_dist-${quip_ver} is already installed, skipping it." + else + if [ -f QUIP-${quip_ver}.tar.gz ]; then + echo "QUIP-${quip_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${quip_sha256}" "QUIP-${quip_ver}.tar.gz" + fi + if [ -f fox-${fox_ver}.tar.gz ]; then + echo "fox-${fox_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${fox_sha256}" "fox-${fox_ver}.tar.gz" + fi + [ -d QUIP-${quip_ver} ] && rm -rf QUIP-${quip_ver} + [ -d fox-${fox_ver} ] && rm -rf fox-${fox_ver} + echo "Installing from scratch into ${pkg_install_dir}" + tar -xzf QUIP-${quip_ver}.tar.gz + tar -xzf fox-${fox_ver}.tar.gz + cd QUIP-${quip_ver} + rmdir ./src/fox + ln -s ../../fox-${fox_ver} ./src/fox + # translate OPENBLAS_ARCH + case $OPENBLAS_ARCH in + x86_64) + quip_arch="x86_64" + ;; + i386) + quip_arch="x86_32" + ;; + arm*) + quip_arch="x86_64" + ;; + *) + report_error ${LINENO} "arch $OPENBLAS_ARCH is currently not supported." + exit 1 + ;; + esac + # The ARCHER cd has a very annoying habit of printing out + # dir names to stdout for any target directories that are + # more than one level deep, and one cannot seem to disable + # it. This unfortunately messes up the installation script + # for QUIP. So this hack will help to resolve the issue + if [ "${ENABLE_CRAY}" = "__TRUE__" ]; then + sed -i \ + -e "s|\(cd build/.*\)|\1 >&- 2>&-|g" \ + bin/find_sizeof_fortran_t + fi + sed -i \ + -e "s|\(F77 *=\).*|\1 ${FC}|g" \ + -e "s|\(F90 *=\).*|\1 ${FC}|g" \ + -e "s|\(F95 *=\).*|\1 ${FC}|g" \ + -e "s|\(CC *=\).*|\1 ${CC}|g" \ + -e "s|\(CPLUSPLUS *=\).*|\1 ${CXX}|g" \ + -e "s|\(LINKER *=\).*|\1 ${FC}|g" \ + -e "s|\(FPP *=\).*|\1 ${FC} -E -x f95-cpp-input|g" \ + -e "s|\(QUIPPY_FCOMPILER *=\).*|\1 ${FC}|g" \ + -e "s|\(QUIPPY_CPP *=\).*|\1 ${FC} -E -x f95-cpp-input|g" \ + arch/Makefile.linux_${quip_arch}_gfortran + + # workaround for compilation with GCC-10, until properly fixed: + # https://github.com/libAtoms/QUIP/issues/209 + if ("${FC}" --version | grep -q 'GNU'); then + compat_flag=$(allowed_gfortran_flags "-fallow-argument-mismatch") + fi + + # enable debug symbols + echo "F95FLAGS += -g ${compat_flag}" >> arch/Makefile.linux_${quip_arch}_gfortran + echo "F77FLAGS += -g ${compat_flag}" >> arch/Makefile.linux_${quip_arch}_gfortran + echo "CFLAGS += -g" >> arch/Makefile.linux_${quip_arch}_gfortran + echo "CPLUSPLUSFLAGS += -g" >> arch/Makefile.linux_${quip_arch}_gfortran + # Makefile.linux_${quip_arch}_gfortran_openmp includes Makefile.linux_${quip_arch}_gfortran + export QUIP_ARCH=linux_${quip_arch}_gfortran_openmp + # hit enter a few times to accept defaults + echo -e "${MATH_LDFLAGS} $(resolve_string "${MATH_LIBS}") \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" | make config > configure.log + # make -j does not work :-( + make > make.log 2>&1 || tail -n ${LOG_LINES} make.log + ! [ -d "${pkg_install_dir}/include" ] && mkdir -p "${pkg_install_dir}/include" + ! [ -d "${pkg_install_dir}/lib" ] && mkdir -p "${pkg_install_dir}/lib" + cp build/${QUIP_ARCH}/quip_unified_wrapper_module.mod \ + "${pkg_install_dir}/include/" + cp build/${QUIP_ARCH}/*.a \ + "${pkg_install_dir}/lib/" + cp src/fox/objs.${QUIP_ARCH}/lib/*.a \ + "${pkg_install_dir}/lib/" + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage6/$(basename ${SCRIPT_NAME})" + fi + QUIP_CFLAGS="-I'${pkg_install_dir}/include'" + QUIP_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding Quip_DIST from system paths ====================" + check_lib -lquip_core "QUIP" + check_lib -latoms "QUIP" + check_lib -lFoX_sax "QUIP" + check_lib -lFoX_common "QUIP" + check_lib -lFoX_utils "QUIP" + check_lib -lFoX_fsys "QUIP" + add_include_from_paths QUIP_CFLAGS "quip*" $INCLUDE_PATHS + add_lib_from_paths QUIP_LDFLAGS "libquip_core*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking Quip_Dist to user paths ====================" + pkg_install_dir="$with_quip" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + QUIP_CFLAGS="-I'${pkg_install_dir}/include'" + QUIP_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "${with_quip}" != "__DONTUSE__" ]; then + QUIP_LIBS="-lquip_core -latoms -lFoX_sax -lFoX_common -lFoX_utils -lFoX_fsys" + if [ "${with_quip}" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_quip" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + fi + cat << EOF >> "${BUILDDIR}/setup_quip" +export QUIP_CFLAGS="${QUIP_CFLAGS}" +export QUIP_LDFLAGS="${QUIP_LDFLAGS}" +export QUIP_LIBS="${QUIP_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} -D__QUIP" +export CP_CFLAGS="\${CP_CFLAGS} ${QUIP_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${QUIP_LDFLAGS}" +export CP_LIBS="${QUIP_LIBS} \${CP_LIBS}" +export QUIP_ROOT="${pkg_install_dir}" +EOF + cat "${BUILDDIR}/setup_quip" >> ${SETUPFILE} +fi + +load "${BUILDDIR}/setup_quip" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "quip" diff --git a/scripts/stage6/install_stage6.sh b/scripts/stage6/install_stage6.sh new file mode 100755 index 0000000..5fcc612 --- /dev/null +++ b/scripts/stage6/install_stage6.sh @@ -0,0 +1,10 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +./scripts/stage6/install_quip.sh +./scripts/stage6/install_gsl.sh +./scripts/stage6/install_plumed.sh + +#EOF diff --git a/scripts/stage7/install_hdf5.sh b/scripts/stage7/install_hdf5.sh new file mode 100755 index 0000000..46a407b --- /dev/null +++ b/scripts/stage7/install_hdf5.sh @@ -0,0 +1,110 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +hdf5_ver="1.14.2" +hdf5_sha256="ea3c5e257ef322af5e77fc1e52ead3ad6bf3bb4ac06480dd17ee3900d7a24cfb" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_hdf5" ] && rm "${BUILDDIR}/setup_hdf5" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_hdf5" in + __INSTALL__) + echo "==================== Installing hdf5 ====================" + pkg_install_dir="${INSTALLDIR}/hdf5/${hdf5_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "hdf5-${hdf5_ver} is already installed, skipping it." + else + if [ -f hdf5-${hdf5_ver}.tar.bz2 ]; then + echo "hdf5-${hdf5_ver}.tar.bz2 is found" + else + download_pkg_from_cp2k_org "${hdf5_sha256}" "hdf5-${hdf5_ver}.tar.bz2" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d hdf5-${hdf5_ver} ] && rm -rf hdf5-${hdf5_ver} + tar xf hdf5-${hdf5_ver}.tar.bz2 + cd hdf5-${hdf5_ver} + ./configure \ + --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + --enable-fortran \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage7/$(basename ${SCRIPT_NAME})" + fi + HDF5_CFLAGS="-I${pkg_install_dir}/include" + HDF5_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding hdf5 from system paths ====================" + check_command pkg-config --modversion hdf5 + pkg_install_dir=$(h5cc -show | tr " " "\n" | grep "\-L" | cut -c3-) + HDF5_CFLAGS="-I${pkg_install_dir}/include" + HDF5_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking hdf5 to user paths ====================" + pkg_install_dir="${with_hdf5}" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + HDF5_CFLAGS="-I'${pkg_install_dir}/include'" + HDF5_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "${with_hdf5}" != "__DONTUSE__" ]; then + # Prefer static libraries if available + if [ -f "${pkg_install_dir}/lib/libhdf5.a" ]; then + HDF5_LIBS="-l:libhdf5_fortran.a -l:libhdf5_hl.a -l:libhdf5.a -lz" + else + HDF5_LIBS="-lhdf5_fortran -lhdf5_hl -lhdf5 -lz" + fi + if [ "${with_hdf5}" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_hdf5" +prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" +prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path CPATH "${pkg_install_dir}/include" +prepend_path PKG_CONFIG_PATH "${pkg_install_dir}/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}" +EOF + else + HDF5_LIBS="${HDF5_LIBS} -lsz" + fi + cat << EOF >> "${BUILDDIR}/setup_hdf5" +export HDF5_CFLAGS="${HDF5_CFLAGS}" +export HDF5_LDFLAGS="${HDF5_LDFLAGS}" +export CP_DFLAGS="\${CP_DFLAGS} -D__HDF5" +export CP_CFLAGS="\${CP_CFLAGS} ${HDF5_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${HDF5_LDFLAGS}" +export CP_LIBS="${HDF5_LIBS} \${CP_LIBS}" +export HDF5_ROOT="${pkg_install_dir}" +export HDF5_LIBRARIES="${HDF5_LIBS}" +export HDF5_HL_LIBRARIES="${HDF5_LIBS}" +export HDF5_INCLUDE_DIRS="${pkg_install_dir}/include" +EOF + cat "${BUILDDIR}/setup_hdf5" >> $SETUPFILE +fi + +load "${BUILDDIR}/setup_hdf5" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "hdf5" diff --git a/scripts/stage7/install_libtorch.sh b/scripts/stage7/install_libtorch.sh new file mode 100755 index 0000000..84f16ff --- /dev/null +++ b/scripts/stage7/install_libtorch.sh @@ -0,0 +1,113 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. + +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +# From https://pytorch.org/get-started/locally/ +libtorch_ver="1.12.1" +libtorch_sha256="82c7be80860f2aa7963f8700004a40af8205e1d721298f2e09b700e766a9d283" + +# shellcheck source=/dev/null +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_libtorch" ] && rm "${BUILDDIR}/setup_libtorch" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_libtorch}" in + __INSTALL__) + echo "==================== Installing libtorch ====================" + pkg_install_dir="${INSTALLDIR}/libtorch/${libtorch_ver}" + mkdir -p /avfs/projects/ops/libtorch/1.12.1 + install_lock_file="${pkg_install_dir}/install_successful" + archive_file="libtorch-cxx11-abi-shared-with-deps-${libtorch_ver}+cpu.zip" + + if verify_checksums "${install_lock_file}"; then + echo "libtorch-${libtorch_ver} is already installed, skipping it." + else + if [ -f ${archive_file} ]; then + echo "${archive_file} is found" + else + download_pkg_from_cp2k_org "${libtorch_sha256}" "${archive_file}" + fi + + echo "Installing from scratch into ${pkg_install_dir}" + [ -d libtorch ] && rm -rf libtorch + [ -d ${pkg_install_dir} ] && rm -rf ${pkg_install_dir} + unzip -q ${archive_file} + mv libtorch ${pkg_install_dir} + + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage7/$(basename "${SCRIPT_NAME}")" + fi + LIBTORCH_CXXFLAGS="-I${pkg_install_dir}/include" + LIBTORCH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath='${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding libtorch from system paths ====================" + check_lib -ltorch "libtorch" + add_include_from_paths LIBTORCH_CXXFLAGS "libtorch.h" $INCLUDE_PATHS + add_lib_from_paths LIBTORCH_LDFLAGS "libtorch.*" "$LIB_PATHS" + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking libtorch to user paths ====================" + pkg_install_dir="${with_libtorch}" + + # use the lib64 directory if present (multi-abi distros may link lib/ to lib32/ instead) + LIBTORCH_LIBDIR="${pkg_install_dir}/lib" + [ -d "${pkg_install_dir}/lib64" ] && LIBTORCH_LIBDIR="${pkg_install_dir}/lib64" + + check_dir "${LIBTORCH_LIBDIR}" + LIBTORCH_CXXFLAGS="-I${pkg_install_dir}/include" + if [ "$ENABLE_CUDA" = "__TRUE__" ]; then + LIBTORCH_LDFLAGS="-Wl,--no-as-needed,-L'${LIBTORCH_LIBDIR}' -Wl,--no-as-needed,-rpath='${LIBTORCH_LIBDIR}'" + else + LIBTORCH_LDFLAGS="-L'${LIBTORCH_LIBDIR}' -Wl,-rpath='${LIBTORCH_LIBDIR}'" + fi + ;; +esac + +if [ "$with_libtorch" != "__DONTUSE__" ]; then + if [ "$with_libtorch" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_libtorch" +prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" +prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + fi + if [ "$ENABLE_CUDA" = "__TRUE__" ]; then + cat << EOF >> "${BUILDDIR}/setup_libtorch" +export CP_DFLAGS="\${CP_DFLAGS} -D__LIBTORCH" +export CXXFLAGS="\${CXXFLAGS} ${LIBTORCH_CXXFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${LIBTORCH_LDFLAGS}" +export CP_LIBS="\${CP_LIBS} -lc10 -lc10_cuda -ltorch_cpu -ltorch_cuda -ltorch" +EOF + cat "${BUILDDIR}/setup_libtorch" >> "${SETUPFILE}" + else + cat << EOF >> "${BUILDDIR}/setup_libtorch" +export CP_DFLAGS="\${CP_DFLAGS} -D__LIBTORCH" +export CXXFLAGS="\${CXXFLAGS} ${LIBTORCH_CXXFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${LIBTORCH_LDFLAGS}" +export CP_LIBS="\${CP_LIBS} -lc10 -ltorch_cpu -ltorch" +EOF + cat "${BUILDDIR}/setup_libtorch" >> "${SETUPFILE}" + fi +fi + +load "${BUILDDIR}/setup_libtorch" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "libtorch" diff --git a/scripts/stage7/install_libvdwxc.sh b/scripts/stage7/install_libvdwxc.sh new file mode 100755 index 0000000..01ac7f0 --- /dev/null +++ b/scripts/stage7/install_libvdwxc.sh @@ -0,0 +1,126 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" +libvdwxc_ver="0.4.0" +libvdwxc_sha256="3524feb5bb2be86b4688f71653502146b181e66f3f75b8bdaf23dd1ae4a56b33" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_libvdwxc" ] && rm "${BUILDDIR}/setup_libvdwxc" + +if [ "$MPI_MODE" = "no" ] && [ $with_sirius = "__FALSE__" ]; then + report_warning $LINENO "MPI and SIRIUS are disabled, skipping libvdwxc installation" + exit 0 +fi + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_libvdwxc" in + __INSTALL__) + require_env FFTW3_INCLUDES + require_env FFTW3_LIBS + + echo "==================== Installing libvdwxc ====================" + pkg_install_dir="${INSTALLDIR}/libvdwxc/${libvdwxc_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "libvdwxc-${libvdwxc_ver} is already installed, skipping it." + else + if [ -f libvdwxc-${libvdwxc_ver}.tar.gz ]; then + echo "libvdwxc-${libvdwxc_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${libvdwxc_sha256}" "libvdwxc-${libvdwxc_ver}.tar.gz" + fi + + echo "Installing from scratch into ${pkg_install_dir}" + [ -d libvdwxc-${libvdwxc_ver} ] && rm -rf libvdwxc-${libvdwxc_ver} + tar -xzf libvdwxc-${libvdwxc_ver}.tar.gz + cd libvdwxc-${libvdwxc_ver} + + if [ "${MPI_MODE}" = "no" ]; then + # compile libvdwxc without mpi support since fftw (or mkl) do not have mpi support activated + ./configure \ + CC="${CC}" \ + FC="${FC}" \ + FFTW3_INCLUDES="${FFTW3_INCLUDES}" \ + FFTW3_LIBS="$(resolve_string "${FFTW3_LIBS}" "MPI")" \ + --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + --disable-shared \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + else + ./configure \ + CC="${MPICC}" \ + FC="${MPIFC}" \ + FFTW3_INCLUDES="${FFTW3_INCLUDES}" \ + FFTW3_LIBS="$(resolve_string "${FFTW3_LIBS}" "MPI")" \ + --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + --disable-shared \ + > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + fi + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage7/$(basename ${SCRIPT_NAME})" + fi + LIBVDWXC_CFLAGS="-I${pkg_install_dir}/include" + LIBVDWXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding libvdwxc from system paths ====================" + check_command pkg-config --modversion libvdwxc + add_include_from_paths LIBVDWXC_CFLAGS "vdwxc.h" $INCLUDE_PATHS + add_lib_from_paths LIBVDWXC_LDFLAGS "libvdwxc*" $LIB_PATHS + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking libvdwxc to user paths ====================" + pkg_install_dir="$with_libvdwxc" + check_dir "$pkg_install_dir/lib" + check_dir "$pkg_install_dir/include" + LIBVDWXC_CFLAGS="-I'${pkg_install_dir}/include'" + LIBVDWXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_libvdwxc" != "__DONTUSE__" ]; then + LIBVDWXC_LIBS="-lvdwxc" + if [ "$with_libvdwxc" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_libvdwxc" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + fi + cat << EOF >> "${BUILDDIR}/setup_libvdwxc" +export LIBVDWXC_CFLAGS="-I$pkg_install_dir/include ${LIBVDWXC_CFLAGS}" +export LIBVDWXC_LDFLAGS="${LIBVDWXC_LDFLAGS}" +export LIBVDWXC_LIBS="${LIBVDWXC_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__LIBVDWXC|)" +export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${LIBVDWXC_CFLAGS}|)" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${LIBVDWXC_LDFLAGS}|)" +export CP_LIBS="IF_MPI(${LIBVDWXC_LIBS}|) \${CP_LIBS}" +export PKG_CONFIG_PATH="$pkg_install_dir/lib/pkgconfig:$PKG_CONFIG_PATH" +export VDWXC_ROOT="$pkg_install_dir" +EOF + cat "${BUILDDIR}/setup_libvdwxc" >> $SETUPFILE +fi + +load "${BUILDDIR}/setup_libvdwxc" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "libvdwxc" diff --git a/scripts/stage7/install_libvori.sh b/scripts/stage7/install_libvori.sh new file mode 100755 index 0000000..a86462f --- /dev/null +++ b/scripts/stage7/install_libvori.sh @@ -0,0 +1,109 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. + +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +libvori_ver="220621" +libvori_sha256="1cfa98c564814bddacf1c0e7f11582137d758668f6307e6eb392c72317984c14" + +# shellcheck source=/dev/null +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_libvori" ] && rm "${BUILDDIR}/setup_libvori" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_libvori:=__INSTALL__}" in + __INSTALL__) + echo "==================== Installing libvori ====================" + pkg_install_dir="${INSTALLDIR}/libvori/${libvori_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "libvori-${libvori_ver} is already installed, skipping it." + else + if [ -f libvori-${libvori_ver}.tar.gz ]; then + echo "libvori-${libvori_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${libvori_sha256}" "libvori-${libvori_ver}.tar.gz" + fi + + echo "Installing from scratch into ${pkg_install_dir}" + [ -d libvori-${libvori_ver} ] && rm -rf libvori-${libvori_ver} + tar -xzf libvori-${libvori_ver}.tar.gz + + mkdir "libvori-${libvori_ver}/build" + cd "libvori-${libvori_ver}/build" + cmake \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + CMAKE_BUILD_PARALLEL_LEVEL="$(get_nprocs)" cmake --build . > build.log 2>&1 || tail -n ${LOG_LINES} build.log + CMAKE_BUILD_PARALLEL_LEVEL="$(get_nprocs)" cmake --build . --target test > test.log 2>&1 || tail -n ${LOG_LINES} test.log + CMAKE_BUILD_PARALLEL_LEVEL="$(get_nprocs)" cmake --build . --target install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage7/$(basename "${SCRIPT_NAME}")" + fi + LIBVORI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding libvori from system paths ====================" + check_lib -lvori "libvori" + add_lib_from_paths LIBVORI_LDFLAGS "libvori.*" "$LIB_PATHS" + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking libvori to user paths ====================" + pkg_install_dir="${with_libvori}" + + # use the lib64 directory if present (multi-abi distros may link lib/ to lib32/ instead) + LIBVORI_LIBDIR="${pkg_install_dir}/lib" + [ -d "${pkg_install_dir}/lib64" ] && LIBVORI_LIBDIR="${pkg_install_dir}/lib64" + + check_dir "${LIBVORI_LIBDIR}" + LIBVORI_LDFLAGS="-L'${LIBVORI_LIBDIR}' -Wl,-rpath,'${LIBVORI_LIBDIR}'" + ;; +esac + +if [ "$with_libvori" != "__DONTUSE__" ]; then + LIBVORI_LIBS="-lvori -lstdc++" + if [ "$with_libvori" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_libvori" +prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" +prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" +prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" +export LIBVORI_LIBS="${LIBVORI_LIBS}" +export LIBVORI_ROOT="${pkg_install_dir}" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + fi + cat << EOF >> "${BUILDDIR}/setup_libvori" +export LIBVORI_ROOT="${pkg_install_dir}" +export LIBVORI_VERSION=${libvori_ver} +export LIBVORI_LDFLAGS="${LIBVORI_LDFLAGS}" +export LIBVORI_LIBRARY="-lvori" +export CP_DFLAGS="\${CP_DFLAGS} -D__LIBVORI" +export CP_LDFLAGS="\${CP_LDFLAGS} ${LIBVORI_LDFLAGS}" +export CP_LIBS="\${CP_LIBS} ${LIBVORI_LIBS}" +EOF + cat "${BUILDDIR}/setup_libvori" >> "${SETUPFILE}" +fi + +load "${BUILDDIR}/setup_libvori" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "libvori" diff --git a/scripts/stage7/install_spglib.sh b/scripts/stage7/install_spglib.sh new file mode 100755 index 0000000..c5854ce --- /dev/null +++ b/scripts/stage7/install_spglib.sh @@ -0,0 +1,109 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" +spglib_ver="1.16.2" +spglib_sha256="5723789bee7371ebba91d78c729d2a608f198fad5e1c95eebe18fda9f2914ec8" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_spglib" ] && rm "${BUILDDIR}/setup_spglib" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_spglib" in + __INSTALL__) + echo "==================== Installing spglib ====================" + pkg_install_dir="${INSTALLDIR}/spglib/${spglib_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "spglib-${spglib_ver} is already installed, skipping it." + else + if [ -f spglib-${spglib_ver}.tar.gz ]; then + echo "spglib-${spglib_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${spglib_sha256}" "spglib-${spglib_ver}.tar.gz" + fi + + echo "Installing from scratch into ${pkg_install_dir}" + rm -rf spglib-${spglib_ver} "${pkg_install_dir}" + tar -xzf spglib-${spglib_ver}.tar.gz + cd spglib-${spglib_ver} + + mkdir build + cd build + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=NO \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + .. > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) symspg > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >> install.log 2>&1 || tail -n ${LOG_LINES} install.log + # Despite -DBUILD_SHARED_LIBS=NO the shared library gets build and installed. + rm -f "${pkg_install_dir}"/lib*/*.so* + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage7/$(basename ${SCRIPT_NAME})" + fi + + SPGLIB_CFLAGS="-I${pkg_install_dir}/include" + SPGLIB_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + if [ -d "${pkg_install_dir}/lib64" ]; then + ln -sf lib64 ${pkg_install_dir}/lib + cd ${pkg_install_dir} + fi + ;; + __SYSTEM__) + echo "==================== Finding spglib from system paths ====================" + check_command pkg-config --modversion spglib + add_include_from_paths SPGLIB_CFLAGS "spglib.h" $INCLUDE_PATHS + add_lib_from_paths SPGLIB_LDFLAGS "libspglib.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking spglib to user paths ====================" + pkg_install_dir="$with_spglib" + check_dir "$pkg_install_dir/lib" + check_dir "$pkg_install_dir/include" + SPGLIB_CFLAGS="-I'${pkg_install_dir}/include'" + SPGLIB_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +esac +if [ "$with_spglib" != "__DONTUSE__" ]; then + SPGLIB_LIBS="-lsymspg" + if [ "$with_spglib" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_spglib" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + fi + cat << EOF >> "${BUILDDIR}/setup_spglib" +export SPGLIB_CFLAGS="-I$pkg_install_dir/include ${SPGLIB_CFLAGS}" +export SPGLIB_LDFLAGS="${SPGLIB_LDFLAGS}" +export CP_DFLAGS="\${CP_DFLAGS} -D__SPGLIB" +export CP_CFLAGS="\${CP_CFLAGS} ${SPGLIB_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${SPGLIB_LDFLAGS}" +export CP_LIBS="${SPGLIB_LIBS} \${CP_LIBS}" +export LIBSPG_ROOT="$pkg_install_dir" +export LIBSPG_INCLUDE_DIR="$pkg_install_dir/include" +EOF + cat "${BUILDDIR}/setup_spglib" >> $SETUPFILE +fi + +load "${BUILDDIR}/setup_spglib" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "spglib" diff --git a/scripts/stage7/install_stage7.sh b/scripts/stage7/install_stage7.sh new file mode 100755 index 0000000..69fc7cf --- /dev/null +++ b/scripts/stage7/install_stage7.sh @@ -0,0 +1,12 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +./scripts/stage7/install_hdf5.sh +./scripts/stage7/install_libvdwxc.sh +./scripts/stage7/install_spglib.sh +./scripts/stage7/install_libvori.sh +./scripts/stage7/install_libtorch.sh + +#EOF diff --git a/scripts/stage8/install_sirius.sh b/scripts/stage8/install_sirius.sh new file mode 100755 index 0000000..dc2634f --- /dev/null +++ b/scripts/stage8/install_sirius.sh @@ -0,0 +1,305 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +sirius_ver="7.4.3" +sirius_sha256="015679a60a39fa750c5d1bd8fb1ce73945524bef561270d8a171ea2fd4687fec" + +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +if [ "$MPI_MODE" = "no" ]; then + report_warning $LINENO "MPI is disabled, skipping sirius installation" + echo 'with_sirius="__FALSE__"' >> ${BUILDDIR}/setup_sirius + exit 0 +fi + +[ -f "${BUILDDIR}/setup_sirius" ] && rm "${BUILDDIR}/setup_sirius" + +SIRIUS_CFLAGS='' +SIRIUS_LDFLAGS='' +SIRIUS_LIBS='' +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_sirius" in + __DONTUSE__) ;; + + __INSTALL__) + echo "==================== Installing SIRIUS ====================" + require_env FFTW_LDFLAGS + require_env FFTW_LIBS + require_env FFTW_CFLAGS + require_env ELPA_ROOT + require_env ELPA_LDFLAGS + require_env ELPA_LIBS + require_env ELPA_CFLAGS + require_env GSL_ROOT + require_env GSL_LDFLAGS + require_env GSL_CFLAGS + require_env GSL_LIBS + require_env GSL_INCLUDE_DIR + require_env GSL_LIBRARY + require_env MATH_LIBS + require_env MPI_LDFLAGS + require_env MPI_LIBS + require_env SCALAPACK_ROOT + require_env SCALAPACK_LDFLAGS + require_env SCALAPACK_CFLAGS + require_env SCALAPACK_LIBS + require_env LIBXC_LIBS + require_env LIBXC_CFLAGS + require_env LIBXC_LDFLAGS + require_env SPGLIB_LIBS + require_env SPGLIB_CFLAGS + require_env SPGLIB_LDFLAGS + require_env HDF5_LIBS + require_env HDF5_CFLAGS + require_env HDF5_LDFLAGS + require_env LIBVDWXC_CFLAGS + require_env LIBVDWXC_LIBS + require_env LIBVDWXC_LDFLAGS + require_env SPFFT_ROOT + require_env SPFFT_CFLAGS + require_env SPFFT_LDFLAGS + require_env SPFFT_LIBS + require_env SPLA_ROOT + require_env SPLA_CFLAGS + require_env SPLA_LDFLAGS + require_env SPLA_LIBS + require_env COSMA_ROOT + ARCH=$(uname -m) + SIRIUS_OPT="-O3 -DNDEBUG -mtune=native -ftree-loop-vectorize ${MATH_CFLAGS}" + if [ "$ARCH" = "ppc64le" ]; then + SIRIUS_OPT="-O3 -DNDEBUG -mcpu=power8 -mtune=power8 -funroll-loops -ftree-vectorize -mvsx -maltivec -mpopcntd -mveclibabi=mass -fvect-cost-model -fpeel-loops -mcmodel=medium ${MATH_CFLAGS}" + SIRIUS_DBG="-O2 -g -mcpu=power8 -mtune=power8 -funroll-loops -ftree-vectorize -mvsx -maltivec -mpopcntd -mveclibabi=mass -fvect-cost-model -fpeel-loops -mcmodel=medium ${MATH_CFLAGS}" + fi + + if [ "$ARCH" = "x86_64" ]; then + if [ "${with_intel}" != "__DONTUSE__" ]; then + SIRIUS_OPT="-DNDEBUG -O2 -g ${MATH_CFLAGS}" + SIRIUS_DBG="-O1 -g ${MATH_CFLAGS}" + # SIRIUS_DBG and SIRIUS_OPT are not really considered by CMake and rather the CMAKE_BUILD_TYPE matters. + # The CMAKE_BUILD_TYPEs "Release" and "RelWithDebInfo" employ -O3/-O2, but already -O2 makes the SIRIUS + # build quite memory and time intensive. The CMAKE_BUILD_TYPE "Debug" allows for fast compilation, but it + # generates very slow code. + # EXTRA_CMAKE_FLAGS="-DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS= ${EXTRA_CMAKE_FLAGS}" + EXTRA_CMAKE_FLAGS="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_FLAGS= ${EXTRA_CMAKE_FLAGS}" + else + SIRIUS_OPT="-O3 -DNDEBUG -mtune=native -ftree-loop-vectorize ${MATH_CFLAGS}" + SIRIUS_DBG="-O2 -g -mtune=native -ftree-loop-vectorize ${MATH_CFLAGS}" + fi + fi + + pkg_install_dir="${INSTALLDIR}/sirius/${sirius_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "sirius_dist-${sirius_ver} is already installed, skipping it." + else + if [ -f SIRIUS-${sirius_ver}.tar.gz ]; then + echo "sirius_${sirius_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${sirius_sha256}" "SIRIUS-${sirius_ver}.tar.gz" + fi + + echo "Installing from scratch into ${pkg_install_dir}" + [ -d sirius-${sirius_ver} ] && rm -rf sirius-${sirius_ver} + tar -xzf SIRIUS-${sirius_ver}.tar.gz + cd SIRIUS-${sirius_ver} + + # GCC 13 stopped including some common headers. + # https://github.com/electronic-structure/SIRIUS/issues/854 + sed -i'' -e '1s/.*/#include \n&/' src/*.hpp + + rm -Rf build + mkdir build + cd build + # if [ -n "$ELPA_LIBS" ] ; then + # if [ -s "$ELPA_ROOT" ] ; then + # export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$ELPA_ROOT/lib/pkgconfig:$ELPA_ROOT/lib64/pkgconfig + # fi + # EXTRA_CMAKE_FLAGS="-DUSE_ELPA=ON -DELPA_INCLUDE_DIR=${ELPA_ROOT}/include/elpa-${ELPA_VERSION} ${EXTRA_CMAKE_FLAGS}" + # fi + + if [ -n "${SCALAPACK_LIBS}" ]; then + export SCALAPACK_LIB="${SCALAPACK_LIBS}" + if [ -s "${SCALAPACK_ROOT}" ]; then + EXTRA_CMAKE_FLAGS="-DUSE_SCALAPACK=ON -DSCALAPACK_INCLUDE_DIR=${SCALAPACK_ROOT}/include ${EXTRA_CMAKE_FLAGS}" + else + EXTRA_CMAKE_FLAGS="-DUSE_SCALAPACK=ON ${EXTRA_CMAKE_FLAGS}" + fi + fi + if [ -n "${HDF5_LIBS}" ]; then + CMAKE_PREFIX_PATH="${HDF5_ROOT} ${CMAKE_PREFIX_PATH}" + fi + if [ -n "${LIBVDWXC_LIBS}" ]; then + CMAKE_PREFIX_PATH="${LIBVDWXC_ROOT} ${CMAKE_PREFIX_PATH}" + EXTRA_CMAKE_FLAGS="-DUSE_VDWXC=ON ${EXTRA_CMAKE_FLAGS}" + else + EXTRA_CMAKE_FLAGS="-DUSE_VDWXC=OFF ${EXTRA_CMAKE_FLAGS}" + fi + if [ -n "${MKL_LIBS}" ]; then + EXTRA_CMAKE_FLAGS="-DUSE_MKL=ON -DMKL_DEF_LIBRARY=${MKLROOT}/lib/intel64 -DUSE_SCALAPACK=ON ${EXTRA_CMAKE_FLAGS}" + fi + SpFFT_DIR="${SpFFT_ROOT}/lib/cmake/SpFFT" + SpLA_DIR="${SpLA_ROOT}/lib/cmake/SPLA" + COSTA_DIR="${COSMA_ROOT}/lib/cmake/costa" + CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${GSL_ROOT}:${SPGLIB_ROOT}:${LIBXC_ROOT}:${SpFFT_DIR}:${SpLA_DIR}:${COSTA_DIR}" cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_CXX_FLAGS_RELEASE="${SIRIUS_OPT}" \ + -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="${SIRIUS_DBG}" \ + -DCMAKE_CXX_COMPILER="${MPICXX}" \ + -DCMAKE_C_COMPILER="${MPICC}" \ + -DCMAKE_Fortran_COMPILER="${MPIFC}" \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DBUILD_SHARED_LIBS=OFF \ + -DUSE_MEMORY_POOL=OFF \ + -DUSE_ELPA=OFF \ + ${EXTRA_CMAKE_FLAGS} .. \ + > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + + make -j $(get_nprocs) -C src >> make.log 2>&1 || tail -n ${LOG_LINES} make.log + + install -d "${pkg_install_dir}/include" >> install.log 2>&1 + install -d "${pkg_install_dir}/lib" >> install.log 2>&1 + cp -R ../src/* "${pkg_install_dir}/include" >> install.log 2>&1 + install -m 644 src/*.a "${pkg_install_dir}/lib" >> install.log 2>&1 + install -m 644 src/mod_files/*.mod "${pkg_install_dir}/include" >> install.log 2>&1 + cd .. + + # now do we have cuda as well + + if [ "$ENABLE_CUDA" = "__TRUE__" ]; then + [ -d build-cuda ] && rm -rf "build-cuda" + mkdir build-cuda + cd build-cuda + CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${GSL_ROOT}:${SPGLIB_ROOT}:${LIBXC_ROOT}:${SpFFT_DIR}:${SpLA_DIR}:${COSTA_DIR}" cmake \ + -DCMAKE_INSTALL_PREFIX=${pkg_install_dir} \ + -DCMAKE_CXX_FLAGS_RELEASE="${SIRIUS_OPT}" \ + -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="${SIRIUS_DBG}" \ + -DCMAKE_CUDA_FLAGS="-std=c++14 -allow-unsupported-compiler" \ + -DUSE_CUDA=ON \ + -DUSE_ELPA=OFF \ + -DGPU_MODEL=P100 \ + -DUSE_MEMORY_POOL=OFF \ + -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_CXX_COMPILER="${MPICXX}" \ + -DCMAKE_C_COMPILER="${MPICC}" \ + -DCMAKE_Fortran_COMPILER="${MPIFC}" \ + ${EXTRA_CMAKE_FLAGS} .. \ + >> cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) -C src >> make.log 2>&1 || tail -n ${LOG_LINES} make.log + install -d ${pkg_install_dir}/lib/cuda + install -d ${pkg_install_dir}/include/cuda + install -m 644 src/*.a ${pkg_install_dir}/lib/cuda >> install.log 2>&1 + install -m 644 src/mod_files/*.mod ${pkg_install_dir}/include/cuda >> install.log 2>&1 + SIRIUS_CUDA_LDFLAGS="-L'${pkg_install_dir}/lib/cuda' -Wl,-rpath,'${pkg_install_dir}/lib/cuda'" + cd .. + fi + SIRIUS_CFLAGS="-I'${pkg_install_dir}/include/cuda'" + SIRIUS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage8/$(basename ${SCRIPT_NAME})" + fi + ;; + __SYSTEM__) + require_env FFTW_LDFLAGS + require_env FFTW_LIBS + require_env FFTW_CFLAGS + require_env ELPA_ROOT + require_env ELPA_LDFLAGS + require_env ELPA_LIBS + require_env ELPA_CFLAGS + require_env GSL_LDFLAGS + require_env GSL_CFLAGS + require_env GSL_LIBS + require_env MATH_LIBS + require_env MPI_LDFLAGS + require_env MPI_LIBS + require_env SCALAPACK_ROOT + require_env SCALAPACK_LDFLAGS + require_env SCALAPACK_CFLAGS + require_env SCALAPACK_LIBS + require_env LIBXC_LIBS + require_env LIBXC_CFLAGS + require_env LIBXC_LDFLAGS + require_env SPGLIB_LIBS + require_env SPGLIB_CFLAGS + require_env SPGLIB_LDFLAGS + require_env HDF5_LIBS + require_env HDF5_CFLAGS + require_env HDF5_LDFLAGS + require_env LIBVDWXC_CFLAGS + require_env LIBVDWXC_LDFLAGS + require_env LIBVDWXC_LIBS + require_env SPFFT_ROOT + require_env SPFFT_CFLAGS + require_env SPFFT_LDFLAGS + require_env SPFFT_LIBS + require_env SPLA_ROOT + require_env SPLA_CFLAGS + require_env SPLA_LDFLAGS + require_env SPLA_LIBS + check_lib -lsirius "sirius" + add_include_from_paths SIRIUS_CFLAGS "sirius*" $INCLUDE_PATHS + add_lib_from_paths SIRIUS_LDFLAGS "libsirius.*" $LIB_PATHS + ;; + *) + echo "==================== Linking SIRIUS_Dist to user paths ====================" + pkg_install_dir="$with_sirius" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/lib64" + check_dir "${pkg_install_dir}/include" + ;; +esac +if [ "$with_sirius" != "__DONTUSE__" ]; then + SIRIUS_LIBS="-lsirius IF_CUDA(-lcusolver|)" + SIRIUS_CUDA_LDFLAGS="-L'${pkg_install_dir}/lib/cuda' -Wl,-rpath,'${pkg_install_dir}/lib/cuda'" + SIRIUS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + SIRIUS_CFLAGS="-I'${pkg_install_dir}/include'" + if [ "$with_sirius" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_sirius" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib/cuda" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib/cuda" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib/cuda" +prepend_path CPATH "$pkg_install_dir/include" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + cat "${BUILDDIR}/setup_sirius" >> $SETUPFILE + fi + cat << EOF >> "${BUILDDIR}/setup_sirius" +export SIRIUS_CFLAGS="IF_CUDA(-I${pkg_install_dir}/include/cuda|-I${pkg_install_dir}/include)" +export SIRIUS_FFLAGS="IF_CUDA(-I${pkg_install_dir}/include/cuda|-I${pkg_install_dir}/include)" +export SIRIUS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" +export SIRIUS_CUDA_LDFLAGS="-L'${pkg_install_dir}/lib/cuda' -Wl,-rpath,'${pkg_install_dir}/lib/cuda'" +export SIRIUS_LIBS="${SIRIUS_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI("-D__SIRIUS"|)" +export CP_CFLAGS="\${CP_CFLAGS} IF_MPI("\${SIRIUS_CFLAGS}"|)" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(IF_CUDA("\${SIRIUS_CUDA_LDFLAGS}"|"\${SIRIUS_LDFLAGS}")|)" +export CP_LIBS="IF_MPI("\${SIRIUS_LIBS}"|) \${CP_LIBS}" +EOF + + cat << EOF >> ${INSTALLDIR}/lsan.supp +# leaks related to SIRIUS +leak:cublasXtDeviceSelect +leak:sirius::sirius_free_object_handler +leak:sirius::sddk::memory_pool::free +leak:sirius::sddk::memory_block_descriptor::free_subblock +EOF +fi + +load "${BUILDDIR}/setup_sirius" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "sirius" diff --git a/scripts/stage8/install_spfft.sh b/scripts/stage8/install_spfft.sh new file mode 100755 index 0000000..fc229a9 --- /dev/null +++ b/scripts/stage8/install_spfft.sh @@ -0,0 +1,205 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +spfft_ver="1.0.6" +spfft_sha256="d179ccdce65890587d0cbf72dc2e5ec0b200ffc56e723ed01a2f5063de6a8630" +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_SpFFT" ] && rm "${BUILDDIR}/setup_SpFFT" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_spfft}" in + __INSTALL__) + echo "==================== Installing spfft ====================" + pkg_install_dir="${INSTALLDIR}/SpFFT/${spfft_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "SpFFT-${spfft_ver} is already installed, skipping it." + else + if [ -f SpFFT-${spfft_ver}.tar.gz ]; then + echo "SpFFT-${spfft_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${spfft_sha256}" "SpFFT-${spfft_ver}.tar.gz" + + fi + if [ "${MATH_MODE}" = "mkl" ]; then + EXTRA_CMAKE_FLAGS="-DSPFFT_MKL=ON -DSPFFT_FFTW_LIB=MKL" + else + EXTRA_CMAKE_FLAGS="" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d SpFFT-${spfft_ver} ] && rm -rf SpFFT-${spfft_ver} + tar -xzf SpFFT-${spfft_ver}.tar.gz + cd SpFFT-${spfft_ver} + mkdir build-cpu + cd build-cpu + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_CXX_COMPILER="${MPICXX}" \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DSPFFT_OMP=ON \ + -DSPFFT_MPI=ON \ + -DSPFFT_STATIC=ON \ + -DSPFFT_FORTRAN=ON \ + -DSPFFT_INSTALL=ON \ + ${EXTRA_CMAKE_FLAGS} .. \ + > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + + cd .. + + if [ "$ENABLE_CUDA" = "__TRUE__" ]; then + [ -d build-cuda ] && rm -rf "build-cuda" + mkdir build-cuda + cd build-cuda + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_CXX_COMPILER="${MPICXX}" \ + -DCMAKE_CUDA_FLAGS="-std=c++14 -allow-unsupported-compiler" \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DSPFFT_OMP=ON \ + -DSPFFT_MPI=ON \ + -DSPFFT_STATIC=ON \ + -DSPFFT_FORTRAN=ON \ + -DSPFFT_INSTALL=ON \ + -DSPFFT_GPU_BACKEND=CUDA \ + ${EXTRA_CMAKE_FLAGS} .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + install -d ${pkg_install_dir}/lib/cuda + [ -f src/libspfft.a ] && install -m 644 src/*.a ${pkg_install_dir}/lib/cuda >> install.log 2>&1 + [ -f src/libspfft.so ] && install -m 644 src/*.so ${pkg_install_dir}/lib/cuda >> install.log 2>&1 + fi + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage8/$(basename ${SCRIPT_NAME})" + + if [ "$ENABLE_HIP" = "__TRUE__" ]; then + case "${GPUVER}" in + K20X | K40 | K80 | P100 | V100 | A100) + [ -d build-cuda ] && rm -rf "build-cuda" + mkdir build-cuda + cd build-cuda + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_CXX_COMPILER="${MPICXX}" \ + -DCMAKE_CUDA_FLAGS="-std=c++14 -allow-unsupported-compiler" \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DSPFFT_OMP=ON \ + -DSPFFT_MPI=ON \ + -DSPFFT_STATIC=ON \ + -DSPFFT_FORTRAN=ON \ + -DSPFFT_INSTALL=ON \ + -DSPFFT_GPU_BACKEND=CUDA \ + ${EXTRA_CMAKE_FLAGS} .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + install -d ${pkg_install_dir}/lib/cuda + [ -f src/libspfft.a ] && install -m 644 src/*.a ${pkg_install_dir}/lib/cuda >> install.log 2>&1 + [ -f src/libspfft.so ] && install -m 644 src/*.so ${pkg_install_dir}/lib/cuda >> install.log 2>&1 + ;; + Mi50 | Mi100 | Mi200 | Mi250) + [ -d build-hip ] && rm -rf "build-hip" + mkdir build-hip + cd build-hip + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DSPLA_OMP=ON \ + -DSPLA_FORTRAN=ON \ + -DSPLA_INSTALL=ON \ + -DSPLA_STATIC=ON \ + -DSPLA_GPU_BACKEND=ROCM \ + ${EXTRA_CMAKE_FLAGS} .. \ + > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + install -d ${pkg_install_dir}/lib/rocm + [ -f src/libspla.a ] && install -m 644 src/*.a ${pkg_install_dir}/lib/rocm >> install.log 2>&1 + [ -f src/libspla.so ] && install -m 644 src/*.so ${pkg_install_dir}/lib/rocm >> install.log 2>&1 + ;; + *) ;; + + esac + fi + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage8/$(basename ${SCRIPT_NAME})" + fi + SPFFT_ROOT="${pkg_install_dir}" + SPFFT_CFLAGS="-I'${pkg_install_dir}/include'" + SPFFT_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + SPFFT_CUDA_LDFLAGS="-L'${pkg_install_dir}/lib/cuda' -Wl,-rpath,'${pkg_install_dir}/lib/cuda'" + ;; + __SYSTEM__) + echo "==================== Finding spfft from system paths ====================" + check_command pkg-config --modversion spfft + add_include_from_paths SPFFT_CFLAGS "spfft.h" $INCLUDE_PATHS + add_lib_from_paths SPFFT_LDFLAGS "libspfft.*" $LIB_PATHS + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking spfft to user paths ====================" + pkg_install_dir="$with_spfft" + + # use the lib64 directory if present (multi-abi distros may link lib/ to lib32/ instead) + SPFFT_LIBDIR="${pkg_install_dir}/lib" + [ -d "${pkg_install_dir}/lib64" ] && SPFFT_LIBDIR="${pkg_install_dir}/lib64" + + check_dir "${SPFFT_LIBDIR}" + check_dir "${pkg_install_dir}/include" + SPFFT_CFLAGS="-I'${pkg_install_dir}/include'" + SPFFT_LDFLAGS="-L'${SPFFT_LIBDIR}' -Wl,-rpath,'${SPFFT_LIBDIR}'" + ;; +esac +if [ "$with_spfft" != "__DONTUSE__" ]; then + SPFFT_LIBS="-lspfft" + if [ "$with_spfft" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_spfft" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include" +export SPFFT_INCLUDE_DIR="$pkg_install_dir/include" +export SPFFT_LIBS="-lspfft" +export SPFFT_ROOT="${pkg_install_dir}" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + fi + cat << EOF >> "${BUILDDIR}/setup_spfft" +export SPFFT_CFLAGS="${SPFFT_CFLAGS}" +export SPFFT_LDFLAGS="${SPFFT_LDFLAGS}" +export SPFFT_CUDA_LDFLAGS="${SPFFT_CUDA_LDFLAGS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__SPFFT|)" +export CP_CFLAGS="\${CP_CFLAGS} ${SPFFT_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_CUDA(${SPFFT_CUDA_LDFLAGS}|${SPFFT_LDFLAGS})" +export SPFFT_LIBRARY="-lspfft" +export SPFFT_ROOT="$pkg_install_dir" +export SPFFT_INCLUDE_DIR="$pkg_install_dir/include" +export SPFFT_VERSION=${spfft-ver} +export CP_LIBS="IF_MPI(${SPFFT_LIBS}|) \${CP_LIBS}" +EOF + cat "${BUILDDIR}/setup_spfft" >> $SETUPFILE +fi + +load "${BUILDDIR}/setup_spfft" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "spfft" diff --git a/scripts/stage8/install_spla.sh b/scripts/stage8/install_spla.sh new file mode 100755 index 0000000..d17ab80 --- /dev/null +++ b/scripts/stage8/install_spla.sh @@ -0,0 +1,217 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" + +spla_ver="1.5.5" +spla_sha256="bc0c366e228344b1b2df55b9ce750d73c1165380e512da5a04d471db126d66ce" +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_SpLA" ] && rm "${BUILDDIR}/setup_SpLA" + +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "${with_spla}" in + __INSTALL__) + echo "==================== Installing spla ====================" + pkg_install_dir="${INSTALLDIR}/SpLA/${spla_ver}" + install_lock_file="$pkg_install_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "SpLA-${spla_ver} is already installed, skipping it." + else + if [ -f SpLA-${spla_ver}.tar.gz ]; then + echo "SpLA-${spla_ver}.tar.gz is found" + else + download_pkg_from_cp2k_org "${spla_sha256}" "SpLA-${spla_ver}.tar.gz" + + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d SpLA-${spla_ver} ] && rm -rf SpLA-${spla_ver} + tar -xzf SpLA-${spla_ver}.tar.gz + cd spla-${spla_ver} + mkdir -p build-cpu + cd build-cpu + case "${MATH_MODE}" in + cray) + EXTRA_CMAKE_FLAGS="-DSPLA_HOST_BLAS=CRAY_LIBSCI" + ;; + mkl) + EXTRA_CMAKE_FLAGS="-DSPLA_HOST_BLAS=MKL" + ;; + *) + EXTRA_CMAKE_FLAGS="-DSPLA_HOST_BLAS=AUTO" + ;; + esac + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DSPLA_OMP=OFF \ + -DSPLA_FORTRAN=ON \ + -DSPLA_INSTALL=ON \ + -DSPLA_STATIC=ON \ + ${EXTRA_CMAKE_FLAGS} .. \ + > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + + if [ "$ENABLE_CUDA" = "__TRUE__" ]; then + [ -d build-cuda ] && rm -rf "build-cuda" + mkdir build-cuda + cd build-cuda + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DSPLA_OMP=OFF \ + -DSPLA_FORTRAN=ON \ + -DSPLA_INSTALL=ON \ + -DSPLA_STATIC=ON \ + -DSPLA_GPU_BACKEND=CUDA \ + ${EXTRA_CMAKE_FLAGS} .. \ + > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + install -d ${pkg_install_dir}/lib/cuda + [ -f src/libspla.a ] && install -m 644 src/*.a ${pkg_install_dir}/lib/cuda >> install.log 2>&1 + [ -f src/libspla.so ] && install -m 644 src/*.so ${pkg_install_dir}/lib/cuda >> install.log 2>&1 + fi + + if [ "$ENABLE_HIP" = "__TRUE__" ]; then + + case "${GPUVER}" in + K20X | K40 | K80 | P100 | V100 | A100) + [ -d build-cuda ] && rm -rf "build-cuda" + mkdir build-cuda + cd build-cuda + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DSPLA_OMP=OFF \ + -DSPLA_FORTRAN=ON \ + -DSPLA_INSTALL=ON \ + -DSPLA_STATIC=ON \ + -DSPLA_GPU_BACKEND=CUDA \ + ${EXTRA_CMAKE_FLAGS} .. \ + > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + install -d ${pkg_install_dir}/lib/hip + [ -f src/libspla.a ] && install -m 644 src/*.a ${pkg_install_dir}/lib/hip >> install.log 2>&1 + [ -f src/libspla.so ] && install -m 644 src/*.so ${pkg_install_dir}/lib/hip >> install.log 2>&1 + ;; + Mi50 | Mi100 | Mi200 | Mi250) + [ -d build-hip ] && rm -rf "build-hip" + mkdir build-hip + cd build-hip + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DSPLA_OMP=OFF \ + -DSPLA_FORTRAN=ON \ + -DSPLA_INSTALL=ON \ + -DSPLA_STATIC=ON \ + -DSPLA_GPU_BACKEND=ROCM \ + ${EXTRA_CMAKE_FLAGS} .. \ + > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log + install -d ${pkg_install_dir}/lib/hip + [ -f src/libspla.a ] && install -m 644 src/*.a ${pkg_install_dir}/lib/hip >> install.log 2>&1 + [ -f src/libspla.so ] && install -m 644 src/*.so ${pkg_install_dir}/lib/hip >> install.log 2>&1 + ;; + *) ;; + esac + fi + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage8/$(basename ${SCRIPT_NAME})" + fi + SPLA_ROOT="${pkg_install_dir}" + SPLA_CFLAGS="-I'${pkg_install_dir}/include/spla'" + SPLA_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + SPLA_CUDA_LDFLAGS="-L'${pkg_install_dir}/lib/cuda' -Wl,-rpath,'${pkg_install_dir}/lib/cuda'" + SPLA_HIP_LDFLAGS="-L'${pkg_install_dir}/lib/hip' -Wl,-rpath,'${pkg_install_dir}/lib/hip'" + ;; + __SYSTEM__) + echo "==================== Finding spla from system paths ====================" + check_command pkg-config --modversion spla + add_include_from_paths SPLA_CFLAGS "spla.h" $INCLUDE_PATHS + add_lib_from_paths SPLA_LDFLAGS "libspla.*" $LIB_PATHS + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking spla to user paths ====================" + pkg_install_dir="$with_spla" + + # use the lib64 directory if present (multi-abi distros may link lib/ to lib32/ instead) + SPLA_LIBDIR="${pkg_install_dir}/lib" + [ -d "${pkg_install_dir}/lib64" ] && SPLA_LIBDIR="${pkg_install_dir}/lib64" + + check_dir "${SPLA_LIBDIR}" + check_dir "${pkg_install_dir}/include/spla" + SPLA_CFLAGS="-I'${pkg_install_dir}/include/spla'" + SPLA_LDFLAGS="-L'${SPLA_LIBDIR}' -Wl,-rpath,'${SPLA_LIBDIR}'" + ;; +esac +if [ "$with_spla" != "__DONTUSE__" ]; then + SPLA_LIBS="-lspla" + if [ "$with_spla" != "__SYSTEM__" ]; then + cat << EOF > "${BUILDDIR}/setup_spla" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir/lib" +prepend_path CPATH "$pkg_install_dir/include/spla" +export SPLA_INCLUDE_DIR="$pkg_install_dir/include/spla" +export SPLA_LIBS="-lspla" +export SPLA_ROOT="${pkg_install_dir}" +prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig" +prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir" +EOF + fi + cat << EOF >> "${BUILDDIR}/setup_spla" +export SPLA_CFLAGS="${SPLA_CFLAGS}" +export SPLA_LDFLAGS="${SPLA_LDFLAGS}" +export SPLA_CUDA_LDFLAGS="${SPLA_CUDA_LDFLAGS}" +export SPLA_HIP_LDFLAGS="${SPLA_HIP_LDFLAGS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_HIP(-D__OFFLOAD_GEMM|) IF_CUDA(-D__OFFLOAD_GEMM|) ${OFFLOAD_DFLAGS} IF_MPI(-D__SPLA|)" +export CP_CFLAGS="\${CP_CFLAGS} ${SPLA_CFLAGS}" +export SPLA_LIBRARY="-lspla" +export SPLA_ROOT="$pkg_install_dir" +export SPLA_INCLUDE_DIR="$pkg_install_dir/include/spla" +export SPLA_VERSION=${spla-ver} +export CP_LIBS="IF_MPI(${SPLA_LIBS}|) \${CP_LIBS}" +EOF + if [ "$ENABLE_HIP" = "__TRUE__" ]; then + cat << EOF >> "${BUILDDIR}/setup_spla" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_HIP(${SPLA_HIP_LDFLAGS}|${SPLA_LDFLAGS})" +EOF + elif [ "$ENABLE_CUDA" = "__TRUE__" ]; then + cat << EOF >> "${BUILDDIR}/setup_spla" +export CP_LDFLAGS="\${CP_LDFLAGS} IF_CUDA(${SPLA_CUDA_LDFLAGS}|${SPLA_LDFLAGS})" +EOF + else + cat << EOF >> "${BUILDDIR}/setup_spla" +export CP_LDFLAGS="\${CP_LDFLAGS} ${SPLA_LDFLAGS}" +EOF + fi + cat "${BUILDDIR}/setup_spla" >> $SETUPFILE +fi + +load "${BUILDDIR}/setup_spla" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "spla" diff --git a/scripts/stage8/install_stage8.sh b/scripts/stage8/install_stage8.sh new file mode 100755 index 0000000..bcfcaf1 --- /dev/null +++ b/scripts/stage8/install_stage8.sh @@ -0,0 +1,9 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +./scripts/stage8/install_spfft.sh +./scripts/stage8/install_spla.sh +./scripts/stage8/install_sirius.sh +#EOF diff --git a/scripts/stage8/sirius-7.3.0-cudatoolkit.patch b/scripts/stage8/sirius-7.3.0-cudatoolkit.patch new file mode 100755 index 0000000..f2940aa --- /dev/null +++ b/scripts/stage8/sirius-7.3.0-cudatoolkit.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/cudalibs_target.cmake b/cmake/cudalibs_target.cmake +index 29802dd3..3d4d761b 100644 +--- a/cmake/cudalibs_target.cmake ++++ b/cmake/cudalibs_target.cmake +@@ -1,6 +1,5 @@ ++find_package(CUDAToolkit REQUIRED) + if (NOT TARGET sirius::cudalibs) + add_library(sirius::cudalibs INTERFACE IMPORTED) +- set_target_properties(sirius::cudalibs PROPERTIES +- INTERFACE_INCLUDE_DIRECTORIES "${CUDA_INCLUDE_DIRS}" +- INTERFACE_LINK_LIBRARIES "${CUDA_LIBRARIES};${CUDA_CUBLAS_LIBRARIES};${CUDA_CUFFT_LIBRARIES};${CUDA_cusolver_LIBRARY}") ++ target_link_libraries(sirius::cudalibs INTERFACE CUDA::cudart CUDA::cublas CUDA::cufft CUDA::cusolver) + endif() diff --git a/scripts/stage9/install_dbcsr.sh b/scripts/stage9/install_dbcsr.sh new file mode 100755 index 0000000..3776552 --- /dev/null +++ b/scripts/stage9/install_dbcsr.sh @@ -0,0 +1,149 @@ +#!/bin/bash -e + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all + +[ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")" && pwd -P)" + +DBCSR_ver="2.5.0" +DBCSR_sha256="e5c545ec16688027537f7865976b905c0783d038ec289e65635e63e961330601" +source "${SCRIPT_DIR}"/common_vars.sh +source "${SCRIPT_DIR}"/tool_kit.sh +source "${SCRIPT_DIR}"/signal_trap.sh +source "${INSTALLDIR}"/toolchain.conf +source "${INSTALLDIR}"/toolchain.env + +[ -f "${BUILDDIR}/setup_dbcsr" ] && rm "${BUILDDIR}/setup_dbcsr" + +DBCSR_CFLAGS='' +DBCSR_LDFLAGS='' +DBCSR_LIBS='' +! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" +cd "${BUILDDIR}" + +case "$with_dbcsr" in + __INSTALL__) + echo "==================== Installing DBCSR ====================" + # + # to be restored to the right value when this script is included in the toolchain + pkg_install_dir="${INSTALLDIR}/DBCSR/${DBCSR_ver}" + install_lock_file="$pkg_install_dirnstall_dir/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "DBCSR-${DBCSR_ver} is already install_dbcsr.sh installed, skipping it." + else + if [ -f dbcsr-${DBCSR_ver}.tar.gz ]; then + echo "dbcsr-${DBCSR_ver}.tar.gz is found" + else + wget "https://github.com/cp2k/dbcsr/archive/refs/tags/v${DBCSR_ver}.tar.gz" -O "dbcsr-${DBCSR_ver}.tar.gz" + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d dbcsr-${DBCSR_ver} ] && rm -rf dbcsr-${DBCSR_ver} + tar xzf dbcsr-${DBCSR_ver}.tar.gz + cd dbcsr-${DBCSR_ver} + COMPILATION_OPTIONS="-DUSE_OPENMP=ON -DBUILD_TESTING=NO -DWITH_EXAMPLES=NO" + [ -d build-cpu ] && rm -rf "build-cpu" + mkdir build-cpu + cd build-cpu + # build compilation option list + if [ "$MPI_MODE" == "no" ]; then + COMPILATION_OPTIONS="${COMPILATION_OPTIONS} -DUSE_MPI=no" + fi + cmake $COMPILATION_OPTIONS -DCMAKE_INSTALL_PREFIX=${pkg_install_dir} .. + make -j $(get_nprocs) > make.log 2>&1 + make install > install.log 2>&1 + cd .. + + if [ "$ENABLE_CUDA" == "__TRUE__" ]; then + [ -d build-cuda ] && rm -rf "build-cuda" + mkdir build-cuda + COMPILATION_OPTIONS="${COMPILATION_OPTIONS} -DCMAKE_INSTALL_PREFIX=${pkg_install_dir}-cuda -DUSE_ACCEL=cuda -DWITH_GPU=P100" + cmake $COMPILATION_OPTIONS .. + make -j $(get_nprocs) > make.log 2>&1 + make install > install.log 2>&1 + cd .. + fi + + if [ "$ENABLE_HIP" == "__TRUE__" ]; then + [ -d build-hip ] && rm -rf "build-hip" + mkdir build-hip + COMPILATION_OPTIONS="${COMPILATION_OPTIONS} -DCMAKE_INSTALL_PREFIX=${pkg_install_dir}-hip -DUSE_ACCEL=hip -DWITH_GPU=Mi250" + cmake $COMPILATION_OPTIONS .. + make -j $(get_nprocs) > make.log 2>&1 + make install > install.log 2>&1 + cd .. + fi + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/$(basename ${SCRIPT_NAME})" + DBCSR_CFLAGS="-I'${pkg_install_dir}/include'" + DBCSR_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath='${pkg_install_dir}/lib'" + DBCSR_CUDA_CFLAGS="-I'${pkg_install_dir}-cuda/include'" + DBCSR_CUDA_LDFLAGS="-L'${pkg_install_dir}-cuda/lib' -Wl,-rpath='${pkg_install_dir}-cuda/lib'" + DBCSR_HIP_CFLAGS="-I'${pkg_install_dir}-hip/include'" + DBCSR_HIP_LDFLAGS="-L'${pkg_install_dir}-hip/lib' -Wl,-rpath='${pkg_install_dir}-hip/lib'" + fi + ;; + __SYSTEM__) + echo "==================== Finding DBCSR from system paths ====================" + check_lib -ldbcsr "dbcsr" + add_include_from_paths DBCSR_CFLAGS "dbcsr.h" $INCLUDE_PATHS + add_lib_from_paths DBCSR_LDFLAGS "dbcsr.*" $LIB_PATHS + ;; + __DONTUSE__) + report_error ${LINENO} "It is not possible to compile cp2k without dbcsr" + ;; + *) + echo "==================== Linking spfft to user paths ====================" + pkg_install_dir="$with_dbcsr" + + # use the lib64 directory if present (multi-abi distros may link lib/ to lib32/ instead) + DBCSR_LIBDIR="${pkg_install_dir}/lib" + [ -d "${pkg_install_dir}/lib64" ] && DBCSR_LIBDIR="${pkg_install_dir}/lib64" + + check_dir "${DBCSR_LIBDIR}" + check_dir "${pkg_install_dir}/include" + DBCSR_CFLAGS="-I'${pkg_install_dir}/include'" + DBCSR_LDFLAGS="-L'${DBCSR_LIBDIR}' -Wl,-rpath,'${DBCSR_LIBDIR}'" + ;; +esac +if [ "$with_dbcsr" != "__DONTUSE__" ]; then + DBCSR_LIBS="-ldbcsr" + if [ "$with_dbcsr" != "__SYSTEM__" ]; then + if [ "$ENABLE_CUDA" == "__TRUE__" ]; then + pkg_install_dir1="${pkg-install-dir}-cuda" + else + if [ "$ENABLE_HIP" == "__TRUE__" ]; then + pkg_install_dir1="${pkg-install-dir}-hip" + else + pkg_install_dir1="${pkg-install-dir}" + fi + fi + fi + cat << EOF > "${BUILDDIR}/setup_dbcsr" +prepend_path LD_LIBRARY_PATH "$pkg_install_dir1/lib" +prepend_path LD_RUN_PATH "$pkg_install_dir1/lib" +prepend_path LIBRARY_PATH "$pkg_install_dir1/lib" +prepend_path CPATH "$pkg_install_dir1/include" +prepend_path CMAKE_INSTALL_PREFIX "${pkg_install_dir1}" +export DBCSR_ROOT="${pkg_install_dir}" +export DBCSR_HIP_ROOT="${pkg_install_dir}-hip" +export DBCSR_CUDA_ROOT="${pkg_install_dir}-cuda" +EOF + cat "${BUILDDIR}/setup_dbcsr" >> $SETUPFILE +fi +cat << EOF >> "${BUILDDIR}/setup_dbcsr" +export DBCSR_CFLAGS="${DBCSR_CFLAGS}" +export DBCSR_LDFLAGS="IF_CUDA(${DBCSR_CUDA_LDFLAGS}|IF_HIP(${DBCSR_HIP_LDFLAGS}|${DBCSR_LDFLAGS}))" +export DBCSR_LIBS="${DBCSR_LIBS}" +export CP_DFLAGS="\${CP_DFLAGS} IF_CUDA(-D__DBCSR_ACC -D__DBCSR|IF_HIP(-D__DBCSR_ACC -D__DBCSR|-D__DBCSR))" +export CP_CFLAGS="\${CP_CFLAGS} ${DBCSR_CFLAGS}" +export CP_LDFLAGS="\${CP_LDFLAGS} ${DBCSR_LDFLAGS}" +export CP_LIBS="${DBCSR_LIBS} \${CP_LIBS}" +EOF + +cat "${BUILDDIR}/setup_dbcsr" >> $SETUPFILE + +load "${BUILDDIR}/setup_dbcsr" +write_toolchain_env "${INSTALLDIR}" + +cd "${ROOTDIR}" +report_timing "DBCSR" \ No newline at end of file diff --git a/scripts/stage9/install_octave.sh b/scripts/stage9/install_octave.sh deleted file mode 100644 index 0279741..0000000 --- a/scripts/stage9/install_octave.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -OCTAVE_VERSION=8.4.0 - -wget -c https://mirrors.kernel.org/gnu/octave/octave-${OCTAVE_VERSION}.tar.gz -# wget -c ftp://ftp.gnu.org/gnu/octave/octave-3.6.3.tar.bz2 -tar -xvf octave-${OCTAVE_VERSION}.tar.gz -cd octave-${OCTAVE_VERSION} -mkdir build && cd build -# ../configure --help -../configure --prefix=/opt/octave/${OCTAVE_VERSION} --enable-64 --enable-readline --with-blas --with-lapack --with-fftw3 --with-qt --with-magick -make -make check -make install diff --git a/scripts/tool_kit.sh b/scripts/tool_kit.sh index 8d5a540..30d9606 100644 --- a/scripts/tool_kit.sh +++ b/scripts/tool_kit.sh @@ -1,35 +1,605 @@ -find_mpi() { - # for MPI, we try to detect system MPI variant - if (command -v mpiexec > /dev/null 2>&1); then - export MPI_ENABLED = true - # check if we are dealing with openmpi, mpich or intelmpi - if (mpiexec --version 2>&1 | grep -s -q "HYDRA"); then - echo "MPI is detected and it appears to be MPICH" - export MPI_MODE="mpich" - # check openmpi version as reported by mpiexec - export MPI_VERSION=$(mpiexec --version | grep "Version:" | awk '{print $2}') - with_mpich="__SYSTEM__" - elif (mpiexec --version 2>&1 | grep -s -q "OpenRTE"); then - echo "MPI is detected and it appears to be OpenMPI" - export MPI_MODE="openmpi" - # check openmpi version as reported by mpiexec - export MPI_VERSION=$(mpiexec --version 2>&1 | grep "(Open MPI)" | awk '{print $4}') - with_openmpi="__SYSTEM__" - elif (mpiexec --version 2>&1 | grep -s -q "Intel"); then - echo "MPI is detected and it appears to be Intel MPI" - export MPI_MODE="intelmpi" - # check intelmpi version as reported by mpiicc - export MPI_VERSION=$(mpiexec --version | grep "Version" | awk '{print $8"."$10}') - with_intelmpi="__SYSTEM__" - else # default to mpich - echo "MPI is detected and defaults to MPICH" - export MPI_MODE="mpich" - with_mpich="__SYSTEM__" - fi +# A set of tools used in the toolchain installer, intended to be used + +# TODO: Review and if possible fix shellcheck errors. +# shellcheck disable=all +# shellcheck shell=bash + +# by sourcing this file inside other scripts. + +SYS_INCLUDE_PATH=${SYS_INCLUDE_PATH:-"/usr/local/include:/usr/include"} +SYS_LIB_PATH=${SYS_LIB_PATH:-"/usr/local/lib64:/usr/local/lib:/usr/lib64:/usr/lib:/lib64:/lib"} +INCLUDE_PATHS=${INCLUDE_PATHS:-"CPATH SYS_INCLUDE_PATH"} +LIB_PATHS=${LIB_PATHS:-"LIBRARY_PATH LD_LIBRARY_PATH LD_RUN_PATH SYS_LIB_PATH"} +time_start=$(date +%s) + +# report timing +report_timing() { + time_stop=$(date +%s) + printf "Step %s took %0.2f seconds.\n" $1 $((time_stop - time_start)) +} + +# report a warning message with script name and line number +report_warning() { + if [ $# -gt 1 ]; then + local __lineno=", line $1" + local __message="$2" else - report_warning $LINENO "No MPI installation detected (ignore this message in Cray Linux Environment or when MPI installation was requested)." - export MPI_MODE="" + local __lineno='' + local __message="$1" fi + echo "WARNING: (${SCRIPT_NAME}${__lineno}) $__message" >&2 +} + +# report an error message with script name and line number +report_error() { + if [ $# -gt 1 ]; then + local __lineno=", line $1" + local __message="$2" + else + local __lineno='' + local __message="$1" + fi + echo "ERROR: (${SCRIPT_NAME}${__lineno}) $__message" >&2 +} + +# error handler for line trap from set -e +error_handler() { + local __lineno="$1" + report_error $1 "Non-zero exit code detected." + exit 1 +} + +# source a file if it exists, otherwise do nothing +load() { + if [ -f "$1" ]; then + source "$1" + fi +} + +# A more portable command that will give the full path, removing +# symlinks, of a given path. This is more portable than readlink -f +# which does not work on Mac OS X +realpath() { + local __path="$1" + if [ "x$__path" = x ]; then + return 0 + fi + local __basename=$(basename "$__path") + if [ -e "$__path" ]; then + echo $( + cd "$(dirname "$__path")" + pwd -P + )/"$__basename" + return 0 + else + return 1 + fi +} + +# given a list, outputs a list with duplicated items filtered out +unique() ( + # given a list, outputs a list with duplicated items filtered out. + # If -d option exists, then output the list delimited + # by ; note that this option does not effect the input. + local __result='' + local __delimiter=' ' + local __item='' + if [ "$1" = "-d" ]; then + shift + __delimiter="$1" + shift + fi + # It is essential that we quote $@, which makes it equivalent to + # "$1" "$2" ... So this works if any of the arguments contains + # space. And we use \n to separate the fields in the + # __result for now, so that fields that contain spaces are + # correctly grepped. + for __item in "$@"; do + if [ x"$__result" = x ]; then + __result="${__item}" + # Note that quoting $__result after echo is essential to + # retain the \n in the variable from the output of echo. Also + # remember grep only works on a line by line basis, so if + # items are delimited by newlines, then for grep search it + # should be delimited by ^ and $ (beginning and end of line) + elif ! (echo "$__result" | + grep -s -q -e "^$__item\$"); then + __result="${__result} +${__item}" + fi + done + __result="$(echo "$__result" | paste -s -d "$__delimiter" -)" + # quoting $__result below is again essential for correct + # behaviour if IFS is set to be the same $__delimiter in the + # parent shell calling this macro + echo "$__result" +) + +# reverse a list +reverse() ( + # given a list, output a list with reversed order. If -d + # option exists, then output the list delimited by + # ; note that this option does not effect the input. + local __result='' + local __delimiter=' ' + local __item='' + if [ "$1" = "-d" ]; then + shift + __delimiter="$1" + shift + fi + for __item in "$@"; do + if [ x"$__result" = x ]; then + __result="$__item" + else + __result="${__item}${__delimiter}${__result}" + fi + done + echo "$__result" +) + +# get the number of processes available for compilation +get_nprocs() { + if [ -n "${NPROCS_OVERWRITE}" ]; then + echo ${NPROCS_OVERWRITE} | sed 's/^0*//' + elif $(command -v nproc > /dev/null 2>&1); then + echo $(nproc --all) + elif $(command -v sysctl > /dev/null 2>&1); then + echo $(sysctl -n hw.ncpu) + else + echo 1 + fi +} + +# convert a list of paths to -L ... used by ld +paths_to_ld() { + # need to define the POSIX default IFS values here, cannot just do + # __ifs=$IFS first, because IFS can be unset, and if so __ifs will + # becomes an empty string (null) and NOT unset, so later when IFS + # is set to __ifs it becomes null rather than unset, and thus + # causing wrong behaviour. So if IFS is unset, __ifs should be + # the POSIX default value. Further more, due to shell + # automatically remove the tailing "\n" in a string during + # variable assignment, we need to add x after \n and then remove + # it. + local __paths=$@ + local __name='' + local __raw_path='' + local __dir='' + local __lib_dirs='' + # set default IFS first + local __ifs=$(printf " \t\nx") + __ifs="${__ifs%x}" + [ "$IFS" ] && __ifs="$IFS" + for __name in $__paths; do + eval __raw_path=\$"$__name" + # change internal field separator to : + IFS=':' + # loop over all dirs in path, and filter out duplications + for __dir in $__raw_path; do + if ! [ x"$__dir" = x ]; then + if ! [[ "$__lib_dirs" =~ (^|[[:space:]])"-L'$__dir'"($|[[:space:]]) ]]; then + __lib_dirs="$__lib_dirs -L'$__dir'" + fi + fi + done + IFS="$__ifs" + done + echo $__lib_dirs +} + +# Find a file from directories given in a list of paths, each has the +# same format as env variable PATH. If the file is found, then echoes +# the full path of the file. If the file is not found, then echoes +# __FALSE__. The file name can also contain wildcards that are +# acceptable for bash, and in that case the full path of the first +# matching file will be echoed. +find_in_paths() { + local __target=$1 + shift + local __paths=$@ + local __name='' + local __raw_path='' + local __dir='' + local __file='' + local __files='' + # use the IFS variable to take care of possible spaces in file/dir names + local __ifs="$(printf " \t\nx")" + __ifs="${__ifs%x}" + [ "$IFS" ] && __ifs="$IFS" + for __name in $__paths; do + eval __raw_path=\$"$__name" + # fields in paths are separated by : + IFS=':' + for __dir in $__raw_path; do + # files in possible glob expansion are to be delimited by "\n\b" + IFS="$(printf "\nx")" + IFS="${IFS%x}" + for __file in $__dir/$__target; do + if [ -e "$__file" ]; then + echo $(realpath "$__file") + # must remember to change IFS back when exiting + IFS="$__ifs" + return 0 + fi + done + IFS=':' + done + IFS=$__ifs + done + echo "__FALSE__" +} + +# search through a list of given paths, try to find the required file +# or directory, and if found then add full path of dirname file, or +# directory, to the -I include list for CFLAGS and append to a user +# specified variable (__cflags_name). If not found, then nothing is +# done. If the option -p is present, then if the search target is a +# directory, then the parent directory of the directory is used for -I +# instead. The search target accepts bash wildcards, and in this case +# the first match will be used. +add_include_from_paths() { + local __parent_dir_only=false + if [ $1 = "-p" ]; then + __parent_dir_only=true + shift + fi + local __cflags_name=$1 + shift + local __search_target=$1 + shift + local __paths=$@ + local __found_target="" + local __cflags="" + __found_target="$(find_in_paths "$__search_target" \ + $__paths)" + if [ "$__found_target" != "__FALSE__" ]; then + if [ -f "$__found_target" ] || $__parent_dir_only; then + __found_target="$(dirname "$__found_target")" + fi + echo "Found include directory $__found_target" + eval __cflags=\$"${__cflags_name}" + __cflags="${__cflags} -I'${__found_target}'" + # remove possible duplicates + __cflags="$(unique $__cflags)" + # must escape all quotes again before the last eval, as + # otherwise all quotes gets interpreted by the shell when + # assigning to variable because eval will reduce one escape + # level + __cflags="${__cflags//'/\\'/}" + eval $__cflags_name=\"$__cflags\" + fi +} + +# search through a list of given paths, try to find the required file +# or directory, and if found then add full path of dirname file, or +# directory, to the -L library list (including -Wl,-rpath) for LDFLAGS +# and append to a user specified variable (__ldflags_name). If not +# found, then nothing is done. If the option -p is present, then if +# the search target is a directory, then the parent directory of the +# directory is used for -L instead. The search target accepts bash +# wildcards, and in this case the first match will be used. +add_lib_from_paths() { + local __parent_dir_only=false + if [ $1 = "-p" ]; then + __parent_dir_only=true + shift + fi + local __ldflags_name=$1 + shift + local __search_target=$1 + shift + local __paths=$@ + local __found_target="" + local __ldflags="" + __found_target="$(find_in_paths "$__search_target" \ + $__paths)" + if [ "$__found_target" != "__FALSE__" ]; then + if [ -f "$__found_target" ] || $__parent_dir_only; then + __found_target="$(dirname "$__found_target")" + fi + echo "Found lib directory $__found_target" + eval __ldflags=\$"${__ldflags_name}" + __ldflags="${__ldflags} -L'${__found_target}' -Wl,-rpath,'${__found_target}'" + # remove possible duplicates + __ldflags="$(unique $__ldflags)" + # must escape all quotes again before the last eval, as + # otherwise all quotes gets interpreted by the shell when + # assigning to variable because eval will reduce one escape + # level + __ldflags="${__ldflags//'/\\'/}" + eval $__ldflags_name=\"$__ldflags\" + fi +} + +# check if environment variable is assigned and non-empty +# https://serverfault.com/questions/7503/how-to-determine-if-a-bash-variable-is-empty +require_env() { + local __env_var_name=$1 + local __env_var="$(eval echo \"\$$__env_var_name\")" + if [ -z "${__env_var+set}" ]; then + report_error "requires environment variable $__env_var_name to work" + return 1 + fi +} + +resolve_string() { + local __to_resolve=$1 + shift + local __flags=$@ + + echo $("${SCRIPTDIR}/parse_if.py" $__flags <<< "${__to_resolve}") +} + +# check if a command is available +check_command() { + local __command=${1} + if [ $# -eq 1 ]; then + local __package=${1} + elif [ $# -gt 1 ]; then + local __package=${2} + fi + if $(command -v ${__command} > /dev/null 2>&1); then + echo "path to ${__command} is $(realpath $(command -v ${__command}))" + else + report_error "Cannot find ${__command}, please check if the package ${__package} is installed or in system search path" + return 1 + fi +} + +# check if directory exists +check_dir() { + local __dir=$1 + if [ -d "$__dir" ]; then + echo "Found directory $__dir" + else + report_error "Cannot find $__dir" + return 1 + fi +} + +# check if a command has been installed correctly +check_install() { + local __command=${1} + if [ $# -eq 1 ]; then + local __package=${1} + elif [ $# -gt 1 ]; then + local __package=${2} + fi + if $(command -v ${__command} > /dev/null 2>&1); then + echo "$(basename ${__command}) is installed as $(command -v ${__command})" + else + report_error "cannot find ${__command}, please check if the package ${__package} has been installed correctly" + return 1 + fi +} + +# check if a library can be found by ld, library names should in the +# format -lname, which would then referred to libname.a or libname.so +# by ld +check_lib() { + local __libname="${1#-l}" + if [ $# -eq 1 ]; then + local __package=lib"$__libname" + elif [ $# -gt 1 ]; then + local __package=$2 + fi + # Note that LD_LIBRARY_PATH is NOT used by ld during linking + # stage, and is only used for searching to the shared libraries + # required by the executable AFTER it has already been compiled, to + # override its internal search paths built into the binary when it + # was compiled. Here, we explicitly include the commonly defined + # library search paths---including LD_LIBRARY_PATH---in the -L + # search paths of ld. This is the only way ld can include + # non-standard directories in its search path. If we use gcc + # instead of ld for linker then we can use LIBRARY_PATH, which IS + # used during link stage. However, I think using ld is more + # general, as in most systems LIBRARY_PATH is rarely defined, and + # we would have to rely on gcc. + local __search_engine="ld -o /dev/null" + local __search_paths="$LIB_PATHS" + # convert a list of paths to -L list used by ld + __search_engine="$__search_engine $(paths_to_ld $__search_paths)" + # needed the eval to interpret the quoted directories correctly (somehow) + if (eval $__search_engine -l$__libname 2>&1 | grep -q -s "\-l$__libname"); then + # if library not found, ld will return error message + # containing the library name + report_error \ + "ld cannot find -l$__libname, please check if $__package is installed or in system search path" + return 1 + else + # if library is found, then ld will return error message about + # not able to find _start or _main symbol + echo "lib$__libname is found in ld search path" + fi +} + +# check if a module is available for the current version of gfortran, +# returns 0 if available and 1 if not +check_gfortran_module() { + local __module_name=$1 + local __FC=${FC:-gfortran} + cat << EOF | $__FC -c -o /dev/null -xf95 -ffree-form - > /dev/null 2>&1 +PROGRAM check_gfortran_module +USE ${__module_name} +IMPLICIT NONE +PRINT *, "PASS" +END PROGRAM check_gfortran_module +EOF +} + +# check if a flag is allowed for the current version of +# gfortran. returns 0 if allowed and 1 if not +check_gfortran_flag() { + local __flag=$1 + local __FC=${FC:-gfortran} + # no need to do a full compilation, just -E -cpp would do for + # checking flags + cat << EOF | $__FC -E -cpp $__flag -xf95 -ffree-form - > /dev/null 2>&1 +PROGRAM test_code + IMPLICIT NONE + PRINT *, "PASS" +END PROGRAM test_code +EOF +} + +# check if a flag is allowed for the current version of +# gcc. returns 0 if allowed and 1 if not +check_gcc_flag() { + local __flag=$1 + local __CC=${CC:-gcc} + # no need to do a full compilation, just -E -cpp would do for + # checking flags + cat << EOF | $__CC -E -cpp $__flag -xc - > /dev/null 2>&1 +#include +int main() { + printf("PASS\n"); +} +EOF +} + +# check if a flag is allowed for the current version of +# g++. returns 0 if allowed and 1 if not +check_gxx_flag() { + local __flag=$1 + local __CXX=${CXX:-g++} + # no need to do a full compilation, just -E -cpp would do for + # checking flags + cat << EOF | $__CXX -E -cpp $__flag -xc - > /dev/null 2>&1 +#include +int main() { + printf("PASS\n"); +} +EOF +} + +# given a list of flags, only print out what is allowed by the current +# version of gfortran +allowed_gfortran_flags() { + local __flags=$@ + local __flag='' + local __result='' + for __flag in $__flags; do + if (check_gfortran_flag $__flag); then + [ -z "$__result" ] && __result="$__flag" || __result="$__result $__flag" + fi + done + echo $__result +} + +# given a list of flags, only print out what is allowed by the current +# version of gcc +allowed_gcc_flags() { + local __flags=$@ + local __flag='' + local __result='' + for __flag in $__flags; do + if (check_gcc_flag $__flag); then + [ -z "$__result" ] && __result="$__flag" || __result="$__result $__flag" + fi + done + echo $__result +} + +# given a list of flags, only print out what is allowed by the current +# version of g++ +allowed_gxx_flags() { + local __flags=$@ + local __flag='' + local __result='' + for __flag in $__flags; do + if (check_gxx_flag $__flag); then + [ -z "$__result" ] && __result="$__flag" || __result="$__result $__flag" + fi + done + echo $__result +} + +# remove a directory to a given path +remove_path() { + local __path_name=$1 + local __directory=$2 + local __path="$(eval echo \$$__path_name)" + # must remove all the middle ones first before treating two ends, + # otherwise there can be cases where not all __directory are + # removed. + __path=${__path//:$__directory:/:} + __path=${__path#$__directory:} + __path=${__path%:$__directory} + __path=$(echo "$__path" | sed "s:^$__directory\$::g") + eval $__path_name=\"$__path\" + export $__path_name +} + +# prepend a directory to a given path +prepend_path() { + # prepend directory to $path_name and then export path_name. If + # the directory already exists in path, bring the directory to the + # front of the list. + # $1 is path name + # $2 is directory + remove_path "$1" "$2" + eval $1=\"$2\${$1:+\":\$$1\"}\" + eval export $1 +} + +# append a directory to a given path +append_path() { + # append directory to $path_name and then export path_name. If + # the directory already exists in path, bring the directory to the + # back of the list. + # $1 is path name + # $2 is directory + remove_path "$1" "$2" + eval $1=\"\${$1:+\"\$$1:\"}$2\" + eval export $1 +} + +# helper routine for reading --enable=* input options +read_enable() { + local __input_var="${1#*=}" + case $__input_var in + "$1") + # if there is no "=" then treat as "yes" + echo "__TRUE__" + ;; + yes) + echo "__TRUE__" + ;; + no) + echo "__FALSE__" + ;; + *) + echo "__INVALID__" + ;; + esac +} + +# helper routine for reading --with=* input options +read_with() { + local __input_var="${1#--with*=}" + case $__input_var in + "${1}") + # if there is no "=" then treat as "install" + if [ ${#} -gt 1 ]; then + echo "${2}" + else + echo "__INSTALL__" + fi + ;; + install) + echo "__INSTALL__" + ;; + system) + echo "__SYSTEM__" + ;; + no) + echo "__DONTUSE__" + ;; + *) + echo "${__input_var//\~/$HOME}" + ;; + esac } # helper routine to check integrity of downloaded files @@ -50,6 +620,22 @@ checksum() { fi } +# downloader for the package tars, includes checksum +download_pkg_from_cp2k_org() { + # usage: download_pkg_from_cp2k_org sha256 filename + local __sha256="$1" + local __filename="$2" + local __url="https://www.cp2k.org/static/downloads/$__filename" + # download + echo "wget ${DOWNLOADER_FLAGS} --quiet $__url" + if ! wget ${DOWNLOADER_FLAGS} --quiet $__url; then + report_error "failed to download $__url" + return 1 + fi + # checksum + checksum "$__filename" "$__sha256" +} + # verify the checksums inside the given checksum file verify_checksums() { local __checksum_file=$1 diff --git a/set_smb_share.sh b/set_smb_share.sh deleted file mode 100644 index d9fbb2c..0000000 --- a/set_smb_share.sh +++ /dev/null @@ -1,81 +0,0 @@ -SHARE_DIR=/data/share - -## DEBIAN -sudo apt-get install samba smbclient cifs-utils - -## CENTOS -sudo yum install samba samba-common samba-client - -## Create a directory to share -sudo mkdir -p ${SHARE_DIR} -sudo chmod -R 2770 ${SHARE_DIR} -sudo chown -R nobody:nogroup ${SHARE_DIR} -sudo chcon -t samba_share_t ${SHARE_DIR} - -cat << EOF >> /etc/samba/smb.conf.bkp -[global] -interfaces = 10.0.0.0/24 eth0 -# hosts allow = 127.0.0.1/8 192.168.1.0/24 -workgroup = WORKGROUP -server string = Samba Server %v -netbios name = MYSHARES -# security = user -unix password sync = Yes -passwd program = /usr/bin/passwd %u -map to guest = bad user -dns proxy = no - -[share] -path = ${SHARE_DIR} -available = yes -valid users = ${USER} -read only = no -browsable = yes -public = no -writable = yes - -[Public] -comment = Public Folder -path = ${SHARE_DIR}/public -writable = yes -guest ok = yes -guest only = yes -force create mode = 770 -force directory mode = 770 - -[Private] -comment = Private Folder -path = ${SHARE_DIR} -writable = yes -guest ok = no -valid users = @smbshare -# force create mode = 660 -# force directory mode = 770 -inherit permissions = yes - -EOF - -sudo testparm /etc/samba/smb.conf.bkp - -## IF EXECUTION WORKS, THEN MOVE THE FILE TO THE ORIGINAL PATH -sudo mv /etc/samba/smb.conf.bkp /etc/samba/smb.conf -sudo useradd -M -s /sbin/nologin sambauser -sudo usermod -aG smbshare sambauser -sudo smbpasswd -a sambauser -sudo smbpasswd -e sambauser - -## DEBIAN -sudo systemctl restart nmbd -sudo systemctl restart smbd -sudo ufw allow from 192.168.205.0/24 to any app Samba - -## CENTOS -sudo firewall-cmd --add-service=samba --zone=public --permanent -sudo firewall-cmd --reload -sudo systemctl start smb -sudo systemctl enable smb -sudo systemctl status smb - -sudo systemctl start nmb -sudo systemctl enable nmb -sudo systemctl status nmb \ No newline at end of file