Dana Vrajitoru
B424 Parallel and Distributed Programming

B424 B524 Homework 10

Due date: Thursday, November 12, 2020.

In this homework we will be implementing an Output Server and use the program written for Homework 9 to test it.

Ex. 1. Output Server

This homework will continue the program written in Homework 9. If you have not turned in Homework 8 on time, you can turn in a single program containing both implementations. In that case, however, appropriate late penalties will be applied to Homework 9.

We will add one extra process to the mix that will act as an output server. This will be the process with id equal to nr_proc-1 (the last process) so that we don't disturb the prior assignment of processes to graph vertices. You will need to run the program with a number of processes equal to at least 1 plus the number of vertices in the graph.

Add a function to the file process_graph.cc with the following prototype:
void Output_server();
that should be called from the main instead of the Master or Worker functions when the process id is equal to the number of processes - 1.

In this function, implement a simple Server function based on the model in the PowerPoint slides. For this particular problem, the server will be receiving a number of messages exactly equal to the number of vertices in the graph, which may or may not be equal to the number of processes - 1. Thus, the server will have to receive this number first from the master. You will also have to add a Send in the master function right after the graph is read.

After that, the server process should do a loop with a number of iterations equal to this number received from the master. In the loop, it should receive a message from any process sending it (use MPI_ANY_SOURCE), and then output it. To simplify the exercise, the processes should be sending their id as a simple integer, and the server should receive them the same way.

Note that if there are more processes than the number of vertices plus 1, the master process is sending the tag of value 0 to all the worker processes with a process number higher than the number of vertices. Modify the code so that the master does not send this tag to the output server process (with process id = nr_proc-1), both when sending the incoming edges, and when sending the outgoing edges. Instead, the master should send the vertex number to this process.

Modify the function process_dependency to make use of the output server. For this, you'll need to replace the output statement of the process id with sending the id to the server process. This should happen after receiving a message from all the incoming dependencies and before sending a message to each outgoing dependency.

Since the id of the server depends on the number of processes, you will need to add a parameter containing this number both to the Worker and to the process_dependency functions. The Master function already has this parameter.

With this modification, the output order of the number of processes should be completely consistent with the dependency graph, no matter which computer you run the program on.

Homework Submission

Upload: to Canvas, Assignments, Homework 10, all the files that you modify, add, create.