name: Tests on: push: branches: [master] pull_request: schedule: - cron: '0 6 * * 1' workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: all: if: github.event_name != 'schedule' || github.repository == 'libmbd/libmbd' name: All strategy: fail-fast: false matrix: include: - type: ubuntu mpi-nodes: 2 numpy: "1" - type: ubuntu mpi-nodes: 4 mpifh: mpifh numpy: "2" - type: macos mpi-nodes: 2 - type: nvhpc nvhpc-version: "26.3" - type: conda python-version: =3.13 - type: conda python-version: =3.13 mpi: openmpi mpi-nodes: 8 elsi: elsi - type: conda python-version: =3.13 mpi: mpich mpi-nodes: 2 - type: conda python-version: =3.10 cmake-version: =3.22 gfortran-version: =11 mpi: openmpi mpi-nodes: 8 - type: conda python-version: =3.10 cmake-version: =3.22 gfortran-version: =11 mpi: mpich=4 mpi-nodes: 2 elsi: elsi runs-on: ${{ fromJSON('{"ubuntu":"ubuntu-latest","macos":"macos-latest","conda":"ubuntu-latest","nvhpc":"ubuntu-latest"}')[matrix.type] }} env: CONDA_ALWAYS_YES: "true" CONDA_QUIET: "true" steps: - name: Set environment variables run: | case ${{ runner.os }} in Linux) XDG_CACHE_HOME=$HOME/.cache ;; macOS) XDG_CACHE_HOME=$HOME/Library/Caches ;; esac echo YEAR_MONTH=$(date +"%Y-%m") >>$GITHUB_ENV echo XDG_CACHE_HOME="$XDG_CACHE_HOME" >>$GITHUB_ENV if [[ "${{ matrix.mpi-nodes }}" ]]; then echo MPI_NODES=${{ matrix.mpi-nodes }} >>$GITHUB_ENV fi if [[ "${{ matrix.mpi }}" == "openmpi" || "${{ matrix.type }}" == "ubuntu" ]]; then echo MPIEXEC_EXTRA_FLAGS=--oversubscribe >>$GITHUB_ENV fi # On the current GitHub-hosted (Azure) ubuntu runner image, conda # MPICH (built on UCX) intermittently aborts at MPI_Init trying to # open the Azure MANA (mana_0) RDMA/verbs device, and conda OpenMPI's # vader BTL hits restrictive-ptrace CMA errors and then SIGSEGVs in # heavy collectives. Every CI run is single-node, so pin both stacks # to intra-node transports (shared memory + self) so they never touch # the network device. Ignored by legs whose MPI does not use them. echo UCX_TLS=sm,self >>$GITHUB_ENV echo UCX_NET_DEVICES=lo >>$GITHUB_ENV echo OMPI_MCA_btl_vader_single_copy_mechanism=none >>$GITHUB_ENV echo VIRTUAL_ENV=$HOME/env >>$GITHUB_ENV echo CONDA_PKGS_DIRS="$XDG_CACHE_HOME/conda/pkgs" >>$GITHUB_ENV echo $HOME/env/bin >>$GITHUB_PATH - uses: actions/checkout@v6 with: fetch-depth: 0 - uses: actions/cache@v5 with: path: | ${{ env.XDG_CACHE_HOME }}/conda/pkgs ${{ env.XDG_CACHE_HOME }}/pip key: ${{ matrix.type }}-${{ matrix.python-version }}-${{ matrix.cmake-version }}-${{ matrix.gfortran-version }}-${{ matrix.mpi }}-${{ matrix.mpifh }}-${{ matrix.numpy }}-${{ env.YEAR_MONTH }}-${{ hashFiles('pyproject.toml') }} - name: Install libMBD dependencies if: matrix.type == 'ubuntu' run: sudo apt-get install -yq --no-install-suggests --no-install-recommends gfortran libblas-dev liblapack-dev mpi-default-dev mpi-default-bin libscalapack-mpi-dev - name: Install libMBD dependencies if: matrix.type == 'macos' run: | brew install open-mpi scalapack # open-mpi's mpi.mod must be read by the same major gfortran it was built with; # brew open-mpi depends on the current `gcc` formula, so the highest-numbered # gfortran-* in brew's bindir is the one we want. # Use `brew --prefix` so this works on both Intel (/usr/local) and Apple Silicon (/opt/homebrew). HOMEBREW_PREFIX=$(brew --prefix) GFORTRAN=$(ls "$HOMEBREW_PREFIX/bin/gfortran-"[0-9]* 2>/dev/null | sort -V | tail -1) if [[ -z "$GFORTRAN" ]]; then echo "::error::No versioned gfortran found in $HOMEBREW_PREFIX/bin" >&2 exit 1 fi echo "MACOS_GFORTRAN=$GFORTRAN" >>$GITHUB_ENV - name: Free disk space if: matrix.type == 'nvhpc' run: | # The NVIDIA HPC SDK is ~13 GB installed plus several GB of packages; # reclaim space from preinstalled toolchains we don't use so the # runner's root disk doesn't fill up. sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc \ /usr/local/.ghcup /opt/hostedtoolcache/CodeQL df -h / - name: Cache NVIDIA HPC SDK packages if: matrix.type == 'nvhpc' uses: actions/cache@v5 with: path: ~/nvhpc-debs key: nvhpc-debs-${{ matrix.nvhpc-version }} - name: Install NVIDIA HPC SDK if: matrix.type == 'nvhpc' run: | sudo apt-get install -yq --no-install-suggests --no-install-recommends libblas-dev liblapack-dev curl -fsSL https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK \ | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg echo 'deb [signed-by=/usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' \ | sudo tee /etc/apt/sources.list.d/nvhpc.list sudo apt-get update -yq # Restore previously downloaded packages so a warm cache skips the multi-GB download. if ls ~/nvhpc-debs/*.deb >/dev/null 2>&1; then sudo cp ~/nvhpc-debs/*.deb /var/cache/apt/archives/ fi pkg="nvhpc-$(echo '${{ matrix.nvhpc-version }}' | tr '.' '-')" sudo apt-get install -yq --no-install-suggests --no-install-recommends "$pkg" # Stash the downloaded .deb files in a user-owned dir for actions/cache to persist. mkdir -p ~/nvhpc-debs sudo cp /var/cache/apt/archives/*.deb ~/nvhpc-debs/ 2>/dev/null || true sudo chown -R "$(id -u):$(id -g)" ~/nvhpc-debs # Drop the apt archive copy now that the packages are stashed for caching. sudo apt-get clean nvroot=$(ls -d /opt/nvidia/hpc_sdk/Linux_x86_64/*/compilers | sort -V | tail -1) echo "$nvroot/bin" >>$GITHUB_PATH echo "LD_LIBRARY_PATH=$nvroot/lib:$LD_LIBRARY_PATH" >>$GITHUB_ENV - name: Create Conda environment if: matrix.type == 'conda' # openblas 0.3.34 SIGSEGVs in the LAPACK complex Hermitian eigensolver # (ZHEEV, reached via ScaLAPACK PZHEEV) on the periodic MBD path, but # only on some runner CPUs -- OpenBLAS dispatches CPU-specific kernels # at runtime. Confirmed empirically: 0.3.33 passes, 0.3.34 crashes, # nothing else in the env changed, and excluding it makes the legs # green again. No matching upstream report yet; drop the exclusion once # a fixed release lands. run: conda create -p ${{ env.VIRTUAL_ENV }} -c conda-forge python${{ matrix.python-version }} pip cmake${{ matrix.cmake-version }} gfortran_linux-64${{ matrix.gfortran-version }} 'openblas!=0.3.34' ${{ matrix.mpi }} scalapack elsi numpy scipy mpi4py - name: Create Python virtual environment if: matrix.type != 'conda' run: | python3 -m venv ${{ env.VIRTUAL_ENV }} ${{ env.VIRTUAL_ENV }}/bin/pip install -U pip - name: Install coverage Python package # The [toml] extra pulls in tomli so coverage can read its config from # pyproject.toml on the Python 3.10 legs (stdlib tomllib is 3.11+). run: pip install -U 'coverage[toml]' - name: Pin numpy major version # pyMBD supports both numpy 1.x and 2.x; pre-install the requested major # so the subsequent pyMBD install keeps it (the dependency only sets a # lower bound). Without a pin pip would always resolve the latest (2.x). # `matrix.numpy` is null (falsy) on legs that don't set it, so the # truthiness check skips them; only the ubuntu venv legs opt in. if: matrix.numpy && matrix.type != 'conda' run: pip install "numpy==${{ matrix.numpy }}.*" - name: Report environment run: | type python type pip python --version cmake --version pip --version git describe --tags --dirty=.dirty - name: Set CMAKE_ARGS run: | CMAKE_ARGS=() if [[ "${{ matrix.type }}" == "nvhpc" ]]; then # nvfortran has no gcov-style coverage flags; build without coverage. # Target a portable x86-64 baseline -- GitHub-hosted runners use a # heterogeneous CPU fleet, and nvfortran's default host-detected # target can emit instructions some runners don't actually execute, # producing SIGILL at runtime in math-heavy paths. FFLAGS=('-tp' 'px') CMAKE_ARGS+=('-DCMAKE_Fortran_COMPILER=nvfortran') else FFLAGS=('-fprofile-arcs' '-ftest-coverage') fi if [[ "${{ matrix.mpi-nodes }}" ]]; then CMAKE_ARGS+=('-DENABLE_SCALAPACK_MPI=ON') fi if [[ "${{ matrix.mpifh }}" == "mpifh" ]]; then CMAKE_ARGS+=('-DENABLE_MPIFH=ON') fi if [[ "${{ matrix.elsi }}" == "elsi" ]]; then CMAKE_ARGS+=('-DENABLE_ELSI=ON') fi if [[ "${{ matrix.type }}" == "macos" && -n "$MACOS_GFORTRAN" ]]; then CMAKE_ARGS+=("-DCMAKE_Fortran_COMPILER=$MACOS_GFORTRAN") fi if [[ "${{ matrix.type }}" == "ubuntu" ]]; then CMAKE_ARGS+=('-DCMAKE_IGNORE_PATH="/usr/lib/cmake/scalapack-2.1.0.openmpi;/lib/cmake/scalapack-2.1.0.openmpi"') fi echo CMAKE_ARGS=${CMAKE_ARGS[@]} echo CMAKE_ARGS=${CMAKE_ARGS[@]} >>$GITHUB_ENV echo FFLAGS=${FFLAGS[@]} echo FFLAGS=${FFLAGS[@]} >>$GITHUB_ENV # Codecov flag for this leg's Fortran coverage. Each preprocessor # configuration (serial/MPI/MPIFH/ELSI) compiles the *.F90 sources to a # different line table, so it must be its own flag -- otherwise Codecov # reconciles conflicting line tables for one file and under-counts it. # Flags are combined (union) for the overall number. COV_FLAG=fortran [[ -n "${{ matrix.mpi-nodes }}" ]] && COV_FLAG=${COV_FLAG}_mpi [[ "${{ matrix.mpifh }}" == "mpifh" ]] && COV_FLAG=${COV_FLAG}_mpifh [[ "${{ matrix.elsi }}" == "elsi" ]] && COV_FLAG=${COV_FLAG}_elsi echo COV_FLAG=$COV_FLAG echo COV_FLAG=$COV_FLAG >>$GITHUB_ENV - name: Run Cmake run: | [[ "${{ matrix.type }}" != "conda" ]] || { source $CONDA/etc/profile.d/conda.sh && conda activate $HOME/env && export CMAKE_ARGS="$CONDA_BACKUP_CMAKE_ARGS"; } make run_cmake - name: Build libMBD run: make build_libmbd -o run_cmake - name: Install libMBD run: make install_libmbd -o build_libmbd - name: Build & install pyMBD run: | [[ "${{ matrix.type }}" != "conda" ]] || { source $CONDA/etc/profile.d/conda.sh && conda activate $HOME/env; } make install -o install_libmbd - run: pip list - name: Test libMBD run: make test_libmbd - name: Test pyMBD run: | make test -o test_libmbd RUN_CMD="coverage run -m" | tee output ! grep failed output >/dev/null - name: Generate coverage reports if: matrix.type != 'nvhpc' run: | [[ "${{ matrix.type }}" != "conda" ]] || { source $CONDA/etc/profile.d/conda.sh && conda activate $HOME/env; } # Python: turn the recorded coverage data into XML for upload. coverage combine 2>/dev/null || true coverage xml -o coverage.xml # Fortran: generate .gcov ourselves (Codecov's own gcov mis-parses the # preprocessed *.F90 -- see devtools/gen-fortran-coverage.sh). On macOS # the build uses a versioned gfortran, so pass the matching gcov. if [[ "${{ matrix.type }}" == "macos" && -n "$MACOS_GFORTRAN" ]]; then export GCOV=$(printf '%s' "$MACOS_GFORTRAN" | sed -E 's#gfortran(-[0-9]+)?$#gcov\1#') fi ./devtools/gen-fortran-coverage.sh coverage-fortran - name: Upload Python coverage to Codecov uses: codecov/codecov-action@v6 if: matrix.type != 'nvhpc' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage.xml flags: python disable_search: true # We hand Codecov ready-made reports; never let it run gcov itself. plugins: noop # strategy.job-index keeps the name unique and non-empty (several # legs don't set matrix.python-version). name: python-${{ matrix.type }}-${{ strategy.job-index }} - name: Upload Fortran coverage to Codecov uses: codecov/codecov-action@v6 if: matrix.type != 'nvhpc' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) with: token: ${{ secrets.CODECOV_TOKEN }} directory: coverage-fortran flags: ${{ env.COV_FLAG }} plugins: noop name: ${{ env.COV_FLAG }}-${{ matrix.type }}-${{ strategy.job-index }} intel: if: github.event_name != 'schedule' || github.repository == 'libmbd/libmbd' name: Intel (${{ matrix.toolchain }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: # intel -> ifx + icx (LLVM-based), intel-classic -> ifort (last release) toolchain: [intel, intel-classic] env: VIRTUAL_ENV: ${{ github.workspace }}/env steps: - uses: actions/checkout@v6 with: fetch-depth: 0 - name: Set up Intel Fortran/C compiler id: setup-fortran uses: fortran-lang/setup-fortran@v1 with: compiler: ${{ matrix.toolchain }} - name: Install Intel MKL run: | sudo apt-get update sudo apt-get install -yq --no-install-suggests --no-install-recommends intel-oneapi-mkl-devel - name: Set up oneAPI environment run: | # setup-fortran already sourced setvars.sh (SETVARS_COMPLETED=1), so a # plain re-source returns exit 3; --force re-runs it and also picks up # the MKL component installed above. source /opt/intel/oneapi/setvars.sh --force test -n "${MKLROOT:-}" || { echo "::error::MKLROOT unset after sourcing setvars.sh"; exit 1; } for v in MKLROOT LD_LIBRARY_PATH LIBRARY_PATH CPATH CMAKE_PREFIX_PATH PKG_CONFIG_PATH NLSPATH; do echo "$v=${!v}" >>"$GITHUB_ENV" done - name: Create Python virtual environment run: | python3 -m venv "$VIRTUAL_ENV" "$VIRTUAL_ENV/bin/pip" install -U pip echo "$VIRTUAL_ENV/bin" >>"$GITHUB_PATH" - name: Set CMAKE_ARGS run: | FC="${{ steps.setup-fortran.outputs.fc }}" CC="${{ steps.setup-fortran.outputs.cc }}" echo "CMAKE_ARGS=-DCMAKE_Fortran_COMPILER=$FC -DCMAKE_C_COMPILER=${CC:-gcc} -DBLA_VENDOR=Intel10_64lp_seq" >>"$GITHUB_ENV" - name: Report environment run: | "${{ steps.setup-fortran.outputs.fc }}" --version cmake --version echo "MKLROOT=$MKLROOT" git describe --tags --dirty=.dirty - name: Build libMBD run: make build_libmbd - name: Install libMBD run: make install_libmbd -o build_libmbd - name: Build & install pyMBD run: make install -o install_libmbd - run: pip list - name: Test libMBD run: make test_libmbd - name: Test pyMBD run: | make test -o test_libmbd | tee output ! grep failed output >/dev/null pr-gate: # Single stable check that branch protection can require on pull requests. # It collapses the whole test matrix and both Intel legs into one job name, # so the required-status-checks list never has to track individual matrix # legs (which churn as the matrix changes). Only runs on pull_request # events -- it exists purely to gate merges. `always()` makes it run even # when a dependency fails so it can report that failure. if: always() && github.event_name == 'pull_request' name: PR gate needs: [all, intel] runs-on: ubuntu-latest steps: - name: Fail if any test job did not succeed if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') run: | echo "One or more test jobs failed, were cancelled, or were skipped." exit 1