9 <object id="TOC" data="graphical-toc.svg" width="100%" type="image/svg+xml"></object>
11 window.onload=function() { // Wait for the SVG to be loaded before changing it
12 var elem=document.querySelector("#TOC").contentDocument.getElementById("S4UBox")
13 elem.style="opacity:0.93999999;fill:#ff0000;fill-opacity:0.1";
19 The S4U interface (SimGrid for you) mixes the full power of SimGrid
20 with the full power of C++. This is the preferred interface to describe
21 abstract algorithms in the domains of Cloud, P2P, HPC, IoT, and similar
28 A typical SimGrid simulation is composed of several |Actors|_, that
29 execute user-provided functions. The actors have to explicitly use the
30 S4U interface to express their
31 :ref:`computation <exhale_class_classsimgrid_1_1s4u_1_1Exec>`,
32 :ref:`communication <exhale_class_classsimgrid_1_1s4u_1_1Comm>`,
33 :ref:`disk usage <exhale_class_classsimgrid_1_1s4u_1_1Io>`,
34 and other |Activities|_, so that they get reflected within the
35 simulator. These activities take place on resources such as |Hosts|_,
36 |Links|_ and |Storages|_. SimGrid predicts the time taken by each
37 activity and orchestrates the actors accordingly, waiting for the
38 completion of these activities.
41 When **communicating**, data is not directly sent to other actors but
42 posted onto a |Mailbox|_ that serves as a rendez-vous point between
43 communicating actors. This means that you don't need to know who you
44 are talking to, you just put your communication `Put` request in a
45 mailbox, and it will be matched with a complementary `Get`
46 request. Alternatively, actors can interact through **classical
47 synchronization mechanisms** such as |Barrier|_, |Semaphore|_,
48 |Mutex|_ and |ConditionVariable|_.
50 Each actor is located on a simulated |Host|_. Each host is located
51 itself in a |NetZone|_, that knows the networking path between one
52 resource to another. Each NetZone is included in another one, forming
53 a tree of NetZones which root zone contains the whole platform.
55 The :ref:`simgrid::s4u::this_actor
56 <namespace_simgrid__s4u__this_actor>` namespace provides many helper
57 functions to simplify the code of actors.
61 - :ref:`class s4u::Actor <exhale_class_classsimgrid_1_1s4u_1_1Actor>`:
62 Active entities executing your application.
63 - :ref:`class s4u::Engine <exhale_class_classsimgrid_1_1s4u_1_1Engine>`
64 Simulation engine (singleton).
65 - :ref:`class s4u::Mailbox <exhale_class_classsimgrid_1_1s4u_1_1Mailbox>`
66 Communication rendez-vous.
68 - **Platform Elements**
70 - :ref:`class s4u::Host <exhale_class_classsimgrid_1_1s4u_1_1Host>`:
71 Actor location, providing computational power.
72 - :ref:`class s4u::Link <exhale_class_classsimgrid_1_1s4u_1_1Link>`
73 Interconnecting hosts.
74 - :ref:`class s4u::NetZone <exhale_class_classsimgrid_1_1s4u_1_1NetZone>`:
75 Sub-region of the platform, containing resources (Hosts, Links, etc).
76 - :ref:`class s4u::Storage <exhale_class_classsimgrid_1_1s4u_1_1Storage>`
77 Resource on which actors can write and read data.
78 - :ref:`class s4u::VirtualMachine <exhale_class_classsimgrid_1_1s4u_1_1VirtualMachine>`:
79 Execution containers that can be moved between Hosts.
81 - **Activities** (:ref:`class s4u::Activity <exhale_class_classsimgrid_1_1s4u_1_1Activity>`):
82 The things that actors can do on resources
84 - :ref:`class s4u::Comm <exhale_class_classsimgrid_1_1s4u_1_1Comm>`
85 Communication activity, started on Mailboxes and consuming links.
86 - :ref:`class s4u::Exec <exhale_class_classsimgrid_1_1s4u_1_1Exec>`
87 Computation activity, started on Host and consuming CPU resources.
88 - :ref:`class s4u::Io <exhale_class_classsimgrid_1_1s4u_1_1Io>`
89 I/O activity, started on and consumming Storages.
91 - **Synchronization Mechanisms**: Classical IPC that actors can use
93 - :ref:`class s4u::Barrier <exhale_class_classsimgrid_1_1s4u_1_1Barrier>`
94 - :ref:`class s4u::ConditionVariable <exhale_class_classsimgrid_1_1s4u_1_1ConditionVariable>`
95 - :ref:`class s4u::Mutex <exhale_class_classsimgrid_1_1s4u_1_1Mutex>`
96 - :ref:`class s4u::Semaphore <exhale_class_classsimgrid_1_1s4u_1_1Semaphore>`
99 .. |Actors| replace:: **Actors**
100 .. _Actors: api/classsimgrid_1_1s4u_1_1Actor.html
102 .. |Activities| replace:: **Activities**
103 .. _Activities: api/classsimgrid_1_1s4u_1_1Activity.html
105 .. |Hosts| replace:: **Hosts**
106 .. _Hosts: api/classsimgrid_1_1s4u_1_1Host.html
108 .. |Links| replace:: **Links**
109 .. _Links: api/classsimgrid_1_1s4u_1_1Link.html
111 .. |Storages| replace:: **Storages**
112 .. _Storages: api/classsimgrid_1_1s4u_1_1Storage.html
114 .. |VirtualMachines| replace:: **VirtualMachines**
115 .. _VirtualMachines: api/classsimgrid_1_1s4u_1_1VirtualMachine.html
117 .. |Host| replace:: **Host**
118 .. _Host: api/classsimgrid_1_1s4u_1_1Host.html
120 .. |Mailbox| replace:: **Mailbox**
121 .. _Mailbox: api/classsimgrid_1_1s4u_1_1Mailbox.html
123 .. |NetZone| replace:: **NetZone**
124 .. _NetZone: api/classsimgrid_1_1s4u_1_1NetZone.html
126 .. |Barrier| replace:: **Barrier**
127 .. _Barrier: api/classsimgrid_1_1s4u_1_1Barrier.html
129 .. |ConditionVariable| replace:: **ConditionVariable**
130 .. _ConditionVariable: api/classsimgrid_1_1s4u_1_1ConditionVariable.html
132 .. |Mutex| replace:: **Mutex**
133 .. _Mutex: api/classsimgrid_1_1s4u_1_1Mutex.html
137 .. include:: ../../examples/s4u/README.rst
143 Activities represent the actions that consume a resource, such as a
144 :ref:`s4u::Comm <exhale_class_classsimgrid_1_1s4u_1_1Comm>` that
145 consumes the *transmiting power* of :ref:`s4u::Link
146 <exhale_class_classsimgrid_1_1s4u_1_1Link>` resources.
148 .......................
149 Asynchronous Activities
150 .......................
152 Every activity can be either **blocking** or **asynchronous**. For
153 example, :cpp:func:`s4u::Mailbox::put() <simgrid::s4u::Mailbox::put>`
154 and :cpp:func:`s4u::Mailbox::get() <simgrid::s4u::Mailbox::get>`
155 create blocking communications: the actor is blocked until the
156 completion of that communication. Asynchronous communications do not
157 block the actor during their execution but progress on their own.
159 Once your asynchronous activity is started, you can test for its
160 completion using :cpp:func:`s4u::Activity::test() <simgrid::s4u::Activity::test>`.
161 This function returns ``true`` if the activity completed already.
162 You can also use :cpp:func:`s4u::Activity::wait() <simgrid::s4u::Activity::wait>`
163 to block until the completion of the activity. To wait for at most a given amount of time,
164 use :cpp:func:`s4u::Activity::wait_for() <simgrid::s4u::Activity::wait_for>`.
165 Finally, to wait at most until a specified time limit, use
166 :cpp:func:`s4u::Activity::wait_until() <simgrid::s4u::Activity::wait_until>`.
170 wait_for and wait_until are currently not implemented for Exec and Io activities.
172 Every kind of activities can be asynchronous:
174 - :ref:`s4u::CommPtr <exhale_class_classsimgrid_1_1s4u_1_1Comm>` are created with
175 :cpp:func:`s4u::Mailbox::put_async() <simgrid::s4u::Mailbox::put_async>` and
176 :cpp:func:`s4u::Mailbox::get_async() <simgrid::s4u::Mailbox::get_async>`.
177 - :ref:`s4u::IoPtr <exhale_class_classsimgrid_1_1s4u_1_1Io>` are created with
178 :cpp:func:`s4u::Storage::read_async() <simgrid::s4u::Storage::read_async>` and
179 :cpp:func:`s4u::Storage::write_async() <simgrid::s4u::Storage::write_async>`.
180 - :ref:`s4u::ExecPtr <exhale_class_classsimgrid_1_1s4u_1_1Exec>` are created with
181 :cpp:func:`s4u::Host::exec_async() <simgrid::s4u::Host::exec_async>`.
182 - In the future, it will become possible to have asynchronous IPC
183 such as asynchronous mutex lock requests.
185 The following example shows how to have several concurrent
186 communications ongoing. First, you have to declare a vector in which
187 we will store the ongoing communications. It is also useful to have a
190 .. literalinclude:: ../../examples/s4u/async-waitall/s4u-async-waitall.cpp
192 :start-after: init-begin
193 :end-before: init-end
196 Then, you start all the communications that should occur concurrently with
197 :cpp:func:`s4u::Mailbox::put_async() <simgrid::s4u::Mailbox::put_async>`.
198 Finally, the actor waits for the completion of all of them at once
200 :cpp:func:`s4u::Comm::wait_all() <simgrid::s4u::Comm::wait_all>`.
202 .. literalinclude:: ../../examples/s4u/async-waitall/s4u-async-waitall.cpp
204 :start-after: put-begin
209 .....................
210 Activities Life cycle
211 .....................
213 Sometimes, you want to change the setting of an activity before it even starts.
215 .. todo:: fill this section