Question: Consider the following multithreaded algorithm for performing pairwise addition on n-element arrays A[1 . . n] and B[1. . n], storing the sums in C[1.
Consider the following multithreaded algorithm for performing pairwise addition on n-element arrays A[1 . . n] and B[1. . n], storing the sums in C[1. . n].
SUM-ARRAYS (A, B, C)
![1 parallel for i = 1 to A.length C[i] = A[i] + B[i]](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1545/6/4/8/9235c20bb1b9f64c1545491186166.jpg)
a. Rewrite the parallel loop in SUM-ARRAYS using nested parallelism (spawn and sync) in the manner of MAT-VEC-MAIN-LOOP. Analyze the parallelism of your implementation.
Consider the following alternative implementation of the parallel loop, which contains a value grain-size to be specified:
SUM-ARRAYS² (A, B, C)
![1 n = A.length 2 grain-size = ? = [n/grain-size] 4 for k = 0 to r – 1 spawn ADD-SUBARRAY(A, B, C,k · grain-size + 1,](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1545/6/4/8/9235c20bb1ba71c01545491186222.jpg)
ADD-SUBARRAY (A, B, C, I, j)
![1 parallel for i = 1 to A.length C[i] = A[i] +](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1545/6/4/8/9235c20bb1bb08b81545491186287.jpg)
b. Suppose that we set grain-size = 1. What is the parallelism of this implementation?
c. Give a formula for the span of SUM-ARRAYS² in terms of n and grain-size. Derive the best value for grain-size to maximize parallelism.
1 parallel for i = 1 to A.length C[i] = A[i] + B[i] 1 n = A.length 2 grain-size = ? = [n/grain-size] 4 for k = 0 to r 1 spawn ADD-SUBARRAY(A, B, C,k grain-size + 1, // to be determined 3 r min((k + 1) grain-size, n)) 6 sync
Step by Step Solution
3.42 Rating (168 Votes )
There are 3 Steps involved in it
a Similar to MATVECMAINLOOP the required procedure which we name NESTEDSUMARRAYS will take parameters i and j to specify the range of the array that i... View full answer
Get step-by-step solutions from verified subject matter experts
