1 S4U (Simgrid for you) is the next interface of SimGrid, expected to be released with SimGrid 4.0.
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.
8 This file follows the Doxygen syntax to be included in the
9 documentation, but it should remain readable directly.
12 @defgroup s4u_examples S4U examples
14 @brief Find the S4U example fitting your needs in the archive.
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.
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.
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
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
43 - @ref s4u_ex_examplars
45 TODO: document here the examples about plugins
47 @section s4u_ex_actors Actors: the active entities
49 @subsection s4u_ex_actors_start Starting and stoping actors
51 - <b>Creating actors</b>.
52 @ref examples/s4u/actor-create/s4u-actor-create.cpp \n
53 Most actors are started from the deployment XML file, but there is other methods.
54 This example show them all.
57 @ref examples/s4u/actor-kill/s4u-actor-kill.cpp \n
58 Actors can forcefully stop other actors with the @ref
59 simgrid::s4u::Actor::kill() method.
61 - <b>Controling the actor life cycle from the XML</b>.
62 @ref examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp
63 @ref examples/s4u/actor-lifetime/s4u-actor-lifetime_d.xml
65 You can specify a start time and a kill time in the deployment file.
67 - <b>Daemonize actors</b>
68 @ref examples/s4u/actor-daemon/s4u-actor-daemon.cpp \n
69 Some actors may be intended to simulate daemons that run in background. This example show how to transform a regular
70 actor into a daemon that will be automatically killed once the simulation is over.
72 @subsection s4u_ex_actors_synchro Inter-actors interactions
74 - <b>Suspend and Resume actors</b>.
75 @ref examples/s4u/actor-suspend/s4u-actor-suspend.cpp \n
76 Actors can be suspended and resumed during their executions
77 thanks to the @ref simgrid::s4u::Actor::suspend and @ref simgrid::s4u::Actor::resume methods.
79 - <b>Migrating Actors</b>.
80 @ref examples/s4u/actor-migration/s4u-actor-migration.cpp \n
81 Actors can move or be moved from a host to another with the @ref
82 simgrid::s4u::this_actor::migrate() method.
84 - <b>Waiting for the termination of an actor</b> (joining on it)
85 @ref examples/s4u/actor-join/s4u-actor-join.cpp \n
86 The simgrid::s4u::Actor::join() method allows to block the current
87 actor until the end of the receiving actor.
89 - <b>Yielding to other actor</b>.
90 @ref examples/s4u/actor-yield/s4u-actor-yield.cpp\n
91 The simgrid::s4u::this_actor::yield() function interrupts the
92 execution of the current actor, leaving a chance to the other actors
93 that are ready to run at this timestamp.
95 @subsection s4u_ex_actors_replay Traces Replay as a Workload
97 This section details how to run trace-driven simulations. It is very
98 handy when you want to test an algorithm or protocol that only react
99 to external events. For example, many P2P protocols react to user
100 requests, but do nothing if there is no such event.
102 In such situations, you should write your protocol in C++, and separate
103 the workload that you want to play onto your protocol in a separate
104 text file. Declare a function handling each type of the events in your
105 trace, register them using @ref xbt_replay_action_register in your
106 main, and then run the simulation.
108 Then, you can either have one trace file containing all your events,
109 or a file per simulated process: the former may be easier to work
110 with, but the second is more efficient on very large traces. Check
111 also the tesh files in the example directories for details.
113 - <b>Communication replay</b>.
114 @ref examples/s4u/replay-comm/s4u-replay-comm.cpp \n
115 Presents a set of event handlers reproducing classical communication
116 primitives (asynchronous send/receive at the moment).
119 @ref examples/s4u/replay-storage/s4u-replay-storage.cpp \n
120 Presents a set of event handlers reproducing classical I/O
121 primitives (open, read, close).
123 @section s4u_ex_activities Activities: the things that Actors do
125 @subsection s4u_ex_activity_comm Communications on the network
127 - <b>Basic asynchronous communications</b>.
128 @ref examples/s4u/async-wait/s4u-async-wait.cpp \n
129 Illustrates how to have non-blocking communications, that are
130 communications running in the background leaving the process free
131 to do something else during their completion. The main functions
132 involved are @ref simgrid::s4u::Mailbox::put_async and
133 @ref simgrid::s4u::Comm::wait().
135 - <b>Waiting for all communications in a set</b>.
136 @ref examples/s4u/async-waitall/s4u-async-waitall.cpp\n
137 The @ref simgrid::s4u::Comm::wait_all() function is useful when you want to block
138 until all activities in a given set have completed.
140 - <b>Waiting for the first completed communication in a set</b>.
141 @ref examples/s4u/async-waitany/s4u-async-waitany.cpp\n
142 The @ref simgrid::s4u::Comm::wait_any() function is useful when you want to block
143 until one activity of the set completes, no matter which terminates
146 @subsection s4u_ex_activity_exec Executions on the CPU
148 - <b>Basic execution</b>.
149 @ref examples/s4u/exec-basic/s4u-exec-basic.cpp \n
150 The computations done in your program are not reported to the
151 simulated world, unless you explicitely request the simulator to pause
152 the actor until a given amount of flops gets computed on its simulated
153 host. Some executions can be given an higher priority so that they
156 - <b>Asynchronous execution</b>.
157 @ref examples/s4u/exec-async/s4u-exec-async.cpp \n
158 You can start asynchronous executions, just like you would fire
161 - <b>Monitoring asynchronous executions</b>.
162 @ref examples/s4u/exec-monitor/s4u-exec-monitor.cpp \n
163 This example shows how to start an asynchronous execution, and
166 - <b>Remote execution</b>.
167 @ref examples/s4u/exec-remote/s4u-exec-remote.cpp \n
168 Before its start, you can change the host on which a given execution will occur.
170 - <b>Using Pstates on a host</b>
171 @ref examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp and
172 @ref examples/platforms/energy_platform.xml \n
173 Show how define a set of pstatesfor a host in the XML, and how the current
174 pstate can be accessed/changed with @ref simgrid::s4u::Host::getPstateSpeed and @ref simgrid::s4u::Host::setPstate.
176 TODO: add an example about parallel executions.
178 @subsection s4u_ex_activity_io I/O on disks and files
180 SimGrid provides two levels of abstraction to interact with the
181 simulated storages. At the simplest level, you simply create read and
182 write actions on the storage resources.
184 - <b>Access to raw storage devices</b>.
185 @ref examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp \n
186 This example illustrates how to simply read and write data on a
187 simulated storage resource.
189 The FileSystem plugin provides a more detailed view, with the
190 classical operations over files: open, move, unlink, and of course
191 read and write. The file and disk sizes are also dealt with and can
192 result in short reads and short write, as in reality.
194 - <b>File Management</b>. @ref examples/s4u/io-file-system/s4u-io-file-system.cpp \n
195 This example illustrates the use of operations on files
196 (read, write, seek, tell, unlink, ...).
199 @ref examples/s4u/io-file-remote/s4u-io-file-remote.cpp \n
200 I/O operations on files can also be done in a remote fashion,
201 i.e. when the accessed disk is not mounted on the caller's host.
203 @subsection s4u_ex_activity_synchro Classical synchronization objects
205 - <b>Mutex: </b> @ref examples/s4u/mutex/s4u-mutex.cpp \n
206 Shows how to use simgrid::s4u::Mutex synchronization objects.
208 @section s4u_ex_platf Interacting with the platform
210 - <b>User-defined properties</b>.
211 @ref examples/s4u/platform-properties/s4u-platform-properties.cpp and
212 @ref examples/s4u/platform-properties/s4u-platform-properties_d.xml and
213 @ref examples/platforms/prop.xml \n
214 You can attach arbitrary information to most platform elements from
215 the XML file, and then interact with these values from your
216 program. Note that the changes are not written into the XML file: they
217 will only last until the end of your simulation.
218 - simgrid::s4u::Actor::getProperty() and simgrid::s4u::Actor::setProperty()
219 - simgrid::s4u::Host::getProperty() and simgrid::s4u::Host::setProperty()
220 - simgrid::s4u::Link::getProperty() and simgrid::s4u::Link::setProperty()
221 - simgrid::s4u::NetZone::getProperty() and simgrid::s4u::NetZone::setProperty()
223 @section s4u_ex_energy Simulating the energy consumption
225 - <b>Consumption due to the CPU</b>
226 @ref examples/s4u/energy-exec/s4u-energy-exec.cpp \n
227 This example shows how to retrieve the amount of energy consumed
228 by the CPU during computations, and the impact of the pstate.
230 @section s4u_ex_tracing Tracing and visualization features
232 Tracing can be activated by various configuration options which
233 are illustrated in these example. See also the
234 @ref tracing_tracing_options "full list of options related to tracing".
236 It is interesting to run the process-create example with the following
237 options to see the task executions:
239 - <b>Platform tracing</b>.
240 @ref examples/s4u/trace-platform/s4u-trace-platform.cpp \n
241 This program is a toy example just loading the platform, so that
242 you can play with the platform visualization. Recommanded options:
243 @verbatim --cfg=tracing:yes --cfg=tracing/categorized:yes
246 @section s4u_ex_examplars Larger SimGrid examplars
248 This section contains application examples that are somewhat larger
249 than the previous examples.
251 - <b>Ping Pong</b>: @ref examples/s4u/app-pingpong/s4u-app-pingpong.cpp\n
252 This simple example just sends one message back and forth.
253 The tesh file laying in the directory show how to start the simulator binary, highlighting how to pass options to
254 the simulators (as detailed in Section \ref options).
256 - <b>Token ring:</b> @ref examples/s4u/app-token-ring/s4u-app-token-ring.cpp \n
257 Shows how to implement a classical communication pattern, where a token is exchanged along a ring to reach every
260 - <b>Master Workers:</b> @ref examples/s4u/app-masterworker/s4u-app-masterworker.cpp \n
261 Another good old example, where one Master process has a bunch of task to dispatch to a set of several Worker
267 @example examples/s4u/actor-create/s4u-actor-create.cpp
268 @example examples/s4u/actor-create/s4u-actor-create_d.xml
269 @example examples/s4u/actor-daemon/s4u-actor-daemon.cpp
270 @example examples/s4u/actor-join/s4u-actor-join.cpp
271 @example examples/s4u/actor-kill/s4u-actor-kill.cpp
272 @example examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp
273 @example examples/s4u/actor-lifetime/s4u-actor-lifetime_d.xml
274 @example examples/s4u/actor-migration/s4u-actor-migration.cpp
275 @example examples/s4u/actor-suspend/s4u-actor-suspend.cpp
276 @example examples/s4u/actor-yield/s4u-actor-yield.cpp
277 @example examples/s4u/async-wait/s4u-async-wait.cpp
278 @example examples/s4u/async-waitall/s4u-async-waitall.cpp
279 @example examples/s4u/async-waitany/s4u-async-waitany.cpp
280 @example examples/s4u/exec-basic/s4u-exec-basic.cpp
281 @example examples/s4u/exec-async/s4u-exec-async.cpp
282 @example examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp
283 @example examples/s4u/exec-monitor/s4u-exec-monitor.cpp
284 @example examples/s4u/exec-remote/s4u-exec-remote.cpp
285 @example examples/s4u/app-token-ring/s4u-app-token-ring.cpp
286 @example examples/s4u/app-masterworker/s4u-app-masterworker.cpp
287 @example examples/s4u/app-pingpong/s4u-app-pingpong.cpp
288 @example examples/s4u/energy-exec/s4u-energy-exec.cpp
289 @example examples/s4u/io-file-system/s4u-io-file-system.cpp
290 @example examples/s4u/io-file-remote/s4u-io-file-remote.cpp
291 @example examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp
292 @example examples/s4u/mutex/s4u-mutex.cpp
293 @example examples/s4u/platform-properties/s4u-platform-properties.cpp
294 @example examples/s4u/platform-properties/s4u-platform-properties_d.xml
295 @example examples/s4u/replay-comm/s4u-replay-comm.cpp
296 @example examples/s4u/replay-storage/s4u-replay-storage.cpp
297 @example examples/s4u/trace-platform/s4u-trace-platform.cpp
298 @example examples/platforms/energy_platform.xml
299 @example examples/platforms/prop.xml