Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
refresh the 'Setting up your own code' part of the documentation
[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_worker Basic Master/Workers
140
141 Simulation of a master-worker application using a realistic platform and an external description of the deployment.
142
143 \paragraph MSG_ex_mw_TOC Table of contents:
144
145    - \ref MSG_ext_mw_preliminary
146    - \ref MSG_ext_ms_master
147    - \ref MSG_ext_ms_slave
148    - \ref MSG_ext_ms_forwarder
149    - \ref MSG_ext_ms_core
150    - \ref MSG_ext_ms_main
151    - \ref MSG_ext_ms_helping
152    - \ref MSG_ext_ms_application
153    - \ref MSG_ext_ms_platform
154
155 <hr>
156
157 \dontinclude msg/app-masterworker/app-masterworker.c
158
159 \paragraph MSG_ext_mw_preliminary Preliminary declarations
160
161 \skip include
162 \until printf
163 \until }
164
165 \paragraph MSG_ext_ms_master Master code
166
167 This function has to be assigned to a #msg_process_t that will behave as
168 the master. It should not be called directly but either given as a
169 parameter to #MSG_process_create() or registered as a public function
170 through #MSG_function_register() and then automatically assigned to a
171 process through #MSG_launch_application().
172
173 C style arguments (argc/argv) are interpreted as:
174    - the number of tasks to distribute
175    - the computation size of each task
176    - the size of the files associated to each task
177    - a list of host that will accept those tasks.
178
179 Tasks are dumbly sent in a round-robin style.
180
181 \until end_of_master
182
183 \paragraph MSG_ext_ms_slave Slave code
184
185 This function has to be assigned to a #msg_process_t that has to behave
186 as a slave. Just like the master function (described in \ref
187 MSG_ext_ms_master), it should not be called directly.
188
189 This function keeps waiting for tasks and executes them as it receives them.
190
191 \until end_of_slave
192
193 \paragraph MSG_ext_ms_forwarder Forwarder code
194
195 This function has to be assigned to a #msg_process_t that has to behave
196 as a forwarder. Just like the master function (described in \ref
197 MSG_ext_ms_master), it should not be called directly.
198
199 C style arguments (argc/argv) are interpreted as a list of hosts that
200 will accept those tasks.
201
202 This function keeps waiting for tasks and dispatches them to its slaves.
203
204 \until end_of_forwarder
205
206 \paragraph MSG_ext_ms_core Simulation core
207
208 This function is the core of the simulation and is divided only into 3 parts
209 thanks to MSG_create_environment() and MSG_launch_application().
210    -# Simulation settings : MSG_create_environment() creates a realistic
211       environment
212    -# Application deployment : create the processes on the right locations with
213       MSG_launch_application()
214    -# The simulation is run with #MSG_main()
215
216 Its arguments are:
217         - <i>platform_file</i>: the name of a file containing an valid surfxml platform description.
218         - <i>application_file</i>: the name of a file containing a valid surfxml application description
219
220 \until end_of_test_all
221
222 \paragraph MSG_ext_ms_main Main() function
223
224 This initializes MSG, runs a simulation, and free all data-structures created by MSG.
225
226 \until end_of_main
227
228 \subsubsection MSG_ext_ms_helping Helping files
229
230 \paragraph MSG_ext_ms_application Example of a deployment file
231
232 The following listing can be found in \c examples/msg/masterslave/deployment_masterslave_forwarder.xml:
233
234 \include msg/masterslave/deployment_masterslave_forwarder.xml
235
236 \paragraph MSG_ext_ms_platform Example of a platform file
237
238 \include platforms/small_platform.xml
239
240 */
241
242