Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Solve white space conflicts
[simgrid.git] / doc / user_guide / doxygen / bindings.doc
1 /*! \page bindings Bindings
2
3
4 \section bindings_binding_Java Java Binding
5 <a href="http://simgrid.gforge.inria.fr/simgrid-java/1.2/doc/">Simgrid-Java documentation</a>.
6
7 \section bindings_binding_Ruby Ruby Binding
8 <a href="http://simgrid.gforge.inria.fr/simgrid-ruby/1.0/doc/">Simgrid-Ruby documentation</a>.
9
10 \section bindings_binding_lua Lua Binding
11
12 Most of Simgrid modules require a  good level in C programming, since simgrid is used to be as standard C library.
13  Sometime users prefer using some kind of “easy scripts” or a language easier to code with, for their works,
14  which avoid dealing with C errors, and sometime an important  gain of time.
15 Besides Java Binding, Lua  and Ruby bindings are available since version 3.4 of Simgrid
16 for MSG Module, and we are currenlty working on bindings for other modules.
17
18
19 \subsection bindings_binding_lua_about What is lua ?
20 Lua is a lightweight, reflective, imperative and functional programming language,
21  designed as a scripting language with extensible semantics as a primary goal (see official web site <a href="http://www.lua.org">here</a>).
22 \subsubsection bindings_binding_lua_why Why lua ?
23 Lua is a fast, portable and powerful script language, quite simple to use for developpers.
24 it combines procedural features with powerful data description facilities,
25  by using a simple, yet powerful, mechanism of tables.
26 Lua has a relatively simple C API compared to other scripting languages,
27 and accordingly it provides a robust, easy to use it.
28 \subsubsection bindings_binding_lua_simgrid How to use lua in Simgrid ?
29 Actually, the use of lua in Simgrid is quite simple, you have just to follow the same steps as coding with C in Simgird :
30   - Coding functions coresponding to each process
31   - loading the platforme/deployment XML file that describe the environment of simulation
32   - and … Running the Simulation.
33
34 \dontinclude lua/masterslave/master.lua
35 \subsection bindings_binding_lua_example_master_slave Master/Slave Example
36
37  \li Master Code
38  \until end_of_master
39 we mainly  use   simgrid.Task.new(task_name,computation_size,communication_size) to create our MSG Task,
40          then simgrid.Task.send(task,alias) to send it.
41 we use also simgrid.Task.name(task), to get the task's name.
42
43 \dontinclude lua/masterslave/slave.lua
44 \li Slave Code
45 \until end_of_slave
46 Here, we see the use of simgrid.Task.recv(alias) to receive a task with a specific alias,
47 this function return directly the task recevied.
48
49 \dontinclude lua/masterslave/master_slave.lua
50 \li Set Environmenet and run application
51 \until simgrid.clean()
52
53 \subsection bindings_binding_lua_example_data Exchanging Data
54 You can also exchange data between Process using lua. for that, you have to deal with lua task as a table,
55 since lua is based itself on a mechanism of tables,
56 so you can exchange any kind of data (tables, matrix, strings,…) between process via tasks.
57
58 \li Sender process
59 \verbatim
60   task = simgrid.Task.new("data_task",task_comp,task_comm);
61   task['matrix'] = my_matrix;
62   task['table'] = my_table;
63   task['message'] = "Hello from (Lua || Simgrid ) !! "
64   …
65   simgrid.Task.send(task,alias)
66 \endverbatim
67         After creating task, we associate to it various kind of data with a specific key (string in this case)
68         to distinguish between data variables. The receiver will use this key to access easily to datas.
69
70
71 \li Receiver processe
72 \verbatim
73   task = simgrid.Task.recv(alias);
74   sender_matrix = task['matrix'];
75   sender_table = task['table'];
76   sender_message = task['message']
77   ...
78 \endverbatim
79         Note that in lua, both sender and receiver share the same lua task.
80         So that the receiver could joint data directly on the received task without sending it back.
81         You can find  a complet example (matrix multiplication case) in the file example/lua/mult_matrix.lua.
82
83
84 \subsection bindings_binding_lua_example_bypass Bypass XML
85         maybe you wonder if there is a way to bypass the XML files,
86          and describe your platform directly from the code, with lua bindings it's Possible !! how ?
87         We provide some additional (tricky?) functions in lua that allows you to set up your own platform without using the XML files
88      ( this can be useful for large platforms, so a simple for loop will avoid you to deal with an annoying XML File ;) )
89
90
91 \li set Routing mode
92 \verbatim
93    simgrid.AS.new{id="AS0",mode="Full"};
94 \endverbatim
95
96 \li set Hosts
97 \verbatim
98   simgrid.Host.new{id="Tremblay",power=98095000};
99   simgrid.Host.new{id="Jupiter",power=76296000};
100   simgrid.Host.new{id="Fafard",power=76296000};
101   simgrid.Host.new{id="Ginette",power=48492000};
102   simgrid.Host.new{id="Bourassa",power=48492000};
103 \endverbatim
104   we use simgrid.Host.new{id=id_host,power=power_host} to instanciate our hosts.
105
106 \li set Links
107 \verbatim
108   for i=0,11 do
109     simgrid.Link.new{id=i,bandwidth=252750+ i*768,latency=0.000270544+i*0.087};    --  some crazy values ;)
110   end
111 \endverbatim
112   we used simgrid.Link.new{id=link_id,bandwidth=bw,latency=lat} with a simple for loop to create all links we need (much easier than XML hein ?)
113
114 \li set Routes
115 \verbatim
116 -- simgrid.Route.new(src_id,des_id,links_nb,links_list)
117    simgrid.Route.new("Tremblay","Jupiter",1,{"1"});
118    simgrid.Route.new("Tremblay","Fafard",6,{"0","1","2","3","4","8"});
119    simgrid.Route.new("Tremblay","Ginette",3,{"3","4","5"});
120    simgrid.Route.new("Tremblay","Bourassa",7,{"0","1","3","2","4","6","7"});
121
122    simgrid.Route.new("Jupiter","Tremblay",1,{"1"});
123    simgrid.Route.new("Jupiter","Fafard",7,{"0","1","2","3","4","8","9"});
124    simgrid.Route.new("Jupiter","Ginette",4,{"3","4","5","9"});
125    simgrid.Route.new("Jupiter","Bourassa",8,{"0","1","2","3","4","6","7","9"});
126    ...
127 \endverbatim
128   for each host you have to specify which route to choose to access to the rest of hosts connected in the grid.
129
130 \li Save platform
131 \verbatim
132   simgrid.register_platform();
133 \endverbatim
134 Don't forget to register your platform, that SURF callbacks starts their work ;)
135
136 \li set application
137 \verbatim
138    simgrid.Host.setFunction("Tremblay","Master",4,{"20","550000000","1000000","4"});
139    simgrid.Host.setFunction("Bourassa","Slave",1,{"0"});
140    simgrid.Host.setFunction("Jupiter","Slave",1,{"1"});
141    simgrid.Host.setFunction("Fafard","Slave",1,{"2"});
142    simgrid.Host.setFunction("Ginette","Slave",1,{"3"});
143 \endverbatim
144   you don't  need to use a deployment XML file, thanks to  simgrid.Host.setFunction(host_id,function,args_number,args_list)
145   you can associate functions for each host with arguments if needed .
146
147 \li
148 \verbatim
149    simgrid.register_application();
150 \endverbatim
151 Yes, Here too you have to register your application before running the simulation.
152
153 the full example is distributed in the file examples/lua/master_slave_bypass.lua
154
155  */