PROGRAMMING ASSIGNMENT #1

Due Date: 4/13/99 11:59 PM

Goal:
The goal of this assignment is to introduce you to parallel programming (message-passing model) with MPI. MPI (Message Passing Interface) is a library of routines that will enable you to write a SPMD-style program.

Resources:
Assignment description: Ring program

Your program will take a command line input of a string of any length. This string will get passed around to all processes. Process 0 will read in the command line input string and pass it to process 1, process 1 will pass the str ing to process 2, and so on. Process N - 1 will pass the string back to process 0. Your program should be able to handle any number of processes, N. Your command line should be of the following format:
mpirun -np <number of processes> -machinefile <file of machine names> ring <input string>
(More information on mpirun is presented in the section below) Hint: work on one step at a time and build your program up in increments.
  1. On startup, each process will discover its rank (i.e. a unique process identifier) using MPI_Comm_rank. For each message the process outputs, it will use its rank to identify itself. For example, the process of rank 2 (or process 2) would output messages like this:
    2: This is an output message.
    Note: there is one space between the colon and the message
  2. Use the call MPI_Get_processor_name to find out what machine you are running on. Print out a message in the following format:
    <rank>: Starting up on host <machine name>...
    For example, the first message process 1 prints out would be:
    1: Starting up on host uape-1.ucsd.edu...
  3. Use the call MPI_Comm_size to find out the total number of processes (i.e. the value passed in with -np). Use the following format:
    <rank>: Number of total processes = <total number of processes>
  4. Process 0 will check that there is an input string and that there are at least 2 processes. If there is an error, process 0 will send a message (using MPI_Bcast) to the other processes telling them to exit. Otherwise, process 0 will send a message to the other processes telling them that the input was correct. In other words, your program should not hang if there is an error.
  5. Process 0 will begin passing the string. It will first send the length of the string and then the actual input string (i.e. 2 separate messages) using MPI_Send. Each of the remaining processes will receive the length of the input string using MPI_Recv, dynamically allocate space for a string of that size, and then receive the input string. Each process should print out the following:
    <rank>: Receiving input string length <length> from process <rank of right neighbor>
    <rank>: Receiving input string '<input string>' from process <rank of right neighbor>
    <rank>: Sending input string length <length> to process <rank of left neighbor>
    <rank>: Sending input string '<input string>' to process <rank of left neighbor>
    
    So, for example, your messages would look something like this:
    3: Received input string length 5 from process 2
    3: Received input string 'hello' from process 2
    3: Sending input string length 5 to process 0
    3: Sending input string 'hello' to process 0
    
  6. When process 0 receives the string back (to make it a complete ring), it will print out the time (using MPI_Wtime) it took for the string to travel around the ring. Process 0 should print out a message of the following format:
    <rank>: total time around loop = <time> s
  7. Create a barrier before exiting using MPI_Barrier. Each process should print out the time that it spent waiting at the barrier in the following format:
    <rank>: time waiting at barrier = <time> s
  8. Have process 0 print out the average time that each process spent waiting using MPI_Reduce and process 0 as the root process. The message should be of the following format:
    <rank>: avg barrier wait time = <time> s
Brief description of mpirun:
To run an MPI program, you should prefix the command line with mpirun . The following command line options will be useful to you when using mp irun:
Brief description of MPI calls that you will use in this program:
How to compile your MPI program:
Copy the makefile from the $PUBLIC directory. Name your program 'ring.c' and then type 'make'.

Things to try out:
Instructions for turning in programming assignment #1:
You only need to turn in your ring.c file (i.e. don't turn in your makefile).
Grading:

Note: This program will be partially graded by scripts, therefore it is important that the output of your messages matches the formats specified above.

If your program passes the scripts and you use all of the MPI calls that I asked for, you will receive full credit. Otherwise, I will check your code and assign the appropriate partial credit. If your program is correct, but your output does not match mine, you will be docked 10%.