Logo AND Algorithmique Numérique Distribuée

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