Consider the following multithreaded algorithm for performing pairwise addition on n-element arrays A[1 . . n] and

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. . 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)


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.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Introduction to Algorithms

ISBN: 978-0262033848

3rd edition

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

Question Posted: