Introduction to Algorithms
Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
bartleby

Concept explainers

Question
Book Icon
Chapter 27, Problem 1P

(a)

Program Plan Intro

To reword the parallel loop in SUM-ARRAYS utilizing nested within the manner of MAT-VEC-MAIN-LOOP.

(a)

Expert Solution
Check Mark

Explanation of Solution

The implementation of the parallel loop that contains a worth grain-size to be specified is as follows:

SUM − ARRAYS’ (A, B, C)

  n=A.length

Grain − Size =?// to be calculated

  r=ceil(n/grainsize)fork=0tor1spawnADDSUBARRAY(A,B,C,k*grainsize+1,min((k+1)*grainsize,n))

Sync

ADD − SUBARRAY (A, B, C, i, j)

  fork=itojC[k]=A[k]+B[k]

Observing the algorithm SUM-ARRAYS (A, B, C) the parallelism is O(n) since it’s work is nlgn and the therefore the span is lgn .

(b)

Program Plan Intro

To calculate the parallelism of the given implementation if we set grain-size=1.

(b)

Expert Solution
Check Mark

Explanation of Solution

It can be concluded that each call to ADDSUBARRAY will return a sum of pair of numbers if the grain size = 1.

SUM − ARRAYS’ (A, B, C)

  n=floor(A.length/2)ifn==0C[1]=A[1]+B[1]elsespawnSUMARRAYS(A[1..n],B[1..n],C[1..n])SUMARRAYS(A[n+1..A.length],B[n+1..A..length],C[n+1..A.length])

(c)

Program Plan Intro

To formulate the span of SUM-ARRAYS’ in terms of n and grain-size and derived the most effective value worth for grain-size to maximize parallelism.

(c)

Expert Solution
Check Mark

Explanation of Solution

Assume g be the grain-size. The runtime of the function is ng . The runtime of any spawned task is g. So, we'd like to attenuate

  ng+g .

To get this we will perform calculus and get a derivative, we have

  0=1ng2 .

To further solve this, we set g=n . This minimizes the amount and makes the span O(ng+g)=O(n) and hence resulting in parallelism of O(n) .

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Sparse matrix-vector multiplication in Python is similar to numpy.dot operation, however the provided @ operator is used. Let us consider multiplying a 5 by 5 sparse matrix with a 5 by 3 sparse matrix shown below. 01000 00010 10001 10000 01000 100 001 x 000 010 100 The Python code to implement multiplication of these two sparse matrices
Explain the behavior of Quicksort Algorithm when the input array A [1: n] consists of n identical elements.
Pseudo Code shown in Figure Q2(c)(i) is an algorithm for binary searching for an array with n number of elements. By applying this algorithm, show step by step approach on how to find number 11 in an array as shown in Figure Q2(c)(ii). low + 0 high + n-1 while (low S high) do ix + (low + high)/2 if (t = A[ix]) then return ix else if (t < A[ix]) then high e ix - 1 else low + ix + 1 return -1 Figure Q2(c)(i) 9 | 10 | 11 | 12 [2] [3] [4] [5] [6] [7] 1 13 | 19 | 33| 45 55 [0] [1] [8] [9] Figure Q2(c)(ii)
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education