Skip to content

Commit

Permalink
#2027: Objgroup: Add separate invoke functions for different return t…
Browse files Browse the repository at this point in the history
…ypes
  • Loading branch information
JacobDomagala committed Feb 2, 2023
1 parent 137536f commit 48c96ce
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/vt/objgroup/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -234,7 +235,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
Expand Down
58 changes: 56 additions & 2 deletions src/vt/objgroup/manager.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,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();
Expand All @@ -224,7 +244,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);
}


Expand Down
1 change: 0 additions & 1 deletion tests/unit/objgroup/test_objgroup_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
//@HEADER
*/

#include <memory>
#if !defined INCLUDED_UNIT_OBJGROUP_TEST_OBJGROUP_COMMON_H
#define INCLUDED_UNIT_OBJGROUP_TEST_OBJGROUP_COMMON_H

Expand Down

0 comments on commit 48c96ce

Please sign in to comment.