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]


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,


ADD-SUBARRAY (A, B, C, I, j)

1 parallel for i = 1 to A.length C[i] = A[i] +


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

1 Expert Approved Answer
Step: 1 Unlock

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

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction to Algorithms Questions!