Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
179d3252d2593bc1edfd3d7a2a05513255e68e5b
[simgrid.git] / examples / s4u / README.doc
1 S4U (Simgrid for you) is the next interface of SimGrid, expected to be released with SimGrid 4.0.
2
3 Even if it is not completely rock stable yet, it may well already fit
4 your needs. You are welcome to try it and report any interface
5 glitches that you see. Be however warned that the interface may change
6 until the final release.  You will have to adapt your code on the way.
7
8 This file follows the Doxygen syntax to be included in the
9 documentation, but it should remain readable directly.
10
11 /** 
12  @defgroup s4u_examples S4U examples
13  @ingroup s4u_api
14  @brief Find the S4U example fitting your needs in the archive.
15
16 SimGrid comes with an extensive set of examples, documented on this
17 page. Most of them only demonstrate one single feature, with some
18 larger examplars listed below. 
19
20 Each of these examples can be found in a subdirectory under
21 examples/s4u in the archive. It contains the source code (also listed
22 from this page), and the so-called tesh file containing how to call
23 the binary obtained by compiling this example and also the expected
24 output. Tesh files are used to turn each of our examples into an
25 integration test. Some examples also contain other files, on need.
26
27 A good way to bootstrap your own project is to copy and combine some
28 of the provided examples to constitute the skeleton of what you plan
29 to simulate.
30
31   - @ref s4u_ex_actors
32     - @ref s4u_ex_actors_start
33     - @ref s4u_ex_actors_synchro
34     - @ref s4u_ex_actors_replay
35   - @ref s4u_ex_activities
36     - @ref s4u_ex_activity_comm
37     - @ref s4u_ex_activity_exec
38     - @ref s4u_ex_activity_io
39     - @ref s4u_ex_activity_synchro
40   - @ref s4u_ex_platf
41   - @ref s4u_ex_energy
42   - @ref s4u_ex_tracing
43   - @ref s4u_ex_app
44     - @ref s4u_ex_app_data
45     - @ref s4u_ex_app_dht
46
47 TODO: document here the examples about plugins
48     
49 @section s4u_ex_actors Actors: the active entities
50
51 @subsection s4u_ex_actors_start Starting and stoping actors
52
53   - <b>Creating actors</b>. 
54     @ref examples/s4u/actor-create/s4u-actor-create.cpp @n
55     Most actors are started from the deployment XML file, but there is other methods.
56     This example show them all.
57
58   - <b>Kill actors</b>.
59     @ref examples/s4u/actor-kill/s4u-actor-kill.cpp @n
60     Actors can forcefully stop other actors with the @ref
61     simgrid::s4u::Actor::kill(void) or the @ref
62     simgrid::s4u::Actor::kill(aid_t) methods.
63
64   - <b>Controling the actor life cycle from the XML</b>.
65     @ref examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp 
66     @ref examples/s4u/actor-lifetime/s4u-actor-lifetime_d.xml 
67     @n
68     You can specify a start time and a kill time in the deployment file.
69
70   - <b>Daemonize actors</b>
71     @ref examples/s4u/actor-daemon/s4u-actor-daemon.cpp @n
72     Some actors may be intended to simulate daemons that run in background. This example show how to transform a regular
73     actor into a daemon that will be automatically killed once the simulation is over. 
74     
75 @subsection s4u_ex_actors_synchro Inter-actors interactions
76
77   - <b>Suspend and Resume actors</b>.
78     @ref examples/s4u/actor-suspend/s4u-actor-suspend.cpp @n
79     Actors can be suspended and resumed during their executions
80     thanks to the @ref simgrid::s4u::Actor::suspend and @ref simgrid::s4u::Actor::resume methods.
81
82   - <b>Migrating Actors</b>.
83     @ref examples/s4u/actor-migration/s4u-actor-migration.cpp @n
84     Actors can move or be moved from a host to another with the @ref
85     simgrid::s4u::this_actor::migrate() method.
86
87   - <b>Waiting for the termination of an actor</b> (joining on it)
88     @ref examples/s4u/actor-join/s4u-actor-join.cpp @n
89     The simgrid::s4u::Actor::join() method allows to block the current
90     actor until the end of the receiving actor.
91
92   - <b>Yielding to other actor</b>.
93     @ref examples/s4u/actor-yield/s4u-actor-yield.cpp@n
94     The simgrid::s4u::this_actor::yield() function interrupts the
95     execution of the current actor, leaving a chance to the other actors
96     that are ready to run at this timestamp.
97
98 @subsection s4u_ex_actors_replay Traces Replay as a Workload
99
100 This section details how to run trace-driven simulations. It is very
101 handy when you want to test an algorithm or protocol that only react
102 to external events. For example, many P2P protocols react to user
103 requests, but do nothing if there is no such event.
104
105 In such situations, you should write your protocol in C++, and separate
106 the workload that you want to play onto your protocol in a separate
107 text file. Declare a function handling each type of the events in your
108 trace, register them using @ref xbt_replay_action_register in your
109 main, and then run the simulation.
110
111 Then, you can either have one trace file containing all your events,
112 or a file per simulated process: the former may be easier to work
113 with, but the second is more efficient on very large traces. Check
114 also the tesh files in the example directories for details.
115
116   - <b>Communication replay</b>.
117     @ref examples/s4u/replay-comm/s4u-replay-comm.cpp @n
118     Presents a set of event handlers reproducing classical communication
119     primitives (asynchronous send/receive at the moment).
120
121   - <b>I/O replay</b>.
122     @ref examples/s4u/replay-storage/s4u-replay-storage.cpp @n
123     Presents a set of event handlers reproducing classical I/O
124     primitives (open, read, close).
125
126 @section s4u_ex_activities Activities: the things that Actors do
127
128 @subsection s4u_ex_activity_comm Communications on the network
129
130  - <b>Basic asynchronous communications</b>. 
131    @ref examples/s4u/async-wait/s4u-async-wait.cpp @n
132    Illustrates how to have non-blocking communications, that are
133    communications running in the background leaving the process free
134    to do something else during their completion. The main functions
135    involved are @ref simgrid::s4u::Mailbox::put_async and 
136    @ref simgrid::s4u::Comm::wait().
137
138  - <b>Waiting for all communications in a set</b>.
139    @ref examples/s4u/async-waitall/s4u-async-waitall.cpp@n
140    The @ref simgrid::s4u::Comm::wait_all() function is useful when you want to block
141    until all activities in a given set have completed.
142
143  - <b>Waiting for the first completed communication in a set</b>.
144    @ref examples/s4u/async-waitany/s4u-async-waitany.cpp@n
145    The @ref simgrid::s4u::Comm::wait_any() function is useful when you want to block
146    until one activity of the set completes, no matter which terminates
147    first.    
148
149 @subsection s4u_ex_activity_exec Executions on the CPU
150
151   - <b>Basic execution</b>.
152     @ref examples/s4u/exec-basic/s4u-exec-basic.cpp @n
153     The computations done in your program are not reported to the
154     simulated world, unless you explicitely request the simulator to pause
155     the actor until a given amount of flops gets computed on its simulated
156     host. Some executions can be given an higher priority so that they
157     get more resources.
158
159   - <b>Asynchronous execution</b>.
160     @ref examples/s4u/exec-async/s4u-exec-async.cpp @n
161     You can start asynchronous executions, just like you would fire
162     background threads.
163     
164   - <b>Monitoring asynchronous executions</b>.
165     @ref examples/s4u/exec-monitor/s4u-exec-monitor.cpp @n
166     This example shows how to start an asynchronous execution, and
167     monitor its status.
168     
169   - <b>Remote execution</b>.
170     @ref examples/s4u/exec-remote/s4u-exec-remote.cpp @n
171     Before its start, you can change the host on which a given execution will occur.
172
173   - <b>Using Pstates on a host</b>
174     @ref examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp and 
175     @ref examples/platforms/energy_platform.xml @n
176     Show how define a set of pstatesfor a host in the XML, and how the current
177     pstate can be accessed/changed with @ref simgrid::s4u::Host::get_pstate_speed and @ref simgrid::s4u::Host::set_pstate.
178
179   - <b>Parallel tasks</b>
180     @ref examples/s4u/exec-ptask/s4u-exec-ptask.cpp@n
181     These objects are convenient abstractions of parallel
182     computational kernels that span over several machines. 
183
184 @subsection s4u_ex_activity_io I/O on disks and files
185
186 SimGrid provides two levels of abstraction to interact with the
187 simulated storages. At the simplest level, you simply create read and
188 write actions on the storage resources.
189
190   - <b>Access to raw storage devices</b>.
191     @ref examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp @n
192     This example illustrates how to simply read and write data on a
193     simulated storage resource.
194
195 The FileSystem plugin provides a more detailed view, with the
196 classical operations over files: open, move, unlink, and of course
197 read and write. The file and disk sizes are also dealt with and can
198 result in short reads and short write, as in reality.
199
200   - <b>File Management</b>. @ref examples/s4u/io-file-system/s4u-io-file-system.cpp @n
201     This example illustrates the use of operations on files
202     (read, write, seek, tell, unlink, ...).
203
204   - <b>Remote I/O</b>. 
205     @ref examples/s4u/io-file-remote/s4u-io-file-remote.cpp @n
206     I/O operations on files can also be done in a remote fashion, 
207     i.e. when the accessed disk is not mounted on the caller's host.
208
209 @subsection s4u_ex_activity_synchro Classical synchronization objects
210
211  - <b>Mutex: </b> @ref examples/s4u/mutex/s4u-mutex.cpp @n
212    Shows how to use simgrid::s4u::Mutex synchronization objects.
213
214 @section s4u_ex_platf Interacting with the platform
215
216  - <b>Retrieving the list of hosts matching a given criteria</b>.
217    @ref examples/s4u/engine-filtering/s4u-engine-filtering.cpp@n
218    Filtering the actors that match a given criteria is rather simple.
219
220  - <b>User-defined properties</b>.
221    @ref examples/s4u/platform-properties/s4u-platform-properties.cpp and 
222    @ref examples/s4u/platform-properties/s4u-platform-properties_d.xml and
223    @ref examples/platforms/prop.xml @n
224    You can attach arbitrary information to most platform elements from
225    the XML file, and then interact with these values from your
226    program. Note that the changes are not written permanently on disk,
227    in the XML file nor anywhere else. They only last until the end of
228    your simulation. 
229    - simgrid::s4u::Actor::get_property() and simgrid::s4u::Actor::set_property()
230    - simgrid::s4u::Host::get_property() and simgrid::s4u::Host::set_property()
231    - simgrid::s4u::Link::get_property() and simgrid::s4u::Link::set_property()
232    - simgrid::s4u::NetZone::get_property() and simgrid::s4u::NetZone::set_property()
233
234 @section s4u_ex_energy Simulating the energy consumption
235
236   - <b>Describing the energy profiles in the platform</b>
237     @ref examples/platforms/energy_platform.xml @n
238     This platform file contains the energy profile of each links and
239     hosts, which is necessary to get energy consumption predictions.
240     As usual, you should not trust our example, and you should strive
241     to double-check that your instanciation matches your target platform.
242
243   - <b>Consumption due to the CPU</b> 
244     @ref examples/s4u/energy-exec/s4u-energy-exec.cpp @n
245     This example shows how to retrieve the amount of energy consumed
246     by the CPU during computations, and the impact of the pstate.
247
248   - <b>Consumption due to the network</b>
249     @ref examples/s4u/energy-link/s4u-energy-link.cpp
250     This example shows how to retrieve and display the energy consumed
251     by the network during communications.
252
253   - <b>Modeling the shutdown and boot of hosts</b>
254     @ref examples/s4u/energy-boot/platform_boot.xml
255     @ref examples/s4u/energy-boot/s4u-energy-boot.cpp@n
256     Simple example of model of model for the energy consumption during
257     the host boot and shutdown periods.
258
259 @section s4u_ex_tracing Tracing and visualization features
260
261 Tracing can be activated by various configuration options which
262 are illustrated in these example. See also the 
263 @ref tracing_tracing_options "full list of options related to tracing".
264
265 It is interesting to run the process-create example with the following
266 options to see the task executions:
267
268   - <b>Platform tracing</b>.
269     @ref examples/s4u/trace-platform/s4u-trace-platform.cpp @n
270     This program is a toy example just loading the platform, so that
271     you can play with the platform visualization. Recommanded options:
272     @verbatim --cfg=tracing:yes --cfg=tracing/categorized:yes
273     @endverbatim
274
275 @section s4u_ex_app Larger SimGrid examplars
276
277 This section contains application examples that are somewhat larger
278 than the previous examples.
279
280   - <b>Ping Pong</b>: @ref examples/s4u/app-pingpong/s4u-app-pingpong.cpp@n
281     This simple example just sends one message back and forth.
282     The tesh file laying in the directory show how to start the simulator binary, highlighting how to pass options to 
283     the simulators (as detailed in Section @ref options). 
284
285   - <b>Token ring:</b> @ref examples/s4u/app-token-ring/s4u-app-token-ring.cpp @n
286     Shows how to implement a classical communication pattern, where a token is exchanged along a ring to reach every
287     participant.
288
289   - <b>Master Workers:</b> @ref examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp 
290                            @ref examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp @n
291     Another good old example, where one Master process has a bunch of task to dispatch to a set of several Worker 
292     processes. This example comes in two equivalent variants, one
293     where the actors are specified as simple functions (which is easier to
294     understand for newcomers) and one where the actors are specified
295     as classes (which is more powerful for the users wanting to build
296     their own projects upon the example).
297     
298 @subsection s4u_ex_app_data Data diffusion
299
300   - <b>Bit Torrent</b> 
301     @ref examples/s4u/app-bittorrent/s4u-bittorrent.cpp@n
302     Classical protocol for Peer-to-Peer data diffusion.
303     
304   - <b>Chained send</b> 
305     @ref examples/s4u/app-chainsend/s4u-app-chainsend.cpp@n
306     Data broadcast over a ring of processes.
307
308 @subsection s4u_ex_app_dht Distributed Hash Tables (DHT)
309
310   - <b>Chord Protocol</b> 
311     @ref examples/s4u/dht-chord/s4u-dht-chord.cpp@n
312     One of the most famous DHT protocol.
313
314 */
315
316 /**
317 @example examples/s4u/actor-create/s4u-actor-create.cpp
318 @example examples/s4u/actor-create/s4u-actor-create_d.xml
319 @example examples/s4u/actor-daemon/s4u-actor-daemon.cpp
320 @example examples/s4u/actor-join/s4u-actor-join.cpp
321 @example examples/s4u/actor-kill/s4u-actor-kill.cpp
322 @example examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp 
323 @example examples/s4u/actor-lifetime/s4u-actor-lifetime_d.xml 
324 @example examples/s4u/actor-migration/s4u-actor-migration.cpp
325 @example examples/s4u/actor-suspend/s4u-actor-suspend.cpp
326 @example examples/s4u/actor-yield/s4u-actor-yield.cpp
327 @example examples/s4u/async-wait/s4u-async-wait.cpp
328 @example examples/s4u/async-waitall/s4u-async-waitall.cpp
329 @example examples/s4u/async-waitany/s4u-async-waitany.cpp
330 @example examples/s4u/app-bittorrent/s4u-bittorrent.cpp
331 @example examples/s4u/app-chainsend/s4u-app-chainsend.cpp
332 @example examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp
333 @example examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp
334 @example examples/s4u/app-pingpong/s4u-app-pingpong.cpp
335 @example examples/s4u/app-token-ring/s4u-app-token-ring.cpp
336 @example examples/s4u/dht-chord/s4u-dht-chord.cpp
337 @example examples/s4u/engine-filtering/s4u-engine-filtering.cpp
338 @example examples/s4u/energy-boot/platform_boot.xml
339 @example examples/s4u/energy-boot/s4u-energy-boot.cpp
340 @example examples/s4u/energy-exec/s4u-energy-exec.cpp
341 @example examples/s4u/energy-link/s4u-energy-link.cpp
342 @example examples/s4u/exec-basic/s4u-exec-basic.cpp
343 @example examples/s4u/exec-async/s4u-exec-async.cpp
344 @example examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp
345 @example examples/s4u/exec-monitor/s4u-exec-monitor.cpp
346 @example examples/s4u/exec-ptask/s4u-exec-ptask.cpp
347 @example examples/s4u/exec-remote/s4u-exec-remote.cpp 
348 @example examples/s4u/io-file-system/s4u-io-file-system.cpp
349 @example examples/s4u/io-file-remote/s4u-io-file-remote.cpp
350 @example examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp
351 @example examples/s4u/mutex/s4u-mutex.cpp
352 @example examples/s4u/platform-properties/s4u-platform-properties.cpp
353 @example examples/s4u/platform-properties/s4u-platform-properties_d.xml
354 @example examples/s4u/replay-comm/s4u-replay-comm.cpp
355 @example examples/s4u/replay-storage/s4u-replay-storage.cpp
356 @example examples/s4u/trace-platform/s4u-trace-platform.cpp
357 @example examples/platforms/energy_platform.xml
358 @example examples/platforms/prop.xml
359
360 */