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 |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 |Activities|_, so that they get reflected within the
41 simulator. These activities take place on resources such as |Hosts|_,
42 |Links|_ and |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 |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 |Barrier|_, |Semaphore|_,
54 |Mutex|_ and |ConditionVariable|_.
56 Each actor is located on a simulated |Host|_. Each host is located
57 itself in a |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
62 <namespace_simgrid__s4u__this_actor>` namespace provides many helper
63 functions to simplify the code of actors.
67 - :ref:`class s4u::Actor <API_s4u_Actor>`:
68 Active entities executing your application.
69 - :ref:`class s4u::Engine <API_s4u_Engine>`
70 Simulation engine (singleton).
71 - :ref:`class s4u::Mailbox <API_s4u_Mailbox>`
72 Communication rendez-vous.
74 - **Platform Elements**
76 - :ref:`class s4u::Host <API_s4u_Host>`:
77 Actor location, providing computational power.
78 - :ref:`class s4u::Link <API_s4u_Link>`
79 Interconnecting hosts.
80 - :ref:`class s4u::NetZone <API_s4u_NetZone>`:
81 Sub-region of the platform, containing resources (Hosts, Links, etc).
82 - :ref:`class s4u::Storage <API_s4u_Storage>`
83 Resource on which actors can write and read data.
84 - :ref:`class s4u::VirtualMachine <API_s4u_VirtualMachine>`:
85 Execution containers that can be moved between Hosts.
87 - **Activities** (:ref:`class s4u::Activity <API_s4u_Activity>`):
88 The things that actors can do on resources
90 - :ref:`class s4u::Comm <API_s4u_Comm>`
91 Communication activity, started on Mailboxes and consuming links.
92 - :ref:`class s4u::Exec <API_s4u_Exec>`
93 Computation activity, started on Host and consuming CPU resources.
94 - :ref:`class s4u::Io <API_s4u_Io>`
95 I/O activity, started on and consumming Storages.
97 - **Synchronization Mechanisms**: Classical IPC that actors can use
99 - :ref:`class s4u::Barrier <API_s4u_Barrier>`
100 - :ref:`class s4u::ConditionVariable <API_s4u_ConditionVariable>`
101 - :ref:`class s4u::Mutex <API_s4u_Mutex>`
102 - :ref:`class s4u::Semaphore <API_s4u_Semaphore>`
105 .. |Actors| replace:: **Actors**
106 .. _Actors: api/classsimgrid_1_1s4u_1_1Actor.html
108 .. |Activities| replace:: **Activities**
109 .. _Activities: api/classsimgrid_1_1s4u_1_1Activity.html
111 .. |Hosts| replace:: **Hosts**
112 .. _Hosts: api/classsimgrid_1_1s4u_1_1Host.html
114 .. |Links| replace:: **Links**
115 .. _Links: api/classsimgrid_1_1s4u_1_1Link.html
117 .. |Storages| replace:: **Storages**
118 .. _Storages: api/classsimgrid_1_1s4u_1_1Storage.html
120 .. |VirtualMachines| replace:: **VirtualMachines**
121 .. _VirtualMachines: api/classsimgrid_1_1s4u_1_1VirtualMachine.html
123 .. |Host| replace:: **Host**
124 .. _Host: api/classsimgrid_1_1s4u_1_1Host.html
126 .. |Mailbox| replace:: **Mailbox**
127 .. _Mailbox: api/classsimgrid_1_1s4u_1_1Mailbox.html
129 .. |NetZone| replace:: **NetZone**
130 .. _NetZone: api/classsimgrid_1_1s4u_1_1NetZone.html
132 .. |Barrier| replace:: **Barrier**
133 .. _Barrier: api/classsimgrid_1_1s4u_1_1Barrier.html
135 .. |ConditionVariable| replace:: **ConditionVariable**
136 .. _ConditionVariable: api/classsimgrid_1_1s4u_1_1ConditionVariable.html
138 .. |Mutex| replace:: **Mutex**
139 .. _Mutex: api/classsimgrid_1_1s4u_1_1Mutex.html
143 .. include:: ../../examples/s4u/README.rst
148 Activities represent the actions that consume a resource, such as a
149 :ref:`s4u::Comm <API_s4u_Comm>` that consumes the *transmiting power* of
150 :ref:`s4u::Link <API_s4u_Link>` resources.
152 =======================
153 Asynchronous Activities
154 =======================
156 Every activity can be either **blocking** or **asynchronous**. For
157 example, :cpp:func:`s4u::Mailbox::put() <simgrid::s4u::Mailbox::put>`
158 and :cpp:func:`s4u::Mailbox::get() <simgrid::s4u::Mailbox::get>`
159 create blocking communications: the actor is blocked until the
160 completion of that communication. Asynchronous communications do not
161 block the actor during their execution but progress on their own.
163 Once your asynchronous activity is started, you can test for its
164 completion using :cpp:func:`s4u::Activity::test() <simgrid::s4u::Activity::test>`.
165 This function returns ``true`` if the activity completed already.
166 You can also use :cpp:func:`s4u::Activity::wait() <simgrid::s4u::Activity::wait>`
167 to block until the completion of the activity. To wait for at most a given amount of time,
168 use :cpp:func:`s4u::Activity::wait_for() <simgrid::s4u::Activity::wait_for>`.
169 Finally, to wait at most until a specified time limit, use
170 :cpp:func:`s4u::Activity::wait_until() <simgrid::s4u::Activity::wait_until>`.
174 wait_for and wait_until are currently not implemented for Exec and Io activities.
176 Every kind of activities can be asynchronous:
178 - :ref:`s4u::CommPtr <API_s4u_Comm>` are created with
179 :cpp:func:`s4u::Mailbox::put_async() <simgrid::s4u::Mailbox::put_async>` and
180 :cpp:func:`s4u::Mailbox::get_async() <simgrid::s4u::Mailbox::get_async>`.
181 - :ref:`s4u::IoPtr <API_s4u_Io>` are created with
182 :cpp:func:`s4u::Storage::read_async() <simgrid::s4u::Storage::read_async>` and
183 :cpp:func:`s4u::Storage::write_async() <simgrid::s4u::Storage::write_async>`.
184 - :ref:`s4u::ExecPtr <API_s4u_Exec>` are created with
185 :cpp:func:`s4u::Host::exec_async() <simgrid::s4u::Host::exec_async>`.
186 - In the future, it will become possible to have asynchronous IPC
187 such as asynchronous mutex lock requests.
189 The following example shows how to have several concurrent
190 communications ongoing. First, you have to declare a vector in which
191 we will store the ongoing communications. It is also useful to have a
194 .. literalinclude:: ../../examples/s4u/async-waitall/s4u-async-waitall.cpp
196 :start-after: init-begin
197 :end-before: init-end
200 Then, you start all the communications that should occur concurrently with
201 :cpp:func:`s4u::Mailbox::put_async() <simgrid::s4u::Mailbox::put_async>`.
202 Finally, the actor waits for the completion of all of them at once
204 :cpp:func:`s4u::Comm::wait_all() <simgrid::s4u::Comm::wait_all>`.
206 .. literalinclude:: ../../examples/s4u/async-waitall/s4u-async-waitall.cpp
208 :start-after: put-begin
213 =====================
214 Activities Life cycle
215 =====================
217 Sometimes, you want to change the setting of an activity before it even starts.
219 .. todo:: write this section
224 For sake of simplicity, we use `RAII
225 <https://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization>`_
226 everywhere in S4U. This is an idiom where resources are automatically
227 managed through the context. Provided that you never manipulate
228 objects of type Foo directly but always FooPtr references (which are
229 defined as `boost::intrusive_ptr
230 <http://www.boost.org/doc/libs/1_61_0/libs/smart_ptr/intrusive_ptr.html>`_
231 <Foo>), you will never have to explicitely release the resource that
232 you use nor to free the memory of unused objects.
234 Here is a little example:
240 simgrid::s4u::MutexPtr mutex = simgrid::s4u::Mutex::create(); // Too bad we cannot use `new`
242 mutex->lock(); // use the mutex as a simple reference
246 } // The mutex gets automatically freed because the only existing reference gets out of scope
251 .. _API_s4u_Activity:
257 .. doxygenclass:: simgrid::s4u::Activity
268 .. doxygentypedef:: ActorPtr
270 .. doxygenclass:: simgrid::s4u::Actor
281 .. doxygentypedef:: BarrierPtr
283 .. doxygenclass:: simgrid::s4u::Barrier
294 .. doxygentypedef:: CommPtr
296 .. doxygenclass:: simgrid::s4u::Comm
301 .. _API_s4u_ConditionVariable:
303 ======================
304 s4u::ConditionVariable
305 ======================
307 .. doxygentypedef:: ConditionVariablePtr
309 .. doxygenclass:: simgrid::s4u::ConditionVariable
320 .. doxygenclass:: simgrid::s4u::Engine
331 .. doxygentypedef:: ExecPtr
333 .. doxygenclass:: simgrid::s4u::Exec
344 .. doxygenclass:: simgrid::s4u::Host
355 .. doxygentypedef:: IoPtr
357 .. doxygenclass:: simgrid::s4u::Io
368 .. doxygenclass:: simgrid::s4u::Link
379 .. doxygentypedef:: MailboxPtr
381 .. doxygenclass:: simgrid::s4u::Mailbox
392 .. doxygentypedef:: MutexPtr
394 .. doxygenclass:: simgrid::s4u::Mutex
405 .. doxygenclass:: simgrid::s4u::NetZone
410 .. _API_s4u_Semaphore:
416 .. doxygentypedef:: SemaphorePtr
418 .. doxygenclass:: simgrid::s4u::Semaphore
429 .. doxygenclass:: simgrid::s4u::Storage
434 .. _API_s4u_VirtualMachine:
440 .. doxygenclass:: simgrid::s4u::VirtualMachine
445 .. _API_s4u_this_actor:
447 =========================
448 namespace s4u::this_actor
449 =========================
452 .. doxygennamespace:: simgrid::s4u::this_actor