Skip to content

Commit

Permalink
#276: Automatically synthesize message type in vt/group
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed Feb 8, 2023
1 parent 21c9392 commit 8ee99f6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/vt/group/group_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,24 @@ struct GroupManager : runtime::component::Component<GroupManager> {
template <typename MsgT, ActiveTypedFnType<MsgT> *f>
void sendMsg(GroupType const group, MsgT* msg);

template <typename ReturnT, typename... Args>
struct FunctionTraits;

template <typename ReturnT, typename T>
struct FunctionTraits<ReturnT(*)(T*)> {
using MsgT = T;
using ReturnType = ReturnT;
};

template <auto f>
void sendMsg(
GroupType const group,
typename FunctionTraits<decltype(f)>::MsgT* msg
) {
using MsgT = typename FunctionTraits<decltype(f)>::MsgT;
return sendMsg<MsgT, f>(group, msg);
}

friend struct Info;
friend struct InfoColl;
friend struct FinishedWork;
Expand Down
28 changes: 28 additions & 0 deletions src/vt/objgroup/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,34 @@ struct ObjGroupManager : runtime::component::Component<ObjGroupManager> {
collective::reduce::ReduceStamp const& stamp
);

template <typename ReturnT, typename... Args>
struct FunctionTraits;

template <typename ReturnT, typename T>
struct FunctionTraits<ReturnT(*)(T*)> {
using MsgT = T;
using ReturnType = ReturnT;
};

/**
* \brief Perform a reduction over an objgroup
*
* \param[in] proxy proxy to the object group
* \param[in] msg reduction message
* \param[in] stamp stamp to identify reduction across nodes
*
* \return the PendingSend corresponding to the reduce
*/
template <typename ObjT, auto f>
PendingSendType reduce(
ProxyType<ObjT> proxy,
messaging::MsgPtrThief<typename FunctionTraits<decltype(f)>::MsgT> msg,
collective::reduce::ReduceStamp const& stamp
) {
using MsgT = typename FunctionTraits<decltype(f)>::MsgT;
return reduce<ObjT, MsgT, f>(proxy, msg, stamp);
}

/**
* \brief Get a pointer to the local objgroup instance. Returns null if the
* object doesn't exist.
Expand Down
2 changes: 1 addition & 1 deletion src/vt/objgroup/manager.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ ObjGroupManager::PendingSendType ObjGroupManager::reduce(
auto const objgroup = proxy.getProxy();

auto r = theCollective()->getReducerObjGroup(objgroup);
return r->template reduce<MsgT,f>(root, msg.get(), stamp);
return r->template reduce<f>(root, msg.get(), stamp);
}

template <typename ObjT>
Expand Down
21 changes: 21 additions & 0 deletions src/vt/objgroup/proxy/proxy_objgroup_elm.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,27 @@ struct ProxyElm<void> {
template <typename MsgT, ActiveTypedFnType<MsgT>* f, typename... Args>
void send(Args&&... args) const;

template <typename ReturnT, typename... Args>
struct FunctionTraits;

template <typename ReturnT, typename T>
struct FunctionTraits<ReturnT(*)(T*)> {
using MsgT = T;
using ReturnType = ReturnT;
};

/**
* \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 <auto f, typename... Args>
void send(Args&&... args) const {
using MsgT = typename FunctionTraits<decltype(f)>::MsgT;
send<MsgT, f>(std::forward<Args>(args)...);
}

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

0 comments on commit 8ee99f6

Please sign in to comment.