Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f7220cd970e07051b933adfe7e7ab37e16700d1a
[simgrid.git] / examples / cxx / explicitDestination / Forwarder.cxx
1 #include "Forwarder.hpp"\r
2 #include "BasicTask.hpp"\r
3 #include "FinalizeTask.hpp"\r
4 \r
5 #include <Host.hpp>\r
6 #include <HostNotFoundException.hpp>\r
7 \r
8 #include <Msg.hpp>\r
9 \r
10 \r
11 MSG_IMPLEMENT_DYNAMIC(Forwarder, Process);\r
12 \r
13 \r
14 int Forwarder::main(int argc, char** argv)\r
15 {\r
16         info("Hello");\r
17         \r
18         int aliasCount = argc;\r
19         \r
20         int taskCount = 0;\r
21         \r
22         Task* taskReceived;\r
23         Task* finalizeTask;\r
24         BasicTask* basicTask;\r
25         \r
26         while(true) \r
27         {\r
28                 taskReceived = Task::receive(Host::currentHost().getName());\r
29         \r
30                 if(taskReceived->isInstanceOf("FinalizeTask")) \r
31                 {\r
32                         info("All tasks have been dispatched. Let's tell everybody the computation is over.");\r
33         \r
34                         for (int i = 0; i < aliasCount; i++) \r
35                         {\r
36                                 finalizeTask = new FinalizeTask();\r
37                                 finalizeTask->send(argv[i]);\r
38                         }\r
39                         \r
40                         delete taskReceived;\r
41         \r
42                         break;\r
43                 }\r
44         \r
45                 basicTask = reinterpret_cast<BasicTask*>(taskReceived);\r
46         \r
47                 info(TEXT_("Received \"") + TEXT_(basicTask->getName()) + TEXT_("\" "));\r
48         \r
49                 info(TEXT_("Sending \"") + TEXT_(basicTask->getName()) + TEXT_("\" to \"") + TEXT_(argv[taskCount % aliasCount]) + TEXT_("\""));\r
50         \r
51                 basicTask->send(argv[taskCount % aliasCount]);\r
52         \r
53                 taskCount++;\r
54         }\r
55         \r
56         \r
57         info("I'm done. See you!");\r
58         \r
59         delete this;\r
60         return 0;\r
61 }