diff --git a/.github/actions/test-fc/action.yml b/.github/actions/test-fc/action.yml index 6c1a596..dec0116 100644 --- a/.github/actions/test-fc/action.yml +++ b/.github/actions/test-fc/action.yml @@ -65,6 +65,22 @@ runs: } rm hw.exe + - name: Test compile Fortran (pwsh) + working-directory: test + if: ${{ (success() || failure()) && runner.os == 'Windows' }} + shell: pwsh + run: | + ${{ env.FC }} -o hw.exe hw.f90 + $output=$(& ".\hw.exe") + if ($output -match "hello world") { + write-output $output + } else { + write-output "unexpected output: $output" + exit 1 + } + rm hw.exe + + - name: Test compile Fortran (powershell) working-directory: test if: ${{ (success() || failure()) && runner.os == 'Windows' }} diff --git a/.github/actions/test-mkl/action.yml b/.github/actions/test-mkl/action.yml new file mode 100644 index 0000000..6016979 --- /dev/null +++ b/.github/actions/test-mkl/action.yml @@ -0,0 +1,31 @@ +name: Test mkl +description: Test installation of mkl libraries +inputs: + compiler: + description: "Toolchain or compiler to install" + required: true + version: + description: "Version of toolchain or compiler" + required: true + install_mkl: + description: "If MKL should be installed along with the compiler" + required: false + default: "false" +runs: + using: "composite" + steps: + - name: Test compile and link mkl (bash) + working-directory: test + shell: bash + run: | + if [[ "${{ inputs.compiler }}" =~ "intel" ]] && [[ "${{ inputs.install_mkl }}" == "true" ]] && ([[ "${{ inputs.version }}" != "2021.5" ]] && [[ "$runner.os" != "macOS" ]]); then + if [ "$RUNNER_OS" == "macOS" ]; then + export DYLD_LIBRARY_PATH="${{ env.MKLLIB }}:$DYLD_LIBRARY_PATH" + fi + linking="-L${{ env.MKLLIB }} -lmkl_intel_lp64 -lmkl_sequential -lmkl_core" + # hello world with blas call program + ${{ env.FC }} $args $linking -o hw_mkl hw_mkl.f90 + output=$(./hw_mkl '2>&1') + [[ "$output" == *"hello world 9.00000000000000"* ]] && echo "$output" || (echo "Unexpected Fortran program 'hw_mkl' output: $output"; exit 1) + rm hw_mkl + fi \ No newline at end of file diff --git a/.github/compat/long_compat.csv b/.github/compat/long_compat.csv index 9311353..b06299d 100644 --- a/.github/compat/long_compat.csv +++ b/.github/compat/long_compat.csv @@ -1,4 +1,5 @@ runner,compiler,version,support +macos-13,intel-classic,2021.5,✓runner,compiler,version,support macos-11,gcc,10,✓ macos-11,gcc,11,✓ macos-11,gcc,12,✓ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 24d806a..ba9cef6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,9 +3,9 @@ name: Test # Push and pull request run in assert mode. # Schedule and dispatch run in report mode. on: - push: - paths-ignore: - - '**.md' + # push: + # paths-ignore: + # - '**.md' pull_request: branches: - main @@ -71,6 +71,7 @@ jobs: with: compiler: ${{ matrix.toolchain.compiler }} version: ${{ matrix.toolchain.version }} + install_mkl: true - name: Test Fortran compiler if: steps.setup-fortran.outcome == 'success' @@ -79,6 +80,14 @@ jobs: compiler: ${{ matrix.toolchain.compiler }} version: ${{ matrix.toolchain.version }} + - name: Test MKL libraries + if: steps.setup-fortran.outcome == 'success' && runner.os != 'windows' + uses: ./.github/actions/test-mkl + with: + compiler: ${{ matrix.toolchain.compiler }} + version: ${{ matrix.toolchain.version }} + install_mkl: true + - name: Test C compiler continue-on-error: true if: needs.options.outputs.mode == 'report' && steps.setup-fortran.outcome == 'success' diff --git a/README.md b/README.md index afbb2e6..a6973a3 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ jobs: - {compiler: gcc, version: 13} - {compiler: intel, version: '2023.2'} - {compiler: intel-classic, version: '2021.10'} + - {compiler: intel-classic, version: '2021.10', install_mkl: 'true'} - {compiler: nvidia-hpc, version: '23.11'} include: - os: ubuntu-latest @@ -68,6 +69,7 @@ jobs: - *intel-classic* (for `ifort`) - *nvidia-hpc* (for `nvfortran`) - *version*: Version of the compiler toolchain. See [runner compatibility](#runner-compatibility) charts below. +- *install_mkl*: If MKL libraries should be installed alongsider the intel compiler. Defaults to `false`. ## Outputs @@ -112,6 +114,8 @@ Toolchain support varies across GitHub-hosted runner images. **Note:** Intel's `ifx` compiler is not supported on macOS, so the `intel` option redirects to `intel-classic` (`ifort`). +**Note:** MKL libraries can only be installed for the Intel Fortran compiler, and only on linux and MacOS operating systems; with the exception of intel-classic 2021.5, for which no compatible library is available. + ## License Licensed under the Apache License, Version 2.0 (the “License”); diff --git a/action.yml b/action.yml index ab9a212..99bcbaa 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,10 @@ inputs: version: description: "Version of toolchain or compiler" required: false + install_mkl: + description: "If MKL should be installed along with the compiler" + required: false + default: "false" outputs: fc: description: "Path to Fortran compiler" @@ -50,6 +54,7 @@ runs: env: COMPILER: ${{ inputs.compiler }} VERSION: ${{ inputs.version }} + INSTALL_MKL: ${{ inputs.install_mkl }} run: | action_path=$(echo '/${{ github.action_path }}' | sed -e 's/\\/\//g' -e 's/://') source "$action_path/setup-fortran.sh" @@ -64,11 +69,11 @@ runs: ;; intel-classic) version=${VERSION:-2023.2.0} - install_intel $platform true + install_intel $platform true ${{ inputs.install_mkl }} ;; intel) version=${VERSION:-2023.2.0} - install_intel $platform false + install_intel $platform false ${{ inputs.install_mkl }} ;; nvidia-hpc) version=${VERSION:-23.11} @@ -133,6 +138,7 @@ runs: echo fc=$FC>>$GITHUB_OUTPUT echo cc=$CC>>$GITHUB_OUTPUT echo cxx=$CXX>>$GITHUB_OUTPUT + echo MKLLIB=$MKLLIB>>$GITHUB_OUTPUT fi # intel oneapi flag to indicate env has been activated diff --git a/setup-fortran.sh b/setup-fortran.sh index a5b25fc..155e2c9 100755 --- a/setup-fortran.sh +++ b/setup-fortran.sh @@ -178,6 +178,8 @@ LD_LIBRARY_PATH=$LD_LIBRARY_PATH LIBRARY_PATH=$LIBRARY_PATH INFOPATH=$INFOPATH MANPATH=$MANPATH +MKLLIB=$MKLLIB +DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH ONEAPI_ROOT=$ONEAPI_ROOT CLASSPATH=$CLASSPATH CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH @@ -247,6 +249,19 @@ intel_version_map_l() fi } +mkl_version_map_l() +{ + local intel_version=$1 + case $intel_version in + 2021.1 | 2021.1.2) + mkl_version=2021.1.1 + ;; + *) + mkl_version=$intel_version + ;; + esac +} + intel_version_map_m() { local actual_version=$1 @@ -281,6 +296,25 @@ intel_version_map_m() esac } +mkl_version_map_m() +{ + local intel_version=$1 + case $intel_version in + 2021.1.0 | 2021.2.0 | 2021.3.0 | 2021.4.0 | 2022.2.0 | 2022.3.0 | 2022.3.1 | 2023.0.0 ) + mkl_version=2022.2.0 + ;; + 2022.1.0) + mkl_version="" + ;; + 2023.1.0) + mkl_version=2023.1.0 + ;; + *) + mkl_version=2023.2.0 + ;; + esac +} + intel_version_map_w() { local actual_version=$1 @@ -328,7 +362,10 @@ install_intel_apt() { local version=$1 local classic=$2 + local mkl_version=$1 + local install_mkl=$3 intel_version_map_l $version $classic + mkl_version_map_l $version require_fetch local _KEY="GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB" @@ -339,11 +376,16 @@ install_intel_apt() | sudo tee /etc/apt/sources.list.d/oneAPI.list sudo apt-get update - sudo apt-get install \ - intel-oneapi-compiler-{fortran,dpcpp-cpp-and-cpp-classic}-$version intel-oneapi-mkl-$version + if $install_mkl; then + sudo apt-get install \ + intel-oneapi-compiler-{fortran,dpcpp-cpp-and-cpp-classic}-$version \ + intel-oneapi-mkl-$mkl_version + else + sudo apt-get install \ + intel-oneapi-compiler-{fortran,dpcpp-cpp-and-cpp-classic}-$version + fi source /opt/intel/oneapi/setvars.sh - export_intel_vars if $classic; then export FC="ifort" @@ -354,56 +396,52 @@ install_intel_apt() export CC="icx" export CXX="icpx" fi + if $install_mkl; then + export MKLLIB="$ONEAPI_ROOT/mkl/latest/lib/intel64" + fi + export_intel_vars } install_intel_dmg() { local version=$1 + local mkl_version=$1 + local install_mkl=$2 intel_version_map_m $version + mkl_version_map_m $version case $version in 2021.1.0) - MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/17426/m_BaseKit_p_2021.1.0.2427.dmg MACOS_HPCKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/17398/m_HPCKit_p_2021.1.0.2681.dmg ;; 2021.2.0) - MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/17714/m_BaseKit_p_2021.2.0.2855.dmg MACOS_HPCKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/17643/m_HPCKit_p_2021.2.0.2903.dmg ;; 2021.3.0) - MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/17969/m_BaseKit_p_2021.3.0.3043.dmg MACOS_HPCKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/17890/m_HPCKit_p_2021.3.0.3226.dmg ;; 2021.4.0) - MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/18256/m_BaseKit_p_2021.4.0.3384.dmg MACOS_HPCKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/18242/m_HPCKit_p_2021.4.0.3389.dmg ;; 2022.1.0) - MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/18342/m_BaseKit_p_2022.1.0.92.dmg MACOS_HPCKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/18341/m_HPCKit_p_2022.1.0.86.dmg ;; 2022.2.0) - MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/IRC_NAS/18675/m_BaseKit_p_2022.2.0.226_offline.dmg MACOS_HPCKIT_URL=https://registrationcenter-download.intel.com/akdlm/IRC_NAS/18681/m_HPCKit_p_2022.2.0.158_offline.dmg ;; 2022.3.0) - MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/18865/m_BaseKit_p_2022.3.0.8743.dmg MACOS_HPCKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/18866/m_HPCKit_p_2022.3.0.8685.dmg ;; 2022.3.1) - MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/18971/m_BaseKit_p_2022.3.1.17244.dmg MACOS_HPCKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/18977/m_HPCKit_p_2022.3.1.15344.dmg ;; 2023.0.0) - MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/19080/m_BaseKit_p_2023.0.0.25441.dmg MACOS_HPCKIT_URL=https://registrationcenter-download.intel.com/akdlm/irc_nas/19086/m_HPCKit_p_2023.0.0.25440.dmg ;; 2023.1.0) - MACOS_BASEKIT_URL=https:/registrationcenter-download.intel.com/akdlm/IRC_NAS/2516a0a0-de4d-4f3d-9e83-545b32127dbb/m_BaseKit_p_2023.1.0.45568.dmg MACOS_HPCKIT_URL=https:/registrationcenter-download.intel.com/akdlm/IRC_NAS/a99cb1c5-5af6-4824-9811-ae172d24e594/m_HPCKit_p_2023.1.0.44543.dmg ;; 2023.2.0) - MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/IRC_NAS/cd013e6c-49c4-488b-8b86-25df6693a9b7/m_BaseKit_p_2023.2.0.49398.dmg MACOS_HPCKIT_URL=https://registrationcenter-download.intel.com/akdlm/IRC_NAS/edb4dc2f-266f-47f2-8d56-21bc7764e119/m_HPCKit_p_2023.2.0.49443.dmg ;; *) @@ -411,19 +449,46 @@ install_intel_dmg() ;; esac - require_fetch - $fetch $MACOS_BASEKIT_URL > m_BASEKit.dmg - hdiutil attach m_BASEKit.dmg - sudo /Volumes/"$(basename "$MACOS_BASEKIT_URL" .dmg)"/bootstrapper.app/Contents/MacOS/bootstrapper -s \ - --action install \ - --eula=accept \ - --continue-with-optional-error=yes \ - --log-dir=. - hdiutil detach /Volumes/"$(basename "$MACOS_BASEKIT_URL" .dmg)" -quiet - rm m_BASEKit.dmg + case $mkl_version in + 2022.2.0) + MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/IRC_NAS/18675/m_BaseKit_p_2022.2.0.226_offline.dmg + ;; + 2023.1.0) + MACOS_BASEKIT_URL=https:/registrationcenter-download.intel.com/akdlm/IRC_NAS/2516a0a0-de4d-4f3d-9e83-545b32127dbb/m_BaseKit_p_2023.1.0.45568.dmg + ;; + 2023.2.0) + MACOS_BASEKIT_URL=https://registrationcenter-download.intel.com/akdlm/IRC_NAS/cd013e6c-49c4-488b-8b86-25df6693a9b7/m_BaseKit_p_2023.2.0.49398.dmg + ;; + "") + ;; + *) + exit 1 + ;; + esac + + if $install_mkl; then + if [ "$MACOS_BASEKIT_URL" == "" ]; then + echo "ERROR: MACOS_BASEKIT_URL is empty - please check the version mapping for MKL" + echo "SKIPPING MKL installation..." + else + require_fetch + $fetch $MACOS_BASEKIT_URL > m_BASEKit.dmg + ls -lh + hdiutil verify m_BASEKit.dmg + hdiutil attach m_BASEKit.dmg + sudo /Volumes/"$(basename "$MACOS_BASEKIT_URL" .dmg)"/bootstrapper.app/Contents/MacOS/bootstrapper -s \ + --action install \ + --eula=accept \ + --continue-with-optional-error=yes \ + --log-dir=. + hdiutil detach /Volumes/"$(basename "$MACOS_BASEKIT_URL" .dmg)" -quiet + rm m_BASEKit.dmg + fi + fi require_fetch $fetch $MACOS_HPCKIT_URL > m_HPCKit.dmg + hdiutil verify m_HPCKit.dmg hdiutil attach m_HPCKit.dmg sudo /Volumes/"$(basename "$MACOS_HPCKIT_URL" .dmg)"/bootstrapper.app/Contents/MacOS/bootstrapper -s \ --action install \ @@ -434,11 +499,17 @@ install_intel_dmg() rm m_HPCKit.dmg source /opt/intel/oneapi/setvars.sh - export_intel_vars export FC="ifort" export CC="icc" export CXX="icpc" + + if $install_mkl; then + export MKLLIB="$ONEAPI_ROOT/mkl/latest/lib" + export DYLD_LIBRARY_PATH="$MKLLIB":$DYLD_LIBRARY_PATH + fi + + export_intel_vars } install_intel_win() @@ -501,12 +572,13 @@ install_intel() { local platform=$1 local classic=$2 + local install_mkl=$3 case $platform in linux*) - install_intel_apt $version $classic + install_intel_apt $version $classic $install_mkl ;; darwin*) - install_intel_dmg $version + install_intel_dmg $version $install_mkl ;; mingw*) install_intel_win $version $classic diff --git a/test/hw_mkl.f90 b/test/hw_mkl.f90 new file mode 100644 index 0000000..cc7445c --- /dev/null +++ b/test/hw_mkl.f90 @@ -0,0 +1,13 @@ +program hello + implicit none + double precision, dimension(3):: a, b + double precision:: c + double precision:: DDOT + + a = (/ 3.D0, 3.D0, 3.D0 /) + b = (/ 1.D0, 1.D0, 1.D0 /) + + c = DDOT(3, a, 1, b, 1) + + print *, "hello world", c +end program hello \ No newline at end of file