Parallel Graph Algorithms

Similar documents
Parallel Graph Algorithms

Lecture 4: Graph Algorithms

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms

Minimum Spanning Trees

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

Lecture 6 Basic Graph Algorithms

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Week 12: Minimum Spanning trees and Shortest Paths

CS 310 Advanced Data Structures and Algorithms

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

Week 11: Minimum Spanning trees

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

Minimum Spanning Trees My T. UF

Undirected Graphs. Hwansoo Han

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

Homework Assignment #3 Graph

Single Source Shortest Path (SSSP) Problem

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

DESIGN AND ANALYSIS OF ALGORITHMS GREEDY METHOD

CHAPTER 13 GRAPH ALGORITHMS

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms

CS420/520 Algorithm Analysis Spring 2009 Lecture 14

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

Shortest Path Problem

CSC 8301 Design & Analysis of Algorithms: Warshall s, Floyd s, and Prim s algorithms

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

Shortest path problems

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

Graph Algorithms. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico.

Graph Algorithms. 1 Preliminary Denitions. CSci 335 Software Design and Analysis III Chapter 9 Graph Algorithms. Prof.

Greedy Approach: Intro

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

COMP 355 Advanced Algorithms

Artificial Intelligence

The Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

Minimum Spanning Trees

Minimum spanning trees

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li

from notes written mostly by Dr. Carla Savage: All Rights Reserved

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170

Minimum Spanning Trees Ch 23 Traversing graphs

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

Analysis of Algorithms, I

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Directed Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1

Minimum Spanning Tree

Konigsberg Bridge Problem

Example. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies

Minimum-Cost Spanning Tree. Example

6.1 Minimum Spanning Trees

2 A Template for Minimum Spanning Tree Algorithms

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

Lecture 11: Analysis of Algorithms (CS ) 1

CSE 100: GRAPH ALGORITHMS

Algorithm Design (8) Graph Algorithms 1/2

Introduction to Algorithms

All Shortest Paths. Questions from exercises and exams

Taking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution

Minimum Spanning Trees

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

Introduction to Algorithms

Graph Theory. ICT Theory Excerpt from various sources by Robert Pergl

Minimum Spanning Trees. CSE 373 Data Structures

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Kruskal's MST Algorithm

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Shortest Paths. Nishant Mehta Lectures 10 and 11

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II

Graph Algorithms shortest paths, minimum spanning trees, etc.

Module 5 Graph Algorithms

CS521 \ Notes for the Final Exam

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

Announcements Problem Set 5 is out (today)!

Graph Algorithms. Definition

Shortest Paths. Nishant Mehta Lectures 10 and 11

tree follows. Game Trees

looking ahead to see the optimum

Graphs. Pseudograph: multiple edges and loops allowed

Sample Solutions to Homework #4

COMP 251 Winter 2017 Online quizzes with answers

Algorithms Sequential and Parallel: A Unified Approach; R. Miller and L. Boxer 3rd Graph Algorithms

CS 561, Lecture 9. Jared Saia University of New Mexico

CSci 231 Final Review

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

Introduction to Algorithms

Graphs and Network Flows IE411. Lecture 21. Dr. Ted Ralphs

Algorithms (IX) Yijia Chen Shanghai Jiaotong University

2pt 0em. Computer Science & Engineering 423/823 Design and Analysis of Algorithms. Lecture 04 Minimum-Weight Spanning Trees (Chapter 23)

Chapter 9 Graph Algorithms

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Transcription:

Parallel Graph Algorithms Design and Analysis of Parallel Algorithms 5DV050 Spring 202

Part I Introduction

Overview Graphsdenitions, properties, representation Minimal spanning tree Prim's algorithm Shortest paths (-to-all) Dijkstra's algorithm Shortest paths (all-to-all) Algorithm based on matrix multiplication Dijkstra's algorithm Source partitioned Source parallel Floyd's algorithm Transitive closure Connected components

Graphs: Denitions Graphs G = (V, E): V is the set of vertices and E is the set of edges Undirected graphs An edge e E is an unordered pair {u, v} where u, v V Directed graphs An arc e E is an ordered pair (u, v) directed from u to v A path from u to v is a sequence u,..., v of vertices where consecutive vertices correspond to an arc Simple path: all vertices are distinct Cycle: u = v Acyclic: contains no cycles

Examples of graphs Undirected 5 4 5 4 Directed 2 3 6 2 3 6

Graphs: Properties A graph is connected if it exists a path between every pair of vertices A graph is complete if it exists an edge between every pair of vertices G = (V, E ) is a sub-graph of G = (V, E) if V V and E E A tree is a connected acyclic graph A forest consists of several trees A graph G = (V, E) is sparse if E is much smaller than V 2 Weighted graphs: G = (V, E, w), where w is a real-valued function dened on E (every edge/arc has a value) The weigh of a graph is the sum of the weights of its edges

Matrix representation of graphs Non-weighted graphs: { if (v i, v j ) E, a i,j = 0 otherwise. 2 3 4 5 Weighted graphs: w(v i, w j ) if (v i, v j ) E, a i,j = 0 if i = j, otherwise. 0 0 0 0 0 0 A = 0 0 0 0 0 0 0 0 0 Suitable for dense graphs

List representation of graphs G = (V, E) is represented by the list Adj[... V ] of lists For each v V, Adj[v] is a linked list of all vertices that has an edge in common with v 2 3 Adj[] 2 Adj[2] 2 3 5 Adj[3] 3 2 5 Adj[4] 4 5 4 5 Adj[5] 5 2 3 4 Suitable for sparse graphs

Part II Minimum Spanning Tree (MST)

Minimum Spanning Tree (MST) A spanning tree of a graph G = (V, E) is a sub-graph of G that is a tree and contains all vertices of G MST for a weighted graph is a spanning tree with minimum weight If G = (V, E) is not connected, then it cannot have an MST but instead has a minimum spanning forest Assume that G is connected, otherwise we nd connected components and nd an MST Of each component

Prim's algorithm Greedy algorithm: Add one edge at a time to the MST Select a vertex at random Choose an edge with minimum weight between the selected set and the unselected set (break ties arbitrarily) Select the unselected vertex Repeat until a spanning tree has been created The constructed tree is an MST

Prim's algorithm: Example (/6) a b c d e f d[] 0 5 a 2 3 f b 5 c 5 2 4 e d

Prim's algorithm: Example (2/6) a b c d e f d[] 0 2 4 a 2 3 f b 5 c 5 2 4 e d

Prim's algorithm: Example (3/6) a b c d e f d[] 0 2 4 2 a 2 3 f b 5 c 5 2 4 e d

Prim's algorithm: Example (4/6) a b c d e f d[] 0 2 2 a 2 3 f b 5 c 5 2 4 e d

Prim's algorithm: Example (5/6) a b c d e f d[] 0 2 2 a 2 3 f b 5 c 5 2 4 e d

Prim's algorithm: Example (6/6) a b c d e f d[] 0 2 2 a 2 3 f b 5 c 5 2 4 e d

Prim's algorithm : PRIM(V, E, w, r) 2: V T := {r} 3: d[r] := 0 4: for all v (V V T ) do 5: d[v] := w(r, v) if (r, v) E else d[v] := 6: end for 7: while V T V do 8: Find vertex u (V V T ) such that d[u] = min{d[v] v (V V T )} 9: V T := V T {u} 0: for all v (V V T ) do : d[v] := min{d[v], w(u, v)} 2: end for 3: end while

Parallelizing Prim's algorithm d[v] is updated for all v Cannot choose two vertices in parallel Cannot parallelize outer while loop Instead we parallelize the inner for loop Every process holds a block column of adjacency matrix A: A = [ ] A A 2 A p and corresponding part of vector d Process P i holds vertex subset V i Owner computes: Process P i responsible for updating its part of d Find global minimum (line 8) with all-reduce Update d in parallel (line 0)

Analysis of the parallel Prim's algorithm Per iteration: Computation (line 0): Θ(n/p) All-reduce (line 8): Θ(log 2 p) Total for n iterations: T P (n, p) = Θ(n 2 /p) + Θ(n log 2 p) T S (n) = Θ(n 2 ) Iso-eciency condition: n = Ω(p log 2 p)

Part III Shortest paths (-to-all)

Dijkstra's algorithm Dijkstra's algorithm: Essentially identical to Prim's algorithm, except Instead of d[u] store l[u], which is the total weight from r to u Parallel Dijkstra's algorithm: Identical to the parallel Prim's algorithm (with the change above) Analysis identical

Part IV Shortest paths (all-to-all)

Shortest paths (all-to-all) Goal is to nd the weight of the shortest path between all pairs of vertices The result is a square matrix D = (d i,j ) where d i,j is the weight of the shortest path from v i to v j

Algorithm based on matrix multiplication Let G = (V, E, w) be represented by the matrix A Let d (k) represent the weight of the shortest path from v i,j i to v j that contains a maximum of k edges (Thus, D () = A) i,j Let v m be a vertex in that path Then d (k) i,j = min m {d (k ) i,m + w(v m, v j )}

Matrix multiplication-based algorithm (continued) D (k) computed from D (k ) using modied matrix multiplication: c i,j := min a i,k + b k,j k (Find k that minimizes a i,k + b k,j ) D (k) = AA A }{{} k factors But we only need D (n ) Compute D (n ) using repeated squaring: D () D (2) D (4) D (8) D (n ) Complexity for matrix multiplication: Θ(n 3 ) Number of steps: Θ(log 2 n) Total complexity: T P (n, p) = Θ(n 3 log 2 n)

Dijkstra's algorithm applied to all-to-all shortest paths Source-partitioned approach: Distribute the sources Run sequential -vertex Dijkstra on all processors in parallel Complexity: Θ(n 2 ) Θ(n/p) = Θ(n 3 /p) Perfectly parallel Degree of concurrency limited to p = O(n) Each processor must have access to the entire graph Source-parallel approach: Partition processors into groups (e.g., of size p) Distributed sources over the groups Run parallel -vertex Dijkstra on all processor groups in parallel Complexity: [ Θ(n 2 / p) + Θ(n log 2 p) ] n/ p = Θ(n 3 /p) + Θ((n 2 / p) log 2 p) Degree of concurrency p = O(n 2 ) (much better) Each processor needs access only to a sub-graph

Floyd's algorithm Given G = (V, E, w) Let V k := {v,..., v k } (rst k vertices of G) For any pair v i, v j V, consider all paths whose intermediate vertices belong to the subset V k Let p (k) i,j be the shortest such path and let d (k) i,j corresponding weight If the vertex v k is not in the path, then p (k) i,j be the = p (k ) i,j If the vertex v k is in the path, then it can be split into two paths: One from v i to v k and one from v k to v j where both paths uses vertices only from V k In that case, the weight of the path is d (k) i,j := d (k ) i,k + d (k ) k,j

Floyd's algorithm : FLOYD(A) 2: D (0) := A 3: for k = to n do 4: for i = to n do 5: for j = to n do 6: d (k) i,j 7: end for 8: end for 9: end for := min{d (k ) i,j, d (k ) i,k + d (k ) k,j } Similar in structure to matrix multiplication Parallelized using SUMMA-style algorithm

Part V Transitive closure

Transitive closure If G = (V, E) is a graph, then its transitive closure is the graph G = (V, E ), where E := {(v i, v j ) exists path from v i to v j in G} Computes the connectivity matrix A such that a i,j = if i = j or a path from v i to v j exists in G and a i,j = otherwise Method : Set the weights in G to and compute all-pairs shortest paths followed by re-interpreting the output Method 2: Modify Floyd's algorithm by replacing min with logical or and + with logical and: d (k) i,j := d (k ) i,j or (d (k ) i,k and d (k ) k,j )

Part VI Connected components

Connected components Partition V into maximal disjoint subsets C, C 2,..., C r such that V = C C 2 C r and u, v C i if and only if u is reachable from v and vice versa The graph below has three connected components 4 6 9 2 3 5 7 8

Depth-rst search based algorithm Perform depth-rst traversal of the graph to generate a spanning forest Each tree in the forest denes a connected component Parallel formulation: Give sub-graph G i = (V, E i ) to process P i Perform sequential algorithm on each sub-graph in parallel Merge forests pair-wise using log 2 p steps

Forest merging find(x): Tree to which x belongs union(u, v): Merge trees to which u and v belong Merge forest A into forest B: Send A to processor holding B For each edge (u, v) (there are at most n ) in A: find(u) in B find(v) in B Same tree? Do nothing Dierent trees? union(u, v) in B Discard A, continue with B Using appropriate set data structure and algorithms, find(x) and union(u, v) have expected constant time complexity Complexity (D block partitioning): T P (n, p) = Θ(n 2 /p) + Θ(n log 2 p)

Part VII Johnson's algorithm

Johnson's algorithm (-to-all shortest paths) Dijkstra's algorithm Find unprocessed u such that d[u] = min{d[v] v unprocessed} Update for all unprocessed vertices v : d[v] := min{d[v], d[u] + w(u, v)} For sparse graph, store unprocessed vertices in a priority queue based on d[v] (smallest rst) Take minimum weight vertex from the priority queue Update adjacent vertices

Johnson's algorithm : JOHNSON(V, E, r) 2: Q := V 3: for all v Q do 4: d[v] := 5: end for 6: d[r] := 0 7: while Q do 8: u := ExtractMin(Q) 9: for each v adjacent to u do 0: if v Q and d[u] + w(u, v) < d[v] then : d[v] := d[u] + w(u, v) 2: end if 3: end for 4: end while

Parallel Johnson's (centralized queue) Maintain Q at a centralized location Processors compute new values and request updates of Q Major bottleneck No asymptotic speedup, since O( E ) updates that are serialized and each take time O(log 2 n) leading to the same complexity as the sequential formulation Moreover, only E / V vertices can be updated in parallel in each iteration, and this number is small since the graph is assumed sparse

Parallel Johnson's (distributed queue) Distributed queue: Manage Q using distributed algorithm Requires a machine with very low latency to be practical Even if the update complexity is reduced from O(log 2 n) to O(), we can expect no more than a O(log 2 n) speedup since the updates are applied sequentially Safe vertices: Let u be a vertex with minimal d[u] All vertices v with d[v] = d[u] can be processed in parallel If we know that the minimum edge weight is m, then we can relax this to all vertices v with d[v] d[u] + m

Parallel Johnson's (unsafe vertices) Process also unsafe vertices in parallel Leads to an algorithm that is no longer equivalent to the sequential algorithm Process p vertices at the top of Q in parallel Each process maintains its own priority queue The distances might no longer correspond to the shortest paths Detect instances of wrongly computed distances and re-process the corresponding vertices

Part VIII Weighted matchings

Weighted matchings A matching M(G) of a graph G = (V, E) is any sub-graph of G where each vertex is incident to at most one edge Let w(e) be the weight of an edge e We dene the weight w(g) of a graph G as the sum of all edge weights A maximum weighted matching M (G) of G is a matching whose weight w(m (G)) is maximum among all matchings of G

Matchings and parallel graph partitioning

Sequential greedy weighted matching algorithm : MATCHING(V, E) 2: M(G) := 3: while E do 4: Pick locally heaviest edge e from E 5: Add e to M(G) 6: Remove e = {u, v} and all edges incident to u and v from E 7: end while Approximates a maximal matching within a factor 2

Parallel greedy weighted matching algorithm For each vertex v in parallel: : PMATCHING(V, E) 2: R := 3: Initialize N to the neighborhood of v (all vertices adjacent to v) 4: Let the candidate c be the vertex connected to v by the locally heaviest edge in N 5: if c then 6: Send req to c 7: end if 8: while N do 9: Receive message m from vertex u 0: If m = req, then R := R {u} : If m = drop, then N := N {u} and update c if u = c and if c send req to c 2: If c and c R, send drop to all vertices in N except c 3: end while