diff --git a/docs/md/registry.md b/docs/md/registry.md index 8ab467020d..6d257faa4d 100644 --- a/docs/md/registry.md +++ b/docs/md/registry.md @@ -1,10 +1,6 @@ \page registry Registry \brief Registered handlers -The registry component `vt::registry::Registry`, accessed via -`vt::theRegistry()` holds type-safe active handlers for execution across a -distributed machine. - - The \ref active-messenger uses the registry to store/dispatch active function and active functor handlers. - The \ref objgroup uses the registry to store/dispatch active member diff --git a/src/vt/collective/collective_ops.cc b/src/vt/collective/collective_ops.cc index 0d38a2a8cd..9f392b93a1 100644 --- a/src/vt/collective/collective_ops.cc +++ b/src/vt/collective/collective_ops.cc @@ -334,11 +334,6 @@ void CollectiveAnyOps::output( } } -template -HandlerType CollectiveAnyOps::registerHandler(ActiveClosureFnType fn) { - return theRegistry()->registerActiveHandler(fn); -} - template struct CollectiveAnyOps; } /* end namespace vt */ diff --git a/src/vt/collective/collective_ops.h b/src/vt/collective/collective_ops.h index 849ac3a6a7..2a9d17dc5f 100644 --- a/src/vt/collective/collective_ops.h +++ b/src/vt/collective/collective_ops.h @@ -47,7 +47,6 @@ #include "vt/config.h" #include "vt/context/context.h" #include "vt/runtime/runtime_headers.h" -#include "vt/registry/registry.h" #include @@ -77,8 +76,6 @@ struct CollectiveAnyOps { bool error = false, bool decorate = true, bool formatted = false, bool abort_out = false ); - - static HandlerType registerHandler(ActiveClosureFnType fn); }; using CollectiveOps = CollectiveAnyOps; diff --git a/src/vt/collective/reduce/reduce.impl.h b/src/vt/collective/reduce/reduce.impl.h index ae957bc12c..0a2724d38d 100644 --- a/src/vt/collective/reduce/reduce.impl.h +++ b/src/vt/collective/reduce/reduce.impl.h @@ -46,7 +46,6 @@ #include "vt/config.h" #include "vt/collective/collective_alg.h" -#include "vt/registry/registry.h" #include "vt/registry/auto/auto_registry_interface.h" #include "vt/messaging/active.h" #include "vt/messaging/message.h" diff --git a/src/vt/context/context.cc b/src/vt/context/context.cc index d18fbb7d07..5215863db1 100644 --- a/src/vt/context/context.cc +++ b/src/vt/context/context.cc @@ -42,7 +42,7 @@ */ #include "vt/context/context.h" -#include "vt/context/runnable_context/from_node.h" +#include "vt/context/runnable_context/set_context.h" #if vt_check_enabled(trace_only) namespace vt { namespace runnable { @@ -111,7 +111,7 @@ void Context::setTask(runnable::RunnableNew* in_task) { NodeType Context::getFromNodeCurrentTask() const { #if !vt_check_enabled(trace_only) if (getTask() != nullptr) { - auto from = getTask()->get(); + auto from = getTask()->get(); if (from != nullptr) { return from->get(); } diff --git a/src/vt/context/runnable_context/base.h b/src/vt/context/runnable_context/base.h deleted file mode 100644 index b02138a420..0000000000 --- a/src/vt/context/runnable_context/base.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -//@HEADER -// ***************************************************************************** -// -// base.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_CONTEXT_RUNNABLE_CONTEXT_BASE_H -#define INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_BASE_H - -#include "vt/configs/types/types_type.h" -#include "vt/elm/elm_id.h" - -namespace vt { namespace ctx { - -/** - * \struct Base - * - * \brief Base context for runnable tasks. - * - * \c ctx::Base is used to create contexts that are associated with tasks - * wrapped with the \c runnable::Runnable class. When messages arrive and - * trigger a handler or other actions occur, contexts that inherit from \c Base - * can be used to maintain a particular context when that runnable is passed to - * the scheduler for later execution. The \c begin() and \c end() methods are - * called when the task starts and stops. If VT is built with user-level threads - * (ULTs), \c suspend() and \c resume might be called if the thread that a task - * is running in suspends the stack mid-execution (typically waiting for a - * dependency). Thus, any context is expected to save all state in suspend and - * then return that state back during resume when the ULT is resumed. - * - * \warning Note that contexts should not hold on to a message pointer and read - * values from the message after the \c begin() method is called as the user - * might modify the message or forward it. - */ -struct Base { - - virtual ~Base() = default; - - /** - * \brief Invoked immediately before a task is executed - */ - virtual void begin() {} - - /** - * \brief Invoked immediately after a task is executed - */ - virtual void end() {} - - /** - * \brief Invoked when a task is suspended (for ULTs, when enabled) - */ - virtual void suspend() {} - - /** - * \brief Invoked when a handler is resumed (for ULTs, when enabled) - */ - virtual void resume() {} - - /** - * \brief Invoked when a message is sent to any node - * - * \param[in] dest the destination of the message - * \param[in] size the size of the message - */ - virtual void send(elm::ElementIDStruct dest, MsgSizeType bytes) { } -}; - -}} /* end namespace vt::ctx */ - -#endif /*INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_BASE_H*/ diff --git a/src/vt/context/runnable_context/from_node.h b/src/vt/context/runnable_context/collection.cc similarity index 71% rename from src/vt/context/runnable_context/from_node.h rename to src/vt/context/runnable_context/collection.cc index 8555ff2bf9..9dfe954549 100644 --- a/src/vt/context/runnable_context/from_node.h +++ b/src/vt/context/runnable_context/collection.cc @@ -2,7 +2,7 @@ //@HEADER // ***************************************************************************** // -// from_node.h +// collection.cc // DARMA/vt => Virtual Transport // // Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC @@ -41,41 +41,24 @@ //@HEADER */ -#if !defined INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_FROM_NODE_H -#define INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_FROM_NODE_H - -#include "vt/context/runnable_context/base.h" +#include "vt/context/runnable_context/collection.h" namespace vt { namespace ctx { -/** - * \struct FromNode - * - * \brief Get the node that instigated the current task running. Typically the - * logical node that caused an handler or event to run. - */ -struct FromNode final : Base { +void Collection::begin() { + set_(); +} - /** - * \brief Construct a \c FromNode - * - * \param[in] in_node the node - */ - explicit FromNode(NodeType const in_node) - : node_(in_node) - { } +void Collection::end() { + clear_(); +} - /** - * \brief Get the node that instigated the current task - * - * \return the node - */ - NodeType get() const { return node_; } +void Collection::suspend() { + end(); +} -private: - NodeType node_ = uninitialized_destination; /**< The from node */ -}; +void Collection::resume() { + begin(); +} }} /* end namespace vt::ctx */ - -#endif /*INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_FROM_NODE_H*/ diff --git a/src/vt/context/runnable_context/collection.h b/src/vt/context/runnable_context/collection.h index 7a730fca78..2a1dd58291 100644 --- a/src/vt/context/runnable_context/collection.h +++ b/src/vt/context/runnable_context/collection.h @@ -44,7 +44,7 @@ #if !defined INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_COLLECTION_H #define INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_COLLECTION_H -#include "vt/context/runnable_context/base.h" +#include namespace vt { namespace vrt { namespace collection { @@ -61,32 +61,34 @@ namespace vt { namespace ctx { * \brief Context for a collection element that is running. Includes the index * and proxy for the collection. */ -template -struct Collection final : Base { +struct Collection { + + Collection() = default; /** * \brief Construct a \c Collection * * \param[in] elm the collection element to extract the index and proxy */ + template explicit Collection(vrt::collection::Indexable* elm); /** * \brief Set the collection context */ - void begin() final override; + void begin(); /** * \brief Remove the collection context */ - void end() final override; + void end(); - void suspend() final override; - void resume() final override; + void suspend(); + void resume(); private: - IndexT idx_ = {}; /**< the collection element index */ - VirtualProxyType proxy_ = no_vrt_proxy; /**< the collection proxy */ + std::function set_; /**< Set context function */ + std::function clear_; /**< Clear context function */ }; }} /* end namespace vt::ctx */ diff --git a/src/vt/context/runnable_context/collection.impl.h b/src/vt/context/runnable_context/collection.impl.h index bffbb35c3a..9a22c23bc4 100644 --- a/src/vt/context/runnable_context/collection.impl.h +++ b/src/vt/context/runnable_context/collection.impl.h @@ -51,30 +51,17 @@ namespace vt { namespace ctx { template -/*explicit*/ Collection::Collection( +/*explicit*/ Collection::Collection( vrt::collection::Indexable* elm -) : idx_(elm->getIndex()), - proxy_(elm->getProxy()) -{ } - -template -void Collection::begin() { - vrt::collection::CollectionContextHolder::set(&idx_, proxy_); -} - -template -void Collection::end() { - vrt::collection::CollectionContextHolder::clear(); -} - -template -void Collection::suspend() { - end(); -} - -template -void Collection::resume() { - begin(); +) { + auto idx_ = elm->getIndex(); + auto proxy_ = elm->getProxy(); + set_ = [=]{ + vrt::collection::CollectionContextHolder::set(&idx_, proxy_); + }; + clear_ = []{ + vrt::collection::CollectionContextHolder::clear(); + }; } }} /* end namespace vt::ctx */ diff --git a/src/vt/context/runnable_context/continuation.h b/src/vt/context/runnable_context/continuation.h index 76030d3b9e..40041017fd 100644 --- a/src/vt/context/runnable_context/continuation.h +++ b/src/vt/context/runnable_context/continuation.h @@ -44,8 +44,6 @@ #if !defined INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_CONTINUATION_H #define INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_CONTINUATION_H -#include "vt/context/runnable_context/base.h" - namespace vt { namespace ctx { /** @@ -53,7 +51,9 @@ namespace vt { namespace ctx { * * \brief A continuation that runs after a task is complete. */ -struct Continuation final : Base { +struct Continuation { + + Continuation() = default; /** * \brief Construct a \c Continuation @@ -67,7 +67,7 @@ struct Continuation final : Base { /** * \brief After the task runs, invoke the continuation if non-null */ - void end() final override { + void end() { if (cont_) { cont_(); } diff --git a/src/vt/context/runnable_context/lb_data.h b/src/vt/context/runnable_context/lb_data.h index 0ca9a27ad2..78b177a240 100644 --- a/src/vt/context/runnable_context/lb_data.h +++ b/src/vt/context/runnable_context/lb_data.h @@ -44,7 +44,6 @@ #if !defined INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_LB_DATA_H #define INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_LB_DATA_H -#include "vt/context/runnable_context/base.h" #include "vt/vrt/collection/balance/lb_common.h" #include "vt/elm/elm_lb_data.fwd.h" @@ -55,10 +54,12 @@ namespace vt { namespace ctx { * * \brief Context for collection of LB data when a task runs */ -struct LBData final : Base { +struct LBData { using ElementIDStruct = elm::ElementIDStruct; using ElementLBData = elm::ElementLBData; + LBData() = default; + /** * \brief Construct a \c LBData * @@ -83,12 +84,12 @@ struct LBData final : Base { /** * \brief Set the context and timing for a collection task */ - void begin() final override; + void begin(); /** * \brief Remove the context and store timing for a collection task */ - void end() final override; + void end(); /** * \brief Record LB data whenever a message is sent and a collection @@ -97,10 +98,10 @@ struct LBData final : Base { * \param[in] dest the destination of the message * \param[in] size the size of the message */ - void send(elm::ElementIDStruct dest, MsgSizeType bytes) final override; + void send(elm::ElementIDStruct dest, MsgSizeType bytes); - void suspend() final override; - void resume() final override; + void suspend(); + void resume(); /** * \brief Get the current element ID struct for the running context diff --git a/src/vt/context/runnable_context/set_context.h b/src/vt/context/runnable_context/set_context.h index 37bb5e2ca0..6073a1354c 100644 --- a/src/vt/context/runnable_context/set_context.h +++ b/src/vt/context/runnable_context/set_context.h @@ -44,7 +44,6 @@ #if !defined INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_SET_CONTEXT_H #define INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_SET_CONTEXT_H -#include "vt/context/runnable_context/base.h" #include "vt/runnable/runnable.fwd.h" #include "vt/utils/ptr/observer.h" @@ -56,36 +55,49 @@ namespace vt { namespace ctx { * \brief Set the context of the current running task for query by other * components or users. */ -struct SetContext final : Base { +struct SetContext { + + SetContext() = default; /** * \brief Construct a \c SetContext * * \param[in] in_nonowning_cur_task the current task (non-owning ptr held) + * \param[in] in_from_node the from node on the message that caused a task to + * run */ - explicit SetContext(runnable::RunnableNew* in_cur_task) - : cur_task_(in_cur_task) + SetContext(runnable::RunnableNew* in_cur_task, NodeType in_from_node) + : cur_task_(in_cur_task), + node_(in_from_node) {} + /** + * \brief Get the node that instigated the current task + * + * \return the node + */ + NodeType get() const { return node_; } + /** * \brief Preserve the existing task and replace with a new one */ - void begin() final override; + void begin(); /** * \brief Restore the previous existing task to the context (if there was one) */ - void end() final override; + void end(); - void suspend() final override; + void suspend(); - void resume() final override; + void resume(); private: /// The previous runnable that was in the context util::ObserverPtr prev_task_ = nullptr; /// The new runnable that is replacing it util::ObserverPtr cur_task_ = nullptr; + NodeType node_ = uninitialized_destination; /**< The from node */ }; }} /* end namespace vt::ctx */ diff --git a/src/vt/context/runnable_context/td.cc b/src/vt/context/runnable_context/td.cc index 1337dc37d4..db8f1b76cb 100644 --- a/src/vt/context/runnable_context/td.cc +++ b/src/vt/context/runnable_context/td.cc @@ -50,30 +50,23 @@ namespace vt { namespace ctx { TD::TD(EpochType in_ep) : ep_(in_ep == no_epoch ? term::any_epoch_sentinel : in_ep) { - if (ep_ != no_epoch) { - theTerm()->produce(ep_); - } -} - -/*virtual*/ TD::~TD() { - if (ep_ != no_epoch) { - theTerm()->consume(ep_); - } + theTerm()->produce(ep_); } void TD::begin() { theTerm()->pushEpoch(ep_); +#if vt_check_enabled(fcontext) auto& epoch_stack = theTerm()->getEpochStack(); - base_epoch_stack_size_ = epoch_stack.size(); +#endif } void TD::end() { +#if vt_check_enabled(fcontext) auto& epoch_stack = theTerm()->getEpochStack(); - vtAssert( base_epoch_stack_size_ <= epoch_stack.size(), "Epoch stack popped below preceding push size in handler" @@ -82,29 +75,32 @@ void TD::end() { while (epoch_stack.size() > base_epoch_stack_size_) { theTerm()->popEpoch(); } +#endif theTerm()->popEpoch(ep_); + theTerm()->consume(ep_); } void TD::suspend() { +#if vt_check_enabled(fcontext) auto& epoch_stack = theTerm()->getEpochStack(); - while (epoch_stack.size() > base_epoch_stack_size_) { suspended_epochs_.push_back(theTerm()->getEpoch()); theTerm()->popEpoch(); } theTerm()->popEpoch(ep_); +#endif } void TD::resume() { +#if vt_check_enabled(fcontext) theTerm()->pushEpoch(ep_); auto& epoch_stack = theTerm()->getEpochStack(); base_epoch_stack_size_ = epoch_stack.size(); - for (auto it = suspended_epochs_.rbegin(); it != suspended_epochs_.rend(); ++it) { @@ -112,6 +108,7 @@ void TD::resume() { } suspended_epochs_.clear(); +#endif } }} /* end namespace vt::ctx */ diff --git a/src/vt/context/runnable_context/td.h b/src/vt/context/runnable_context/td.h index b991a8760e..8a0cf0f913 100644 --- a/src/vt/context/runnable_context/td.h +++ b/src/vt/context/runnable_context/td.h @@ -44,7 +44,7 @@ #if !defined INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_TD_H #define INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_TD_H -#include "vt/context/runnable_context/base.h" +#include "vt/config.h" #include "vt/configs/types/types_type.h" #include "vt/configs/types/types_sentinels.h" #include "vt/epoch/epoch_type.h" @@ -60,7 +60,9 @@ namespace vt { namespace ctx { * the epoch stack associated with running tasks. Produces and consumes in the * constructor and destructor to ensure termination is not detected early. */ -struct TD final : Base { +struct TD { + + TD() = default; /** * \brief Construct with a given epoch; produce on that epoch. @@ -69,11 +71,6 @@ struct TD final : Base { */ explicit TD(EpochType in_ep); - /** - * \brief When destroyed, consume the epoch held by the context. - */ - virtual ~TD(); - /** * \brief Construct with a message to extract the epoch; produce on that * epoch. @@ -81,36 +78,38 @@ struct TD final : Base { * \param[in] msg the message to extract the epoch from */ template - explicit TD(MsgPtrT msg); + explicit TD(MsgPtrT const& msg); /** * \brief During begin \c TD will capture the epoch stack size and push \c ep_ */ - void begin() final override; + void begin(); /** * \brief During end \c TD will pop all epochs off of the stack down to the * size in captured in \c begin() */ - void end() final override; + void end(); /** * \brief When suspended, \c TD will preserve any epochs pushed on the stack * after begin and restore the stack back to the state before begin was * invoked */ - void suspend() final override; + void suspend(); /** * \brief When resumed, \c TD will restore the stack back from when it was * suspended */ - void resume() final override; + void resume(); private: EpochType ep_ = no_epoch; /**< The epoch for the task */ +#if vt_check_enabled(fcontext) std::size_t base_epoch_stack_size_ = 0; /**< Epoch stack size at start */ std::vector suspended_epochs_; /**< Suspended epoch stack */ +#endif }; }} /* end namespace vt::ctx */ diff --git a/src/vt/context/runnable_context/td.impl.h b/src/vt/context/runnable_context/td.impl.h index e456ffd713..0992a18b54 100644 --- a/src/vt/context/runnable_context/td.impl.h +++ b/src/vt/context/runnable_context/td.impl.h @@ -60,7 +60,7 @@ namespace { * \return the associated epoch */ template -static EpochType extractEpochMsg(MsgPtrT msg) { +static EpochType extractEpochMsg(MsgPtrT const& msg) { auto const is_term = envelopeIsTerm(msg->env); if (not is_term) { auto ep_ = envelopeIsEpochType(msg->env) ? @@ -77,7 +77,7 @@ static EpochType extractEpochMsg(MsgPtrT msg) { } /* end anon namespace */ template -/*explicit*/ TD::TD(MsgPtrT msg) +/*explicit*/ TD::TD(MsgPtrT const& msg) : TD(extractEpochMsg(msg)) { } diff --git a/src/vt/context/runnable_context/trace.h b/src/vt/context/runnable_context/trace.h index c63b733832..8e6e93d30e 100644 --- a/src/vt/context/runnable_context/trace.h +++ b/src/vt/context/runnable_context/trace.h @@ -44,7 +44,6 @@ #if !defined INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_TRACE_H #define INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_TRACE_H -#include "vt/context/runnable_context/base.h" #include "vt/trace/trace_common.h" #include "vt/messaging/envelope/envelope_get.h" #include "vt/registry/auto/auto_registry_common.h" @@ -58,7 +57,9 @@ namespace vt { namespace ctx { * * \brief Manages tracing a task's execution for outputting logs */ -struct Trace final : Base { +struct Trace { + + Trace() = default; /** * \brief Construct a new trace context (basic processing event) @@ -100,10 +101,10 @@ struct Trace final : Base { */ trace::TraceEventIDType getEvent() const { return event_; } - void begin() final override; - void end() final override; - void suspend() final override; - void resume() final override; + void begin(); + void end(); + void suspend(); + void resume(); private: /// Whether it's a collection or not @@ -126,7 +127,7 @@ struct Trace final : Base { #else -struct Trace : Base { +struct Trace { template Trace(Args&&... args) {} diff --git a/src/vt/messaging/active.cc b/src/vt/messaging/active.cc index b5c7de42dc..aeafcddbcb 100644 --- a/src/vt/messaging/active.cc +++ b/src/vt/messaging/active.cc @@ -890,7 +890,7 @@ bool ActiveMessenger::recvDataMsg( ); } -bool ActiveMessenger::processActiveMsg( +void ActiveMessenger::processActiveMsg( MsgSharedPtr const& base, NodeType const& from, bool insert, ActionType cont ) { @@ -913,18 +913,17 @@ bool ActiveMessenger::processActiveMsg( } if (deliver) { - return prepareActiveMsgToRun(base,from,insert,cont); + prepareActiveMsgToRun(base,from,insert,cont); } else { amForwardCounterGauge.incrementUpdate(base.size(), 1); if (cont != nullptr) { cont(); } - return false; } } -bool ActiveMessenger::prepareActiveMsgToRun( +void ActiveMessenger::prepareActiveMsgToRun( MsgSharedPtr const& base, NodeType const& in_from_node, bool insert, ActionType cont ) { @@ -937,8 +936,6 @@ bool ActiveMessenger::prepareActiveMsgToRun( auto const handler = envelopeGetHandler(msg->env); auto const epoch = envelopeIsEpochType(msg->env) ? envelopeGetEpoch(msg->env) : term::any_epoch_sentinel; - auto const is_tag = envelopeIsTagType(msg->env); - auto const tag = is_tag ? envelopeGetTag(msg->env) : no_tag; auto const from_node = is_bcast ? dest : in_from_node; if (!is_term || vt_check_enabled(print_term_msgs)) { @@ -950,56 +947,29 @@ bool ActiveMessenger::prepareActiveMsgToRun( ); } - bool const is_auto = HandlerManagerType::isHandlerAuto(handler); - bool const is_obj = HandlerManagerType::isHandlerObjGroup(handler); - bool has_handler = - (is_obj or is_auto) or theRegistry()->getHandler(handler, tag) != nullptr; - if (!is_term || vt_check_enabled(print_term_msgs)) { vt_debug_print( normal, active, - "prepareActiveMsgToRun: msg={}, handler={:x}, tag={}, is_auto={}, " - "is_obj_group={}, has_handler={}, insert={}\n", - print_ptr(msg), handler, tag, is_auto, is_obj, - has_handler, insert + "prepareActiveMsgToRun: msg={}, handler={:x}, insert={}\n", + print_ptr(msg), handler, insert ); } - if (has_handler) { - runnable::makeRunnable(base, not is_term, handler, from_node) - .withContinuation(cont) - .withTag(tag) - .withTDEpochFromMsg(is_term) - .withLBData(&bare_handler_lb_data_, bare_handler_dummy_elm_id_for_lb_data_) - .enqueue(); - - if (is_term) { - tdRecvCount.increment(1); - } - amHandlerCount.increment(1); + runnable::makeRunnable(base, not is_term, handler, from_node) + .withContinuation(cont) + .withTDEpochFromMsg(is_term) + .withLBData(&bare_handler_lb_data_, bare_handler_dummy_elm_id_for_lb_data_) + .enqueue(); - if (not is_term) { - theTerm()->consume(epoch,1,in_from_node); - theTerm()->hangDetectRecv(); - } - } else { - if (insert) { - auto iter = pending_handler_msgs_.find(handler); - if (iter == pending_handler_msgs_.end()) { - pending_handler_msgs_.emplace( - std::piecewise_construct, - std::forward_as_tuple(handler), - std::forward_as_tuple( - MsgContType{BufferedMsgType{base,from_node,cont}} - ) - ); - } else { - iter->second.push_back(BufferedMsgType{base,from_node,cont}); - } - } + if (is_term) { + tdRecvCount.increment(1); } + amHandlerCount.increment(1); - return has_handler; + if (not is_term) { + theTerm()->consume(epoch,1,in_from_node); + theTerm()->hangDetectRecv(); + } } bool ActiveMessenger::tryProcessIncomingActiveMsg() { @@ -1176,7 +1146,6 @@ bool ActiveMessenger::testPendingAsyncOps() { int ActiveMessenger::progress(TimeType current_time) { bool const started_irecv_active_msg = tryProcessIncomingActiveMsg(); bool const started_irecv_data_msg = tryProcessDataMsgRecv(); - processMaybeReadyHanTag(); bool const received_active_msg = testPendingActiveMsgAsyncRecv(); bool const received_data_msg = testPendingDataMsgAsyncRecv(); bool const general_async = testPendingAsyncOps(); @@ -1185,101 +1154,6 @@ int ActiveMessenger::progress(TimeType current_time) { received_active_msg or received_data_msg or general_async; } -void ActiveMessenger::processMaybeReadyHanTag() { - decltype(maybe_ready_tag_han_) maybe_ready = maybe_ready_tag_han_; - // Clear first so clearing doesn't happen after new entries may be added by an - // active message arriving - maybe_ready_tag_han_.clear(); - for (auto&& x : maybe_ready) { - deliverPendingMsgsHandler(std::get<0>(x), std::get<1>(x)); - } -} - -HandlerType ActiveMessenger::registerNewHandler( - ActiveClosureFnType fn, TagType const& tag -) { - return theRegistry()->registerNewHandler(fn, tag); -} - -HandlerType ActiveMessenger::collectiveRegisterHandler( - ActiveClosureFnType fn, TagType const& tag -) { - return theRegistry()->registerActiveHandler(fn, tag); -} - -void ActiveMessenger::swapHandlerFn( - HandlerType const han, ActiveClosureFnType fn, TagType const& tag -) { - vt_debug_print( - verbose, active, - "swapHandlerFn: han={}, tag={}\n", han, tag - ); - - theRegistry()->swapHandler(han, fn, tag); - - if (fn != nullptr) { - maybe_ready_tag_han_.push_back(ReadyHanTagType{han,tag}); - } -} - -void ActiveMessenger::deliverPendingMsgsHandler( - HandlerType const han, TagType const& tag -) { - vt_debug_print( - normal, active, - "deliverPendingMsgsHandler: han={}, tag={}\n", han, tag - ); - auto iter = pending_handler_msgs_.find(han); - if (iter != pending_handler_msgs_.end()) { - if (iter->second.size() > 0) { - for (auto cur = iter->second.begin(); cur != iter->second.end(); ) { - vt_debug_print( - verbose, active, - "deliverPendingMsgsHandler: msg={}, from={}\n", - print_ptr(cur->buffered_msg.get()), cur->from_node - ); - if ( - prepareActiveMsgToRun( - cur->buffered_msg, cur->from_node, false, cur->cont - ) - ) { - cur = iter->second.erase(cur); - } else { - ++cur; - } - } - } else { - pending_handler_msgs_.erase(iter); - } - } -} - -void ActiveMessenger::registerHandlerFn( - HandlerType const han, ActiveClosureFnType fn, TagType const& tag -) { - vt_debug_print( - verbose, active, - "registerHandlerFn: han={}, tag={}\n", han, tag - ); - - swapHandlerFn(han, fn, tag); - - if (fn != nullptr) { - maybe_ready_tag_han_.push_back(ReadyHanTagType{han,tag}); - } -} - -void ActiveMessenger::unregisterHandlerFn( - HandlerType const han, TagType const& tag -) { - vt_debug_print( - verbose, active, - "unregisterHandlerFn: han={}, tag={}\n", han, tag - ); - - return theRegistry()->unregisterHandlerFn(han, tag); -} - void ActiveMessenger::registerAsyncOp(std::unique_ptr in) { in_progress_ops.emplace(AsyncOpWrapper{std::move(in)}); } diff --git a/src/vt/messaging/active.h b/src/vt/messaging/active.h index 2b44025004..49aa04b43f 100644 --- a/src/vt/messaging/active.h +++ b/src/vt/messaging/active.h @@ -57,7 +57,6 @@ #include "vt/messaging/send_info.h" #include "vt/messaging/async_op_wrapper.h" #include "vt/event/event.h" -#include "vt/registry/registry.h" #include "vt/registry/auto/auto_registry_interface.h" #include "vt/trace/trace_common.h" #include "vt/utils/static_checks/functor.h" @@ -320,10 +319,7 @@ struct ActiveMessenger : runtime::component::PollableComponent using SendFnType = std::function; using UserSendFnType = std::function; using ContainerPendingType = std::unordered_map; - using MsgContType = std::list; - using ContWaitType = std::unordered_map; using ReadyHanTagType = std::tuple; - using MaybeReadyType = std::vector; using HandlerManagerType = HandlerManager; using PendingSendType = PendingSend; @@ -1354,65 +1350,6 @@ struct ActiveMessenger : runtime::component::PollableComponent */ int progress(TimeType current_time) override; - /** - * \internal - * \brief Register a bare handler - * - * \param[in] fn the function to register - * \param[in] tag the tag this handler will accept (\c vt::no_tag means any) - * - * \return the handler ID - */ - HandlerType registerNewHandler( - ActiveClosureFnType fn, TagType const& tag = no_tag - ); - - /** - * \internal - * \brief Swap the underlying handler function pointer - * - * \param[in] han the handler to swap function pointers - * \param[in] fn the new function pointer - * \param[in] tag the tag this handler will accept (\c vt::no_tag means any) - */ - void swapHandlerFn( - HandlerType const han, ActiveClosureFnType fn, TagType const& tag = no_tag - ); - - /** - * \internal - * \brief Un-register a bare handler - * - * \param[in] han the handler to de-register - * \param[in] tag the tag this handler will accept (\c vt::no_tag means any) - */ - void unregisterHandlerFn(HandlerType const han, TagType const& tag = no_tag); - - /** - * \internal - * \brief Register a handler function for existing handler - * - * \param[in] han the handler to swap function pointers - * \param[in] fn the new function pointer - * \param[in] tag the tag this handler will accept (\c vt::no_tag means any) - */ - void registerHandlerFn( - HandlerType const han, ActiveClosureFnType fn, TagType const& tag = no_tag - ); - - /** - * \internal - * \brief Register an active handler (collective) - * - * \param[in] fn the function pointer for the handler - * \param[in] tag the tag this handler will accept (\c vt::no_tag means any) - * - * \return the handler ID - */ - HandlerType collectiveRegisterHandler( - ActiveClosureFnType fn, TagType const& tag = no_tag - ); - /** * \internal * \brief Process an incoming active message @@ -1425,10 +1362,8 @@ struct ActiveMessenger : runtime::component::PollableComponent * \param[in] sender the sender of the message * \param[in] insert whether to insert the message if handler does not exist * \param[in] cont continuation after message is processed - * - * \return whether it was delivered locally */ - bool processActiveMsg( + void processActiveMsg( MsgSharedPtr const& base, NodeType const& sender, bool insert, ActionType cont = nullptr ); @@ -1441,32 +1376,12 @@ struct ActiveMessenger : runtime::component::PollableComponent * \param[in] from_node the node the message came from * \param[in] insert whether to insert the message if handler does not exist * \param[in] cont continuation after message is processed - * - * \return whether the message was delivered, false when handler does not exist */ - bool prepareActiveMsgToRun( + void prepareActiveMsgToRun( MsgSharedPtr const& base, NodeType const& from_node, bool insert, ActionType cont ); - /** - * \internal - * \brief Deliver pending messaging waiting for a handler to be registered - * - * \param[in] han the handler that will now accept - * \param[in] tag the tag for that handler - */ - void deliverPendingMsgsHandler( - HandlerType const han, TagType const& tag = no_tag - ); - - /** - * \internal - * \brief Process any messages that might be ready now (handler is now - * registered) - */ - void processMaybeReadyHanTag(); - /** * \internal * \brief Send message as low-level bytes after packing put bytes if needed @@ -1622,9 +1537,7 @@ struct ActiveMessenger : runtime::component::PollableComponent template void serialize(SerializerT& s) { - s | maybe_ready_tag_han_ - | pending_handler_msgs_ - | pending_recvs_ + s | pending_recvs_ | cur_direct_buffer_tag_ | in_progress_active_msg_irecv | in_progress_data_irecv @@ -1732,8 +1645,6 @@ struct ActiveMessenger : runtime::component::PollableComponent trace::UserEventIDType trace_asyncop = trace::no_user_event_id; # endif - MaybeReadyType maybe_ready_tag_han_ = {}; - ContWaitType pending_handler_msgs_ = {}; ContainerPendingType pending_recvs_ = {}; TagType cur_direct_buffer_tag_ = starting_direct_buffer_tag; RequestHolder in_progress_active_msg_irecv; diff --git a/src/vt/messaging/envelope/payload_envelope.h b/src/vt/messaging/envelope/payload_envelope.h index 6bcfebf6d8..09ec6e47a8 100644 --- a/src/vt/messaging/envelope/payload_envelope.h +++ b/src/vt/messaging/envelope/payload_envelope.h @@ -53,7 +53,7 @@ namespace vt { using PutPtrType = void*; using PutPtrConstType = void const*; using PutEnvSizeType = size_t; -using PutUnderEnvelopeT = Envelope; +using PutUnderEnvelopeT = EpochTagEnvelope; /** * \struct PutEnvelope @@ -75,8 +75,7 @@ struct PutEnvelope { TagType put_data_tag_; /**< The put tag */ }; -//using PutBasicEnvelope = PutEnvelope; -using PutShortEnvelope = PutEnvelope; +using PutShortEnvelope = PutEnvelope; using eEnvType = messaging::eEnvelopeType; /** diff --git a/src/vt/registry/auto/auto_registry.cc b/src/vt/registry/auto/auto_registry.cc index 9eceda1d16..6cdb9f0176 100644 --- a/src/vt/registry/auto/auto_registry.cc +++ b/src/vt/registry/auto/auto_registry.cc @@ -44,7 +44,6 @@ #include "vt/config.h" #include "vt/registry/auto/auto_registry_common.h" #include "vt/registry/auto/auto_registry_interface.h" -#include "vt/registry/registry.h" #include diff --git a/src/vt/registry/auto/auto_registry.h b/src/vt/registry/auto/auto_registry.h index fef2832a5a..36362d1bb3 100644 --- a/src/vt/registry/auto/auto_registry.h +++ b/src/vt/registry/auto/auto_registry.h @@ -47,7 +47,6 @@ #include "vt/config.h" #include "vt/registry/auto/auto_registry_common.h" #include "vt/registry/auto/auto_registry_general.h" -#include "vt/registry/registry.h" #include "vt/trace/trace.h" #include "vt/utils/demangle/demangle.h" diff --git a/src/vt/registry/auto/auto_registry_common.h b/src/vt/registry/auto/auto_registry_common.h index 52140ee1aa..d8eb56b66b 100644 --- a/src/vt/registry/auto/auto_registry_common.h +++ b/src/vt/registry/auto/auto_registry_common.h @@ -44,11 +44,10 @@ #if !defined INCLUDED_VT_REGISTRY_AUTO_AUTO_REGISTRY_COMMON_H #define INCLUDED_VT_REGISTRY_AUTO_AUTO_REGISTRY_COMMON_H -#include "vt/trace/trace_event.h" - #include "vt/config.h" +#include "vt/handler/handler.h" +#include "vt/trace/trace_event.h" #include "vt/activefn/activefn.h" -#include "vt/registry/registry.h" #include "vt/trace/trace.h" #include "vt/vrt/context/context_vrt_funcs.h" #include "vt/vrt/collection/active/active_funcs.h" diff --git a/src/vt/registry/auto/auto_registry_interface.h b/src/vt/registry/auto/auto_registry_interface.h index 11ef7d538c..5b1fb6dc70 100644 --- a/src/vt/registry/auto/auto_registry_interface.h +++ b/src/vt/registry/auto/auto_registry_interface.h @@ -46,7 +46,6 @@ #include "vt/registry/auto/auto_registry_common.h" #include "vt/config.h" -#include "vt/registry/registry.h" namespace vt { namespace auto_registry { diff --git a/src/vt/registry/auto/collection/auto_registry_collection.h b/src/vt/registry/auto/collection/auto_registry_collection.h index 742b46e1db..d025a07646 100644 --- a/src/vt/registry/auto/collection/auto_registry_collection.h +++ b/src/vt/registry/auto/collection/auto_registry_collection.h @@ -47,7 +47,6 @@ #include "vt/config.h" #include "vt/registry/auto/auto_registry_common.h" #include "vt/registry/auto/auto_registry_general.h" -#include "vt/registry/registry.h" #include "vt/activefn/activefn.h" #include "vt/vrt/collection/active/active_funcs.h" diff --git a/src/vt/registry/auto/functor/auto_registry_functor.h b/src/vt/registry/auto/functor/auto_registry_functor.h index a69d2ae43c..79c1221afe 100644 --- a/src/vt/registry/auto/functor/auto_registry_functor.h +++ b/src/vt/registry/auto/functor/auto_registry_functor.h @@ -46,7 +46,6 @@ #include "vt/config.h" #include "vt/registry/auto/auto_registry_common.h" -#include "vt/registry/registry.h" #include #include diff --git a/src/vt/registry/auto/index/auto_registry_index.h b/src/vt/registry/auto/index/auto_registry_index.h index d5d1029fbf..13a5415ec4 100644 --- a/src/vt/registry/auto/index/auto_registry_index.h +++ b/src/vt/registry/auto/index/auto_registry_index.h @@ -47,7 +47,6 @@ #include "vt/config.h" #include "vt/registry/auto/auto_registry_common.h" #include "vt/registry/auto/auto_registry_general.h" -#include "vt/registry/registry.h" namespace vt { namespace auto_registry { diff --git a/src/vt/registry/auto/index/auto_registry_index.impl.h b/src/vt/registry/auto/index/auto_registry_index.impl.h index 79289b124b..1ca22c5a14 100644 --- a/src/vt/registry/auto/index/auto_registry_index.impl.h +++ b/src/vt/registry/auto/index/auto_registry_index.impl.h @@ -47,7 +47,6 @@ #include "vt/config.h" #include "vt/registry/auto/auto_registry_common.h" #include "vt/registry/auto/auto_registry_general.h" -#include "vt/registry/registry.h" #include "vt/registry/auto/index/auto_registry_index.h" #include "vt/registry/auto/index/auto_registry_index_reg.h" diff --git a/src/vt/registry/auto/index/auto_registry_index_reg.h b/src/vt/registry/auto/index/auto_registry_index_reg.h index 19220b8a7a..36fbe6833d 100644 --- a/src/vt/registry/auto/index/auto_registry_index_reg.h +++ b/src/vt/registry/auto/index/auto_registry_index_reg.h @@ -47,7 +47,6 @@ #include "vt/config.h" #include "vt/registry/auto/auto_registry_common.h" #include "vt/registry/auto/auto_registry_general.h" -#include "vt/registry/registry.h" namespace vt { namespace auto_registry { diff --git a/src/vt/registry/auto/map/auto_registry_map.h b/src/vt/registry/auto/map/auto_registry_map.h index 4585f0995c..c81213f476 100644 --- a/src/vt/registry/auto/map/auto_registry_map.h +++ b/src/vt/registry/auto/map/auto_registry_map.h @@ -47,7 +47,6 @@ #include "vt/config.h" #include "vt/registry/auto/auto_registry_common.h" #include "vt/registry/auto/auto_registry_general.h" -#include "vt/registry/registry.h" #include "vt/topos/mapping/mapping_function.h" diff --git a/src/vt/registry/auto/rdma/auto_registry_rdma.h b/src/vt/registry/auto/rdma/auto_registry_rdma.h index 04ed7a0ee6..162d19a8a5 100644 --- a/src/vt/registry/auto/rdma/auto_registry_rdma.h +++ b/src/vt/registry/auto/rdma/auto_registry_rdma.h @@ -47,7 +47,6 @@ #include "vt/config.h" #include "vt/registry/auto/auto_registry_common.h" #include "vt/registry/auto/auto_registry_general.h" -#include "vt/registry/registry.h" #include "vt/activefn/activefn.h" #include "vt/vrt/collection/active/active_funcs.h" diff --git a/src/vt/registry/auto/vc/auto_registry_vc.h b/src/vt/registry/auto/vc/auto_registry_vc.h index a5850eb8dd..05c5d1d70a 100644 --- a/src/vt/registry/auto/vc/auto_registry_vc.h +++ b/src/vt/registry/auto/vc/auto_registry_vc.h @@ -47,7 +47,6 @@ #include "vt/config.h" #include "vt/registry/auto/auto_registry_common.h" #include "vt/registry/auto/auto_registry_general.h" -#include "vt/registry/registry.h" #include "vt/activefn/activefn.h" #include "vt/vrt/context/context_vrt_funcs.h" diff --git a/src/vt/registry/registry.cc b/src/vt/registry/registry.cc deleted file mode 100644 index ddf67052ed..0000000000 --- a/src/vt/registry/registry.cc +++ /dev/null @@ -1,132 +0,0 @@ -/* -//@HEADER -// ***************************************************************************** -// -// registry.cc -// 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 -*/ - -#include "vt/config.h" -#include "vt/registry/registry.h" - -namespace vt { namespace registry { - -HandlerType Registry::registerNewHandler( - ActiveClosureFnType fn, TagType const& tag, bool const& is_collective -) { - HandlerType new_handle = 0; - HandlerIdentifierType const& new_identifier = - is_collective ? cur_ident_collective_++ : cur_ident_++; - - HandlerManagerType::setHandlerIdentifier(new_handle, new_identifier); - - if (tag == no_tag) { - registered_[new_handle] = fn; - } else { - tagged_registered_[new_handle][tag] = fn; - } - - return new_handle; -} - -void Registry::swapHandler( - HandlerType const han, ActiveClosureFnType fn, TagType const& tag -) { - if (tag == no_tag) { - auto iter = registered_.find(han); - vtAssert( - iter != registered_.end(), "Handler must be registered" - ); - iter->second = fn; - } else { - if (fn == nullptr) { - auto tag_iter = tagged_registered_[han].find(tag); - if (tag_iter != tagged_registered_[han].end()) { - tagged_registered_[han].erase(tag_iter); - if (tagged_registered_[han].size() == 0) { - tagged_registered_.erase(tagged_registered_.find(han)); - } - } - } else { - tagged_registered_[han][tag] = fn; - } - } -} - -void Registry::unregisterHandlerFn( - HandlerType const han, TagType const& tag -) { - swapHandler(han, nullptr, tag); -} - -HandlerType Registry::registerActiveHandler( - ActiveClosureFnType fn, TagType const& tag -) { - return registerNewHandler(fn, tag, true); -} - -ActiveClosureFnType Registry::getHandlerNoTag(HandlerType const han) { - auto iter = registered_.find(han); - if (iter != registered_.end()) { - return iter->second; - } else { - return nullptr; - } -} - -ActiveClosureFnType Registry::getHandler( - HandlerType const han, TagType const& tag -) { - if (tag == no_tag) { - return getHandlerNoTag(han); - } else { - auto tag_iter = tagged_registered_.find(han); - if (tag_iter == tagged_registered_.end()) { - return getHandlerNoTag(han); - } else { - auto iter = tag_iter->second.find(tag); - if (iter != tag_iter->second.end()) { - return iter->second; - } else { - return getHandlerNoTag(han); - } - } - } -} - -}} //end namespace vt::registry diff --git a/src/vt/registry/registry.h b/src/vt/registry/registry.h deleted file mode 100644 index bcd79f0670..0000000000 --- a/src/vt/registry/registry.h +++ /dev/null @@ -1,169 +0,0 @@ -/* -//@HEADER -// ***************************************************************************** -// -// registry.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_REGISTRY_REGISTRY_H -#define INCLUDED_VT_REGISTRY_REGISTRY_H - -#include -#include -#include - -#include "vt/config.h" -#include "vt/activefn/activefn.h" -#include "vt/handler/handler.h" -#include "vt/runtime/component/component.h" - -namespace vt { namespace registry { - -/** - * \struct Registry - * - * \brief A VT component that manages registered active handlers. - */ -struct Registry : runtime::component::Component { - using HandlerManagerType = HandlerManager; - using HandlerBitsType = eHandlerBits; - using TaggerHandlerType = std::tuple; - using ContainerType = std::unordered_map; - using TagContainerType = std::unordered_map; - using HanTagContainerType = std::unordered_map; - - /** - * \internal \brief System call to construct a registry - */ - Registry() = default; - - std::string name() override { return "Registry"; } - - /** - * \brief Register a new handler - * - * \param[in] fn the active function pointer - * \param[in] tag relevant message tag for delivery - * \param[in] is_collective whether it's a collective registration - * - * \return the handler ID - */ - HandlerType registerNewHandler( - ActiveClosureFnType fn, TagType const& tag = no_tag, - bool const& is_collective = false - ); - - /** - * \brief Unregister a handler - * - * \param[in] han the handler ID - * \param[in] tag relevant message tag for delivery - */ - void unregisterHandlerFn( - HandlerType const han, TagType const& tag = no_tag - ); - - /** - * \brief Swap underlying handler out for registered handler ID - * - * \param[in] han the handler ID - * \param[in] fn the active function to attach - * \param[in] tag tag to associate - */ - void swapHandler( - HandlerType const han, ActiveClosureFnType fn, TagType const& tag = no_tag - ); - - /** - * \brief Registry an active handler - * - * \param[in] fn the active handler - * \param[in] tag relevant message tag - * - * \return the handler ID - */ - HandlerType registerActiveHandler( - ActiveClosureFnType fn, TagType const& tag = no_tag - ); - - /** - * \brief Get active function for handler - * - * \param[in] han the handler ID - * \param[in] tag the relevant tag - * - * \return the active function - */ - ActiveClosureFnType getHandler( - HandlerType const han, TagType const& tag = no_tag - ); - - /** - * \brief Get active function for handler - * - * \param[in] han the handler ID - * - * \return the active function - */ - ActiveClosureFnType getHandlerNoTag(HandlerType const han); - - template - void serialize(SerializerT& s) { - s | registered_ - | tagged_registered_ - | cur_ident_collective_ - | cur_ident_; - } - -private: - ContainerType registered_; - HanTagContainerType tagged_registered_; - HandlerIdentifierType cur_ident_collective_ = first_handle_identifier; - HandlerIdentifierType cur_ident_ = first_handle_identifier; -}; - -}} //end namespace vt::registry - -namespace vt { - -extern registry::Registry* theRegistry(); - -} // end namespace vt - -#endif /*INCLUDED_VT_REGISTRY_REGISTRY_H*/ diff --git a/src/vt/runnable/make_runnable.h b/src/vt/runnable/make_runnable.h index 79442c790d..d019ad45b9 100644 --- a/src/vt/runnable/make_runnable.h +++ b/src/vt/runnable/make_runnable.h @@ -47,7 +47,6 @@ #include "vt/runnable/runnable.h" #include "vt/context/runnable_context/td.h" #include "vt/context/runnable_context/trace.h" -#include "vt/context/runnable_context/from_node.h" #include "vt/context/runnable_context/set_context.h" #include "vt/context/runnable_context/collection.h" #include "vt/context/runnable_context/lb_data.h" @@ -74,13 +73,14 @@ struct RunnableMaker { * \param[in] in_from_node the from node for the runnable */ RunnableMaker( - std::unique_ptr in_impl, MsgSharedPtr const& in_msg, + RunnableNew* in_impl, MsgSharedPtr const& in_msg, HandlerType in_handler, NodeType in_from_node - ) : impl_(std::move(in_impl)), + ) : impl_(in_impl), msg_(in_msg), handler_(in_handler), is_void_(in_msg == nullptr), - from_node_(in_from_node) + from_node_(in_from_node), + has_msg_(in_msg != nullptr) { } RunnableMaker(RunnableMaker const&) = delete; RunnableMaker(RunnableMaker&&) = default; @@ -97,7 +97,7 @@ struct RunnableMaker { * \param[in] cont the continuation */ RunnableMaker&& withContinuation(ActionType cont) { - impl_->template addContext(cont); + impl_->addContextCont(cont); return std::move(*this); } @@ -108,8 +108,9 @@ struct RunnableMaker { * \param[in] is_term whether it's a termination message */ RunnableMaker&& withTDEpoch(EpochType ep, bool is_term = false) { + is_term_ = is_term; if (not is_term) { - impl_->template addContext(ep); + impl_->addContextTD(ep); } return std::move(*this); } @@ -120,8 +121,9 @@ struct RunnableMaker { * \param[in] is_term whether it's a termination message */ RunnableMaker&& withTDEpochFromMsg(bool is_term = false) { + is_term_ = is_term; if (not is_term) { - impl_->template addContext(msg_); + impl_->addContextTD(msg_); } return std::move(*this); } @@ -145,7 +147,7 @@ struct RunnableMaker { */ template RunnableMaker&& withCollection(ElmT* elm) { - impl_->template addContext>(elm); + impl_->addContextCol(elm); set_handler_ = true; if (handler_ != uninitialized_handler) { @@ -170,7 +172,7 @@ struct RunnableMaker { template RunnableMaker&& withLBData(ElmT* elm, MsgU* msg) { #if vt_check_enabled(lblite) - impl_->template addContext(elm, msg); + impl_->addContextLB(elm, msg); #endif return std::move(*this); } @@ -194,7 +196,7 @@ struct RunnableMaker { template RunnableMaker&& withLBData(LBDataT* lb_data, T elm_id) { #if vt_check_enabled(lblite) - impl_->template addContext(lb_data, elm_id); + impl_->addContextLB(lb_data, elm_id); #endif return std::move(*this); } @@ -207,11 +209,12 @@ struct RunnableMaker { template RunnableMaker&& withLBData(ElmT* elm) { #if vt_check_enabled(lblite) - impl_->template addContext(elm, msg_.get()); + impl_->addContextLB(elm, msg_.get()); #endif return std::move(*this); } +#if vt_check_enabled(trace_enabled) /** * \brief Add a trace index (for collection elements) * @@ -225,21 +228,12 @@ struct RunnableMaker { trace::TraceEventIDType trace_event, uint64_t idx1, uint64_t idx2, uint64_t idx3, uint64_t idx4 ) { - impl_->template addContext( + impl_->addContextTrace( msg_, trace_event, handler_, from_node_, idx1, idx2, idx3, idx4 ); return std::move(*this); } - - /** - * \brief Add a tag to the handler - * - * \param[in] tag the tag - */ - RunnableMaker&& withTag(TagType tag) { - tag_ = tag; - return std::move(*this); - } +#endif /** * \brief Run or enqueue the runnable depending on argument @@ -261,6 +255,8 @@ struct RunnableMaker { void run() { setup(); impl_->run(); + delete impl_; + impl_ = nullptr; is_done_ = true; } @@ -286,20 +282,21 @@ struct RunnableMaker { */ void setup() { if (not set_handler_) { - impl_->setupHandler(handler_, is_void_, tag_); + impl_->setupHandler(handler_, is_void_); set_handler_ = true; } } private: - std::unique_ptr impl_ = nullptr; - MsgSharedPtr msg_ = nullptr; + RunnableNew* impl_ = nullptr; + MsgSharedPtr const& msg_; HandlerType handler_ = uninitialized_handler; bool set_handler_ = false; - TagType tag_ = no_tag; bool is_void_ = false; NodeType from_node_ = uninitialized_destination; bool is_done_ = false; + bool is_term_ = false; + bool has_msg_ = true; }; /** @@ -317,16 +314,17 @@ template RunnableMaker makeRunnable( MsgSharedPtr const& msg, bool is_threaded, HandlerType handler, NodeType from ) { - auto r = std::make_unique(msg, is_threaded); + auto r = new RunnableNew(msg, is_threaded); +#if vt_check_enabled(trace_enabled) auto const han_type = HandlerManager::getHandlerRegistryType(handler); if (han_type == auto_registry::RegistryTypeEnum::RegVrt or han_type == auto_registry::RegistryTypeEnum::RegGeneral or han_type == auto_registry::RegistryTypeEnum::RegObjGroup) { - r->template addContext(msg, handler, from); + r->addContextTrace(msg, handler, from); } - r->template addContext(from); - r->template addContext(r.get()); - return RunnableMaker{std::move(r), msg, handler, from}; +#endif + r->addContextSetContext(r, from); + return RunnableMaker{r, msg, handler, from}; } /** @@ -342,11 +340,10 @@ inline RunnableMaker makeRunnableVoid( bool is_threaded, HandlerType handler, NodeType from ) { // These are currently only types of registry entries that can be void - auto r = std::make_unique(is_threaded); + auto r = new RunnableNew(is_threaded); // @todo: figure out how to trace this? - r->template addContext(from); - r->template addContext(r.get()); - return RunnableMaker{std::move(r), nullptr, handler, from}; + r->addContextSetContext(r, from); + return RunnableMaker{r, nullptr, handler, from}; } }} /* end namespace vt::runnable */ diff --git a/src/vt/runnable/make_runnable.impl.h b/src/vt/runnable/make_runnable.impl.h index a1adcb034c..bb6ec61930 100644 --- a/src/vt/runnable/make_runnable.impl.h +++ b/src/vt/runnable/make_runnable.impl.h @@ -52,10 +52,14 @@ namespace vt { namespace runnable { template void RunnableMaker::enqueue() { setup(); - if (msg_ != nullptr) { - theSched()->enqueue(msg_, std::move(impl_)); + if (has_msg_) { +#if vt_check_enabled(priorities) + theSched()->enqueue(msg_, impl_); +#else + theSched()->enqueue(is_term_, impl_); +#endif } else { - theSched()->enqueue(std::move(impl_)); + theSched()->enqueue(impl_); } is_done_ = true; } diff --git a/src/vt/runnable/runnable.cc b/src/vt/runnable/runnable.cc index a867cc4d6f..15ba22af36 100644 --- a/src/vt/runnable/runnable.cc +++ b/src/vt/runnable/runnable.cc @@ -53,7 +53,7 @@ namespace vt { namespace runnable { -void RunnableNew::setupHandler(HandlerType handler, bool is_void, TagType tag) { +void RunnableNew::setupHandler(HandlerType handler, bool is_void) { using HandlerManagerType = HandlerManager; bool const is_obj = HandlerManagerType::isHandlerObjGroup(handler); @@ -75,7 +75,7 @@ void RunnableNew::setupHandler(HandlerType handler, bool is_void, TagType tag) { } return; - } else if (is_auto) { + } else { bool const is_base_msg_derived = HandlerManagerType::isHandlerBaseMsgDerived(handler); if (is_base_msg_derived) { @@ -87,10 +87,6 @@ void RunnableNew::setupHandler(HandlerType handler, bool is_void, TagType tag) { auto const& func = auto_registry::getScatterAutoHandler(handler); task_ = [=, &func] { func->dispatch(msg_.get(), nullptr); }; return; - } else { - auto typed_func = theRegistry()->getHandler(handler, tag); - task_ = [=] { typed_func(msg_.get()); }; - return; } } } else { @@ -137,6 +133,7 @@ void RunnableNew::setupHandlerElement( } void RunnableNew::run() { +#if vt_check_enabled(fcontext) vtAbortIf( done_ and not suspended_, "Runnable task must either be not done (finished execution) or suspended" @@ -147,12 +144,17 @@ void RunnableNew::run() { "start running task={}, done={}, suspended={}\n", print_ptr(this), done_, suspended_ ); +#endif +#if vt_check_enabled(fcontext) if (suspended_) { resume(); } else { begin(); } +#else + begin(); +#endif vtAssert(task_ != nullptr, "Must have a valid task to run"); @@ -178,54 +180,103 @@ void RunnableNew::run() { } else #endif { +#if vt_check_enabled(fcontext) // force use this for when fcontext is disabled to avoid compiler warning vt_force_use(is_threaded_, tid_) +#endif + task_(); + +#if vt_check_enabled(fcontext) done_ = true; +#endif } +#if vt_check_enabled(fcontext) if (done_) { end(); } else { suspended_ = true; suspend(); } +#else + end(); +#endif +#if vt_check_enabled(fcontext) vt_debug_print( terse, context, "done running task={}, done={}, suspended={}\n", print_ptr(this), done_, suspended_ ); +#endif } void RunnableNew::begin() { - for (auto&& ctx : contexts_) { - ctx->begin(); - } + contexts_.setcontext.begin(); + if (contexts_.has_td) contexts_.td.begin(); + if (contexts_.has_col) contexts_.col.begin(); + if (contexts_.has_lb) contexts_.lb.begin(); +#if vt_check_enabled(trace_enabled) + if (contexts_.has_trace) contexts_.trace.begin(); +#endif } void RunnableNew::end() { - for (auto&& ctx : contexts_) { - ctx->end(); - } + contexts_.setcontext.end(); + if (contexts_.has_td) contexts_.td.end(); + if (contexts_.has_col) contexts_.col.end(); + if (contexts_.has_cont) contexts_.cont.end(); + if (contexts_.has_lb) contexts_.lb.end(); +#if vt_check_enabled(trace_enabled) + if (contexts_.has_trace) contexts_.trace.end(); +#endif } void RunnableNew::suspend() { - for (auto&& ctx : contexts_) { - ctx->suspend(); - } +#if vt_check_enabled(fcontext) + contexts_.setcontext.suspend(); + if (contexts_.has_td) contexts_.td.suspend(); + if (contexts_.has_col) contexts_.col.suspend(); + if (contexts_.has_lb) contexts_.lb.suspend(); + +# if vt_check_enabled(trace_enabled) + if (contexts_.has_trace) contexts_.trace.suspend(); +# endif +#endif } void RunnableNew::resume() { - for (auto&& ctx : contexts_) { - ctx->resume(); - } +#if vt_check_enabled(fcontext) + contexts_.setcontext.resume(); + if (contexts_.has_td) contexts_.td.resume(); + if (contexts_.has_col) contexts_.col.resume(); + if (contexts_.has_lb) contexts_.lb.resume(); + +# if vt_check_enabled(trace_enabled) + if (contexts_.has_trace) contexts_.trace.resume(); +# endif +#endif } void RunnableNew::send(elm::ElementIDStruct elm, MsgSizeType bytes) { - for (auto&& ctx : contexts_) { - ctx->send(elm, bytes); - } + if (contexts_.has_lb) contexts_.lb.send(elm, bytes); +} + +/*static*/ void* RunnableNew::operator new(std::size_t sz) { + return RunnableNewAlloc::runnable->alloc(sz,0); } +/*static*/ void RunnableNew::operator delete(void* ptr) { + RunnableNewAlloc::runnable->dealloc(ptr); +} + +/*static*/ +std::unique_ptr> +RunnableNewAlloc::runnable = std::make_unique< + pool::MemoryPoolEqual +>(256); + }} /* end namespace vt::runnable */ + +#include "vt/pool/static_sized/memory_pool_equal.cc" diff --git a/src/vt/runnable/runnable.h b/src/vt/runnable/runnable.h index 3634fa7e57..8691457262 100644 --- a/src/vt/runnable/runnable.h +++ b/src/vt/runnable/runnable.h @@ -45,7 +45,13 @@ #define INCLUDED_VT_RUNNABLE_RUNNABLE_H #include "vt/messaging/message/smart_ptr.h" -#include "vt/context/runnable_context/base.h" +#include "vt/context/runnable_context/td.h" +#include "vt/context/runnable_context/trace.h" +#include "vt/context/runnable_context/set_context.h" +#include "vt/context/runnable_context/collection.h" +#include "vt/context/runnable_context/lb_data.h" +#include "vt/context/runnable_context/continuation.h" +#include "vt/pool/static_sized/memory_pool_equal.h" #include "vt/elm/elm_id.h" // fwd-declarations for the element types @@ -61,6 +67,26 @@ struct UntypedCollection; namespace vt { namespace runnable { +namespace detail { + +struct Contexts { +#if vt_check_enabled(trace_enabled) + bool has_trace = false; + ctx::Trace trace; +#endif + ctx::SetContext setcontext; + bool has_td = false; + ctx::TD td; + bool has_cont = false; + ctx::Continuation cont; + bool has_col = false; + ctx::Collection col; + bool has_lb = false; + ctx::LBData lb; +}; + +} /* end namespace detail */ + /** * \struct RunnableNew * @@ -68,8 +94,6 @@ namespace vt { namespace runnable { * with it to run it independently of the where in the stack it was created. */ struct RunnableNew { - using CtxBasePtr = std::unique_ptr; - template using FnParamType = void(*)(Args...); @@ -81,8 +105,10 @@ struct RunnableNew { */ template RunnableNew(MsgSharedPtr const& in_msg, bool in_is_threaded) - : msg_(in_msg.template to()), - is_threaded_(in_is_threaded) + : msg_(in_msg.template to()) +#if vt_check_enabled(fcontext) + , is_threaded_(in_is_threaded) +#endif { } /** @@ -91,7 +117,9 @@ struct RunnableNew { * \param[in] in_is_threaded whether the handler can be run with a thread */ explicit RunnableNew(bool in_is_threaded) +#if vt_check_enabled(fcontext) : is_threaded_(in_is_threaded) +#endif { } RunnableNew(RunnableNew&&) = default; @@ -101,15 +129,60 @@ struct RunnableNew { public: /** - * \brief Add a new context for this handler + * \brief Add a new \c SetContext for this handler * * \param[in] args arguments to build the context, forwarded to constructor of * \c T */ - template - void addContext(Args&&... args) { - contexts_.emplace_back(std::make_unique(std::forward(args)...)); - } + template + void addContextSetContext(Args&&... args); + + /** + * \brief Add a new \c TD for this handler + * + * \param[in] args arguments to build the context, forwarded to constructor of + * \c T + */ + template + void addContextTD(Args&&... args); + + /** + * \brief Add a new \c Cont for this handler + * + * \param[in] args arguments to build the context, forwarded to constructor of + * \c T + */ + template + void addContextCont(Args&&... args); + + /** + * \brief Add a new \c Col for this handler + * + * \param[in] args arguments to build the context, forwarded to constructor of + * \c T + */ + template + void addContextCol(Args&&... args); + + /** + * \brief Add a new \c LB for this handler + * + * \param[in] args arguments to build the context, forwarded to constructor of + * \c T + */ + template + void addContextLB(Args&&... args); + +#if vt_check_enabled(trace_enabled) + /** + * \brief Add a new \c Trace for this handler + * + * \param[in] args arguments to build the context, forwarded to constructor of + * \c T + */ + template + void addContextTrace(Args&&... args); +#endif /** * \brief Set up a handler to run on an collection object @@ -134,11 +207,8 @@ struct RunnableNew { * * \param[in] handler the handler ID bits * \param[in] is_void whether it's a void handler w/o an associated message - * \param[in] tag an optional tag */ - void setupHandler( - HandlerType handler, bool is_void = false, TagType tag = no_tag - ); + void setupHandler(HandlerType handler, bool is_void = false); /** * \brief Run the task! @@ -149,6 +219,7 @@ struct RunnableNew { */ void run(); +#if vt_check_enabled(fcontext) /** * \brief Get the thread ID associated with the runnable. * @@ -158,6 +229,7 @@ struct RunnableNew { * \return the thread ID */ ThreadIDType getThreadID() const { return tid_; } +#endif private: /** @@ -213,6 +285,7 @@ struct RunnableNew { */ BaseMsgType* getMsg() const { return msg_.get(); } +#if vt_check_enabled(fcontext) /** * \brief Check if this runnable is complete or not * @@ -231,6 +304,7 @@ struct RunnableNew { * \return return if it is suspended */ bool isSuspended() const { return suspended_; } +#endif /** * \brief Set an explicit task for the runnable bypassing the handler @@ -241,14 +315,36 @@ struct RunnableNew { task_ = task_in; } + /** + * \internal \brief Operator new for runnables targeting pool + * + * \param[in] sz the allocation size + * + * \return the new allocation + */ + static void* operator new(std::size_t sz); + + /** + * \internal \brief Operator develop for runnables + * + * \param[in] ptr the pointer + */ + static void operator delete(void* ptr); + private: + detail::Contexts contexts_; /**< The contexts */ MsgSharedPtr msg_ = nullptr; /**< The associated message */ - bool is_threaded_ = false; /**< Whether ULTs are supported */ - std::vector contexts_; /**< Vector of contexts */ ActionType task_ = nullptr; /**< The runnable's task */ +#if vt_check_enabled(fcontext) + bool is_threaded_ = false; /**< Whether ULTs are supported */ bool done_ = false; /**< Whether task is complete */ bool suspended_ = false; /**< Whether task is suspended */ ThreadIDType tid_ = no_thread_id; /**< The thread ID for the task */ +#endif +}; + +struct RunnableNewAlloc { + static std::unique_ptr> runnable; }; }} /* end namespace vt::runnable */ diff --git a/src/vt/runnable/runnable.impl.h b/src/vt/runnable/runnable.impl.h index 647cb4660f..3fb93ac5f0 100644 --- a/src/vt/runnable/runnable.impl.h +++ b/src/vt/runnable/runnable.impl.h @@ -50,17 +50,67 @@ namespace vt { namespace runnable { -template -T* RunnableNew::get() { - for (auto&& ctx : contexts_) { - auto t = dynamic_cast(ctx.get()); - if (t) { - return t; - } - } - return nullptr; +template <> +inline ctx::SetContext* RunnableNew::get() { + return &contexts_.setcontext; } +template <> +inline ctx::LBData* RunnableNew::get() { + if (contexts_.has_lb) + return &contexts_.lb; + else + return nullptr; +} + +#if vt_check_enabled(trace_enabled) +template <> +inline ctx::Trace* RunnableNew::get() { + if (contexts_.has_trace) + return &contexts_.trace; + else + return nullptr; +} +#endif + + +template +void RunnableNew::addContextSetContext(Args&&... args) { + contexts_.setcontext = ctx::SetContext{std::forward(args)...}; +} + +template +void RunnableNew::addContextTD(Args&&... args) { + contexts_.td = ctx::TD{std::forward(args)...}; + contexts_.has_td = true; +} + +template +void RunnableNew::addContextCont(Args&&... args) { + contexts_.cont = ctx::Continuation{std::forward(args)...}; + contexts_.has_cont = true; +} + +template +void RunnableNew::addContextCol(Args&&... args) { + contexts_.col = ctx::Collection{std::forward(args)...}; + contexts_.has_col = true; +} + +template +void RunnableNew::addContextLB(Args&&... args) { + contexts_.lb = ctx::LBData{std::forward(args)...}; + contexts_.has_lb = true; +} + +#if vt_check_enabled(trace_enabled) +template +void RunnableNew::addContextTrace(Args&&... args) { + contexts_.trace = ctx::Trace{std::forward(args)...}; + contexts_.has_trace = true; +} +#endif + }} /* end namespace vt::runnable */ #endif /*INCLUDED_VT_RUNNABLE_RUNNABLE_IMPL_H*/ diff --git a/src/vt/runtime/runtime.cc b/src/vt/runtime/runtime.cc index fcaa3812c9..48a23db6a0 100644 --- a/src/vt/runtime/runtime.cc +++ b/src/vt/runtime/runtime.cc @@ -45,7 +45,6 @@ #include "vt/runtime/runtime.h" #include "vt/context/context.h" #include "vt/context/context_attorney.h" -#include "vt/registry/registry.h" #include "vt/messaging/active.h" #include "vt/event/event.h" #include "vt/termination/termination.h" @@ -680,10 +679,6 @@ void Runtime::initializeComponents() { phase::PhaseManager // For outputting memory at phase boundaries >{}); - p_->registerComponent(&theRegistry, Deps< - ctx::Context // Everything depends on theContext - >{}); - p_->registerComponent(&thePool, Deps< ctx::Context // Everything depends on theContext >{}); @@ -730,8 +725,7 @@ void Runtime::initializeComponents() { # endif ctx::Context, // Everything depends on theContext event::AsyncEvent, // Depends on event to send messages - pool::Pool, // Depends on pool for message allocation - registry::Registry // Depends on registry for handlers + pool::Pool // Depends on pool for message allocation >{} ); @@ -887,7 +881,6 @@ void Runtime::initializeComponents() { p_->add(); p_->add(); p_->add(); - p_->add(); p_->add(); p_->add(); # if vt_check_enabled(trace_enabled) @@ -909,7 +902,6 @@ void Runtime::initializeComponents() { p_->add(); p_->add(); p_->add(); - p_->add(); p_->add(); p_->add(); p_->add(); @@ -1112,10 +1104,6 @@ void Runtime::printMemoryFootprint() const { printComponentFootprint( static_cast(base) ); - } else if (name == "Registry") { - printComponentFootprint( - static_cast(base) - ); } else if (name == "Scheduler") { printComponentFootprint( static_cast(base) diff --git a/src/vt/runtime/runtime.h b/src/vt/runtime/runtime.h index 00f2a9162f..b2a4c8d2c5 100644 --- a/src/vt/runtime/runtime.h +++ b/src/vt/runtime/runtime.h @@ -395,7 +395,6 @@ struct Runtime { public: ComponentPtrType theArgConfig = nullptr; - ComponentPtrType theRegistry = nullptr; ComponentPtrType theMsg = nullptr; ComponentPtrType theContext = nullptr; ComponentPtrType theEvent = nullptr; diff --git a/src/vt/runtime/runtime_component_fwd.h b/src/vt/runtime/runtime_component_fwd.h index 93cf5153ed..b54bc264b0 100644 --- a/src/vt/runtime/runtime_component_fwd.h +++ b/src/vt/runtime/runtime_component_fwd.h @@ -52,9 +52,6 @@ namespace vt { namespace arguments { struct ArgConfig; } -namespace registry { -struct Registry; -} namespace messaging { struct ActiveMessenger; } diff --git a/src/vt/runtime/runtime_get.cc b/src/vt/runtime/runtime_get.cc index 670f4f3e45..8aa6dab0c2 100644 --- a/src/vt/runtime/runtime_get.cc +++ b/src/vt/runtime/runtime_get.cc @@ -49,7 +49,6 @@ #include "vt/utils/tls/tls.h" #include "vt/vrt/context/context_vrtmanager.h" #include "vt/context/context.h" -#include "vt/registry/registry.h" #include "vt/messaging/active.h" #include "vt/event/event.h" #include "vt/termination/term_headers.h" @@ -119,7 +118,6 @@ event::AsyncEvent* theEvent() { return CUR_RT->theEvent; messaging::ActiveMessenger* theMsg() { return CUR_RT->theMsg; } param::Param* theParam() { return CUR_RT->theParam; } rdma::RDMAManager* theRDMA() { return CUR_RT->theRDMA; } -registry::Registry* theRegistry() { return CUR_RT->theRegistry; } sched::Scheduler* theSched() { return CUR_RT->theSched; } term::TerminationDetector* theTerm() { return CUR_RT->theTerm; } location::LocationManager* theLocMan() { return CUR_RT->theLocMan; } diff --git a/src/vt/scheduler/base_unit.cc b/src/vt/scheduler/base_unit.cc index 2f7901b149..3a4292d289 100644 --- a/src/vt/scheduler/base_unit.cc +++ b/src/vt/scheduler/base_unit.cc @@ -54,7 +54,11 @@ void BaseUnit::execute() { if (not r_->isDone()) { auto tid = r_->getThreadID(); theSched()->suspend(tid, std::move(r_)); + } else { + delete r_; } + #else + delete r_; #endif } else if (work_) { work_(); diff --git a/src/vt/scheduler/base_unit.h b/src/vt/scheduler/base_unit.h index 86519b0d9d..027485e028 100644 --- a/src/vt/scheduler/base_unit.h +++ b/src/vt/scheduler/base_unit.h @@ -58,7 +58,7 @@ namespace vt { namespace sched { * to a runnable or contains a general lambda to execute. */ struct BaseUnit { - using RunnablePtrType = std::unique_ptr; + using RunnablePtrType = runnable::RunnableNew*; BaseUnit() = default; @@ -69,7 +69,7 @@ struct BaseUnit { * \param[in] in_r the runnable moved in */ BaseUnit(bool in_is_term, RunnablePtrType in_r) - : r_(std::move(in_r)), + : r_(in_r), is_term_(in_is_term) { } diff --git a/src/vt/scheduler/scheduler.cc b/src/vt/scheduler/scheduler.cc index fe574166c2..ced76058a2 100644 --- a/src/vt/scheduler/scheduler.cc +++ b/src/vt/scheduler/scheduler.cc @@ -275,7 +275,7 @@ void Scheduler::runSchedulerOnceImpl(bool msg_only) { */ UnitType work = work_queue_.pop(); runWorkUnit(work); - + } else { // Enter idle state immediately after processing if relevant. if (not is_idle_minus_term and num_term_msgs_ == work_queue_.size()) { is_idle_minus_term = true; diff --git a/src/vt/scheduler/scheduler.h b/src/vt/scheduler/scheduler.h index 4c48cff718..45e4fde9c8 100644 --- a/src/vt/scheduler/scheduler.h +++ b/src/vt/scheduler/scheduler.h @@ -114,7 +114,7 @@ struct Scheduler : runtime::component::Component { using TriggerType = std::function; using TriggerContainerType = std::list; using EventTriggerContType = std::vector; - using RunnablePtrType = std::unique_ptr; + using RunnablePtrType = runnable::RunnableNew*; struct SchedulerLoopGuard { SchedulerLoopGuard(Scheduler* scheduler); @@ -247,6 +247,15 @@ struct Scheduler : runtime::component::Component { */ void printMemoryUsage(); + /** + * \brief Enqueue an action without a message. + * + * \param[in] is_term whether it is a termination message or not + * \param[in] r the runnable + */ + template + void enqueue(bool is_term, RunT r); + /** * \brief Enqueue an action associated with a prioritized message. The action * will be enqueued with the priority found on the message. @@ -265,7 +274,7 @@ struct Scheduler : runtime::component::Component { * \param[in] r the runnable to execute later */ template - void enqueue(messaging::MsgSharedPtr msg, RunT r); + void enqueue(messaging::MsgSharedPtr const& msg, RunT r); /** * \brief Get the work queue size diff --git a/src/vt/scheduler/scheduler.impl.h b/src/vt/scheduler/scheduler.impl.h index 1e0c9b7520..c7834bbd4e 100644 --- a/src/vt/scheduler/scheduler.impl.h +++ b/src/vt/scheduler/scheduler.impl.h @@ -87,6 +87,14 @@ void runInEpochRooted(std::string const& label, Callable&& fn) { namespace vt { namespace sched { +template +void Scheduler::enqueue(bool is_term, RunT r) { + if (is_term) { + num_term_msgs_++; + } + work_queue_.emplace(UnitType(is_term, r)); +} + template void Scheduler::enqueue(MsgT* msg, RunT r) { bool const is_term = envelopeIsTerm(msg->env); @@ -104,7 +112,8 @@ void Scheduler::enqueue(MsgT* msg, RunT r) { } template -void Scheduler::enqueue(MsgSharedPtr msg, RunT r) { +void Scheduler::enqueue(MsgSharedPtr const& msg, RunT r) { +# if vt_check_enabled(priorities) // // Assume that MsgSharedPtr is already captured in the action. // @@ -112,6 +121,10 @@ void Scheduler::enqueue(MsgSharedPtr msg, RunT r) { // could be dispatched directly based on type/state-bits // enqueue(msg.get(), std::move(r)); +#else + bool const is_term = envelopeIsTerm(msg->env); + enqueue(is_term, r); +#endif } template diff --git a/src/vt/scheduler/suspended_units.h b/src/vt/scheduler/suspended_units.h index ebb7fb5f27..f61aabeddf 100644 --- a/src/vt/scheduler/suspended_units.h +++ b/src/vt/scheduler/suspended_units.h @@ -62,7 +62,7 @@ namespace detail { * until is ready to resume */ struct SuspendedRunnable { - using RunnablePtrType = std::unique_ptr; + using RunnablePtrType = runnable::RunnableNew*; /** * \brief Construct a new suspended runnable @@ -90,7 +90,7 @@ struct SuspendedRunnable { * calls \c resumeRunnable on it with the appropriate thread ID. */ struct SuspendedUnits { - using RunnablePtrType = std::unique_ptr; + using RunnablePtrType = runnable::RunnableNew*; /** * \brief Add a suspended runnable that is running in a thread diff --git a/src/vt/termination/termination.cc b/src/vt/termination/termination.cc index bcd1dd6912..a413df460c 100644 --- a/src/vt/termination/termination.cc +++ b/src/vt/termination/termination.cc @@ -791,7 +791,7 @@ TermStatusEnum TerminationDetector::testEpochTerminated(EpochType epoch) { } vt_debug_print( - normal, term, + verbose, term, "testEpochTerminated: epoch={:x}, pending={}, terminated={}, remote={}\n", epoch, status == TermStatusEnum::Pending, status == TermStatusEnum::Terminated, status == TermStatusEnum::Remote diff --git a/src/vt/transport.h b/src/vt/transport.h index f69f54213b..d035867f7a 100644 --- a/src/vt/transport.h +++ b/src/vt/transport.h @@ -55,7 +55,6 @@ #include "vt/collective/collective_alg.h" #include "vt/collective/collective.h" #include "vt/event/event.h" -#include "vt/registry/registry.h" #include "vt/messaging/active.h" #include "vt/parameterization/parameterization.h" #include "vt/event/event_msgs.h" diff --git a/src/vt/vrt/collection/manager.impl.h b/src/vt/vrt/collection/manager.impl.h index ca2af41855..c43e92354c 100644 --- a/src/vt/vrt/collection/manager.impl.h +++ b/src/vt/vrt/collection/manager.impl.h @@ -213,16 +213,20 @@ CollectionManager::collectionAutoMsgDeliver( // Expand out the index for tracing purposes; Projections takes up to // 4-dimensions +#if vt_check_enabled(trace_enabled) auto idx = base->getIndex(); uint64_t const idx1 = idx.ndims() > 0 ? idx[0] : 0; uint64_t const idx2 = idx.ndims() > 1 ? idx[1] : 0; uint64_t const idx3 = idx.ndims() > 2 ? idx[2] : 0; uint64_t const idx4 = idx.ndims() > 3 ? idx[3] : 0; +#endif runnable::makeRunnable(user_msg, true, han, from) .withTDEpoch(theMsg()->getEpochContextMsg(msg)) .withCollection(base) +#if vt_check_enabled(trace_enabled) .withTraceIndex(event, idx1, idx2, idx3, idx4) +#endif .withLBData(base, msg) .runOrEnqueue(immediate); } @@ -235,17 +239,21 @@ CollectionManager::collectionAutoMsgDeliver( ) { // Expand out the index for tracing purposes; Projections takes up to // 4-dimensions +#if vt_check_enabled(trace_enabled) auto idx = base->getIndex(); uint64_t const idx1 = idx.ndims() > 0 ? idx[0] : 0; uint64_t const idx2 = idx.ndims() > 1 ? idx[1] : 0; uint64_t const idx3 = idx.ndims() > 2 ? idx[2] : 0; uint64_t const idx4 = idx.ndims() > 3 ? idx[3] : 0; +#endif auto m = promoteMsg(msg); runnable::makeRunnable(m, true, han, from) .withTDEpoch(theMsg()->getEpochContextMsg(msg)) .withCollection(base) +#if vt_check_enabled(trace_enabled) .withTraceIndex(event, idx1, idx2, idx3, idx4) +#endif .withLBData(base) .runOrEnqueue(immediate); }