Skip to content

Commit 560f6dd

Browse files
committed
#1260: examples: Add additional examples that cover the changes made to Active send/broadcast with Functor
1 parent 0284799 commit 560f6dd

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

examples/hello_world/hello_world_functor.cc

+27-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,21 @@ struct HelloMsg : vt::Message {
5252
{ }
5353
};
5454

55+
struct AnotherMsg : vt::Message{};
56+
5557
struct HelloWorld {
5658
void operator()(HelloMsg* msg) const {
57-
fmt::print("{}: Hello from node {}\n", vt::theContext()->getNode(), msg->from);
59+
fmt::print("{}: HelloWorld -> Hello from node {}\n", vt::theContext()->getNode(), msg->from);
60+
}
61+
};
62+
63+
struct MultipleFunctions {
64+
void operator()(HelloMsg* msg) const {
65+
fmt::print("{}: MultipleFunctions -> Hello from node {}\n", vt::theContext()->getNode(), msg->from);
66+
}
67+
68+
void operator()(AnotherMsg* msg) const {
69+
fmt::print("{}: MultipleFunctions with AnotherMsg\n", vt::theContext()->getNode());
5870
}
5971
};
6072

@@ -70,7 +82,21 @@ int main(int argc, char** argv) {
7082

7183
if (this_node == 0) {
7284
auto msg = vt::makeMessage<HelloMsg>(this_node);
85+
86+
// 'HelloWorld' functor has only single 'operator()' declared
87+
// so we can call send/braodcast without specyfing message type
7388
vt::theMsg()->broadcastMsg<HelloWorld>(msg);
89+
90+
msg = vt::makeMessage<HelloMsg>(this_node);
91+
vt::theMsg()->sendMsg<HelloWorld>(1, msg);
92+
93+
// 'MultipleFunctions' functor declares more than one 'operator()'
94+
// so we have to specify the type of the message, as it can't be deduced
95+
auto new_msg = vt::makeMessage<AnotherMsg>();
96+
vt::theMsg()->broadcastMsg<MultipleFunctions, AnotherMsg>(new_msg);
97+
98+
new_msg = vt::makeMessage<AnotherMsg>();
99+
vt::theMsg()->sendMsg<MultipleFunctions, AnotherMsg>(1, new_msg);
74100
}
75101

76102
vt::finalize();

0 commit comments

Comments
 (0)