|
|
|
@ -52,23 +52,23 @@ mutable struct HYPREMatrix # <: AbstractMatrix{HYPRE_Complex} |
|
|
|
#= const =# iupper::HYPRE_BigInt |
|
|
|
#= const =# iupper::HYPRE_BigInt |
|
|
|
#= const =# jlower::HYPRE_BigInt |
|
|
|
#= const =# jlower::HYPRE_BigInt |
|
|
|
#= const =# jupper::HYPRE_BigInt |
|
|
|
#= const =# jupper::HYPRE_BigInt |
|
|
|
IJMatrix::HYPRE_IJMatrix |
|
|
|
ijmatrix::HYPRE_IJMatrix |
|
|
|
ParCSRMatrix::HYPRE_ParCSRMatrix |
|
|
|
parmatrix::HYPRE_ParCSRMatrix |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function HYPREMatrix(comm::MPI.Comm, ilower::Integer, iupper::Integer, |
|
|
|
function HYPREMatrix(comm::MPI.Comm, ilower::Integer, iupper::Integer, |
|
|
|
jlower::Integer=ilower, jupper::Integer=iupper) |
|
|
|
jlower::Integer=ilower, jupper::Integer=iupper) |
|
|
|
# Create the IJ matrix |
|
|
|
# Create the IJ matrix |
|
|
|
A = HYPREMatrix(comm, ilower, iupper, jlower, jupper, C_NULL, C_NULL) |
|
|
|
A = HYPREMatrix(comm, ilower, iupper, jlower, jupper, C_NULL, C_NULL) |
|
|
|
IJMatrixRef = Ref{HYPRE_IJMatrix}(C_NULL) |
|
|
|
ijmatrix_ref = Ref{HYPRE_IJMatrix}(C_NULL) |
|
|
|
@check HYPRE_IJMatrixCreate(comm, ilower, iupper, ilower, iupper, IJMatrixRef) |
|
|
|
@check HYPRE_IJMatrixCreate(comm, ilower, iupper, ilower, iupper, ijmatrix_ref) |
|
|
|
A.IJMatrix = IJMatrixRef[] |
|
|
|
A.ijmatrix = ijmatrix_ref[] |
|
|
|
# Attach a finalizer |
|
|
|
# Attach a finalizer |
|
|
|
finalizer(x -> HYPRE_IJMatrixDestroy(x.IJMatrix), A) |
|
|
|
finalizer(x -> HYPRE_IJMatrixDestroy(x.ijmatrix), A) |
|
|
|
# Set storage type |
|
|
|
# Set storage type |
|
|
|
@check HYPRE_IJMatrixSetObjectType(A.IJMatrix, HYPRE_PARCSR) |
|
|
|
@check HYPRE_IJMatrixSetObjectType(A.ijmatrix, HYPRE_PARCSR) |
|
|
|
# Initialize to make ready for setting values |
|
|
|
# Initialize to make ready for setting values |
|
|
|
@check HYPRE_IJMatrixInitialize(A.IJMatrix) |
|
|
|
@check HYPRE_IJMatrixInitialize(A.ijmatrix) |
|
|
|
return A |
|
|
|
return A |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@ -76,11 +76,11 @@ end |
|
|
|
# This should be called after setting all the values |
|
|
|
# This should be called after setting all the values |
|
|
|
function Internals.assemble_matrix(A::HYPREMatrix) |
|
|
|
function Internals.assemble_matrix(A::HYPREMatrix) |
|
|
|
# Finalize after setting all values |
|
|
|
# Finalize after setting all values |
|
|
|
@check HYPRE_IJMatrixAssemble(A.IJMatrix) |
|
|
|
@check HYPRE_IJMatrixAssemble(A.ijmatrix) |
|
|
|
# Fetch the assembled CSR matrix |
|
|
|
# Fetch the assembled CSR matrix |
|
|
|
ParCSRMatrixRef = Ref{Ptr{Cvoid}}(C_NULL) |
|
|
|
parmatrix_ref = Ref{Ptr{Cvoid}}(C_NULL) |
|
|
|
@check HYPRE_IJMatrixGetObject(A.IJMatrix, ParCSRMatrixRef) |
|
|
|
@check HYPRE_IJMatrixGetObject(A.ijmatrix, parmatrix_ref) |
|
|
|
A.ParCSRMatrix = convert(Ptr{HYPRE_ParCSRMatrix}, ParCSRMatrixRef[]) |
|
|
|
A.parmatrix = convert(Ptr{HYPRE_ParCSRMatrix}, parmatrix_ref[]) |
|
|
|
return A |
|
|
|
return A |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@ -92,39 +92,39 @@ mutable struct HYPREVector # <: AbstractVector{HYPRE_Complex} |
|
|
|
#= const =# comm::MPI.Comm |
|
|
|
#= const =# comm::MPI.Comm |
|
|
|
#= const =# ilower::HYPRE_BigInt |
|
|
|
#= const =# ilower::HYPRE_BigInt |
|
|
|
#= const =# iupper::HYPRE_BigInt |
|
|
|
#= const =# iupper::HYPRE_BigInt |
|
|
|
IJVector::HYPRE_IJVector |
|
|
|
ijvector::HYPRE_IJVector |
|
|
|
ParVector::HYPRE_ParVector |
|
|
|
parvector::HYPRE_ParVector |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function HYPREVector(comm::MPI.Comm, ilower::Integer, iupper::Integer) |
|
|
|
function HYPREVector(comm::MPI.Comm, ilower::Integer, iupper::Integer) |
|
|
|
# Create the IJ vector |
|
|
|
# Create the IJ vector |
|
|
|
b = HYPREVector(comm, ilower, iupper, C_NULL, C_NULL) |
|
|
|
b = HYPREVector(comm, ilower, iupper, C_NULL, C_NULL) |
|
|
|
b_ref = Ref{HYPRE_IJVector}(C_NULL) |
|
|
|
ijvector_ref = Ref{HYPRE_IJVector}(C_NULL) |
|
|
|
@check HYPRE_IJVectorCreate(comm, ilower, iupper, b_ref) |
|
|
|
@check HYPRE_IJVectorCreate(comm, ilower, iupper, ijvector_ref) |
|
|
|
b.IJVector = b_ref[] |
|
|
|
b.ijvector = ijvector_ref[] |
|
|
|
# Attach a finalizer |
|
|
|
# Attach a finalizer |
|
|
|
finalizer(x -> HYPRE_IJVectorDestroy(x.IJVector), b) # Set storage type |
|
|
|
finalizer(x -> HYPRE_IJVectorDestroy(x.ijvector), b) |
|
|
|
# Set storage type |
|
|
|
# Set storage type |
|
|
|
@check HYPRE_IJVectorSetObjectType(b.IJVector, HYPRE_PARCSR) |
|
|
|
@check HYPRE_IJVectorSetObjectType(b.ijvector, HYPRE_PARCSR) |
|
|
|
# Initialize to make ready for setting values |
|
|
|
# Initialize to make ready for setting values |
|
|
|
@check HYPRE_IJVectorInitialize(b.IJVector) |
|
|
|
@check HYPRE_IJVectorInitialize(b.ijvector) |
|
|
|
return b |
|
|
|
return b |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function Internals.assemble_vector(b::HYPREVector) |
|
|
|
function Internals.assemble_vector(b::HYPREVector) |
|
|
|
# Finalize after setting all values |
|
|
|
# Finalize after setting all values |
|
|
|
@check HYPRE_IJVectorAssemble(b.IJVector) |
|
|
|
@check HYPRE_IJVectorAssemble(b.ijvector) |
|
|
|
# Fetch the assembled vector |
|
|
|
# Fetch the assembled vector |
|
|
|
par_b_ref = Ref{Ptr{Cvoid}}(C_NULL) |
|
|
|
parvector_ref = Ref{Ptr{Cvoid}}(C_NULL) |
|
|
|
@check HYPRE_IJVectorGetObject(b.IJVector, par_b_ref) |
|
|
|
@check HYPRE_IJVectorGetObject(b.ijvector, parvector_ref) |
|
|
|
b.ParVector = convert(Ptr{HYPRE_ParVector}, par_b_ref[]) |
|
|
|
b.parvector = convert(Ptr{HYPRE_ParVector}, parvector_ref[]) |
|
|
|
return b |
|
|
|
return b |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function Internals.get_proc_rows(b::HYPREVector) |
|
|
|
function Internals.get_proc_rows(b::HYPREVector) |
|
|
|
# ilower_ref = Ref{HYPRE_BigInt}() |
|
|
|
# ilower_ref = Ref{HYPRE_BigInt}() |
|
|
|
# iupper_ref = Ref{HYPRE_BigInt}() |
|
|
|
# iupper_ref = Ref{HYPRE_BigInt}() |
|
|
|
# @check HYPRE_IJVectorGetLocalRange(b.IJVector, ilower_ref, iupper_ref) |
|
|
|
# @check HYPRE_IJVectorGetLocalRange(b.ijvector, ilower_ref, iupper_ref) |
|
|
|
# ilower = ilower_ref[] |
|
|
|
# ilower = ilower_ref[] |
|
|
|
# iupper = iupper_ref[] |
|
|
|
# iupper = iupper_ref[] |
|
|
|
# return ilower, iupper |
|
|
|
# return ilower, iupper |
|
|
|
@ -135,8 +135,8 @@ function Internals.get_comm(b::HYPREVector) |
|
|
|
# # The MPI communicator is (currently) the first field of the struct: |
|
|
|
# # The MPI communicator is (currently) the first field of the struct: |
|
|
|
# # https://github.com/hypre-space/hypre/blob/48de53e675af0e23baf61caa73d89fd9f478f453/src/IJ_mv/IJ_vector.h#L23 |
|
|
|
# # https://github.com/hypre-space/hypre/blob/48de53e675af0e23baf61caa73d89fd9f478f453/src/IJ_mv/IJ_vector.h#L23 |
|
|
|
# # Fingers crossed this doesn't change! |
|
|
|
# # Fingers crossed this doesn't change! |
|
|
|
# @assert b.IJVector != C_NULL |
|
|
|
# @assert b.ijvector != C_NULL |
|
|
|
# comm = unsafe_load(Ptr{MPI.Comm}(b.IJVector)) |
|
|
|
# comm = unsafe_load(Ptr{MPI.Comm}(b.ijvector)) |
|
|
|
# return comm |
|
|
|
# return comm |
|
|
|
return b.comm |
|
|
|
return b.comm |
|
|
|
end |
|
|
|
end |
|
|
|
@ -150,7 +150,7 @@ function Base.zero(b::HYPREVector) |
|
|
|
nvalues = jupper - jlower + 1 |
|
|
|
nvalues = jupper - jlower + 1 |
|
|
|
indices = collect(HYPRE_BigInt, jlower:jupper) |
|
|
|
indices = collect(HYPRE_BigInt, jlower:jupper) |
|
|
|
values = zeros(HYPRE_Complex, nvalues) |
|
|
|
values = zeros(HYPRE_Complex, nvalues) |
|
|
|
@check HYPRE_IJVectorSetValues(x.IJVector, nvalues, indices, values) |
|
|
|
@check HYPRE_IJVectorSetValues(x.ijvector, nvalues, indices, values) |
|
|
|
# Finalize and return |
|
|
|
# Finalize and return |
|
|
|
Internals.assemble_vector(x) |
|
|
|
Internals.assemble_vector(x) |
|
|
|
return x |
|
|
|
return x |
|
|
|
@ -237,7 +237,7 @@ end |
|
|
|
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) |
|
|
|
@check HYPRE_IJMatrixSetValues(A.IJMatrix, nrows, ncols, rows, cols, values) |
|
|
|
@check HYPRE_IJMatrixSetValues(A.ijmatrix, nrows, ncols, rows, cols, values) |
|
|
|
Internals.assemble_matrix(A) |
|
|
|
Internals.assemble_matrix(A) |
|
|
|
return A |
|
|
|
return A |
|
|
|
end |
|
|
|
end |
|
|
|
@ -260,7 +260,7 @@ end |
|
|
|
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) |
|
|
|
@check HYPRE_IJVectorSetValues(b.IJVector, nvalues, indices, values) |
|
|
|
@check HYPRE_IJVectorSetValues(b.ijvector, nvalues, indices, values) |
|
|
|
Internals.assemble_vector(b) |
|
|
|
Internals.assemble_vector(b) |
|
|
|
return b |
|
|
|
return b |
|
|
|
end |
|
|
|
end |
|
|
|
@ -276,7 +276,7 @@ function Base.copy!(x::Vector{HYPRE_Complex}, h::HYPREVector) |
|
|
|
throw(ArgumentError("different lengths")) |
|
|
|
throw(ArgumentError("different lengths")) |
|
|
|
end |
|
|
|
end |
|
|
|
indices = collect(HYPRE_BigInt, ilower:iupper) |
|
|
|
indices = collect(HYPRE_BigInt, ilower:iupper) |
|
|
|
@check HYPRE_IJVectorGetValues(h.IJVector, nvalues, indices, x) |
|
|
|
@check HYPRE_IJVectorGetValues(h.ijvector, nvalues, indices, x) |
|
|
|
return x |
|
|
|
return x |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@ -404,7 +404,7 @@ function HYPREMatrix(B::PSparseMatrix) |
|
|
|
# Set all the values |
|
|
|
# Set all the values |
|
|
|
map_parts(B.values, B.rows.partition, B.cols.partition) do Bv, Br, Bc |
|
|
|
map_parts(B.values, B.rows.partition, B.cols.partition) do Bv, Br, Bc |
|
|
|
nrows, ncols, rows, cols, values = Internals.to_hypre_data(Bv, Br, Bc) |
|
|
|
nrows, ncols, rows, cols, values = Internals.to_hypre_data(Bv, Br, Bc) |
|
|
|
@check HYPRE_IJMatrixSetValues(A.IJMatrix, nrows, ncols, rows, cols, values) |
|
|
|
@check HYPRE_IJMatrixSetValues(A.ijmatrix, nrows, ncols, rows, cols, values) |
|
|
|
return nothing |
|
|
|
return nothing |
|
|
|
end |
|
|
|
end |
|
|
|
# Finalize |
|
|
|
# Finalize |
|
|
|
@ -446,7 +446,7 @@ function HYPREVector(v::PVector) |
|
|
|
# end |
|
|
|
# end |
|
|
|
# nvalues = length(indices) |
|
|
|
# nvalues = length(indices) |
|
|
|
|
|
|
|
|
|
|
|
@check HYPRE_IJVectorSetValues(b.IJVector, nvalues, indices, values) |
|
|
|
@check HYPRE_IJVectorSetValues(b.ijvector, nvalues, indices, values) |
|
|
|
return nothing |
|
|
|
return nothing |
|
|
|
end |
|
|
|
end |
|
|
|
# Finalize |
|
|
|
# Finalize |
|
|
|
@ -469,7 +469,7 @@ function Base.copy!(v::PVector{HYPRE_Complex}, h::HYPREVector) |
|
|
|
indices = collect(HYPRE_BigInt, ilower_v_part:iupper_v_part) |
|
|
|
indices = collect(HYPRE_BigInt, ilower_v_part:iupper_v_part) |
|
|
|
|
|
|
|
|
|
|
|
# TODO: Safe to use vv here? Owned values are always first? |
|
|
|
# TODO: Safe to use vv here? Owned values are always first? |
|
|
|
@check HYPRE_IJVectorGetValues(h.IJVector, nvalues, indices, vv) |
|
|
|
@check HYPRE_IJVectorGetValues(h.ijvector, nvalues, indices, vv) |
|
|
|
end |
|
|
|
end |
|
|
|
return v |
|
|
|
return v |
|
|
|
end |
|
|
|
end |
|
|
|
|