diff --git a/platforms/common/spack_utils.sh b/platforms/common/spack_utils.sh index 0cd0adeabc4606391788b9f4955680aa9b520900..0650e618d850d432bd6f49962c5880d9807fb741 100644 --- a/platforms/common/spack_utils.sh +++ b/platforms/common/spack_utils.sh @@ -1,7 +1,27 @@ +function spack_env() { +export SPACK_SETUP_ENV=spack/share/spack/setup-env.sh +export SPACK_VENV=spack_icon_env +export SPACK_USER_CACHE_PATH=${WORKDIR}/SPACK_USER_CACHE_PATH +export SPACK_DISABLE_LOCAL_CONFIG=true +} + function install_spack() { +spack_env + +#TODO: Would be good to enable the re-utilization of existing spack packages (via packages.yaml or upstreams.yaml) +if [ ! -f ${SPACK_SETUP_ENV} ]; then + git clone ${SPACK_URL} -b ${SPACK_BRANCH} +fi +. ${SPACK_SETUP_ENV} +spack env create $SPACK_VENV +spack env activate -p $SPACK_VENV +spack compiler find } function load_spack() { - -} \ No newline at end of file +spack_env +if [ ! -f ${SPACK_SETUP_ENV} ]; then install_spack; fi +. ${SPACK_SETUP_ENV} +spack env activate -p $SPACK_VENV +} diff --git a/templates/common/build_icon.sh b/templates/common/build_icon.sh index e1db87552109fb6b78a7b6cb1a300c1a33ab23bd..29442e138ca163b608b9fd294d2c414a036ada42 100644 --- a/templates/common/build_icon.sh +++ b/templates/common/build_icon.sh @@ -14,24 +14,28 @@ fi # Go to the working directory cd ${WORKDIR} -# Check if experiment's spack installation already exists, if it doesn't, clone it. -SPACK_ENV=spack/share/spack/setup-env.sh -if [ ! -f ${SPACK_ENV} ]; then - git clone ${SPACK_URL} -b ${SPACK_BRANCH} - #TODO: Would be good to enable the re-utilization of existing spack packages (via packages.yaml or upstreams.yaml) -fi - -# Setup the environment -source ${SPACK_ENV} +. ${WORKDIR}/proj/platforms/common/spack_utils.sh +load_spack if [ $( spack find icon-nwp@${ICON_VERSION} &>/dev/null echo $? ) -ne 0 ]; then echo "Installing icon-nwp@${ICON_VERSION}." - # Compile openmpi with schedulers=slurm - spack install openmpi%${SPACK_COMPILER}+legacylaunchers schedulers=slurm - spack install icon-nwp@${ICON_VERSION}%${SPACK_COMPILER} ^openmpi%${SPACK_COMPILER} + + if [[ $(spack compiler info ${SPACK_COMPILER}) ]]; then + echo "Found Compiler" + else + echo "could not find compiler, try to install it... this may take a while" + spack add ${SPACK_COMPILER} + spack install + spack compiler add $(spack location --install-dir $SPACK_COMPILER) + fi + + spack add ucx%${SPACK_COMPILER}+dc+dm+ib_hw_tm+mlx5_dv+rc+rdmacm+thread_multiple+ud+verbs~cuda + spack add openmpi%${SPACK_COMPILER}+pmi+legacylaunchers~cuda schedulers=slurm fabrics=ucx + spack add icon-nwp@${ICON_VERSION}%${SPACK_COMPILER} ^openmpi%${SPACK_COMPILER} + spack install else echo "icon-nwp@${ICON_VERSION} already installed!" fi