Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
All of the examples use now the StringHelp class to simplify the string manipulation.
[simgrid.git] / examples / cxx / basic / Forwarder.cxx
1 #include "Forwarder.hpp"\r
2 #include "BasicTask.hpp"\r
3 #include "FinalizeTask.hpp"\r
4 #include <Host.hpp>\r
5 #include <HostNotFoundException.hpp>\r
6 \r
7 #include <Msg.hpp>\r
8 \r
9 MSG_IMPLEMENT_DYNAMIC(Forwarder, Process);\r
10 \r
11 \r
12 int Forwarder::main(int argc, char** argv)\r
13 {\r
14         info("Hello");\r
15         \r
16         int slavesCount = argc;\r
17         \r
18         Host* slaves = new Host[slavesCount];\r
19         \r
20         for (int i = 0; i < argc; i++) \r
21         {\r
22                 try \r
23                 {             \r
24                         slaves[i] = Host::getByName(argv[i]);\r
25                 } \r
26                 catch (HostNotFoundException e) \r
27                 {\r
28                         error(TEXT_(e.toString()));\r
29                         error("Buggy deployment file");\r
30                         exit(1);\r
31                 }\r
32         }\r
33         \r
34         int taskCount = 0;\r
35 \r
36         while(true) \r
37         {\r
38                 Task* t = Task::get(0); \r
39         \r
40                 if(t->isInstanceOf("FinalizeTask")) \r
41                 {\r
42                         info("All tasks have been dispatched. Let's tell everybody the computation is over.");\r
43         \r
44                         for (int cpt = 0; cpt< slavesCount; cpt++) \r
45                                 slaves[cpt].put(0, new FinalizeTask());\r
46 \r
47                         delete t;\r
48 \r
49                         break;\r
50                 }\r
51 \r
52                 info(TEXT_("Received \"") + TEXT_(t->getName()) + TEXT_("\" "));\r
53         \r
54                 info(TEXT_("Sending \"") + TEXT_(t->getName()) + TEXT_("\" to \"") + TEXT_(slaves[taskCount % slavesCount].getName()) + TEXT_("\""));\r
55                 \r
56                 slaves[taskCount % slavesCount].put(0, t);\r
57         \r
58                 taskCount++;\r
59         }\r
60         \r
61         \r
62         info("I'm done. See you!");\r
63         \r
64         delete[] slaves;\r
65 \r
66         delete this;\r
67       \r
68         return 0;\r
69 }