1 /*! \page examples SimGrid Examples
4 This page is under work -- sorry for the inconvenience (FIXME).
10 SimGrid comes with many examples provided in the examples/ directory.
11 Those examples are described in section \ref MSG_examples. Those
12 examples are commented and should be easy to understand. for a first
13 step into SimGrid we also provide some more detailed examples in the
17 You should also check our online <a href="http://simgrid.gforge.inria.fr/documentation.html"> tutorial section</a> that contains a generic tutorial about using SimGrid.
20 \section using_msg Using MSG
23 You should also check our online <a href="http://simgrid.gforge.inria.fr/documentation.html"> tutorial section</a> that contains a dedicated tutorial.
26 Here are some examples on how to use MSG, the most used API.
28 MSG comes with an extensive set of examples. It is sometimes difficult
29 to find the one you need. This list aims at helping you finding the
30 example from which you can learn what you want to.
32 \subsection MSG_ex_basics Basic examples and features
34 \subsubsection MSG_ex_master_worker Basic Master/Workers
36 Simulation of a master-worker application using a realistic platform and an external description of the deployment.
38 \paragraph MSG_ex_mw_TOC Table of contents:
40 - \ref MSG_ext_mw_preliminary
41 - \ref MSG_ext_mw_master
42 - \ref MSG_ext_mw_worker
43 - \ref MSG_ext_mw_core
44 - \ref MSG_ext_mw_platform
45 - \ref MSG_ext_mw_application
49 \dontinclude msg/app-masterworker/app-masterworker.c
51 \paragraph MSG_ext_mw_preliminary Preliminary declarations
55 \skipline Master expects
57 \paragraph MSG_ext_mw_master Master code
59 This function has to be assigned to a #msg_process_t that will behave as the master. It should not be called directly
60 but either given as a parameter to #MSG_process_create() or registered as a public function through
61 #MSG_function_register() and then automatically assigned to a process through #MSG_launch_application().
63 C style arguments (argc/argv) are interpreted as:
64 - the number of tasks to distribute
65 - the computational size of each task
66 - the communication size of each task
67 - the number of workers managed by the master.
69 Tasks are evenly sent in a round-robin style.
73 \skipline Worker expects
75 \paragraph MSG_ext_mw_worker Worker code
77 This function has to be assigned to a #msg_process_t that has to behave as a worker. Just like the master function
78 (described in \ref MSG_ext_mw_master), it should not be called directly.
80 C style arguments (argc/argv) are interpreted as:
81 - a unique id used to build the mailbox name of the worker
83 This function keeps waiting for tasks and executes them as it receives them. When a special task named 'finalize' is
84 received from the master, the process ends its execution.
89 \paragraph MSG_ext_mw_core Main function
91 This function is the core of the simulation and is divided only into 3 parts:
92 -# Simulation settings : #MSG_create_environment() creates a realistic
94 -# Application deployment : create the processes on the right locations with
95 #MSG_launch_application()
96 -# The simulation is run with #MSG_main()
99 - <i>platform_file</i>: the name of a file containing an valid platform description.
100 - <i>deployment_file</i>: the name of a file containing a valid application description
105 \paragraph MSG_ext_mw_platform Example of a platform file
107 The following platform description can be found in \c examples/msg/platforms/small_platform.xml
108 \include platforms/small_platform.xml
110 \paragraph MSG_ext_mw_application Example of a deployment file
112 The following application description can be found in \c examples/msg/app-masterworker/app-masterworker_d.xml:
114 \include msg/app-masterworker/app-masterworker_d.xml
116 \subsubsection MSG_ex_asynchronous_communications Asynchronous communications
118 Simulation of asynchronous communications between a sender and a receiver using a realistic platform and
119 an external description of the deployment.
121 - \ref MSG_ext_async_code
122 - \ref MSG_ext_async_preliminary
123 - \ref MSG_ext_async_Sender
124 - \ref MSG_ext_async_Receiver
125 - \ref MSG_ext_async_Main
126 - \ref MSG_ext_async_fct_Waitall
127 - \ref MSG_ext_async_fct_Waitany
131 \dontinclude msg/async-wait/async-wait.c
133 \paragraph MSG_ext_async_code Code of the application
135 \paragraph MSG_ext_async_preliminary Preliminary declarations
139 \paragraph MSG_ext_async_Sender Sender function
141 A host can send an asynchronous message with \c MSG_task_isend(). %As this function is non-blocking, we have to call
142 \c MSG_comm_test() to know if the communication is complete and evenetually destroy it with a call to
143 \c MSG_comm_destroy(). It is also possible to call \c MSG_comm_wait() which provides a shortcut.
145 C style arguments (argc/argv) are interpreted as:
146 - the number of tasks to distribute
147 - the computation size of each task
148 - the size of the files associated to each task
149 - the number of receivers that will accept those tasks
150 - the time to sleep at the beginning of the function. This time defines the process sleep time:
151 - if time = 0, use MSG_comm_wait()
152 - if time > 0, use MSG_comm_test()
156 \paragraph MSG_ext_async_Receiver Receiver function
158 This function executes tasks when it receives them. %As the receiving is asynchronous, we have to test the completion of
159 the communication with \c MSG_comm_test() or wait for it with \c MSG_comm_wait().
161 C style arguments (argc/argv) are interpreted as:
162 - the id to use for received the communication.
163 - the time to sleep at the beginning of the function
164 - This time defined the process sleep time
165 - if time = 0 use of MSG_comm_wait()
166 - if time > 0 use of MSG_comm_test()
171 \paragraph MSG_ext_async_Main Main function
173 This function is the core of the simulation and is divided only into 3 parts:
174 -# Simulation settings : MSG_create_environment() loads a platform description
175 -# Application deployment : create the processes on the right locations with MSG_launch_application()
176 -# The simulation is run with #MSG_main()
179 - <i>platform_file</i>: the name of a file containing an valid platform description.
180 - <i>application_file</i>: the name of a file containing a valid application deployment.
185 \dontinclude msg/async-waitall/async-waitall.c
187 \paragraph MSG_ext_async_fct_Waitall Waitall function
189 The use of MSG_comm_waitall() allows a process to send all the tasks and then wait for the completion of all in one call.
195 \paragraph MSG_ext_async_fct_Waitany Waitany function
197 The MSG_comm_waitany() function returns the place of the first message send or receive from a xbt_dynar.