Write portions of a MPI program to multiply two n-by-n matrices A and B of integers using p processors organized in a ring network. Assume matrix A is stored in row-major order and the matrix B is stored as its transpose – call it matrix BT. The latter assumption allows you to send/receive columns of B by referring to the rows of matrix BT. P0 will initially distribute ith row-band of A and ith row-band of BT to Pi, 1 ≤ i ≤ p−1. To compute their row-bands of product matrix C, the processors will use p steps of computation (multiplying row-bands of A and BT) and (p-1) steps of communication (sending the row-band of BT to the right neighbor and receiving from the left neighbor. You must only use send/receive primitives. P0 finally receives the ith row-bands of product matrix C from Pi, 1 ≤ i ≤ p − 1. Note: To simplify, you can assume that you can multiply row-band of A with row-band of BT each starting at row j and with m rows and store the block produced into row-band of matrix C at row j starting in column k by calling a function mat mul row band(A, BT, j, m, C, k). You may modify the interface of this function slightly to suit your design. (a) Give the code for P0 to send the ith row-band of A and ith row-bands of BT to Pi, 1 ≤ i ≤ p − 1. Clearly show the starting row and number of rows to be sent to each processor, including the last processor. (b) Give the code for Pi to receive the ith row-band of A and ith row-band of BT from P0. Give the correct parameter for how many integers are received.
Write portions of a MPI program to multiply two n-by-n matrices A and B of integers using p processors organized in a ring network. Assume matrix A is stored in row-major order and the matrix B is stored as its transpose – call it matrix BT. The latter assumption allows you to send/receive columns of B by referring to the rows of matrix BT. P0 will initially distribute ith row-band of A and ith row-band of BT to Pi, 1 ≤ i ≤ p−1. To compute their row-bands of product matrix C, the processors will use p steps of computation (multiplying row-bands of A and BT) and (p-1) steps of communication (sending the row-band of BT to the right neighbor and receiving from the left neighbor. You must only use send/receive primitives. P0 finally receives the ith row-bands of product matrix C from Pi, 1 ≤ i ≤ p − 1. Note: To simplify, you can assume that you can multiply row-band of A with row-band of BT each starting at row j and with m rows and store the block produced into row-band of matrix C at row j starting in column k by calling a function mat mul row band(A, BT, j, m, C, k). You may modify the interface of this function slightly to suit your design.
(a) Give the code for P0 to send the ith row-band of A and ith row-bands of BT to Pi, 1 ≤ i ≤ p − 1. Clearly show the starting row and number of rows to be sent to each processor, including the last processor.
(b) Give the code for Pi to receive the ith row-band of A and ith row-band of BT from P0. Give the correct parameter for how many integers are received.
Step by step
Solved in 2 steps with 5 images