diff --git a/src/vt/vrt/collection/collection_builder.impl.h b/src/vt/vrt/collection/collection_builder.impl.h index e9115497af..7d66df9061 100644 --- a/src/vt/vrt/collection/collection_builder.impl.h +++ b/src/vt/vrt/collection/collection_builder.impl.h @@ -66,9 +66,7 @@ std::tuple CollectionManager::makeCollection( "collection construction", term::UseDS{false} ); theMsg()->pushEpoch(ep); - using MsgType = param::ConstructParamMsg; - auto m = makeMessage(po); - theMsg()->broadcastMsg(m); + theMsg()->send>(vt::Node(0), po, true); theMsg()->popEpoch(ep); theTerm()->finishedEpoch(ep); return std::make_tuple(ep, proxy_bits); @@ -82,11 +80,37 @@ std::tuple CollectionManager::makeCollection( } } +/*static*/ inline void CollectionManager::finishedRootedConstruction() { + theCollection()->has_pending_construction_ = false; + if (theCollection()->pending_rooted_constructions_.size() > 0) { + auto action = theCollection()->pending_rooted_constructions_.back(); + theCollection()->pending_rooted_constructions_.pop_back(); + action(); + } +} + template /*static*/ void CollectionManager::makeCollectionHandler( - param::ConstructParamMsg* msg + param::ConstructParams po, bool is_root ) { - theCollection()->makeCollectionImpl(*msg->po); + if (is_root) { + if (theCollection()->has_pending_construction_) { + auto ep = theMsg()->getEpoch(); + theTerm()->produce(ep); + theCollection()->pending_rooted_constructions_.push_back([=]{ + theTerm()->pushEpoch(ep); + makeCollectionHandler(po, true); + theTerm()->consume(ep); + theTerm()->popEpoch(ep); + }); + } else { + theMsg()->broadcast>(po, false); + } + } else { + theCollection()->makeCollectionImpl(po); + auto r = theCollection()->reducer(); + r->reduce(vt::Node(0)); + } } namespace detail { diff --git a/src/vt/vrt/collection/manager.h b/src/vt/vrt/collection/manager.h index 9ef6540206..000dbd18b8 100644 --- a/src/vt/vrt/collection/manager.h +++ b/src/vt/vrt/collection/manager.h @@ -72,7 +72,6 @@ #include "vt/runtime/component/component_pack.h" #include "vt/context/runnable_context/lb_data.fwd.h" #include "vt/vrt/collection/param/construct_params.h" -#include "vt/vrt/collection/param/construct_params_msg.h" #include "vt/utils/fntraits/fntraits.h" #include @@ -1697,10 +1696,18 @@ struct CollectionManager * \internal \brief Handler for receiving a new collection configuration to * construct on this node * - * \param[in] msg the configuration message + * \param[in] po construct parameters + * \param[in] is_root whether if it's boucing off the root first */ template - static void makeCollectionHandler(param::ConstructParamMsg* msg); + static void makeCollectionHandler( + param::ConstructParams po, bool is_root + ); + + /** + * \brief Finished a rooted construction--do the next if needed + */ + static void finishedRootedConstruction(); /** * \internal \brief System function to actually constructing the collection @@ -1766,6 +1773,8 @@ struct CollectionManager VirtualIDType next_rooted_id_ = 0; TypelessHolder typeless_holder_; std::unordered_map reduce_stamp_; + bool has_pending_construction_ = false; + std::list pending_rooted_constructions_; }; }}} /* end namespace vt::vrt::collection */ diff --git a/src/vt/vrt/collection/param/construct_params_msg.h b/src/vt/vrt/collection/param/construct_params_msg.h deleted file mode 100644 index 63086db3cf..0000000000 --- a/src/vt/vrt/collection/param/construct_params_msg.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -//@HEADER -// ***************************************************************************** -// -// construct_params_msg.h -// DARMA/vt => Virtual Transport -// -// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC -// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. -// Government retains certain rights in this software. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * Neither the name of the copyright holder nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// Questions? Contact darma@sandia.gov -// -// ***************************************************************************** -//@HEADER -*/ - -#if !defined INCLUDED_VT_VRT_COLLECTION_PARAM_CONSTRUCT_PARAMS_MSG_H -#define INCLUDED_VT_VRT_COLLECTION_PARAM_CONSTRUCT_PARAMS_MSG_H - -#include "vt/vrt/collection/param/construct_params.h" - -namespace vt { namespace vrt { namespace collection { namespace param { - -/** - * \struct ConstructParamMsg - * - * \brief Construct PO configuration message for distributed construction - */ -template -struct ConstructParamMsg : vt::Message { - using MessageParentType = ::vt::Message; - vt_msg_serialize_required(); // po - - ConstructParamMsg() = default; - explicit ConstructParamMsg(param::ConstructParams& in_po) - : po(std::make_unique>(in_po)) - { } - - template - void serialize(SerializerT& s) { - MessageParentType::serialize(s); - s | po; - } - - /// Must use \c std::unique_ptr here because without the indirection, - /// AppleClang generates invalid alignment that causes a segfault when \c new - /// is called on this message type. The only other work around is some - /// seemingly arbitrary value to alignas (alignas(1024) seems to do the - /// trick). - std::unique_ptr> po = nullptr; -}; - -}}}} /* end namespace vt::vrt::collection::param */ - -#endif /*INCLUDED_VT_VRT_COLLECTION_PARAM_CONSTRUCT_PARAMS_MSG_H*/