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 2 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 @@ -191,6 +191,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand All @@ -208,6 +209,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 = ktimer(start_time)
stats.status = "Breakdown bᴴc = 0"
solver.warm_start = false
Expand Down Expand Up @@ -281,6 +283,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 = ktimer(start_time)
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 @@ -185,6 +185,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand All @@ -200,6 +201,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 = ktimer(start_time)
stats.status = "Breakdown bᴴc = 0"
solver.warm_start = false
Expand Down Expand Up @@ -414,6 +416,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 = ktimer(start_time)
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 @@ -187,6 +187,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 = ktimer(start_time)
stats.status = "Breakdown bᴴc = 0"
solver.warm_start = false
Expand Down Expand Up @@ -489,6 +490,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 = ktimer(start_time)
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 @@ -351,6 +351,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 = ktimer(start_time)
stats.status = status
return solver
Expand Down
32 changes: 22 additions & 10 deletions src/block_krylov_solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ for (KS, fun, nsol, nA, nAt, warm_start) in [
end

function ksizeof(attribute)
if isa(attribute, Vector{<:AbstractVector}) && !isempty(attribute)
if isa(attribute, Vector) && isa(eltype(attribute), Vector) && !isempty(attribute)
# A vector of vectors 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])
Expand All @@ -109,16 +109,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 @@ -184,6 +184,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand Down Expand Up @@ -259,6 +260,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 = ktimer(start_time)
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 @@ -169,6 +169,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand Down Expand Up @@ -272,6 +273,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 = ktimer(start_time)
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 @@ -168,6 +168,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand Down Expand Up @@ -268,6 +269,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 = ktimer(start_time)
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 @@ -158,6 +158,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
return solver
Expand Down Expand Up @@ -277,6 +278,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 = ktimer(start_time)
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 @@ -162,6 +162,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
history && push!(rNorms, zero(T))
Expand Down Expand Up @@ -238,6 +239,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 = ktimer(start_time)
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 @@ -169,6 +169,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
return solver
Expand Down Expand Up @@ -247,6 +248,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 = ktimer(start_time)
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 @@ -186,6 +186,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand All @@ -197,6 +198,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 = ktimer(start_time)
stats.status = "Breakdown bᴴc = 0"
solver.warm_start =false
Expand Down Expand Up @@ -285,6 +287,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 = ktimer(start_time)
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 @@ -180,6 +180,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
history && push!(ArNorms, zero(T))
Expand Down Expand Up @@ -223,6 +224,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 = ktimer(start_time)
stats.status = "nonpositive curvature"
return solver
Expand Down Expand Up @@ -388,6 +390,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 = ktimer(start_time)
stats.status = "solver encountered numerical issues"
solver.warm_start = false
Expand Down Expand Up @@ -418,6 +421,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 = ktimer(start_time)
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 @@ -220,6 +220,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
return solver
Expand Down Expand Up @@ -400,6 +401,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 = ktimer(start_time)
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 @@ -207,6 +207,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
return solver
Expand Down Expand Up @@ -235,6 +236,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 = ktimer(start_time)
stats.status = "x = 0 is a minimum least-squares solution"
return solver
Expand Down Expand Up @@ -392,6 +394,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 = ktimer(start_time)
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 @@ -157,6 +157,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
history && push!(ArNorms, zero(T))
Expand Down Expand Up @@ -263,6 +264,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 = ktimer(start_time)
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 @@ -168,6 +168,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
history && push!(ArNorms, zero(T))
Expand Down Expand Up @@ -239,6 +240,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 = ktimer(start_time)
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 @@ -175,6 +175,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 = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand Down Expand Up @@ -332,6 +333,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 = ktimer(start_time)
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/dqgmres.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ kwargs_dqgmres = (:M, :N, :ldiv, :reorthogonalization, :atol, :rtol, :itmax, :ti
if rNorm == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand Down Expand Up @@ -334,6 +335,7 @@ kwargs_dqgmres = (:M, :N, :ldiv, :reorthogonalization, :atol, :rtol, :itmax, :ti
stats.niter = iter
stats.solved = solved
stats.inconsistent = false
stats.storage = sizeof(solver)
stats.timer = ktimer(start_time)
stats.status = status
return solver
Expand Down
2 changes: 2 additions & 0 deletions src/fgmres.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ kwargs_fgmres = (:M, :N, :ldiv, :restart, :reorthogonalization, :atol, :rtol, :i
if β == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.storage = sizeof(solver)
stats.timer = ktimer(start_time)
stats.status = "x = 0 is a zero-residual solution"
solver.warm_start = false
Expand Down Expand Up @@ -384,6 +385,7 @@ kwargs_fgmres = (:M, :N, :ldiv, :restart, :reorthogonalization, :atol, :rtol, :i
stats.niter = iter
stats.solved = solved
stats.inconsistent = inconsistent
stats.storage = sizeof(solver)
stats.timer = ktimer(start_time)
stats.status = status
return solver
Expand Down
Loading
Loading