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_worker Basic Master/Workers
141 Simulation of a master-worker application using a realistic platform and an external description of the deployment.
143 \paragraph MSG_ex_mw_TOC Table of contents:
145 - \ref MSG_ext_mw_preliminary
146 - \ref MSG_ext_mw_master
147 - \ref MSG_ext_mw_worker
148 - \ref MSG_ext_mw_core
149 - \ref MSG_ext_mw_platform
150 - \ref MSG_ext_mw_application
154 \dontinclude msg/app-masterworker/app-masterworker.c
156 \paragraph MSG_ext_mw_preliminary Preliminary declarations
160 \skipline Master expects
162 \paragraph MSG_ext_mw_master Master code
164 This function has to be assigned to a #msg_process_t that will behave as the master. It should not be called directly
165 but either given as a parameter to #MSG_process_create() or registered as a public function through
166 #MSG_function_register() and then automatically assigned to a process through #MSG_launch_application().
168 C style arguments (argc/argv) are interpreted as:
169 - the number of tasks to distribute
170 - the computational size of each task
171 - the communication size of each task
172 - the number of workers managed by the master.
174 Tasks are evenly sent in a round-robin style.
178 \skipline Worker expects
180 \paragraph MSG_ext_mw_worker Worker code
182 This function has to be assigned to a #msg_process_t that has to behave as a worker. Just like the master function
183 (described in \ref MSG_ext_mw_master), it should not be called directly.
185 C style arguments (argc/argv) are interpreted as:
186 - a unique id used to build the mailbox name of the worker
188 This function keeps waiting for tasks and executes them as it receives them. When a special task named 'finalize' is
189 received from the master, the process ends its execution.
194 \paragraph MSG_ext_mw_core Main function
196 This function is the core of the simulation and is divided only into 3 parts:
197 -# Simulation settings : #MSG_create_environment() creates a realistic
199 -# Application deployment : create the processes on the right locations with
200 #MSG_launch_application()
201 -# The simulation is run with #MSG_main()
204 - <i>platform_file</i>: the name of a file containing an valid platform description.
205 - <i>deployment_file</i>: the name of a file containing a valid application description
210 \subsubsection MSG_ext_mw_platform Example of a platform file
212 The following platform description can be found in \c examples/msg/platforms/small_platform.xml
213 \include platforms/small_platform.xml
215 \subsubsection MSG_ext_mw_application Example of a deployment file
217 The following application description can be found in \c examples/msg/app-masterworker/app-masterworker_d.xml:
219 \include msg/app-masterworker/app-masterworker_d.xml