From bd6cf258735ad6bc62fcb4f17c7fd9fdafa54a2c Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 21 May 2024 08:26:58 -0400 Subject: [PATCH] Display storage allocated in the stats --- src/bicgstab.jl | 3 ++ src/bilq.jl | 3 ++ src/bilqr.jl | 2 ++ src/block_gmres.jl | 1 + src/car.jl | 2 ++ src/cg.jl | 2 ++ src/cg_lanczos.jl | 2 ++ src/cg_lanczos_shift.jl | 2 ++ src/cgls.jl | 2 ++ src/cgls_lanczos_shift.jl | 2 ++ src/cgne.jl | 2 ++ src/cgs.jl | 3 ++ src/cr.jl | 4 +++ src/craig.jl | 2 ++ src/craigmr.jl | 3 ++ src/crls.jl | 2 ++ src/crmr.jl | 2 ++ src/diom.jl | 2 ++ src/dqgmres.jl | 2 ++ src/fgmres.jl | 2 ++ src/fom.jl | 2 ++ src/gmres.jl | 2 ++ src/gpmr.jl | 1 + src/krylov_solvers.jl | 72 +++++++++++++++++++-------------------- src/krylov_stats.jl | 32 ++++++++++++++--- src/lnlq.jl | 2 ++ src/lslq.jl | 3 ++ src/lsmr.jl | 3 ++ src/lsqr.jl | 3 ++ src/minares.jl | 2 ++ src/minres.jl | 3 ++ src/minres_qlp.jl | 2 ++ src/qmr.jl | 3 ++ src/symmlq.jl | 2 ++ src/tricg.jl | 1 + src/trilqr.jl | 1 + src/trimr.jl | 1 + src/usymlq.jl | 2 ++ src/usymqr.jl | 2 ++ test/test_stats.jl | 40 +++++++++++++--------- 40 files changed, 168 insertions(+), 56 deletions(-) diff --git a/src/bicgstab.jl b/src/bicgstab.jl index bf07c5174..719a0b1fb 100644 --- a/src/bicgstab.jl +++ b/src/bicgstab.jl @@ -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 @@ -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 @@ -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 diff --git a/src/bilq.jl b/src/bilq.jl index 5fb8f1a04..eaf953c1a 100644 --- a/src/bilq.jl +++ b/src/bilq.jl @@ -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 @@ -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 @@ -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 diff --git a/src/bilqr.jl b/src/bilqr.jl index 29b27934c..78f56108c 100644 --- a/src/bilqr.jl +++ b/src/bilqr.jl @@ -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 @@ -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 diff --git a/src/block_gmres.jl b/src/block_gmres.jl index 376193114..d19b3c1aa 100644 --- a/src/block_gmres.jl +++ b/src/block_gmres.jl @@ -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 diff --git a/src/car.jl b/src/car.jl index ee6f9a695..68f04f809 100644 --- a/src/car.jl +++ b/src/car.jl @@ -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 @@ -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 diff --git a/src/cg.jl b/src/cg.jl index 3cb8a60d9..b8d9004d2 100644 --- a/src/cg.jl +++ b/src/cg.jl @@ -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 @@ -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 diff --git a/src/cg_lanczos.jl b/src/cg_lanczos.jl index 466d06f0a..fe40aa38a 100644 --- a/src/cg_lanczos.jl +++ b/src/cg_lanczos.jl @@ -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 @@ -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 diff --git a/src/cg_lanczos_shift.jl b/src/cg_lanczos_shift.jl index ba48ef30f..0155822b6 100644 --- a/src/cg_lanczos_shift.jl +++ b/src/cg_lanczos_shift.jl @@ -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 @@ -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 diff --git a/src/cgls.jl b/src/cgls.jl index 3bf862c77..653e10df1 100644 --- a/src/cgls.jl +++ b/src/cgls.jl @@ -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)) @@ -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 diff --git a/src/cgls_lanczos_shift.jl b/src/cgls_lanczos_shift.jl index b772fde01..4348fa6a7 100644 --- a/src/cgls_lanczos_shift.jl +++ b/src/cgls_lanczos_shift.jl @@ -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 @@ -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 diff --git a/src/cgne.jl b/src/cgne.jl index e37dc2c6d..4229d1f60 100644 --- a/src/cgne.jl +++ b/src/cgne.jl @@ -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 @@ -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 diff --git a/src/cgs.jl b/src/cgs.jl index ce9ca118d..d4c76a380 100644 --- a/src/cgs.jl +++ b/src/cgs.jl @@ -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 @@ -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 @@ -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 diff --git a/src/cr.jl b/src/cr.jl index 0be5ca4f1..3a1b770ee 100644 --- a/src/cr.jl +++ b/src/cr.jl @@ -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)) @@ -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 @@ -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 @@ -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 diff --git a/src/craig.jl b/src/craig.jl index c99bad81f..5f7d9e2e2 100644 --- a/src/craig.jl +++ b/src/craig.jl @@ -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 @@ -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 diff --git a/src/craigmr.jl b/src/craigmr.jl index 7fc5a42d0..fe30b3616 100644 --- a/src/craigmr.jl +++ b/src/craigmr.jl @@ -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 @@ -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 @@ -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 diff --git a/src/crls.jl b/src/crls.jl index 5239a5cf6..60b05b7ac 100644 --- a/src/crls.jl +++ b/src/crls.jl @@ -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)) @@ -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 diff --git a/src/crmr.jl b/src/crmr.jl index f4b797d20..06614cd04 100644 --- a/src/crmr.jl +++ b/src/crmr.jl @@ -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)) @@ -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 diff --git a/src/diom.jl b/src/diom.jl index 0c201b0aa..ead8d2d10 100644 --- a/src/diom.jl +++ b/src/diom.jl @@ -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 @@ -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 diff --git a/src/dqgmres.jl b/src/dqgmres.jl index 82ef8e135..32b3c45c0 100644 --- a/src/dqgmres.jl +++ b/src/dqgmres.jl @@ -154,6 +154,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 = start_time |> ktimer stats.status = "x = 0 is a zero-residual solution" solver.warm_start = false @@ -313,6 +314,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 = start_time |> ktimer stats.status = status return solver diff --git a/src/fgmres.jl b/src/fgmres.jl index 6227909d4..244a71346 100644 --- a/src/fgmres.jl +++ b/src/fgmres.jl @@ -164,6 +164,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 = start_time |> ktimer stats.status = "x = 0 is a zero-residual solution" solver.warm_start = false @@ -363,6 +364,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 = start_time |> ktimer stats.status = status return solver diff --git a/src/fom.jl b/src/fom.jl index 27512499d..61d7a61cb 100644 --- a/src/fom.jl +++ b/src/fom.jl @@ -159,6 +159,7 @@ kwargs_fom = (:M, :N, :ldiv, :restart, :reorthogonalization, :atol, :rtol, :itma 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 @@ -343,6 +344,7 @@ kwargs_fom = (:M, :N, :ldiv, :restart, :reorthogonalization, :atol, :rtol, :itma stats.niter = iter stats.solved = solved stats.inconsistent = !solved && breakdown + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/gmres.jl b/src/gmres.jl index 2162ff8da..4ac2bdb22 100644 --- a/src/gmres.jl +++ b/src/gmres.jl @@ -159,6 +159,7 @@ kwargs_gmres = (:M, :N, :ldiv, :restart, :reorthogonalization, :atol, :rtol, :it 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 @@ -360,6 +361,7 @@ kwargs_gmres = (:M, :N, :ldiv, :restart, :reorthogonalization, :atol, :rtol, :it stats.niter = iter stats.solved = solved stats.inconsistent = inconsistent + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/gpmr.jl b/src/gpmr.jl index a362becea..e92bbfc00 100644 --- a/src/gpmr.jl +++ b/src/gpmr.jl @@ -522,6 +522,7 @@ kwargs_gpmr = (:C, :D, :E, :F, :ldiv, :gsp, :λ, :μ, :reorthogonalization, :ato stats.niter = iter stats.solved = solved stats.inconsistent = inconsistent + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/krylov_solvers.jl b/src/krylov_solvers.jl index 2793699f5..cd3ff5501 100644 --- a/src/krylov_solvers.jl +++ b/src/krylov_solvers.jl @@ -90,7 +90,7 @@ function MinresSolver(m, n, S; window :: Int=5) y = S(undef, n) v = S(undef, 0) err_vec = zeros(T, window) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = MinresSolver{T,FC,S}(m, n, Δx, x, r1, r2, w1, w2, y, v, err_vec, false, stats) return solver end @@ -139,7 +139,7 @@ function MinaresSolver(m, n, S) dₖ₋₂ = S(undef, n) dₖ₋₁ = S(undef, n) q = S(undef, n) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = MinaresSolver{T,FC,S}(m, n, Δx, vₖ, vₖ₊₁, x, wₖ₋₂, wₖ₋₁, dₖ₋₂, dₖ₋₁, q, false, stats) return solver end @@ -182,7 +182,7 @@ function CgSolver(m, n, S) p = S(undef, n) Ap = S(undef, n) z = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = CgSolver{T,FC,S}(m, n, Δx, x, r, p, Ap, z, false, stats) return solver end @@ -227,7 +227,7 @@ function CrSolver(m, n, S) q = S(undef, n) Ar = S(undef, n) Mq = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = CrSolver{T,FC,S}(m, n, Δx, x, r, p, q, Ar, Mq, false, stats) return solver end @@ -276,7 +276,7 @@ function CarSolver(m, n, S) t = S(undef, n) u = S(undef, n) Mu = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = CarSolver{T,FC,S}(m, n, Δx, x, r, p, s, q, t, u, Mu, false, stats) return solver end @@ -327,7 +327,7 @@ function SymmlqSolver(m, n, S; window :: Int=5) clist = zeros(T, window) zlist = zeros(T, window) sprod = ones(T, window) - stats = SymmlqStats(0, false, T[], Union{T, Missing}[], T[], Union{T, Missing}[], T(NaN), T(NaN), 0.0, "unknown") + stats = SymmlqStats(0, false, T[], Union{T, Missing}[], T[], Union{T, Missing}[], T(NaN), T(NaN), 0, 0.0, "unknown") solver = SymmlqSolver{T,FC,S}(m, n, Δx, x, Mvold, Mv, Mv_next, w̅, v, clist, zlist, sprod, false, stats) return solver end @@ -372,7 +372,7 @@ function CgLanczosSolver(m, n, S) p = S(undef, n) Mv_next = S(undef, n) v = S(undef, 0) - stats = LanczosStats(0, false, T[], false, T(NaN), T(NaN), 0.0, "unknown") + stats = LanczosStats(0, false, T[], false, T(NaN), T(NaN), 0, 0.0, "unknown") solver = CgLanczosSolver{T,FC,S}(m, n, Δx, x, Mv, Mv_prev, p, Mv_next, v, false, stats) return solver end @@ -430,7 +430,7 @@ function CgLanczosShiftSolver(m, n, nshifts, S) indefinite = BitVector(undef, nshifts) converged = BitVector(undef, nshifts) not_cv = BitVector(undef, nshifts) - stats = LanczosShiftStats(0, false, Vector{T}[T[] for i = 1 : nshifts], indefinite, T(NaN), T(NaN), 0.0, "unknown") + stats = LanczosShiftStats(0, false, Vector{T}[T[] for i = 1 : nshifts], indefinite, T(NaN), T(NaN), 0, 0.0, "unknown") solver = CgLanczosShiftSolver{T,FC,S}(m, n, nshifts, Mv, Mv_prev, Mv_next, v, x, p, σ, δhat, ω, γ, rNorms, converged, not_cv, stats) return solver end @@ -477,7 +477,7 @@ function MinresQlpSolver(m, n, S) x = S(undef, n) p = S(undef, n) vₖ = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = MinresQlpSolver{T,FC,S}(m, n, Δx, wₖ₋₁, wₖ, M⁻¹vₖ₋₁, M⁻¹vₖ, x, p, vₖ, false, stats) return solver end @@ -531,7 +531,7 @@ function DqgmresSolver(m, n, memory, S) c = Vector{T}(undef, memory) s = Vector{FC}(undef, memory) H = Vector{FC}(undef, memory+1) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = DqgmresSolver{T,FC,S}(m, n, Δx, x, t, z, w, P, V, c, s, H, false, stats) return solver end @@ -583,7 +583,7 @@ function DiomSolver(m, n, memory, S) V = S[S(undef, n) for i = 1 : memory] L = Vector{FC}(undef, memory-1) H = Vector{FC}(undef, memory) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = DiomSolver{T,FC,S}(m, n, Δx, x, t, z, w, P, V, L, H, false, stats) return solver end @@ -632,7 +632,7 @@ function UsymlqSolver(m, n, S) vₖ₋₁ = S(undef, m) vₖ = S(undef, m) q = S(undef, m) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = UsymlqSolver{T,FC,S}(m, n, uₖ₋₁, uₖ, p, Δx, x, d̅, vₖ₋₁, vₖ, q, false, stats) return solver end @@ -683,7 +683,7 @@ function UsymqrSolver(m, n, S) uₖ₋₁ = S(undef, n) uₖ = S(undef, n) p = S(undef, n) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = UsymqrSolver{T,FC,S}(m, n, vₖ₋₁, vₖ, q, Δx, x, wₖ₋₂, wₖ₋₁, uₖ₋₁, uₖ, p, false, stats) return solver end @@ -746,7 +746,7 @@ function TricgSolver(m, n, S) Δy = S(undef, 0) uₖ = S(undef, 0) vₖ = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = TricgSolver{T,FC,S}(m, n, y, N⁻¹uₖ₋₁, N⁻¹uₖ, p, gy₂ₖ₋₁, gy₂ₖ, x, M⁻¹vₖ₋₁, M⁻¹vₖ, q, gx₂ₖ₋₁, gx₂ₖ, Δx, Δy, uₖ, vₖ, false, stats) return solver end @@ -817,7 +817,7 @@ function TrimrSolver(m, n, S) Δy = S(undef, 0) uₖ = S(undef, 0) vₖ = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = TrimrSolver{T,FC,S}(m, n, y, N⁻¹uₖ₋₁, N⁻¹uₖ, p, gy₂ₖ₋₃, gy₂ₖ₋₂, gy₂ₖ₋₁, gy₂ₖ, x, M⁻¹vₖ₋₁, M⁻¹vₖ, q, gx₂ₖ₋₃, gx₂ₖ₋₂, gx₂ₖ₋₁, gx₂ₖ, Δx, Δy, uₖ, vₖ, false, stats) return solver end @@ -874,7 +874,7 @@ function TrilqrSolver(m, n, S) y = S(undef, m) wₖ₋₃ = S(undef, m) wₖ₋₂ = S(undef, m) - stats = AdjointStats(0, false, false, T[], T[], 0.0, "unknown") + stats = AdjointStats(0, false, false, T[], T[], 0, 0.0, "unknown") solver = TrilqrSolver{T,FC,S}(m, n, uₖ₋₁, uₖ, p, d̅, Δx, x, vₖ₋₁, vₖ, q, Δy, y, wₖ₋₃, wₖ₋₂, false, stats) return solver end @@ -923,7 +923,7 @@ function CgsSolver(m, n, S) ts = S(undef, n) yz = S(undef, 0) vw = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = CgsSolver{T,FC,S}(m, n, Δx, x, r, u, p, q, ts, yz, vw, false, stats) return solver end @@ -972,7 +972,7 @@ function BicgstabSolver(m, n, S) qd = S(undef, n) yz = S(undef, 0) t = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = BicgstabSolver{T,FC,S}(m, n, Δx, x, r, p, v, s, qd, yz, t, false, stats) return solver end @@ -1025,7 +1025,7 @@ function BilqSolver(m, n, S) d̅ = S(undef, n) t = S(undef, 0) s = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = BilqSolver{T,FC,S}(m, n, uₖ₋₁, uₖ, q, vₖ₋₁, vₖ, p, Δx, x, d̅, t, s, false, stats) return solver end @@ -1080,7 +1080,7 @@ function QmrSolver(m, n, S) wₖ₋₁ = S(undef, n) t = S(undef, 0) s = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = QmrSolver{T,FC,S}(m, n, uₖ₋₁, uₖ, q, vₖ₋₁, vₖ, p, Δx, x, wₖ₋₂, wₖ₋₁, t, s, false, stats) return solver end @@ -1137,7 +1137,7 @@ function BilqrSolver(m, n, S) d̅ = S(undef, n) wₖ₋₃ = S(undef, n) wₖ₋₂ = S(undef, n) - stats = AdjointStats(0, false, false, T[], T[], 0.0, "unknown") + stats = AdjointStats(0, false, false, T[], T[], 0, 0.0, "unknown") solver = BilqrSolver{T,FC,S}(m, n, uₖ₋₁, uₖ, q, vₖ₋₁, vₖ, p, Δx, x, Δy, y, d̅, wₖ₋₃, wₖ₋₂, false, stats) return solver end @@ -1179,7 +1179,7 @@ function CglsSolver(m, n, S) r = S(undef, m) q = S(undef, m) Mr = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = CglsSolver{T,FC,S}(m, n, x, p, s, r, q, Mr, stats) return solver end @@ -1239,7 +1239,7 @@ function CglsLanczosShiftSolver(m, n, nshifts, S) indefinite = BitVector(undef, nshifts) converged = BitVector(undef, nshifts) not_cv = BitVector(undef, nshifts) - stats = LanczosShiftStats(0, false, Vector{T}[T[] for i = 1 : nshifts], indefinite, T(NaN), T(NaN), 0.0, "unknown") + stats = LanczosShiftStats(0, false, Vector{T}[T[] for i = 1 : nshifts], indefinite, T(NaN), T(NaN), 0. 0.0, "unknown") solver = CglsLanczosShiftSolver{T,FC,S}(m, n, nshifts, Mv, Mv_prev, Mv_next, u, v, x, p, σ, δhat, ω, γ, rNorms, converged, not_cv, stats) return solver end @@ -1285,7 +1285,7 @@ function CrlsSolver(m, n, S) Ap = S(undef, m) s = S(undef, m) Ms = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = CrlsSolver{T,FC,S}(m, n, x, p, Ar, q, r, Ap, s, Ms, stats) return solver end @@ -1329,7 +1329,7 @@ function CgneSolver(m, n, S) q = S(undef, m) s = S(undef, 0) z = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = CgneSolver{T,FC,S}(m, n, x, p, Aᴴz, r, q, s, z, stats) return solver end @@ -1373,7 +1373,7 @@ function CrmrSolver(m, n, S) q = S(undef, m) Nq = S(undef, 0) s = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = CrmrSolver{T,FC,S}(m, n, x, p, Aᴴr, r, q, Nq, s, stats) return solver end @@ -1421,7 +1421,7 @@ function LslqSolver(m, n, S; window :: Int=5) u = S(undef, 0) v = S(undef, 0) err_vec = zeros(T, window) - stats = LSLQStats(0, false, false, T[], T[], T[], false, T[], T[], 0.0, "unknown") + stats = LSLQStats(0, false, false, T[], T[], T[], false, T[], T[], 0, 0.0, "unknown") solver = LslqSolver{T,FC,S}(m, n, x, Nv, Aᴴu, w̄, Mu, Av, u, v, err_vec, stats) return solver end @@ -1469,7 +1469,7 @@ function LsqrSolver(m, n, S; window :: Int=5) u = S(undef, 0) v = S(undef, 0) err_vec = zeros(T, window) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = LsqrSolver{T,FC,S}(m, n, x, Nv, Aᴴu, w, Mu, Av, u, v, err_vec, stats) return solver end @@ -1519,7 +1519,7 @@ function LsmrSolver(m, n, S; window :: Int=5) u = S(undef, 0) v = S(undef, 0) err_vec = zeros(T, window) - stats = LsmrStats(0, false, false, T[], T[], zero(T), zero(T), zero(T), zero(T), zero(T), 0.0, "unknown") + stats = LsmrStats(0, false, false, T[], T[], zero(T), zero(T), zero(T), zero(T), zero(T), 0, 0.0, "unknown") solver = LsmrSolver{T,FC,S}(m, n, x, Nv, Aᴴu, h, hbar, Mu, Av, u, v, err_vec, stats) return solver end @@ -1569,7 +1569,7 @@ function LnlqSolver(m, n, S) u = S(undef, 0) v = S(undef, 0) q = S(undef, 0) - stats = LNLQStats(0, false, T[], false, T[], T[], 0.0, "unknown") + stats = LNLQStats(0, false, T[], false, T[], T[], 0, 0.0, "unknown") solver = LnlqSolver{T,FC,S}(m, n, x, Nv, Aᴴu, y, w̄, Mu, Av, u, v, q, stats) return solver end @@ -1619,7 +1619,7 @@ function CraigSolver(m, n, S) u = S(undef, 0) v = S(undef, 0) w2 = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = CraigSolver{T,FC,S}(m, n, x, Nv, Aᴴu, y, w, Mu, Av, u, v, w2, stats) return solver end @@ -1673,7 +1673,7 @@ function CraigmrSolver(m, n, S) u = S(undef, 0) v = S(undef, 0) q = S(undef, 0) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = CraigmrSolver{T,FC,S}(m, n, x, Nv, Aᴴu, d, y, Mu, w, wbar, Av, u, v, q, stats) return solver end @@ -1728,7 +1728,7 @@ function GmresSolver(m, n, memory, S) s = Vector{FC}(undef, memory) z = Vector{FC}(undef, memory) R = Vector{FC}(undef, div(memory * (memory+1), 2)) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = GmresSolver{T,FC,S}(m, n, Δx, x, w, p, q, V, c, s, z, R, false, 0, stats) return solver end @@ -1783,7 +1783,7 @@ function FgmresSolver(m, n, memory, S) s = Vector{FC}(undef, memory) z = Vector{FC}(undef, memory) R = Vector{FC}(undef, div(memory * (memory+1), 2)) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = FgmresSolver{T,FC,S}(m, n, Δx, x, w, q, V, Z, c, s, z, R, false, 0, stats) return solver end @@ -1835,7 +1835,7 @@ function FomSolver(m, n, memory, S) l = Vector{FC}(undef, memory) z = Vector{FC}(undef, memory) U = Vector{FC}(undef, div(memory * (memory+1), 2)) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = FomSolver{T,FC,S}(m, n, Δx, x, w, p, q, V, l, z, U, false, stats) return solver end @@ -1901,7 +1901,7 @@ function GpmrSolver(m, n, memory, S) gc = Vector{T}(undef, 4 * memory) zt = Vector{FC}(undef, 2 * memory) R = Vector{FC}(undef, memory * (2 * memory + 1)) - stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown") + stats = SimpleStats(0, false, false, T[], T[], T[], 0, 0.0, "unknown") solver = GpmrSolver{T,FC,S}(m, n, wA, wB, dA, dB, Δx, Δy, x, y, q, p, V, U, gs, gc, zt, R, false, stats) return solver end diff --git a/src/krylov_stats.jl b/src/krylov_stats.jl index c383b7914..402be5e3f 100644 --- a/src/krylov_stats.jl +++ b/src/krylov_stats.jl @@ -14,7 +14,8 @@ The fields are as follows: - `inconsistent`: Flags whether the system was detected as inconsistent (i.e., when `b` is not in the range of `A`); - `residuals`: A vector containing the residual norms at each iteration; - `Aresiduals`: A vector of `A'`-residual norms at each iteration; -- `Acond`: An estimate of the condition number of matrix `A`. +- `Acond`: An estimate of the condition number of matrix `A`; +- `storage`: Total number of bytes required for the workspace; - `timer`: The elapsed time (in seconds) taken by the solver to complete all iterations; - `status`: A string indicating the outcome of the solve, providing additional details beyond `solved`. """ @@ -25,6 +26,7 @@ mutable struct SimpleStats{T} <: KrylovStats{T} residuals :: Vector{T} Aresiduals :: Vector{T} Acond :: Vector{T} + storage :: Int timer :: Float64 status :: String end @@ -42,6 +44,7 @@ function copyto!(dest :: SimpleStats, src :: SimpleStats) dest.residuals = copy(src.residuals) dest.Aresiduals = copy(src.Aresiduals) dest.Acond = copy(src.Acond) + dest.storage = src.storage dest.timer = src.timer dest.status = src.status return dest @@ -72,6 +75,7 @@ mutable struct LsmrStats{T} <: KrylovStats{T} Acond :: T Anorm :: T xNorm :: T + storage :: Int timer :: Float64 status :: String end @@ -92,6 +96,7 @@ function copyto!(dest :: LsmrStats, src :: LsmrStats) dest.Acond = src.Acond dest.Anorm = src.Anorm dest.xNorm = src.xNorm + dest.storage = src.storage dest.timer = src.timer dest.status = src.status return dest @@ -116,6 +121,7 @@ mutable struct LanczosStats{T} <: KrylovStats{T} indefinite :: Bool Anorm :: T Acond :: T + storage :: Int timer :: Float64 status :: String end @@ -131,6 +137,7 @@ function copyto!(dest :: LanczosStats, src :: LanczosStats) dest.indefinite = src.indefinite dest.Anorm = src.Anorm dest.Acond = src.Acond + dest.storage = src.storage dest.timer = src.timer dest.status = src.status return dest @@ -155,6 +162,7 @@ mutable struct LanczosShiftStats{T} <: KrylovStats{T} indefinite :: BitVector Anorm :: T Acond :: T + storage :: Int timer :: Float64 status :: String end @@ -172,6 +180,7 @@ function copyto!(dest :: LanczosShiftStats, src :: LanczosShiftStats) dest.indefinite = src.indefinite dest.Anorm = src.Anorm dest.Acond = src.Acond + dest.storage = src.storage dest.timer = src.timer dest.status = src.status return dest @@ -200,6 +209,7 @@ mutable struct SymmlqStats{T} <: KrylovStats{T} errorscg :: Vector{Union{T, Missing}} Anorm :: T Acond :: T + storage :: Int timer :: Float64 status :: String end @@ -220,6 +230,7 @@ function copyto!(dest :: SymmlqStats, src :: SymmlqStats) dest.errorscg = copy(src.errorscg) dest.Anorm = src.Anorm dest.Acond = src.Acond + dest.storage = src.storage dest.timer = src.timer dest.status = src.status return dest @@ -242,6 +253,7 @@ mutable struct AdjointStats{T} <: KrylovStats{T} solved_dual :: Bool residuals_primal :: Vector{T} residuals_dual :: Vector{T} + storage :: Int timer :: Float64 status :: String end @@ -257,6 +269,7 @@ function copyto!(dest :: AdjointStats, src :: AdjointStats) dest.solved_dual = src.solved_dual dest.residuals_primal = copy(src.residuals_primal) dest.residuals_dual = copy(src.residuals_dual) + dest.storage = src.storage dest.timer = src.timer dest.status = src.status return dest @@ -282,6 +295,7 @@ mutable struct LNLQStats{T} <: KrylovStats{T} error_with_bnd :: Bool error_bnd_x :: Vector{T} error_bnd_y :: Vector{T} + storage :: Int timer :: Float64 status :: String end @@ -299,6 +313,7 @@ function copyto!(dest :: LNLQStats, src :: LNLQStats) dest.error_with_bnd = src.error_with_bnd dest.error_bnd_x = copy(src.error_bnd_x) dest.error_bnd_y = copy(src.error_bnd_y) + dest.storage = src.storage dest.timer = src.timer dest.status = src.status return dest @@ -329,6 +344,7 @@ mutable struct LSLQStats{T} <: KrylovStats{T} error_with_bnd :: Bool err_ubnds_lq :: Vector{T} err_ubnds_cg :: Vector{T} + storage :: Int timer :: Float64 status :: String end @@ -351,6 +367,7 @@ function copyto!(dest :: LSLQStats, src :: LSLQStats) dest.error_with_bnd = src.error_with_bnd dest.err_ubnds_lq = copy(src.err_ubnds_lq) dest.err_ubnds_cg = copy(src.err_ubnds_cg) + dest.storage = src.storage dest.timer = src.timer dest.status = src.status return dest @@ -382,13 +399,20 @@ function show(io :: IO, stats :: KrylovStats) statfield = getfield(stats, field) if isa(statfield, AbstractVector) && eltype(statfield) <: Union{Missing, AbstractFloat} s *= @sprintf " %s\n" vec2str(statfield) + elseif field_name == "storage" + s *= @sprintf " %s\n" format_bytes(statfield) elseif field_name == "timer" - (statfield < 1e-3) && (s *= @sprintf " %.2fμs\n" 1e6*statfield) - (1e-3 ≤ statfield < 1.00) && (s *= @sprintf " %.2fms\n" 1e3*statfield) - (statfield ≥ 1.00) && (s *= @sprintf " %.2fs\n" statfield) + s *= display_timer(statfield) else s *= @sprintf " %s\n" statfield end end print(io, s) end + +function display_timer(timer::Float64) + (timer < 1e-3) && (s = @sprintf(" %.2fμs\n", 1e6 * timer)) + (1e-3 ≤ timer < 1.00) && (s = @sprintf(" %.2fms\n", 1e3 * timer)) + (timer ≥ 1.00) && (s = @sprintf(" %.2fs\n", timer)) + return s +end diff --git a/src/lnlq.jl b/src/lnlq.jl index d74396097..5fb5d8254 100644 --- a/src/lnlq.jl +++ b/src/lnlq.jl @@ -207,6 +207,7 @@ kwargs_lnlq = (:M, :N, :ldiv, :transfer_to_craig, :sqd, :λ, :σ, :utolx, :utoly stats.solved = true stats.error_with_bnd = false history && push!(rNorms, bNorm) + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = "x = 0 is a zero-residual solution" return solver @@ -543,6 +544,7 @@ kwargs_lnlq = (:M, :N, :ldiv, :transfer_to_craig, :sqd, :λ, :σ, :utolx, :utoly stats.niter = iter stats.solved = solved_lq || solved_cg stats.error_with_bnd = complex_error_bnd + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/lslq.jl b/src/lslq.jl index 535dc6f2c..92805d0c2 100644 --- a/src/lslq.jl +++ b/src/lslq.jl @@ -235,6 +235,7 @@ kwargs_lslq = (:M, :N, :ldiv, :transfer_to_lsqr, :sqd, :λ, :σ, :etol, :utol, : stats.error_with_bnd = false history && push!(rNorms, zero(T)) 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 @@ -255,6 +256,7 @@ kwargs_lslq = (:M, :N, :ldiv, :transfer_to_lsqr, :sqd, :λ, :σ, :etol, :utol, : stats.error_with_bnd = 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 @@ -498,6 +500,7 @@ kwargs_lslq = (:M, :N, :ldiv, :transfer_to_lsqr, :sqd, :λ, :σ, :etol, :utol, : stats.solved = solved stats.inconsistent = !zero_resid stats.error_with_bnd = complex_error_bnd + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/lsmr.jl b/src/lsmr.jl index eb9be839f..1f15b3dcb 100644 --- a/src/lsmr.jl +++ b/src/lsmr.jl @@ -206,6 +206,7 @@ kwargs_lsmr = (:M, :N, :ldiv, :sqd, :λ, :radius, :etol, :axtol, :btol, :conlim, 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!(rNorms, zero(T)) @@ -267,6 +268,7 @@ kwargs_lsmr = (:M, :N, :ldiv, :sqd, :λ, :radius, :etol, :axtol, :btol, :conlim, 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 minimum least-squares solution" return solver @@ -433,6 +435,7 @@ kwargs_lsmr = (:M, :N, :ldiv, :sqd, :λ, :radius, :etol, :axtol, :btol, :conlim, stats.niter = iter stats.solved = solved stats.inconsistent = !zero_resid + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/lsqr.jl b/src/lsqr.jl index 03e6539f8..fcc67536a 100644 --- a/src/lsqr.jl +++ b/src/lsqr.jl @@ -203,6 +203,7 @@ kwargs_lsqr = (:M, :N, :ldiv, :sqd, :λ, :radius, :etol, :axtol, :btol, :conlim, 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!(rNorms, zero(T)) @@ -249,6 +250,7 @@ kwargs_lsqr = (:M, :N, :ldiv, :sqd, :λ, :radius, :etol, :axtol, :btol, :conlim, 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 minimum least-squares solution" return solver @@ -418,6 +420,7 @@ kwargs_lsqr = (:M, :N, :ldiv, :sqd, :λ, :radius, :etol, :axtol, :btol, :conlim, stats.niter = iter stats.solved = solved stats.inconsistent = !zero_resid + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/minares.jl b/src/minares.jl index 9a32ebef0..c20edd569 100644 --- a/src/minares.jl +++ b/src/minares.jl @@ -194,6 +194,7 @@ kwargs_minares = (:M, :ldiv, :λ, :atol, :rtol, :Artol, :itmax, :timemax, :verbo 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 @@ -580,6 +581,7 @@ kwargs_minares = (:M, :ldiv, :λ, :atol, :rtol, :Artol, :itmax, :timemax, :verbo stats.niter = iter stats.solved = solved # stats.inconsistent = inconsistent + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/minres.jl b/src/minres.jl index 27f7a6f2e..fc9f06651 100644 --- a/src/minres.jl +++ b/src/minres.jl @@ -178,6 +178,7 @@ kwargs_minres = (:M, :ldiv, :λ, :atol, :rtol, :etol, :conlim, :itmax, :timemax, 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!(rNorms, β₁) @@ -328,6 +329,7 @@ kwargs_minres = (:M, :ldiv, :λ, :atol, :rtol, :etol, :conlim, :itmax, :timemax, # Aᴴb = 0 so x = 0 is a minimum least-squares solution stats.niter = 1 stats.solved, stats.inconsistent = true, true + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = "x is a minimum least-squares solution" solver.warm_start = false @@ -378,6 +380,7 @@ kwargs_minres = (:M, :ldiv, :λ, :atol, :rtol, :etol, :conlim, :itmax, :timemax, stats.niter = iter stats.solved = solved stats.inconsistent = !zero_resid + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/minres_qlp.jl b/src/minres_qlp.jl index 2538a1802..9b34eb8a7 100644 --- a/src/minres_qlp.jl +++ b/src/minres_qlp.jl @@ -168,6 +168,7 @@ kwargs_minres_qlp = (:M, :ldiv, :λ, :atol, :rtol, :Artol, :itmax, :timemax, :ve 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 @@ -469,6 +470,7 @@ kwargs_minres_qlp = (:M, :ldiv, :λ, :atol, :rtol, :Artol, :itmax, :timemax, :ve stats.niter = iter stats.solved = solved stats.inconsistent = inconsistent + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/qmr.jl b/src/qmr.jl index 1f6afe290..11343e247 100644 --- a/src/qmr.jl +++ b/src/qmr.jl @@ -170,6 +170,7 @@ kwargs_qmr = (:c, :M, :N, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose, :hist 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 @@ -185,6 +186,7 @@ kwargs_qmr = (:c, :M, :N, :ldiv, :atol, :rtol, :itmax, :timemax, :verbose, :hist 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 @@ -389,6 +391,7 @@ kwargs_qmr = (: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 diff --git a/src/symmlq.jl b/src/symmlq.jl index 2cacbc572..6e4ac80b5 100644 --- a/src/symmlq.jl +++ b/src/symmlq.jl @@ -168,6 +168,7 @@ kwargs_symmlq = (:M, :ldiv, :transfer_to_cg, :λ, :λest, :atol, :rtol, :etol, : stats.Acond = T(NaN) history && push!(rNorms, zero(T)) history && push!(rcgNorms, zero(T)) + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = "x = 0 is a zero-residual solution" solver.warm_start = false @@ -441,6 +442,7 @@ kwargs_symmlq = (:M, :ldiv, :transfer_to_cg, :λ, :λest, :atol, :rtol, :etol, : stats.solved = solved stats.Anorm = ANorm stats.Acond = Acond + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/tricg.jl b/src/tricg.jl index 9348467a9..c179567bc 100644 --- a/src/tricg.jl +++ b/src/tricg.jl @@ -448,6 +448,7 @@ kwargs_tricg = (:M, :N, :ldiv, :spd, :snd, :flip, :τ, :ν, :atol, :rtol, :itmax stats.niter = iter stats.solved = solved stats.inconsistent = !solved && breakdown + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/trilqr.jl b/src/trilqr.jl index 03b7ff482..ad3f6a585 100644 --- a/src/trilqr.jl +++ b/src/trilqr.jl @@ -446,6 +446,7 @@ kwargs_trilqr = (:transfer_to_usymcg, :atol, :rtol, :itmax, :timemax, :verbose, 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 diff --git a/src/trimr.jl b/src/trimr.jl index da7d0aa05..6eeebe6b2 100644 --- a/src/trimr.jl +++ b/src/trimr.jl @@ -551,6 +551,7 @@ kwargs_trimr = (:M, :N, :ldiv, :spd, :snd, :flip, :sp, :τ, :ν, :atol, :rtol, : stats.niter = iter stats.solved = solved stats.inconsistent = !solved && breakdown + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/src/usymlq.jl b/src/usymlq.jl index 7a8172500..9fabe87ae 100644 --- a/src/usymlq.jl +++ b/src/usymlq.jl @@ -153,6 +153,7 @@ kwargs_usymlq = (:transfer_to_usymcg, :atol, :rtol, :itmax, :timemax, :verbose, 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 @@ -350,6 +351,7 @@ kwargs_usymlq = (:transfer_to_usymcg, :atol, :rtol, :itmax, :timemax, :verbose, 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 diff --git a/src/usymqr.jl b/src/usymqr.jl index fa86d4524..5e3aaf676 100644 --- a/src/usymqr.jl +++ b/src/usymqr.jl @@ -156,6 +156,7 @@ kwargs_usymqr = (:atol, :rtol, :itmax, :timemax, :verbose, :history, :callback, 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 @@ -346,6 +347,7 @@ kwargs_usymqr = (:atol, :rtol, :itmax, :timemax, :verbose, :history, :callback, stats.niter = iter stats.solved = solved stats.inconsistent = inconsistent + stats.storage = sizeof(solver) stats.timer = start_time |> ktimer stats.status = status return solver diff --git a/test/test_stats.jl b/test/test_stats.jl index 0a9a96650..3fcad5250 100644 --- a/test/test_stats.jl +++ b/test/test_stats.jl @@ -1,6 +1,6 @@ @testset "stats" begin - stats = Krylov.SimpleStats(0, true, true, Float64[1.0], Float64[2.0], Float64[], 1.234, "unknown") - stats2 = Krylov.SimpleStats(1, true, true, Float64[1.0], Float64[2.0], Float64[], 1.234, "unknown") + stats = Krylov.SimpleStats(0, true, true, Float64[1.0], Float64[2.0], Float64[], 1024, 1.234, "unknown") + stats2 = Krylov.SimpleStats(1, true, true, Float64[1.0], Float64[2.0], Float64[], 1024, 1.234, "unknown") copyto!(stats2, stats) io = IOBuffer() show(io, stats) @@ -13,6 +13,7 @@ residuals: [ 1.0e+00 ] Aresiduals: [ 2.0e+00 ] κ₂(A): [] + storage: 1024 bytes timer: 1.23s status: unknown""" @test strip.(split(chomp(showed), "\n")) == strip.(split(chomp(expected), "\n")) @@ -21,8 +22,8 @@ nbytes_allocated = @allocated Krylov.reset!(stats) @test nbytes_allocated == 0 - stats = Krylov.LsmrStats(0, true, true, Float64[1.0], Float64[2.0], Float64(3.0), Float64(4.0), Float64(5.0), Float64(6.0), Float64(7.0), 0.1234, "unknown") - stats2 = Krylov.LsmrStats(1, true, true, Float64[1.0], Float64[2.0], Float64(3.0), Float64(4.0), Float64(5.0), Float64(6.0), Float64(7.0), 0.1234, "unknown") + stats = Krylov.LsmrStats(0, true, true, Float64[1.0], Float64[2.0], Float64(3.0), Float64(4.0), Float64(5.0), Float64(6.0), Float64(7.0), 1024, 0.1234, "unknown") + stats2 = Krylov.LsmrStats(1, true, true, Float64[1.0], Float64[2.0], Float64(3.0), Float64(4.0), Float64(5.0), Float64(6.0), Float64(7.0), 1024, 0.1234, "unknown") copyto!(stats2, stats) io = IOBuffer() show(io, stats) @@ -39,6 +40,7 @@ κ₂(A): 5.0 ‖A‖F: 6.0 xNorm: 7.0 + storage: 1024 bytes timer: 123.40ms status: unknown""" @test strip.(split(chomp(showed), "\n")) == strip.(split(chomp(expected), "\n")) @@ -47,8 +49,8 @@ nbytes_allocated = @allocated Krylov.reset!(stats) @test nbytes_allocated == 0 - stats = Krylov.LanczosStats(0, true, Float64[3.0], true, NaN, NaN, 1.234, "unknown") - stats2 = Krylov.LanczosStats(1, true, Float64[3.0], true, NaN, NaN, 1.234, "unknown") + stats = Krylov.LanczosStats(0, true, Float64[3.0], true, NaN, NaN, 1024, 1.234, "unknown") + stats2 = Krylov.LanczosStats(1, true, Float64[3.0], true, NaN, NaN, 1024, 1.234, "unknown") copyto!(stats2, stats) io = IOBuffer() show(io, stats) @@ -61,6 +63,7 @@ indefinite: true ‖A‖F: NaN κ₂(A): NaN + storage: 1024 bytes timer: 1.23s status: unknown""" @test strip.(split(chomp(showed), "\n")) == strip.(split(chomp(expected), "\n")) @@ -69,8 +72,8 @@ nbytes_allocated = @allocated Krylov.reset!(stats) @test nbytes_allocated == 0 - stats = Krylov.LanczosShiftStats(0, true, [Float64[0.9, 0.5], Float64[0.6, 0.4, 0.1]], BitVector([false, true]), NaN, NaN, 0.00056789, "unknown") - stats2 = Krylov.LanczosShiftStats(1, true, [Float64[0.9, 0.5], Float64[0.6, 0.4, 0.1]], BitVector([false, true]), NaN, NaN, 0.00056789, "unknown") + stats = Krylov.LanczosShiftStats(0, true, [Float64[0.9, 0.5], Float64[0.6, 0.4, 0.1]], BitVector([false, true]), NaN, NaN, 1024, 0.00056789, "unknown") + stats2 = Krylov.LanczosShiftStats(1, true, [Float64[0.9, 0.5], Float64[0.6, 0.4, 0.1]], BitVector([false, true]), NaN, NaN, 1024, 0.00056789, "unknown") copyto!(stats2, stats) io = IOBuffer() show(io, stats) @@ -83,6 +86,7 @@ indefinite: Bool[0, 1] ‖A‖F: NaN κ₂(A): NaN + storage: 1024 bytes timer: 567.89μs status: unknown""" @test strip.(split(chomp(showed), "\n")) == strip.(split(chomp(expected), "\n")) @@ -90,8 +94,8 @@ nbytes_allocated = @allocated Krylov.reset!(stats) @test nbytes_allocated == 0 - stats = Krylov.SymmlqStats(0, true, Float64[4.0], Union{Float64,Missing}[5.0, missing], Float64[6.0], Union{Float64,Missing}[7.0, missing], NaN, NaN, 1.234, "unknown") - stats2 = Krylov.SymmlqStats(1, true, Float64[4.0], Union{Float64,Missing}[5.0, missing], Float64[6.0], Union{Float64,Missing}[7.0, missing], NaN, NaN, 1.234, "unknown") + stats = Krylov.SymmlqStats(0, true, Float64[4.0], Union{Float64,Missing}[5.0, missing], Float64[6.0], Union{Float64,Missing}[7.0, missing], NaN, NaN, 1024, 1.234, "unknown") + stats2 = Krylov.SymmlqStats(1, true, Float64[4.0], Union{Float64,Missing}[5.0, missing], Float64[6.0], Union{Float64,Missing}[7.0, missing], NaN, NaN, 1024, 1.234, "unknown") copyto!(stats2, stats) io = IOBuffer() show(io, stats) @@ -106,6 +110,7 @@ errors (cg): [ 7.0e+00 ✗✗✗✗ ] ‖A‖F: NaN κ₂(A): NaN + storage: 1024 bytes timer: 1.23s status: unknown""" @test strip.(split(chomp(showed), "\n")) == strip.(split(chomp(expected), "\n")) @@ -114,8 +119,8 @@ nbytes_allocated = @allocated Krylov.reset!(stats) @test nbytes_allocated == 0 - stats = Krylov.AdjointStats(0, true, true, Float64[8.0], Float64[9.0], 1.234, "unknown") - stats2 = Krylov.AdjointStats(1, true, true, Float64[8.0], Float64[9.0], 1.234, "unknown") + stats = Krylov.AdjointStats(0, true, true, Float64[8.0], Float64[9.0], 1024, 1.234, "unknown") + stats2 = Krylov.AdjointStats(1, true, true, Float64[8.0], Float64[9.0], 1024, 1.234, "unknown") copyto!(stats2, stats) io = IOBuffer() show(io, stats) @@ -127,6 +132,7 @@ solved dual: true residuals primal: [ 8.0e+00 ] residuals dual: [ 9.0e+00 ] + storage: 1024 bytes timer: 1.23s status: unknown""" @test strip.(split(chomp(showed), "\n")) == strip.(split(chomp(expected), "\n")) @@ -135,8 +141,8 @@ nbytes_allocated = @allocated Krylov.reset!(stats) @test nbytes_allocated == 0 - stats = Krylov.LNLQStats(0, true, Float64[10.0], false, Float64[11.0], Float64[12.0], 1.234, "unknown") - stats2 = Krylov.LNLQStats(1, true, Float64[10.0], false, Float64[11.0], Float64[12.0], 1.234, "unknown") + stats = Krylov.LNLQStats(0, true, Float64[10.0], false, Float64[11.0], Float64[12.0], 1024, 1.234, "unknown") + stats2 = Krylov.LNLQStats(1, true, Float64[10.0], false, Float64[11.0], Float64[12.0], 1024, 1.234, "unknown") copyto!(stats2, stats) io = IOBuffer() show(io, stats) @@ -149,6 +155,7 @@ error with bnd: false error bnd x: [ 1.1e+01 ] error bnd y: [ 1.2e+01 ] + storage: 1024 bytes timer: 1.23s status: unknown""" @test strip.(split(chomp(showed), "\n")) == strip.(split(chomp(expected), "\n")) @@ -157,8 +164,8 @@ nbytes_allocated = @allocated Krylov.reset!(stats) @test nbytes_allocated == 0 - stats = Krylov.LSLQStats(0, true, false, Float64[13.0], Float64[14.0], Float64[15.0], false, Float64[16.0], Float64[17.0], 1.234, "unknown") - stats2 = Krylov.LSLQStats(1, true, false, Float64[13.0], Float64[14.0], Float64[15.0], false, Float64[16.0], Float64[17.0], 1.234, "unknown") + stats = Krylov.LSLQStats(0, true, false, Float64[13.0], Float64[14.0], Float64[15.0], false, Float64[16.0], Float64[17.0], 1024, 1.234, "unknown") + stats2 = Krylov.LSLQStats(1, true, false, Float64[13.0], Float64[14.0], Float64[15.0], false, Float64[16.0], Float64[17.0], 1024, 1.234, "unknown") copyto!(stats2, stats) io = IOBuffer() show(io, stats) @@ -174,6 +181,7 @@ error with bnd: false error bound LQ: [ 1.6e+01 ] error bound CG: [ 1.7e+01 ] + storage: 1024 bytes timer: 1.23s status: unknown""" @test strip.(split(chomp(showed), "\n")) == strip.(split(chomp(expected), "\n"))