Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tuto smpi: Lab0 (hello world) drafted
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 18 Sep 2018 14:29:14 +0000 (16:29 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 18 Sep 2018 14:29:14 +0000 (16:29 +0200)
docs/source/tuto_s4u.rst
docs/source/tuto_smpi.rst
docs/source/tuto_smpi/roundtrip.c [new file with mode: 0644]

index 5fc672c..18c43c4 100644 (file)
@@ -366,7 +366,6 @@ Discovering the Provided Code
 
 Please compile and execute the provided simulator as follows:
 
-
 .. code-block:: shell
 
    make master-workers
index 0584720..fe11f83 100644 (file)
@@ -110,8 +110,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
-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).
@@ -137,9 +137,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
-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::
 
@@ -290,23 +290,65 @@ Debian and Ubuntu for example, you can get them as follows:
 
    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/
-   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.
 
+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.txt ./roundtrip
+
+- The ``-np 16`` option, just like in regular MPI, specifies the
+  number of MPI processes to use. 
+- The ``-hostfile cluster_hostfile.txt`` 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).
+
+
+
+We will use following simple MPI program, roundtrip.c, in which the processes pass around a message and print the elpased time:
 
 ..  LocalWords:  SimGrid
diff --git a/docs/source/tuto_smpi/roundtrip.c b/docs/source/tuto_smpi/roundtrip.c
new file mode 100644 (file)
index 0000000..53f523b
--- /dev/null
@@ -0,0 +1,42 @@
+#include <mpi.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define N (1024 * 1024 * 1)
+
+int main(int argc, char* argv[])
+{
+  int size, rank;
+  struct timeval start, end;
+  char hostname[256];
+  int hostname_len;
+
+  MPI_Init(&argc, &argv);
+
+  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+  MPI_Comm_size(MPI_COMM_WORLD, &size);
+  MPI_Get_processor_name(hostname, &hostname_len);
+
+  // Allocate a 1 MiB buffer
+  char* buffer = malloc(sizeof(char) * N);
+
+  // Communicate along the ring
+  if (rank == 0) {
+    gettimeofday(&start, NULL);
+    printf("Rank %d (running on '%s'): sending the message rank %d\n", rank, hostname, 1);
+    MPI_Send(buffer, N, MPI_BYTE, 1, 1, MPI_COMM_WORLD);
+    MPI_Recv(buffer, N, MPI_BYTE, size - 1, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+    printf("Rank %d (running on '%s'): received the message from rank %d\n", rank, hostname, size - 1);
+    gettimeofday(&end, NULL);
+    printf("%f\n", (end.tv_sec * 1000000.0 + end.tv_usec - start.tv_sec * 1000000.0 - start.tv_usec) / 1000000.0);
+
+  } else {
+    MPI_Recv(buffer, N, MPI_BYTE, rank - 1, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+    printf("Rank %d (running on '%s'): receive the message and sending it to rank %d\n", rank, hostname,
+           (rank + 1) % size);
+    MPI_Send(buffer, N, MPI_BYTE, (rank + 1) % size, 1, MPI_COMM_WORLD);
+  }
+
+  MPI_Finalize();
+  return 0;
+}