Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active July 11, 2025 21:56
Show Gist options
  • Select an option

  • Save scivision/b22455e3322826a1c385d5d4b1a8d25e to your computer and use it in GitHub Desktop.

Select an option

Save scivision/b22455e3322826a1c385d5d4b1a8d25e to your computer and use it in GitHub Desktop.
Intel oneAPI GitHub Actions (with caching) MKL and MPI (C, C++, Fortran) and CMake

GitHub Actions Intel oneAPI with caching

Using GitHub Actions cache is a little more complicated than not caching, but makes the setup time dramatically shorter.

This example uses MKL and MPI.

To avoid problems with the CI executing the scripts, do one time:

git update-index --chmod=+x .github/workflows/oneapi_cache_exclude_linux.sh .github/workflows/oneapi_setup_apt_repo_linux.sh

Examples

name: oneapi-linux
env:
CTEST_NO_TESTS_ACTION: error
on:
push:
paths:
- "**.c"
- "**.f"
- "**.F"
- "**.f90"
- "**.F90"
- "**.cmake"
- "**/CMakeLists.txt"
- ".github/workflows/oneapi-linux.yml"
- "!scripts/*"
jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
oneapi: [2025.1]
steps:
# must be first as we're using scripts from this repo
- uses: actions/checkout@v4
- name: cache install oneAPI
id: cache-install
uses: actions/cache@v4
with:
path: |
/opt/intel/oneapi
key: oneapi-${{ matrix.oneapi }}-apt
- name: non-cache install oneAPI
if: steps.cache-install.outputs.cache-hit != 'true'
timeout-minutes: 5
run: |
sh -c .github/workflows/oneapi_setup_apt_repo_linux.sh
sudo apt install --no-install-recommends \
intel-oneapi-compiler-fortran-${{ matrix.oneapi }} \
intel-oneapi-compiler-dpcpp-cpp-${{ matrix.oneapi }} \
intel-oneapi-mpi \
intel-oneapi-mpi-devel \
intel-oneapi-mkl-${{ matrix.oneapi }} \
intel-oneapi-mkl-devel-${{ matrix.oneapi }}
- name: Setup Intel oneAPI environment
run: |
source /opt/intel/oneapi/setvars.sh
printenv >> $GITHUB_ENV
- name: CMake Configure
run: cmake -B build
- name: Upload log failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: oneapi-${{ matrix.oneapi }}-${{ runner.os }}-CMakeConfigureLog.yaml
path: build/CMakeFiles/CMakeConfigureLog.yaml
- name: CMake build
run: cmake --build build --parallel
- name: CMake Test
run: ctest --test-dir build -V
- name: exclude unused files from cache
if: steps.cache-install.outputs.cache-hit != 'true'
run: sh -c .github/workflows/oneapi_cache_exclude_linux.sh
#!/bin/bash
# SPDX-FileCopyrightText: 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#shellcheck disable=SC2010
LATEST_VERSION=$(ls -1 /opt/intel/oneapi/compiler/ | grep -v latest | sort | tail -1)
sudo rm -rf /opt/intel/oneapi/compiler/"$LATEST_VERSION"/linux/compiler/lib/ia32_lin
sudo rm -rf /opt/intel/oneapi/compiler/"$LATEST_VERSION"/linux/bin/ia32
sudo rm -rf /opt/intel/oneapi/compiler/"$LATEST_VERSION"/linux/lib/emu
sudo rm -rf /opt/intel/oneapi/compiler/"$LATEST_VERSION"/linux/lib/oclfpga
#!/bin/bash
# This script sets up the Intel oneAPI apt repository on a Linux system.
# https://www.intel.com/content/www/us/en/docs/oneapi/installation-guide-linux/2025-1/base-apt.html#BASE-APT
curl -sS -L https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
| gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/oneAPI.list" -o APT::Get::List-Cleanup="0"
@scivision
Copy link
Author

@mathomp4 this cache approach may be of interest as it makes the oneAPI Install time seconds instead of minutes for each CI run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment