Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display storage allocated in the stats #867

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/bicgstab.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ kwargs_bicgstab = (:c, :M, :N, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose,
if rNorm == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand All @@ -187,6 +188,7 @@ kwargs_bicgstab = (:c, :M, :N, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose,
if next_ρ == 0
stats.niter = 0
stats.solved, stats.inconsistent = false, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "Breakdown bᴴc = 0"
solver.warm_start = false
Expand Down Expand Up @@ -260,6 +262,7 @@ kwargs_bicgstab = (:c, :M, :N, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose,
stats.niter = iter
stats.solved = solved
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
3 changes: 3 additions & 0 deletions src/bilq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ kwargs_bilq = (:c, :transfer_to_bicg, :M, :N, :ldiv, :atol, :rtol, :itmax, :time
stats.niter = 0
stats.solved = true
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand All @@ -179,6 +180,7 @@ kwargs_bilq = (:c, :transfer_to_bicg, :M, :N, :ldiv, :atol, :rtol, :itmax, :time
stats.niter = 0
stats.solved = false
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "Breakdown bᴴc = 0"
solver.warm_start = false
Expand Down Expand Up @@ -393,6 +395,7 @@ kwargs_bilq = (:c, :transfer_to_bicg, :M, :N, :ldiv, :atol, :rtol, :itmax, :time
stats.niter = iter
stats.solved = solved_lq || solved_cg
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/bilqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ kwargs_bilqr = (:transfer_to_bicg, :atol, :rtol, :itmax, :timemax, :verbose, :hi
stats.niter = 0
stats.solved_primal = false
stats.solved_dual = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "Breakdown bᴴc = 0"
solver.warm_start = false
Expand Down Expand Up @@ -468,6 +469,7 @@ kwargs_bilqr = (:transfer_to_bicg, :atol, :rtol, :itmax, :timemax, :verbose, :hi
stats.niter = iter
stats.solved_primal = solved_primal
stats.solved_dual = solved_dual
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
1 change: 1 addition & 0 deletions src/block_gmres.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ kwargs_block_gmres = (:M, :N, :ldiv, :restart, :reorthogonalization, :atol, :rto
# Update stats
stats.niter = iter
stats.solved = solved
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
36 changes: 24 additions & 12 deletions src/block_krylov_solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function BlockGmresSolver(m, n, p, memory, SV, SM)
H = SM[SM(undef, 2p, p) for i = 1 : memory]
τ = SV[SV(undef, p) for i = 1 : memory]
tmp = C isa Matrix ? SM(undef, 0, 0) : SM(undef, p, p)
stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown")
stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown")
solver = BlockGmresSolver{T,FC,SV,SM}(m, n, p, ΔX, X, W, P, Q, C, D, V, Z, R, H, τ, tmp, false, stats)
return solver
end
Expand Down Expand Up @@ -103,8 +103,8 @@ for (KS, fun, nsol, nA, nAt, warm_start) in [
end

function ksizeof(attribute)
if isa(attribute, Vector{<:AbstractVector}) && !isempty(attribute)
# A vector of vectors is a vector of pointers in Julia.
if isa(attribute, Vector) && !isempty(attribute)
# A vector of arrays is a vector of pointers in Julia.
# All vectors inside a vector have the same size in Krylov.jl
size_attribute = sizeof(attribute) + length(attribute) * ksizeof(attribute[1])
else
Expand All @@ -113,16 +113,28 @@ function ksizeof(attribute)
return size_attribute
end

function sizeof(stats_solver :: Union{KrylovStats, KrylovSolver, BlockKrylovSolver})
type = typeof(stats_solver)
nfields = fieldcount(type)
storage = 0
for i = 1:nfields
field_i = getfield(stats_solver, i)
size_i = ksizeof(field_i)
storage += size_i
# function sizeof(stats_solver :: Union{KrylovStats, KrylovSolver, BlockKrylovSolver})
# type = typeof(stats_solver)
# nfields = fieldcount(type)
# storage::Int = 0
# for i = 1:nfields
# field_name = fieldname(type, i)
# field_type::DataType = fieldtype(type, field_name)
# field = getfield(stats_solver, field_name)
# storage += ksizeof(field)::Int
# end
# return storage
# end

@generated function Base.sizeof(stats_solver::T) where T <: Union{KrylovStats, KrylovSolver, BlockKrylovSolver}
nfields = fieldcount(T)
quote
storage = 0
Base.Cartesian.@nexprs $nfields i -> begin
storage += ksizeof(getfield(stats_solver, i))
end
return storage
end
return storage
end

"""
Expand Down
2 changes: 2 additions & 0 deletions src/car.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ kwargs_car = (:M, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose, :history, :ca
if rNorm == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand Down Expand Up @@ -239,6 +240,7 @@ kwargs_car = (:M, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose, :history, :ca
stats.niter = iter
stats.solved = solved
stats.inconsistent = inconsistent
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/cg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ kwargs_cg = (:M, :ldiv, :radius, :linesearch, :atol, :rtol, :itmax, :timemax, :v
if γ == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand Down Expand Up @@ -257,6 +258,7 @@ kwargs_cg = (:M, :ldiv, :radius, :linesearch, :atol, :rtol, :itmax, :timemax, :v
stats.niter = iter
stats.solved = solved
stats.inconsistent = inconsistent
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/cg_lanczos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ kwargs_cg_lanczos = (:M, :ldiv, :check_curvature, :atol, :rtol, :itmax, :timemax
stats.solved = true
stats.Anorm = zero(T)
stats.indefinite = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand Down Expand Up @@ -247,6 +248,7 @@ kwargs_cg_lanczos = (:M, :ldiv, :check_curvature, :atol, :rtol, :itmax, :timemax
stats.solved = solved
stats.Anorm = sqrt(Anorm2)
stats.indefinite = indefinite
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/cg_lanczos_shift.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ kwargs_cg_lanczos_shift = (:M, :ldiv, :check_curvature, :atol, :rtol, :itmax, :t
if β == 0
stats.niter = 0
stats.solved = true
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
return solver
Expand Down Expand Up @@ -267,6 +268,7 @@ kwargs_cg_lanczos_shift = (:M, :ldiv, :check_curvature, :atol, :rtol, :itmax, :t
# Update stats. TODO: Estimate Anorm and Acond.
stats.niter = iter
stats.solved = solved
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/cgls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ kwargs_cgls = (:M, :ldiv, :radius, :λ, :atol, :rtol, :itmax, :timemax, :verbose
if bNorm == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
history && push!(rNorms, zero(T))
Expand Down Expand Up @@ -228,6 +229,7 @@ kwargs_cgls = (:M, :ldiv, :radius, :λ, :atol, :rtol, :itmax, :timemax, :verbose
stats.niter = iter
stats.solved = solved
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/cgls_lanczos_shift.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ kwargs_cgls_lanczos_shift = (:M, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose
if β == 0
stats.niter = 0
stats.solved = true
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
return solver
Expand Down Expand Up @@ -261,6 +262,7 @@ kwargs_cgls_lanczos_shift = (:M, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose
# Update stats
stats.niter = iter
stats.solved = solved
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/cgne.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ kwargs_cgne = (:N, :ldiv, :λ, :atol, :rtol, :itmax, :timemax, :verbose, :histor
if rNorm == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
return solver
Expand Down Expand Up @@ -237,6 +238,7 @@ kwargs_cgne = (:N, :ldiv, :λ, :atol, :rtol, :itmax, :timemax, :verbose, :histor
stats.niter = iter
stats.solved = solved
stats.inconsistent = inconsistent
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
3 changes: 3 additions & 0 deletions src/cgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ kwargs_cgs = (:c, :M, :N, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose, :hist
if rNorm == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand All @@ -176,6 +177,7 @@ kwargs_cgs = (:c, :M, :N, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose, :hist
if ρ == 0
stats.niter = 0
stats.solved, stats.inconsistent = false, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "Breakdown bᴴc = 0"
solver.warm_start =false
Expand Down Expand Up @@ -264,6 +266,7 @@ kwargs_cgs = (:c, :M, :N, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose, :hist
stats.niter = iter
stats.solved = solved
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
4 changes: 4 additions & 0 deletions src/cr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ kwargs_cr = (:M, :ldiv, :radius, :linesearch, :γ, :atol, :rtol, :itmax, :timema
if ρ == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
history && push!(ArNorms, zero(T))
Expand Down Expand Up @@ -202,6 +203,7 @@ kwargs_cr = (:M, :ldiv, :radius, :linesearch, :γ, :atol, :rtol, :itmax, :timema
(verbose > 0) && @printf(iostream, "nonpositive curvature detected: pᴴAp = %8.1e and rᴴAr = %8.1e\n", pAp, ρ)
stats.solved = solved
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "nonpositive curvature"
return solver
Expand Down Expand Up @@ -367,6 +369,7 @@ kwargs_cr = (:M, :ldiv, :radius, :linesearch, :γ, :atol, :rtol, :itmax, :timema
stats.niter = iter
stats.solved = solved
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "solver encountered numerical issues"
solver.warm_start = false
Expand Down Expand Up @@ -397,6 +400,7 @@ kwargs_cr = (:M, :ldiv, :radius, :linesearch, :γ, :atol, :rtol, :itmax, :timema
stats.niter = iter
stats.solved = solved
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/craig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ kwargs_craig = (:M, :N, :ldiv, :transfer_to_lsqr, :sqd, :λ, :btol, :conlim, :at
if β₁ == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
return solver
Expand Down Expand Up @@ -390,6 +391,7 @@ kwargs_craig = (:M, :N, :ldiv, :transfer_to_lsqr, :sqd, :λ, :btol, :conlim, :at
stats.niter = iter
stats.solved = solved
stats.inconsistent = inconsistent
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
3 changes: 3 additions & 0 deletions src/craigmr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ kwargs_craigmr = (:M, :N, :ldiv, :sqd, :λ, :atol, :rtol, :itmax, :timemax, :ver
stats.solved, stats.inconsistent = true, false
history && push!(rNorms, β)
history && push!(ArNorms, zero(T))
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
return solver
Expand Down Expand Up @@ -225,6 +226,7 @@ kwargs_craigmr = (:M, :N, :ldiv, :sqd, :λ, :atol, :rtol, :itmax, :timemax, :ver
stats.solved, stats.inconsistent = true, false
history && push!(rNorms, β)
history && push!(ArNorms, zero(T))
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a minimum least-squares solution"
return solver
Expand Down Expand Up @@ -382,6 +384,7 @@ kwargs_craigmr = (:M, :N, :ldiv, :sqd, :λ, :atol, :rtol, :itmax, :timemax, :ver
stats.niter = iter
stats.solved = solved
stats.inconsistent = inconsistent
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/crls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ kwargs_crls = (:M, :ldiv, :radius, :λ, :atol, :rtol, :itmax, :timemax, :verbose
if bNorm == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
history && push!(ArNorms, zero(T))
Expand Down Expand Up @@ -253,6 +254,7 @@ kwargs_crls = (:M, :ldiv, :radius, :λ, :atol, :rtol, :itmax, :timemax, :verbose
stats.niter = iter
stats.solved = solved
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/crmr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ kwargs_crmr = (:N, :ldiv, :λ, :atol, :rtol, :itmax, :timemax, :verbose, :histor
if bNorm == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
history && push!(ArNorms, zero(T))
Expand Down Expand Up @@ -229,6 +230,7 @@ kwargs_crmr = (:N, :ldiv, :λ, :atol, :rtol, :itmax, :timemax, :verbose, :histor
stats.niter = iter
stats.solved = solved
stats.inconsistent = inconsistent
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/diom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ kwargs_diom = (:M, :N, :ldiv, :reorthogonalization, :atol, :rtol, :itmax, :timem
if rNorm == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand Down Expand Up @@ -311,6 +312,7 @@ kwargs_diom = (:M, :N, :ldiv, :reorthogonalization, :atol, :rtol, :itmax, :timem
stats.niter = iter
stats.solved = solved
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = start_time |> ktimer
stats.status = status
return solver
Expand Down
Loading
Loading