Download presentation
Presentation is loading. Please wait.
Published byMaximilian Pitts Modified over 9 years ago
1
Parallel Programming: All-Pairs Shortest Path CS599 David Monismith Based upon notes from multiple sources
2
All-Pairs Shortest Path Recall from last time that rather than finding the shortest path from one vertex to all other vertices, we may be interested in finding the shortest paths between all pairs of vertices. To do so, we will investigate Floyd’s Algorithm, which is one method for finding an all-pairs shortest path. Thereafter, we will investigate depth-first search.
3
Floyd’s Algorithm Floyd’s algorithm finds the shortest path from every vertex in a graph to every other vertex in the graph, if such paths exist. This algorithm requires that there be no negative cycles in the graph, however, negative edges may be included. We will make use of the adjacency matrix to implement Floyd’s algorithm.
4
Adjacency Matrix Recall that the adjacency matrix can be represented as follows: – A i,j = 0, if i == j – A i,j = w i,j, if an edge exists between vertices i and j – A i,j = ∞, if no edge exists between vertices i and j Similarly, an adjacency list can be created by storing only the values for which edges exist.
5
Floyd’s Algorithm – Recursive Definition The shortest path from point i to point j is either: – The length of the path “as is”: A ij, or – The length of the paths from i to k and from k to j including the intermediate point k – A ik + A kj Thus at any given timestep, A ij (t) can be defined as: – A ij (t) = min(A ij (t-1), A ik (t-1) + A kj (t-1) )
6
Floyd’s Algorithm – Pseudocode Fill adjacency matrix Fill pointer matrix with -1’s for k = 0 to |V| - 1 for i = 0 to |V| - 1 for j = 0 to |V| - 1 adj[i][j] = min(adj[i][j], adj[i][k]+adj[k][j]; pointer[i][j] = k; end for
7
Floyd’s Algorithm - Complexity Complexity of Floyd’s algorithm is quite obvious O(V 3 ) with space complexity of at most O(V 2 ).
8
Floyd’s Algorithm – Parallelization Parallelization of Floyd’s algorithm can be accomplished on a row level basis. This requires using a double buffering strategy. It also requires work be evenly distributed between processes and that the rows stored by each process be broadcast to the remaining processes.
9
Parallel Floyd’s Algorithm – Pseudocode Fill adjacency matrix Fill pointer matrix with -1’s for k = 0 to |V| - 1 out = out - 1, in = out - 1 for i = rank*|V|/p to rank*|V|/p + |V|/p for j = 0 to |V| - 1 adj[out][i][j] = min(adj[in][i][j], adj[in][i][k]+adj[in][k][j]); end for broadcast row k to other processes from the process that is currently working on it. end for
10
References Floyd-Warshall Algorithm http://en.wikipedia.org/wiki/Floyd%E2%80%9 3Warshall_algorithm http://en.wikipedia.org/wiki/Floyd%E2%80%9 3Warshall_algorithm Case-Study: Shortest Path Algorithms - http://www.mcs.anl.gov/~itf/dbpp/text/node 35.html http://www.mcs.anl.gov/~itf/dbpp/text/node 35.html Floyd’s Algorithm - http://webpages.uncc.edu/ras/courses/Floyd. ppt http://webpages.uncc.edu/ras/courses/Floyd. ppt
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.