8 <object id="TOC" data="graphical-toc.svg" width="100%" type="image/svg+xml"></object>
10 window.onload=function() { // Wait for the SVG to be loaded before changing it
11 var elem=document.querySelector("#TOC").contentDocument.getElementById("S4UBox")
12 elem.style="opacity:0.93999999;fill:#ff0000;fill-opacity:0.1";
18 The S4U interface (SimGrid for you) mixes the full power of SimGrid
19 with the full power of C++. This is the preferred interface to describe
20 abstract algorithms in the domains of Cloud, P2P, HPC, IoT, and similar
23 Currently (v3.21), S4U is definitely the way to go for long-term
24 projects. It is feature complete, but may still evolve slightly in the
25 future releases. It can already be used to do everything that can be
26 done in SimGrid, but you may have to adapt your code in future
27 releases. When this happens, compiling your code will produce
28 deprecation warnings for 4 releases (one year) before the removal of
30 If you want an API that will never ever evolve in the future, you
31 should use the deprecated MSG API instead.
36 A typical SimGrid simulation is composed of several |API_s4u_Actors|_, that
37 execute user-provided functions. The actors have to explicitly use the
38 S4U interface to express their :ref:`computation <API_s4u_Exec>`,
39 :ref:`communication <API_s4u_Comm>`, :ref:`disk usage <API_s4u_Io>`,
40 and other |API_s4u_Activities|_, so that they get reflected within the
41 simulator. These activities take place on resources such as |API_s4u_Hosts|_,
42 |API_s4u_Links|_ and |API_s4u_Storages|_. SimGrid predicts the time taken by each
43 activity and orchestrates the actors accordingly, waiting for the
44 completion of these activities.
47 When **communicating**, data is not directly sent to other actors but
48 posted onto a |API_s4u_Mailbox|_ that serves as a rendez-vous point between
49 communicating actors. This means that you don't need to know who you
50 are talking to, you just put your communication `Put` request in a
51 mailbox, and it will be matched with a complementary `Get`
52 request. Alternatively, actors can interact through **classical
53 synchronization mechanisms** such as |API_s4u_Barrier|_, |API_s4u_Semaphore|_,
54 |API_s4u_Mutex|_ and |API_s4u_ConditionVariable|_.
56 Each actor is located on a simulated |API_s4u_Host|_. Each host is located
57 itself in a |API_s4u_NetZone|_, that knows the networking path between one
58 resource to another. Each NetZone is included in another one, forming
59 a tree of NetZones which root zone contains the whole platform.
61 The :ref:`simgrid::s4u::this_actor <API_s4u_this_actor>` namespace
62 provides many helper functions to simplify the code of actors.
66 - :ref:`class s4u::Actor <API_s4u_Actor>`:
67 Active entities executing your application.
68 - :ref:`class s4u::Engine <API_s4u_Engine>`
69 Simulation engine (singleton).
70 - :ref:`class s4u::Mailbox <API_s4u_Mailbox>`
71 Communication rendez-vous.
73 - **Platform Elements**
75 - :ref:`class s4u::Host <API_s4u_Host>`:
76 Actor location, providing computational power.
77 - :ref:`class s4u::Link <API_s4u_Link>`
78 Interconnecting hosts.
79 - :ref:`class s4u::NetZone <API_s4u_NetZone>`:
80 Sub-region of the platform, containing resources (Hosts, Links, etc).
81 - :ref:`class s4u::Storage <API_s4u_Storage>`
82 Resource on which actors can write and read data.
83 - :ref:`class s4u::VirtualMachine <API_s4u_VirtualMachine>`:
84 Execution containers that can be moved between Hosts.
86 - **Activities** (:ref:`class s4u::Activity <API_s4u_Activity>`):
87 The things that actors can do on resources
89 - :ref:`class s4u::Comm <API_s4u_Comm>`
90 Communication activity, started on Mailboxes and consuming links.
91 - :ref:`class s4u::Exec <API_s4u_Exec>`
92 Computation activity, started on Host and consuming CPU resources.
93 - :ref:`class s4u::Io <API_s4u_Io>`
94 I/O activity, started on and consumming Storages.
96 - **Synchronization Mechanisms**: Classical IPC that actors can use
98 - :ref:`class s4u::Barrier <API_s4u_Barrier>`
99 - :ref:`class s4u::ConditionVariable <API_s4u_ConditionVariable>`
100 - :ref:`class s4u::Mutex <API_s4u_Mutex>`
101 - :ref:`class s4u::Semaphore <API_s4u_Semaphore>`
104 .. |API_s4u_Actors| replace:: **Actors**
105 .. _API_s4u_Actors: #s4u-actor
107 .. |API_s4u_Activities| replace:: **Activities**
108 .. _API_s4u_Activities: #s4u-activity
110 .. |API_s4u_Hosts| replace:: **Hosts**
111 .. _API_s4u_Hosts: #s4u-host
113 .. |API_s4u_Links| replace:: **Links**
114 .. _API_s4u_Links: #s4u-link
116 .. |API_s4u_Storages| replace:: **Storages**
117 .. _API_s4u_Storages: #s4u-storage
119 .. |API_s4u_VirtualMachines| replace:: **VirtualMachines**
120 .. _API_s4u_VirtualMachines: #s4u-virtualmachine
122 .. |API_s4u_Host| replace:: **Host**
124 .. |API_s4u_Mailbox| replace:: **Mailbox**
126 .. |API_s4u_NetZone| replace:: **NetZone**
128 .. |API_s4u_Barrier| replace:: **Barrier**
130 .. |API_s4u_Semaphore| replace:: **Semaphore**
132 .. |API_s4u_ConditionVariable| replace:: **ConditionVariable**
134 .. |API_s4u_Mutex| replace:: **Mutex**
138 .. include:: ../../examples/s4u/README.rst
143 Activities represent the actions that consume a resource, such as a
144 :ref:`s4u::Comm <API_s4u_Comm>` that consumes the *transmiting power* of
145 :ref:`s4u::Link <API_s4u_Link>` resources.
147 =======================
148 Asynchronous Activities
149 =======================
151 Every activity can be either **blocking** or **asynchronous**. For
152 example, :cpp:func:`s4u::Mailbox::put() <simgrid::s4u::Mailbox::put>`
153 and :cpp:func:`s4u::Mailbox::get() <simgrid::s4u::Mailbox::get>`
154 create blocking communications: the actor is blocked until the
155 completion of that communication. Asynchronous communications do not
156 block the actor during their execution but progress on their own.
158 Once your asynchronous activity is started, you can test for its
159 completion using :cpp:func:`s4u::Activity::test() <simgrid::s4u::Activity::test>`.
160 This function returns ``true`` if the activity completed already.
161 You can also use :cpp:func:`s4u::Activity::wait() <simgrid::s4u::Activity::wait>`
162 to block until the completion of the activity. To wait for at most a given amount of time,
163 use :cpp:func:`s4u::Activity::wait_for() <simgrid::s4u::Activity::wait_for>`.
164 Finally, to wait at most until a specified time limit, use
165 :cpp:func:`s4u::Activity::wait_until() <simgrid::s4u::Activity::wait_until>`.
169 wait_for and wait_until are currently not implemented for Exec and Io activities.
171 Every kind of activities can be asynchronous:
173 - :ref:`s4u::CommPtr <API_s4u_Comm>` are created with
174 :cpp:func:`s4u::Mailbox::put_async() <simgrid::s4u::Mailbox::put_async>` and
175 :cpp:func:`s4u::Mailbox::get_async() <simgrid::s4u::Mailbox::get_async>`.
176 - :ref:`s4u::IoPtr <API_s4u_Io>` are created with
177 :cpp:func:`s4u::Storage::read_async() <simgrid::s4u::Storage::read_async>` and
178 :cpp:func:`s4u::Storage::write_async() <simgrid::s4u::Storage::write_async>`.
179 - :ref:`s4u::ExecPtr <API_s4u_Exec>` are created with
180 :cpp:func:`s4u::Host::exec_async() <simgrid::s4u::Host::exec_async>`.
181 - In the future, it will become possible to have asynchronous IPC
182 such as asynchronous mutex lock requests.
184 The following example shows how to have several concurrent
185 communications ongoing. First, you have to declare a vector in which
186 we will store the ongoing communications. It is also useful to have a
189 .. literalinclude:: ../../examples/s4u/async-waitall/s4u-async-waitall.cpp
191 :start-after: init-begin
192 :end-before: init-end
195 Then, you start all the communications that should occur concurrently with
196 :cpp:func:`s4u::Mailbox::put_async() <simgrid::s4u::Mailbox::put_async>`.
197 Finally, the actor waits for the completion of all of them at once
199 :cpp:func:`s4u::Comm::wait_all() <simgrid::s4u::Comm::wait_all>`.
201 .. literalinclude:: ../../examples/s4u/async-waitall/s4u-async-waitall.cpp
203 :start-after: put-begin
208 =====================
209 Activities Life cycle
210 =====================
212 Sometimes, you want to change the setting of an activity before it even starts.
214 .. todo:: write this section
219 For sake of simplicity, we use `RAII
220 <https://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization>`_
221 everywhere in S4U. This is an idiom where resources are automatically
222 managed through the context. Provided that you never manipulate
223 objects of type Foo directly but always FooPtr references (which are
224 defined as `boost::intrusive_ptr
225 <http://www.boost.org/doc/libs/1_61_0/libs/smart_ptr/intrusive_ptr.html>`_
226 <Foo>), you will never have to explicitely release the resource that
227 you use nor to free the memory of unused objects.
229 Here is a little example:
235 simgrid::s4u::MutexPtr mutex = simgrid::s4u::Mutex::create(); // Too bad we cannot use `new`
237 mutex->lock(); // use the mutex as a simple reference
241 } // The mutex gets automatically freed because the only existing reference gets out of scope
246 .. _API_s4u_Activity:
252 .. doxygenclass:: simgrid::s4u::Activity
263 .. doxygentypedef:: ActorPtr
265 .. doxygenclass:: simgrid::s4u::Actor
276 .. doxygentypedef:: BarrierPtr
278 .. doxygenclass:: simgrid::s4u::Barrier
289 .. doxygentypedef:: CommPtr
291 .. doxygenclass:: simgrid::s4u::Comm
296 .. _API_s4u_ConditionVariable:
298 ======================
299 s4u::ConditionVariable
300 ======================
302 .. doxygentypedef:: ConditionVariablePtr
304 .. doxygenclass:: simgrid::s4u::ConditionVariable
315 .. doxygenclass:: simgrid::s4u::Engine
326 .. doxygentypedef:: ExecPtr
328 .. doxygenclass:: simgrid::s4u::Exec
339 .. doxygenclass:: simgrid::s4u::Host
350 .. doxygentypedef:: IoPtr
352 .. doxygenclass:: simgrid::s4u::Io
363 .. doxygenclass:: simgrid::s4u::Link
374 .. doxygentypedef:: MailboxPtr
376 .. doxygenclass:: simgrid::s4u::Mailbox
387 .. doxygentypedef:: MutexPtr
389 .. doxygenclass:: simgrid::s4u::Mutex
400 .. doxygenclass:: simgrid::s4u::NetZone
405 .. _API_s4u_Semaphore:
411 .. doxygentypedef:: SemaphorePtr
413 .. doxygenclass:: simgrid::s4u::Semaphore
424 .. doxygenclass:: simgrid::s4u::Storage
429 .. _API_s4u_VirtualMachine:
435 .. doxygenclass:: simgrid::s4u::VirtualMachine
440 .. _API_s4u_this_actor:
442 =========================
443 namespace s4u::this_actor
444 =========================
447 .. doxygennamespace:: simgrid::s4u::this_actor