Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2027: Objgroup: Add separate invoke functions for different return t…
Browse files Browse the repository at this point in the history
…ypes
JacobDomagala committed Dec 7, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent a25cfe2 commit c94d156
Showing 2 changed files with 78 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/vt/objgroup/manager.h
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@

#include "vt/config.h"
#include "vt/runtime/component/component_pack.h"
#include "vt/utils/static_checks/function_ret_check.h"
#include "vt/objgroup/common.h"
#include "vt/objgroup/manager.fwd.h"
#include "vt/objgroup/proxy/proxy_objgroup.h"
@@ -237,7 +238,27 @@ struct ObjGroupManager : runtime::component::Component<ObjGroupManager> {
* \param[in] args function arguments
*/
template <typename ObjT, typename Type, Type f, typename... Args>
decltype(auto) invoke(ProxyElmType<ObjT> proxy, Args&&... args);
util::NotCopyable<Type> invoke(ProxyElmType<ObjT> proxy, Args&&... args);

/**
* \internal \brief Invoke function 'f' on an element of the object group
* The function will be invoked inline without going through scheduler
*
* \param[in] proxy proxy to the object group
* \param[in] args function arguments
*/
template <typename ObjT, typename Type, Type f, typename... Args>
util::Copyable<Type> invoke(ProxyElmType<ObjT> proxy, Args&&... args);

/**
* \internal \brief Invoke function 'f' on an element of the object group
* The function will be invoked inline without going through scheduler
*
* \param[in] proxy proxy to the object group
* \param[in] args function arguments
*/
template <typename ObjT, typename Type, Type f, typename... Args>
util::IsVoidReturn<Type> invoke(ProxyElmType<ObjT> proxy, Args&&... args);

/**
* \internal \brief Broadcast a message to all nodes in object group
58 changes: 56 additions & 2 deletions src/vt/objgroup/manager.impl.h
Original file line number Diff line number Diff line change
@@ -236,7 +236,27 @@ void ObjGroupManager::invoke(
}

template <typename ObjT, typename Type, Type f, typename... Args>
decltype(auto)
util::IsVoidReturn<Type>
ObjGroupManager::invoke(ProxyElmType<ObjT> proxy, Args&&... args) {
auto const dest_node = proxy.getNode();
auto const this_node = theContext()->getNode();

auto ptr = get(proxy);
vtAssert(
dest_node == this_node,
fmt::format(
"Attempting to invoke handler on node:{} instead of node:{}!\n",
this_node, dest_node));

runnable::makeRunnableVoid(false, uninitialized_handler, this_node)
.withExplicitTask([&]{
runnable::invoke<Type, f>(ptr, std::forward<Args>(args)...);
})
.run();
}

template <typename ObjT, typename Type, Type f, typename... Args>
util::Copyable<Type>
ObjGroupManager::invoke(ProxyElmType<ObjT> proxy, Args&&... args) {
auto const dest_node = proxy.getNode();
auto const this_node = theContext()->getNode();
@@ -249,7 +269,41 @@ ObjGroupManager::invoke(ProxyElmType<ObjT> proxy, Args&&... args) {
)
);

return runnable::invoke<Type, f>(get(proxy), std::forward<Args>(args)...);
util::Copyable<Type> result;

runnable::makeRunnableVoid(false, uninitialized_handler, dest_node)
.withExplicitTask([&] {
result = runnable::invoke<Type, f>(get(proxy), std::forward<Args>(args)...);
})
.run();

return result;
}

template <typename ObjT, typename Type, Type f, typename... Args>
util::NotCopyable<Type>
ObjGroupManager::invoke(ProxyElmType<ObjT> proxy, Args&&... args) {
auto const dest_node = proxy.getNode();
auto const this_node = theContext()->getNode();

vtAssert(
dest_node == this_node,
fmt::format(
"Attempting to invoke handler on node:{} instead of node:{}!\n", this_node,
dest_node
)
);

util::NotCopyable<Type>* result;

runnable::makeRunnableVoid(false, uninitialized_handler, dest_node)
.withExplicitTask([&] {
auto&& ret = runnable::invoke<Type, f>(get(proxy), std::forward<Args>(args)...);
*result = std::move(ret);
})
.run();

return std::move(*result);
}


0 comments on commit c94d156

Please sign in to comment.