From b21d3adedf338250a25d84a124f93cea4b593f74 Mon Sep 17 00:00:00 2001 From: Jakub Strzebonski Date: Fri, 20 Nov 2020 19:45:24 +0100 Subject: [PATCH] #973: specialize Proxy and ProxyElm for bare handlers --- examples/callback/callback_context.cc | 36 ++-------------------- src/vt/objgroup/manager.h | 8 +++++ src/vt/objgroup/proxy/proxy_objgroup.h | 17 ++++++++++ src/vt/objgroup/proxy/proxy_objgroup_elm.h | 24 +++++++++++++++ 4 files changed, 51 insertions(+), 34 deletions(-) diff --git a/examples/callback/callback_context.cc b/examples/callback/callback_context.cc index 0153ef7e9b..f7db10d846 100644 --- a/examples/callback/callback_context.cc +++ b/examples/callback/callback_context.cc @@ -96,38 +96,6 @@ static void handler(CallbackMsg* msg) { // Some instance of the context static MyContext my_global_ctx = {}; -namespace { - -struct DefaultProxyElem { - explicit DefaultProxyElem(vt::NodeType in_node) : node_(in_node) {} - - template * fn, typename... Args> - void send(Args&&... args) const { - vt::theMsg()->sendMsg( - node_, vt::makeMessage(std::forward(args)...) - ); - } - - private: - vt::NodeType node_; -}; - -struct DefaultProxy { - DefaultProxyElem operator[](vt::NodeType node) const { - return DefaultProxyElem{node}; - } - - static const DefaultProxy& get() { - static DefaultProxy const default_proxy; - return default_proxy; - } - - private: - DefaultProxy() = default; -}; - -} - int main(int argc, char** argv) { vt::initialize(argc, argv); @@ -141,8 +109,8 @@ int main(int argc, char** argv) { vt::pipe::LifetimeEnum::Once, &my_global_ctx, callbackFn ); - auto const& default_proxy = DefaultProxy::get(); - default_proxy[1].send(cb); + auto const proxy = vt::theObjGroup()->makeCollective(); + proxy[1].send(cb); } vt::finalize(); diff --git a/src/vt/objgroup/manager.h b/src/vt/objgroup/manager.h index 0082dcd510..7969da32b7 100644 --- a/src/vt/objgroup/manager.h +++ b/src/vt/objgroup/manager.h @@ -109,6 +109,14 @@ struct ObjGroupManager : runtime::component::Component { * communicator */ + /** + * \brief Construct a special proxy instance that allows sending, broadcasting + * and reducing without actual object group. + * + * \return proxy to the object group + */ + proxy::DefaultProxyType makeCollective() { return proxy::DefaultProxyType{}; } + /** * \brief Collectively construct a new object group. Allocates and constructs * the object on each node by forwarding constructor arguments. diff --git a/src/vt/objgroup/proxy/proxy_objgroup.h b/src/vt/objgroup/proxy/proxy_objgroup.h index 917d038836..6fcebd175f 100644 --- a/src/vt/objgroup/proxy/proxy_objgroup.h +++ b/src/vt/objgroup/proxy/proxy_objgroup.h @@ -336,6 +336,23 @@ struct Proxy { ObjGroupProxyType proxy_ = no_obj_group; /**< The raw proxy ID bits */ }; +template <> +struct Proxy { + /** + * \brief Index the proxy to get the element proxy for a particular node + * + * \param[in] node the desired node + * + * \return an indexed proxy to that node + */ + // DefaultProxyElm operator[](NodeType node) const; + DefaultProxyElm operator[](NodeType node) const { + return DefaultProxyElm{node}; + } +}; + +using DefaultProxyType = Proxy; + }}} /* end namespace vt::objgroup::proxy */ #endif /*INCLUDED_VT_OBJGROUP_PROXY_PROXY_OBJGROUP_H*/ diff --git a/src/vt/objgroup/proxy/proxy_objgroup_elm.h b/src/vt/objgroup/proxy/proxy_objgroup_elm.h index db840c8590..ae1c9f5ddb 100644 --- a/src/vt/objgroup/proxy/proxy_objgroup_elm.h +++ b/src/vt/objgroup/proxy/proxy_objgroup_elm.h @@ -49,6 +49,8 @@ #include "vt/objgroup/common.h" #include "vt/objgroup/proxy/proxy_bits.h" #include "vt/objgroup/active_func/active_func.h" +#include "vt/activefn/activefn.h" +#include "vt/messaging/active.h" #include "vt/messaging/message/smart_ptr.h" namespace vt { namespace objgroup { namespace proxy { @@ -179,6 +181,28 @@ struct ProxyElm { NodeType node_ = uninitialized_destination; /**< The indexed node */ }; +template <> +struct ProxyElm { + explicit ProxyElm(NodeType in_node) : node_{in_node} {} + + /** + * \brief Send a message to the node indexed by this proxy to be + * delivered to the local object instance + * + * \param[in] args args to pass to the message constructor + */ + template * fn, typename... Args> + void send(Args&&... args) const { + vt::theMsg()->sendMsg( + node_, vt::makeMessage(std::forward(args)...)); + } + + private: + NodeType node_ = uninitialized_destination; /**< The indexed node */ +}; + +using DefaultProxyElm = ProxyElm; + }}} /* end namespace vt::objgroup::proxy */ #endif /*INCLUDED_VT_OBJGROUP_PROXY_PROXY_OBJGROUP_ELM_H*/