Add close/clear/destroy function to classes with collective destructor
Non-deterministic garbage collective in Python can lead to MPI deadlocks when destructors are collective. See thread at https://www.mail-archive.com/fenics@fenicsproject.org/msg01783.html.
To work around this, we can add a close()
/clear()
/destroy()
to each class that requires collective destruction. From the destructor of each class, a warning message can be printed if the object is not manually cleaned up before destruction. In which cases the warning is printed can be tuned.
Comments (9)
-
-
No, I just added enter enter and exit methods to File and HDF5File.
-
reporter If
HDF5File::close()
has been added, do we need a corresponding function to 're-open' the file?XDMFFile
also needs a close function.If would be good to expand the docstring for
HDF5File::close()
inHDF5File.h
. -
And
File
also. -
reporter @blechta That's another reason why I would like to not support HDF5/XDMF via the
File
interface.File
only makes sense for very simple formats that all have the same interface, i.e. it is not suitable for rich interfaces like HDF5 and proper (hierarchal) XML. -
reporter - changed milestone to 1.6
-
- changed milestone to 1.7
-
- removed milestone
Removing milestone: 1.7 (automated comment)
-
Introduced much more garbage collection to unit tests to avoid problems like
#775in cea15e6, a1af51d. But that does not make the problem resolved. We need to shift a bit paradigm typing FEniCS programs, e.g., into Pythonicwith Function(V) as u: solver.solve(u.vector, b) with HDF5File(comm, 'u.h5', 'w') as f: f.write(u, '/u')
or PETScish
u = Function(V) solver.solve(u.vector()) f = HDF5File(comm, 'u.h5', 'w') f.write(u, '/u') f.close() u.destroy()
Note that function may own PETSc vector so it's destructor is effectively collective. This will spread out, I guess, through many objects.
- Log in to comment
@johanhake didn't you fix this for all file classes? This issue is also about LA objects with collective destructors.