From 866f28ffebf6b7563b9ec869ba323c585ed15570 Mon Sep 17 00:00:00 2001
From: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de>
Date: Mon, 27 Jun 2022 11:28:53 +0200
Subject: [PATCH] Move CI script for Intel to Levante.

---
 .../test.all.intel-classic-2021.5.0}          | 16 ++++++-
 .ci/bb/levante-dkrz/utils.sh                  | 45 +++++++++++++++++++
 2 files changed, 59 insertions(+), 2 deletions(-)
 rename .ci/bb/{mistral-dkrz/test.all.intel-17.0.6 => levante-dkrz/test.all.intel-classic-2021.5.0} (58%)

diff --git a/.ci/bb/mistral-dkrz/test.all.intel-17.0.6 b/.ci/bb/levante-dkrz/test.all.intel-classic-2021.5.0
similarity index 58%
rename from .ci/bb/mistral-dkrz/test.all.intel-17.0.6
rename to .ci/bb/levante-dkrz/test.all.intel-classic-2021.5.0
index 3bed9eb40..66fc79234 100755
--- a/.ci/bb/mistral-dkrz/test.all.intel-17.0.6
+++ b/.ci/bb/levante-dkrz/test.all.intel-classic-2021.5.0
@@ -7,13 +7,23 @@ script_dir=$(cd "$(dirname "$0")"; pwd)
 top_srcdir=$(cd "${script_dir}/../../.."; pwd)
 
 . "${script_dir}/utils.sh"
-init_intel1706
+init_intelclassic202150
 
 test -f "${top_srcdir}/configure" || "${top_srcdir}/autogen.sh"
 
 # Create a subdirectory for building and switch to it:
 mkdir build && cd build
 
+# The configure script does not check the 'lib64' subdirectory, therefore we
+# run it with '--with-eccodes' and the following flags. Note that fixing this
+# in the configure script might be tricky: the 'lib64' subdirectory should be
+# checked first but if it does not exist or does not contain the library, we
+# might end up linking to a library from the linker's default search path
+# (e.g. /usr/lib) instead of the one from "$with_eccodes/lib" because
+# "-L${with_eccodes}/lib64" would be ignored in that case:
+CPPFLAGS="-I${ECCODES_ROOT}/include"
+LDFLAGS="-L${ECCODES_ROOT}/lib64"
+
 "${top_srcdir}/configure" \
 --disable-maintainer-mode \
 --enable-cf-interface \
@@ -21,10 +31,12 @@ mkdir build && cd build
 --enable-mpi \
 --enable-option-checking=fatal \
 --enable-ppm-dist-array \
---with-grib-api="${GRIBAPI_ROOT}" \
+--with-eccodes \
 --with-netcdf="${NETCDF_ROOT}" \
 CC="${MPICC}" \
+CPPFLAGS="${CPPFLAGS}" \
 FC="${MPIFC}" \
+LDFLAGS="${LDFLAGS}" \
 MPI_LAUNCH="${MPI_LAUNCH}" \
 PKG_CONFIG_PATH="${YAXT_ROOT}/lib/pkgconfig:${PPM_ROOT}/lib/pkgconfig"
 
diff --git a/.ci/bb/levante-dkrz/utils.sh b/.ci/bb/levante-dkrz/utils.sh
index 0113ac6f8..da6c10625 100644
--- a/.ci/bb/levante-dkrz/utils.sh
+++ b/.ci/bb/levante-dkrz/utils.sh
@@ -122,6 +122,35 @@ init_gcc1120 ()
   export LD_LIBRARY_PATH="${ECCODES_ROOT}/lib64:${NETCDF_ROOT}/lib:${LD_LIBRARY_PATH-}"
 }
 
+#
+# Sets variables for tests with Intel Classic 2021.5.0.
+#
+init_intelclassic202150 ()
+{
+  init_env
+  # Try to make sure that the compiler works with the system gcc:
+  module unload gcc
+  # For whatever reason, Intel Classic 2021.5.0 is enabled with
+  # intel-oneapi-compilers/2022.0.1-gcc-11.2.0:
+  switch_for_module intel-oneapi-compilers/2022.0.1-gcc-11.2.0 openmpi/4.1.2-intel-2021.5.0
+
+  CC=icc
+  CXX=icpc
+  FC=ifort
+  MPICC=mpicc
+  MPIFC=mpif90
+  MPI_LAUNCH="$(which mpirun)"
+
+  ECCODES_ROOT='/sw/spack-levante/eccodes-2.21.0-3ehkbb'
+  NETCDF_ROOT='/sw/spack-levante/netcdf-c-4.8.1-2k3cmu'
+  PPM_ROOT='/work/mh0287/m300488/libcdi-ci-sw/install/ppm-1.0.8-intel-classic-2021.5.0'
+  YAXT_ROOT='/work/mh0287/m300488/libcdi-ci-sw/install/yaxt-0.9.3-intel-classic-2021.5.0'
+
+  # Here we fix a never-ending story with Libtool overlinkning, absence of
+  # '*.la' files when they could help, and '-Wl,--disable/enable-new-dtags':
+  export LD_LIBRARY_PATH="${ECCODES_ROOT}/lib64:${NETCDF_ROOT}/lib:${LD_LIBRARY_PATH-}"
+}
+
 #
 # Accepts a path to a file containing the testsuite summary (either the
 # 'test-suite.log' or the standard output of the 'make check' command) and
@@ -138,3 +167,19 @@ check_all_tests_passed ()
          }
        }' $1 >&2
 }
+
+#
+# Checks whether the current working directory or any of its subdirectories
+# contain a file and fails with an error message if that is the case.
+#
+check_no_files_in_cwd ()
+{
+  cnfic_files=`find . -type f 2>/dev/null`
+  if test -n "$cnfic_files"; then
+    {
+      echo "ERROR: the current working directory contains undeleted files:"
+      echo "$cnfic_files"
+    } >&2
+    exit 1
+  fi
+}
-- 
GitLab