Collectives
Collective operations.
The collective component vt::
, accessed via vt::
implements active-message-based distributed collectives over the vt runtime. It performs asynchronous reductions, scatters, barriers, and allows one to safely use MPI interspersed through vt code, while running in a handler.
Reductions
vt comes with several reduction operators built in that can operate over types where the operator already applies (like integers, doubles, etc.) or user-defined overloaded operators. These operators also have specializations for std::vector<T>
and std::array<T>
.
Operator | Reference |
---|---|
operator&& | vt:: |
operator|| | vt:: |
operator+ | vt:: |
std::min | vt:: |
std::max | vt:: |
operator& | vt:: |
operator| | vt:: |
operator^ | vt:: |
<no-operator> | vt:: |
A Simple Reduction
#include <vt/transport.h> // Reduce ints struct ReduceDataMsg : vt::collective::ReduceTMsg<int> { explicit ReduceDataMsg(int val) : vt::collective::ReduceTMsg<int>(val) { } }; // Handler to target for reduction struct ReduceResult { void operator()(ReduceDataMsg* msg) { auto num_nodes = vt::theContext()->getNumNodes(); auto output = msg->getConstVal(); fmt::print("reduction value={}\n", output); vtAssert(num_nodes * 50 == output, "Must be equal); } }; int main(int argc, char** argv) { vt::initialize(argc, argv); auto reduce_msg = vt::makeMessage<ReduceDataMsg>(50); NodeType const root_reduce_node = 0; vt::theCollective()->global()->reduce<vt::collective::PlusOp<int>,ReduceResult>( root_reduce_node, reduce_msg.get() ); vt::finalize(); // spins in scheduler until termination return 0; }