From c94d1565c3409a04f4b9384f64e92565258db90b Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Wed, 7 Dec 2022 22:58:11 +0100 Subject: [PATCH] #2027: Objgroup: Add separate invoke functions for different return types --- src/vt/objgroup/manager.h | 23 +++++++++++++- src/vt/objgroup/manager.impl.h | 58 ++++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/vt/objgroup/manager.h b/src/vt/objgroup/manager.h index a43c107501..dc45a430bd 100644 --- a/src/vt/objgroup/manager.h +++ b/src/vt/objgroup/manager.h @@ -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 { * \param[in] args function arguments */ template - decltype(auto) invoke(ProxyElmType proxy, Args&&... args); + util::NotCopyable invoke(ProxyElmType 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 + util::Copyable invoke(ProxyElmType 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 + util::IsVoidReturn invoke(ProxyElmType proxy, Args&&... args); /** * \internal \brief Broadcast a message to all nodes in object group diff --git a/src/vt/objgroup/manager.impl.h b/src/vt/objgroup/manager.impl.h index dffb5f7917..6522f0d179 100644 --- a/src/vt/objgroup/manager.impl.h +++ b/src/vt/objgroup/manager.impl.h @@ -236,7 +236,27 @@ void ObjGroupManager::invoke( } template -decltype(auto) +util::IsVoidReturn +ObjGroupManager::invoke(ProxyElmType 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(ptr, std::forward(args)...); + }) + .run(); +} + +template +util::Copyable ObjGroupManager::invoke(ProxyElmType proxy, Args&&... args) { auto const dest_node = proxy.getNode(); auto const this_node = theContext()->getNode(); @@ -249,7 +269,41 @@ ObjGroupManager::invoke(ProxyElmType proxy, Args&&... args) { ) ); - return runnable::invoke(get(proxy), std::forward(args)...); + util::Copyable result; + + runnable::makeRunnableVoid(false, uninitialized_handler, dest_node) + .withExplicitTask([&] { + result = runnable::invoke(get(proxy), std::forward(args)...); + }) + .run(); + + return result; +} + +template +util::NotCopyable +ObjGroupManager::invoke(ProxyElmType 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* result; + + runnable::makeRunnableVoid(false, uninitialized_handler, dest_node) + .withExplicitTask([&] { + auto&& ret = runnable::invoke(get(proxy), std::forward(args)...); + *result = std::move(ret); + }) + .run(); + + return std::move(*result); }