Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : new example for liveness properties
[simgrid.git] / examples / cxx / basic / Forwarder.cxx
1 #include "Forwarder.hpp"
2 #include "BasicTask.hpp"
3 #include "FinalizeTask.hpp"
4 #include <MsgHost.hpp>
5 #include <HostNotFoundException.hpp>
6
7 #include <Msg.hpp>
8
9 MSG_IMPLEMENT_DYNAMIC(Forwarder, Process)
10
11
12 int Forwarder::main(int argc, char** argv)
13 {
14         info("Hello");
15         
16         int slavesCount = argc;
17         
18         Host* slaves = new Host[slavesCount];
19         
20         for (int i = 0; i < argc; i++) 
21         {
22                 try 
23                 {             
24                         slaves[i] = Host::getByName(argv[i]);
25                 } 
26                 catch (HostNotFoundException e) 
27                 {
28                         error(TEXT_(e.toString()));
29                         error("Buggy deployment file");
30                         exit(1);
31                 }
32         }
33         
34         int taskCount = 0;
35
36         while(true) 
37         {
38                 Task* t = Task::get(0); 
39         
40                 if(t->isInstanceOf("FinalizeTask")) 
41                 {
42                         info("All tasks have been dispatched. Let's tell everybody the computation is over.");
43         
44                         for (int cpt = 0; cpt< slavesCount; cpt++) 
45                                 slaves[cpt].put(0, new FinalizeTask());
46
47                         delete t;
48
49                         break;
50                 }
51
52                 info(TEXT_("Received \"") + TEXT_(t->getName()) + TEXT_("\" "));
53         
54                 info(TEXT_("Sending \"") + TEXT_(t->getName()) + TEXT_("\" to \"") + TEXT_(slaves[taskCount % slavesCount].getName()) + TEXT_("\""));
55                 
56                 slaves[taskCount % slavesCount].put(0, t);
57         
58                 taskCount++;
59         }
60         
61         
62         info("I'm done. See you!");
63         
64         delete[] slaves;
65
66         delete this;
67       
68         return 0;
69 }