Lect 5 Brent
Lect 5 Brent
PRAM ALGORITHMS:
BRENT’S LAW
2
1
13‐08‐2015
PARALLEL MERGE
Consider two sorted lists of distinct elements of size n/2.
We spawn n processors, one for each element of the list to be
merged.
In parallel, the processors perform binary search of the corresponding
elements in the other half of the array.
Element in the lower half of the array performs a binary search in the upper half.
Element in the upper half of the array performs a binary search in the lower half.
2
13‐08‐2015
THE TASK OF P3
A[1] A[8]
A[i=3] is larger than Thus, 7 is larger than 2
i-1=(3-1)=2 elements in 1 5 7 13 17 19 23 elements in the lower array,
the lower array (lower and larger than
wrt. Index) (high-n/2)=10-8=2 elements
in the upper array.
3
13‐08‐2015
PRAM (CONTD.)
Note that the final writing into the array is done by the processors
without any conflict. All the locations are distinct.
Also note that the total number of operations performed have increased
from that in a sequential algorithm Θ to Θ in the parallel
algorithm. 8
4
13‐08‐2015
COST-OPTIMAL SOLUTIONS
We have seen examples of PRAM algorithms which are not cost
optimal.
Is there a cost-optimal parallel reduction algorithm that has also the
same time complexity?
10
5
13‐08‐2015
∑ ∑ ∑ ∑ .
11
log Θ
Θ(logn)
Thus reducing the number of processors from n to does not change
the complexity of the parallel algorithm.
If the total number of operations performed by the parallel algorithm is
the same as an optimal sequential algorithm, then a cost optimal parallel
algorithm does exist.
12
6
13‐08‐2015
13
EXERCISES
Now think of the cost optimal solutions that we discussed,
like reduction, prefix sum, suffix sum, pointer jumping, tree
traversal etc. in the light of Brent’s Law.
14
7
13‐08‐2015
15
NON-OBVIOUS APPLICATIONS OF
PARALLEL SCAN / REDUCTIONS
Suppose, we have an array of 0’s and 1’s, and we want to determine
how many 1’s begin the array.
Ex (1,1,1,0,1,1,0,1)..The answer is 3.
16
8
13‐08‐2015
THE TRICK
Let us define for any segment of the array by the notation (x,p)
x denotes the number of leading 1’s
p denotes whether the segment contains only 1’s.
17
EXAMPLE
1 1 1 0 1 1 0 1
(3,0) (2,0)
(3,0)
18
9
13‐08‐2015
19
ANNOUNCEMENTS:
NO CLASS ON 13TH AUGUST.
QUIZ ON 14TH AUGUST, 2015 AT 4:30 PM
-- SYLLABUS (TILL THIS POINT)
IF YOU AGREE, WE CAN SWAP THE ABOVE
TOO!
20
10