Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
just delete some blank lines
[simgrid.git] / examples / cxx / autoDestination / Master.cxx
1 #include "Master.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 MSG_IMPLEMENT_DYNAMIC(Master, Process);\r
11 \r
12 int Master::main(int argc, char** argv)\r
13 {\r
14         int taskCount;          \r
15         double taskComputeSize;         \r
16         double taskCommunicateSize;\r
17         \r
18         info("Hello");\r
19                 \r
20         info(TEXT_("argc=") + TEXT_(argc));\r
21                 \r
22         for (int i = 0; i< argc; i++)       \r
23                 info(TEXT_("argv:") + TEXT_(argv[i]));\r
24         \r
25         sscanf(argv[0],"%d", &taskCount);\r
26         sscanf(argv[1],"%lg", &taskComputeSize);\r
27         sscanf(argv[2],"%lg", &taskCommunicateSize);\r
28         \r
29         BasicTaskPtr* basicTasks = new BasicTaskPtr[taskCount];\r
30                 \r
31         for (int i = 0; i < taskCount; i++) \r
32                 basicTasks[i] = new BasicTask((TEXT_("Task_") + TEXT_(i)), taskComputeSize, taskCommunicateSize);               \r
33         \r
34         int aliasCount = argc - 3;\r
35                 \r
36         char** aliases = (char**) calloc(aliasCount, sizeof(char*));\r
37                 \r
38         for(int i = 3; i < argc ; i++) \r
39                 aliases[i - 3] = _strdup(argv[i]);\r
40                 \r
41         info(TEXT_("Got ") + TEXT_(aliasCount) + TEXT_(" alias(es) :"));\r
42                 \r
43         for (int i = 0; i < aliasCount; i++)\r
44                 info(TEXT_("\t") + TEXT_(aliases[i]));\r
45                 \r
46         info(TEXT_("Got ") + TEXT_(taskCount) + TEXT_(" task to process."));\r
47                 \r
48         for (int i = 0; i < taskCount; i++) \r
49         {       \r
50                 info(TEXT_("Sending \"") + TEXT_(basicTasks[i]->getName()) + TEXT_("\" to \"") + TEXT_(aliases[i % aliasCount]) + TEXT_("\""));\r
51                 \r
52                 /*if((Host::currentHost().getName()).equals((aliases[i % aliasCount].split(":"))[0]))\r
53                         info("Hey ! It's me ! ");\r
54                 */\r
55                         \r
56                 basicTasks[i]->send(aliases[i % aliasCount]);\r
57         }\r
58                 \r
59         info("Send completed");\r
60         \r
61         info("All tasks have been dispatched. Let's tell everybody the computation is over.");\r
62         \r
63         FinalizeTask* finalizeTask;\r
64         \r
65         for (int i = 0; i < aliasCount; i++) \r
66         {\r
67                 finalizeTask = new FinalizeTask();\r
68                 finalizeTask->send(aliases[i]);\r
69                 \r
70         }\r
71         \r
72         info("Goodbye now!");\r
73 \r
74         delete[] basicTasks;\r
75         delete[] aliases;\r
76 \r
77         delete this;\r
78 \r
79         return 0;\r
80 }