Browse Source

Rework HYPREMatrix(::SparseMatrixCS(C|R)) and HYPREVector(::Vector)

This patch changes the argument order from:

    HYPREMatrix(::SparseMatrixCS(C|R), ::Integer, ::Integer, ::MPI.Comm)
    HYPREVector(::Vector,              ::Integer, ::Integer, ::MPI.Comm)

to:

    HYPREMatrix(::MPI.Comm, ::SparseMatrixCS(C|R), ::Integer, ::Integer)
    HYPREVector(::MPI.Comm, ::Vector,              ::Integer, ::Integer)

to match the basic constructor. This also makes it easier to default
owned rows to the full matrix/vector for single process solves. The
methods without the communicator (added in this patch) will in the
future have this default.
Fredrik Ekre 3 years ago
parent
commit
7769b403f8
  1. 9
      src/HYPRE.jl
  2. 13
      test/runtests.jl

9
src/HYPRE.jl

@ -208,7 +208,7 @@ function Internals.to_hypre_data(A::SparseMatrixCSR, ilower, iupper)
end end
# TODO: Default to ilower = 1, iupper = size(B, 1)? # TODO: Default to ilower = 1, iupper = size(B, 1)?
function HYPREMatrix(B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower, iupper, comm::MPI.Comm=MPI.COMM_WORLD) function HYPREMatrix(comm::MPI.Comm, B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower, iupper)
A = HYPREMatrix(comm, ilower, iupper) A = HYPREMatrix(comm, ilower, iupper)
nrows, ncols, rows, cols, values = Internals.to_hypre_data(B, ilower, iupper) nrows, ncols, rows, cols, values = Internals.to_hypre_data(B, ilower, iupper)
@check HYPRE_IJMatrixSetValues(A.IJMatrix, nrows, ncols, rows, cols, values) @check HYPRE_IJMatrixSetValues(A.IJMatrix, nrows, ncols, rows, cols, values)
@ -216,6 +216,9 @@ function HYPREMatrix(B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower, iupper,
return A return A
end end
HYPREMatrix(B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower, iupper) =
HYPREMatrix(MPI.COMM_WORLD, B, ilower, iupper)
######################### #########################
# Vector -> HYPREVector # # Vector -> HYPREVector #
######################### #########################
@ -229,7 +232,7 @@ end
# TODO: Internals.to_hypre_data(x::SparseVector, ilower, iupper) (?) # TODO: Internals.to_hypre_data(x::SparseVector, ilower, iupper) (?)
# TODO: Default to ilower = 1, iupper = length(x)? # TODO: Default to ilower = 1, iupper = length(x)?
function HYPREVector(x::Vector, ilower, iupper, comm=MPI.COMM_WORLD) function HYPREVector(comm::MPI.Comm, x::Vector, ilower, iupper)
b = HYPREVector(comm, ilower, iupper) b = HYPREVector(comm, ilower, iupper)
nvalues, indices, values = Internals.to_hypre_data(x, ilower, iupper) nvalues, indices, values = Internals.to_hypre_data(x, ilower, iupper)
@check HYPRE_IJVectorSetValues(b.IJVector, nvalues, indices, values) @check HYPRE_IJVectorSetValues(b.IJVector, nvalues, indices, values)
@ -237,6 +240,8 @@ function HYPREVector(x::Vector, ilower, iupper, comm=MPI.COMM_WORLD)
return b return b
end end
HYPREVector(x::Vector, ilower, iupper) = HYPREVector(MPI.COMM_WORLD, x, ilower, iupper)
function Base.copy!(x::Vector, h::HYPREVector) function Base.copy!(x::Vector, h::HYPREVector)
ilower, iupper = Internals.get_proc_rows(h) ilower, iupper = Internals.get_proc_rows(h)
nvalues = iupper - ilower + 1 nvalues = iupper - ilower + 1

13
test/runtests.jl

@ -52,10 +52,16 @@ end
CSC = sprand(5, 10, 0.3) CSC = sprand(5, 10, 0.3)
CSR = sparsecsr(findnz(CSC)..., size(CSC)...) CSR = sparsecsr(findnz(CSC)..., size(CSC)...)
@test CSC == CSR @test CSC == CSR
H = HYPREMatrix(CSC, ilower, iupper) H = HYPREMatrix(CSC, ilower, iupper)
@test H.IJMatrix != HYPRE_IJMatrix(C_NULL) @test H.IJMatrix != HYPRE_IJMatrix(C_NULL)
@test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL) @test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL)
H = HYPREMatrix(CSR, ilower, iupper) H = HYPREMatrix(MPI.COMM_WORLD, CSC, ilower, iupper)
@test H.IJMatrix != HYPRE_IJMatrix(C_NULL)
@test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL)
H = HYPREMatrix(CSR, ilower, iupper)
@test H.IJMatrix != HYPRE_IJMatrix(C_NULL)
@test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL)
H = HYPREMatrix(MPI.COMM_WORLD, CSR, ilower, iupper)
@test H.IJMatrix != HYPRE_IJMatrix(C_NULL) @test H.IJMatrix != HYPRE_IJMatrix(C_NULL)
@test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL) @test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL)
end end
@ -182,6 +188,9 @@ end
h = HYPREVector(b, ilower, iupper) h = HYPREVector(b, ilower, iupper)
@test h.IJVector != HYPRE_IJVector(C_NULL) @test h.IJVector != HYPRE_IJVector(C_NULL)
@test h.ParVector != HYPRE_ParVector(C_NULL) @test h.ParVector != HYPRE_ParVector(C_NULL)
h = HYPREVector(MPI.COMM_WORLD, b, ilower, iupper)
@test h.IJVector != HYPRE_IJVector(C_NULL)
@test h.ParVector != HYPRE_ParVector(C_NULL)
@test_throws ArgumentError HYPREVector([1, 2], ilower, iupper) @test_throws ArgumentError HYPREVector([1, 2], ilower, iupper)
ilower, iupper = 1, 10 ilower, iupper = 1, 10

Loading…
Cancel
Save