Skip to content

Reuse one Krylov workspace and residual buffer across CG attempts - #540

Merged
ViralBShah merged 1 commit into
masterfrom
vs/cg-workspace-reuse
Nov 15, 2026
Merged

ViralBShah merged 1 commit into
masterfrom
vs/cg-workspace-reuse

Conversation

@ViralBShah

Copy link
Copy Markdown
Member

solve_linear_system (the cg+amg solve) allocated a fresh Krylov workspace for every attempt and two temporaries for every residual check:

It now builds one Krylov.CgWorkspace and 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 of cg! exist from Krylov 0.10.0, so the compat bound is unchanged.

Full test suite passes.

🤖 Generated with Claude Code

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>
@ViralBShah
ViralBShah merged commit 16b0dcb into master Nov 15, 2026
6 checks passed
@ViralBShah
ViralBShah deleted the vs/cg-workspace-reuse branch November 15, 2026 12:42
@ViralBShah ViralBShah mentioned this pull request Nov 21, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant