ECE 563 First Midterm Spring 2018
You may not collaborate with other students. You should not copy solutions from the internet. You should do your own work. You may look things up on the internet, just don’t copy code.
1. Write code that performs an MPI_Allreduce collective communication in Log2P time. You should implement the communication pattern shown on slides 103 and 104 (Rabenseifner’s algorithm). Use it to perform an Allreduce. Your program should look like:
void main( ) {
Intialization
for (int i = 0; i < local_ub; i++) { local_sum += a[i]l
}
your allReduce code here
printf(“pid %d has sum %d”, pid, result of reduce on this processor);
}
Run your program on 4 and 16 processes.
2. Write an MPI program that performs the computation in the file temp.c. Consider the array below:
If this array were processed by the temp.c program, cols would be 16 and rows 6. Rows 0 and 5 would have the values of 100, columns 0 and 16 would have the values -50. When solving this in parallel with MPI, a reasonable distribution would be:
Halo, shadow or boundary elements
Halo, shadow or boundary elements
Note that each of the middle processes has added one or two columns to receive data from its left and right neighbors, with the end processors have a column to receive from its right or left neighbor. Thus P0, with blue elements, would get column 3, in the global space, data in its left buffer and column 8, in the global space, data in its right buffer. After each update (one iteration of the while loop) processors should send data to their neighbors and receive data from their neighbors.
Run your program on 2, 4, 8 and 16 processes and report the times.
3. Write an OpenMP program that performs the computations in the file temp.c. Use buffers to store values after each iteration so that synchronization is not needed. Collapse the i and j loops inside the while into a single parallel loop.
What to turn in:
Turn in a directory with the same name as your userid. Have your code for your program in 3 files call 1.c, 2.c and 3.c. Have your output for 1 in files 1_4.0, 1_4.e, 1_16.o and 1_16.e. For two, have you code in files 1_2.o, 1_2.e, 1_4.o, 1_4.e, and so forth, up to 1_16.o and 1_16.e. For 3, have your output in a file call 3.o.
Scoring:
Each question will be worth 30 points. There will be 10 points for turning things in in the right format. Please ask questions on piazza.