From 765524cb298483bebe43e82dc8e594b0db5eac45 Mon Sep 17 00:00:00 2001 From: Alex Richert <alexander.richert@noaa.gov> Date: Wed, 8 Nov 2023 10:19:54 -0800 Subject: [PATCH 1/3] Add IntelLLVM support --- .github/workflows/Intel.yml | 78 +++++++++++++++++++++++++++++++++++++ .github/workflows/main.yml | 2 +- CMakeLists.txt | 2 +- src/CMakeLists.txt | 3 +- 4 files changed, 81 insertions(+), 4 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..e710355 --- /dev/null +++ b/.github/workflows/Intel.yml @@ -0,0 +1,78 @@ +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 }}-${{ hashFiles('pfunit/VERSION') }}-${{ 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 VERBOSE=1 + make install + + - name: checkout + uses: actions/checkout@v4 + with: + path: gfsio + submodules: true + + - name: build + run: | + cd gfsio + mkdir build + cd build + ${{ matrix.compilers }} cmake .. -DENABLE_TESTS=ON -DCMAKE_PREFIX_PATH="~/pfunit" + make -j2 VERBOSE=1 + + - name: test + run: | + cd $GITHUB_WORKSPACE/gfsio/build + make test VERBOSE=1 + diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a7403f8..6d90032 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: uses: actions/cache@v2 with: path: ~/pfunit - key: pfunit-${{ runner.os }}-${{ hashFiles('pfunit/VERSION') }} + key: pfunit-${{ runner.os }}-${{ hashFiles('pfunit/VERSION') }}-gcc - name: build-pfunit if: steps.cache-pfunit.outputs.cache-hit != 'true' diff --git a/CMakeLists.txt b/CMakeLists.txt index 25190d1..f5ab17d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,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 7051443..3a6c885 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 -traceback -free -convert big_endian -assume byterecl ${CMAKE_Fortran_FLAGS}") elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$") From 2aaa0b5b93ef0b1b0d2f27a29b492643660eabdb Mon Sep 17 00:00:00 2001 From: Alex Richert <alexander.richert@noaa.gov> Date: Wed, 8 Nov 2023 10:36:36 -0800 Subject: [PATCH 2/3] Add Spack-based CI workflow --- .github/workflows/Spack.yml | 68 +++++++++++++++++++++++++++++++++++++ spack/README | 3 ++ spack/package.py | 49 ++++++++++++++++++++++++++ 3 files changed, 120 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..abecc5d --- /dev/null +++ b/.github/workflows/Spack.yml @@ -0,0 +1,68 @@ +# This is a CI workflow for the NCEPLIBS-gfsio project. +# +# This workflow builds gfsio 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-gfsio + uses: actions/checkout@v4 + with: + path: gfsio + + - 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 gfsio-env + spack env activate gfsio-env + cp $GITHUB_WORKSPACE/gfsio/spack/package.py $SPACK_ROOT/var/spack/repos/builtin/packages/gfsio/package.py + spack develop --no-clone --path $GITHUB_WORKSPACE/gfsio gfsio@develop + spack add gfsio@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 gfsio + ls $GFSIO_LIB + ls $GFSIO_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-gfsio + uses: actions/checkout@v4 + with: + path: gfsio + + - 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/gfsio/CMakeLists.txt) ; do + echo "Checking for presence of '$opt' CMake option in package.py" + grep -cP "define.+\b${opt}\b" $GITHUB_WORKSPACE/gfsio/spack/package.py + done diff --git a/spack/README b/spack/README new file mode 100644 index 0000000..6c327dc --- /dev/null +++ b/spack/README @@ -0,0 +1,3 @@ +This directory contains an authoritative, up-to-date Spack recipe for NCEPLIBS-gfsio, which is found under Spack as "gfsio". + +Before each release of NCEPLIBS-gfsio, 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..07ab774 --- /dev/null +++ b/spack/package.py @@ -0,0 +1,49 @@ +# 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 Gfsio(CMakePackage): + """The GFSIO library provides an API to convert GFS Gaussian output into + grib output. + + This is part of the NOAA NCEPLIBS project.""" + + homepage = "https://github.com/NOAA-EMC/NCEPLIBS-gfsio" + url = "https://github.com/NOAA-EMC/NCEPLIBS-gfsio/archive/refs/tags/v1.4.1.tar.gz" + git = "https://github.com/NOAA-EMC/NCEPLIBS-gfsio" + + maintainers("AlexanderRichert-NOAA", "Hang-Lei-NOAA", "edwardhartnett") + + version("develop", branch="develop") + version("1.4.1", sha256="eab106302f520600decc4f9665d7c6a55e7b4901fab6d9ef40f29702b89b69b1") + + 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): + lib = find_libraries("libgfsio", root=self.prefix, shared=False, recursive=True) + # Only one library version, but still need to set _4 to make NCO happy + for suffix in ("4", ""): + env.set("GFSIO_LIB" + suffix, lib[0]) + env.set("GFSIO_INC" + suffix, join_path(self.prefix, "include")) + + 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") From 5cb5d37633f99afada0516b1f3bc1a1a576a5bd3 Mon Sep 17 00:00:00 2001 From: Alex Richert <alexander.richert@noaa.gov> Date: Wed, 8 Nov 2023 11:29:14 -0800 Subject: [PATCH 3/3] remove pfunit/VERSION in CI cache keys --- .github/workflows/Intel.yml | 2 +- .github/workflows/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Intel.yml b/.github/workflows/Intel.yml index e710355..cb10432 100644 --- a/.github/workflows/Intel.yml +++ b/.github/workflows/Intel.yml @@ -45,7 +45,7 @@ jobs: uses: actions/cache@v2 with: path: ~/pfunit - key: pfunit-${{ runner.os }}-${{ hashFiles('pfunit/VERSION') }}-${{ matrix.compilers }} + key: pfunit-${{ runner.os }}-${{ matrix.compilers }} - name: build-pfunit if: steps.cache-pfunit.outputs.cache-hit != 'true' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6d90032..b475940 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: uses: actions/cache@v2 with: path: ~/pfunit - key: pfunit-${{ runner.os }}-${{ hashFiles('pfunit/VERSION') }}-gcc + key: pfunit-${{ runner.os }}-gcc - name: build-pfunit if: steps.cache-pfunit.outputs.cache-hit != 'true'