Docsity

Graph Algorithms - Parallel Computing - Lecture Slides, Slides of Parallel Computing and Programming

Partial preview of the text

Download Graph Algorithms - Parallel Computing - Lecture Slides and more Slides Parallel Computing and Programming in PDF only on Docsity!

Graph Algorithms

2

Topics for Today

Terminology and graph representations

Minimum spanning tree

—Prim's algorithm

Single-source shortest paths

—Dijkstra's Algorithm

All-Pairs shortest paths

Transitive closure

Connected components

4

Directed and Undirected Graph Examples

undirected graph directed graph

5

More Terminology

Connected undirected graph

—every pair of vertices is connected by a path.

Forest: an acyclic graph

Tree: a connected acyclic graph

Weighted graph : graph with edge weights

Common graph representations

—adjacency matrix

—adjacency list

7

Adjacency List for Graph G = (V,E)

An array Adj[1..| V |] of lists

—each list Adj[v] is a list of all vertices adjacent to v

Requires Θ(|E|) space

Undirected graph

Adjacency list

representation

8

Minimum Spanning Tree

Spanning tree of a connected undirected graph G

—subgraph of G that is a tree containing all the vertices of G

—if graph is not connected: spanning forest

Weight of a subgraph in a weighted graph

— sum of the weights of the edges in the subgraph

Minimum spanning tree (MST) for weighted undirected graph

—spanning tree with minimum weight

10

Computing a Minimum Spanning Tree

Prim's sequential algorithm

// initialize spanning tree vertices V

T

with vertex r, the designated root

// compute d[:], the

// weight between

// r and each

// vertex outside V

T

// use d[:] to find u,

// vertex closest to T

// add u to T

// recompute d[:] now

// that u is in T

// while there are vertices outside T

11

Minimum Spanning Tree: Prim's Algorithm

3 iterations of Prim’s algorithm

start with arbitrary root

13

Parallel Formulation of Prim's Algorithm

distance array

adjacency matrix

partition d and A among p processes

Data partitioning

  • partition adjacency matrix in a 1-D block fashion (blocks of columns)
  • partition distance vector d accordingly

Parallel Formulation of Prim's Algorithm

In each step,

—each process first identifies the locally closest node

—perform a global reduction to select globally closest node

  • minloc reduction: node id and distance

—leader inserts node into MST

—broadcasts choice to all processes

—each process updates its part of d vector locally based on choice

14

16

17

Single-Source Shortest Paths

Given weighted graph G = (V,E,w)

Problem: single-source shortest paths

find the shortest paths from vertex v ∈ V to all other vertices in V

Dijkstra's algorithm: similar to Prim's algorithm

—maintains a set of nodes for which the shortest paths are known

—grows set by adding node closest to source using one of the

nodes in the current shortest path set

19

Parallel Formulation of Dijkstra's Algorithm

Similar to parallel formulation of Prim's algorithm for MST

Approach

—data partitioning

  • partition weighted adjacency matrix in a 1-D block fashion
  • partition distance vector L accordingly

—in each step,

  • each process identifies its node closest to source
  • perform a global reduction to select globally closest node

use a MINLOC reduction, after which everyone knows (u, L[u])

  • each process updates its part of L vector locally

Parallel performance of Dijkstra's algorithm

— identical to that of Prim's algorithm

  • parallel time per iteration: O(n/p + log p)
  • total parallel time: O(n

2

/p + n log p)

20

All-Pairs Shortest Paths

Given weighted graph G(V,E,w)

Problem: all-pairs shortest paths

— find the shortest paths between all pairs of vertices v

i

, v

j

∈ V

Several algorithms known for solving this problem