-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#672: docs: add page of theCollective
- Loading branch information
1 parent
46a4e84
commit 6e7f7ed
Showing
2 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
\page collective Collectives | ||
\brief Collective operations | ||
|
||
The collective component `vt::collective::CollectiveAlg`, accessed via | ||
`vt::theCollective()` 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. | ||
|
||
\section collective-reduce-example A Simple Reduction | ||
|
||
\code{.cpp} | ||
#include <vt/transport.h> | ||
|
||
// Reduce ints | ||
struct ReduceDataMsg : ::vt::collective::ReduceTMsg<int> {}; | ||
|
||
// 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>(); | ||
reduce_msg->getVal() = 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; | ||
} | ||
\endcode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters