Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix and correct async detailed example
[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_master_worker Basic Master/Workers
35
36 Simulation of a master-worker application using a realistic platform and an external description of the deployment.
37
38 \paragraph MSG_ex_mw_TOC Table of contents:
39
40    - \ref MSG_ext_mw_preliminary
41    - \ref MSG_ext_mw_master
42    - \ref MSG_ext_mw_worker
43    - \ref MSG_ext_mw_core
44      - \ref MSG_ext_mw_platform
45      - \ref MSG_ext_mw_application
46
47 <hr>
48
49 \dontinclude msg/app-masterworker/app-masterworker.c
50
51 \paragraph MSG_ext_mw_preliminary Preliminary declarations
52
53 \skip include
54 \until example");
55 \skipline Master expects
56
57 \paragraph MSG_ext_mw_master Master code
58
59 This function has to be assigned to a #msg_process_t that will behave as the master. It should not be called directly 
60 but either given as a parameter to #MSG_process_create() or registered as a public function through 
61 #MSG_function_register() and then automatically assigned to a process through #MSG_launch_application().
62
63 C style arguments (argc/argv) are interpreted as:
64    - the number of tasks to distribute
65    - the computational size of each task
66    - the communication size of each task
67    - the number of workers managed by the master.
68
69 Tasks are evenly sent in a round-robin style.
70
71 \until return 0;
72 \until }
73 \skipline Worker expects
74
75 \paragraph MSG_ext_mw_worker Worker code
76
77 This function has to be assigned to a #msg_process_t that has to behave as a worker. Just like the master function 
78 (described in \ref MSG_ext_mw_master), it should not be called directly.
79
80 C style arguments (argc/argv) are interpreted as:
81    - a unique id used to build the mailbox name of the worker
82
83 This function keeps waiting for tasks and executes them as it receives them. When a special task named 'finalize' is
84 received from the master, the process ends its execution.
85
86 \until return 0;
87 \until }
88
89 \paragraph MSG_ext_mw_core Main function
90
91 This function is the core of the simulation and is divided only into 3 parts:
92    -# Simulation settings : #MSG_create_environment() creates a realistic
93       environment
94    -# Application deployment : create the processes on the right locations with
95       #MSG_launch_application()
96    -# The simulation is run with #MSG_main()
97
98 Its arguments are:
99    - <i>platform_file</i>: the name of a file containing an valid platform description.
100    - <i>deployment_file</i>: the name of a file containing a valid application description
101 \line main
102 \until OK;
103 \until }
104
105 \paragraph MSG_ext_mw_platform Example of a platform file
106
107 The following platform description can be found in \c examples/msg/platforms/small_platform.xml
108 \include platforms/small_platform.xml
109
110 \paragraph MSG_ext_mw_application Example of a deployment file
111
112 The following application description can be found in \c examples/msg/app-masterworker/app-masterworker_d.xml:
113
114 \include msg/app-masterworker/app-masterworker_d.xml
115
116 \subsubsection MSG_ex_asynchronous_communications Asynchronous communications
117
118 Simulation of asynchronous communications between a sender and a receiver using a realistic platform and
119 an external description of the deployment.
120
121  - \ref MSG_ext_async_code
122    - \ref MSG_ext_async_preliminary
123    - \ref MSG_ext_async_Sender
124    - \ref MSG_ext_async_Receiver
125    - \ref MSG_ext_async_Main
126  - \ref MSG_ext_async_fct_Waitall
127  - \ref MSG_ext_async_fct_Waitany
128
129 <hr>
130
131 \dontinclude msg/async-wait/async-wait.c
132
133 \paragraph MSG_ext_async_code Code of the application
134
135 \paragraph MSG_ext_async_preliminary Preliminary declarations
136 \skip include
137 \until Sender
138
139 \paragraph MSG_ext_async_Sender Sender function
140
141 A host can send an asynchronous message with \c MSG_task_isend(). %As this function is non-blocking, we have to call 
142 \c MSG_comm_test() to know if the communication is complete and evenetually destroy it with a call to 
143 \c MSG_comm_destroy(). It is also possible to call \c MSG_comm_wait() which provides a shortcut.
144
145   C style arguments (argc/argv) are interpreted as:
146    - the number of tasks to distribute
147    - the computation size of each task
148    - the size of the files associated to each task
149    - the number of receivers that will accept those tasks
150    - the time to sleep at the beginning of the function. This time defines the process sleep time:
151            - if time = 0, use MSG_comm_wait()
152            - if time > 0, use MSG_comm_test()
153
154 \until Receiver
155
156 \paragraph MSG_ext_async_Receiver Receiver function
157
158 This function executes tasks when it receives them. %As the receiving is asynchronous, we have to test the completion of
159 the communication with \c MSG_comm_test() or wait for it with \c MSG_comm_wait().
160
161   C style arguments (argc/argv) are interpreted as:
162    - the id to use for received the communication.
163    - the time to sleep at the beginning of the function
164    - This time defined the process sleep time
165            - if time = 0 use of MSG_comm_wait()
166            - if time > 0 use of MSG_comm_test()
167
168 \until return
169 \until }
170
171 \paragraph MSG_ext_async_Main Main function
172
173 This function is the core of the simulation and is divided only into 3 parts:
174      -# Simulation settings : MSG_create_environment() loads a platform description
175      -# Application deployment : create the processes on the right locations with MSG_launch_application()
176      -# The simulation is run with #MSG_main()
177
178   Its arguments are:
179     - <i>platform_file</i>: the name of a file containing an valid platform description.
180     - <i>application_file</i>: the name of a file containing a valid application deployment.
181
182 \until return
183 \until }
184
185 \dontinclude msg/async-waitall/async-waitall.c
186
187 \paragraph MSG_ext_async_fct_Waitall Waitall function
188
189 The use of MSG_comm_waitall() allows a process to send all the tasks and then wait for the completion of all in one call.
190
191 \skipline static
192 \until return
193 \until }
194
195 \paragraph MSG_ext_async_fct_Waitany Waitany function
196
197 The MSG_comm_waitany() function returns the place of the first message send or receive from a xbt_dynar.
198
199 \skipline static
200 \until return
201 \until }
202
203 */
204
205