Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
delete the process at the end of the main method
[simgrid.git] / examples / cxx / comm_time / Slave.cxx
1 #include "Slave.hpp"\r
2 #include "FinalizeTask.hpp"\r
3 #include "CommTimeTask.hpp"\r
4 #include <Host.hpp>\r
5 #include <HostNotFoundException.hpp>\r
6 #include <Msg.hpp>\r
7 \r
8 #include <iostream>\r
9 using namespace std;\r
10 \r
11 MSG_IMPLEMENT_DYNAMIC(Slave, Process);\r
12 \r
13 int Slave::main(int argc, char** argv)\r
14 {\r
15         cout <<"[" << getName() << ":" << getHost().getName() << "] " << "Hello I'm " << getName() << " on " << getHost().getName() << "!" << endl;\r
16         \r
17         while(true) \r
18         {\r
19                 double time1 = getClock();       \r
20                 Task* t = Task::get(0); \r
21                 double time2 = getClock();\r
22         \r
23                 if(t->isInstanceOf("FinalizeTask")) \r
24                 {\r
25                         delete t;\r
26                         break;\r
27                 }\r
28                 \r
29                 CommTimeTask* task = reinterpret_cast<CommTimeTask*>(t);\r
30         \r
31                 if(time1 < task->getTime())\r
32                         time1 = task->getTime();\r
33                         \r
34                 // cout <<"[" << getName() << ":" << getHost().getName() << "] " << "Processing \"" << task->getName() << "\" " << getHost().getName() <<  " (Communication time : " <<  (time2 - time1) << ")" << endl;\r
35          \r
36                 task->execute();\r
37                 \r
38                 delete task;\r
39         }\r
40         \r
41         cout <<"[" << getName() << ":" << getHost().getName() << "] " << "Received Finalize. I'm done. See you!" << endl;\r
42         \r
43         delete this;\r
44         return 0;\r
45         \r
46 }