Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for self-installed MKL from intel oneAPI #99

Merged
merged 4 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ library.

### MKL PARDISO

By default Julia, will automatically install a suitable MKL for your platform.
By default Julia, will automatically install a suitable MKL for your platform by loading `MKL_jll.jl`.
Note that if you use a mac you will need to pin `MKL_jll` to version 2023.

If you rather use a self installed MKL follow these instructions:
If you instead use a self installed MKL, follow these instructions:

* Set the `MKLROOT` environment variable. See the [MKL getting started
manual](https://software.intel.com/en-us/articles/intel-mkl-103-getting-started)
* Set the `MKLROOT` environment variable. See the [MKL set environment variables
manual](https://www.intel.com/content/www/us/en/docs/onemkl/developer-guide-linux/2024-0/scripts-to-set-environment-variables.html)
for a thorough guide how to set this variable correctly, typically done by
executing something like `source /opt/intel/mkl/bin/mklvars.sh intel64` or
executing something like `source /opt/intel/oneapi/setvars.sh intel64` or
running `"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" intel64`
* Run `Pkg.build("Pardiso")`
* Run `Pkg.build("Pardiso", verbose=true)`
* Run `Pardiso.show_build_log()` to see the build log for additional
information.
* Note that the `MKLROOT` environment variable must be set whenever using the library.
* Note that the `MKLROOT` environment variable must be set, and `LD_LIBRARY_PATH` must contain `$MKLROOT/lib`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true? I don't think I have had to explicitly set this before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The advise by intel is to run

source /opt/intel/oneapi/setvars.sh

This sets MKLROOT and adds the lib directory to the LD_LIBRARY_PATH . I accidently run with only MKLROOT set, and libmkl_rt was not found as a consequence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

whenever using the library.

### PARDISO 6.0

Expand Down
4 changes: 2 additions & 2 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ println("\nMKL Pardiso")
println("=============")
function find_mklparadiso()
if haskey(ENV, "MKLROOT")
println("found MKLROOT environment varaible, enabling local MKL")
println("found MKLROOT environment variable, enabling local MKL")
return true
end
println("did not find MKLROOT environment variable, using provided MKL")
println("did not find MKLROOT environment variable, using MKL_jll")
return false
end

Expand Down
18 changes: 15 additions & 3 deletions src/Pardiso.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import MKL_jll
end

mkl_is_available() = LOCAL_MKL_FOUND || MKL_jll.is_available()

if LinearAlgebra.BLAS.vendor() === :mkl && LinearAlgebra.BlasInt == Int64
const MklInt = Int64
const PARDISO_FUNC = :pardiso_64
Expand Down Expand Up @@ -109,17 +111,18 @@
const PARDISO_LOADED = Ref(false)

function __init__()
if MKL_jll.is_available()
libmkl_rt[] = MKL_jll.libmkl_rt_path
elseif LOCAL_MKL_FOUND
if LOCAL_MKL_FOUND
if Sys.iswindows()
libmkl_rt[] = "mkl_rt"
elseif Sys.isapple()
libmkl_rt[] = "@rpath/libmkl_rt.dylib"
else
libmkl_rt[] = "libmkl_rt"
end
elseif MKL_jll.is_available()
libmkl_rt[] = MKL_jll.libmkl_rt_path
end

if !haskey(ENV, "PARDISOLICMESSAGE")
ENV["PARDISOLICMESSAGE"] = 1
end
Expand All @@ -128,6 +131,15 @@
@warn "MKLROOT not set, MKL Pardiso solver will not be functional"
end

if mkl_is_available()
try
libmklpardiso = Libdl.dlopen(libmkl_rt[])
j-fu marked this conversation as resolved.
Show resolved Hide resolved
mklpardiso_f = Libdl.dlsym(libmklpardiso, "pardiso")
catch e
@error("MKL Pardiso did not manage to load, error thrown was: $(sprint(showerror, e))")

Check warning on line 139 in src/Pardiso.jl

View check run for this annotation

Codecov / codecov/patch

src/Pardiso.jl#L139

Added line #L139 was not covered by tests
end
end

# This is apparently needed for MKL to not get stuck on 1 thread when
# libpardiso is loaded in the block below...
if libmkl_rt[] !== ""
Expand Down
2 changes: 1 addition & 1 deletion src/mkl_pardiso.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mutable struct MKLPardisoSolver <: AbstractPardisoSolver
end

function MKLPardisoSolver()
if !MKL_jll.is_available()
if !( LOCAL_MKL_FOUND || MKL_jll.is_available())
j-fu marked this conversation as resolved.
Show resolved Hide resolved
j-fu marked this conversation as resolved.
Show resolved Hide resolved
error("MKL is not available no this platform")
j-fu marked this conversation as resolved.
Show resolved Hide resolved
end
pt = zeros(Int, 64)
Expand Down
6 changes: 4 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
ENV["OMP_NUM_THREADS"] = 2


using Pkg
if Sys.isapple()
Pkg.add(name="MKL_jll"; version = "2023")
end


using Test
using Pardiso
using Random
Expand All @@ -14,7 +16,7 @@ using LinearAlgebra
Random.seed!(1234)

available_solvers = empty([Pardiso.AbstractPardisoSolver])
if Pardiso.MKL_jll.is_available()
if Pardiso.mkl_is_available()
push!(available_solvers, MKLPardisoSolver)
else
@warn "Not testing MKL Pardiso solver"
Expand Down Expand Up @@ -71,7 +73,7 @@ for solver in available_solvers
example_hermitian_psd(solver)
end

if Pardiso.MKL_jll.is_available()
if Pardiso.mkl_is_available()
if Sys.CPU_THREADS >= 4
@testset "procs" begin
ps = MKLPardisoSolver()
Expand Down
Loading