Browse Source

Add solve(!) methods for using SparseMatrixCS(C|R) directly.

fe/copyto
Fredrik Ekre 3 years ago
parent
commit
0267837576
  1. 18
      src/solvers.jl
  2. 16
      test/runtests.jl

18
src/solvers.jl

@ -51,6 +51,24 @@ function solve!(solver::HYPRESolver, x::PVector, A::PSparseMatrix, b::PVector)
return x return x
end end
########################################
# SparseMatrixCS(C|R) solver interface #
########################################
# TODO: This could use the HYPRE compile flag for sequential mode to avoid MPI overhead
function solve(solver::HYPRESolver, A::Union{SparseMatrixCSC,SparseMatrixCSR}, b::Vector)
hypre_x = solve(solver, HYPREMatrix(A), HYPREVector(b))
x = copy!(copy(b), hypre_x)
return x
end
function solve!(solver::HYPRESolver, x::Vector, A::Union{SparseMatrixCSC,SparseMatrixCSR}, b::Vector)
hypre_x = HYPREVector(x)
solve!(solver, hypre_x, HYPREMatrix(A), HYPREVector(b))
copy!(x, hypre_x)
return x
end
##################################### #####################################
## Concrete solver implementations ## ## Concrete solver implementations ##

16
test/runtests.jl

@ -454,3 +454,19 @@ end
x_p = HYPRE.solve(pcg, A_p, b_p) x_p = HYPRE.solve(pcg, A_p, b_p)
@test tomain(x_p) A \ b atol=tol @test tomain(x_p) A \ b atol=tol
end end
@testset "solve with SparseMatrixCS(C|R)" begin
# Setup
A = sprand(100, 100, 0.05); A = A'A + 5I
b = rand(100)
x = zeros(100)
# Solve
tol = 1e-9
pcg = HYPRE.PCG(; Tol = tol)
## solve!
HYPRE.solve!(pcg, x, A, b)
@test x A \ b atol=tol
## solve
x = HYPRE.solve(pcg, A, b)
@test x A \ b atol=tol
end

Loading…
Cancel
Save