Logo AND Algorithmique Numérique Distribuée

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