Skip to content

Conversation

@briochemc
Copy link
Contributor

Attempt at fixing #110.

Note I don't really understand the internals, just trying this out and hopefully the CI tests will let us know if that was not worth it.

Attempt at fixing JuliaSparse#110.

Note I don't really understand the internals, just trying this out and hopefully the CI tests will let us know if that was not worth it.
@codecov
Copy link

codecov bot commented Oct 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 45.61%. Comparing base (650f566) to head (57c618f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #121      +/-   ##
==========================================
- Coverage   45.74%   45.61%   -0.14%     
==========================================
  Files           4        4              
  Lines         470      467       -3     
==========================================
- Hits          215      213       -2     
+ Misses        255      254       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@briochemc
Copy link
Contributor Author

Not sure this was very useful, but at least it's not using the deprecated BLAS.vendor().

How would I go about adding tests with using MKL? Seeing @del2341 tried to override these already without success, would it even work here? Has MKLInt == Int64 ever been tested here in the first place?

@KristofferC
Copy link
Member

Can this choice really be made at compile time now? Since with LBT you change things dynamically, there might need to be a switch at runtime to choose which ccall to make?

@briochemc
Copy link
Contributor Author

FWIW I tried enforcing MklInt=Int64 but then I get a segfault, even for small size M. I'd love to help but I'm out of my depth here: I don't even understand how to use LBT.

@briochemc
Copy link
Contributor Author

@KristofferC could you clarify how to make this switch at runtime? I'm really just looking for a MWE that uses Pardiso.jl with MklInt = Int64.

@KristofferC
Copy link
Member

I mean, when we want to do a pardiso call we have to check with LBT if we are using 64 or 32 bit MKL and decide what to do at that point.

@briochemc
Copy link
Contributor Author

You mean the const MklInt needs to be replaced by a function that can be called at runtime? Something like below?

isMkl() = if VERSION  v"1.7.0-beta2"
    config = BLAS.get_config().loaded_libs
    occursin("mkl_rt", config[1].libname)
else
    BLAS.vendor() === :mkl
end
isMkl64() = isMkl() && LinearAlgebra.BlasInt == Int64
MklInt() = isMkl64() ? Int64 : Int32
pardisoFunc() = isMkl64() ? :pardiso_64 : :pardiso

Again this is not my expertise so I may be misunderstanding what you mean.

@KristofferC
Copy link
Member

Yes, but all the ccalls need to be split up into two, for example:

ccall((:pardisoinit, libmkl_rt[]), Cvoid,
(Ptr{Int}, Ptr{MklInt}, Ptr{MklInt}),
ps.pt, Ref(MklInt(ps.mtype)), ps.iparm)

need to be something like:

if MKLInt == Int32
 ccall((:pardisoinit, libmkl_rt[]), Cvoid, 
       (Ptr{Int}, Ptr{Int32}, Ptr{Int32}), 
       ps.pt, Ref(Int32(ps.mtype)), ps.iparm) 
else
 ccall((:pardisoinit, libmkl_rt[]), Cvoid, 
       (Ptr{Int}, Ptr{Int64}, Ptr{Int64}), 
       ps.pt, Ref(Int64(ps.mtype)), ps.iparm) 

etc.

@KristofferC
Copy link
Member

But we are not going through LBT here though so we need to be consistent with the MKL that is loaded...

@KristofferC
Copy link
Member

After thinking about it more, I think what of what I have said here is more or less nonsense. Updating the check to use Base.USE_BLAS64 which is the same as https://github.com/JuliaLinearAlgebra/MKL.jl/blob/6c67f83736b198c2e927491d011c7b69bb04f194/src/MKL.jl#L47 does should be enough.

@briochemc
Copy link
Contributor Author

Once again I'm sure things are flying over my head, but I tried removing the check entirely and enforcing MklInt = Int64 and this resulted in a segfault (so the same as what @del2341 was saying in #110). So even if the check for setting MklInt was changed, more needs to be done, right?

@KristofferC
Copy link
Member

Do you have Julia code for what fails?

We should look at what the actual ccall becomes and figure out what is wrong with it.

@briochemc
Copy link
Contributor Author

Yes but I'll need a little time to cook a MWE, but essentially I commented out the checks here so my own dev'ed Pardiso.jl contains just

const MklInt = Int64
const PARDISO_FUNC = :pardiso_64

Then I loaded these packages (I used the LinearSolve.jl interface)

using MKL
using LinearAlgebra
import Pardiso
using LinearSolve

And finally I created a simple matrix A and vector b and did

prob = init(LinearProblem(A, b), MKLPardisoIterate())
sol = solve!(prob).u

@briochemc
Copy link
Contributor Author

briochemc commented Oct 19, 2025

I made a branch of Pardiso.jl that forces MklInt64 there, and a little project that adds that branch and MKL.jl there. When running the simple example in the ReadMe, which is just:

using Pkg
Pkg.activate(".")
Pkg.instantiate()

using MKL
using LinearAlgebra
using SparseArrays
# Load my branch of Pardiso that forces MklInt = Int64
# https://github.com/briochemc/Pardiso.jl/tree/MKL_force_Int64
using Pardiso

ps = MKLPardisoSolver()

A = sparse(rand(10, 10))
B = rand(10, 2)
X = zeros(10, 2)
solve!(ps, X, A, B)

I checked that it uses

MKLParido64"LinearAlgebra.BlasInt = Int64
Base.USE_BLAS64 = true
Pardiso.MklInt = Int64
Pardiso.PARDISO_FUNC = :pardiso_64

But this segfaults (on my cluster) with:

[2054555] signal 11 (1): Segmentation fault
in expression starting at /home/561/bp3051/Projects/MKLParido64/src/MKLParido64_fail.jl:15
mkl_pds_reorder1_pardiso at /scratch/gh0/bp3051/.julia/artifacts/27edf95310a71d47422663c3aea849f56efb1360/lib/libmkl_core.so (unknown line)
mkl_pds_do_all_pardiso_fc at /scratch/gh0/bp3051/.julia/artifacts/27edf95310a71d47422663c3aea849f56efb1360/lib/libmkl_core.so (unknown line)
mkl_pds_pardiso_c at /scratch/gh0/bp3051/.julia/artifacts/27edf95310a71d47422663c3aea849f56efb1360/lib/libmkl_core.so (unknown line)
mkl_pds_pardiso at /scratch/gh0/bp3051/.julia/artifacts/27edf95310a71d47422663c3aea849f56efb1360/lib/libmkl_core.so (unknown line)
PARDISO_64 at /scratch/gh0/bp3051/.julia/artifacts/27edf95310a71d47422663c3aea849f56efb1360/lib/libmkl_rt.so (unknown line)
ccall_pardiso at /scratch/gh0/bp3051/.julia/packages/Pardiso/q3JXQ/src/mkl_pardiso.jl:66
pardiso at /scratch/gh0/bp3051/.julia/packages/Pardiso/q3JXQ/src/Pardiso.jl:500
solve! at /scratch/gh0/bp3051/.julia/packages/Pardiso/q3JXQ/src/Pardiso.jl:400
solve! at /scratch/gh0/bp3051/.julia/packages/Pardiso/q3JXQ/src/Pardiso.jl:361
unknown function (ip: 0x15153a0cb102)
jl_apply at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
do_call at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:126
eval_value at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:223
eval_stmt_value at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:174 [inlined]
eval_body at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:666
jl_interpret_toplevel_thunk at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:824
jl_toplevel_eval_flex at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/toplevel.c:943
jl_toplevel_eval_flex at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/toplevel.c:886
ijl_toplevel_eval_in at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/toplevel.c:994
eval at ./boot.jl:430 [inlined]
include_string at ./loading.jl:2734
_include at ./loading.jl:2794
include at ./sysimg.jl:38
unknown function (ip: 0x15153a096f12)
jl_apply at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
do_call at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:126
eval_value at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:223
eval_stmt_value at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:174 [inlined]
eval_body at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:666
jl_interpret_toplevel_thunk at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:824
jl_toplevel_eval_flex at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/toplevel.c:943
jl_toplevel_eval_flex at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/toplevel.c:886
ijl_toplevel_eval_in at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/toplevel.c:994
eval at ./boot.jl:430 [inlined]
eval_user_input at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:261
repl_backend_loop at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:368
#start_repl_backend#59 at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:343
start_repl_backend at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:340
#run_repl#76 at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:500
run_repl at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:486
jfptr_run_repl_10226.1 at /home/561/bp3051/.julia/juliaup/julia-1.11.7+0.x64.linux.gnu/share/julia/compiled/v1.11/REPL/u0gqU_XvZAg.so (unknown line)
#1150 at ./client.jl:446
jfptr_YY.1150_14873.1 at /home/561/bp3051/.julia/juliaup/julia-1.11.7+0.x64.linux.gnu/share/julia/compiled/v1.11/REPL/u0gqU_XvZAg.so (unknown line)
jl_apply at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
jl_f__call_latest at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/builtins.c:875
#invokelatest#2 at ./essentials.jl:1055 [inlined]
invokelatest at ./essentials.jl:1052 [inlined]
run_main_repl at ./client.jl:430
repl_main at ./client.jl:567 [inlined]
_start at ./client.jl:541
jfptr__start_73684.1 at /home/561/bp3051/.julia/juliaup/julia-1.11.7+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
jl_apply at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
true_main at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/jlapi.c:900
jl_repl_entrypoint at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/jlapi.c:1059
main at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/cli/loader_exe.c:58
__libc_start_main at /lib64/libc.so.6 (unknown line)
unknown function (ip: 0x4010b8)
Allocations: 7770065 (Pool: 7768135; Big: 1930); GC: 8
Segmentation fault

EDIT: So I'm likely doing something wrong of course but any help to fix this much appreciated, so that I can try with big matrices that actually requires Int64.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants