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

Fix Pardiso extension for the case of an AbstractSparseMatrixCSC #550

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions ext/LinearSolvePardisoExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,11 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::PardisoJL; kwargs
if cache.isfresh
phase = alg.cache_analysis ? Pardiso.NUM_FACT : Pardiso.ANALYSIS_NUM_FACT
Pardiso.set_phase!(cache.cacheval, phase)
Pardiso.pardiso(cache.cacheval, A, eltype(A)[])
Pardiso.pardiso(cache.cacheval, SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), eltype(A)[])
cache.isfresh = false
end
Pardiso.set_phase!(cache.cacheval, Pardiso.SOLVE_ITERATIVE_REFINE)
Pardiso.pardiso(cache.cacheval, u, A, b)

Pardiso.pardiso(cache.cacheval, u, SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), b)
return SciMLBase.build_linear_solution(alg, cache.u, nothing, cache)
end

Expand Down
2 changes: 1 addition & 1 deletion src/extension_algs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ All values default to `nothing` and the solver internally determines the values
given the input types, and these keyword arguments are only for overriding the
default handling process. This should not be required by most users.
"""
struct PardisoJL{T1, T2} <: LinearSolve.SciMLLinearSolveAlgorithm
struct PardisoJL{T1, T2} <: AbstractSparseFactorization
nprocs::Union{Int, Nothing}
solver_type::T1
matrix_type::T2
Expand Down
37 changes: 37 additions & 0 deletions test/pardiso/pardiso.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,40 @@ for solver in solvers
@test Pardiso.get_iparm(solver, i) == iparm[i][2]
end
end

@testset "AbstractSparseMatrixCSC" begin
struct MySparseMatrixCSC2{Tv, Ti} <: SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}
csc::SparseMatrixCSC{Tv, Ti}
end

Base.size(m::MySparseMatrixCSC2) = size(m.csc)
SparseArrays.getcolptr(m::MySparseMatrixCSC2) = SparseArrays.getcolptr(m.csc)
SparseArrays.rowvals(m::MySparseMatrixCSC2) = SparseArrays.rowvals(m.csc)
SparseArrays.nonzeros(m::MySparseMatrixCSC2) = SparseArrays.nonzeros(m.csc)

for alg in algs
N = 100
u0 = ones(N)
A0 = spdiagm(1 => -ones(N - 1), 0 => fill(10.0, N), -1 => -ones(N - 1))
b0 = A0 * u0
B0 = MySparseMatrixCSC2(A0)
A1 = spdiagm(1 => -ones(N - 1), 0 => fill(100.0, N), -1 => -ones(N - 1))
b1=A1*u0
B1= MySparseMatrixCSC2(A1)


pr = LinearProblem(B0, b0)
# test default algorithn
u=solve(pr,alg)
@test norm(u - u0, Inf) < 1.0e-13

# test factorization with reinit!
pr = LinearProblem(B0, b0)
cache=init(pr,alg)
u=solve!(cache)
@test norm(u - u0, Inf) < 1.0e-13
reinit!(cache; A=B1, b=b1)
u=solve!(cache)
@test norm(u - u0, Inf) < 1.0e-13
end
end
Loading