Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'dev/s4u_tuto_fixes' into 'master'
[simgrid.git] / docs / source / Tutorial_Algorithms.rst
index 72eb7f3..8adaa60 100644 (file)
@@ -364,14 +364,14 @@ was obtained with the Triva software.
 Using Docker
 ............
 
-The easiest way to take the tutorial is to use the dedicated Docker
-image. Once you `installed Docker itself
-<https://docs.docker.com/install/>`_, simply do the following:
+The easiest way to take the tutorial is to use the dedicated Docker image. 
+Once you `installed Docker itself <https://docs.docker.com/install/>`_, simply do the following:
 
 .. code-block:: console
 
    $ docker pull simgrid/tuto-s4u
-   $ docker run -it --rm --name simgrid --volume ~/simgrid-tutorial:/source/tutorial simgrid/tuto-s4u bash
+   $ mkdir ~/simgrid-tutorial
+   $ docker run --user $UID:$GID -it --rm --name simgrid --volume ~/simgrid-tutorial:/source/tutorial simgrid/tuto-s4u bash
 
 This will start a new container with all you need to take this
 tutorial, and create a ``simgrid-tutorial`` directory in your home on
@@ -390,16 +390,32 @@ All needed dependencies are already installed in this container
 optional in this tutorial, it is not installed to reduce the image
 size.
 
+The docker does not run as root, so that the files can easily be exchanged between within the container and the outer world.
+If you need to run a command as root within the container, simply type the following in another terminal to join the same container as root:
+
+.. code-block:: console
+
+   $ docker container ls
+   # This lists all containers running on your machine. For example:
+   #    CONTAINER ID   IMAGE            COMMAND   CREATED         STATUS         PORTS     NAMES
+   #    7e921b1b18a7   simgrid/stable   "bash"    7 minutes ago   Up 7 minutes             simgrid
+
+   $ docker exec --user root -it simgrid bash
+
 The code template is available under ``/source/simgrid-template-s4u.git``
 in the image. You should copy it to your working directory and
 recompile it when you first log in:
 
 .. code-block:: console
 
-   $ cp -r /source/simgrid-template-s4u.git/* /source/tutorial
-   $ cd /source/tutorial
-   $ cmake .
-   $ make
+   $ # Make sure the simgrid-tutorial directory can be read and written by the non-root user
+   $ sudo chown $UID:$GID ~/simgrid-tutorial
+   $ # Connect to the running container if needed
+   $ docker exec --user $UID:$GID -ti simgrid bash
+   $container) cp -r /source/simgrid-template-s4u.git/* /source/tutorial
+   $container) cd /source/tutorial
+   $container) cmake .
+   $container) make
 
 Using your Computer Natively
 ............................
@@ -465,6 +481,15 @@ Using your Computer Natively
       your :ref:`SimGrid installation <install>`.  On need, please refer to
       the :ref:`Troubleshooting your Project Setup <install_yours_troubleshooting>` section.
 
+.. warning::
+
+   If you use the stable version of Debian 11, Ubuntu 21.04 or Ubuntu 21.10, then you need the right version of this tutorial 
+   (add ``--branch simgrid-v3.25`` as below). These distributions only contain SimGrid v3.25 while the latest version of this
+   tutorial needs at least SimGrid v3.27.
+
+   .. code-block:: console
+
+      $ git clone --branch simgrid-v3.25 https://framagit.org/simgrid/simgrid-template-s4u.git
 
 For R analysis of the produced traces, you may want to install R
 and the `pajengr <https://github.com/schnorr/pajengr#installation/>`_ package.
@@ -493,6 +518,9 @@ Discovering the Provided Code
          $ make master-workers
          $ ./master-workers small_platform.xml master-workers_d.xml
 
+      If you get an error message complaining that ``simgrid::s4u::Mailbox::get()`` does not exist, 
+      then your version of SimGrid is too old for the version of the tutorial that you got. Check again previous section.
+
    .. group-tab:: Python
 
       Please execute the provided simulator as follows:
@@ -501,6 +529,9 @@ Discovering the Provided Code
 
          $ python master-workers.py small_platform.xml master-workers_d.xml
 
+      If you get an error stating that the simgrid module does not exist, you need to get a newer version of SimGrid. 
+      You may want to take the tutorial from the docker to get the newest version.
+
 For a more "fancy" output, you can use simgrid-colorizer.
 
 .. code-block:: console
@@ -563,7 +594,7 @@ It produces a ``Rplots.pdf`` with the following content:
 Lab 1: Simpler deployments
 --------------------------
 
-.. rst-class:: learning-goals
+.. rst-class:: compact-list
 
    **Learning goals:** 
 
@@ -647,7 +678,7 @@ for more details.
 Lab 2: Using the Whole Platform
 -------------------------------
 
-.. rst-class:: learning-goals
+.. rst-class:: compact-list
 
    **Learning goals:** 
 
@@ -683,35 +714,35 @@ Creating the workers from the master
 
       .. code-block:: cpp
 
-      void my_actor(int param1, double param2, std::string param3) {
-         ...
-      }
-      int main(int argc, char argv**) {
-         ...
-         simgrid::s4u::ActorPtr actor;
-         actor = simgrid::s4u::Actor::create("name", simgrid::s4u::Host::by_name("the_host"),
-                                             &my_actor, 42, 3.14, "thevalue");
-         ...
-      }
+         void my_actor(int param1, double param2, std::string param3) {
+            ...
+         }
+         int main(int argc, char argv**) {
+            ...
+            simgrid::s4u::ActorPtr actor;
+            actor = simgrid::s4u::Actor::create("name", simgrid::s4u::Host::by_name("the_host"),
+                                                &my_actor, 42, 3.14, "thevalue");
+            ...
+         }
 
    .. group-tab:: Python
 
       For that, the master needs to retrieve the list of hosts declared in
-      the platform with :py:func:`simgrid.Engine.get_all_hosts`.
-      Then, the master should start the worker actors with
-      :py:func:`simgrid.Actor.create`.
+      the platform with :py:func:`simgrid.Engine.get_all_hosts`. Since this method is not static, 
+      you may want to call it on the Engine instance, as in ``Engine.instance().get_all_hosts()``.
+      Then, the master should start the worker actors with :py:func:`simgrid.Actor.create`.
 
       ``Actor.create(name, host, func, params...)`` is a very flexible
       function. Its third parameter is the function that the actor should
       execute. This function can take any kind of parameter, provided that
-      you pass similar parameters to ``Actor?create()``. For example, you
+      you pass similar parameters to ``Actor.create()``. For example, you
       could have something like this:
 
-      .. code-block:: cpp
+      .. code-block:: python
 
-      def my_actor(param1, param2, param3):
-         ...
-      actor = simgrid.Actor.create("name", the_host, my_actor, 42, 3.14, "thevalue")
+         def my_actor(param1, param2, param3):
+            # your code comes here
+         actor = simgrid.Actor.create("name", the_host, my_actor, 42, 3.14, "thevalue")
 
 
 Master-Workers Communication
@@ -727,11 +758,22 @@ Since we want later to study concurrent applications, it is advised to
 use a mailbox name that is unique over the simulation even if there is
 more than one master.
 
-One possibility for that is to use the actor ID (aid) of each worker
-as a mailbox name. The master can retrieve the aid of the newly
-created actor with ``get_pid()`` while the actor itself can
-retrieve its own aid with ``this_actor::get_pid()``.
-The retrieved value is an ``aid_t``, which is an alias for ``long``.
+.. tabs::
+
+   .. group-tab:: C++
+
+      One possibility for that is to use the actor ID (aid) of each worker
+      as a mailbox name. The master can retrieve the aid of the newly
+      created actor with :cpp:func:`simgrid::s4u::Actor::get_pid()` while the actor itself can
+      retrieve its own aid with :cpp:func:`simgrid::s4u::this_actor::get_pid()`.
+      The retrieved value is an :cpp:type:`aid_t`, which is an alias for ``long``.
+
+   .. group-tab:: Python
+
+      One possibility for that is to use the actor ID of each worker
+      as a mailbox name. The master can retrieve the aid of the newly
+      created actor with :py:func:`simgrid.Actor.pid` while the actor itself can
+      retrieve its own aid with :py:func:`simgrid.this_actor.get_pid()`.
 
 Wrap up
 .......
@@ -754,7 +796,7 @@ separation of concerns between things of different nature.
 Lab 3: Fixed Experiment Duration
 --------------------------------
 
-.. rst-class:: learning-goals
+.. rst-class:: compact-list
 
    **Learning goals:** 
 
@@ -775,7 +817,7 @@ simulation. Instead, retrieve the time in the simulated world with
 
 You can still stop your workers with a specific task as previously,
 or you may kill them forcefully with :cpp:func:`simgrid::s4u::Actor::kill` (C++)
-:py:func:`simgrid.Actor.kill` (C++).
+:py:func:`simgrid.Actor.kill` (Python).
 
 Anyway, the new deployment `deployment3.xml` file should thus look
 like this:
@@ -787,8 +829,8 @@ Controlling the message verbosity
 .................................
 
 Not all messages are equally informative, so you probably want to
-change some of the *info* messages (C: :c:macro:`XBT_INFO`; Python: :py:func:`this_actor.info`) 
-into *debug* messages`(C: c:macro:`XBT_DEBUG`; Python: :py:func:`this_actor.debug`) so that they are
+change some of the *info* messages (C: :c:macro:`XBT_INFO`; Python: :py:func:`simgrid.this_actor.info`) 
+into *debug* messages`(C: :c:macro:`XBT_DEBUG`; Python: :py:func:`simgrid.this_actor.debug`) so that they are
 hidden by default. For example, you may want to use an *info* message once
 every 100 tasks and *debug* when sending all the other tasks. Or
 you could show only the total number of tasks processed by
@@ -801,22 +843,18 @@ default. You can still see the debug messages as follows:
 Lab 4: What-if analysis
 -----------------------
 
-.. rst-class:: learning-goals
+.. rst-class:: compact-list
 
    **Learning goals:** 
 
    * Change the platform characteristics during the simulation.
    * Explore other communication patterns.
 
-.. todo::
-
-   Some of the required functions are not implemented in Python yet. You can detect that if the method name is not a link to the documentation.
-
 Computational speed
 ...................
 
 Attach a profile to your hosts, so that their computational speed automatically vary over time, modeling an external load on these machines.
-This can be done with :cpp:func:`simgrid::s4u::Host::set_speed_profile` (C++) or :py:func:`simgrid.Host.set_speed_profile` (python). 
+This can be done with :cpp:func:`simgrid::s4u::Host::set_speed_profile` (C++) or :py:func:`simgrid.Host.set_speed_profile` (Python). 
 
 Make it so that one of the hosts get really really slow, and observe how your whole application performance decreases.
 This is because one slow host slows down the whole process. Instead of a round-robin dispatch push, 
@@ -840,10 +878,10 @@ Retrieve a link from its name with :cpp:func:`simgrid::s4u::Link::by_name()` (C+
 
 Retrieve all links in the platform with :cpp:func:`simgrid::s4u::Engine::get_all_links()` (C++) or :py:func:`simgrid.Engine.get_all_links()` (python).
 
-Retrieve the list of links from one host to another with :cpp:func:`simgrid::s4u::Host::route_to` (C++) or :cpp:func:`simgrid.Host.route_to` (python).
+Retrieve the list of links from one host to another with :cpp:func:`simgrid::s4u::Host::route_to` (C++) or :py:func:`simgrid.Host.route_to` (python).
 
 Modify the bandwidth of a given link with :cpp:func:`simgrid::s4u::Link::set_bandwidth` (C++) or :py:func:`simgrid.Link.set_bandwidth` (python).
-You can even have the bandwidth automatically vary over time with :cpp:func:`simgrid::s4u::Link::set_bandwidth_profile` (C++) or :py:func:`simgrid.Link.set_bandwidth_profile` (python). 
+You can even have the bandwidth automatically vary over time with :cpp:func:`simgrid::s4u::Link::set_bandwidth_profile` (C++) or :py:func:`simgrid.Link.set_bandwidth_profile` (python).
 
 Once implemented, you will notice that slow communications may still result in situations
 where one worker only works at a given point of time. To overcome that, your master needs 
@@ -867,7 +905,7 @@ Again, there is a nice example demoing this feature, :ref:`under platform-failur
 Lab 5: Competing Applications
 -----------------------------
 
-.. rst-class:: learning-goals
+.. rst-class:: compact-list
 
    **Learning goals:** 
 
@@ -888,12 +926,14 @@ will categorize the tasks.
 Instead of starting the execution in one function call only with
 ``this_actor::execute(cost)``, you need to
 create the execution activity, set its tracing category, start it 
-and wait for its completion, as follows:
+and wait for its completion, as follows.
 
 .. tabs::
 
    .. group-tab:: C++
 
+      Use :cpp:func:`simgrid::s4u::Exec::set_tracing_category` to change the category of an execution.
+
       .. code-block:: cpp
 
          simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(compute_cost);
@@ -909,11 +949,13 @@ and wait for its completion, as follows:
 
    .. group-tab:: Python
 
+      Use :py:func:`simgrid.Exec.set_tracing_category` to change the category of an execution.
+
       .. code-block:: python
 
          exec = simgrid:.this_actor.exec_init(compute_cost)
          exec.set_tracing_category(category)
-         // exec.start() is optional here as wait() starts the activity on need
+         # exec.start() is optional here as wait() starts the activity on need
          exec->wait()
 
       You can shorten this code as follows: