Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make a tesh file for ns3.
[simgrid.git] / examples / cxx / comm_time / Master.cxx
1 #include "Master.hpp"
2 #include "CommTimeTask.hpp"
3 #include "FinalizeTask.hpp"
4 #include <MsgHost.hpp>
5 #include <HostNotFoundException.hpp>
6 #include <Msg.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 numberOfTasks;              
15         double taskComputeSize;         
16         double taskCommunicateSize;
17
18         if (argc < 3) 
19         {
20                 error("Master needs 3 arguments");
21                 exit(1);
22         }
23         
24         info("Hello");
25         
26         int slaveCount = 0;
27         Host* slaves = NULL;
28         
29         sscanf(argv[0],"%d", &numberOfTasks);
30         
31         sscanf(argv[1],"%lg", &taskComputeSize);
32         
33         sscanf(argv[2],"%lg", &taskCommunicateSize);
34         
35         
36         slaveCount = argc - 3;
37         slaves = new Host[slaveCount];
38         
39         for(int i = 3; i < argc ; i++)  
40         {
41                 try 
42                 {
43                         slaves[i-3] = Host::getByName(argv[i]);
44                 }
45                 
46                 catch(HostNotFoundException e) 
47                 {
48                         error(TEXT_(e.toString()) + TEXT_(". Stopping Now!"));
49                         exit(1);
50                 }
51         }
52         
53         info(TEXT_("Got slave(s) :" ) + TEXT_(slaveCount));
54                         
55         for (int i = 0; i < slaveCount; i++)
56                 info(TEXT_("\t") + TEXT_(slaves[i].getName()));
57         
58         info(TEXT_("Got ") + TEXT_(numberOfTasks) + TEXT_(" task to process."));
59         
60         
61         for (int i = 0; i < numberOfTasks; i++) 
62         {                       
63                 CommTimeTask* task = new CommTimeTask(TEXT_("Task_") + TEXT_(i), taskComputeSize, taskCommunicateSize);
64                 task->setTime(getClock());
65                 slaves[i % slaveCount].put(0, task);
66                 
67         }
68         
69         info("All tasks have been dispatched. Let's tell everybody the computation is over.");
70         
71         for (int i = 0; i < slaveCount; i++) 
72         { 
73                 info(TEXT_("Finalize host ") + TEXT_(slaves[i].getName()) + TEXT_(" [") + TEXT_(i) + TEXT_("]"));
74                 slaves[i].put(0, new FinalizeTask());
75         }
76         
77         info("All finalize messages have been dispatched. Goodbye now!");
78         
79
80         delete[] slaves;
81         delete this;
82         return 0;
83 }