mesh-sieve 4.0.2

Modular, high-performance Rust library for mesh and data management, designed for scientific computing and PDE codes.
Documentation
name: Rust

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

env:
  CARGO_TERM_COLOR: always

jobs:
  cuda-production:
    # Repository-managed runners must provide a supported NVIDIA GPU, driver,
    # and NVRTC. Dynamic skips are promoted to failures by the environment flag.
    strategy:
      fail-fast: false
      matrix:
        architecture: [cuda-sm80, cuda-sm90]
    runs-on: [self-hosted, linux, x64, "${{ matrix.architecture }}"]
    env:
      MESH_SIEVE_RUN_CUDA_TESTS: "1"
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Record CUDA runtime
        run: nvidia-smi
      - name: Compile every CUDA feature combination
        run: |
          cargo check --all-targets --features cuda
          cargo check --all-targets --features cuda-cublas
          cargo check --all-targets --features cuda-cusparse
          cargo check --all-targets --features cuda-cusolver
          cargo check --all-targets --features cuda-nccl
      - name: Execute required CUDA differential tests
        run: cargo test --features cuda,cuda-cusparse --test cuda_fvm --test cuda_strict_mode

  build:
    runs-on: ubuntu-latest
    
    strategy:
      fail-fast: false
      max-parallel: 2
      matrix:
        # Keep the main CI matrix small and fast. MPI-specific runs are moved
        # to the dedicated `mpi-tests` job below to avoid expensive/fragile
        # matrix entries that can cause cancellations.
        features:
          - ""
          - "rayon"

    steps:
    - uses: actions/checkout@v4
    - name: Cache cargo
      uses: actions/cache@v4
      with:
        path: |

          ~/.cargo/registry
          ~/.cargo/git
          target
          ~/.cargo/bin
        key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
        restore-keys: |

          ${{ runner.os }}-cargo-
    
  # MPI is not installed in the standard build matrix. MPI tests run in
  # the separate `mpi-tests` job which installs MPI only when needed.
        
    - name: Setup Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        override: true
        
    - name: Build library
      run: cargo build --lib --verbose --features "${{ matrix.features }}"
      
    - name: Build examples
      run: cargo build --examples --verbose --features "${{ matrix.features }}"
      
    - name: Run library tests
      run: cargo test --lib --verbose --features "${{ matrix.features }}"
      
    - name: Run example tests (non-MPI)
      run: |

        # Run non-MPI examples
        cargo run --features "${{ matrix.features }}" --example partition || true

        # Run example tests if they exist
        cargo test --examples --verbose --features "${{ matrix.features }}" || true

    # Note: MPI-specific examples are executed in the separate `mpi-tests` job
    # below which installs MPI and runs a curated, smaller set to avoid timeouts.

  docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
      - name: Build docs
        run: cargo doc --no-deps

  check-invariants:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
      - name: Build with invariant checks
        run: cargo build --release --verbose --features "check-invariants"
      - name: Run tests with invariant checks
        run: cargo test --release --verbose --features "check-invariants"

  test-release-strict:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Build (release + strict invariants)
        run: cargo build --workspace --release --features strict-invariants
      - name: Test (release + strict invariants)
        run: cargo test --workspace --release --features strict-invariants

  # Separate job for benchmarks and integration tests
  benchmarks:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Install MPI
      run: |

        sudo apt-get update
        sudo apt-get install -y mpich libmpich-dev
        
    - name: Setup Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        override: true
        
    - name: Build benchmarks
      run: cargo build --benches --verbose --features "mpi-support,rayon"
      
    - name: Run integration tests
      run: cargo test --tests --verbose --features "mpi-support,rayon"

  mpi-tests:
    runs-on: ubuntu-latest
    needs: build
    timeout-minutes: 45
    strategy:
      fail-fast: false
      matrix:
        features:
          - "mpi-support"
          - "rayon,mpi-support"

    steps:
    - uses: actions/checkout@v4

    - name: Cache cargo
      uses: actions/cache@v4
      with:
        path: |

          ~/.cargo/registry
          ~/.cargo/git
          target
          ~/.cargo/bin
        key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
        restore-keys: |

          ${{ runner.os }}-cargo-

    - name: Install MPI
      run: |

        sudo apt-get update
        sudo apt-get install -y mpich libmpich-dev
        mpirun --version

    - name: Setup Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        override: true

    - name: Install cargo-mpirun
      run: |

        # Install the cargo subcommand to run MPI examples via `cargo mpirun`
        if [ -x "$HOME/.cargo/bin/cargo-mpirun" ]; then
          echo "cargo-mpirun already installed at $HOME/.cargo/bin/cargo-mpirun"
          $HOME/.cargo/bin/cargo-mpirun --version || true
        else
          cargo install --locked cargo-mpirun
        fi

    - name: Build library (MPI)
      run: cargo build --lib --verbose --features "${{ matrix.features }}"

    - name: Run selected MPI examples
      run: |

        echo "Running MPI examples with features: ${{ matrix.features }}"
        # Keep MPI runs small and deterministic (2 ranks where possible).
        cargo mpirun -n 2 --features "${{ matrix.features }}" --example mpi_complete
        cargo mpirun -n 2 --features "${{ matrix.features }}" --example mpi_complete_stack || true
        cargo mpirun -n 2 --features "${{ matrix.features }}" --example mesh_distribute_two_ranks || true
        echo "MPI examples finished for features: ${{ matrix.features }}"