Home CPSC 425

Lab 8: MPI Deadlock


To identify and resolve deadlock in a message-passing program.


This lab will deal with the 08-deadlock.c program. This program computes a number of square root values, and then sends them from one process to another in a specific pattern.

Process 0 sends its values to process 1, process 1 sends its to process 2 and so on. The last process sends its values back to process 0.

As currently written, this program will not complete due to deadlock. Your job is to figure out why it's deadlocking and fix it.

When you're done, the output of the program should look like this when run with 4 processes (though the order may of course be different:

Process 1 received 1000 values from process 0.
Process 2 received 1000 values from process 1.
Process 3 received 1000 values from process 2.
Process 0 received 1000 values from process 3.

Note that you should keep the communication pattern the same - i.e. you can't just remove the communication to fix the problem, but rework the communication so that it happens without deadlock.


  1. Download and run the 08-deadlock.c program.
  2. Observe that the program will deadlock.
  3. Figure out why the program deadlocks.
  4. Fix the program so it can no longer cause deadlock. There are multiple ways to do this!


When you have gotten the program to run without deadlock, send the code to ifinlay@umw.edu. In the email body, include a brief description of what caused the deadlock and how you fixed it.

Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.