Skip to content

Commit 3b5f9a6

Browse files
thearusablelifflander
authored andcommitted
#276: Automatically synthesize message type in vt/group
1 parent 24b802a commit 3b5f9a6

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

src/vt/group/group_manager.h

+18
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,24 @@ struct GroupManager : runtime::component::Component<GroupManager> {
193193
template <typename MsgT, ActiveTypedFnType<MsgT> *f>
194194
void sendMsg(GroupType const group, MsgT* msg);
195195

196+
template <typename ReturnT, typename... Args>
197+
struct FunctionTraits;
198+
199+
template <typename ReturnT, typename T>
200+
struct FunctionTraits<ReturnT(*)(T*)> {
201+
using MsgT = T;
202+
using ReturnType = ReturnT;
203+
};
204+
205+
template <auto f>
206+
void sendMsg(
207+
GroupType const group,
208+
typename FunctionTraits<decltype(f)>::MsgT* msg
209+
) {
210+
using MsgT = typename FunctionTraits<decltype(f)>::MsgT;
211+
return sendMsg<MsgT, f>(group, msg);
212+
}
213+
196214
friend struct Info;
197215
friend struct InfoColl;
198216
friend struct FinishedWork;

src/vt/objgroup/manager.h

+28
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,34 @@ struct ObjGroupManager : runtime::component::Component<ObjGroupManager> {
273273
collective::reduce::ReduceStamp const& stamp
274274
);
275275

276+
template <typename ReturnT, typename... Args>
277+
struct FunctionTraits;
278+
279+
template <typename ReturnT, typename T>
280+
struct FunctionTraits<ReturnT(*)(T*)> {
281+
using MsgT = T;
282+
using ReturnType = ReturnT;
283+
};
284+
285+
/**
286+
* \brief Perform a reduction over an objgroup
287+
*
288+
* \param[in] proxy proxy to the object group
289+
* \param[in] msg reduction message
290+
* \param[in] stamp stamp to identify reduction across nodes
291+
*
292+
* \return the PendingSend corresponding to the reduce
293+
*/
294+
template <typename ObjT, auto f>
295+
PendingSendType reduce(
296+
ProxyType<ObjT> proxy,
297+
messaging::MsgPtrThief<typename FunctionTraits<decltype(f)>::MsgT> msg,
298+
collective::reduce::ReduceStamp const& stamp
299+
) {
300+
using MsgT = typename FunctionTraits<decltype(f)>::MsgT;
301+
return reduce<ObjT, MsgT, f>(proxy, msg, stamp);
302+
}
303+
276304
/**
277305
* \brief Get a pointer to the local objgroup instance. Returns null if the
278306
* object doesn't exist.

src/vt/objgroup/manager.impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ ObjGroupManager::PendingSendType ObjGroupManager::reduce(
271271
auto const objgroup = proxy.getProxy();
272272

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

277277
template <typename ObjT>

src/vt/objgroup/proxy/proxy_objgroup_elm.h

+21
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,27 @@ struct ProxyElm<void> {
213213
template <typename MsgT, ActiveTypedFnType<MsgT>* f, typename... Args>
214214
void send(Args&&... args) const;
215215

216+
template <typename ReturnT, typename... Args>
217+
struct FunctionTraits;
218+
219+
template <typename ReturnT, typename T>
220+
struct FunctionTraits<ReturnT(*)(T*)> {
221+
using MsgT = T;
222+
using ReturnType = ReturnT;
223+
};
224+
225+
/**
226+
* \brief Send a message to the node indexed by this proxy to be
227+
* delivered to the local object instance
228+
*
229+
* \param[in] args args to pass to the message constructor
230+
*/
231+
template <auto f, typename... Args>
232+
void send(Args&&... args) const {
233+
using MsgT = typename FunctionTraits<decltype(f)>::MsgT;
234+
send<MsgT, f>(std::forward<Args>(args)...);
235+
}
236+
216237
private:
217238
NodeType node_ = uninitialized_destination; /**< The indexed node */
218239
};

0 commit comments

Comments
 (0)