Lab 1

MPI

We will use openMPI. It can be installed on any Linux distribution, the Linux Subsystem (Windows) or MacPorts

yum install libopenmpi-dev openmpi-bin.

To check OpenMPI is properly installed, look for mpicc (or openmpicc) and mpirun (or openmpirun).

If mpirun returns an error regarding slots, use the --oversubscribe option.

Hello world

  1. Write an MPI program which prints its rank and execute it on a variable number of processors.
  2. Write an MPI program where the first process prints "hello", the second "goodbye" and the others don't do anything.

Ping Pong

  1. Write an MPI program with 2 processes. The first one will send an int value to the second one. The latter will add its rank and send it back. The first process will print the final value.
  2. Modify the previous program so it works with more than 2 processes. The master will send the data to each process and wait for their result.
  3. Use MPI_ANY_SOURCE in the master so it doesn't have to wait in order. Modify one of the processes to add a sleep so it takes more time to receive its reply.
  4. How does the master knows the sender of a message it has received ?

Pipeline

  1. Implements the pipeline studied during the lectures.

Ring

We consider a virtual ring topology. Although MPI offers primitives to create topologies (e.g. MPI_Cart_*) but we won't use them.

  1. Write an MPI program where each processors sends its rank to its successor.
  2. Write an MPI program where process 0 sends an int (a token) which will travel along the ring. The program will stops when the token is back to the sender.
  3. Write an MPI program where process 0 sends an array along the ring. Each process will put the current time at the index corresponding to its rank, and pass along the array.

Deadlock

We consider 2 strictly identical processes. Both will send an array to each other, and then perform a receive.

  1. Test your code with various array sizes (10, 100, 1000,...) until it stops working.
  2. How can you explain the deadlock only appears after a specific size ?