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.
17 - @ref s4u_ex_activities
18 - @ref s4u_ex_activity_comm
19 - @ref s4u_ex_activity_exec
20 - @ref s4u_ex_activity_io
22 - @ref s4u_ex_actors_start
23 - @ref s4u_ex_actors_synchro
24 - @ref s4u_ex_actors_replay
29 TODO: document here the examples about plugins
31 @section s4u_ex_basics Basics of SimGrid simulation
33 - <b>Creating actors:</b> @ref examples/s4u/actor-create/s4u-actor-create.cpp and
34 @ref examples/s4u/actor-create/s4u-actor-create_d.xml \n
35 Shows how to start your actors to populate your simulation.
37 - <b>Ping Pong</b>: @ref examples/s4u/app-pingpong/s4u-app-pingpong.cpp\n
38 This simple example just sends one message back and forth.
39 The tesh file laying in the directory show how to start the simulator binary, highlighting how to pass options to
40 the simulators (as detailed in Section \ref options).
42 - <b>Token ring:</b> @ref examples/s4u/app-token-ring/s4u-app-token-ring.cpp \n
43 Shows how to implement a classical communication pattern, where a token is exchanged along a ring to reach every
46 - <b>Master Workers:</b> @ref examples/s4u/app-masterworker/s4u-app-masterworker.cpp \n
47 Another good old example, where one Master process has a bunch of task to dispatch to a set of several Worker
50 @section s4u_ex_activities Activities that consume Resources (communications, executions and disks)
52 @subsection s4u_ex_activity_comm Communications (using the network)
54 - <b>Basic asynchronous communications</b>.
55 @ref examples/s4u/async-wait/s4u-async-wait.cpp \n
56 Illustrates how to have non-blocking communications, that are
57 communications running in the background leaving the process free
58 to do something else during their completion. The main functions
59 involved are @ref simgrid::s4u::Mailbox::put_async and
60 @ref simgrid::s4u::Comm::wait().
62 - <b>Waiting for all communications in a set</b>.
63 @ref examples/s4u/async-waitall/s4u-async-waitall.cpp\n
64 The @ref simgrid::s4u::Comm::wait_all() function is useful when you want to block
65 until all activities in a given set have completed.
67 - <b>Waiting for the first completed communication in a set</b>.
68 @ref examples/s4u/async-waitany/s4u-async-waitany.cpp\n
69 The @ref simgrid::s4u::Comm::wait_any() function is useful when you want to block
70 until one activity of the set completes, no matter which terminates
73 @subsection s4u_ex_activity_exec Executions (using the CPU)
75 - <b>Basic execution</b>.
76 @ref examples/s4u/exec-basic/s4u-exec-basic.cpp \n
77 The computations done in your program are not reported to the
78 simulated world, unless you explicitely request the simulator to pause
79 the actor until a given amount of flops gets computed on its simulated
80 host. Some executions can be given an higher priority so that they
83 - <b>Asynchronous execution</b>.
84 @ref examples/s4u/exec-async/s4u-exec-async.cpp \n
85 You can start asynchronous executions, just like you would fire
88 - <b>Monitoring asynchronous executions</b>.
89 @ref examples/s4u/exec-monitor/s4u-exec-monitor.cpp \n
90 This example shows how to start an asynchronous execution, and
93 - <b>Remote execution</b>.
94 @ref examples/s4u/exec-remote/s4u-exec-remote.cpp \n
95 Before its start, you can change the host on which a given execution will occur.
97 TODO: add an example about parallel executions.
99 @subsection s4u_ex_activity_io I/O (using disks and files)
101 SimGrid provides two levels of abstraction to interact with the
102 simulated storages. At the simplest level, you simply create read and
103 write actions on the storage resources.
105 - <b>Access to raw storage devices</b>.
106 @ref examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp \n
107 This example illustrates how to simply read and write data on a
108 simulated storage resource.
110 The FileSystem plugin provides a more detailed view, with the
111 classical operations over files: open, move, unlink, and of course
112 read and write. The file and disk sizes are also dealt with and can
113 result in short reads and short write, as in reality.
115 - <b>File Management</b>. @ref examples/s4u/io-file-system/s4u-io-file-system.cpp \n
116 This example illustrates the use of operations on files
117 (read, write, seek, tell, unlink, ...).
120 @ref examples/s4u/io-file-remote/s4u-io-file-remote.cpp \n
121 I/O operations on files can also be done in a remote fashion,
122 i.e. when the accessed disk is not mounted on the caller's host.
124 @section s4u_ex_actors Acting on Actors
126 @subsection s4u_ex_actors_start Starting and stoping actors
128 - <b>Creating actors</b>.
129 @ref examples/s4u/actor-create/s4u-actor-create.cpp \n
130 Most actors are started from the deployment XML file, but there is other methods.
131 This example show them all.
133 - <b>Kill actors</b>.
134 @ref examples/s4u/actor-kill/s4u-actor-kill.cpp \n
135 Actors can forcefully stop other actors with the @ref
136 simgrid::s4u::Actor::kill() method.
138 - <b>Controling the actor life cycle from the XML</b>.
139 @ref examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp
140 @ref examples/s4u/actor-lifetime/s4u-actor-lifetime_d.xml
142 You can specify a start time and a kill time in the deployment file.
144 - <b>Daemonize actors</b>
145 @ref examples/s4u/actor-daemon/s4u-actor-daemon.cpp \n
146 Some actors may be intended to simulate daemons that run in background. This example show how to transform a regular
147 actor into a daemon that will be automatically killed once the simulation is over.
149 @subsection s4u_ex_actors_synchro Inter-actors interactions
151 - <b>Suspend and Resume actors</b>.
152 @ref examples/s4u/actor-suspend/s4u-actor-suspend.cpp \n
153 Actors can be suspended and resumed during their executions
154 thanks to the @ref simgrid::s4u::Actor::suspend and @ref simgrid::s4u::Actor::resume methods.
156 - <b>Migrating Actors</b>.
157 @ref examples/s4u/actor-migration/s4u-actor-migration.cpp \n
158 Actors can move or be moved from a host to another with the @ref
159 simgrid::s4u::this_actor::migrate() method.
161 - <b>Waiting for the termination of an actor</b> (joining on it)
162 @ref examples/s4u/actor-join/s4u-actor-join.cpp \n
163 The simgrid::s4u::Actor::join() method allows to block the current
164 actor until the end of the receiving actor.
166 - <b>Yielding to other actor</b>.
167 @ref examples/s4u/actor-yield/s4u-actor-yield.cpp\n
168 The simgrid::s4u::this_actor::yield() function interrupts the
169 execution of the current actor, leaving a chance to the other actors
170 that are ready to run at this timestamp.
172 @subsection s4u_ex_actors_replay Traces Replay as a Workload
174 This section details how to run trace-driven simulations. It is very
175 handy when you want to test an algorithm or protocol that only react
176 to external events. For example, many P2P protocols react to user
177 requests, but do nothing if there is no such event.
179 In such situations, you should write your protocol in C++, and separate
180 the workload that you want to play onto your protocol in a separate
181 text file. Declare a function handling each type of the events in your
182 trace, register them using @ref xbt_replay_action_register in your
183 main, and then run the simulation.
185 Then, you can either have one trace file containing all your events,
186 or a file per simulated process: the former may be easier to work
187 with, but the second is more efficient on very large traces. Check
188 also the tesh files in the example directories for details.
190 - <b>Communication replay</b>.
191 @ref examples/s4u/actions-comm/s4u-actions-comm.cpp \n
192 Presents a set of event handlers reproducing classical communication
193 primitives (asynchronous send/receive at the moment).
196 @ref examples/s4u/actions-storage/s4u-actions-storage.cpp \n
197 Presents a set of event handlers reproducing classical I/O
198 primitives (open, read, close).
200 @section s4u_ex_synchro Classical synchronization objects
202 - <b>Mutex: </b> @ref examples/s4u/mutex/s4u-mutex.cpp \n
203 Shows how to use simgrid::s4u::Mutex synchronization objects.
205 @section s4u_ex_platf Interacting with the platform
207 - <b>User-defined properties</b>.
208 @ref examples/s4u/platform-properties/s4u-platform-properties.cpp and
209 @ref examples/s4u/platform-properties/s4u-platform-properties_d.xml and
210 @ref examples/platforms/prop.xml \n
211 You can attach arbitrary information to most platform elements from
212 the XML file, and then interact with these values from your
213 program. Note that the changes are not written into the XML file: they
214 will only last until the end of your simulation.
215 - simgrid::s4u::Actor::getProperty() and simgrid::s4u::Actor::setProperty()
216 - simgrid::s4u::Host::getProperty() and simgrid::s4u::Host::setProperty()
217 - simgrid::s4u::Link::getProperty() and simgrid::s4u::Link::setProperty()
218 - simgrid::s4u::NetZone::getProperty() and simgrid::s4u::NetZone::setProperty()
221 @section s4u_ex_energy Simulating the energy consumption
223 - <b>Using Pstates on a host</b>
224 @ref examples/s4u/energy-pstate/s4u-energy-pstate.cpp and
225 @ref examples/platforms/energy_platform.xml \n
226 Show how define a set of pstates for a host and how the current
227 pstate can be accessed/changed with @ref simgrid::s4u::Host::getPstateSpeed and @ref simgrid::s4u::Host::setPstate.
228 See also the platform XML file for have a details on how to declare the CPU capacity for each pstate.
233 @example examples/s4u/actions-comm/s4u-actions-comm.cpp
234 @example examples/s4u/actions-storage/s4u-actions-storage.cpp
235 @example examples/s4u/actor-create/s4u-actor-create.cpp
236 @example examples/s4u/actor-create/s4u-actor-create_d.xml
237 @example examples/s4u/actor-daemon/s4u-actor-daemon.cpp
238 @example examples/s4u/actor-join/s4u-actor-join.cpp
239 @example examples/s4u/actor-kill/s4u-actor-kill.cpp
240 @example examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp
241 @example examples/s4u/actor-lifetime/s4u-actor-lifetime_d.xml
242 @example examples/s4u/actor-migration/s4u-actor-migration.cpp
243 @example examples/s4u/actor-suspend/s4u-actor-suspend.cpp
244 @example examples/s4u/actor-yield/s4u-actor-yield.cpp
245 @example examples/s4u/async-wait/s4u-async-wait.cpp
246 @example examples/s4u/async-waitall/s4u-async-waitall.cpp
247 @example examples/s4u/async-waitany/s4u-async-waitany.cpp
248 @example examples/s4u/exec-basic/s4u-exec-basic.cpp
249 @example examples/s4u/exec-async/s4u-exec-async.cpp
250 @example examples/s4u/exec-monitor/s4u-exec-monitor.cpp
251 @example examples/s4u/exec-remote/s4u-exec-remote.cpp
252 @example examples/s4u/app-token-ring/s4u-app-token-ring.cpp
253 @example examples/s4u/app-masterworker/s4u-app-masterworker.cpp
254 @example examples/s4u/app-pingpong/s4u-app-pingpong.cpp
255 @example examples/s4u/energy-pstate/s4u-energy-pstate.cpp
256 @example examples/s4u/io-file-system/s4u-io-file-system.cpp
257 @example examples/s4u/io-file-remote/s4u-io-file-remote.cpp
258 @example examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp
259 @example examples/s4u/mutex/s4u-mutex.cpp
260 @example examples/s4u/platform-properties/s4u-platform-properties.cpp
261 @example examples/s4u/platform-properties/s4u-platform-properties_d.xml
262 @example examples/platforms/energy_platform.xml
263 @example examples/platforms/prop.xml