Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cosmetics: rename host::on to host::turnOn
[simgrid.git] / doc / doxygen / examples.doc
1 /*! \page examples SimGrid Examples
2
3 \note 
4   This page is under work -- sorry for the inconvenience (FIXME).
5
6 - @ref help
7
8 \tableofcontents
9
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
14 sections below. 
15
16 \htmlonly
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. 
18 \endhtmlonly
19
20 \section using_msg Using MSG
21
22 \htmlonly
23 You should also check our online <a href="http://simgrid.gforge.inria.fr/documentation.html"> tutorial section</a> that contains a dedicated tutorial. 
24 \endhtmlonly
25
26 Here are some examples on how to use MSG, the most used API.
27
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.
31
32 \subsection MSG_ex_basics Basic examples and features
33
34 \subsubsection MSG_ex_asynchronous_communications Asynchronous communications
35
36
37 Simulation of asynchronous communications between a sender and a receiver using a realistic platform and
38 an external description of the deployment.
39
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
48
49 <hr>
50
51 \dontinclude msg/icomms/peer.c
52
53 \paragraph MSG_ext_icomms_code Code of the application
54
55 \paragraph MSG_ext_icomms_preliminary Preliminary declarations
56 \skip include
57 \until Sender function
58
59 \paragraph MSG_ext_icomms_Sender Sender function
60
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.
64
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()
74
75
76 \until Receiver function
77
78 \paragraph MSG_ext_icomms_Receiver Receiver function
79
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().
82
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()
89
90 \until Test function
91
92 \paragraph MSG_ext_icomms_core Simulation core
93
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
97         environment
98      -# Application deployment : create the processes on the right locations with
99         MSG_launch_application()
100      -# The simulation is run with #MSG_main()
101
102   Its arguments are:
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
105
106 \until Main function
107
108 \paragraph MSG_ext_icomms_Main Main function
109
110 This initializes MSG, runs a simulation, and free all data-structures created by MSG.
111
112 \until end_of_main
113
114 \dontinclude msg/icomms/peer2.c
115
116 \paragraph MSG_ext_icomms_fct_Waitall Waitall function for sender
117
118 The use of this function permit to send all messages and wait for the completion of all in one time.
119
120 \skipline Sender function
121 \until end_of_sender
122
123 \paragraph MSG_ext_icomms_fct_Waitany Waitany function
124
125 The MSG_comm_waitany() function return the place of the first message send or receive from a xbt_dynar_t table.
126
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
131 \until end_of_sender
132
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
138
139 \subsubsection MSG_ex_master_slave Basic Master/Slaves
140
141 Simulation of a master-slave application using a realistic platform
142 and an external description of the deployment.
143
144 \paragraph MSG_ex_ms_TOC Table of contents:
145
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
155
156 <hr>
157
158 \dontinclude msg/masterslave/masterslave_forwarder.c
159
160
161 \paragraph MSG_ext_ms_preliminary Preliminary declarations
162
163 \skip include
164 \until printf
165 \until }
166
167 \paragraph MSG_ext_ms_master Master code
168
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().
174
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.
180
181 Tasks are dumbly sent in a round-robin style.
182
183 \until end_of_master
184
185 \paragraph MSG_ext_ms_slave Slave code
186
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.
190
191 This function keeps waiting for tasks and executes them as it receives them.
192
193 \until end_of_slave
194
195 \paragraph MSG_ext_ms_forwarder Forwarder code
196
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.
200
201 C style arguments (argc/argv) are interpreted as a list of hosts that
202 will accept those tasks.
203
204 This function keeps waiting for tasks and dispatches them to its slaves.
205
206 \until end_of_forwarder
207
208 \paragraph MSG_ext_ms_core Simulation core
209
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
213       environment
214    -# Application deployment : create the processes on the right locations with
215       MSG_launch_application()
216    -# The simulation is run with #MSG_main()
217
218 Its arguments are:
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
221
222 \until end_of_test_all
223
224 \paragraph MSG_ext_ms_main Main() function
225
226 This initializes MSG, runs a simulation, and free all data-structures created by MSG.
227
228 \until end_of_main
229
230 \subsubsection MSG_ext_ms_helping Helping files
231
232 \paragraph MSG_ext_ms_application Example of a deployment file
233
234 The following listing can be found in \c examples/msg/masterslave/deployment_masterslave_forwarder.xml:
235
236 \include msg/masterslave/deployment_masterslave_forwarder.xml
237
238 \paragraph MSG_ext_ms_platform Example of a platform file
239
240 \include platforms/small_platform.xml
241
242 */
243
244