Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
401c17dd9083b7e0c34d3ea5029bda9d18edea7f
[simgrid.git] / examples / lua / SimSplay / sim_splay.lua
1 require "simgrid"
2 -- Splay global modules
3 rpc = {}
4 log = {}
5 job = {}
6 event = {}
7 os = {}
8 start = {}
9 -- Splay global variables
10 job.me ={}
11 job.nodes = {}
12 job.list_type = "random"
13
14 --Init nodes tables
15 function init_nodes()
16         for i= 1,simgrid.Host.number() do               
17                 job.nodes[i] = simgrid.Host.getPropValue(simgrid.Host.at(i),"ip")..":"..simgrid.Host.getPropValue(simgrid.Host.at(i),"port");
18         end     
19 end
20
21 function init_jobs()
22    init_nodes()
23 end
24
25 -- Job methods
26 function job.me.ip()
27      return simgrid.Host.getPropValue(simgrid.Host.self(),"ip");
28 end
29
30 function job.me.port()
31  return simgrid.Host.getPropValue(simgrid.Host.self(),"port");
32 end
33
34 function job.position()
35   return simgrid.Host.getPropValue(simgrid.Host.self(),"position");
36 end
37
38 -- log Methods
39 function log:print(msg)
40   simgrid.info(msg);
41 end
42
43 -- rpc Methods
44 function rpc.call(node,call)
45  --init_nodes();
46  func = "empty"
47  arg = "empty"
48  mailbox = node
49
50  if type(call) == "table" then
51         func = call[1]
52         arg = call[2]
53  end
54  task_call = simgrid.Task.new("splay_task",10000,10000);
55  task_call['func_call_name'] = func;
56  task_call['func_call_arg'] = arg;
57  --log:print("Sending Task to mailbox "..mailbox.." to call "..func.." with arg "..arg);
58  simgrid.Task.iSend(task_call,mailbox);
59  call_function(func,arg)
60 end 
61
62 -- event Methods
63 function event.sleep(time)
64   my_mailbox = job.me.ip()..":"..job.me.port()
65   task = simgrid.Task.splay_recv(my_mailbox, time)
66 end
67
68 -- main func for each process, this is equivalent to the Deploiment file 
69 function event.thread(main_func)
70   dofile("platform_script.lua");
71  init_jobs()
72 end
73
74 -- OS methods
75 function os.exit()
76  simgrid.Host.destroy(simgrid.Host.self());
77 end
78
79 -- Start Methods
80 function start.loop()
81  simgrid.run()
82  simgrid.clean()
83 end
84 -- useful functions
85 function call_function(fct,arg)
86     _G[fct](arg)
87 end
88
89 function SPLAYschool()
90  simgrid.info("Calling me...")
91 end