Open amartinhuertas opened 3 years ago
Hi @amartinhuertas
I have implemented a draft of another approach to handle petsc gc. See branch: https://github.com/gridap/GridapPETSc.jl/tree/petsc_gc
My principal goal is to fix the issue of petsc gc using the standard petsc destroy functions (e.g., VecDestroy, MatDestroy, etc).
I am not 100% confortable using more sophisticated petsc functions as we explored here https://github.com/gridap/GridapPETSc.jl/pull/42 In particular, with this error
[1]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
[1]PETSC ERROR: Petsc has generated inconsistent data
[1]PETSC ERROR: No more room in array, limit 256
recompile src/sys/objects/destroy.c with larger value for MAXREGDESOBJS
So, I think it is perhaps a good idea to find a solution with the standard petsc destroy functions alone.
The main idea is to maintain a package global vector _REFS
containing the low level handlers of types Ref{Vec}
, Ref{Mat}
, etc that are created in the computation. Then, we also consider another package global vector _STATES
telling the state of these low level references. Three states are possible _INITIALIZED
, _FINALIZED
, and _ORPHAN
. The idea is that we install a finalizer so that the Julia gc marks the corresponding low level refs as _ORPHAN
. Then with a call to function petsc_cg()
all the orphan references with be destroyed with VecDestroy etc collectively.
The draft is incomplete:
Finalize()
in sequential runs as before.In particular, with this error
@fverdugo ... this error is easily by-passeable. Barry Smith told us the solution and that they would accept a PR in PETSc along the lines that he proposed. Anyway, I understand your point, it is much better if we are able to solve the problem using more standard functionality in PETSc. I still have to understand what you are proposing, whether it works, etc. The current solution works. (up to that nasty error that is not acceptable).