Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d0518bab877dcad95a12fb668de83c99a81d870d
[simgrid.git] / examples / cxx / ping_pong / Sender.cxx
1 #include "Sender.hpp"\r
2 #include "PingPongTask.hpp"\r
3 #include <Host.hpp>\r
4 #include <HostNotFoundException.hpp>\r
5 #include <Msg.hpp>\r
6 \r
7 #include <iostream>\r
8 using namespace std;\r
9 \r
10 const double commSizeLat = 1;\r
11 const double commSizeBw = 100000000;\r
12 \r
13 MSG_IMPLEMENT_DYNAMIC(Sender, Process);\r
14 \r
15 int Sender::main(int argc, char** argv)\r
16 {\r
17         cout <<"[" << getName() << ":" << getHost().getName() << "] " << "Hello I'm " << getName() << " on " << getHost().getName() << "!" << endl;\r
18         \r
19         int hostCount = argc;\r
20         \r
21         cout <<"[" << getName() << ":" << getHost().getName() << "] " <<  "host count : " << hostCount << endl;\r
22         \r
23         Host* hostTable = new Host[hostCount]; \r
24         double time;\r
25         double computeDuration = 0;\r
26         PingPongTask* task;\r
27         \r
28         for(int pos = 0; pos < argc ; pos++) \r
29         {\r
30                 try \r
31                 {\r
32                         hostTable[pos] = Host::getByName(argv[pos]);\r
33                 } \r
34                 catch(HostNotFoundException e) \r
35                 {\r
36                         cerr << e.toString() <<". Stopping Now!" << endl;\r
37                         exit(1);\r
38                 }\r
39         }\r
40         \r
41         for (int pos = 0; pos < hostCount; pos++) \r
42         { \r
43                 time = getClock(); \r
44         \r
45                 cout <<"[" << getName() << ":" << getHost().getName() << "] " <<  "sender time : " << time << endl;\r
46         \r
47                 task = new PingPongTask("no name",computeDuration,commSizeLat);\r
48                 task->setTime(time);\r
49         \r
50                 hostTable[pos].put(0,task);\r
51         } \r
52         \r
53         cout <<"[" << getName() << ":" << getHost().getName() << "] " <<  "goodbye!" << endl;\r
54         \r
55         delete[] hostTable;\r
56 \r
57         delete this;\r
58 \r
59         return 0;\r
60     \r
61 }