Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first draft of lua bindings
[simgrid.git] / src / bindings / lua / tasklua.lua
1 function getn(t)
2   if type(t.n) == "number" then return t.n end
3   local max=0
4   for i,_ in to do
5     if type(i) == "number" and i>max then max=i end
6   end
7   t.n = max
8   return max
9 end
10
11 --Master Function
12 function master(...) 
13
14 print("Hello from lua, I'm the master")
15 for i,v in ipairs(arg) do
16     print("Got "..v)
17 end
18 t_tasks={}   --tasks table
19 t_slaves={}  --slaves table
20
21 nb_task = arg[1];
22 comp_size = arg[2];
23 comm_size = arg[3];
24
25 -- Let's Create the tasks to dispatch
26 for i=1,nb_task do
27   t_tasks[i] = Task.new("Task "..i,comp_size,comm_size); --data set to NULL
28 end
29
30
31 -- Process Organisation
32
33 argc=getn(arg)
34 print("Argc="..argc.." (should be 8)")
35
36 slave_count = getn(arg) -3;
37
38 for i=4,argc do
39 slv_name = arg[i];
40 t_slaves[i - 3] = Host.new(slv_name);
41 -- do not do directly that : t_slaves[i - 4] = Host.new(argv[i]); 
42 end
43
44
45
46
47 -- Print List Of Tasks / Slaves
48 --[[
49 for  i=1,nb_task do
50 todo = Task.name(t_tasks[i]);
51 print(i % slave_count+1);
52 slv = Host.name(t_slaves[i % slave_count+1]);
53 print ( "Sending : " .. todo .. " To : " .. slv);
54 end
55 ]]--
56
57
58
59 for i=1,nb_task do
60 tk_name = Task.name(t_tasks[i]);
61 ht_name = Host.name(t_slaves[i]);
62 print("Sending  " .. tk_name .." To " .. ht_name);
63 Task.send(t_task[i],"slave "..(i%slave_count));
64 print("Sent");
65 end
66
67 end
68
69 --Slave Function ---------------------------------------------------------
70 function slave(...)
71
72 my_mailbox="slave "..arg[1]
73 print("Hello from lua, I'm a poor slave with mbox: "..my_mailbox)
74
75 while true do
76   tk = Task.recv(my_mailbox);
77   print("Got something");
78   --testing res !!!!
79   tk_name = Task.name(tk)
80
81   if (tk_name == "finalize") then
82     Task.destroy(tk);
83    end
84
85   print("Processing "..Task.name(tk))
86   Task.execute(tk);
87
88   print(Task.name(tk) .. "Done")
89   Task.destroy(tk);
90 end -- while
91
92 print("I'm Done . See You !!");
93
94 end -- function ----------------------------------------------------------
95 --]]