Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
various cosmetics improvements
[simgrid.git] / src / bindings / lua / tasklua.lua
1
2 --Master Function
3 function master(...) 
4
5 print("Hello from lua, I'm the master")
6 for i,v in ipairs(arg) do
7     print("Got "..v)
8 end
9
10 nb_task = arg[1];
11 comp_size = arg[2];
12 comm_size = arg[3];
13 slave_count = arg[4]
14
15
16 argc=#arg
17 print("Argc="..argc.." (should be 4)")
18
19 -- Dispatch the tasks
20
21 for i=1,nb_task do
22   tk = Msg.Task.new("Task "..i,comp_size,comm_size);
23   alias = "slave "..(i%slave_count);
24   print("Master sending  '" .. Msg.Task.name(tk) .."' To '" .. alias .."'");
25   Msg.Task.send(tk,alias); -- C user data set to NULL
26   print("Master done sending '".. Msg.Task.name(tk) .."' To '" .. alias .."'");
27 end
28
29 --[[
30 Sending Finalize Message To Others
31 --]]
32
33 print("Master: All tasks have been dispatched. Let's tell everybody the computation is over.");
34 for i=0,slave_count-1 do
35   alias = "slave "..i;
36   print("Master: sending finalize to "..alias);
37   Msg.Task.send(Msg.Task.new("finalize",0,0),alias);
38 end
39 print("Master: Everything's done.");
40
41
42 end
43
44 --Slave Function ---------------------------------------------------------
45 function slave(...)
46
47 my_mailbox="slave "..arg[1]
48 print("Hello from lua, I'm a poor slave with mbox: "..my_mailbox)
49
50
51 while true do
52 --  tk = Msg.Task.new("",0,0); --??
53 --  Msg.Task.recv2(tk,my_mailbox);
54   tk = Msg.Task.recv(my_mailbox);
55   
56   tk_name = Msg.Task.name(tk)
57
58   if (tk_name == "finalize") then
59     print("Slave '" ..my_mailbox.."' got finalize msg");
60     break
61   end
62
63   print("Slave '" ..my_mailbox.."' processing "..Msg.Task.name(tk))
64   Msg.Task.execute(tk);
65
66   print("Slave '" ..my_mailbox.."': task "..Msg.Task.name(tk) .. " done")
67 end -- while
68
69 print("Slave '" ..my_mailbox.."': I'm Done . See You !!");
70
71 end -- function ----------------------------------------------------------
72 --]]