Upload
others
View
21
Download
0
Embed Size (px)
Citation preview
A Multi-Source Label-Correcting Algorithm for the All-Pairs Shortest Paths Problem
Hiroki Yanagisawa
(IBM Research – Tokyo)
All-Pairs Shortest Paths (APSP) Problem
• Compute shortest path length for every pair of nodes
B
CE
D
5
2
3
4
3
2
A
2
0
5
3
5
D ECBA
7520A
0357E
2535D
3045C
5402Bfrom
to
Input: Graph with edge lengths• n = (# nodes)• m = (# edges)
Output: Distance matrix
Repeating Dijkstra’s Algorithm
• Multiple runs of single-source shortest path algorithm
– We often use Dijkstra’s algorithm
• O(mn + n log n) time and O(m + n) space
– Hereafter, we call this algorithm as n-Dijkstra algorithm
D ECBA
A
E
D
C
Bfrom
to
Compute for A
Compute for B
Compute for C
Compute for D
Compute for E
B
CE
D
5
2
3
4
3
2
A
Contribution
• Faster algorithm for APSP on sparse graphs
– 10 times or more faster (with SIMD) than n-Dijkstraalgorithm
– O(m+n) working space
– Essentially equivalent to Hilger’s centralized algorithm (given in 2007)
• We were not aware of this algorithm (thanks to an anonymous reviewer)
• Its SIMD implementation
– 2.3 – 3.7 times faster than scalar implementation
– Hilger did not give SIMD implementation
– As far as we know, first acceleration with SIMD instructions for sparse graph
• In contrast to many SIMD implementations for dense graphs
Inefficiency of n-Dijkstra
• n-Dijkstra algorithm does not use information on the shortest paths from other source nodes
D ECBA
A
E
D
C
Bfrom
to
Compute for A
Compute for B
Compute for C
Compute for D
Compute for E
Independent of each otherIndependent to each other
B
CE
D
5
2
3
4
3
2
A
shortest path
shortest
Idea
• Source nodes are close to each other
shortest path trees are similar
we can efficiently compute them at the same time!
A
B
13
2
2
5
5
2
6
1
4
3
2
6
1
3
A
B
13
2
2
5
5
2
6
1
4
3
2
6
1
3
⇒
⇒
Our algorithm
• Multiple runs of multi-source shortest paths algorithm
D ECBA
A
E
D
C
Bfrom
to
Compute forA, B, and C
Compute forD and E
B
CE
D
5
2
3
4
3
2
A
Partition graph
Dijkstra’s algorithm
• Single-source shortest path
0
?
??
?
?
?
?
?
1
3
2
2
5
5
2
6
1
4
3
2
6
1
32
3
1
0
1
6
2 6
38
55
11
69
8
10
9
10
: in priority queue
: unvisited
Extension of Dijkstra’s Algorithm
• Dijkstra’s algorithm– Each node is associated with single label
– Label corresponds to distance label
– Node with minimum label is extracted from priority queue
• Our algorithm for multi-source case– Each node is associated with single key label and distance label for each source node
– Node with minimum key label is extracted from priority queue
– Key label is set to the minimum of distance labels
?6
6,7,…
Distance labels
Key label
?6
Label
Algorithm for Multi-Source Shortest Path
• Multi-source shortest paths
– For case with two source nodes
0
?
??
?
?
0
?
?
1
3
2
2
5
5
2
6
1
4
3
2
6
1
32
3
0,?
?,0
2,?
0
0
3,?
1,0
5
6,5
0
0,12
3,2
0
2,3
2 6
6,7
27
8,7
4
5,4
4
7
11,10
69
9,10
7
8
9,8
9
10,9
8
9
: in priority queue
: unvisited
Extension for Many Source Nodes
• Easy to extend for case # source nodes is B (>2)
• There are tradeoffs– Pros: The # extraction from priority queue may decrease by a
factor of B• Only one extraction from priority queue in best case, whereas B runs of Dijkstra’s algorithm needs B extractions from priority queue
– Cons: Each scan operation takes O(B) time
• Our experiment shows B=128 is best
5
3,1,…,4
1 ?
0
0
0
…
?,?,…,?
5
3,1,…,4
1 6
0
0
0
…
8,6,…,9
scan
B
Key Selection Rule
• Any key rule outputs correct answer– Key label should be closeness from source nodes– Minimum key rule is the best one in our experiments
53,1
1 ?
?,?
53,1
1 6
8,6scan
53,1
1 8
8,6
Maximum key rule
53,1
1 7
8,6
Average key rule
Minimum key rule
Label-Setting/Correcting Algorithms
• Dijkstra’s algorithm is classified as label-setting algorithm– Easy to analyze worst-case computation time
scanned labeled
scanned labeled
• Our algorithm is classified as label-correcting algorithm– Difficult to analyze worst-case computation time
Time Complexity
• Our algorithm terminates in finite time
• No theoretical time bound were given for
– Minimum key rule
– Average key rule
– Maximum key rule
• Hilger gave worst-case running time for another key rule (minimum tentative key)
– O(B (m+n log n)) time• The same as B runs of Dijkstra’s algorithm
– However slower than minimum key rule (from experiments by Hilger)
SIMD implementation
• Each scan operation can be easily SIMDized
2
3,4,7,7,6,5,2,1,3,……………………………………,51
4 4,8,9,7,4,5,6,6,6,……………………………………,4
5,6,9,9,8,7,4,3,5,……………………………………,7
+2 (SIMD)
compare (SIMD)
4,6,9,7,4,5,4,3,5,……………………………………,4
Compute minimum (SIMD)
3
B labels
Our algorithm
• Multiple runs of multi-source shortest path algorithm
D ECBA
A
E
D
C
Bfrom
to
Compute forA, B, and C
Compute forD and E
B
CE
D
5
2
3
4
3
2
A
Partition graph
Graph Partitioning
• Repeating following procedure
– Pick up a node and traverse nearby nodes
• BFS is the best (among BFS, DFS, and kNN traverses)
• Times for graph partitioning are negligible
2
3
5
8
4
1
2
6
2
9
6
7
Ex. B =3
Experiment: Single-Thread
• Our algorithm clearly outperforms n-Dijkstra algorithm
• SIMD implementation accelerates scalar version 2.3 – 3.7 times
0
5
10
15
20
25
30
35
Grid16x8192 Grid256x256 HI AK VT
n-Dijkstra
Ours (scalar)
Ours (SIMD)
We used B = 128, BFS partitioning, and minimum key ruleMachine: Quad Core Xeon 3.16 GHz on Windows Server 2003
Grid graphs Road
networks in US
Speedup
Experiment: Single-Thread (cont.)
• The acceleration is due to the decrease of # operation on priority queue– In best case, this number is decreased by a factor of B
We used B = 128, BFS partitioning, and minimum key ruleMachine: Quad Core Xeon 3.16 GHz on Windows Server 2003
Best case
0
20
40
60
80
100
120
140
Grid16x8192 Grid256x256 HI AK VT
Experiment: Multiple-Thread
• Parallel speedup with multi-thread implementation
0
1
2
3
4
1 2 3 4 1 2 3 4
VT
Grid16x8192
Grid256x256
Scalar SIMD
We used B = 128, BFS partitioning, and minimum key ruleMachine: Quad Core Xeon 3.16 GHz on Windows Server 2003
Speedup
# threads
Improving Initializations
• Hilger suggested using better initializations yields 1 – 3 times faster running time
0
?
?
?
0
1
3
2
2
5
2
1
0,?
?,0
0
?
?
?
0
1
3
2
2
5
2
1
0,1
1,0
No initialization
No initialization
Initialize with
shortest path lengths
Initialize with
shortest path lengths
Our algorithm Hilger’s algorithm
Many-to-Many Shortest Paths
• It is trivial to extend our algorithm for many-to-many shortest paths problem
A
B
C
D
E
13
2
2
5
5
2
6
1
4
3
2
6
1
3
5
0
7
5
6
D ECBA
10530A
06710E
5756D
6025C
7203Bfrom
to
Summary
• Results
– We give fast algorithm for APSP on sparse graph and its SIMD implementation
– First SIMD acceleration for sparse graph
• Future work
– Thorough investigations of our algorithm for the many-to-many shortest paths problem