Parallelization of Dijkstra's Algorithm
Parallelization of Dijkstra's Algorithm
Dijkstra's algorithm
Salvator Gkalea
Department ICT/ES
KTH
[email protected]
Dionysios Zelios
Department of Physics
Stockholm University
[email protected]
Contents
Abstract ..................................................................................................................................... 3
Introduction ............................................................................................................................... 3
Dijkstra's Parallelization ............................................................................................................ 5
Simulation results and analysis ................................................................................................. 8
References ............................................................................................................................... 14
Abstract
Dijkstra's algorithm is a graph search algorithm that solves the singlesource shortest path problem for a graph with non-negative edge path
costs, producing a shortest path tree. This algorithm is often used in
routing and as a subroutine in other graph algorithms. In this project we
investigate the parallelization of this algorithm and its speedup against
the sequential one. Message Passing Interface (MPI) is used for this
purpose, in order to parallelize the source-shortest path algorithm.
Introduction
Dijkstras algorithm determines the shortest path from a single source
vertex to every other vertex. It can also be used for finding costs of
shortest paths from a single vertex to a single destination vertex by
stopping the algorithm once the shortest path to the destination vertex
has been determined. For instance, if the vertices of the graph represent
cities and edge path costs represent driving distances between pairs of
cities connected by a direct road, Dijkstra's algorithm can be used to find
the shortest route between one city and all other cities.
A pseudo-code representation of the Dijkstra's sequential single-source
shortest-paths Algorithm is given. The pseudo-algorithm proceeds as
follows:
1. function Dijkstra(V, E, w, s)
2. begin
3.
VT := {s};
4.
for all v exists in (V - VT) do
5.
if (s, v) exists
set l[v] := w(s, v);
6.
else
set l[v] := infinitive;
end for
7.
while VT V do
8.
begin
9.
find a vertex u such that l[u] :=
min{l[v]|v exists in (V - VT)};
10.
VT := VT joint {u};
11.
for all v exists in (V - VT) do
12.
l[v] := min{l[v], l[u] + w(u, v)};
13.
end while
14. end Dijkstra
MPI_Init
MPI_Finalize
Dijkstra's Parallelization
The pseudo-code mentioned above can be parallelized based on the line
9 in which the minimum distance among all the nodes is computed or
based on the line 11 where the algorithm calculates the minimum
overall distance and stores it to the local minimum distance array.
The classic approach is to break down the data that need to be
computed into segments. Then each node is responsible to process and
compute a segment of data. At the end all the results from all the
segments must be gathered at a node. The C code above demonstrates
the logic mentioned above.
#include <stdio.h>
#include <mpi.h>
int numV,
//number of vertices
*todo, //vertices to be analysed
numNodes, //number of nodes
chunk, //number of vertices handled by every node
start, end, //start, end point vertex for each node
myNode; //ID of node
unsigned maxInt,
localMin[2], // [0]: min for local node, [1]: vertex
for that min
if (0 && myNode == 0)
for (k = 1; k < numV; i++) {
printf("node[%d] = %u\n", i, minDistance[i]);
}
if (myNode == 0)
printf("elapsed: %f\n", (float) (T2 - T1));
MPI_Finalize();
}
2
0.010213
4
0.007118
8
0.008694
16
0.015567
32
0.034436
2
0.150809
4
0.092254
8
0.062077
16
0.105193
32
0.1638634
2
0.597349
4
0.352130
8
0.202681
16
0.189242
32
0.200911
2
2.077290
4
1.213774
8
0.874406
16
0.85756
32
1.056482
mesh= 64*106
Nodes
Time
(sec)
1
0.14132
mesh= 256*106
Nodes
Time
(sec)
1
0.564806
mesh=900*106
Nodes
Time
(sec)
1
1.984156
Speed up measurements
In our next step, we want to investigate the speed up of our algorithm.
In order to do that, we divided the base time in one node with time
needed for multiple nodes to be executed. The measurements and the
corresponding plot are given below:
mesh= 4*106
Nodes 1
Time 1
(sec)
2
0.889356
4
1.276060
8
1.044743
16
0.583477
32
0.263764
2
0,9370793
4
1,531857
8
2,27652
16
1,3434353
32
0,862425
2
0,945520
4
1,60397
8
2,78667
16
2,98457
32
2,81122
2
0,9551
4
1,63469
8
2,269147
16
2,3137
32
1,8780
mesh= 64*106
Nodes
Time
(sec)
1
1
mesh= 256*106
Nodes
Time
(sec)
1
1
mesh=900*106
Nodes
Time
(sec)
1
1
Cost measurements
mesh= 4*106
Nodes 1
Time 1,87807
(sec)
2
0,020426
4
0,028472
8
0,069552
16
0,249072
32
1,101952
2
0,301618
4
0,369016
8
0,496616
16
1,683088
32
5,2436288
2
1,194698
4
1,40852
8
1,621448
16
3,027872
32
6,429152
2
4,15458
4
4,855096
8
6,995248
16
13,72096
32
36,97687
mesh= 64*106
Nodes
Time
(sec)
1
0,14132
mesh= 256*106
Nodes
Time
(sec)
1
0,564806
mesh=900*106
Nodes
Time
(sec)
1
1,984156
The cost is increasing because the speed up (or the benefit of a reduced
running time) cannot outperform the cost of using more cores.
References
1) Wikipedia: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
2) Lecture notes by Erwin Laure:
http://agenda.albanova.se/conferenceDisplay.py?confId=4384
3)Han, Xiao Gang, Qin Lei Sun, and Jiang Wei Fan. "Parallel Dijkstra's
Algorithm Based on Multi-Core and MPI." Applied Mechanics and
Materials 441 (2014): 750-753.
4) http://www.mpich.org/
5) http://www.open-mpi.org/
6) Crauser, Andreas, et al. "A parallelization of Dijkstra's shortest
path algorithm."Mathematical Foundations of Computer Science
1998. Springer Berlin Heidelberg, 1998. 722-731
7) Meyer, Ulrich, and Peter Sanders. "-stepping: A parallel single
source shortest path algorithm." AlgorithmsESA98. Springer
Berlin Heidelberg, 1998. 393-404.
8)http://www.inf.ed.ac.uk/publications/thesis/online/IM040172.pdf