Algorithmes Parallèles et Distribués -- Partie MPI

(last update: Wed Dec 16 09:43:00 CET 2015)

1   This course

Instructors:

2   Installing MPI

In Debian or Ubuntu, we will use the OpenMPI implementation of the MPI standard. OpenMPI is installed on all computers at the room G207.

If you wish to install it at home or in your laptop, you will need to following packages:

libopenmpi-dev
openmpi-bin
openmpi-doc
openmpi-checkpoint

3   Getting Help

4   Hello World

The following program says hello from each process (files found here: examples/hello-world):

#include <stdio.h>
#include <mpi.h>

int main (int argc, char ** argv)
{
   int rank;

   MPI_Init (&argc, & argv);

   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
   printf ("p%d: hello\n", rank);

   MPI_Finalize ();
   return 0;
}

To compile it, execute the following command:

mpicc -Wall hello.c -o hello

To run it, using 4 processes, all of them running on the local host:

mpirun -n 4 ./hello

It will output something similar to this:

p0: hello
p1: hello
p3: hello
p2: hello

The following Makefile could be useful for your projects (obseve that the target all not only compiles the program hello.c but it also executes it):

CFLAGS=-Wall
CC=mpicc

all : hello
       mpirun -n 4 ./hello

clean :
       rm -f hello *.o

5   Running on Multiple Hosts

Running 4 processes, all of them on the local host:

mpirun -n 4 ./hello

Equivalenly:

mpirun -n 4 -H localhost ./hello

Running 3 processes, two of them in machine G207-1 and one in G207-10 (the assignment of processes (ranks) to hosts is done round-robin):

mpirun -n 3 -H G207-1,G207-10 ./hello

Running 5 processes, 3 on G207-1 and 2 on G207-2 (note that there is no -n option):

$ cat hosts
G207-1  slots=3
G207-2  slots=2
$ mpirun -hostfile hosts ./hello

Running 3 processes, all of them in G207-1:

mpirun -n 3 -hostfile hosts ./hello

Running 9 processes (3 + 3) in G207-1, (2 + 1) in G207-2 (two rounds of assignment, as first one "completed" the slots):

mpirun -n 9 -hostfile hosts ./hello

6   Conway's Game of Life