- 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
- 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...
- 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>
- 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.
- 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
- 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
- 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
- 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