Reuse factor buffers across re-factorizations (follow-up to #55)#56
Merged
Conversation
…factorization SparseLU / SparseCholesky / SparseLDL (Double and Complex) allocate L/U (and pinv, D) only on the first Factorize call, and Clear() + reuse the existing buffers on subsequent calls (same sparsity pattern), avoiding re-allocation on every Refactorize. For SparseLU the end-of-factorization trim (Resize(0)) is now gated on the existing CompressedColumnStorage<T>.AutoTrimStorage flag: disabling it keeps the L/U buffers allocated across re-factorizations (iterative solvers, time-stepping) — fully allocation-free reuse. AutoTrimStorage's doc is updated accordingly. Cholesky/LDL allocate the exact factor size, so no trim is involved there. Adds TestRefactorizeNoTrim (refactorize with AutoTrimStorage = false stays correct). All 293 tests pass.
Owner
|
Thanks again, this can be merged as is! The SparseLU implementation has quite a naive approach to memory management, just doubling the sizes of the storage arrays, in case the number of non-zeros exceed the available space. This tends to leave a lot more memory allocated than actually needed, so I added the resize-to-nonzero-count at the end of the I'll update the nuget package later this week. |
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.
Follow-up to #55 (merged) — as you suggested, rebased onto current
masterfor a clean history.What
SparseLU/SparseCholesky/SparseLDL(Double and Complex) now allocateL/U(and
pinv,D) only on the firstFactorizecall, andClear()+ reuse the bufferson subsequent calls (same sparsity pattern). This avoids re-allocating the factor storage
on every
Refactorize— the point of #55, for Newton / time-stepping loops.The
SparseLUtrim (per your note)You suggested gating the end-of-factorization trim on
AutoTrimStoragerather than droppingit — done.
SparseLU.Factorizenow wraps the finalResize(0)inif (CompressedColumnStorage<T>.AutoTrimStorage). So withAutoTrimStorage = falsetheL/Ubuffers stay allocated acrossRefactorizecalls → fully allocation-free reuse foriterative solvers / time-stepping. I updated the
AutoTrimStoragedoc to mention this.(
Cholesky/LDLallocate the exact factor size, so no trim is involved there.)