Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initialize and finalize and destroy #155

Open
jkozdon opened this issue Aug 5, 2021 · 3 comments · May be fixed by #149
Open

initialize and finalize and destroy #155

jkozdon opened this issue Aug 5, 2021 · 3 comments · May be fixed by #149

Comments

@jkozdon
Copy link
Member

jkozdon commented Aug 5, 2021

Do we ever see a use case where we might have something like:

PETSc.initialize(petsclib)
# ... work....
PETSc.finalize(petsclib)

# start PETSc again...
PETSc.initialize(petsclib)

I ask because this can cause problems with the garbage collector in when it's used. For instance, if the garbage collector is run on a PETSc object allocated in the first chunk of work AFTER petsc has been re-initialized this is an error since the actual PETSc object doesn't exist anymore. The destroy has a check for whether PETSc is finalized, but this will not catch PETSc having been re-initialized.

@jkozdon jkozdon changed the title initialize and finalize initialize and finalize and destroy Aug 5, 2021
@boriskaus
Copy link
Collaborator

I see no reason why this would be done. In the testing we do this but with a finalize at the end

@psanan
Copy link
Contributor

psanan commented Aug 6, 2021

PETSc supports this. It is done sometimes in practice because someone uses PETSc within a larger code and wants to encapsulate as much as possible, so they initialize and finalize PETSc for each solve.

Is it already an issue without the second initialize()? You aren't allowed to destroy PETSc objects after you finalize PETSc.

@jkozdon
Copy link
Member Author

jkozdon commented Aug 6, 2021

Is it already an issue without the second initialize()? You aren't allowed to destroy PETSc objects after you finalize PETSc.

That is true, but we catch it with a check to see if PETSc is finalized

PETSc.jl/src/mat.jl

Lines 191 to 195 in 73f12e0

function destroy(nullspace::MatNullSpace{$PetscScalar})
finalized($petsclib) ||
@chk ccall((:MatNullSpaceDestroy, $libpetsc), PetscErrorCode, (Ptr{CMatNullSpace},), nullspace)
return nothing
end

OK. I have a few ideas for how to work around this, so will leave the issue open. Some smarter people than me may weigh in as well.

@jkozdon jkozdon linked a pull request Aug 7, 2021 that will close this issue
8 tasks
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 a pull request may close this issue.

3 participants