Browse Source

Default rows for HYPREMatrix(::SparseMatrixCS(C|R)) and HYPREVector(::Vector)

This patch adds defaults for ilower and iupper in constructors when i)
using SparseMatrixCS(C|R) and Vector and ii) when no communicator is
passed. In this case we simply assume the users wants a single-processor
solve, and default to passing 1 and size(A, 1) as the default values.

In the future this could possibly use the HYPRE sequential compiler
flag to completely avoid MPI.
fe/copyto
Fredrik Ekre 3 years ago
parent
commit
975c69d699
  1. 7
      src/HYPRE.jl
  2. 25
      test/runtests.jl

7
src/HYPRE.jl

@ -207,7 +207,6 @@ function Internals.to_hypre_data(A::SparseMatrixCSR, ilower, iupper)
return nrows, ncols, rows, cols, values return nrows, ncols, rows, cols, values
end end
# TODO: Default to ilower = 1, iupper = size(B, 1)?
function HYPREMatrix(comm::MPI.Comm, B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower, iupper) 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)
@ -216,7 +215,7 @@ function HYPREMatrix(comm::MPI.Comm, B::Union{SparseMatrixCSC,SparseMatrixCSR},
return A return A
end end
HYPREMatrix(B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower, iupper) = HYPREMatrix(B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower=1, iupper=size(B, 1)) =
HYPREMatrix(MPI.COMM_WORLD, B, ilower, iupper) HYPREMatrix(MPI.COMM_WORLD, B, ilower, iupper)
######################### #########################
@ -231,7 +230,6 @@ function Internals.to_hypre_data(x::Vector, ilower, iupper)
end 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)?
function HYPREVector(comm::MPI.Comm, x::Vector, ilower, iupper) 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)
@ -240,7 +238,8 @@ function HYPREVector(comm::MPI.Comm, x::Vector, ilower, iupper)
return b return b
end end
HYPREVector(x::Vector, ilower, iupper) = HYPREVector(MPI.COMM_WORLD, x, ilower, iupper) HYPREVector(x::Vector, ilower=1, iupper=length(x)) =
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)

25
test/runtests.jl

@ -52,18 +52,36 @@ 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(MPI.COMM_WORLD, CSC, ilower, iupper) H = HYPREMatrix(MPI.COMM_WORLD, 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(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)
H = HYPREMatrix(MPI.COMM_WORLD, CSR, ilower, iupper) 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)
# Default to owning all rows
CSC = sprand(10, 10, 0.3)
CSR = sparsecsr(findnz(CSC)..., size(CSC)...)
H = HYPREMatrix(CSC)
@test H.IJMatrix != HYPRE_IJMatrix(C_NULL)
@test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL)
@test H.comm == MPI.COMM_WORLD
@test H.ilower == H.jlower == 1
@test H.iupper == H.jupper == 10
H = HYPREMatrix(CSR)
@test H.IJMatrix != HYPRE_IJMatrix(C_NULL)
@test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL)
@test H.comm == MPI.COMM_WORLD
@test H.ilower == H.jlower == 1
@test H.iupper == H.jupper == 10
end end
function tomain(x) function tomain(x)
@ -192,6 +210,13 @@ end
@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)
@test_throws ArgumentError HYPREVector([1, 2], ilower, iupper) @test_throws ArgumentError HYPREVector([1, 2], ilower, iupper)
# Default to owning all rows
h = HYPREVector(b)
@test h.IJVector != HYPRE_IJVector(C_NULL)
@test h.ParVector != HYPRE_ParVector(C_NULL)
@test h.comm == MPI.COMM_WORLD
@test h.ilower == 1
@test h.iupper == 10
ilower, iupper = 1, 10 ilower, iupper = 1, 10
b = rand(HYPRE_Complex, 10) b = rand(HYPRE_Complex, 10)

Loading…
Cancel
Save