1 /** \addtogroup MSG_API
3 MSG was the first distributed programming environment provided within
4 SimGrid. While almost realistic, it remains quite simple (simplistic?).
5 This describes the native to MSG.
7 \section jMSG_who Who should use this (and who shouldn't)
9 You should use MSG if you want to study some heuristics for a
10 given problem you don't really want to implement. If you want to
11 use the C programming language, your are in the right
12 section. To use the Java or Ruby programming interfaces, please refer to
13 the documentation provided in the relevant packages.
15 \section MSG_funct Offered functionnalities
16 - \ref m_process_management
17 - \ref m_datatypes_management
18 - \ref m_host_management
19 - \ref m_task_management
20 - \ref m_file_management
21 - \ref msg_trace_driven
22 - \ref msg_gos_functions
23 - \ref msg_deprecated_functions
26 Also make sure to visit the page @ref MSG_examples.
30 @defgroup MSG_examples MSG Examples
33 @htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Examples" --> @endhtmlonly
35 MSG comes with an extensive set of examples. It is sometimes difficult
36 to find the one you need. This list aims at helping you finding the
37 example from which you can learn what you want to.
39 @section MSG_ex_basics Basic examples and features
44 @defgroup msg_simulation Main MSG simulation Functions
46 @brief Describes how to setup and control your simulation.
48 The basic workflow is the following (check the \ref MSG_examples for
51 -# Initialize the library with #MSG_global_init
52 -# Create a platform (usually by parsing a file with
53 #MSG_create_environment)
54 -# Register the functions that your processes are supposed to run with
55 #MSG_function_register (and maybe #MSG_function_register_default)
56 -# Launch your processes from a deployment file with #MSG_launch_application
57 -# Run the simulation with #MSG_main
58 -# Cleanup the library with #MSG_clean before ending your program
61 @htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Simulation Control" --> @endhtmlonly
65 /** @defgroup m_datatypes_management MSG Data Types
67 @brief This section describes the different datatypes provided by MSG.
69 \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Data types" --> \endhtmlonly
72 /** @defgroup m_process_management Process Management Functions
74 * @brief This section describes the process structure of MSG
75 * (#m_process_t) and the functions for managing it.
78 /** @defgroup m_host_management Host Management Functions
80 * @brief This section describes the host structure of MSG
83 /** @defgroup m_task_management Task Management Functions
85 * @brief This section describes the task structure of MSG
86 * (#m_task_t) and the functions for managing it.
89 /** @defgroup m_file_management File Management Functions
91 * @brief This section describes the file structure of MSG
92 * (#m_file_t) and the functions for managing it. It
93 * is based on POSIX functions.
97 @defgroup msg_trace_driven Trace-driven simulations
99 @brief This section describes the functions allowing to build trace-driven simulations.
101 \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Trace-Driven" --> \endhtmlonly
103 This is very handy when you want to test an algorithm or protocol that
104 does nothing unless it receives some events from outside. For example,
105 a P2P protocol reacts to requests from the user, but does nothing if
106 there is no such event.
108 In such situations, SimGrid allows to write your protocol in your C
109 file, and the events to react to in a separate text file. Declare a
110 function handling each of the events that you want to accept in your
111 trace files, register them using #MSG_action_register in your main,
112 and then use #MSG_action_trace_run to launch the simulation. You can
113 either have one trace file containing all your events, or a file per
116 Check the examples in <b>examples/msg/actions/actions.c</b> for details.
120 /** @defgroup msg_gos_functions MSG Operating System Functions
122 * @brief This section describes the functions that can be used
123 * by a process for handling some task.
128 @defgroup MSG_LUA Lua bindings
130 @brief Lua bindings to MSG (\ref MSG_API)
132 @htmlonly <!-- DOXYGEN_NAVBAR_LABEL="LUA bindings" --> @endhtmlonly
134 This is the lua bindings of the \ref MSG_API interface.
136 \section lMSG_who Who should use this (and who shouldn't)
138 If you want to use MSG to study your algorithm, but you don't want to
139 use the C language (using \ref MSG_API), then you should use some
140 bindings such as this one. The advantage of the lua bindings is that
141 they are distributed directly with the main archive (in contrary to
142 Java and Ruby bindings, for example, that are distributed separately).
143 Another advantage of lua is that there is almost no performance loss
144 with regard to the C version (at least there shouln't be any -- it is
145 still to be precisely assessed).
147 \section MSG_Lua_funct Lua offered functionnalities in MSG
149 Almost all important features of the MSG interface are available from
150 the lua bindings. Unfortunately, since doxygen does not support the
151 lua modules implemented directly in C as we are using, there is no
152 ready to use reference documentation for this module. Even more than
153 for the other modules, you will have to dig into the source code of
154 the examples to learn how to use it.
156 \section Lua_examples Examples of lua MSG
158 - \ref MSG_ex_master_slave_lua
159 - \ref MSG_ex_master_slave_lua_bypass
160 - Also, the lua version of the Chord example (in the source tree)
161 is a working non-trivial example of use of the lua bindings
165 @defgroup msg_deprecated_functions MSG Deprecated
167 @brief This section describes the deprecated functions. PLEASE STOP USING THEM.
169 We don't remove them because the ability to run old scientific
170 code is something important to us. But these functionalities are
171 not actively supported anymore.
173 To access these functions, you should define the relevant option
174 at configuration time in ccmake.
179 @defgroup MSG_ex_asynchronous_communications Asynchronous communications
180 @ingroup MSG_examples
182 Simulation of asynchronous communications between a sender and a receiver using a realistic platform and
183 an external description of the deployment.
185 \section MSG_ex_ms_TOC Table of contents:
186 - \ref MSG_ext_icomms_code
187 - \ref MSG_ext_icomms_preliminary
188 - \ref MSG_ext_icomms_Sender
189 - \ref MSG_ext_icomms_Receiver
190 - \ref MSG_ext_icomms_core
191 - \ref MSG_ext_icomms_Main
192 - \ref MSG_ext_icomms_fct_Waitall
193 - \ref MSG_ext_icomms_fct_Waitany
197 \dontinclude msg/icomms/peer.c
199 \section MSG_ext_icomms_code Code of the application
201 \subsection MSG_ext_icomms_preliminary Preliminary declarations
203 \until Sender function
205 \subsection MSG_ext_icomms_Sender Sender function
207 The sender send to a receiver an asynchronous message with the function "MSG_task_isend()". Cause this function is non-blocking
208 we have to make "MSG_comm_test()" to know if the communication is finished for finally destroy it with function "MSG_comm_destroy()".
209 It also available to "make MSG_comm_wait()" which make both of them.
211 C style arguments (argc/argv) are interpreted as:
212 - the number of tasks to distribute
213 - the computation size of each task
214 - the size of the files associated to each task
215 - a list of host that will accept those tasks.
216 - the time to sleep at the beginning of the function
217 - This time defined the process sleep time
218 if time = 0 use of MSG_comm_wait()
219 if time > 0 use of MSG_comm_test()
222 \until Receiver function
224 \subsection MSG_ext_icomms_Receiver Receiver function
226 This function executes tasks when it receives them. As the receiving is asynchronous we have to test the communication to know
227 if it is completed or not with "MSG_comm_test()" or wait for the completion "MSG_comm_wait()".
229 C style arguments (argc/argv) are interpreted as:
230 - the id to use for received the communication.
231 - the time to sleep at the beginning of the function
232 - This time defined the process sleep time
233 if time = 0 use of MSG_comm_wait()
234 if time > 0 use of MSG_comm_test()
238 \subsection MSG_ext_icomms_core Simulation core
240 This function is the core of the simulation and is divided only into 3 parts
241 thanks to MSG_create_environment() and MSG_launch_application().
242 -# Simulation settings : MSG_create_environment() creates a realistic
244 -# Application deployment : create the processes on the right locations with
245 MSG_launch_application()
246 -# The simulation is run with #MSG_main()
249 - <i>platform_file</i>: the name of a file containing an valid surfxml platform description.
250 - <i>application_file</i>: the name of a file containing a valid surfxml application description
254 \subsection MSG_ext_icomms_Main Main function
256 This initializes MSG, runs a simulation, and free all data-structures created by MSG.
260 \dontinclude msg/icomms/peer2.c
262 \section MSG_ext_icomms_fct_Waitall Waitall function for sender
264 The use of this function permit to send all messages and wait for the completion of all in one time.
266 \skipline Sender function
269 \section MSG_ext_icomms_fct_Waitany Waitany function
271 The MSG_comm_waitany() function return the place of the first message send or receive from a xbt_dynar_t table.
273 \subsection MSG_ext_icomms_fct_Waitany_sender From a sender
274 We can use this function to wait all sent messages.
275 \dontinclude msg/icomms/peer3.c
276 \skipline Sender function
279 \subsection MSG_ext_icomms_fct_Waitany_receiver From a receiver
280 We can also wait for the arrival of all messages.
281 \dontinclude msg/icomms/peer3.c
282 \skipline Receiver function
283 \until end_of_receiver
288 @defgroup MSG_ex_master_slave Basic Master/Slaves
289 @ingroup MSG_examples
291 Simulation of a master-slave application using a realistic platform
292 and an external description of the deployment.
294 \section MSG_ex_ms_TOC Table of contents:
296 - \ref MSG_ext_ms_code
297 - \ref MSG_ext_ms_preliminary
298 - \ref MSG_ext_ms_master
299 - \ref MSG_ext_ms_slave
300 - \ref MSG_ext_ms_forwarder
301 - \ref MSG_ext_ms_core
302 - \ref MSG_ext_ms_main
303 - \ref MSG_ext_ms_helping
304 - \ref MSG_ext_ms_application
305 - \ref MSG_ext_ms_platform
309 \dontinclude msg/masterslave/masterslave_forwarder.c
311 \section MSG_ext_ms_code Code of the application
313 \subsection MSG_ext_ms_preliminary Preliminary declarations
319 \subsection MSG_ext_ms_master Master code
321 This function has to be assigned to a m_process_t that will behave as
322 the master. It should not be called directly but either given as a
323 parameter to #MSG_process_create() or registered as a public function
324 through #MSG_function_register() and then automatically assigned to a
325 process through #MSG_launch_application().
327 C style arguments (argc/argv) are interpreted as:
328 - the number of tasks to distribute
329 - the computation size of each task
330 - the size of the files associated to each task
331 - a list of host that will accept those tasks.
333 Tasks are dumbly sent in a round-robin style.
337 \subsection MSG_ext_ms_slave Slave code
339 This function has to be assigned to a #m_process_t that has to behave
340 as a slave. Just like the master fuction (described in \ref
341 MSG_ext_ms_master), it should not be called directly.
343 This function keeps waiting for tasks and executes them as it receives them.
347 \subsection MSG_ext_ms_forwarder Forwarder code
349 This function has to be assigned to a #m_process_t that has to behave
350 as a forwarder. Just like the master function (described in \ref
351 MSG_ext_ms_master), it should not be called directly.
353 C style arguments (argc/argv) are interpreted as a list of host that
354 will accept those tasks.
356 This function keeps waiting for tasks and dispathes them to its slaves.
358 \until end_of_forwarder
360 \subsection MSG_ext_ms_core Simulation core
362 This function is the core of the simulation and is divided only into 3 parts
363 thanks to MSG_create_environment() and MSG_launch_application().
364 -# Simulation settings : MSG_create_environment() creates a realistic
366 -# Application deployment : create the processes on the right locations with
367 MSG_launch_application()
368 -# The simulation is run with #MSG_main()
371 - <i>platform_file</i>: the name of a file containing an valid surfxml platform description.
372 - <i>application_file</i>: the name of a file containing a valid surfxml application description
374 \until end_of_test_all
376 \subsection MSG_ext_ms_main Main() function
378 This initializes MSG, runs a simulation, and free all data-structures created by MSG.
382 \section MSG_ext_ms_helping Helping files
384 \subsection MSG_ext_ms_application Example of application file
386 \include msg/masterslave/deployment_masterslave.xml
388 \subsection MSG_ext_ms_platform Example of platform file
390 \include msg/small_platform.xml
394 /** \page MSG_ex_master_slave_lua Master/slave Lua application
396 Simulation of a master-slave application using lua bindings
397 - \ref MSG_ext_ms_code_lua
398 - \ref MSG_ext_ms_master_lua
399 - \ref MSG_ext_ms_slave_lua
400 - \ref MSG_ext_ms_core_lua
402 - \ref MSG_ext_ms_helping
403 - \ref MSG_ext_ms_application
404 - \ref MSG_ext_ms_platform
407 \dontinclude lua/masterslave/master_slave.lua
409 \section MSG_ext_ms_code_lua Code of the application
411 \subsection MSG_ext_ms_master_lua Master code
413 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.
415 Lua style arguments (...) in for the master are interpreted as:
416 - the number of tasks to distribute
417 - the computation size of each task
418 - the size of the files associated to each task
419 - a list of host that will accept those tasks.
421 Tasks are dumbly sent in a round-robin style.
426 \subsection MSG_ext_ms_slave_lua Slave code
428 This function has to be assigned to a #m_process_t that has to behave as a slave.
429 This function keeps waiting for tasks and executes them as it receives them.
432 \subsection MSG_ext_ms_core_lua Simulation core
434 in this section the core of the simulation which start by including the simgrid lib for bindings
435 : <i>require "simgrid" </i>
437 -# Simulation settings : <i>simgrid.platform</i> creates a realistic
439 -# Application deployment : create the processes on the right locations with
440 <i>simgrid.application</i>
441 -# The simulation is run with <i>simgrid.run</i>
444 - <i>platform_file</i>: the name of a file containing an valid surfxml platform description.( first command line argument)
445 - <i>application_file</i>: the name of a file containing a valid surfxml application description ( second commande line argument )
447 \until simgrid.clean()
451 /** \page MSG_ex_master_slave_lua_bypass Master/slave Bypass Lua application
453 Simulation of a master-slave application using lua bindings, Bypassing the XML parser
454 - \ref MSG_ext_ms_code_lua
455 - \ref MSG_ext_ms_master_lua
456 - \ref MSG_ext_ms_slave_lua
457 - \ref MSG_ext_ms_core_lua
460 \dontinclude lua/console/master_slave_bypass.lua
462 \section MSG_ext_ms_code_lua Code of the application
464 \subsection MSG_ext_ms_master_lua Master code
466 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.
468 Lua style arguments (...) in for the master are interpreted as:
469 - the number of tasks to distribute
470 - the computation size of each task
471 - the size of the files associated to each task
472 - a list of host that will accept those tasks.
474 Tasks are dumbly sent in a round-robin style.
479 \subsection MSG_ext_ms_slave_lua Slave code
481 This function has to be assigned to a #m_process_t that has to behave as a slave.
482 This function keeps waiting for tasks and executes them as it receives them.
485 \subsection MSG_ext_ms_core_lua Simulation core
487 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.
488 : <i>require "simgrid" </i>
490 -# Hosts : <i>simgrid.Host.new</i> instanciate a new host with an id, and power.
491 -# Links : <i>simgrid.Link.new</i> instanictae a new link that will require an id, bandwith and latency values.
492 -# Route : <i>simgrid.Route.new</i> define a route between two hosts specifying the links to use.
493 -# Simulation settings : <i>simgrid.register_platform();</i> register own platform without using the XML SURF parser.
495 we can also bypass the XML deployment file, and associate functions for each of defined hosts.
496 - <i>simgrid.Host.setFunction</i>: associate a function to a host, specifying arguments if needed.
497 - <i>simgrid.register_application()</i>: saving the deployment settings before running the simualtion.
499 \until simgrid.clean()