Skip to content

Commit

Permalink
#276: reduce: reorder arguments for bare reduce to match
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander committed Jun 13, 2023
1 parent 1aea01b commit e454bc5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/hello_world/hello_reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(int argc, char** argv) {
vt::NodeType const root = 0;

auto r = vt::theCollective()->global();
r->reduce<vt::collective::PlusOp, reduceResult>(vt::Node{root}, 50, 52.334);
r->reduce<reduceResult, vt::collective::PlusOp>(vt::Node{root}, 50, 52.334);

vt::finalize();
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/vt/collective/reduce/get_reduce_stamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "vt/collective/reduce/reduce_scope.h"
#include "vt/messaging/message.h"

#include <tuple>
#include <utility>
#include <type_traits>

Expand Down
32 changes: 14 additions & 18 deletions src/vt/collective/reduce/reduce.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,31 +168,27 @@ struct Reduce : virtual collective::tree::Tree {
return reduce<MsgT, f>(root, msg, id, num_contrib);
}

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
template <template<typename Arg> class Op, auto f, typename... Params>
/**
* \brief Perform a reduction without a message
*
* \param[in] root the root node to target
* \param[in] params parameters to reduce
*
* \return a pending send
*/
template <
auto f,
template <typename Arg> class Op = NoneOp,
typename... Params
>
PendingSendType reduce(Node root, Params&&... params) {
using Tuple = typename FuncTraits<decltype(f)>::TupleType;
using OpT = Op<Tuple>;
return reduce<OpT, f>(root, std::forward<Params>(params)...);
}

template <typename Op, auto f, typename... Params>
PendingSendType reduce(Node root, Params&&... params) {
using Tuple = typename FuncTraits<decltype(f)>::TupleType;
using MsgT = ReduceTMsg<Tuple>;

auto msg = vt::makeMessage<MsgT>(std::tuple{std::forward<Params>(params)...});
auto id = detail::ReduceStamp{};
auto han = auto_registry::makeAutoHandlerParam<decltype(f), f, MsgT>();
msg->root_handler_ = han;

return reduce<Op, operators::NoCombine, MsgT>(root.get(), msg.get(), id, 1);
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
PendingSendType reduce(Node root, Params&&... params);

/**
* \brief Reduce a message up the tree
Expand Down
14 changes: 14 additions & 0 deletions src/vt/collective/reduce/reduce.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ void Reduce::reduceRootRecv(MsgT* msg) {
.run();
}

template <typename Op, auto f, typename... Params>
Reduce::PendingSendType Reduce::reduce(Node root, Params&&... params) {
using Tuple = typename FuncTraits<decltype(f)>::TupleType;
using MsgT = ReduceTMsg<Tuple>;

auto msg = vt::makeMessage<MsgT>(std::forward<Params>(params)...);
auto id = detail::ReduceStamp{};
auto han = auto_registry::makeAutoHandlerParam<decltype(f), f, MsgT>();
msg->root_handler_ = han;

return reduce<Op, operators::NoCombine, MsgT>(root.get(), msg.get(), id, 1);
}


template <typename OpT, typename MsgT, ActiveTypedFnType<MsgT> *f>
Reduce::PendingSendType Reduce::reduce(
NodeType const& root, MsgT* msg, Callback<MsgT> cb, detail::ReduceStamp id,
Expand Down

0 comments on commit e454bc5

Please sign in to comment.