Академический Документы
Профессиональный Документы
Культура Документы
CS170
Fall 2016
This lecture
What are parallel algorithms, and
how do they differ from (sequential)
algorithms?
What are the important performance
criteria parallel algorithms?
What are the basic tricks?
What does the landscape look like?
Sketches of two sophisticated
parallel algorithms: MST and
connected components
Parallel Algorithms
need a completely new mindset!!
In sequential algorithms:
We care about Time
Acceptable: O(n), O(n log n), O(n 2),
O(|E||V|2)
Polynomial time
Unacceptable: Exponential time 2 n
Sometimes unacceptable is the only
possible: NP-complete problems
How about in parallel algorithms?
RAM
P processors
Q: How about memory
congestion?
ShA: OK to Read concurrently, not OK to Write:
CREW PRAM
Language?
Threads in Java, Python, etc.
Parallel languages facilitate parallel
programming through syntax
(parbegin/parend)
In our pseudocode:
Instead of
for every edge (u,v) in E do
we may say
for every edge (u,v) in E do in parallel
Proof
time
t
wt
P
processors
we have
function sum(A[1..n])
If n = 1 return A[1]
for i = 1,,n/2 do in parallel
A[i] = A[2i -1] + A[2i]
return sum(A[1..n/2])
23175486
5 8 9 14
13 23
36
Work? Time?
W(n) = W(n/2) + n/2 O(n)
D(n) = D(n/2) + 2 O(log n)
Hackattack:
(embarrassing
(for i = 1 to n
parallelism)
check if k[i] is the secret key)
MST
Prim?
Applies the cut property to the component
that contains S sequential
Kruskal?
Goes through the edges in sorted order
sequential
Little problem
Solution
3
3
3.007
3
3.003
3.001
Borvkas Algorithm in
parallel?
T = empty
C (list of the ccs of T) = [{1}, {2}, , {n}]
while |C| > 1
for each c in C do in parallel
find the shortest edge out of c W=|E|, D=log|V|
add it to T
C = connected components of T W = |E| log |V|
D = log |V|
Total: W = O(|E| log2 |V|), D = O(log2 |V|)
Borvkas Algorithm in
parallel?
T = empty
C (list of the ccs of T) = [{1}, {2}, ,
{n}]
while |C| > 1
for each c in C do in parallel
find the shortest edge out of c How???
add it to T
C = connected components of T How???
Total: W = O(|E| log2 |V|), D = O(log2 |V|)
Connected Components
function cc(V,E) returns array[V] of V
initialize: for every node v do in parallel:
leader[v] = fifty-fifty(), ptr[v] = v
for all non-leader node v do in parallel:
chose an adjacent leader node u, if one exists,
and set ptr[v] = u
(ptr is now a bunch of stars)
V = {v: ptr[v] = v} (the roots of the stars)
E = {(u,v): u v in V, there is (a, b) in E such that
ptr[a] = u and ptr[b] = v} (contract the graph)
label[] = cc(V,E) (compute cc recursively on
the contracted graph)
return cc[v] = label[ptr[v]]