Browse Source

runic -i .

pull/32/head
Fredrik Ekre 11 months ago
parent
commit
85af5be132
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 33
      examples/ex5.jl
  2. 12
      ext/HYPREPartitionedArrays.jl
  3. 4
      ext/HYPRESparseArrays.jl
  4. 2
      ext/HYPRESparseMatricesCSR.jl
  5. 15
      gen/generator.jl
  6. 6
      gen/prologue.jl
  7. 3
      gen/solver_options.jl
  8. 1752
      lib/LibHYPRE.jl
  9. 15
      src/HYPRE.jl
  10. 3
      src/LibHYPRE.jl
  11. 8
      src/solver_options.jl
  12. 19
      src/solvers.jl
  13. 119
      test/runtests.jl
  14. 10
      test/test_assembler.jl

33
examples/ex5.jl

@ -85,7 +85,9 @@ function main(argc, argv) @@ -85,7 +85,9 @@ function main(argc, argv)
end
# Preliminaries: want at least one processor per row
if n * n < num_procs; n = trunc(Int, sqrt(n)) + 1; end
if n * n < num_procs
n = trunc(Int, sqrt(n)) + 1
end
N = n * n # global number of rows
h = 1.0 / (n + 1) # mesh size
h2 = h * h
@ -257,8 +259,7 @@ function main(argc, argv) @@ -257,8 +259,7 @@ function main(argc, argv)
num_iterations = Ref{Cint}()
final_res_norm = Ref{Cdouble}()
# AMG
if solver_id == 0
if solver_id == 0 # AMG
# Create solver
HYPRE_BoomerAMGCreate(solver_ref)
solver = solver_ref[]
@ -270,7 +271,7 @@ function main(argc, argv) @@ -270,7 +271,7 @@ function main(argc, argv)
HYPRE_BoomerAMGSetRelaxOrder(solver, 1) # uses C/F relaxation
HYPRE_BoomerAMGSetNumSweeps(solver, 1) # Sweeeps on each level
HYPRE_BoomerAMGSetMaxLevels(solver, 20) # maximum number of levels
HYPRE_BoomerAMGSetTol(solver, 1e-7) # conv. tolerance
HYPRE_BoomerAMGSetTol(solver, 1.0e-7) # conv. tolerance
# Now setup and solve!
HYPRE_BoomerAMGSetup(solver, parcsr_A, par_b, par_x)
@ -289,15 +290,14 @@ function main(argc, argv) @@ -289,15 +290,14 @@ function main(argc, argv)
# Destroy solver
HYPRE_BoomerAMGDestroy(solver)
# PCG
elseif solver_id == 50
elseif solver_id == 50 # PCG
# Create solver
HYPRE_ParCSRPCGCreate(MPI_COMM_WORLD, solver_ref)
solver = solver_ref[]
# Set some parameters (See Reference Manual for more parameters)
HYPRE_PCGSetMaxIter(solver, 1000) # max iterations
HYPRE_PCGSetTol(solver, 1e-7) # conv. tolerance
HYPRE_PCGSetTol(solver, 1.0e-7) # conv. tolerance
HYPRE_PCGSetTwoNorm(solver, 1) # use the two norm as the stopping criteria
HYPRE_PCGSetPrintLevel(solver, 2) # prints out the iteration info
HYPRE_PCGSetLogging(solver, 1) # needed to get run info later
@ -319,15 +319,14 @@ function main(argc, argv) @@ -319,15 +319,14 @@ function main(argc, argv)
# Destroy solver
HYPRE_ParCSRPCGDestroy(solver)
# PCG with AMG preconditioner
elseif solver_id == 1
elseif solver_id == 1 # PCG with AMG preconditioner
# Create solver
HYPRE_ParCSRPCGCreate(MPI_COMM_WORLD, solver_ref)
solver = solver_ref[]
# Set some parameters (See Reference Manual for more parameters)
HYPRE_PCGSetMaxIter(solver, 1000) # max iterations
HYPRE_PCGSetTol(solver, 1e-7) # conv. tolerance
HYPRE_PCGSetTol(solver, 1.0e-7) # conv. tolerance
HYPRE_PCGSetTwoNorm(solver, 1) # use the two norm as the stopping criteria
HYPRE_PCGSetPrintLevel(solver, 2) # print solve info
HYPRE_PCGSetLogging(solver, 1) # needed to get run info later
@ -364,15 +363,14 @@ function main(argc, argv) @@ -364,15 +363,14 @@ function main(argc, argv)
HYPRE_ParCSRPCGDestroy(solver)
HYPRE_BoomerAMGDestroy(precond)
# PCG with Parasails Preconditioner
elseif solver_id == 8
elseif solver_id == 8 # PCG with Parasails Preconditioner
# Create solver
HYPRE_ParCSRPCGCreate(MPI_COMM_WORLD, solver_ref)
solver = solver_ref[]
# Set some parameters (See Reference Manual for more parameters)
HYPRE_PCGSetMaxIter(solver, 1000) # max iterations
HYPRE_PCGSetTol(solver, 1e-7) # conv. tolerance
HYPRE_PCGSetTol(solver, 1.0e-7) # conv. tolerance
HYPRE_PCGSetTwoNorm(solver, 1) # use the two norm as the stopping criteria
HYPRE_PCGSetPrintLevel(solver, 2) # print solve info
HYPRE_PCGSetLogging(solver, 1) # needed to get run info later
@ -412,8 +410,7 @@ function main(argc, argv) @@ -412,8 +410,7 @@ function main(argc, argv)
HYPRE_ParCSRPCGDestroy(solver)
HYPRE_ParaSailsDestroy(precond)
# Flexible GMRES with AMG Preconditioner
elseif solver_id == 61
elseif solver_id == 61 # Flexible GMRES with AMG Preconditioner
# Create solver
HYPRE_ParCSRFlexGMRESCreate(MPI_COMM_WORLD, solver_ref)
@ -422,7 +419,7 @@ function main(argc, argv) @@ -422,7 +419,7 @@ function main(argc, argv)
# Set some parameters (See Reference Manual for more parameters)
HYPRE_FlexGMRESSetKDim(solver, 30) # restart
HYPRE_FlexGMRESSetMaxIter(solver, 1000) # max iterations
HYPRE_FlexGMRESSetTol(solver, 1e-7) # conv. tolerance
HYPRE_FlexGMRESSetTol(solver, 1.0e-7) # conv. tolerance
HYPRE_FlexGMRESSetPrintLevel(solver, 2) # print solve info
HYPRE_FlexGMRESSetLogging(solver, 1) # needed to get run info later
@ -459,7 +456,9 @@ function main(argc, argv) @@ -459,7 +456,9 @@ function main(argc, argv)
HYPRE_BoomerAMGDestroy(precond)
else
if myid == 0; println("Invalid solver id specified."); end
if myid == 0
println("Invalid solver id specified.")
end
end
# Clean up

12
ext/HYPREPartitionedArrays.jl

@ -66,7 +66,7 @@ function Internals.to_hypre_data( @@ -66,7 +66,7 @@ function Internals.to_hypre_data(
# Keep track of the last index used for every row
lastinds = zeros(Int, nrows)
cumsum!((@view lastinds[2:end]), (@view ncols[1:end-1]))
cumsum!((@view lastinds[2:end]), (@view ncols[1:(end - 1)]))
# Second pass to populate the output. Here we need to map column
# indices from own/ghost to global
@ -149,11 +149,11 @@ function Internals.to_hypre_data( @@ -149,11 +149,11 @@ function Internals.to_hypre_data(
return nrows, ncols, rows, cols, values
end
function Internals.get_comm(A::Union{PSparseMatrix{<:Any,<:M}, PVector{<:Any,<:M}}) where M <: MPIArray
function Internals.get_comm(A::Union{PSparseMatrix{<:Any, <:M}, PVector{<:Any, <:M}}) where {M <: MPIArray}
return partition(A).comm
end
Internals.get_comm(_::Union{PSparseMatrix,PVector}) = MPI.COMM_SELF
Internals.get_comm(_::Union{PSparseMatrix, PVector}) = MPI.COMM_SELF
function Internals.get_proc_rows(A::Union{PSparseMatrix, PVector})
ilower::HYPRE_BigInt = typemax(HYPRE_BigInt)
@ -238,10 +238,10 @@ function copy_check(dst::HYPREVector, src::PVector) @@ -238,10 +238,10 @@ function copy_check(dst::HYPREVector, src::PVector)
il_src, iu_src = Internals.get_proc_rows(src)
if il_dst != il_src && iu_dst != iu_src
# TODO: Why require this?
throw(ArgumentError(
"row owner mismatch between dst ($(il_dst:iu_dst)) and src ($(il_src:iu_src))"
))
msg = "row owner mismatch between dst ($(il_dst:iu_dst)) and src ($(il_src:iu_src))"
throw(ArgumentError(msg))
end
return
end
# TODO: Other eltypes could be support by using a intermediate buffer

4
ext/HYPRESparseArrays.jl

@ -33,7 +33,7 @@ function Internals.to_hypre_data(A::SparseMatrixCSC, ilower, iupper) @@ -33,7 +33,7 @@ function Internals.to_hypre_data(A::SparseMatrixCSC, ilower, iupper)
# Keep track of the last index used for every row
lastinds = zeros(Int, nrows)
cumsum!((@view lastinds[2:end]), (@view ncols[1:end-1]))
cumsum!((@view lastinds[2:end]), (@view ncols[1:(end - 1)]))
# Second pass to populate the output
@inbounds for j in 1:size(A, 2)
@ -59,7 +59,7 @@ function HYPRE.HYPREMatrix(comm::MPI.Comm, B::SparseMatrixCSC, ilower, iupper) @@ -59,7 +59,7 @@ function HYPRE.HYPREMatrix(comm::MPI.Comm, B::SparseMatrixCSC, ilower, iupper)
end
# Note: keep in sync with the SparseMatrixCSC method
function HYPRE.HYPREMatrix(B::SparseMatrixCSC, ilower=1, iupper=size(B, 1))
function HYPRE.HYPREMatrix(B::SparseMatrixCSC, ilower = 1, iupper = size(B, 1))
return HYPREMatrix(MPI.COMM_SELF, B, ilower, iupper)
end

2
ext/HYPRESparseMatricesCSR.jl

@ -53,7 +53,7 @@ function HYPRE.HYPREMatrix(comm::MPI.Comm, B::SparseMatrixCSR, ilower, iupper) @@ -53,7 +53,7 @@ function HYPRE.HYPREMatrix(comm::MPI.Comm, B::SparseMatrixCSR, ilower, iupper)
end
# Note: keep in sync with the SparseMatrixCSC method
function HYPRE.HYPREMatrix(B::SparseMatrixCSR, ilower=1, iupper=size(B, 1))
function HYPRE.HYPREMatrix(B::SparseMatrixCSR, ilower = 1, iupper = size(B, 1))
return HYPREMatrix(MPI.COMM_SELF, B, ilower, iupper)
end

15
gen/generator.jl

@ -21,12 +21,15 @@ push!(args, "-DHYPRE_ENABLE_CUDA_STREAMS=OFF") @@ -21,12 +21,15 @@ push!(args, "-DHYPRE_ENABLE_CUDA_STREAMS=OFF")
push!(args, "-DHYPRE_ENABLE_CUSPARSE=OFF")
push!(args, "-DHYPRE_ENABLE_CURAND=OFF")
headers = joinpath.(hypre_include_dir, [
"HYPRE.h",
"HYPRE_IJ_mv.h",
"HYPRE_parcsr_mv.h",
"HYPRE_parcsr_ls.h",
])
headers = joinpath.(
hypre_include_dir,
[
"HYPRE.h",
"HYPRE_IJ_mv.h",
"HYPRE_parcsr_mv.h",
"HYPRE_parcsr_ls.h",
]
)
ctx = create_context(headers, args, options)

6
gen/prologue.jl

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
using MPI: MPI, MPI_Comm
if isdefined(MPI, :API) # MPI >= 0.20.0
if isdefined(MPI, :API)
# MPI >= 0.20.0
using MPI.API: MPI_INT, MPI_DOUBLE
else # MPI < 0.20.0
else
# MPI < 0.20.0
using MPI: MPI_INT, MPI_DOUBLE
end

3
gen/solver_options.jl

@ -5,7 +5,7 @@ function generate_options(io, structname, prefixes...) @@ -5,7 +5,7 @@ function generate_options(io, structname, prefixes...)
println(io, "function Internals.set_options(solver::$(structname), kwargs)")
println(io, " for (k, v) in kwargs")
ns = Tuple{Symbol,String}[]
ns = Tuple{Symbol, String}[]
for prefix in prefixes, n in names(LibHYPRE)
r = Regex("^" * prefix * "([A-Z].*)\$")
if (m = match(r, string(n)); m !== nothing)
@ -43,6 +43,7 @@ function generate_options(io, structname, prefixes...) @@ -43,6 +43,7 @@ function generate_options(io, structname, prefixes...)
println(io, " end")
println(io, " end")
println(io, "end")
return
end
open(joinpath(@__DIR__, "..", "src", "solver_options.jl"), "w") do io

1752
lib/LibHYPRE.jl

File diff suppressed because it is too large Load Diff

15
src/HYPRE.jl

@ -25,7 +25,7 @@ initialized. @@ -25,7 +25,7 @@ initialized.
**Note**: This function *must* be called before using HYPRE functions.
"""
function Init(; finalize_atexit=true)
function Init(; finalize_atexit = true)
if !(MPI.Initialized())
MPI.Init()
end
@ -65,8 +65,11 @@ end @@ -65,8 +65,11 @@ end
Base.unsafe_convert(::Type{HYPRE_IJMatrix}, A::HYPREMatrix) = A.ijmatrix
Base.unsafe_convert(::Type{HYPRE_ParCSRMatrix}, A::HYPREMatrix) = A.parmatrix
function HYPREMatrix(comm::MPI.Comm, ilower::Integer, iupper::Integer,
jlower::Integer=ilower, jupper::Integer=iupper)
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)
ijmatrix_ref = Ref{HYPRE_IJMatrix}(C_NULL)
@ -191,6 +194,7 @@ function Internals.check_n_rows(A, ilower, iupper) @@ -191,6 +194,7 @@ function Internals.check_n_rows(A, ilower, iupper)
if size(A, 1) != (iupper - ilower + 1)
throw(ArgumentError("number of rows in matrix does not match global start/end rows ilower and iupper"))
end
return
end
function Internals.to_hypre_data(x::Vector, ilower, iupper)
@ -209,8 +213,9 @@ function HYPREVector(comm::MPI.Comm, x::Vector, ilower, iupper) @@ -209,8 +213,9 @@ function HYPREVector(comm::MPI.Comm, x::Vector, ilower, iupper)
return b
end
HYPREVector(x::Vector, ilower=1, iupper=length(x)) =
HYPREVector(MPI.COMM_SELF, x, ilower, iupper)
function HYPREVector(x::Vector, ilower = 1, iupper = length(x))
return HYPREVector(MPI.COMM_SELF, x, ilower, iupper)
end
# TODO: Other eltypes could be support by using a intermediate buffer
function Base.copy!(dst::Vector{HYPRE_Complex}, src::HYPREVector)

3
src/LibHYPRE.jl

@ -80,7 +80,7 @@ macro check(arg) @@ -80,7 +80,7 @@ macro check(arg)
end
# Export everything with HYPRE_ prefix
for name in names(@__MODULE__; all=true)
for name in names(@__MODULE__; all = true)
if startswith(string(name), "HYPRE_")
@eval export $name
end
@ -92,6 +92,7 @@ function __init__() @@ -92,6 +92,7 @@ function __init__()
patch_ref = Ref{HYPRE_Int}(-1)
@check HYPRE_VersionNumber(major_ref, minor_ref, patch_ref, C_NULL)
global VERSION = VersionNumber(major_ref[], minor_ref[], patch_ref[])
return
end
end

8
src/solver_options.jl

@ -29,6 +29,7 @@ function Internals.set_options(solver::BiCGSTAB, kwargs) @@ -29,6 +29,7 @@ function Internals.set_options(solver::BiCGSTAB, kwargs)
throw(ArgumentError("unknown option $k for HYPRE.BiCGSTAB"))
end
end
return
end
function Internals.set_options(solver::BoomerAMG, kwargs)
@ -285,6 +286,7 @@ function Internals.set_options(solver::BoomerAMG, kwargs) @@ -285,6 +286,7 @@ function Internals.set_options(solver::BoomerAMG, kwargs)
throw(ArgumentError("unknown option $k for HYPRE.BoomerAMG"))
end
end
return
end
function Internals.set_options(solver::FlexGMRES, kwargs)
@ -314,6 +316,7 @@ function Internals.set_options(solver::FlexGMRES, kwargs) @@ -314,6 +316,7 @@ function Internals.set_options(solver::FlexGMRES, kwargs)
throw(ArgumentError("unknown option $k for HYPRE.FlexGMRES"))
end
end
return
end
function Internals.set_options(solver::GMRES, kwargs)
@ -347,6 +350,7 @@ function Internals.set_options(solver::GMRES, kwargs) @@ -347,6 +350,7 @@ function Internals.set_options(solver::GMRES, kwargs)
throw(ArgumentError("unknown option $k for HYPRE.GMRES"))
end
end
return
end
function Internals.set_options(solver::Hybrid, kwargs)
@ -456,6 +460,7 @@ function Internals.set_options(solver::Hybrid, kwargs) @@ -456,6 +460,7 @@ function Internals.set_options(solver::Hybrid, kwargs)
throw(ArgumentError("unknown option $k for HYPRE.Hybrid"))
end
end
return
end
function Internals.set_options(solver::ILU, kwargs)
@ -490,6 +495,7 @@ function Internals.set_options(solver::ILU, kwargs) @@ -490,6 +495,7 @@ function Internals.set_options(solver::ILU, kwargs)
throw(ArgumentError("unknown option $k for HYPRE.ILU"))
end
end
return
end
function Internals.set_options(solver::ParaSails, kwargs)
@ -510,6 +516,7 @@ function Internals.set_options(solver::ParaSails, kwargs) @@ -510,6 +516,7 @@ function Internals.set_options(solver::ParaSails, kwargs)
throw(ArgumentError("unknown option $k for HYPRE.ParaSails"))
end
end
return
end
function Internals.set_options(solver::PCG, kwargs)
@ -547,4 +554,5 @@ function Internals.set_options(solver::PCG, kwargs) @@ -547,4 +554,5 @@ function Internals.set_options(solver::PCG, kwargs)
throw(ArgumentError("unknown option $k for HYPRE.PCG"))
end
end
return
end

19
src/solvers.jl

@ -17,6 +17,7 @@ function Internals.safe_finalizer(Destroy, solver) @@ -17,6 +17,7 @@ function Internals.safe_finalizer(Destroy, solver)
s.solver = C_NULL
end
end
return
end
# Defining unsafe_convert enables ccall to automatically convert solver::HYPRESolver to
@ -71,8 +72,8 @@ Create a `BiCGSTAB` solver. See HYPRE API reference for details and supported se @@ -71,8 +72,8 @@ Create a `BiCGSTAB` solver. See HYPRE API reference for details and supported se
mutable struct BiCGSTAB <: HYPRESolver
comm::MPI.Comm
solver::HYPRE_Solver
precond::Union{HYPRESolver,Nothing}
function BiCGSTAB(comm::MPI.Comm=MPI.COMM_NULL; kwargs...)
precond::Union{HYPRESolver, Nothing}
function BiCGSTAB(comm::MPI.Comm = MPI.COMM_NULL; kwargs...)
# comm defaults to COMM_NULL since it is unused in HYPRE_ParCSRBiCGSTABCreate
solver = new(comm, C_NULL, nothing)
solver_ref = Ref{HYPRE_Solver}(C_NULL)
@ -166,8 +167,8 @@ Create a `FlexGMRES` solver. See HYPRE API reference for details and supported s @@ -166,8 +167,8 @@ Create a `FlexGMRES` solver. See HYPRE API reference for details and supported s
mutable struct FlexGMRES <: HYPRESolver
comm::MPI.Comm
solver::HYPRE_Solver
precond::Union{HYPRESolver,Nothing}
function FlexGMRES(comm::MPI.Comm=MPI.COMM_NULL; kwargs...)
precond::Union{HYPRESolver, Nothing}
function FlexGMRES(comm::MPI.Comm = MPI.COMM_NULL; kwargs...)
# comm defaults to COMM_NULL since it is unused in HYPRE_ParCSRFlexGMRESCreate
solver = new(comm, C_NULL, nothing)
solver_ref = Ref{HYPRE_Solver}(C_NULL)
@ -251,8 +252,8 @@ Create a `GMRES` solver. See HYPRE API reference for details and supported setti @@ -251,8 +252,8 @@ Create a `GMRES` solver. See HYPRE API reference for details and supported setti
mutable struct GMRES <: HYPRESolver
comm::MPI.Comm
solver::HYPRE_Solver
precond::Union{HYPRESolver,Nothing}
function GMRES(comm::MPI.Comm=MPI.COMM_NULL; kwargs...)
precond::Union{HYPRESolver, Nothing}
function GMRES(comm::MPI.Comm = MPI.COMM_NULL; kwargs...)
# comm defaults to COMM_NULL since it is unused in HYPRE_ParCSRGMRESCreate
solver = new(comm, C_NULL, nothing)
solver_ref = Ref{HYPRE_Solver}(C_NULL)
@ -299,7 +300,7 @@ Create a `Hybrid` solver. See HYPRE API reference for details and supported sett @@ -299,7 +300,7 @@ Create a `Hybrid` solver. See HYPRE API reference for details and supported sett
"""
mutable struct Hybrid <: HYPRESolver
solver::HYPRE_Solver
precond::Union{HYPRESolver,Nothing}
precond::Union{HYPRESolver, Nothing}
function Hybrid(; kwargs...)
solver = new(C_NULL, nothing)
solver_ref = Ref{HYPRE_Solver}(C_NULL)
@ -396,7 +397,7 @@ settings. @@ -396,7 +397,7 @@ settings.
mutable struct ParaSails <: HYPRESolver
comm::MPI.Comm
solver::HYPRE_Solver
function ParaSails(comm::MPI.Comm=MPI.COMM_WORLD; kwargs...)
function ParaSails(comm::MPI.Comm = MPI.COMM_WORLD; kwargs...)
# Note: comm is used in this solver so default to COMM_WORLD
solver = new(comm, C_NULL)
solver_ref = Ref{HYPRE_Solver}(C_NULL)
@ -432,7 +433,7 @@ mutable struct PCG <: HYPRESolver @@ -432,7 +433,7 @@ mutable struct PCG <: HYPRESolver
comm::MPI.Comm
solver::HYPRE_Solver
precond::Union{HYPRESolver, Nothing}
function PCG(comm::MPI.Comm=MPI.COMM_NULL; kwargs...)
function PCG(comm::MPI.Comm = MPI.COMM_NULL; kwargs...)
# comm defaults to COMM_NULL since it is unused in HYPRE_ParCSRPCGCreate
solver = new(comm, C_NULL, nothing)
solver_ref = Ref{HYPRE_Solver}(C_NULL)

119
test/runtests.jl

@ -31,11 +31,10 @@ end @@ -31,11 +31,10 @@ end
@testset "HYPREMatrix(::SparseMatrixCS(C|R))" begin
ilower, iupper = 4, 6
CSC = convert(SparseMatrixCSC{HYPRE_Complex, HYPRE_Int}, sparse([
1 2 0 0 3
0 4 0 5 0
0 6 7 0 8
]))
CSC = convert(
SparseMatrixCSC{HYPRE_Complex, HYPRE_Int},
sparse([1 2 0 0 3; 0 4 0 5 0; 0 6 7 0 8])
)
CSR = sparsecsr(findnz(CSC)..., size(CSC)...)
@test CSC == CSR
csc = Internals.to_hypre_data(CSC, ilower, iupper)
@ -52,8 +51,8 @@ end @@ -52,8 +51,8 @@ end
@test csr[5] == CSR.nzval
@test_broken csr[5]::Vector{HYPRE_Complex} === CSR.nzval
@test_throws ArgumentError Internals.to_hypre_data(CSC, ilower, iupper-1)
@test_throws ArgumentError Internals.to_hypre_data(CSR, ilower, iupper+1)
@test_throws ArgumentError Internals.to_hypre_data(CSC, ilower, iupper - 1)
@test_throws ArgumentError Internals.to_hypre_data(CSR, ilower, iupper + 1)
ilower, iupper = 6, 10
CSC = sprand(5, 10, 0.3)
@ -70,7 +69,7 @@ end @@ -70,7 +69,7 @@ end
H = HYPREMatrix(CSR, ilower, iupper)
@test H.ijmatrix != HYPRE_IJMatrix(C_NULL)
@test H.parmatrix != 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.parmatrix != HYPRE_ParCSRMatrix(C_NULL)
@ -183,7 +182,6 @@ end @@ -183,7 +182,6 @@ end
end
@testset "HYPREVector" begin
h = HYPREVector(MPI.COMM_WORLD, 1, 5)
@test h.ijvector != HYPRE_IJVector(C_NULL)
@ -283,7 +281,7 @@ end @@ -283,7 +281,7 @@ end
@test H === H′
pbc = similar(pb)
copy!(pbc, H)
@test pbc == 2*pb
@test pbc == 2 * pb
end
end
@ -360,16 +358,16 @@ end @@ -360,16 +358,16 @@ end
b_h = HYPREVector(b)
x_h = HYPREVector(x)
# Solve
tol = 1e-9
tol = 1.0e-9
bicg = HYPRE.BiCGSTAB(; Tol = tol)
HYPRE.solve!(bicg, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(bicg, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test solver queries
@test HYPRE.GetFinalRelativeResidualNorm(bicg) < tol
@test HYPRE.GetNumIterations(bicg) > 0
@ -381,11 +379,11 @@ end @@ -381,11 +379,11 @@ end
HYPRE.solve!(bicg, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(bicg, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
# Tests Internals.set_precond_defaults for BoomerAMG
precond = HYPRE.BoomerAMG()
bicg = HYPRE.BiCGSTAB(; Tol = tol, Precond = precond)
@ -393,7 +391,7 @@ end @@ -393,7 +391,7 @@ end
HYPRE.solve!(bicg, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
end
@testset "BoomerAMG" begin
@ -407,11 +405,11 @@ end @@ -407,11 +405,11 @@ end
for i in 1:99
k = (1 + rand()) * [1.0 -1.0; -1.0 1.0]
append!(V, k)
append!(I, [i, i+1, i, i+1]) # rows
append!(J, [i, i, i+1, i+1]) # cols
append!(I, [i, i + 1, i, i + 1]) # rows
append!(J, [i, i, i + 1, i + 1]) # cols
end
A = sparse(I, J, V)
A[:, 1] .= 0; A[1, :] .= 0; A[:, end] .= 0; A[end, :] .= 0;
A[:, 1] .= 0; A[1, :] .= 0; A[:, end] .= 0; A[end, :] .= 0
A[1, 1] = 2; A[end, end] = 2
@test isposdef(A)
b = rand(100)
@ -421,7 +419,7 @@ end @@ -421,7 +419,7 @@ end
b_h = HYPREVector(b, ilower, iupper)
x_h = HYPREVector(b, ilower, iupper)
# Solve
tol = 1e-9
tol = 1.0e-9
amg = HYPRE.BoomerAMG(; Tol = tol)
HYPRE.solve!(amg, x_h, A_h, b_h)
copy!(x, x_h)
@ -451,16 +449,16 @@ end @@ -451,16 +449,16 @@ end
b_h = HYPREVector(b)
x_h = HYPREVector(x)
# Solve
tol = 1e-9
tol = 1.0e-9
gmres = HYPRE.FlexGMRES(; Tol = tol)
HYPRE.solve!(gmres, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(gmres, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test solver queries
@test HYPRE.GetFinalRelativeResidualNorm(gmres) < tol
@test HYPRE.GetNumIterations(gmres) > 0
@ -472,11 +470,11 @@ end @@ -472,11 +470,11 @@ end
HYPRE.solve!(gmres, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(gmres, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
end
@ -494,16 +492,16 @@ end @@ -494,16 +492,16 @@ end
b_h = HYPREVector(b)
x_h = HYPREVector(x)
# Solve
tol = 1e-9
tol = 1.0e-9
gmres = HYPRE.GMRES(; Tol = tol)
HYPRE.solve!(gmres, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(gmres, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test solver queries
@test HYPRE.GetFinalRelativeResidualNorm(gmres) < tol
@test HYPRE.GetNumIterations(gmres) > 0
@ -515,11 +513,11 @@ end @@ -515,11 +513,11 @@ end
HYPRE.solve!(gmres, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(gmres, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
end
@testset "Hybrid" begin
@ -536,16 +534,16 @@ end @@ -536,16 +534,16 @@ end
b_h = HYPREVector(b)
x_h = HYPREVector(x)
# Solve
tol = 1e-9
tol = 1.0e-9
hybrid = HYPRE.Hybrid(; Tol = tol)
HYPRE.solve!(hybrid, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(hybrid, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test solver queries
@test HYPRE.GetFinalRelativeResidualNorm(hybrid) < tol
@test HYPRE.GetNumIterations(hybrid) > 0
@ -557,11 +555,11 @@ end @@ -557,11 +555,11 @@ end
HYPRE.solve!(hybrid, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(hybrid, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
end
@ -579,16 +577,16 @@ end @@ -579,16 +577,16 @@ end
b_h = HYPREVector(b)
x_h = HYPREVector(x)
# Solve
tol = 1e-9
tol = 1.0e-9
ilu = HYPRE.ILU(; Tol = tol)
HYPRE.solve!(ilu, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(ilu, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test solver queries
@test HYPRE.GetFinalRelativeResidualNorm(ilu) < tol
@test HYPRE.GetNumIterations(ilu) > 0
@ -600,11 +598,11 @@ end @@ -600,11 +598,11 @@ end
HYPRE.solve!(pcg, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(pcg, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
end
@ -623,13 +621,13 @@ end @@ -623,13 +621,13 @@ end
b_h = HYPREVector(b, ilower, iupper)
x_h = HYPREVector(b, ilower, iupper)
# Solve with ParaSails as preconditioner
tol = 1e-9
tol = 1.0e-9
parasails = HYPRE.ParaSails()
pcg = HYPRE.PCG(; Tol = tol, Precond = parasails)
HYPRE.solve!(pcg, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test solver queries (should error)
@test_throws ArgumentError("cannot get residual norm for HYPRE.ParaSails") HYPRE.GetFinalRelativeResidualNorm(parasails)
@test_throws ArgumentError("cannot get number of iterations for HYPRE.ParaSails") HYPRE.GetNumIterations(parasails)
@ -650,16 +648,16 @@ end @@ -650,16 +648,16 @@ end
b_h = HYPREVector(b, ilower, iupper)
x_h = HYPREVector(b, ilower, iupper)
# Solve
tol = 1e-9
tol = 1.0e-9
pcg = HYPRE.PCG(; Tol = tol)
HYPRE.solve!(pcg, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(pcg, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test solver queries
@test HYPRE.GetFinalRelativeResidualNorm(pcg) < tol
@test HYPRE.GetNumIterations(pcg) > 0
@ -671,11 +669,11 @@ end @@ -671,11 +669,11 @@ end
HYPRE.solve!(pcg, x_h, A_h, b_h)
copy!(x, x_h)
# Test result with direct solver
@test x A \ b atol=tol
@test x A \ b atol = tol
# Test without passing initial guess
x_h = HYPRE.solve(pcg, A_h, b_h)
copy!(x, x_h)
@test x A \ b atol=tol
@test x A \ b atol = tol
end
function topartitioned(x::Vector, A::SparseMatrixCSC, b::Vector, backend)
@ -713,18 +711,18 @@ end @@ -713,18 +711,18 @@ end
end
# Solve
tol = 1e-9
tol = 1.0e-9
pcg = HYPRE.PCG(; Tol = tol)
## solve!
HYPRE.solve!(pcg, x_p, A_p, b_p)
ref = A\b
ref = A \ b
map(local_values(x_p)) do x
@test x ref atol=tol
@test x ref atol = tol
end
## solve
x_p = HYPRE.solve(pcg, A_p, b_p)
map(local_values(x_p)) do x
@test x ref atol=tol
@test x ref atol = tol
end
end
end
@ -737,24 +735,27 @@ end @@ -737,24 +735,27 @@ end
xcsc = zeros(100)
xcsr = zeros(100)
# Solve
tol = 1e-9
tol = 1.0e-9
pcg = HYPRE.PCG(; Tol = tol)
## solve!
HYPRE.solve!(pcg, xcsc, CSC, b)
@test xcsc CSC \ b atol=tol
@test xcsc CSC \ b atol = tol
HYPRE.solve!(pcg, xcsr, CSR, b)
@test xcsr CSC \ b atol=tol # TODO: CSR \ b fails
@test xcsr CSC \ b atol = tol # TODO: CSR \ b fails
## solve
xcsc = HYPRE.solve(pcg, CSC, b)
@test xcsc CSC \ b atol=tol
@test xcsc CSC \ b atol = tol
xcsr = HYPRE.solve(pcg, CSR, b)
@test xcsr CSC \ b atol=tol # TODO: CSR \ b fails
@test xcsr CSC \ b atol = tol # TODO: CSR \ b fails
end
@testset "MPI execution" begin
testfiles = joinpath.(@__DIR__, [
"test_assembler.jl",
])
testfiles = joinpath.(
@__DIR__,
[
"test_assembler.jl",
]
)
for file in testfiles
r = run(ignorestatus(`$(mpiexec()) -n 2 $(Base.julia_cmd()) $(file)`))
@test r.exitcode == 0

10
test/test_assembler.jl

@ -30,11 +30,13 @@ end @@ -30,11 +30,13 @@ end
function values_and_indices(n)
idx = [n - 1, n, n + 1]
a = Float64[
n -2n -n
-2n n -2n
-n -2n n
# runic: off
n -2n -n
-2n n -2n
-n -2n n
# runic: on
]
b = Float64[n, n/2, n/3]
b = Float64[n, n / 2, n / 3]
return idx, a, b
end

Loading…
Cancel
Save