From c0636a943e1b750d562ceb7bfc6d0c770215024f Mon Sep 17 00:00:00 2001 From: Alex Richert Date: Wed, 8 Nov 2023 11:50:42 -0800 Subject: [PATCH 1/2] Add IntelLLVM support --- .github/workflows/Intel.yml | 77 +++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 2 +- src/CMakeLists.txt | 3 +- 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/Intel.yml diff --git a/.github/workflows/Intel.yml b/.github/workflows/Intel.yml new file mode 100644 index 0000000..9f6cefb --- /dev/null +++ b/.github/workflows/Intel.yml @@ -0,0 +1,77 @@ +name: Intel +on: + push: + branches: + - develop + pull_request: + branches: + - develop + +# Use custom shell with -l so .bash_profile is sourced which loads intel/oneapi/setvars.sh +# without having to do it in manually every step +defaults: + run: + shell: bash -leo pipefail {0} + +jobs: + Intel: + runs-on: ubuntu-latest + strategy: + matrix: + compilers: ["CC=icc FC=ifort", "CC=icx FC=ifx"] + + steps: + + # See https://software.intel.com/content/www/us/en/develop/articles/oneapi-repo-instructions.html + - name: install-intel + run: | + cd /tmp + wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB + sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB + rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB + echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list + sudo apt-get update + sudo apt-get install intel-oneapi-dev-utilities intel-oneapi-mpi-devel intel-oneapi-openmp intel-oneapi-compiler-fortran intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic + echo "source /opt/intel/oneapi/setvars.sh" >> ~/.bash_profile + + - name: checkout-pfunit + uses: actions/checkout@v2 + with: + repository: Goddard-Fortran-Ecosystem/pFUnit + path: pfunit + + - name: cache-pfunit + id: cache-pfunit + uses: actions/cache@v2 + with: + path: ~/pfunit + key: pfunit-${{ runner.os }}-${{ matrix.compilers }} + + - name: build-pfunit + if: steps.cache-pfunit.outputs.cache-hit != 'true' + run: | + cd pfunit + mkdir build + cd build + ${{ matrix.compilers }} cmake .. -DSKIP_MPI=YES -DSKIP_ESMF=YES -DSKIP_FHAMCREST=YES -DCMAKE_INSTALL_PREFIX=~/pfunit -DCMAKE_BUILD_TYPE=Release + make -j2 + make install + + - name: checkout + uses: actions/checkout@v4 + with: + path: landsfcutil + submodules: true + + - name: build + run: | + cd landsfcutil + mkdir build + cd build + ${{ matrix.compilers }} cmake .. -DENABLE_TESTS=ON -DCMAKE_PREFIX_PATH="~/pfunit" + make -j2 VERBOSE=1 + + - name: test + run: | + cd $GITHUB_WORKSPACE/landsfcutil/build + make test VERBOSE=1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8964225..2f764e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$") "MinSizeRel" "RelWithDebInfo") endif() -if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|GNU|Clang|AppleClang)$") +if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|IntelLLVM|GNU|Clang|AppleClang)$") message( WARNING "Compiler not officially supported: ${CMAKE_Fortran_COMPILER_ID}") endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9d597e5..60db979 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,4 @@ - -if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$") +if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|IntelLLVM)$") set(CMAKE_Fortran_FLAGS "-g -ip -FR -fp-model strict ${CMAKE_Fortran_FLAGS}") set(CMAKE_Fortran_FLAGS_RELEASE "-O3") set(fortran_d_flags "-r8") From bfc4ad5e59d8fb35f9e1b037c3b1d5e79104f9cb Mon Sep 17 00:00:00 2001 From: Alex Richert Date: Wed, 8 Nov 2023 11:54:06 -0800 Subject: [PATCH 2/2] Add spack-based CI workflow --- .github/workflows/Spack.yml | 68 +++++++++++++++++++++++++++++++++++++ spack/README | 3 ++ spack/package.py | 51 ++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 .github/workflows/Spack.yml create mode 100644 spack/README create mode 100644 spack/package.py diff --git a/.github/workflows/Spack.yml b/.github/workflows/Spack.yml new file mode 100644 index 0000000..3029cbd --- /dev/null +++ b/.github/workflows/Spack.yml @@ -0,0 +1,68 @@ +# This is a CI workflow for the NCEPLIBS-landsfcutil project. +# +# This workflow builds landsfcutil with Spack, including installing with the "--test +# root" option to run the pFunit test. It also has a one-off job that validates +# the recipe by ensuring that every CMake option that should be set in the +# Spack recipe is so set. +# +# Alex Richert, Sep 2023 +name: Spack +on: + push: + branches: + - develop + pull_request: + branches: + - develop + +jobs: + Spack: + strategy: + matrix: + os: ["ubuntu-latest"] + + runs-on: ${{ matrix.os }} + + steps: + + - name: checkout-landsfcutil + uses: actions/checkout@v4 + with: + path: landsfcutil + + - name: spack-build-and-test + run: | + git clone -c feature.manyFiles=true https://github.com/jcsda/spack + . spack/share/spack/setup-env.sh + spack env create landsfcutil-env + spack env activate landsfcutil-env + cp $GITHUB_WORKSPACE/landsfcutil/spack/package.py $SPACK_ROOT/var/spack/repos/builtin/packages/landsfcutil/package.py + spack develop --no-clone --path $GITHUB_WORKSPACE/landsfcutil landsfcutil@develop + spack add landsfcutil@develop%gcc@11 +pfunit + spack external find cmake gmake m4 python + spack concretize + # Run installation and run pFunit testing + spack install --verbose --fail-fast --test root + # Run 'spack load' to check for obvious errors in setup_run_environment + spack load landsfcutil + ls $LANDSFCUTIL_LIB + ls $LANDSFCUTIL_LIB4 + + # This job validates the Spack recipe by making sure each cmake build option is represented + recipe-check: + runs-on: ubuntu-latest + + steps: + + - name: checkout-landsfcutil + uses: actions/checkout@v4 + with: + path: landsfcutil + + - name: recipe-check + run: | + echo "If this jobs fails, look at the most recently output CMake option below and make sure that option appears in spack/package.py" + for opt in $(grep -ioP '^option\(\K(?!(DUMMY_ENTRY))[^ ]+' $GITHUB_WORKSPACE/landsfcutil/CMakeLists.txt) ; do + echo "Checking for presence of '$opt' CMake option in package.py" + grep -cP "define.+\b${opt}\b" $GITHUB_WORKSPACE/landsfcutil/spack/package.py + done diff --git a/spack/README b/spack/README new file mode 100644 index 0000000..3cd86ff --- /dev/null +++ b/spack/README @@ -0,0 +1,3 @@ +This directory contains an authoritative, up-to-date Spack recipe for NCEPLIBS-landsfcutil, which is found under Spack as "landsfcutil". + +Before each release of NCEPLIBS-landsfcutil, this file should be updated to accommodate changes in build options, etc., and .github/workflows/spack.yml should be updated to exercise all variants. Only the version entry should need to be updated after the release prior to incorporation into the Spack repository and the JCSDA Spack fork. diff --git a/spack/package.py b/spack/package.py new file mode 100644 index 0000000..9006e99 --- /dev/null +++ b/spack/package.py @@ -0,0 +1,51 @@ +# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +from spack.package import * + + +class Landsfcutil(CMakePackage): + """Utility routines useful for initializing land-surface states in + NCEP models. + + This is part of NOAA's NCEPLIBS project.""" + + homepage = "https://github.com/NOAA-EMC/NCEPLIBS-landsfcutil" + url = "https://github.com/NOAA-EMC/NCEPLIBS-landsfcutil/archive/refs/tags/v2.4.1.tar.gz" + git = "https://github.com/NOAA-EMC/NCEPLIBS-landsfcutil" + + maintainers("edwardhartnett", "AlexanderRichert-NOAA", "Hang-Lei-NOAA") + + version("develop", branch="develop") + version("2.4.1", sha256="831c5005a480eabe9a8542b4deec838c2650f6966863ea2711cc0cc5db51ca14") + + variant("pfunit", default=False, description="Enable pFunit testing") + + depends_on("pfunit", when="+pfunit") + + def cmake_args(self): + args = [ + self.define("ENABLE_TESTS", self.run_tests), + ] + return args + + def setup_run_environment(self, env): + for suffix in ("4", "d"): + lib = find_libraries( + "liblandsfcutil_" + suffix, root=self.prefix, shared=False, recursive=True + ) + + env.set("LANDSFCUTIL_LIB" + suffix, lib[0]) + env.set("LANDSFCUTIL_INC" + suffix, join_path(self.prefix, "include_" + suffix)) + + def flag_handler(self, name, flags): + if self.spec.satisfies("%fj"): + if name == "fflags": + flags.append("-Free") + return (None, None, flags) + + def check(self): + with working_dir(self.builder.build_directory): + make("test")