CSCI-455/552 Introduction to High Performance Computing Lecture 18.

Slides:



Advertisements
Similar presentations
Chapter 5: Tree Constructions
Advertisements

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
Chapter 9: Graphs Shortest Paths
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
CSCI-455/552 Introduction to High Performance Computing Lecture 11.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Topological Sort Topological sort is the list of vertices in the reverse order of their finishing times (post-order) of the depth-first search. Topological.
1 Theory I Algorithm Design and Analysis (10 - Shortest paths in graphs) T. Lauer.
1 Load Balancing and Termination Detection ITCS 4/5145 Parallel Programming, UNC-Charlotte, B. Wilkinson, 2009.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Parallel Programming: Techniques and Applications Using Networked Workstations and Parallel Computers Chapter 7: Load Balancing and Termination Detection.
EECC756 - Shaaban #1 lec # 8 Spring Synchronous Iteration Iteration-based computation is a powerful method for solving numerical (and some.
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Shortest path algorithm. Introduction 4 The graphs we have seen so far have edges that are unweighted. 4 Many graph situations involve weighted edges.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
EECC756 - Shaaban #1 lec # 9 Spring Synchronous Iteration (Synchronous Parallelism) : –Barriers: Counter Barrier Implementation. Tree Barrier.
The Shortest Path Problem
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms Shortest-Path.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
Load Balancing and Termination Detection Load balance : - statically before the execution of any processes - dynamic during the execution of the processes.
WAN technologies and routing Packet switches and store and forward Hierarchical addresses, routing and routing tables Routing table computation Example.
Graph Algorithms. Definitions and Representation An undirected graph G is a pair (V,E), where V is a finite set of points called vertices and E is a finite.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Data Structures and Algorithms Ver. 1.0 Session 17 Objectives In this session, you will learn to: Implement a graph Apply graphs to solve programming problems.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
CSCI-455/552 Introduction to High Performance Computing Lecture 13.
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.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
Most of contents are provided by the website Graph Essentials TJTSD66: Advanced Topics in Social Media.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
CSCI-455/552 Introduction to High Performance Computing Lecture 23.
Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
CSCI-455/552 Introduction to High Performance Computing Lecture 21.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Load Balancing and Termination Detection
Shortest Path Graph represents highway system Edges have weights
Graphs & Graph Algorithms 2
Graphs Chapter 11 Objectives Upon completion you will be able to:
CSE 373: Data Structures and Algorithms
Shortest Path Algorithms
Slide Courtesy: Uwash, UT
CSE 373: Data Structures and Algorithms
CSE 373 Data Structures and Algorithms
Slide Courtesy: Uwash, UT
Introduction to High Performance Computing Lecture 16
Introduction to High Performance Computing Lecture 17
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Chapter 9: Graphs Shortest Paths
Presentation transcript:

CSCI-455/552 Introduction to High Performance Computing Lecture 18

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 2 Load balancing/termination detection Example Shortest Path Problem Finding the shortest distance between two points on a graph. It can be stated as follows: Given a set of interconnected nodes where the links between the nodes are marked with “weights,” find the path from one specific node to another specific node that has the smallest accumulated weights.

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 3 The interconnected nodes can be described by a graph. The nodes are called vertices, and the links are called edges. If the edges have implied directions (that is, an edge can only be traversed in one direction, the graph is a directed graph.

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 4 Graph used to find solution to many different problems; eg: 1.Shortest distance between two towns or other points on a map, where the weights represent distance 2.Quickest route to travel, where weights represent time ( quickest route may not be shortest route if different modes of travel available; for example, flying to certain towns) 3.Least expensive way to travel by air, where weights represent cost of flights between cities (the vertices) 4.Best way to climb a mountain given a terrain map with contours 5.Best route through a computer network for minimum message delay (vertices represent computers, and weights represent delay between two computers) 6.Most efficient manufacturing system, where weights represent hours of work

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 5 “The best way to climb a mountain” will be used as an example.

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 6 Example: The Best Way to Climb a Mountain

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 7 Graph of mountain climb Weights in graph indicate amount of effort that would be expended in traversing the route between two connected camp sites. The effort in one direction may be different from the effort in the opposite direction (downhill instead of uphill!). (directed graph)

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 8 Graph Representation Two basic ways that a graph can be represented in a program: 1. Adjacency matrix — a two-dimensional array, a, in which a[i][j] holds the weight associated with the edge between vertex i and vertex j if one exists 2. Adjacency list — for each vertex, a list of vertices directly connected to the vertex by an edge and the corresponding weights associated with the edges Adjacency matrix used for dense graphs. Adjacency list used for sparse graphs. Difference based upon space (storage) requirements. Accessing the adjacency list is slower than accessing the adjacency matrix.

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 9 Representing the graph

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 10

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 11 Searching a Graph Two well-known single-source shortest-path algorithms: Moore’s single-source shortest-path algorithm (Moore, 1957) Dijkstra’s single-source shortest-path algorithm (Dijkstra, 1959) which are similar. Moore’s algorithm is chosen because it is more amenable to parallel implementation although it may do more work. The weights must all be positive values for the algorithm to work.

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 12 Moore’s Algorithm Starting with the source vertex, the basic algorithm implemented when vertex i is being considered as follows. Find the distance to vertex j through vertex i and compare with the current minimum distance to vertex j. Change the minimum distance if the distance through vertex i is shorter. If d i is the current minimum distance from source vertex to vertex i and w i,j is weight of edge from vertex i to vertex j: d j = min(d j, d i + w i,j )

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 13 Moore’s Shortest-path Algorithm

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 14 Data Structures First-in-first-out vertex queue created to hold a list of vertices to examine. Initially, only source vertex is in queue. Current shortest distance from source vertex to vertex i stored in array dist[i]. At first, none of these distances known and array elements are initialized to infinity.

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 15 Code Suppose w[i][j] holds the weight of the edge from vertex i and vertex j (infinity if no edge). The code could be of the form newdist_j = dist[i] + w[i][j]; if (newdist_j < dist[j]) dist[j] = newdist_j; When a shorter distance is found to vertex j, vertex j is added to the queue (if not already in the queue), which will cause vertex j to be examined again - Important aspect of this algorithm, which is not present in Dijkstra’s algorithm.

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 16 Stages in Searching a Graph Example The initial values of the two key data structures are

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 17 After examining A to

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 18 After examining B to F, E, D, and C::

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 19 After examining E to F 51

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 20 After examining D to E: 51

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 21 No more vertices to consider. Have minimum distance from vertex A to each of the other vertices, including destination vertex, F. Usually, path required in addition to distance. Then, path stored as distances recorded. Path in our case is A -> B -> D -> E ->F. After examining C to D: No changes. After examining E (again) to F :

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 22 Sequential Code Let next_vertex() return the next vertex from the vertex queue or no_vertex if none. Assume that adjacency matrix used, named w[ ][ ].

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 23 Parallel Implementations Centralized Work Pool Centralized work pool holds vertex queue, vertex_queue[] as tasks. Each slave takes vertices from vertex queue and returns new vertices. Since the structure holding the graph weights is fixed, this structure could be copied into each slave, say a copied adjacency matrix.

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 24

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 25

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 26 Decentralized Work Pool Convenient approach is to assign slave process i to search around vertex i only and for it to have the vertex queue entry for vertex i if this exists in the queue. The array dist[ ] distributed among processes so that process i maintains current minimum distance to vertex i. Process also stores adjacency matrix/list for vertex i, for the purpose of identifying the edges from vertex i.

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 27 Search Algorithm Vertex A is the first vertex to search. The process assigned to vertex A is activated. This process will search around its vertex to find distances to connected vertices. Distance to process j will be sent to process j for it to compare with its currently stored value and replace if the currently stored value is larger. In this fashion, all minimum distances will be updated during the search. If the contents of d[i] changes, process i will be reactivated to search again.

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 28 Distributed graph search

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 29

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 30

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M Pearson Education Inc. All rights reserved. 31 Mechanism necessary to repeat actions and terminate when all processes idle - must cope with messages in transit. Simplest solution Use synchronous message passing, in which a process cannot proceed until destination has received message. Process only active after its vertex is placed on queue. Possible for many processes to be inactive, leading to an inefficient solution. Impractical for a large graph if one vertex is allocated to each processor. Group of vertices could be allocated to each processor.