Assignment 1 Final
See the page Assignment 1 Introduction for an overview.
You should finish the Milestone before beginning this part.
Your task here is to write an MPI program for a set of tasks communicating in a ring topology.
On page 37 B of the textbook, you can see a picture of processors connected by a ring interconnect.
In such a network, it is only possible for a given processor to communicate directly with either its left or its right neighbour. We are going to try to emulate
this behaviour with MI tasks. Hence, when emulating ring communication, point to point communication events must always have immediate neighbours
as source and destination.
We are going to be mostly concerned with moving numbers in a circular fashion around the ring.
Think about this pseudocode. Remember that it is executed simultaneously by all tasks.
Send m to the right
Receive m from the left
Remembering that m is local to each task, this has the effect of shifting the set of m values one element to the right.
For example, consider four tasks, such that in task j, variable m has the value j.
In other words, in task O, m is O, in task 1, it is 1 and so on.
Then, before we execute the code above, the m values will be: 0, 1, 2, 3.
After the code is executed, we will have: 3. 0, 1, 2.
Draw a diagram showing the four tasks, and the communication events, to make sure that you understand this.
Also, write down the left and right neighbours of each task.
For example, the left neighbour of task 2 is 1, its right neighbour is 3.
Think carefully about tasks O and 3.
We are asking you to carry out these steps:
1. Initialise the m-values in each task, by having each task generate a random integer between 10 and 20 and using that as its m-value.
2. Do a left circular shift of the m-values three places to the left by shifting values to the left. 3 times, around the ring. In the example above, the result after
execution will be: 3.0.1.2.
3. After that is done, each task outputs its m-value. The outputs must be ordered based on rank. You must use point-to-point communication only to
implement this ordering.
Make sure to print out a record of each communication.
For example, before a Send operation, output something like this: “Task O sending number 5 to task 3”
And after a Receive operation, something like this: “Task 3 received number 5 from task O”.
Your assignment will be assessed both on your program, and a report. In the report, we ask you to explain certain aspects of your program, and to provide a
summarised version of its output. The program will constitute 60% of the assessment for this assignment, and the report 40%.
Include the following in your report:
1. A clear and concise explanation in words of how you achieve a circular shift one place to the left;
2. A clear and concise explanation in words of your strategy for achieving ordered output;
3. An extract from the printed record of communication, showing only the interactions between tasks 0 and 3;
4. A copy of the ordered output of m-values.
Items 3 and 4 must be included separately in the report. The report should be about 1000 to 1200 words in length.
Your program will be assessed on the clarity of the code itself and of the comments associated with that code, as well as the actual output.
In the comments that you write for your code, make sure to clearly explain how you implement the neighbour relationship between tasks.
Here is I, an example of a program that is notable for the clarity of both comments and code. The program is written in a different language, and for an
unrelated topic, so that you can pay attention primarily to how well the comments explain the meaning of the program to someone reading it. That is what
you should attempt to emulate in your own program.