Repository navigation
Dense mat keep alive - #313
Merged
Merged
Conversation
A dense matrix made from a Julia array kept that array alive only as long as its Julia handle. A KSP holds the matrix past that point, so once the handle was collected the next solve read freed memory: a wrong answer, or a PETSc zero-pivot error. PetscMat(petsclib, A::Matrix) now keeps the array with the PETSc object, as CSR matrices and vectors on Julia arrays already did. PetscMat(petsclib, m, n; type = :dense) lets PETSc allocate the storage, so no Julia array is involved.
The DMDA, DMStag and DMPlex constructors and fe_create_default pushed their options onto PETSc's options stack around a PETSc call and popped them afterwards, but not when the call threw. The options then stayed on the stack: every object created afterwards read them, and they could no longer be destroyed. The options are now popped whether or not the call throws. Assisted-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.
Fix two lifetime bugs where an exception or a garbage collection broke an object's lifetime rules
PetscMat(petsclib, A::Matrix), orPetscMat(petsclib, m, n; type = :dense)) could lose its storage while a KSP still used it. Once the Julia handle was collected, the next solve read freed memory, which gave a wrong answer or a zero-pivot error. The array now lives as long as the PETSc matrix, as it already did for CSR matrices and vectors on Julia arrays.fe_create_defaultleft their options pushed on PETSc's options stack when PETSc threw. Later objects read those options, and destroying them failed. They're now popped in every case.