diff --git a/src/TiledArray/array_impl.h b/src/TiledArray/array_impl.h index 449141331c..610ba275e9 100644 --- a/src/TiledArray/array_impl.h +++ b/src/TiledArray/array_impl.h @@ -632,6 +632,14 @@ class ArrayImpl : public TensorImpl { return value; } + /// Reports the number of live DelayedSet requests for this object's + /// DistributedStorage + + /// @return const reference to the atomic counter of live DelayedSet requests + const madness::AtomicInt& num_live_ds() const { + return data_.num_live_ds(); + } + }; // class ArrayImpl #ifndef TILEDARRAY_HEADER_ONLY diff --git a/src/TiledArray/dist_array.h b/src/TiledArray/dist_array.h index 6cd156ba5d..9521db58cd 100644 --- a/src/TiledArray/dist_array.h +++ b/src/TiledArray/dist_array.h @@ -142,6 +142,9 @@ class DistArray : public madness::archive::ParallelSerializableObject { const madness::uniqueidT id = pimpl->id(); cleanup_counter_++; + // wait for all DelayedSet's to vanish + world.await([&]() { return (pimpl->num_live_ds() == 0); }, true); + try { world.gop.lazy_sync(id, [pimpl]() { delete pimpl; diff --git a/src/TiledArray/distributed_storage.h b/src/TiledArray/distributed_storage.h index bc03967456..030ed91205 100644 --- a/src/TiledArray/distributed_storage.h +++ b/src/TiledArray/distributed_storage.h @@ -293,6 +293,12 @@ class DistributedStorage : public madness::WorldObject > { } } + /// Reports the number of live DelayedSet requests + + /// @return const reference to the atomic counter of live DelayedSet requests + const madness::AtomicInt& num_live_ds() const { + return num_live_ds_; + } }; // class DistributedStorage } // namespace detail