JuliaParallel / JuliaParallel/PETSc.jl
MPI Friendly GC
- Dominant language
- Julia
- Stars
- 182
- Forks
- 46
- Avg merge
- 15h
- Merged PRs (30d)
- 18
Description
We should consider implementing what [`GridapPETSc.jl`](https://github.com/gridap/GridapPETSc.jl) has done for GC with mpi objects.
Basically the julia finalizer registers the object for destruction with [`PetscObjectRegisterDestroy`](https://petsc.org/release/docs/manualpages/Sys/PetscObjectRegisterDestroy.html), see for example [`PETScLinearSolverNS`](
https://github.com/gridap/GridapPETSc.jl/blob/5cd8a956fc4933fe3fe0d07aeae0c3c8f2eb827d/src/PETScLinearSolvers.jl#L38-L50)
Of course this means the object is not destroyed until PETSc is finalized. If the user wants to destroy things sooner they can call a function [`gridap_petsc_gc`](https://github.com/gridap/GridapPETSc.jl/blob/5cd8a956fc4933fe3fe0d07aeae0c3c8f2eb827d/src/Environment.jl#L42-L47):
```julia
# In an MPI environment context,
# this function has global collective semantics.
function gridap_petsc_gc()
GC.gc()
@check_error_code PETSC.PetscObjectRegisterDestroyAll()
end
```
By first calling `GC.gc()` all objects will be properly registered via `PetscObjectRegisterDestroy` and the call to [`PetscObjectRegisterDestroyAll`](https://petsc.org/release/docs/manualpages/Sys/PetscObjectRegisterDestroyAll.html) actually destroys then.
The only change I would make is to suggest still allow manual destruction of objects is this is desired for performance reason (though I don't know if this is really ever needed).
h/t: @amartinhuertas in https://github.com/JuliaParallel/PETSc.jl/issues/146#issuecomment-987425710
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.