Skip to content

Commit 835f224

Browse files
committed
Fix iparm value for transposed matrix for MKL Pardiso
1 parent e864de3 commit 835f224

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

ext/LinearSolvePardisoExt.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ function LinearSolve.init_cacheval(alg::PardisoJL,
3232
vendor=:MKL
3333
end
3434
end
35-
35+
36+
transposed_iparm = 1
3637
solver = if vendor == :MKL
3738
solver = if Pardiso.mkl_is_available()
3839
solver = Pardiso.MKLPardisoSolver()
3940
nprocs !== nothing && Pardiso.set_nprocs!(solver, nprocs)
41+
transposed_iparm = 2 # see https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2024-0/pardiso-iparm-parameter.html#IPARM37
4042

4143
solver
4244
else
@@ -84,7 +86,7 @@ function LinearSolve.init_cacheval(alg::PardisoJL,
8486
end
8587

8688
# Make sure to say it's transposed because its CSC not CSR
87-
Pardiso.set_iparm!(solver, 12, 1)
89+
Pardiso.set_iparm!(solver, 12, transposed_iparm)
8890

8991
#=
9092
Note: It is recommended to use IPARM(11)=1 (scaling) and IPARM(13)=1 (matchings) for
@@ -107,12 +109,12 @@ function LinearSolve.init_cacheval(alg::PardisoJL,
107109
# applies these exact factors L and U for the next steps in a
108110
# preconditioned Krylov-Subspace iteration. If the iteration does not
109111
# converge, the solver will automatically switch back to the numerical factorization.
110-
Pardiso.set_iparm!(solver, 3, round(Int, abs(log10(reltol)), RoundDown) * 10 + 1)
112+
Pardiso.set_iparm!(solver, 4, round(Int, abs(log10(reltol)), RoundDown) * 10 + 1)
111113
end
112114

113115
Pardiso.pardiso(solver,
114-
u,
115-
SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)),
116+
u,
117+
SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)),
116118
b)
117119

118120
return solver
@@ -121,7 +123,6 @@ end
121123
function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::PardisoJL; kwargs...)
122124
@unpack A, b, u = cache
123125
A = convert(AbstractMatrix, A)
124-
125126
if cache.isfresh
126127
Pardiso.set_phase!(cache.cacheval, Pardiso.NUM_FACT)
127128
Pardiso.pardiso(cache.cacheval, A, eltype(A)[])
@@ -130,6 +131,7 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::PardisoJL; kwargs
130131

131132
Pardiso.set_phase!(cache.cacheval, Pardiso.SOLVE_ITERATIVE_REFINE)
132133
Pardiso.pardiso(cache.cacheval, u, A, b)
134+
133135
return SciMLBase.build_linear_solution(alg, cache.u, nothing, cache)
134136
end
135137

test/pardiso/pardiso.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,24 @@ cache_kwargs = (; abstol = 1e-8, reltol = 1e-8, maxiter = 30)
1818

1919
prob2 = LinearProblem(A2, b2)
2020

21-
algs=[]
22-
# if Pardiso.mkl_is_available()
23-
# algs=vcat(algs,[PardisoJL(), MKLPardisoFactorize(), MKLPardisoIterate()])
24-
# end
21+
algs=[PardisoJL()]
22+
23+
if Pardiso.mkl_is_available()
24+
algs=vcat(algs,[MKLPardisoFactorize(), MKLPardisoIterate()])
25+
end
2526

2627
if Pardiso.panua_is_available()
27-
algs=vcat(algs,[PardisoJL(), PanuaPardisoFactorize(), PanuaPardisoIterate()])
28+
algs=vcat(algs,[PanuaPardisoFactorize(), PanuaPardisoIterate()])
2829
end
29-
@info algs
30+
31+
3032
for alg in algs
3133
u = solve(prob1, alg; cache_kwargs...).u
3234
@test A1 * u b1
3335

3436
u = solve(prob2, alg; cache_kwargs...).u
35-
# @test eltype(u) <: Complex
36-
# @test A2 * u ≈ b2
37+
@test eltype(u) <: Complex
38+
@test A2 * u b2
3739
end
3840

3941
Random.seed!(10)

0 commit comments

Comments
 (0)