From df2be870f366ea5db9539d9be39b0c06b84ad90f Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Thu, 27 May 2021 16:54:09 -0400 Subject: [PATCH 1/2] SparseShape::is_replicated fixed to produce same result on all ranks --- src/TiledArray/sparse_shape.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/TiledArray/sparse_shape.h b/src/TiledArray/sparse_shape.h index 502620ca8a..3edd306c5f 100644 --- a/src/TiledArray/sparse_shape.h +++ b/src/TiledArray/sparse_shape.h @@ -1627,10 +1627,15 @@ bool is_replicated(World& world, const SparseShape& shape) { const auto volume = shape.data().size(); std::vector data(shape.data().data(), shape.data().data() + volume); world.gop.max(data.data(), volume); + bool result = true; for (size_t i = 0; i != data.size(); ++i) { - if (data[i] != shape.data()[i]) return false; + if (data[i] != shape.data()[i]) { + result = false; + break; + } } - return true; + world.gop.logic_and(&result, 1); + return result; } #ifndef TILEDARRAY_HEADER_ONLY From d749a423e94d439069a5e40a6b778f7d32e47365 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Thu, 27 May 2021 16:54:58 -0400 Subject: [PATCH 2/2] TensorImpl distributed ctor by default replicates shape across all ranks provide replicate_shape=false to revert to the old behavior --- src/TiledArray/tensor_impl.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/TiledArray/tensor_impl.h b/src/TiledArray/tensor_impl.h index 066bd49832..05374834f6 100644 --- a/src/TiledArray/tensor_impl.h +++ b/src/TiledArray/tensor_impl.h @@ -62,11 +62,20 @@ class TensorImpl : private NO_DEFAULTS { /// \param trange The tiled range for this tensor /// \param shape The shape of this tensor /// \param pmap The tile-process map + /// \param replicate_shape if true, will replicate the shape from rank 0, else + /// will use as is, but assert that the data is _bitwise_ identical + /// between ranks /// \throw TiledArray::Exception When the size of shape is not equal to /// zero TensorImpl(World& world, const trange_type& trange, const shape_type& shape, - const std::shared_ptr& pmap) + const std::shared_ptr& pmap, + bool replicate_shape = true) : world_(world), trange_(trange), shape_(shape), pmap_(pmap) { + // ensure that shapes are identical on every rank + if (replicate_shape) + world.gop.broadcast_serializable(shape_, 0); + else + TA_ASSERT(is_replicated(world, shape_)); // Validate input data. TA_ASSERT(pmap_); TA_ASSERT(pmap_->size() == trange_.tiles_range().volume()); @@ -75,8 +84,6 @@ class TensorImpl : private NO_DEFAULTS { TA_ASSERT(pmap_->procs() == typename pmap_interface::size_type(world_.size())); TA_ASSERT(shape_.validate(trange_.tiles_range())); - // ensure that shapes are identical on every rank - TA_ASSERT(is_replicated(world, shape)); } /// Virtual destructor