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_asynchronous_communications Asynchronous communications
37 Simulation of asynchronous communications between a sender and a receiver using a realistic platform and
38 an external description of the deployment.
40 - \ref MSG_ext_icomms_code
41 - \ref MSG_ext_icomms_preliminary
42 - \ref MSG_ext_icomms_Sender
43 - \ref MSG_ext_icomms_Receiver
44 - \ref MSG_ext_icomms_core
45 - \ref MSG_ext_icomms_Main
46 - \ref MSG_ext_icomms_fct_Waitall
47 - \ref MSG_ext_icomms_fct_Waitany
51 \dontinclude msg/icomms/peer.c
53 \paragraph MSG_ext_icomms_code Code of the application
55 \paragraph MSG_ext_icomms_preliminary Preliminary declarations
57 \until Sender function
59 \paragraph MSG_ext_icomms_Sender Sender function
61 A host can send an an asynchronous message with \c MSG_task_isend(). %As this function is non-blocking,
62 we have to call \c MSG_comm_test() to know if the communication has finished and finally destroy it with a call to \c MSG_comm_destroy().
63 It is also possible to call \c MSG_comm_wait() which, is provides a shortcut.
65 C style arguments (argc/argv) are interpreted as:
66 - the number of tasks to distribute
67 - the computation size of each task
68 - the size of the files associated to each task
69 - a list of host that will accept those tasks.
70 - the time to sleep at the beginning of the function
71 - This time defined the process sleep time
72 if time = 0 use of MSG_comm_wait()
73 if time > 0 use of MSG_comm_test()
76 \until Receiver function
78 \paragraph MSG_ext_icomms_Receiver Receiver function
80 This function executes tasks when it receives them. %As the receiving is asynchronous we have to test the communication to know
81 if it is completed or not with \c MSG_comm_test() or wait for the completion \c MSG_comm_wait().
83 C style arguments (argc/argv) are interpreted as:
84 - the id to use for received the communication.
85 - the time to sleep at the beginning of the function
86 - This time defined the process sleep time
87 if time = 0 use of MSG_comm_wait()
88 if time > 0 use of MSG_comm_test()
92 \paragraph MSG_ext_icomms_core Simulation core
94 This function is the core of the simulation and is divided only into 3 parts
95 thanks to MSG_create_environment() and MSG_launch_application().
96 -# Simulation settings : MSG_create_environment() creates a realistic
98 -# Application deployment : create the processes on the right locations with
99 MSG_launch_application()
100 -# The simulation is run with #MSG_main()
103 - <i>platform_file</i>: the name of a file containing an valid surfxml platform description.
104 - <i>application_file</i>: the name of a file containing a valid surfxml application description
108 \paragraph MSG_ext_icomms_Main Main function
110 This initializes MSG, runs a simulation, and free all data-structures created by MSG.
114 \dontinclude msg/icomms/peer2.c
116 \paragraph MSG_ext_icomms_fct_Waitall Waitall function for sender
118 The use of this function permit to send all messages and wait for the completion of all in one time.
120 \skipline Sender function
123 \paragraph MSG_ext_icomms_fct_Waitany Waitany function
125 The MSG_comm_waitany() function return the place of the first message send or receive from a xbt_dynar_t table.
127 \paragraph MSG_ext_icomms_fct_Waitany_sender From a sender
128 We can use this function to wait all sent messages.
129 \dontinclude msg/icomms/peer3.c
130 \skipline Sender function
133 \paragraph MSG_ext_icomms_fct_Waitany_receiver From a receiver
134 We can also wait for the arrival of all messages.
135 \dontinclude msg/icomms/peer3.c
136 \skipline Receiver function
137 \until end_of_receiver
139 \subsubsection MSG_ex_master_slave Basic Master/Slaves
141 Simulation of a master-slave application using a realistic platform
142 and an external description of the deployment.
144 \paragraph MSG_ex_ms_TOC Table of contents:
146 - \ref MSG_ext_ms_preliminary
147 - \ref MSG_ext_ms_master
148 - \ref MSG_ext_ms_slave
149 - \ref MSG_ext_ms_forwarder
150 - \ref MSG_ext_ms_core
151 - \ref MSG_ext_ms_main
152 - \ref MSG_ext_ms_helping
153 - \ref MSG_ext_ms_application
154 - \ref MSG_ext_ms_platform
158 \dontinclude msg/masterslave/masterslave_forwarder.c
161 \paragraph MSG_ext_ms_preliminary Preliminary declarations
167 \paragraph MSG_ext_ms_master Master code
169 This function has to be assigned to a #msg_process_t that will behave as
170 the master. It should not be called directly but either given as a
171 parameter to #MSG_process_create() or registered as a public function
172 through #MSG_function_register() and then automatically assigned to a
173 process through #MSG_launch_application().
175 C style arguments (argc/argv) are interpreted as:
176 - the number of tasks to distribute
177 - the computation size of each task
178 - the size of the files associated to each task
179 - a list of host that will accept those tasks.
181 Tasks are dumbly sent in a round-robin style.
185 \paragraph MSG_ext_ms_slave Slave code
187 This function has to be assigned to a #msg_process_t that has to behave
188 as a slave. Just like the master function (described in \ref
189 MSG_ext_ms_master), it should not be called directly.
191 This function keeps waiting for tasks and executes them as it receives them.
195 \paragraph MSG_ext_ms_forwarder Forwarder code
197 This function has to be assigned to a #msg_process_t that has to behave
198 as a forwarder. Just like the master function (described in \ref
199 MSG_ext_ms_master), it should not be called directly.
201 C style arguments (argc/argv) are interpreted as a list of hosts that
202 will accept those tasks.
204 This function keeps waiting for tasks and dispatches them to its slaves.
206 \until end_of_forwarder
208 \paragraph MSG_ext_ms_core Simulation core
210 This function is the core of the simulation and is divided only into 3 parts
211 thanks to MSG_create_environment() and MSG_launch_application().
212 -# Simulation settings : MSG_create_environment() creates a realistic
214 -# Application deployment : create the processes on the right locations with
215 MSG_launch_application()
216 -# The simulation is run with #MSG_main()
219 - <i>platform_file</i>: the name of a file containing an valid surfxml platform description.
220 - <i>application_file</i>: the name of a file containing a valid surfxml application description
222 \until end_of_test_all
224 \paragraph MSG_ext_ms_main Main() function
226 This initializes MSG, runs a simulation, and free all data-structures created by MSG.
230 \subsubsection MSG_ext_ms_helping Helping files
232 \paragraph MSG_ext_ms_application Example of a deployment file
234 The following listing can be found in \c examples/msg/masterslave/deployment_masterslave_forwarder.xml:
236 \include msg/masterslave/deployment_masterslave_forwarder.xml
238 \paragraph MSG_ext_ms_platform Example of a platform file
240 \include platforms/small_platform.xml