Add close/clear/destroy function to classes with collective destructor

Issue #390 new
Prof Garth Wells created an issue

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)

  1. Martin Sandve Alnæs

    @johanhake didn't you fix this for all file classes? This issue is also about LA objects with collective destructors.

  2. Prof Garth Wells 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() in HDF5File.h.

  3. Prof Garth Wells 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.

  4. Jan Blechta

    Introduced much more garbage collection to unit tests to avoid problems like #775 in cea15e6, a1af51d. But that does not make the problem resolved. We need to shift a bit paradigm typing FEniCS programs, e.g., into Pythonic

    with 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.

  5. Log in to comment