2 @defgroup MSG_examples MSG Examples
3 @ingroup MSG_User_Guide
6 MSG comes with an extensive set of examples. It is sometimes difficult
7 to find the one you need. This list aims at helping you finding the
8 example from which you can learn what you want to.
10 @section MSG_ex_basics Basic examples and features
15 @defgroup MSG_ex_asynchronous_communications Asynchronous communications
18 Simulation of asynchronous communications between a sender and a receiver using a realistic platform and
19 an external description of the deployment.
21 \section MSG_ex_ms_TOC Table of contents:
22 - \ref MSG_ext_icomms_code
23 - \ref MSG_ext_icomms_preliminary
24 - \ref MSG_ext_icomms_Sender
25 - \ref MSG_ext_icomms_Receiver
26 - \ref MSG_ext_icomms_core
27 - \ref MSG_ext_icomms_Main
28 - \ref MSG_ext_icomms_fct_Waitall
29 - \ref MSG_ext_icomms_fct_Waitany
33 \dontinclude msg/icomms/peer.c
35 \section MSG_ext_icomms_code Code of the application
37 \subsection MSG_ext_icomms_preliminary Preliminary declarations
39 \until Sender function
41 \subsection MSG_ext_icomms_Sender Sender function
43 The sender send to a receiver an asynchronous message with the function "MSG_task_isend()". Cause this function is non-blocking
44 we have to make "MSG_comm_test()" to know if the communication is finished for finally destroy it with function "MSG_comm_destroy()".
45 It also available to "make MSG_comm_wait()" which make both of them.
47 C style arguments (argc/argv) are interpreted as:
48 - the number of tasks to distribute
49 - the computation size of each task
50 - the size of the files associated to each task
51 - a list of host that will accept those tasks.
52 - the time to sleep at the beginning of the function
53 - This time defined the process sleep time
54 if time = 0 use of MSG_comm_wait()
55 if time > 0 use of MSG_comm_test()
58 \until Receiver function
60 \subsection MSG_ext_icomms_Receiver Receiver function
62 This function executes tasks when it receives them. As the receiving is asynchronous we have to test the communication to know
63 if it is completed or not with "MSG_comm_test()" or wait for the completion "MSG_comm_wait()".
65 C style arguments (argc/argv) are interpreted as:
66 - the id to use for received the communication.
67 - the time to sleep at the beginning of the function
68 - This time defined the process sleep time
69 if time = 0 use of MSG_comm_wait()
70 if time > 0 use of MSG_comm_test()
74 \subsection MSG_ext_icomms_core Simulation core
76 This function is the core of the simulation and is divided only into 3 parts
77 thanks to MSG_create_environment() and MSG_launch_application().
78 -# Simulation settings : MSG_create_environment() creates a realistic
80 -# Application deployment : create the processes on the right locations with
81 MSG_launch_application()
82 -# The simulation is run with #MSG_main()
85 - <i>platform_file</i>: the name of a file containing an valid surfxml platform description.
86 - <i>application_file</i>: the name of a file containing a valid surfxml application description
90 \subsection MSG_ext_icomms_Main Main function
92 This initializes MSG, runs a simulation, and free all data-structures created by MSG.
96 \dontinclude msg/icomms/peer2.c
98 \section MSG_ext_icomms_fct_Waitall Waitall function for sender
100 The use of this function permit to send all messages and wait for the completion of all in one time.
102 \skipline Sender function
105 \section MSG_ext_icomms_fct_Waitany Waitany function
107 The MSG_comm_waitany() function return the place of the first message send or receive from a xbt_dynar_t table.
109 \subsection MSG_ext_icomms_fct_Waitany_sender From a sender
110 We can use this function to wait all sent messages.
111 \dontinclude msg/icomms/peer3.c
112 \skipline Sender function
115 \subsection MSG_ext_icomms_fct_Waitany_receiver From a receiver
116 We can also wait for the arrival of all messages.
117 \dontinclude msg/icomms/peer3.c
118 \skipline Receiver function
119 \until end_of_receiver
125 @defgroup MSG_ex_master_slave Basic Master/Slaves
126 @ingroup MSG_examples
128 Simulation of a master-slave application using a realistic platform
129 and an external description of the deployment.
131 \section MSG_ex_ms_TOC Table of contents:
133 - \ref MSG_ext_ms_code
134 - \ref MSG_ext_ms_preliminary
135 - \ref MSG_ext_ms_master
136 - \ref MSG_ext_ms_slave
137 - \ref MSG_ext_ms_forwarder
138 - \ref MSG_ext_ms_core
139 - \ref MSG_ext_ms_main
140 - \ref MSG_ext_ms_helping
141 - \ref MSG_ext_ms_application
142 - \ref MSG_ext_ms_platform
146 \dontinclude msg/masterslave/masterslave_forwarder.c
148 \section MSG_ext_ms_code Code of the application
150 \subsection MSG_ext_ms_preliminary Preliminary declarations
156 \subsection MSG_ext_ms_master Master code
158 This function has to be assigned to a m_process_t that will behave as
159 the master. It should not be called directly but either given as a
160 parameter to #MSG_process_create() or registered as a public function
161 through #MSG_function_register() and then automatically assigned to a
162 process through #MSG_launch_application().
164 C style arguments (argc/argv) are interpreted as:
165 - the number of tasks to distribute
166 - the computation size of each task
167 - the size of the files associated to each task
168 - a list of host that will accept those tasks.
170 Tasks are dumbly sent in a round-robin style.
174 \subsection MSG_ext_ms_slave Slave code
176 This function has to be assigned to a #m_process_t that has to behave
177 as a slave. Just like the master fuction (described in \ref
178 MSG_ext_ms_master), it should not be called directly.
180 This function keeps waiting for tasks and executes them as it receives them.
184 \subsection MSG_ext_ms_forwarder Forwarder code
186 This function has to be assigned to a #m_process_t that has to behave
187 as a forwarder. Just like the master function (described in \ref
188 MSG_ext_ms_master), it should not be called directly.
190 C style arguments (argc/argv) are interpreted as a list of host that
191 will accept those tasks.
193 This function keeps waiting for tasks and dispathes them to its slaves.
195 \until end_of_forwarder
197 \subsection MSG_ext_ms_core Simulation core
199 This function is the core of the simulation and is divided only into 3 parts
200 thanks to MSG_create_environment() and MSG_launch_application().
201 -# Simulation settings : MSG_create_environment() creates a realistic
203 -# Application deployment : create the processes on the right locations with
204 MSG_launch_application()
205 -# The simulation is run with #MSG_main()
208 - <i>platform_file</i>: the name of a file containing an valid surfxml platform description.
209 - <i>application_file</i>: the name of a file containing a valid surfxml application description
211 \until end_of_test_all
213 \subsection MSG_ext_ms_main Main() function
215 This initializes MSG, runs a simulation, and free all data-structures created by MSG.
219 \section MSG_ext_ms_helping Helping files
221 \subsection MSG_ext_ms_application Example of application file
223 \include msg/masterslave/deployment_masterslave.xml
225 \subsection MSG_ext_ms_platform Example of platform file
227 \include msg/small_platform.xml
231 /** \page MSG_ex_master_slave_lua Master/slave Lua application
233 Simulation of a master-slave application using lua bindings
234 - \ref MSG_ext_ms_code_lua
235 - \ref MSG_ext_ms_master_lua
236 - \ref MSG_ext_ms_slave_lua
237 - \ref MSG_ext_ms_core_lua
239 - \ref MSG_ext_ms_helping
240 - \ref MSG_ext_ms_application
241 - \ref MSG_ext_ms_platform
244 \dontinclude lua/masterslave/master_slave.lua
246 \section MSG_ext_ms_code_lua Code of the application
248 \subsection MSG_ext_ms_master_lua Master code
250 as described ine the C native master/Slave exmaple , this function has to be assigned to a m_process_t that will behave as the master.
252 Lua style arguments (...) in for the master are interpreted as:
253 - the number of tasks to distribute
254 - the computation size of each task
255 - the size of the files associated to each task
256 - a list of host that will accept those tasks.
258 Tasks are dumbly sent in a round-robin style.
263 \subsection MSG_ext_ms_slave_lua Slave code
265 This function has to be assigned to a #m_process_t that has to behave as a slave.
266 This function keeps waiting for tasks and executes them as it receives them.
269 \subsection MSG_ext_ms_core_lua Simulation core
271 in this section the core of the simulation which start by including the simgrid lib for bindings
272 : <i>require "simgrid" </i>
274 -# Simulation settings : <i>simgrid.platform</i> creates a realistic
276 -# Application deployment : create the processes on the right locations with
277 <i>simgrid.application</i>
278 -# The simulation is run with <i>simgrid.run</i>
281 - <i>platform_file</i>: the name of a file containing an valid surfxml platform description.( first command line argument)
282 - <i>application_file</i>: the name of a file containing a valid surfxml application description ( second commande line argument )
284 \until simgrid.clean()
288 /** \page MSG_ex_master_slave_lua_bypass Master/slave Bypass Lua application
290 Simulation of a master-slave application using lua bindings, Bypassing the XML parser
291 - \ref MSG_ext_ms_code_lua
292 - \ref MSG_ext_ms_master_lua
293 - \ref MSG_ext_ms_slave_lua
294 - \ref MSG_ext_ms_core_lua
297 \dontinclude lua/console/master_slave_bypass.lua
299 \section MSG_ext_ms_code_lua Code of the application
301 \subsection MSG_ext_ms_master_lua Master code
303 as described ine the C native master/Slave exmaple , this function has to be assigned to a m_process_t that will behave as the master.
305 Lua style arguments (...) in for the master are interpreted as:
306 - the number of tasks to distribute
307 - the computation size of each task
308 - the size of the files associated to each task
309 - a list of host that will accept those tasks.
311 Tasks are dumbly sent in a round-robin style.
316 \subsection MSG_ext_ms_slave_lua Slave code
318 This function has to be assigned to a #m_process_t that has to behave as a slave.
319 This function keeps waiting for tasks and executes them as it receives them.
322 \subsection MSG_ext_ms_core_lua Simulation core
324 in this section the core of the simulation which start by including the simgrid lib for bindings, then create the resources we need to set up our environment bypassing the XML parser.
325 : <i>require "simgrid" </i>
327 -# Hosts : <i>simgrid.Host.new</i> instanciate a new host with an id, and power.
328 -# Links : <i>simgrid.Link.new</i> instanictae a new link that will require an id, bandwith and latency values.
329 -# Route : <i>simgrid.Route.new</i> define a route between two hosts specifying the links to use.
330 -# Simulation settings : <i>simgrid.register_platform();</i> register own platform without using the XML SURF parser.
332 we can also bypass the XML deployment file, and associate functions for each of defined hosts.
333 - <i>simgrid.Host.setFunction</i>: associate a function to a host, specifying arguments if needed.
334 - <i>simgrid.register_application()</i>: saving the deployment settings before running the simualtion.
336 \until simgrid.clean()