Skip to content

Commit

Permalink
Reuse memory for CG point in SYMMLQ
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison authored and dpo committed Mar 7, 2019
1 parent ef0a34e commit 270d90d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/symmlq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ function symmlq(A :: AbstractLinearOperator, b :: AbstractVector{T};

ϵM = eps(T)
x_lq = zeros(T, n)
x_cg = zeros(T, n)
ctol = conlim > 0.0 ? 1 / conlim : 0.0;

# Initialize Lanczos process.
# β₁ M v₁ = b.
Mvold = copy(b)
vold = M * Mvold
β₁ = @kdot(m, vold, Mvold)
β₁ == 0.0 && return (x_lq, x_cg, SimpleStats(true, true, [0.0], [0.0], "x = 0 is a zero-residual solution"))
β₁ == 0.0 && return (x_lq, zeros(T, n), SimpleStats(true, true, [0.0], [0.0], "x = 0 is a zero-residual solution"))
β₁ = sqrt(β₁)
β = β₁
@kscal!(m, 1 / β, vold)
Expand Down Expand Up @@ -263,7 +262,8 @@ function symmlq(A :: AbstractLinearOperator, b :: AbstractVector{T};
end

# Compute CG point
@. x_cg = x_lq + ζbar * wbar
@kaxpby!(m, 1.0, x_lq, ζbar, wbar)
x_cg = wbar

tired && (status = "maximum number of iterations exceeded")
ill_cond_mach && (status = "condition number seems too large for this machine")
Expand Down
4 changes: 2 additions & 2 deletions test/test_alloc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ mem = 10
shifts = [1:5;]
nshifts = 5

# without preconditioner and with Ap preallocated, SYMMLQ needs 6 n-vectors: x_lq, x_cg, vold, v, w, wbar
storage_symmlq(n) = 6 * n
# without preconditioner and with Ap preallocated, SYMMLQ needs 5 n-vectors: x_lq, vold, v, w, wbar
storage_symmlq(n) = 5 * n
storage_symmlq_bytes(n) = 8 * storage_symmlq(n)

expected_symmlq_bytes = storage_symmlq_bytes(n)
Expand Down

0 comments on commit 270d90d

Please sign in to comment.