@@ -52,9 +52,21 @@ struct HelloMsg : vt::Message {
52
52
{ }
53
53
};
54
54
55
+ struct AnotherMsg : vt::Message{};
56
+
55
57
struct HelloWorld {
56
58
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 ());
58
70
}
59
71
};
60
72
@@ -70,7 +82,21 @@ int main(int argc, char** argv) {
70
82
71
83
if (this_node == 0 ) {
72
84
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
73
88
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);
74
100
}
75
101
76
102
vt::finalize ();
0 commit comments