Repository navigation
Reuse one Krylov workspace and residual buffer across CG attempts - #540
Merged
Merged
Conversation
solve_linear_system allocated a fresh Krylov workspace (five vectors of the system's size) for the first attempt and another (six) for each warm-started retry, plus two temporaries for every residual check. It now builds one CgWorkspace and one residual buffer and reuses them: a solve that needs one retry, as every Omniscape window does, allocates seven vectors instead of fifteen. Results are bit-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
ViralBShah
referenced
this pull request
Nov 21, 2026
Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
solve_linear_system(thecg+amgsolve) allocated a fresh Krylov workspace for every attempt and two temporaries for every residual check:Krylov.cgbuilds a workspace of 5 vectors of the system's sizenorm(G*v .- curr): 2 moreIt now builds one
Krylov.CgWorkspaceand one residual buffer per solve and reuses them across attempts (Krylov.cg!, with the warm start passed the workspace's own solution, which Krylov copies before overwriting). A solve that needs one retry, as every Omniscape window does, now allocates 7 vectors instead of 15; one that passes first time, 6 instead of 7.Results are bit-identical to master (relative difference 0.0 on an 800×800 grid Laplacian, Float64 and Float32, with and without a retry).
Effect on Omniscape: on 9 real radius-668 windows (single thread, Circuitscape, AlgebraicMultigrid and Omniscape at master), allocation drops from 1.870 to 1.833 GB per window, about 2%, with the same total current. Most of what remains is AMG setup and graph construction, not the CG solve; the CG + AMG path itself is type stable and allocates essentially nothing per iteration.
The
CgWorkspace(A, b)constructor and the warm-start form ofcg!exist from Krylov 0.10.0, so the compat bound is unchanged.Full test suite passes.
🤖 Generated with Claude Code