Starting and Stopping Actors
----------------------------
+.. _s4u_ex_actors_create:
+
Creating actors
^^^^^^^^^^^^^^^
This example shows how to attach a callback to:
- the end of a specific actor: :cpp:func:`simgrid::s4u::Actor::on_exit()`
- - the end of any actor: :cpp:member:`simgrid::s4u::Actor::on_termination()`
- - the destruction of any actor: :cpp:member:`simgrid::s4u::Actor::on_destruction()`
+ - the end of any actor: :cpp:func:`simgrid::s4u::Actor::on_termination_cb`
+ - the destruction of any actor: :cpp:func:`simgrid::s4u::Actor::on_destruction_cb`
.. example-tab:: examples/c/actor-exiting/actor-exiting.c
.. example-tab:: examples/python/actor-kill/actor-kill.py
- See also :py:func:`simgrid.Actor.kill`, :py:func:`simgrid.Actor.kill_all`, :py:func:`simgrid.this_actor.exit`,
+ See also :py:func:`simgrid.Actor.kill()`, :py:func:`simgrid.Actor.kill_all()`, :py:func:`simgrid.this_actor.exit()`,
:py:func:`simgrid.this_actor.on_exit`.
.. example-tab:: examples/c/actor-kill/actor-kill.c
.. example-tab:: examples/python/actor-migrate/actor-migrate.py
- See also :py:func:`simgrid.this_actor.set_host()` and :py:func:`simgrid.Actor.set_host()`.
+ See also :py:attr:`simgrid.Actor.host`.
.. example-tab:: examples/c/actor-migrate/actor-migrate.c
.. example-tab:: examples/cpp/comm-pingpong/s4u-comm-pingpong.cpp
+ .. example-tab:: examples/python/comm-pingpong/comm-pingpong.py
+
.. example-tab:: examples/c/comm-pingpong/comm-pingpong.c
See also :cpp:func:`simgrid::s4u::Activity::wait_until()` and :cpp:func:`simgrid::s4u::Comm::wait_for()`.
+ .. example-tab:: examples/python/comm-waituntil/comm-waituntil.py
+
+ See also :py:func:`simgrid.Comm.wait_until()`
+
Suspending communications
^^^^^^^^^^^^^^^^^^^^^^^^^
:cpp:func:`simgrid::s4u::Activity::resume()` and
:cpp:func:`simgrid::s4u::Activity::is_suspended()`.
+ .. example-tab:: examples/python/comm-suspend/comm-suspend.py
+
+ See also :py:func:`simgrid.Comm::suspend()` and
+ :py:func:`simgrid.Comm.resume()`.
+
Waiting for all communications in a set
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Waiting for the first completed communication in a set
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-The ``wait_any()`` function is useful when you want to block until one activity of the set completes, no matter which terminates first.
+The ``wait_any()`` blocks until one activity of the set completes, no matter which terminates first.
.. tabs::
See also :cpp:func:`sg_comm_wait_any`.
+Testing whether at least one communication completed
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The ``test_any()`` returns whether at least one activity of the set has completed, or -1.
+
+.. tabs::
+
+ .. example-tab:: examples/cpp/comm-testany/s4u-comm-testany.cpp
+
+ See also :cpp:func:`simgrid::s4u::Comm::test_any()`.
+
+ .. example-tab:: examples/python/comm-testany/comm-testany.py
+
+ See also :py:func:`simgrid.Comm.test_any()`.
+
.. _s4u_ex_execution:
Executions on the CPU
.. example-tab:: examples/python/exec-async/exec-async.py
See also :py:func:`simgrid.this_actor.exec_init()`,
- :py:func:`simgrid.Activity.start()`,
- :py:func:`simgrid.Activity.wait()`,
- :py:func:`simgrid.Activity.get_remaining()`,
- :py:func:`simgrid.Exec.get_remaining_ratio()`,
+ :py:func:`simgrid.Exec.start()`,
+ :py:func:`simgrid.Exec.wait()`,
+ :py:attr:`simgrid.Exec.remaining`,
+ :py:attr:`simgrid.Exec.remaining_ratio`,
:py:func:`simgrid.this_actor.exec_async()` and
- :py:func:`simgrid.Activity.cancel()`.
+ :py:func:`simgrid.Exec.cancel()`.
.. example-tab:: examples/c/exec-async/exec-async.c
.. example-tab:: examples/python/exec-remote/exec-remote.py
- See also :py:func:`simgrid.Exec.set_host()`.
+ See also :py:attr:`simgrid.Exec.host`.
.. example-tab:: examples/c/exec-remote/exec-remote.c
See also :cpp:func:`sg_exec_set_host()`.
+.. _s4u_ex_ptasks:
+
Parallel executions
^^^^^^^^^^^^^^^^^^^
See also :cpp:func:`simgrid::s4u::this_actor::parallel_execute()`.
+ .. example-tab:: examples/python/exec-ptask/exec-ptask.py
+
+ See also :ref:`simgrid.this_actor.parallel_execute()`
+
DVFS and pstates
^^^^^^^^^^^^^^^^
.. example-tab:: examples/python/exec-dvfs/exec-dvfs.py
- See also :py:func:`Host.get_pstate_speed` and :py:func:`Host.set_pstate`.
+ See also :py:func:`simgrid.Host.pstate_speed()` and :py:attr:`simgrid.Host.pstate`.
.. example-tab:: examples/platforms/energy_platform.xml
.. example-tab:: examples/cpp/synchro-barrier/s4u-synchro-barrier.cpp
+ .. example-tab:: examples/python/synchro-barrier/synchro-barrier.py
+
Condition variable: basic usage
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. example-tab:: examples/cpp/synchro-mutex/s4u-synchro-mutex.cpp
+ .. example-tab:: examples/python/synchro-mutex/synchro-mutex.py
+
Semaphore
^^^^^^^^^
.. example-tab:: examples/cpp/synchro-semaphore/s4u-synchro-semaphore.cpp
+ .. example-tab:: examples/python/synchro-semaphore/synchro-semaphore.py
+
.. example-tab:: examples/c/synchro-semaphore/synchro-semaphore.c
=============================
.. example-tab:: examples/c/platform-failures/platform-failures.c
+ .. example-tab:: examples/python/platform-failures/platform-failures.py
+
.. group-tab:: XML
.. showfile:: examples/platforms/small_platform_failures.xml
.. example-tab:: examples/cpp/platform-profile/s4u-platform-profile.cpp
+ .. example-tab:: examples/python/platform-profile/platform-profile.py
+
.. group-tab:: XML
.. showfile:: examples/platforms/small_platform_profile.xml
.. example-tab:: examples/c/energy-exec/energy-exec.c
+Virtual machines consumption
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+This example is very similar to the previous one, adding VMs to the picture.
+
+.. tabs::
+
+ .. example-tab:: examples/cpp/energy-vm/s4u-energy-vm.cpp
+
+ .. example-tab:: examples/c/energy-vm/energy-vm.c
+
Wired network energy consumption
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Master Workers
^^^^^^^^^^^^^^
-Another good old example, where one Master acto$ has a bunch of tasks to dispatch to a set of several Worker actors.
+Another good old example, where one Master actor has a bunch of tasks to dispatch to a set of several Worker actors.
This example is used in the :ref:`SimGrid tutorial <usecase_simalgo>`.
.. tabs::
.. showfile:: examples/c/app-masterworker/app-masterworker.c
:language: cpp
+ .. example-tab:: examples/python/app-masterworkers/app-masterworkers.py
+
Data diffusion
--------------
.. showfile:: examples/c/dht-kademlia/node.c
:language: cpp
+Pastry
+^^^^^^
+
+Yet another well-known DHT protocol.
+
+.. tabs::
+
+ .. example-tab:: examples/c/dht-pastry/dht-pastry.c
+
.. _s4u_ex_clouds:
Simulating Clouds
mode is rather experimental in SimGrid (as of v3.25). We are working on it :)
Failing assert
-^^^^^^^^^^^^^^
+--------------
In this example, two actors send some data to a central server, which asserts that the messages are always received in the same order.
This is wrong, and the model-checker correctly finds a counter-example to that assertion.