From c2be7984e0ea58d90177fa2b48b761fedcb79558 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sun, 24 Jul 2022 00:38:03 +0200 Subject: [PATCH] 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. --- src/HYPRE.jl | 9 +++++++-- test/runtests.jl | 13 +++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/HYPRE.jl b/src/HYPRE.jl index b8ab947..07b11a2 100644 --- a/src/HYPRE.jl +++ b/src/HYPRE.jl @@ -208,7 +208,7 @@ function Internals.to_hypre_data(A::SparseMatrixCSR, ilower, iupper) end # 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) nrows, ncols, rows, cols, values = Internals.to_hypre_data(B, ilower, iupper) @check HYPRE_IJMatrixSetValues(A.IJMatrix, nrows, ncols, rows, cols, values) @@ -216,6 +216,9 @@ function HYPREMatrix(B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower, iupper, return A end +HYPREMatrix(B::Union{SparseMatrixCSC,SparseMatrixCSR}, ilower, iupper) = + HYPREMatrix(MPI.COMM_WORLD, B, ilower, iupper) + ######################### # Vector -> HYPREVector # ######################### @@ -229,7 +232,7 @@ end # TODO: Internals.to_hypre_data(x::SparseVector, ilower, iupper) (?) # 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) nvalues, indices, values = Internals.to_hypre_data(x, ilower, iupper) @check HYPRE_IJVectorSetValues(b.IJVector, nvalues, indices, values) @@ -237,6 +240,8 @@ function HYPREVector(x::Vector, ilower, iupper, comm=MPI.COMM_WORLD) return b end +HYPREVector(x::Vector, ilower, iupper) = HYPREVector(MPI.COMM_WORLD, x, ilower, iupper) + function Base.copy!(x::Vector, h::HYPREVector) ilower, iupper = Internals.get_proc_rows(h) nvalues = iupper - ilower + 1 diff --git a/test/runtests.jl b/test/runtests.jl index 21e67a3..8bf873c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -52,10 +52,16 @@ end CSC = sprand(5, 10, 0.3) CSR = sparsecsr(findnz(CSC)..., size(CSC)...) @test CSC == CSR - H = HYPREMatrix(CSC, ilower, iupper) + H = HYPREMatrix(CSC, ilower, iupper) @test H.IJMatrix != HYPRE_IJMatrix(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.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL) end @@ -182,6 +188,9 @@ end h = HYPREVector(b, ilower, iupper) @test h.IJVector != HYPRE_IJVector(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) ilower, iupper = 1, 10