Lab 1
MPI
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
Hello world
- Write an MPI program which prints its rank and execute it on a variable number of processors.
- Write an MPI program where the first process prints "hello", the second "goodbye" and the others don't do anything.
Ping Pong
Ping Pong
- 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.
- 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.
- 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. - How does the master knows the sender of a message it has received ?
Pipeline
Pipeline
- Implements the pipeline studied during the lectures.
Ring
Ring
We consider a virtual ring topology. Although MPI offers primitives to create topologies (e.g. MPI_Cart_*) but we won't use them.
- Write an MPI program where each processors sends its rank to its successor.
- 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.
- 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
Deadlock
We consider 2 strictly identical processes. Both will send an array to each other, and then perform a receive.
- Test your code with various array sizes (10, 100, 1000,...) until it stops working.
- How can you explain the deadlock only appears after a specific size ?