1- Base. @kwdef struct PardisoJL <: SciMLLinearSolveAlgorithm
2- nprocs:: Union{Int, Nothing} = nothing
3- solver_type:: Union{Int, Pardiso.Solver, Nothing} = nothing
4- matrix_type:: Union{Int, Pardiso.MatrixType, Nothing} = nothing
5- iparm:: Union{Vector{Tuple{Int,Int}}, Nothing} = nothing
6- dparm:: Union{Vector{Tuple{Int,Int}}, Nothing} = nothing
1+ module LinearSolvePardiso
2+
3+ using Pardiso, LinearSolve, SciMLBase
4+
5+ Base. @kwdef struct PardisoJL <: SciMLBase.SciMLLinearSolveAlgorithm
6+ nprocs:: Union{Int,Nothing} = nothing
7+ solver_type:: Union{Int,Pardiso.Solver,Nothing} = nothing
8+ matrix_type:: Union{Int,Pardiso.MatrixType,Nothing} = nothing
9+ iparm:: Union{Vector{Tuple{Int,Int}},Nothing} = nothing
10+ dparm:: Union{Vector{Tuple{Int,Int}},Nothing} = nothing
711end
812
9- MKLPardisoFactorize (;kwargs... ) = PardisoJL (;solver_type = 0 , kwargs... )
10- MKLPardisoIterate (;kwargs... ) = PardisoJL (;solver_type = 1 , kwargs... )
11- needs_concrete_A (alg:: PardisoJL ) = true
13+ MKLPardisoFactorize (; kwargs... ) = PardisoJL (; solver_type = 0 , kwargs... )
14+ MKLPardisoIterate (; kwargs... ) = PardisoJL (; solver_type = 1 , kwargs... )
15+ LinearSolve . needs_concrete_A (alg:: PardisoJL ) = true
1216
1317# TODO schur complement functionality
1418
15- function init_cacheval (alg:: PardisoJL , A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose)
19+ function LinearSolve . init_cacheval (alg:: PardisoJL , A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose)
1620 @unpack nprocs, solver_type, matrix_type, iparm, dparm = alg
17- A = convert (AbstractMatrix,A)
21+ A = convert (AbstractMatrix, A)
1822
1923 solver =
20- if Pardiso. PARDISO_LOADED[]
21- solver = Pardiso. PardisoSolver ()
22- solver_type != = nothing && Pardiso. set_solver! (solver, solver_type)
24+ if Pardiso. PARDISO_LOADED[]
25+ solver = Pardiso. PardisoSolver ()
26+ solver_type != = nothing && Pardiso. set_solver! (solver, solver_type)
2327
24- solver
25- else
26- solver = Pardiso. MKLPardisoSolver ()
27- nprocs != = nothing && Pardiso. set_nprocs! (solver, nprocs)
28+ solver
29+ else
30+ solver = Pardiso. MKLPardisoSolver ()
31+ nprocs != = nothing && Pardiso. set_nprocs! (solver, nprocs)
2832
29- solver
30- end
33+ solver
34+ end
3135
3236 Pardiso. pardisoinit (solver) # default initialization
3337
@@ -58,7 +62,7 @@ function init_cacheval(alg::PardisoJL, A, b, u, Pl, Pr, maxiters, abstol, reltol
5862 end
5963
6064 # Make sure to say it's transposed because its CSC not CSR
61- Pardiso. set_iparm! (solver,12 , 1 )
65+ Pardiso. set_iparm! (solver, 12 , 1 )
6266
6367 #=
6468 Note: It is recommended to use IPARM(11)=1 (scaling) and IPARM(13)=1 (matchings) for
@@ -71,8 +75,8 @@ function init_cacheval(alg::PardisoJL, A, b, u, Pl, Pr, maxiters, abstol, reltol
7175 be changed to Pardiso.ANALYSIS_NUM_FACT in the solver loop otherwise instabilities
7276 occur in the example https://github.com/SciML/OrdinaryDiffEq.jl/issues/1569
7377 =#
74- Pardiso. set_iparm! (solver,11 , 0 )
75- Pardiso. set_iparm! (solver,13 , 0 )
78+ Pardiso. set_iparm! (solver, 11 , 0 )
79+ Pardiso. set_iparm! (solver, 13 , 0 )
7680
7781 Pardiso. set_phase! (solver, Pardiso. ANALYSIS)
7882
@@ -81,17 +85,17 @@ function init_cacheval(alg::PardisoJL, A, b, u, Pl, Pr, maxiters, abstol, reltol
8185 # applies these exact factors L and U for the next steps in a
8286 # preconditioned Krylov-Subspace iteration. If the iteration does not
8387 # converge, the solver will automatically switch back to the numerical factorization.
84- Pardiso. set_iparm! (solver,3 , round (Int,abs (log10 (reltol)),RoundDown) * 10 + 1 )
88+ Pardiso. set_iparm! (solver, 3 , round (Int, abs (log10 (reltol)), RoundDown) * 10 + 1 )
8589 end
8690
8791 Pardiso. pardiso (solver, u, A, b)
8892
8993 return solver
9094end
9195
92- function SciMLBase. solve (cache:: LinearCache , alg:: PardisoJL ; kwargs... )
96+ function SciMLBase. solve (cache:: LinearSolve. LinearCache , alg:: PardisoJL ; kwargs... )
9397 @unpack A, b, u = cache
94- A = convert (AbstractMatrix,A)
98+ A = convert (AbstractMatrix, A)
9599
96100 if cache. isfresh
97101 Pardiso. set_phase! (cache. cacheval, Pardiso. NUM_FACT)
@@ -100,10 +104,12 @@ function SciMLBase.solve(cache::LinearCache, alg::PardisoJL; kwargs...)
100104
101105 Pardiso. set_phase! (cache. cacheval, Pardiso. SOLVE_ITERATIVE_REFINE)
102106 Pardiso. pardiso (cache. cacheval, u, A, b)
103- return SciMLBase. build_linear_solution (alg,cache. u,nothing ,cache)
107+ return SciMLBase. build_linear_solution (alg, cache. u, nothing , cache)
104108end
105109
106110# Add finalizer to release memory
107111# Pardiso.set_phase!(cache.cacheval, Pardiso.RELEASE_ALL)
108112
109113export PardisoJL, MKLPardisoFactorize, MKLPardisoIterate
114+
115+ end
0 commit comments