From 9c1687837d8b38413fc96ac1cb2561a09737c795 Mon Sep 17 00:00:00 2001
From: "Fabian.Jakub" <fabian@jakub.com>
Date: Tue, 21 Mar 2023 15:18:01 +0100
Subject: [PATCH] first try to run through the icon install with a encapsulated
 spack

---
 platforms/common/spack_utils.sh | 24 ++++++++++++++++++++++--
 templates/common/build_icon.sh  | 28 ++++++++++++++++------------
 2 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/platforms/common/spack_utils.sh b/platforms/common/spack_utils.sh
index 0cd0ade..0650e61 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 e1db875..29442e1 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
-- 
GitLab