Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
no need to set the number of host,link or route at the beginning , thanks to xbt_dyna...
[simgrid.git] / examples / lua / master_slave_bypass.lua
1 --Master Function
2 function Master(...) 
3
4 simgrid.info("Hello from lua, I'm the master")
5 for i,v in ipairs(arg) do
6     simgrid.info("Got "..v)
7 end
8
9 nb_task = arg[1];
10 comp_size = arg[2];
11 comm_size = arg[3];
12 slave_count = arg[4]
13
14
15 if (#arg ~= 4) then
16     error("Argc should be 4");
17 end
18 simgrid.info("Argc="..(#arg).." (should be 4)")
19
20 -- Dispatch the tasks
21
22 for i=1,nb_task do
23   tk = simgrid.Task.new("Task "..i,comp_size,comm_size);
24   alias = "slave "..(i%slave_count);
25   simgrid.info("Master sending  '" .. simgrid.Task.name(tk) .."' To '" .. alias .."'");
26   simgrid.Task.send(tk,alias); -- C user data set to NULL
27   simgrid.info("Master done sending '".. simgrid.Task.name(tk) .."' To '" .. alias .."'");
28 end
29
30 -- Sending Finalize Message To Others
31
32 simgrid.info("Master: All tasks have been dispatched. Let's tell everybody the computation is over.");
33 for i=0,slave_count-1 do
34   alias = "slave "..i;
35   simgrid.info("Master: sending finalize to "..alias);
36   finalize = simgrid.Task.new("finalize",comp_size,comm_size);
37   simgrid.Task.send(finalize,alias)
38 end
39   simgrid.info("Master: Everything's done.");
40 end
41
42 -- Slave Function ---------------------------------------------------------
43 function Slave(...)
44
45 local my_mailbox="slave "..arg[1]
46 simgrid.info("Hello from lua, I'm a poor slave with mbox: "..my_mailbox)
47
48 while true do
49
50   local tk = simgrid.Task.recv(my_mailbox);
51   if (simgrid.Task.name(tk) == "finalize") then
52     simgrid.info("Slave '" ..my_mailbox.."' got finalize msg");
53     break
54   end
55   --local tk_name = simgrid.Task.name(tk) 
56   simgrid.info("Slave '" ..my_mailbox.."' processing "..simgrid.Task.name(tk))
57   simgrid.Task.execute(tk)
58   simgrid.info("Slave '" ..my_mailbox.."': task "..simgrid.Task.name(tk) .. " done")
59 end -- while
60
61 simgrid.info("Slave '" ..my_mailbox.."': I'm Done . See You !!");
62
63 end -- function ----------------------------------------------------------
64 --]]
65
66 require "simgrid"
67   
68   --simgrid.Host.new(host_id,power)
69   simgrid.Host.new("Tremblay",98095000);
70   simgrid.Host.new("Jupiter",76296000);
71   simgrid.Host.new("Fafard",76296000);
72   simgrid.Host.new("Ginette",48492000);
73   simgrid.Host.new("Bourassa",48492000);
74
75     -- create Links
76   for i=0,11 do
77     simgrid.Link.new(i,252750+ i*768,0.000270544+i*0.087);    -- let's create link !! with crazy values ;)
78   end
79
80
81
82   -- simgrid.Route.new(src_id,des_id,links_nb,links_list)
83   simgrid.Route.new("Tremblay","Jupiter",1,{"1"});
84   simgrid.Route.new("Tremblay","Fafard",6,{"0","1","2","3","4","8"});
85   simgrid.Route.new("Tremblay","Ginette",3,{"3","4","5"});
86   simgrid.Route.new("Tremblay","Bourassa",7,{"0","1","3","2","4","6","7"});
87
88    simgrid.Route.new("Jupiter","Tremblay",1,{"1"});
89    simgrid.Route.new("Jupiter","Fafard",7,{"0","1","2","3","4","8","9"});
90    simgrid.Route.new("Jupiter","Ginette",4,{"3","4","5","9"});
91    simgrid.Route.new("Jupiter","Bourassa",8,{"0","1","2","3","4","6","7","9"});
92  
93    simgrid.Route.new("Fafard","Tremblay",6,{"0","1","2","3","4","8"});
94    simgrid.Route.new("Fafard","Jupiter",7,{"0","1","2","3","4","8","9"});
95    simgrid.Route.new("Fafard","Ginette",5,{"0","1","2","5","8"});
96    simgrid.Route.new("Fafard","Bourassa",3,{"6","7","8"});
97   
98    simgrid.Route.new("Ginette","Tremblay",3,{"3","4","5"});
99    simgrid.Route.new("Ginette","Jupiter",4,{"3","4","5","9"});
100    simgrid.Route.new("Ginette","Fafard",5,{"0","1","2","5","8"});
101    simgrid.Route.new("Ginette","Bourassa",6,{"0","1","2","5","6","7"});
102
103    simgrid.Route.new("Bourassa","Tremblay",7,{"0","1","3","2","4","6","7"});
104    simgrid.Route.new("Bourassa","Jupiter",8,{"0","1","2","3","4","6","7","9"});
105    simgrid.Route.new("Bourassa","Fafard",3,{"6","7","8"});
106    simgrid.Route.new("Bourassa","Ginette",6,{"0","1","2","5","6","7"});
107   
108    --Save Platform
109    simgrid.info("start registering platform");
110    simgrid.register_platform();
111    simgrid.info("platform registered");
112
113   
114   --Set Application
115
116   --simgrid.Host.setFunction(host_id,function_name,args_nb,args_list)
117    simgrid.Host.setFunction("Tremblay","Master",4,{"20","550000000","1000000","4"});
118    simgrid.Host.setFunction("Bourassa","Slave",1,{"0"});
119    simgrid.Host.setFunction("Jupiter","Slave",1,{"1"});
120    simgrid.Host.setFunction("Fafard","Slave",1,{"2"});
121    simgrid.Host.setFunction("Ginette","Slave",1,{"3"});
122    
123   --Save Application 
124    simgrid.register_application();
125
126 -- Run The Application
127
128    simgrid.run()
129    simgrid.info("Simulation's over.See you.")
130    simgrid.clean()