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.
25 TODO: document here the examples about plugins
27 @section s4u_ex_basics Basics of SimGrid simulation
29 - <b>Creating actors:</b> @ref examples/s4u/actor-create/s4u-actor-create.cpp and
30 @ref examples/s4u/actor-create/s4u-actor-create_d.xml \n
31 Shows how to start your actors to populate your simulation.
33 - <b>Ping Pong</b>: @ref examples/s4u/app-pingpong/s4u-app-pingpong.cpp\n
34 This simple example just sends one message back and forth.
35 The tesh file laying in the directory show how to start the simulator binary, highlighting how to pass options to
36 the simulators (as detailed in Section \ref options).
38 - <b>Token ring:</b> @ref examples/s4u/app-token-ring/s4u-app-token-ring.cpp \n
39 Shows how to implement a classical communication pattern, where a token is exchanged along a ring to reach every
42 - <b>Master Workers:</b> @ref examples/s4u/app-masterworker/s4u-app-masterworker.cpp \n
43 Another good old example, where one Master process has a bunch of task to dispatch to a set of several Worker
46 @section s4u_ex_async Asynchronous communications
48 - <b>Basic asynchronous communications</b>.
49 @ref examples/s4u/async-wait/s4u-async-wait.cpp \n
50 Illustrates how to have non-blocking communications, that are
51 communications running in the background leaving the process free
52 to do something else during their completion. The main functions
53 involved are @ref simgrid::s4u::Mailbox::put_async and
54 @ref simgrid::s4u::Comm::wait().
56 - <b>Waiting for all communications in a set</b>.
57 @ref examples/s4u/async-waitall/s4u-async-waitall.cpp\n
58 The @ref simgrid::s4u::Comm::wait_all() function is useful when you want to block
59 until all activities in a given set have completed.
61 - <b>Waiting for the first completed communication in a set</b>.
62 @ref examples/s4u/async-waitany/s4u-async-waitany.cpp\n
63 The @ref simgrid::s4u::Comm::wait_any() function is useful when you want to block
64 until one activity of the set completes, no matter which terminates
67 @section s4u_ex_actors Acting on Actors
69 - <b>Creating actors</b>.
70 @ref examples/s4u/actor-create/s4u-actor-create.cpp \n
71 Most actors are started from the deployment XML file, but there is other methods.
72 This example show them all.
74 - <b>Actors using CPU time</b>.
75 @ref examples/s4u/actor-execute/s4u-actor-execute.cpp \n
76 The computations done in your program are not reported to the
77 simulated world, unless you explicitely request the simulator to pause
78 the actor until a given amount of flops gets computed on its simulated
79 host. Some executions can be given an higher priority so that they
82 - <b>Daemonize actors</b>
83 @ref examples/s4u/actor-daemon/s4u-actor-daemon.cpp \n
84 Some actors may be intended to simulate daemons that run in background. This example show how to transform a regular
85 actor into a daemon that will be automatically killed once the simulation is over.
87 - <b>Suspend and Resume actors</b>.
88 @ref examples/s4u/actor-suspend/s4u-actor-suspend.cpp \n
89 Actors can be suspended and resumed during their executions
90 thanks to the @ref simgrid::s4u::Actor::suspend and @ref simgrid::s4u::Actor::resume methods.
93 @ref examples/s4u/actor-kill/s4u-actor-kill.cpp \n
94 Actors can forcefully stop other actors with the @ref
95 simgrid::s4u::Actor::kill() method.
97 - <b>Controling the actor life cycle from the XML</b>.
98 @ref examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp
99 @ref examples/s4u/actor-lifetime/s4u-actor-lifetime_d.xml
101 You can specify a start time and a kill time in the deployment file.
103 - <b>Migrating Actors</b>.
104 @ref examples/s4u/actor-migration/s4u-actor-migration.cpp \n
105 Actors can move or be moved from a host to another with the @ref
106 simgrid::s4u::this_actor::migrate() method.
108 - <b>Yielding to other actor</b>.
109 @ref examples/s4u/actor-yield/s4u-actor-yield.cpp\n
110 The simgrid::s4u::this_actor::yield() function interrupts the
111 execution of the current actor, leaving a chance to the other actors
112 that are ready to run at this timestamp.
114 @section s4u_ex_synchro Inter-Actor Synchronization
116 - <b>Waiting for the termination of an actor</b> (joining on it)
117 @ref examples/s4u/actor-join/s4u-actor-join.cpp \n
118 The simgrid::s4u::Actor::join() method allows to block the current
119 actor until the end of the receiving actor.
121 - <b>Mutex: </b> @ref examples/s4u/mutex/s4u-mutex.cpp \n
122 Shows how to use simgrid::s4u::Mutex synchronization objects.
124 @section s4u_ex_actions Following Workload Traces
126 This section details how to run trace-driven simulations. It is very
127 handy when you want to test an algorithm or protocol that only react
128 to external events. For example, many P2P protocols react to user
129 requests, but do nothing if there is no such event.
131 In such situations, you should write your protocol in C++, and separate
132 the workload that you want to play onto your protocol in a separate
133 text file. Declare a function handling each type of the events in your
134 trace, register them using @ref xbt_replay_action_register in your
135 main, and then run the simulation.
137 Then, you can either have one trace file containing all your events,
138 or a file per simulated process: the former may be easier to work
139 with, but the second is more efficient on very large traces. Check
140 also the tesh files in the example directories for details.
142 - <b>Communication replay</b>.
143 @ref examples/s4u/actions-comm/s4u-actions-comm.cpp \n
144 Presents a set of event handlers reproducing classical communication
145 primitives (asynchronous send/receive at the moment).
148 @ref examples/s4u/actions-storage/s4u-actions-storage.cpp \n
149 Presents a set of event handlers reproducing classical I/O
150 primitives (open, read, close).
152 @section s4u_ex_platf Interacting with the platform
154 - <b>User-defined properties</b>.
155 @ref examples/s4u/platform-properties/s4u-platform-properties.cpp and
156 @ref examples/s4u/platform-properties/s4u-platform-properties_d.xml and
157 @ref examples/platforms/prop.xml \n
158 You can attach arbitrary information to most platform elements from
159 the XML file, and then interact with these values from your
160 program. Note that the changes are not written into the XML file: they
161 will only last until the end of your simulation.
162 - simgrid::s4u::Actor::getProperty() and simgrid::s4u::Actor::setProperty()
163 - simgrid::s4u::Host::getProperty() and simgrid::s4u::Host::setProperty()
164 - simgrid::s4u::Link::getProperty() and simgrid::s4u::Link::setProperty()
165 - simgrid::s4u::NetZone::getProperty() and simgrid::s4u::NetZone::setProperty()
167 @section s4u_ex_io Simulating disks and files
169 The examples of this section demonstrate how to interact with the
172 - <b>File Management</b>. @ref examples/s4u/io-file-system/s4u-io-file-system.cpp \n
173 This example illustrates the use of operations on files
174 (read, write, seek, tell, unlink, ...).
176 - <b>Access to raw storage devices </b>.
177 @ref examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp \n
178 This example illustrates how to simply read and write data on a
179 simulated storage resource.
182 @ref examples/s4u/io-file-remote/s4u-io-file-remote.cpp \n
183 I/O operations on files can also be done in a remote fashion,
184 i.e. when the accessed disk is not mounted on the caller's host.
186 @section s4u_ex_energy Simulating the energy consumption
188 - <b>Using Pstates on a host</b>
189 @ref examples/s4u/energy-pstate/s4u-energy-pstate.cpp and
190 @ref examples/platforms/energy_platform.xml \n
191 Show how define a set of pstates for a host and how the current
192 pstate can be accessed/changed with @ref simgrid::s4u::Host::getPstateSpeed and @ref simgrid::s4u::Host::setPstate.
193 See also the platform XML file for have a details on how to declare the CPU capacity for each pstate.
198 @example examples/s4u/actions-comm/s4u-actions-comm.cpp
199 @example examples/s4u/actions-storage/s4u-actions-storage.cpp
200 @example examples/s4u/actor-create/s4u-actor-create.cpp
201 @example examples/s4u/actor-create/s4u-actor-create_d.xml
202 @example examples/s4u/actor-daemon/s4u-actor-daemon.cpp
203 @example examples/s4u/actor-execute/s4u-actor-execute.cpp
204 @example examples/s4u/actor-join/s4u-actor-join.cpp
205 @example examples/s4u/actor-kill/s4u-actor-kill.cpp
206 @example examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp
207 @example examples/s4u/actor-lifetime/s4u-actor-lifetime_d.xml
208 @example examples/s4u/actor-migration/s4u-actor-migration.cpp
209 @example examples/s4u/actor-suspend/s4u-actor-suspend.cpp
210 @example examples/s4u/actor-yield/s4u-actor-yield.cpp
211 @example examples/s4u/app-token-ring/s4u-app-token-ring.cpp
212 @example examples/s4u/app-masterworker/s4u-app-masterworker.cpp
213 @example examples/s4u/app-pingpong/s4u-app-pingpong.cpp
214 @example examples/s4u/async-wait/s4u-async-wait.cpp
215 @example examples/s4u/async-waitall/s4u-async-waitall.cpp
216 @example examples/s4u/async-waitany/s4u-async-waitany.cpp
217 @example examples/s4u/energy-pstate/s4u-energy-pstate.cpp
218 @example examples/s4u/io-file-system/s4u-io-file-system.cpp
219 @example examples/s4u/io-file-remote/s4u-io-file-remote.cpp
220 @example examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp \n
221 @example examples/s4u/mutex/s4u-mutex.cpp
222 @example examples/s4u/platform-properties/s4u-platform-properties.cpp
223 @example examples/s4u/platform-properties/s4u-platform-properties_d.xml
224 @example examples/platforms/energy_platform.xml
225 @example examples/platforms/prop.xml