Skip to content

Commit

Permalink
Merge pull request #1262 from DARMA-tasking/1261-use-collective-epoch…
Browse files Browse the repository at this point in the history
…s-in-tutorial

1261: Use collective epochs for tutorial examples
  • Loading branch information
JacobDomagala authored Feb 16, 2021
2 parents 3147e2d + 608f25c commit 007e872
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 35 deletions.
2 changes: 1 addition & 1 deletion tutorial/tutorial_1e.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct MySimpleMsg : ::vt::Message { };
// Forward declaration for the active message handler
static void msgHandlerGroupA(MySimpleMsg* msg);

// Tutorial code to demonstrate broadcasting a message to the entire system
// Tutorial code to demonstrate rooted group creation and broadcast to that group
static inline void activeMessageGroupRoot() {
NodeType const this_node = ::vt::theContext()->getNode();
NodeType const num_nodes = ::vt::theContext()->getNumNodes();
Expand Down
2 changes: 1 addition & 1 deletion tutorial/tutorial_1f.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct MySimpleMsg2 : ::vt::Message { };
// Forward declaration for the active message handler
static void msgHandlerGroupB(MySimpleMsg2* msg);

// Tutorial code to demonstrate broadcasting a message to the entire system
// Tutorial code to demonstrate collective group creation and broadcast to that group
static inline void activeMessageGroupCollective() {
NodeType const this_node = ::vt::theContext()->getNode();
NodeType const num_nodes = ::vt::theContext()->getNumNodes();
Expand Down
2 changes: 1 addition & 1 deletion tutorial/tutorial_1h.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct ReduceResult {
};


// Tutorial code to demonstrate using a callback
// Tutorial code to demonstrate using reduction on all nodes
static inline void activeMessageReduce() {
NodeType const this_node = ::vt::theContext()->getNode();
(void)this_node; // don't warn about unused variable
Expand Down
54 changes: 22 additions & 32 deletions tutorial/tutorial_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,51 +81,42 @@ int main(int argc, char** argv) {
*/

// These parts of the tutorial only require the root node
if (::vt::theContext()->getNode() == 0) {
// Invoke tutorial 1a: context (node, number of nodes)
context();
::vt::runInEpochCollective([] {
if (::vt::theContext()->getNode() == 0) {
// Invoke tutorial 1a: context (node, number of nodes)
context();

// Invoke tutorial 1b: active message send
activeMessageNode();
// Invoke tutorial 1b: active message send
activeMessageNode();

// Invoke tutorial 1c: active message serialization
activeMessageSerialization();
// Invoke tutorial 1c: active message serialization
activeMessageSerialization();

// Invoke tutorial 1d: active message broadcast
activeMessageBroadcast();
// Invoke tutorial 1d: active message broadcast
activeMessageBroadcast();

// Invoke tutorial 1e: active message group rooted
activeMessageGroupRoot();
// Invoke tutorial 1e: active message group rooted
activeMessageGroupRoot();

// Invoke tutorial 1g: callback
activeMessageCallback();
}

/*
* The barrier (which should not be used in most cases) causes all nodes to
* wait until they arrive. Barriers can be named (as an optional parameter) so
* multiple strands can independently make progress. The barrier here is so
* the output from the above calls are easier to read and not interleaved with
* the following.
*/
::vt::theCollective()->barrier();
// Invoke tutorial 1g: callback
activeMessageCallback();
}
});

// Invoke tutorial 1f: active message group collective
activeMessageGroupCollective();

::vt::theCollective()->barrier();
::vt::runInEpochCollective([] { activeMessageGroupCollective(); });

// Invoke tutorial 1h: reduction
activeMessageReduce();
::vt::runInEpochCollective([] {activeMessageReduce(); });

// Invoke tutorial 2a: virtual collection creation
collection();
::vt::runInEpochCollective([] { collection(); });

// Invoke tutorial 2b: virtual collection reduce
collectionReduce();
::vt::runInEpochCollective([] { collectionReduce(); });

// Termination with active messages
activeMessageTerm();
// Invoke tutorial 3a: Termination with active messages
::vt::runInEpochCollective([] { activeMessageTerm(); });


/*
Expand All @@ -143,5 +134,4 @@ int main(int argc, char** argv) {
* All node invoke finalize at the end of the program
*/
::vt::CollectiveOps::finalize();

}

0 comments on commit 007e872

Please sign in to comment.