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

Similar documents
Introduction to Parallel & Distributed Computing Parallel Graph Algorithms

CS 4407 Algorithms Lecture 5: Graphs an Introduction

Lecture 4: Graph Algorithms

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

Outlines: Graphs Part-2

UNDIRECTED GRAPHS BBM 201 DATA STRUCTURES DEPT. OF COMPUTER ENGINEERING

Graph Algorithms. Definition

Basic Graph Algorithms

Lecture 6 Basic Graph Algorithms

Graph Theory. Many problems are mapped to graphs. Problems. traffic VLSI circuits social network communication networks web pages relationship

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

3. GRAPHS. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley Copyright 2013 Kevin Wayne. Last updated on Sep 8, :19 AM

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

Graph: representation and traversal

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Basic Graph Algorithms (CLRS B.4-B.5, )

Representations of Graphs

Outline. Graphs. Divide and Conquer.

Parallel Graph Algorithms

Graph Algorithms. Andreas Klappenecker

Graph representation

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

Sample Solutions to Homework #4

Index. stack-based, 400 A* algorithm, 325


Elementary Graph Algorithms

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

Algorithm Design (8) Graph Algorithms 1/2

Graph Representation

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

Introduction to Algorithms. Lecture 11

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

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

Graph Search. Adnan Aziz

Parallel Graph Algorithms

Konigsberg Bridge Problem

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

3.1 Basic Definitions and Applications

Chapter 9 Graph Algorithms

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

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

! Interesting and broadly useful abstraction. ! Challenging branch of computer science and discrete math. ! Hundreds of graph algorithms known.

Trees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

COP 4531 Complexity & Analysis of Data Structures & Algorithms

Homework Assignment #3 Graph

Review: Graph Theory and Representation

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

Design and Analysis of Algorithms

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

CS521 \ Notes for the Final Exam

Chapter 22 Elementary Graph Algorithms

Greedy Approach: Intro

Chapter 22. Elementary Graph Algorithms

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

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

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

Minimum Spanning Trees Ch 23 Traversing graphs

CSI 604 Elementary Graph Algorithms

Minimum Spanning Trees

Graph Traversal CSCI Algorithms I. Andrew Rosenberg

Graph implementations :

W4231: Analysis of Algorithms

csci 210: Data Structures Graph Traversals

Graphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

CS200: Graphs. Prichard Ch. 14 Rosen Ch. 10. CS200 - Graphs 1

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

Graph: representation and traversal

CHAPTER 13 GRAPH ALGORITHMS

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

Graph Representations and Traversal

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

Unit 2: Algorithmic Graph Theory

CS4800: Algorithms & Data Jonathan Ullman

Introduction to Algorithms Third Edition

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

GRAPHICAL ALGORITHMS. UNIT _II Lecture-12 Slides No. 3-7 Lecture Slides No Lecture Slides No

Graph. Vertex. edge. Directed Graph. Undirected Graph

Basic Graph Definitions

Chapter 9 Graph Algorithms

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

CS Elementary Graph Algorithms

CS Elementary Graph Algorithms

CSE 100: GRAPH ALGORITHMS

Reference Sheet for CO142.2 Discrete Mathematics II

CS 310 Advanced Data Structures and Algorithms

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

CSCE 750, Fall 2002 Notes 6 Page Graph Problems ffl explore all nodes (breadth first and depth first) ffl find the shortest path from a given s

Copyright 2000, Kevin Wayne 1

Lecture 9 Graph Traversal

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

( ) n 3. n 2 ( ) D. Ο

( ) 1 B. 1. Suppose f x

- Logic and Algorithms - Graph Algorithms

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

CS 5220: Parallel Graph Algorithms. David Bindel

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

L22-23: Graph Algorithms

n 2 ( ) ( ) + n is in Θ n logn

Transcription:

Graph Algorithms Parallel and Distributed Computing Department of Computer Science and Engineering (DEI) Instituto Superior Técnico May, 0 CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Outline Problems Described on Graphs Graph Representations Parallel Graph Algorithms Connected Components Maximal Independent Set Breath First Search CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Graph Definition Graph G = (V, E) V is a finite set of vertices (or nodes) E is a finite set of edges (or lines) Directed graph: (u, v) E, incident from vertex u to vertex v Weighted graph: value (cost) w assigned to each (u, v) E Path from a vertex u to v: sequence <v 0, v, v,..., v k > of vertices, v 0 = u, v k = v, and (v i, v i+ ) E path length: number of edges in a path, or sum of weights of the edges CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Sample Application Areas of Graphs AREA VERTICES EDGES Communication telephones, computers fiber optic cable Circuits gates, registers, processors wires Mechanical joints rods, beams, springs Hydraulic reservoirs, pumping stations pipelines Financial stocks, currency transactions Transportation street intersections, airports highways, air routes Scheduling tasks precedence constraints Software systems functions function calls Internet web pages hyperlinks Games board positions legal moves Social networks people, actors, terrorists friendships, movie casts, etc Protein interaction networks proteins protein-protein interactions Genetic regulatory networks genes regulatory interactions Neural networks neurons synapses Infectious disease people infections Electrical power grid transmission stations cable Chemical compounds molecules chemical bonds CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Graph Representation 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Adjacency Matrix ( E V ) Adjacency List ( E V ) CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Distributed Graph Representation each processor stores the entire graph CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Distributed Graph Representation each processor stores the entire graph each processor stores n p vertices (and all edges out of these vertices) CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Distributed Graph Representation each processor stores the entire graph each processor stores n p vertices (and all edges out of these vertices) How to create these p vertex partitions? CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Distributed Graph Representation each processor stores the entire graph each processor stores n p vertices (and all edges out of these vertices) How to create these p vertex partitions? graph partitioning algorithms: recursively optimize while minimizing edges crossing partitions balance vertices or edges inside partitions? CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

D Graph Partioning consider a logical D processor grid (p = p r p c ) and the matrix representation of the graph assign each processor a sub-matrix (edges within the sub-matrix) Example: consider the previous graph, and p = : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Sample Graph Algorithms Searches (breadth-first, depth-first, A*) Single-source shortest paths (Dijkstra, Bellman-Ford, DAG) All-pairs shortest paths (Johnson, Floyd-Warshall) Minimum spanning tree (Kruskal, Prim) Components (connected, strongly connected, biconnected) Maximum cardinality matching Max-flow (Edmonds-Karp, push-relabel) Sparse matrix ordering (Cuthill-McKee, King, Sloan, minimum degree) Layout (Kamada-Kawai, Fruchterman-Reingold, Gursoy-Atun) Betweenness centrality PageRank Isomorphism Vertex coloring Transitive closure Dominator tree CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 8 /

All-pairs Shortest Path Floyd-Warshall Algorithm:. for k 0 to V. for i 0 to V. for j 0 to V. d[i, j] min(d[i, j], d[i, k] + d[k, j]) Complexity: Θ( V ) CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 9 /

Graph Algorithms Irregular and unbalanced Non-local Data driven High data to computation ratio CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 0 /

Connected Components Connected Components Equivalence classes of vertices under the is reachable from relation for undirected graphs. Serial algorithm: perform depth-first search (DFS) on a graph. Number of trees in the forest = separate connected component. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Parallel Connected Components 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Parallel Connected Components 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Processor Processor CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Parallel Connected Components Each process computes DFS to obtain a forest of trees for its subgraph. Processor Processor Merge forests of trees to form the final solution. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Parallel Connected Components Merge pairs of spanning forests using disjoint sets of vertices. Consider the following operations on the disjoint sets: find(x) returns pointer to representative element of the set containing x each set has its own unique representative union(x, y) merges the sets containing the elements x and y the sets are assumed disjoint prior to the operation A simple linked list, with clever heuristics (ranking and path compression) provides a very efficient implementation for these operations. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Parallel Connected Components To merge forest A into forest B: for each edge (u,v) of A, perform find operations on u and v to determine if u and v are in same tree of B: if not, then union the two trees (sets) of B containing u and v else, no union operation is necessary Merging forest A and forest B requires at most: ( V ) find operations ( V ) union operations These operations can be performed in time Θ( V ). CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Analysis of Parallel Connected Components Partition the V V adjacency matrix into p blocks V Each processor computes local spanning forest: Θ( p ) Merging approach: use a tree of processes. log p merging stages each merge stage takes time Θ( V ) total cost due to merging is Θ( V log p) During each merging stage, spanning forests are sent between nearest neighbors: Θ( V ) edges of the spanning forest are transmitted Parallel execution time: Θ( V p ) + Θ( V log p) (the corresponding scalability function is p log p...) CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Maximal Independent Sets Independent Vertices A set of vertices I V is called independent if no pair of vertices in I is connected via an edge in G. Maximal Independent Sets (MIS) An independent set is called maximal if by including any other vertex not in I, the independence property is violated. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Serial Algorithms for MIS Practical MIS algorithms are incremental in nature. Start with an empty set. Add the vertex with the smallest degree. Remove node and adjacent vertices from graph. While graph not empty, Goto. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 8 /

Serial Algorithms for MIS Practical MIS algorithms are incremental in nature. Start with an empty set. Add the vertex with the smallest degree. Remove node and adjacent vertices from graph. While graph not empty, Goto. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 8 /

Serial Algorithms for MIS Practical MIS algorithms are incremental in nature. Start with an empty set. Add the vertex with the smallest degree. Remove node and adjacent vertices from graph. While graph not empty, Goto. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 8 /

Serial Algorithms for MIS Practical MIS algorithms are incremental in nature. Start with an empty set. Add the vertex with the smallest degree. Remove node and adjacent vertices from graph. While graph not empty, Goto. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 8 /

Serial Algorithms for MIS Practical MIS algorithms are incremental in nature. Start with an empty set. Add the vertex with the smallest degree. Remove node and adjacent vertices from graph. While graph not empty, Goto. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 8 /

Serial Algorithms for MIS Practical MIS algorithms are incremental in nature. Start with an empty set. Add the vertex with the smallest degree. Remove node and adjacent vertices from graph. While graph not empty, Goto. These algorithms are intrinsically serial! CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 8 /

Luby s MIS Algorithm Randomized algorithm. Start with an empty set. Assign a random number to each vertex. Vertices whose random number are smaller than all of the numbers assigned to their adjacent vertices are included in the MIS. Vertices adjacent to the newly inserted vertices are removed. While graph not empty, Goto. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 9 /

Luby s MIS Algorithm Randomized algorithm. Start with an empty set. Assign a random number to each vertex. Vertices whose random number are smaller than all of the numbers assigned to their adjacent vertices are included in the MIS. Vertices adjacent to the newly inserted vertices are removed. While graph not empty, Goto. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 9 /

Luby s MIS Algorithm Randomized algorithm. Start with an empty set. Assign a random number to each vertex. Vertices whose random number are smaller than all of the numbers assigned to their adjacent vertices are included in the MIS. Vertices adjacent to the newly inserted vertices are removed. While graph not empty, Goto. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 9 /

Luby s MIS Algorithm Randomized algorithm. Start with an empty set. Assign a random number to each vertex. Vertices whose random number are smaller than all of the numbers assigned to their adjacent vertices are included in the MIS. Vertices adjacent to the newly inserted vertices are removed. While graph not empty, Goto. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 9 /

Luby s MIS Algorithm Randomized algorithm. Start with an empty set. Assign a random number to each vertex. Vertices whose random number are smaller than all of the numbers assigned to their adjacent vertices are included in the MIS. Vertices adjacent to the newly inserted vertices are removed. While graph not empty, Goto. This algorithm will terminate in O(log V ) iterations. Why is this a good algorithm to parallelize? CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 9 /

Luby s MIS Algorithm Randomized algorithm. Start with an empty set. Assign a random number to each vertex. Vertices whose random number are smaller than all of the numbers assigned to their adjacent vertices are included in the MIS. Vertices adjacent to the newly inserted vertices are removed. While graph not empty, Goto. This algorithm will terminate in O(log V ) iterations. Why is this a good algorithm to parallelize? How will the parallel formulation proceed? shared memory distributed memory CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 9 /

Breath First Search Breath-first Search Graph traversal algorithm that is performed by starting at the source node and visit nodes in order of distance from the source. for each vertex v in V-{s} color[v]=white; d[v]=oo; p[v]=nil; color[s]=gray; d[s]=0; p[s]=nil; enqueue(q, s); while Q not empty u = gettopqueue(q); for each v adjacent to u if(color[v] == WHITE) color[v] = GREY; d[v] = d[u] + ; p[v] = u; enqueue(q, v); color[u] = BLACK; CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 0 /

Breath First Search Breath-first Search Graph traversal algorithm that is performed by starting at the source node and visit nodes in order of distance from the source. for each vertex v in V-{s} color[v]=white; d[v]=oo; p[v]=nil; color[s]=gray; d[s]=0; p[s]=nil; enqueue(q, s); while Q not empty u = gettopqueue(q); for each v adjacent to u if(color[v] == WHITE) color[v] = GREY; d[v] = d[u] + ; p[v] = u; enqueue(q, v); color[u] = BLACK; d=0 p=nil d= p= d= p= d= p= d= p= d= p= d= p= CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 0 /

Breath First Search Parallel BFS? for each vertex v in V-{s} color[v]=white; d[v]=oo; p[v]=nil; color[s]=gray; d[s]=0; p[s]=nil; enqueue(q, s); while Q not empty u = gettopqueue(q); for each v adjacent to u if(color[v] == WHITE) color[v] = GREY; d[v] = d[u] + ; p[v] = u; enqueue(q, v); color[u] = BLACK; CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Breath First Search Parallel BFS? for each vertex v in V-{s} color[v]=white; d[v]=oo; p[v]=nil; color[s]=gray; d[s]=0; p[s]=nil; enqueue(q, s); while Q not empty u = gettopqueue(q); for each v adjacent to u if(color[v] == WHITE) color[v] = GREY; d[v] = d[u] + ; p[v] = u; enqueue(q, v); color[u] = BLACK; Primite task: enumerate out-edges of a vertex. Distributed adjacency list Problems: shared global queue vertex coloring CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Distributed Queue Fundamental operations: gettopqueue: retrieves from top of queue enqueue: add to end of queue empty: signals termination CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Distributed Queue Fundamental operations: gettopqueue: retrieves from top of queue enqueue: add to end of queue empty: signals termination Distributed queue: each node stores a local queue. gettopqueue: always from local queue enqueue: local if owner, otherwise sends to owner empty: wait for remote sends CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Vertex Coloring Store data on the node that owns the vertex (or edge). Two alternatives: send message request color of a remote node CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Vertex Coloring Store data on the node that owns the vertex (or edge). Two alternatives: send message request color of a remote node send message if color of remote node is locally changed CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Vertex Coloring Store data on the node that owns the vertex (or edge). Two alternatives: send message request color of a remote node send message if color of remote node is locally changed Or: keep local copies of adjacent nodes CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Vertex Coloring Store data on the node that owns the vertex (or edge). Two alternatives: send message request color of a remote node send message if color of remote node is locally changed Or: keep local copies of adjacent nodes broadcast message if color of a node (any node) is changed CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Vertex Coloring Store data on the node that owns the vertex (or edge). Two alternatives: send message request color of a remote node send message if color of remote node is locally changed Or: keep local copies of adjacent nodes broadcast message if color of a node (any node) is changed Some problems may require arbitration when the data of a node is changed. CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Review Problems Described on Graphs Graph Representations Parallel Graph Algorithms Connected Components Maximal Independent Set Breath First Search CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /

Next Class parallel sorting CPD (DEI / IST) Parallel and Distributed Computing 0-0-0 /