cs 584

17
CS 584 • Project Write up – Due on day of final – HTML format – Email a tar zipped file to me – I will post • Poster session for final – 4 page poster

Upload: lilly

Post on 06-Jan-2016

35 views

Category:

Documents


1 download

DESCRIPTION

CS 584. Project Write up Due on day of final HTML format Email a tar zipped file to me I will post Poster session for final 4 page poster. Graphs. A graph G is a pair (V, E) V is a set of vertices E is a set of edges Graphs can be directed or undirected Terms path adjacent incident. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS 584

CS 584

• Project Write up– Due on day of final– HTML format– Email a tar zipped file to me– I will post

• Poster session for final– 4 page poster

Page 2: CS 584

Graphs

• A graph G is a pair (V, E)– V is a set of vertices– E is a set of edges

• Graphs can be directed or undirected

• Terms– path– adjacent– incident

Page 3: CS 584

Graph Algorithms

• We will consider the following algorithms– Minimum Spanning Tree– Single Source Shortest Paths– All pairs shortest paths– Transitive closure

Page 4: CS 584

Minimum Spanning Tree

• A spanning tree is a subgraph of G that is a tree containing all the nodes of G.

• A minimal spanning tree is a spanning tree of minimal weight

• If the graph G is not connected, it does not have a spanning tree. It has a spanning forest.

Page 5: CS 584

Prim’s MST AlgorithmProcedure PRIM_MST(V, E, w, r)

VT = {r};d[r] = 0;for all v in (V - VT) do

if E[r,v] exists set d[v] = w[r, v]else set d[v] = infinite

end forwhile VT != V

find a vertex u such that d[u] = min(d[v] | v in (V - VT))VT = VT union {u}for all v in (V - VT) do d[v] = min(d[v], w[u, v])

end whileend Procedure

Page 6: CS 584

0 24

d[]

2 1

d[]

1

51 1

2

1

12

5

1

4

b

a

f

d

c

e

3

2

1

12

5

1

4

b

a

f

d

c

e

3

(d)Final minimumspanning tree

(c)has been selectedAfter the second edge

After the first edge hasbeen selected

(b)

2

1

12

5

1

4

b

a

f

d

c

e

3

2

1

12

5

1

4

b

a

f

d

c

e

3

5

5

5

5

0

3

10

02

1

01405 0

2abcdef

0 1

31 5

5 21

1 4 52

0

3

10

02

1

01405 0

2abcdef

d[]

31 5

5 21

1 4 52

0

3

10

02

1

01405 0

2abcdef

d[]

31 5

5 21

1 4 52

2 4

ca b d e

ca b d e

ca b d e

0

3

10

02

1

01405 0

2abcdef

0

31 5

5 21

1 4 52

ca b d e f

f

f

f

(a) Original graph

0 11 2 1 2

1

Page 7: CS 584

Parallelizing Prim’s Algorithm

• Since the value of d[v] for a vertex v may change every time a vertex is added, it is impossible to select more than one vertex at a time.

• So the iterations of the while loop cannot be done in parallel.

• What about parallelizing a single iteration?

Page 8: CS 584

Parallelizing Prim’s Algorithm

• Consider the calculation of the next node to add to the set. – Calculates the min distance from any of the

nodes already in the tree.

• Have all processors calculate a min of their nodes and then do a global min.

Page 9: CS 584

Data Decomposition

iProcessors 0 1 p-1

(b)

(a)

A

d[1..n]| n/p |

n

Page 10: CS 584

Analysis

• Computation ---> O(n2/p)

• Communication per iteration– Global min ---> log2p

– Bcast min ---> log2p

Page 11: CS 584

Single Source Shortest Paths

• Find the shortest paths from a vertex to all other vertices.

• A shortest path is a minimum cost path

• Similar to Prim’s algorithm

• Note: Instead of storing distances, we store the min cost to a vertex from the vertices in the set.

Page 12: CS 584

Dijkstra’s AlgorithmProcedure DIJKSTRA_SSP(V, E, w, s)

VT = {s};

for all v in (V - VT) doif E[s,v] exists set L[v] = w[r, v]else set L[v] = infinite

end forwhile VT != V

find a vertex u such that L[u] = min(L[v] | v in (V - VT))VT = VT union {u}for all v in (V - VT) do L[v] = min(L[v], L[u] + w[u, v])

end whileend Procedure

Page 13: CS 584

Parallelizing Dijkstra’s Algorithm

• Parallelized exactly the same way as Prim’s algorithm

• Exact same cost as Prim’s algorithm

Page 14: CS 584

All pairs shortest paths

• Find the shortest paths between all pairs of vertices.

• Three algorithms presented.– Matrix Multiplication– Dijkstra’s– Floyd’s

• We will consider Dijkstra’s

Page 15: CS 584

Dijkstra’s Algorithm

• Two ways to parallelize– source partitioned

• Partition the nodes

• Each processor computes Dijkstra’s sequential algorithm

– source parallel• Run the parallel single source shortest path algorithm

for all nodes

• Can subdivide the processors into sets and also divide the nodes into sets.

Page 16: CS 584

Analysis

• Source Partitioned– No communication– Each vertex requires O(n2)– The algorithm can use at most n processors

• Source Parallel– Communication is O(n log2 n)

– Each vertex requires O(n2/p)– Can efficiently use more processors

Page 17: CS 584

Transitive Closure

• Determine if any two vertices are connected

• Computed by first computing all pairs shortest path– if there is a shortest path, there is a path

• Parallelize the all pairs shortest path