Skip to content

Commit

Permalink
#973: specialize Proxy and ProxyElm for bare handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Strzebonski committed Nov 25, 2020
1 parent d68126d commit b21d3ad
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 34 deletions.
36 changes: 2 additions & 34 deletions examples/callback/callback_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename MsgT, vt::ActiveTypedFnType<MsgT>* fn, typename... Args>
void send(Args&&... args) const {
vt::theMsg()->sendMsg<MsgT, fn>(
node_, vt::makeMessage<MsgT>(std::forward<Args>(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);

Expand All @@ -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<CallbackMsg, handler>(cb);
auto const proxy = vt::theObjGroup()->makeCollective();
proxy[1].send<CallbackMsg, handler>(cb);
}

vt::finalize();
Expand Down
8 changes: 8 additions & 0 deletions src/vt/objgroup/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ struct ObjGroupManager : runtime::component::Component<ObjGroupManager> {
* 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.
Expand Down
17 changes: 17 additions & 0 deletions src/vt/objgroup/proxy/proxy_objgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,23 @@ struct Proxy {
ObjGroupProxyType proxy_ = no_obj_group; /**< The raw proxy ID bits */
};

template <>
struct Proxy<void> {
/**
* \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<void>;

}}} /* end namespace vt::objgroup::proxy */

#endif /*INCLUDED_VT_OBJGROUP_PROXY_PROXY_OBJGROUP_H*/
24 changes: 24 additions & 0 deletions src/vt/objgroup/proxy/proxy_objgroup_elm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -179,6 +181,28 @@ struct ProxyElm {
NodeType node_ = uninitialized_destination; /**< The indexed node */
};

template <>
struct ProxyElm<void> {
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 <typename MsgT, ActiveTypedFnType<MsgT>* fn, typename... Args>
void send(Args&&... args) const {
vt::theMsg()->sendMsg<MsgT, fn>(
node_, vt::makeMessage<MsgT>(std::forward<Args>(args)...));
}

private:
NodeType node_ = uninitialized_destination; /**< The indexed node */
};

using DefaultProxyElm = ProxyElm<void>;

}}} /* end namespace vt::objgroup::proxy */

#endif /*INCLUDED_VT_OBJGROUP_PROXY_PROXY_OBJGROUP_ELM_H*/

0 comments on commit b21d3ad

Please sign in to comment.