Browse Source

Lowercase for all struct fields.

pull/5/head
Fredrik Ekre 3 years ago
parent
commit
3ff69b2324
  1. 14
      docs/src/libhypre.md
  2. 68
      src/HYPRE.jl
  3. 16
      src/solvers.jl
  4. 60
      test/runtests.jl

14
docs/src/libhypre.md

@ -9,13 +9,13 @@ This is useful when you need some functionality from the library which can't be @@ -9,13 +9,13 @@ This is useful when you need some functionality from the library which can't be
through the Julia interface. Many functions require passing a reference to a matrix/vector
or a solver. These can be obtained as follows:
| C type signature | Argument to pass |
|:---------------------|:----------------------------------------|
| `HYPRE_IJMatrix` | `A.IJMatrix` where `A::HYPREMatrix` |
| `HYPRE_IJVector` | `b.IJVector` where `b::HYPREVector` |
| `HYPRE_ParCSRMatrix` | `A.ParCSRMatrix` where `A::HYPREMatrix` |
| `HYPRE_ParVector` | `b.ParVector` where `b::HYPREVector` |
| `HYPRE_Solver` | `s.Solver` where `s::HYPRESolver` |
| C type signature | Argument to pass |
|:---------------------|:-------------------------------------|
| `HYPRE_IJMatrix` | `A.ijmatrix` where `A::HYPREMatrix` |
| `HYPRE_ParCSRMatrix` | `A.parmatrix` where `A::HYPREMatrix` |
| `HYPRE_IJVector` | `b.ijvector` where `b::HYPREVector` |
| `HYPRE_ParVector` | `b.parvector` where `b::HYPREVector` |
| `HYPRE_Solver` | `s.solver` where `s::HYPRESolver` |
[^1]: Bindings are generated using
[Clang.jl](https://github.com/JuliaInterop/Clang.jl), see

68
src/HYPRE.jl

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

16
src/solvers.jl

@ -96,8 +96,8 @@ end @@ -96,8 +96,8 @@ end
const ParCSRBiCGSTAB = BiCGSTAB
function solve!(bicg::BiCGSTAB, x::HYPREVector, A::HYPREMatrix, b::HYPREVector)
@check HYPRE_ParCSRBiCGSTABSetup(bicg.solver, A.ParCSRMatrix, b.ParVector, x.ParVector)
@check HYPRE_ParCSRBiCGSTABSolve(bicg.solver, A.ParCSRMatrix, b.ParVector, x.ParVector)
@check HYPRE_ParCSRBiCGSTABSetup(bicg.solver, A.parmatrix, b.parvector, x.parvector)
@check HYPRE_ParCSRBiCGSTABSolve(bicg.solver, A.parmatrix, b.parvector, x.parvector)
return x
end
@ -132,8 +132,8 @@ mutable struct BoomerAMG <: HYPRESolver @@ -132,8 +132,8 @@ mutable struct BoomerAMG <: HYPRESolver
end
function solve!(amg::BoomerAMG, x::HYPREVector, A::HYPREMatrix, b::HYPREVector)
@check HYPRE_BoomerAMGSetup(amg.solver, A.ParCSRMatrix, b.ParVector, x.ParVector)
@check HYPRE_BoomerAMGSolve(amg.solver, A.ParCSRMatrix, b.ParVector, x.ParVector)
@check HYPRE_BoomerAMGSetup(amg.solver, A.parmatrix, b.parvector, x.parvector)
@check HYPRE_BoomerAMGSolve(amg.solver, A.parmatrix, b.parvector, x.parvector)
return x
end
@ -161,8 +161,8 @@ mutable struct GMRES <: HYPRESolver @@ -161,8 +161,8 @@ mutable struct GMRES <: HYPRESolver
end
function solve!(gmres::GMRES, x::HYPREVector, A::HYPREMatrix, b::HYPREVector)
@check HYPRE_ParCSRGMRESSetup(gmres.solver, A.ParCSRMatrix, b.ParVector, x.ParVector)
@check HYPRE_ParCSRGMRESSolve(gmres.solver, A.ParCSRMatrix, b.ParVector, x.ParVector)
@check HYPRE_ParCSRGMRESSetup(gmres.solver, A.parmatrix, b.parvector, x.parvector)
@check HYPRE_ParCSRGMRESSolve(gmres.solver, A.parmatrix, b.parvector, x.parvector)
return x
end
@ -199,8 +199,8 @@ end @@ -199,8 +199,8 @@ end
const ParCSRPCG = PCG
function solve!(pcg::PCG, x::HYPREVector, A::HYPREMatrix, b::HYPREVector)
@check HYPRE_ParCSRPCGSetup(pcg.solver, A.ParCSRMatrix, b.ParVector, x.ParVector)
@check HYPRE_ParCSRPCGSolve(pcg.solver, A.ParCSRMatrix, b.ParVector, x.ParVector)
@check HYPRE_ParCSRPCGSetup(pcg.solver, A.parmatrix, b.parvector, x.parvector)
@check HYPRE_ParCSRPCGSolve(pcg.solver, A.parmatrix, b.parvector, x.parvector)
return x
end

60
test/runtests.jl

@ -15,11 +15,11 @@ HYPRE.Init() @@ -15,11 +15,11 @@ HYPRE.Init()
@testset "HYPREMatrix" begin
H = HYPREMatrix(MPI.COMM_WORLD, 1, 5)
@test H.IJMatrix != HYPRE_IJMatrix(C_NULL)
@test H.ParCSRMatrix == HYPRE_ParCSRMatrix(C_NULL)
@test H.ijmatrix != HYPRE_IJMatrix(C_NULL)
@test H.parmatrix == HYPRE_ParCSRMatrix(C_NULL)
Internals.assemble_matrix(H)
@test H.IJMatrix != HYPRE_IJMatrix(C_NULL)
@test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL)
@test H.ijmatrix != HYPRE_IJMatrix(C_NULL)
@test H.parmatrix != HYPRE_ParCSRMatrix(C_NULL)
end
@testset "HYPREMatrix(::SparseMatrixCS(C|R))" begin
@ -54,31 +54,31 @@ end @@ -54,31 +54,31 @@ end
@test CSC == CSR
H = HYPREMatrix(CSC, ilower, iupper)
@test H.IJMatrix != HYPRE_IJMatrix(C_NULL)
@test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL)
@test H.ijmatrix != HYPRE_IJMatrix(C_NULL)
@test H.parmatrix != HYPRE_ParCSRMatrix(C_NULL)
H = HYPREMatrix(MPI.COMM_WORLD, CSC, ilower, iupper)
@test H.IJMatrix != HYPRE_IJMatrix(C_NULL)
@test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL)
@test H.ijmatrix != HYPRE_IJMatrix(C_NULL)
@test H.parmatrix != HYPRE_ParCSRMatrix(C_NULL)
H = HYPREMatrix(CSR, ilower, iupper)
@test H.IJMatrix != HYPRE_IJMatrix(C_NULL)
@test H.ParCSRMatrix != HYPRE_ParCSRMatrix(C_NULL)
@test H.ijmatrix != HYPRE_IJMatrix(C_NULL)
@test H.parmatrix != 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)
@test H.ijmatrix != HYPRE_IJMatrix(C_NULL)
@test H.parmatrix != 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.ijmatrix != HYPRE_IJMatrix(C_NULL)
@test H.parmatrix != 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.ijmatrix != HYPRE_IJMatrix(C_NULL)
@test H.parmatrix != HYPRE_ParCSRMatrix(C_NULL)
@test H.comm == MPI.COMM_WORLD
@test H.ilower == H.jlower == 1
@test H.iupper == H.jupper == 10
@ -185,11 +185,11 @@ end @@ -185,11 +185,11 @@ end
@testset "HYPREVector" begin
h = HYPREVector(MPI.COMM_WORLD, 1, 5)
@test h.IJVector != HYPRE_IJVector(C_NULL)
@test h.ParVector == HYPRE_ParVector(C_NULL)
@test h.ijvector != HYPRE_IJVector(C_NULL)
@test h.parvector == HYPRE_ParVector(C_NULL)
Internals.assemble_vector(h)
@test h.IJVector != HYPRE_IJVector(C_NULL)
@test h.ParVector != HYPRE_ParVector(C_NULL)
@test h.ijvector != HYPRE_IJVector(C_NULL)
@test h.parvector != HYPRE_ParVector(C_NULL)
# Base.zero(::HYPREVector) and Base.copy!(::Vector, HYPREVector)
b = rand(10)
@ -204,16 +204,16 @@ end @@ -204,16 +204,16 @@ end
ilower, iupper = 1, 10
b = rand(HYPRE_Complex, 10)
h = HYPREVector(b, ilower, iupper)
@test h.IJVector != HYPRE_IJVector(C_NULL)
@test h.ParVector != HYPRE_ParVector(C_NULL)
@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 h.ijvector != HYPRE_IJVector(C_NULL)
@test h.parvector != HYPRE_ParVector(C_NULL)
@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.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
@ -251,8 +251,8 @@ end @@ -251,8 +251,8 @@ end
assemble!(pb)
@test tomain(pb) == [i in 4:6 ? 2x : x for (i, x) in zip(eachindex(b), b)]
H = HYPREVector(pb)
@test H.IJVector != HYPRE_IJVector(C_NULL)
@test H.ParVector != HYPRE_ParVector(C_NULL)
@test H.ijvector != HYPRE_IJVector(C_NULL)
@test H.parvector != HYPRE_ParVector(C_NULL)
pbc = fill!(copy(pb), 0)
copy!(pbc, H)
@test tomain(pbc) == tomain(pb)
@ -268,8 +268,8 @@ end @@ -268,8 +268,8 @@ end
assemble!(pb)
@test tomain(pb) == b
H = HYPREVector(pb)
@test H.IJVector != HYPRE_IJVector(C_NULL)
@test H.ParVector != HYPRE_ParVector(C_NULL)
@test H.ijvector != HYPRE_IJVector(C_NULL)
@test H.parvector != HYPRE_ParVector(C_NULL)
pbc = fill!(copy(pb), 0)
copy!(pbc, H)
@test tomain(pbc) == tomain(pb)

Loading…
Cancel
Save