]> AND Public Git Repository - simgrid.git/blobdiff - docs/source/tuto_smpi.rst
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
another thing that SMPI cannot do yet
[simgrid.git] / docs / source / tuto_smpi.rst
index 3af02291286c43f8193e28ccbd845b882a02a515..17eec10f9645fa0f0fbe4bd40cafc82a2d87602a 100644 (file)
@@ -3,6 +3,11 @@
 Simulating MPI Applications
 ===========================
 
 Simulating MPI Applications
 ===========================
 
+.. warning:: This document is still in early stage. You can try to
+   take this tutorial, but should not be surprised if things fall short.
+   It will be completed for the next release, v3.22, released by the end
+   of 2018.
+
 Discover SMPI
 -------------
 
 Discover SMPI
 -------------
 
@@ -24,9 +29,9 @@ use SimGrid for their integration and performance testing.
 
 MPI 2.2 is already partially covered: over 160 primitives are
 supported. Some parts of the standard are still missing: MPI-IO, MPI3
 
 MPI 2.2 is already partially covered: over 160 primitives are
 supported. Some parts of the standard are still missing: MPI-IO, MPI3
-collectives, spawning ranks, and some others. If one of the functions
-you use is still missing, please drop us an email. We may find the
-time to implement it for you.
+collectives, spawning ranks, inter-communicators, and some others. If
+one of the functions you use is still missing, please drop us an
+email. We may find the time to implement it for you.
 
 Multi-threading support is very limited in SMPI. Only funneled
 applications are supported: at most one thread per rank can issue any
 
 Multi-threading support is very limited in SMPI. Only funneled
 applications are supported: at most one thread per rank can issue any
@@ -49,7 +54,7 @@ To start using SMPI, you just need to compile your application with
 ``mpiff``, or with ``smpicxx`` instead of ``mpicxx``. Then, the only
 difference between the classical ``mpirun`` and the new ``smpirun`` is
 that it requires a new parameter ``-platform`` with a file describing
 ``mpiff``, or with ``smpicxx`` instead of ``mpicxx``. Then, the only
 difference between the classical ``mpirun`` and the new ``smpirun`` is
 that it requires a new parameter ``-platform`` with a file describing
-the virtual platform on which your application shall run.
+the simulated platform on which your application shall run.
 
 Internally, all ranks of your application are executed as threads of a
 single unix process. That's not a problem if your application has
 
 Internally, all ranks of your application are executed as threads of a
 single unix process. That's not a problem if your application has
@@ -68,7 +73,7 @@ Describing Your Platform
 ------------------------
 
 As a SMPI user, you are supposed to provide a description of your
 ------------------------
 
 As a SMPI user, you are supposed to provide a description of your
-virtual platform, that is mostly a set of simulated hosts and network
+simulated platform, that is mostly a set of simulated hosts and network
 links with some performance characteristics. SimGrid provides a plenty
 of :ref:`documentation <platform>` and examples (in the
 `examples/platforms <https://framagit.org/simgrid/simgrid/tree/master/examples/platforms>`_
 links with some performance characteristics. SimGrid provides a plenty
 of :ref:`documentation <platform>` and examples (in the
 `examples/platforms <https://framagit.org/simgrid/simgrid/tree/master/examples/platforms>`_
@@ -110,8 +115,8 @@ concurrently at full speed. For instance:
    :lines: 1-3,18-
 
 One specifies a name prefix and suffix for each host, and then give an
    :lines: 1-3,18-
 
 One specifies a name prefix and suffix for each host, and then give an
-integer range. In the example the cluster contains 262145 hosts (!),
-named ``host-0.simgrid.org`` to ``host-262144.simgrid.org``. All hosts
+integer range. In the example the cluster contains 65535 hosts (!),
+named ``node-0.simgrid.org`` to ``node-65534.simgrid.org``. All hosts
 have the same power (1 Gflop/sec) and are connected to the switch via
 links with same bandwidth (125 MBytes/sec) and latency (50
 microseconds).
 have the same power (1 Gflop/sec) and are connected to the switch via
 links with same bandwidth (125 MBytes/sec) and latency (50
 microseconds).
@@ -137,9 +142,9 @@ The only differences with the crossbar cluster above are the ``bb_bw``
 and ``bb_lat`` attributes that specify the backbone characteristics
 (here, a 500 microseconds latency and a 2.25 GByte/sec
 bandwidth). This link is used for every communication within the
 and ``bb_lat`` attributes that specify the backbone characteristics
 (here, a 500 microseconds latency and a 2.25 GByte/sec
 bandwidth). This link is used for every communication within the
-cluster. The route from ``node-0.acme.org`` to ``node-1.acme.org``
-counts 3 links: the private link of ``node-0.acme.org``, the backbone
-and the private link of ``node-1.acme.org``.
+cluster. The route from ``node-0.simgrid.org`` to ``node-1.simgrid.org``
+counts 3 links: the private link of ``node-0.simgrid.org``, the backbone
+and the private link of ``node-1.simgrid.org``.
           
 .. todo::
 
           
 .. todo::
 
@@ -209,15 +214,28 @@ Dragonfly Cluster
 This topology was introduced to further reduce the amount of links
 while maintaining a high bandwidth for local communications. To model
 this in SimGrid, pass a ``topology="DRAGONFLY"`` attribute to your
 This topology was introduced to further reduce the amount of links
 while maintaining a high bandwidth for local communications. To model
 this in SimGrid, pass a ``topology="DRAGONFLY"`` attribute to your
-cluster.
+cluster. It's based on the implementation of the topology used on 
+Cray XC systems, described in paper
+`Cray Cascade: A scalable HPC system based on a Dragonfly network <https://dl.acm.org/citation.cfm?id=2389136>`_.
+
+System description follows the format ``topo_parameters=#groups;#chassis;#routers;#nodes``
+For example, ``3,4 ; 3,2 ; 3,1 ; 2``:
+
+- ``3,4``: There are 3 groups with 4 links between each (blue level).
+  Links to nth group are attached to the nth router of the group 
+  on our implementation.
+- ``3,2``: In each group, there are 3 chassis with 2 links between each nth router
+  of each group (black level)
+- ``3,1``: In each chassis, 3 routers are connected together with a single link
+  (green level)
+- ``2``: Each router has two nodes attached (single link) 
+
+.. image:: ../../examples/platforms/cluster_dragonfly.svg
+   :align: center
 
 .. literalinclude:: ../../examples/platforms/cluster_dragonfly.xml
    :language: xml
 
 
 .. literalinclude:: ../../examples/platforms/cluster_dragonfly.xml
    :language: xml
 
-.. todo::
-
-   Add the image, and the documuentation of the topo_parameters.
-
 Final Word
 ..........
 
 Final Word
 ..........
 
@@ -246,33 +264,35 @@ image. Once you `installed Docker itself
 .. code-block:: shell
 
    docker pull simgrid/tuto-smpi
 .. code-block:: shell
 
    docker pull simgrid/tuto-smpi
-   docker run -it --rm --name simgrid --volume ~/smpi-tutorial:/src/tutorial simgrid/tuto-smpi bash
+   docker run -it --rm --name simgrid --volume ~/smpi-tutorial:/source/tutorial simgrid/tuto-smpi bash
 
 This will start a new container with all you need to take this
 tutorial, and create a ``smpi-tutorial`` directory in your home on
 
 This will start a new container with all you need to take this
 tutorial, and create a ``smpi-tutorial`` directory in your home on
-your host machine that will be visible as ``/src/tutorial`` within the
+your host machine that will be visible as ``/source/tutorial`` within the
 container.  You can then edit the files you want with your favorite
 editor in ``~/smpi-tutorial``, and compile them within the
 container to enjoy the provided dependencies.
 
 .. warning::
 
 container.  You can then edit the files you want with your favorite
 editor in ``~/smpi-tutorial``, and compile them within the
 container to enjoy the provided dependencies.
 
 .. warning::
 
-   Any change to the container out of ``/src/tutorial`` will be lost
+   Any change to the container out of ``/source/tutorial`` will be lost
    when you log out of the container, so don't edit the other files!
 
 All needed dependencies are already installed in this container
    when you log out of the container, so don't edit the other files!
 
 All needed dependencies are already installed in this container
-(SimGrid, a C/C++ compiler, a Fortran compiler, make, pajeng and
-R). Vite being only optional in this tutorial, it is not installed to
-reduce the image size.
+(SimGrid, the C/C++/Fortran compilers, make, pajeng and R). Vite being
+only optional in this tutorial, it is not installed to reduce the
+image size. 
 
 
-The code template is available under ``/src/simgrid-template-smpi`` in
-the image. You should copy it to your working directory when you first
-log in:
+The container also include the example platform files from the
+previous section as well as the source code of the NAS Parallel
+Benchmarks. These files are available under
+``/source/simgrid-template-smpi`` in the image. You should copy it to
+your working directory when you first log in:
 
 .. code-block:: shell
 
 
 .. code-block:: shell
 
-   cp -r /src/simgrid-template-smpi/* /src/tutorial
-   cd /src/tutorial
+   cp -r /source/simgrid-template-smpi/* /source/tutorial
+   cd /source/tutorial
 
 Using your Computer Natively
 ............................
 
 Using your Computer Natively
 ............................
@@ -288,23 +308,205 @@ Debian and Ubuntu for example, you can get them as follows:
 
    sudo apt install simgrid pajeng make gcc g++ gfortran vite
 
 
    sudo apt install simgrid pajeng make gcc g++ gfortran vite
 
-An initial version of the source code is provided on framagit. This
-template compiles with cmake. If SimGrid is correctly installed, you
-should be able to clone the `repository
-<https://framagit.org/simgrid/simgrid-template-smpi>`_ and recompile
-everything as follows:
+To take this tutorial, you will also need the platform files from the
+previous section as well as the source code of the NAS Parallel
+Benchmarks. Just  clone `this repository
+<https://framagit.org/simgrid/simgrid-template-smpi>`_  to get them all:
 
 .. code-block:: shell
 
    git clone git@framagit.org:simgrid/simgrid-template-smpi.git
    cd simgrid-template-smpi/
 
 .. code-block:: shell
 
    git clone git@framagit.org:simgrid/simgrid-template-smpi.git
    cd simgrid-template-smpi/
-   cmake .
-   make
 
 If you struggle with the compilation, then you should double check
 your :ref:`SimGrid installation <install>`.  On need, please refer to
 the :ref:`Troubleshooting your Project Setup
 <install_yours_troubleshooting>` section.
 
 
 If you struggle with the compilation, then you should double check
 your :ref:`SimGrid installation <install>`.  On need, please refer to
 the :ref:`Troubleshooting your Project Setup
 <install_yours_troubleshooting>` section.
 
+Lab 0: Hello World
+------------------
+
+It is time to simulate your first MPI program. Use the simplistic
+example `roundtrip.c
+<https://framagit.org/simgrid/simgrid-template-smpi/raw/master/roundtrip.c?inline=false>`_
+that comes with the template.
+
+.. literalinclude:: /tuto_smpi/roundtrip.c
+   :language: c
+
+Compiling and Executing
+.......................
+             
+Compiling the program is straightforward (double check your
+:ref:`SimGrid installation <install>` if you get an error message):
+
+
+.. code-block:: shell
+               
+  $ smpicc -O3 roundtrip.c -o roundtrip
+
+
+Once compiled, you can simulate the execution of this program on 16
+nodes from the ``cluster_crossbar.xml`` platform as follows:
+
+.. code-block:: shell
+
+   $ smpirun -np 16 -platform cluster_crossbar.xml -hostfile cluster_hostfile ./roundtrip
+
+- The ``-np 16`` option, just like in regular MPI, specifies the
+  number of MPI processes to use. 
+- The ``-hostfile cluster_hostfile`` option, just like in regular
+  MPI, specifies the host file. If you omit this option, ``smpirun``
+  will deploy the application on the first machines of your platform.
+- The ``-platform cluster_crossbar.xml`` option, **which doesn't exist
+  in regular MPI**, specifies the platform configuration to be
+  simulated. 
+- At the end of the line, one finds the executable name and
+  command-line arguments (if any -- roundtrip does not expect any arguments).
+
+Feel free to tweak the content of the XML platform file and the
+program to see the effect on the simulated execution time. It may be
+easier to compare the executions with the extra option
+``--cfg=smpi/display_timing:yes``.  Note that the simulation accounts
+for realistic network protocol effects and MPI implementation
+effects. As a result, you may see "unexpected behavior" like in the
+real world (e.g., sending a message 1 byte larger may lead to
+significant higher execution time).
+
+Lab 1: Visualizing LU
+---------------------
+
+We will now simulate a larger application: the LU benchmark of the NAS
+suite. The version provided in the code template was modified to
+compile with SMPI instead of the regular MPI. Compare the difference
+between the original ``config/make.def.template`` and the
+``config/make.def`` that was adapted to SMPI. We use ``smpiff`` and
+``smpicc`` as compilers, and don't pass any additional library.
+
+Now compile and execute the LU benchmark, class S (i.e., for `small
+data size
+<https://www.nas.nasa.gov/publications/npb_problem_sizes.html>`_) with
+4 nodes.
+
+.. code-block:: shell
+
+   $ make lu NPROCS=4 CLASS=S
+   (compilation logs)
+   $ smpirun -np 4 -platform ../cluster_backbone.xml bin/lu.S.4
+   (execution logs)
+
+To get a better understanding of what is going on, activate the
+vizualization tracing, and convert the produced trace for later
+use:
+
+.. code-block:: shell
+
+   smpirun -np 4 -platform ../cluster_backbone.xml -trace --cfg=tracing/filename:lu.S.4.trace bin/lu.S.4
+   pj_dump --ignore-incomplete-links lu.S.4.trace | grep State > lu.S.4.state.csv
+
+You can then produce a Gantt Chart with the following R chunk. You can
+either copy/paste it in a R session, or `turn it into a Rscript executable
+<https://swcarpentry.github.io/r-novice-inflammation/05-cmdline/>`_ to
+run it again and again.
+
+.. code-block:: R
+
+   library(ggplot2)
+
+   # Read the data
+   df_state = read.csv("lu.S.4.state.csv", header=F, strip.white=T)
+   names(df_state) = c("Type", "Rank", "Container", "Start", "End", "Duration", "Level", "State");
+   df_state = df_state[!(names(df_state) %in% c("Type","Container","Level"))]
+   df_state$Rank = as.numeric(gsub("rank-","",df_state$Rank))
+
+   # Draw the Gantt Chart
+   gc = ggplot(data=df_state) + geom_rect(aes(xmin=Start, xmax=End, ymin=Rank, ymax=Rank+1,fill=State))
+
+   # Produce the output
+   plot(gc)
+   dev.off()
+
+This produces a file called ``Rplots.pdf`` with the following
+content. You can find more visualization examples `online
+<http://simgrid.gforge.inria.fr/contrib/R_visualization.html>`_.
+
+.. image:: /tuto_smpi/img/lu.S.4.png
+   :align: center
+
+Lab 2: Tracing and Replay of LU
+-------------------------------
+
+Now compile and execute the LU benchmark, class A, with 32 nodes.
+
+.. code-block:: shell
+
+   $ make lu NPROCS=32 CLASS=A
+
+This takes several minutes to to simulate, because all code from all
+processes has to be really executed, and everything is serialized.
+
+SMPI provides several methods to speed things up. One of them is to
+capture a time independent trace of the running application, and
+replay it on a different platform with the same amount of nodes. The
+replay is much faster than live simulation, as the computations are
+skipped (the application must be network-dependent for this to work).
+
+You can even generate the trace during as live simulation, as follows:
+
+.. code-block:: shell
+
+   $ smpirun -trace-ti --cfg=tracing/filename:LU.A.32 -np 32 -platform ../cluster_backbone.xml bin/lu.A.32 
+
+The produced trace is composed of a file ``LU.A.32`` and a folder
+``LU.A.32_files``. To replay this with SMPI, you need to first compile
+the provided ``smpi_replay.cpp`` file, that comes from
+`simgrid/examples/smpi/replay
+<https://framagit.org/simgrid/simgrid/tree/master/examples/smpi/replay>`_.
+
+.. code-block:: shell
+
+   $ smpicxx ../replay.cpp -O3 -o ../smpi_replay
+
+Afterward, you can replay your trace in SMPI as follows:
+
+   $ smpirun -np 32 -platform ../cluster_torus.xml -ext smpi_replay ../smpi_replay LU.A.32
+
+All the outputs are gone, as the application is not really simulated
+here. Its trace is simply replayed. But if you visualize the live
+simulation and the replay, you will see that the behavior is
+unchanged. The simulation does not run much faster on this very
+example, but this becomes very interesting when your application
+is computationally hungry.
+
+.. todo:: smpi_replay should be installed by SimGrid, and smpirun interface could be simplified here.
+
+Lab 3: Execution Sampling on EP
+-------------------------------
+
+The second method to speed up simulations is to sample the computation
+parts in the code.  This means that the person doing the simulation
+needs to know the application and identify parts that are compute
+intensive and take time, while being regular enough not to ruin
+simulation accuracy. Furthermore there should not be any MPI calls
+inside such parts of the code.
+
+Use the EP benchmark, class B, 16 processes.
+
+.. todo:: write this section, and the following ones.
+
+Further Readings
+----------------
+
+You may also be interested in the `SMPI reference article
+<https://hal.inria.fr/hal-01415484>`_ or these `introductory slides
+<http://simgrid.org/tutorials/simgrid-smpi-101.pdf>`_. The `SMPI
+reference documentation <SMPI_doc>`_ covers much more content than
+this short tutorial.
+
+Finally, we regularly use SimGrid in our teachings on MPI. This way,
+our student can experiment with platforms that they do not have access
+to, and the associated visualisation tools helps them to understand
+their work.  The whole material is available online, in a separate
+project: the `SMPI CourseWare <https://simgrid.github.io/SMPI_CourseWare/>`_.
 
 ..  LocalWords:  SimGrid
 
 ..  LocalWords:  SimGrid