PRAM Algorithms
PRAM Algorithms
M3 M7
6 7
EXAMPLE – CW ON EW MODEL
⚫ P1(6) P2(2) P3(9) P4(3) P5(7)
1 0 1 0 0
⚫ P1(6) P2(2) P3(9) P4(3) P5(7)
M3 M7
6 7
Parallel algorithms
1.Parallel reduction
2.Prefix sums
3.List ranking
4.Preorder traversal
5.Merging two sorted lists
6.Graph coloring
An initial example
⚫ How do you add N numbers residing in
memory location M[0, 1, …, N]
P0 + P1 + P2 + P3 + Step 1
P0 + P2 + Step 2
P0 + Step 3
Parallel reduction
⚫ Begin
⚫ for all Pi where 0<=i<=n/2 - 1 do
⚫ For j=0 to log n -1 do
⚫ If i mod 2j =0 and 2i +2j <n then
⚫ A[2i]=A[2i]+A[2i +2j ]
⚫ End if
⚫ End for
⚫ End for
⚫ end
Example – PARALLEL REDUCTION
⚫ 4 3 8 2 9 1 0 5 6 3
⚫ 7 10 10 5 9
⚫ 17 15 9
⚫ 32 9
⚫ 41
PRAM Algorithm (Parallel Addition)
⚫ Log (n) steps = time needed
⚫ n / 2 processors needed
⚫ Applicable for other operations
◦ +, *, <, >, etc.
2.Prefix sums
⚫ Also called as parallel prefixes and scans
⚫ Packing elements-applications
Prefix sums algorithm
⚫ For all Pi where 1<=i<=n-1 do
⚫ For j=0 to log n -1 do
⚫ if i-2j >=0 then
A[i]=A[i]+A[i-2j ]
end if
end for
end for
end
⚫
Example:Prefix sums
⚫ 4 3 8 2 9 1 0 5 6 3
⚫ 4 7 11 10 11 10 1 5 11 9
⚫ 4 7 15 17 22 20 12 15 12 14
⚫ 4 7 15 17 26 27 27 32 34 34
⚫ 4 7 15 17 26 27 27 32 38 41
Application-Prefix sums
Packing characters
⚫ AbCDeFghI
APPLY PREFIX
⚫ 1 0 1 1 0 10 0 1 SUM
⚫1 1 2 3 3444 5
⚫A b CDeFgh I
⚫ ACDFI