Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[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_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
151
152 <hr>
153
154 \dontinclude msg/app-masterworker/app-masterworker.c
155
156 \paragraph MSG_ext_mw_preliminary Preliminary declarations
157
158 \skip include
159 \until example");
160 \skipline Master expects
161
162 \paragraph MSG_ext_mw_master Master code
163
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().
167
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.
173
174 Tasks are evenly sent in a round-robin style.
175
176 \until return 0;
177 \until }
178 \skipline Worker expects
179
180 \paragraph MSG_ext_mw_worker Worker code
181
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.
184
185 C style arguments (argc/argv) are interpreted as:
186    - a unique id used to build the mailbox name of the worker
187
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.
190
191 \until return 0;
192 \until }
193
194 \paragraph MSG_ext_mw_core Main function
195
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
198       environment
199    -# Application deployment : create the processes on the right locations with
200       #MSG_launch_application()
201    -# The simulation is run with #MSG_main()
202
203 Its arguments are:
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
206 \line main
207 \until OK;
208 \until }
209
210 \subsubsection MSG_ext_mw_platform Example of a platform file
211
212 The following platform description can be found in \c examples/msg/platforms/small_platform.xml
213 \include platforms/small_platform.xml
214
215 \subsubsection MSG_ext_mw_application Example of a deployment file
216
217 The following application description can be found in \c examples/msg/app-masterworker/app-masterworker_d.xml:
218
219 \include msg/app-masterworker/app-masterworker_d.xml
220
221 */
222
223