1 CS 240A : Breadth-first search in Cilk++ Thanks to Charles E. Leiserson for some of these slides.

Slides:



Advertisements
Similar presentations
Jecho and Donatus Depth First and Breadth First Search.
Advertisements

CS203 Lecture 15.
Graphs CSE 331 Section 2 James Daly. Reminders Homework 4 is out Due Thursday in class Project 3 is out Covers graphs (discussed today and Thursday) Due.
1 CS 240A : Numerical Examples in Shared Memory with Cilk++ Matrix-matrix multiplication Matrix-vector multiplication Hyperobjects Thanks to Charles E.
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
1 Graphs Traversals In many graph problems, we need to traverse the vertices of the graph in some order Analogy: Binary tree traversals –Pre-order Traversal.
CS 473Lecture 141 CS473-Algorithms I Lecture 14-A Graph Searching: Breadth-First Search.
Graphs - II CS 2110, Spring Where did I leave that book?
CS 473Lecture 141 CS473-Algorithms I Lecture 14-A Graph Searching: Breadth-First Search.
David Luebke 1 5/9/2015 CS 332: Algorithms Graph Algorithms.
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Breadth-First Search Seminar – Networking Algorithms CS and EE Dept. Lulea University of Technology 27 Jan Mohammad Reza Akhavan.
Zhengjin Graphs: Adjacency Matrix ● Example: a d bc A ?? 4.
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 27 Graphs and Applications.
Breadth-First and Depth-First Search
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 27 Graph Applications.
1 Graphs: Traversal Searching/Traversing a graph = visiting the vertices of a graph by following the edges in a systematic way Example: Given a highway.
Graph Search Methods Spring 2007 CSE, POSTECH. Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. A search method.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Graph Searching (Graph Traversal) Algorithm Design and Analysis Week 8 Bibliography: [CLRS] – chap 22.2 –
1 Graph Programming Gordon College. 2 Graph Basics A graph G = (V, E) –V = set of vertices, E = set of edges –Dense graph: |E|  |V| 2 ; Sparse graph:
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
UNINFORMED SEARCH Problem - solving agents Example : Romania  On holiday in Romania ; currently in Arad.  Flight leaves tomorrow from Bucharest.
Distributed Breadth-First Search with 2-D Partitioning Edmond Chow, Keith Henderson, Andy Yoo Lawrence Livermore National Laboratory LLNL Technical report.
Graphs CS-240/341. Graphs Used for representing many-to-many relationships –can take two forms directed (digraph) - a finite set of elements called vertices.
Graphs CS-240/341. Uses for Graphs computer networks and routing airline flights geographic maps course prerequisite structures tasks for completing a.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Alyce Brady CS 510: Computer Algorithms Breadth-First Graph Traversal Algorithm.
1 Data Structures and Algorithms Graphs I: Representation and Search Gal A. Kaminka Computer Science Department.
CS 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
CS 240A : Examples with Cilk++
Alyce Brady CS 510: Computer Algorithms Depth-First Graph Traversal Algorithm.
Depth-first search COMP171 Fall Graph / Slide 2 Depth-First Search (DFS) * DFS is another popular graph search strategy n Idea is similar to pre-order.
Breadth First Search (BFS) Part 2 COMP171. Graph / Slide 2 Shortest Path Recording * BFS we saw only tells us whether a path exists from source s, to.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
Tirgul 7 Review of graphs Graph algorithms: – BFS (next tirgul) – DFS – Properties of DFS – Topological sort.
David Luebke 1 8/7/2015 CS 332: Algorithms Graph Algorithms.
Search Related Algorithms. Graph Code Adjacency List Representation:
Graph Search Computing 2 COMP s1. P ROBLEMS ON G RAPHS What kinds of problems do we want to solve on/via graphs? Is there a simple path from A to.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Dijkstra’s Algorithm: single source shortest paths David Kauchak cs62 Spring 2010.
ADA: 9. Graph Search1 Objective o describe and compare depth-first and breadth- first graph searching, and look at the creation of spanning trees.
Most of contents are provided by the website Graph Essentials TJTSD66: Advanced Topics in Social Media.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Graph Algorithms Searching. Review: Graphs ● A graph G = (V, E) ■ V = set of vertices, E = set of edges ■ Dense graph: |E|  |V| 2 ; Sparse graph: |E|
Data Structures and Algorithms in Parallel Computing Lecture 3.
Depth-First Search Lecture 21: Graph Traversals
Graphs Slide credits:  K. Wayne, Princeton U.  C. E. Leiserson and E. Demaine, MIT  K. Birman, Cornell U.
CS 2133: Algorithms Intro to Graph Algorithms (Slides created by David Luebke)
7. Graph Traversal Describe and compare depth-first and breadth-first graph searching, and look at the creation of spanning trees Contest Algorithms: 7.
Chapter 05 Introduction to Graph And Search Algorithms.
Graph Theory Def: A graph is a set of vertices and edges G={V,E} Ex. V = {a,b,c,d,e} E = {ab,bd,ad,ed,ce,cd} Note: above is a purely mathematical definition.
CSC 213 – Large Scale Programming Lecture 31: Graph Traversals.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 22 Graphs and Applications.
Graphs. What is a graph? In simple words, A graph is a set of vertices and edges which connect them. A node (or vertex) is a discrete position in the.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
Graphs Representation, BFS, DFS
Data Structures and Algorithms I
Graph Traversals Some algorithms require that every vertex of a graph be visited exactly once. The order in which the vertices are visited may be important,
Unweighted Shortest Path Neil Tang 3/11/2010
CS120 Graphs.
Chapter 11 Graphs.
CS 260 Search Exercise A B C D E F G H I J K L M
Algorithms: Design and Analysis
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Presentation transcript:

1 CS 240A : Breadth-first search in Cilk++ Thanks to Charles E. Leiserson for some of these slides

2 Breadth First Search ∙Level-by-level graph traversal ∙Serially complexity: Θ(m+n) G(E,V) Graph: G(E,V) E: E: Set of edges (size m) V: V: Set of vertices (size n)

3 Breadth First Search ∙Level-by-level graph traversal ∙Serially complexity: Θ(m+n) Level

4 Breadth First Search ∙Level-by-level graph traversal ∙Serially complexity: Θ(m+n) Level 1 Level

5 Breadth First Search ∙Level-by-level graph traversal ∙Serially complexity: Θ(m+n) Level Level Level 3

6 Breadth First Search ∙Level-by-level graph traversal ∙Serially complexity: Θ(m+n) Level 1 Level Level 3 Level

7 Breadth First Search ∙Level-by-level graph traversal ∙Serially complexity: Θ(m+n) Level 1 Level Level 3 Level Level

8 Breadth First Search ∙Level-by-level graph traversal ∙Serially complexity: Θ(m+n) Level 1 Level Level 3 Level Level Level

9 Breadth First Search parent(19) ∙Who is parent(19)?  If we use a queue for expanding the frontier?  Does it actually matter? Level 1 Level Level 3 Level Level Level

10 Parallel BFS ∙Way #1: A custom reducer void BFS(Graph *G, Vertex root) { Bag frontier(root); while ( ! frontier.isEmpty() ) { cilk::hyperobject > succbag(); cilk_for cilk_for (int i=0; i< frontier.size(); i++) { for( Vertex v in frontier[i].adjacency() ) { if( ! v.unvisited() ) succbag() += v; } frontier = succbag.getValue(); } void BFS(Graph *G, Vertex root) { Bag frontier(root); while ( ! frontier.isEmpty() ) { cilk::hyperobject > succbag(); cilk_for cilk_for (int i=0; i< frontier.size(); i++) { for( Vertex v in frontier[i].adjacency() ) { if( ! v.unvisited() ) succbag() += v; } frontier = succbag.getValue(); } Bag has an associative reduce function that merges two sets operator+=(Vertex & rhs) also marks rhs “visited”

11 Parallel BFS ∙Way #2: Concurrent writes + List reducer void BFS(Graph *G, Vertex root) { list frontier(root); Vertex * parent = new Vertex[n]; while ( ! frontier.isEmpty() ) { cilk_for cilk_for (int i=0; i< frontier.size(); i++) { for( Vertex v in frontier[i].adjacency() ) { if ( ! v.visited() ) parent[v] = frontier[i]; }... } void BFS(Graph *G, Vertex root) { list frontier(root); Vertex * parent = new Vertex[n]; while ( ! frontier.isEmpty() ) { cilk_for cilk_for (int i=0; i< frontier.size(); i++) { for( Vertex v in frontier[i].adjacency() ) { if ( ! v.visited() ) parent[v] = frontier[i]; }... } An intentional data race How to generate the new frontier?

12 Parallel BFS void BFS(Graph *G, Vertex root) {... while ( ! frontier.isEmpty() ) {... hyperobject > succlist(); cilk_for cilk_for (int i=0; i< frontier.size(); i++) { for( Vertex v in frontier[i].adjacency() ) { if ( parent[v] == frontier[i] ) { succlist.push_back(v); v.visit(); // Mark “visited” } frontier = succlist.getValue(); } void BFS(Graph *G, Vertex root) {... while ( ! frontier.isEmpty() ) {... hyperobject > succlist(); cilk_for cilk_for (int i=0; i< frontier.size(); i++) { for( Vertex v in frontier[i].adjacency() ) { if ( parent[v] == frontier[i] ) { succlist.push_back(v); v.visit(); // Mark “visited” } frontier = succlist.getValue(); } Run cilk_for loop again !v.visited() check is not necessary. Why?

13 Parallel BFS ∙Each level is explored with Θ(1) span ∙Graph G has at most d, at least d/2 levels  Depending on the location of root  d=diameter(G) T 1 (n)= Θ(m+n)Work: T ∞ (n)= Θ(d)Span: Parallelism: T 1 (n) T ∞ (n) = Θ((m+n)/d)

14 Parallel BFS Caveats ∙d is usually small ∙d = lg(n) for scale-free graphs  But the degrees are not bounded  ∙Parallel scaling will be memory-bound ∙Lots of burdened parallelism,  Loops are skinny  Especially to the root and leaves of BFS-tree ∙You are not “expected” to parallelize BFS part of Homework #4  You may do it for extra credit though