Documente Academic
Documente Profesional
Documente Cultură
Overview
Graphs - definitions, properties, representation
Minimal spanning tree
Prims algorithm
Shortest path (1-to-all)
Dijkstras algorithm
Shortest path (all pairs)
Algorithm based on matrix multiplication
Dijkstras algorithm
Source partitioned
Source parallel
Floyds algorithm
Transitive closure
Connected components
Parallella grafalgoritmer
Graphs - definitions
Examples of graphs
Undirected graph:
G(V, E): V is the set of vertices and E is the set of edges
An edge e E is an unordered pair (u, v) where u,v V
Directed graph:
An edge e E is an ordered pair (u, v) (from u to v) where u,v V
A path from u to v is a sequence (u, ..., v) of vertices where
consecutive vertices in the sequence corresponds to an edge in the
graph
Simple path: all vertices in the path are distinct
Cycle: u = v
Acyclic: contains no cycles
Parallella grafalgoritmer
Parallella grafalgoritmer
Graphs - properties
om (v i , v j ) E
annars
a i, j =
Weighted graph
w (v i , v j ) om (v i ,v j ) E
a i, j = 10
om i = j
annars
0
Suitable for
dense graphs
Weighted graphs:
G(V, E, w), where w is a real valued function defined on E (every
existing edge has a value)
The weight of the graph is the sum of the weights of its edges
Parallella grafalgoritmer
Parallella grafalgoritmer
Suitable for
sparse graphs
Parallella grafalgoritmer
Parallella grafalgoritmer
10
Prims algoritm
Parallella grafalgoritmer
Update d-values
Parallella grafalgoritmer
11
12
Start node: b
Parallella grafalgoritmer
Parallella grafalgoritmer
13
14
Updating:
...
for all v (V - VT ) that I own
d[v] = min{d[v], w(u, v)}
end
Parallella grafalgoritmer
Parallella grafalgoritmer
15
16
Parallella grafalgoritmer
Parallella grafalgoritmer
17
18
na +b
cij = minkk =
kj
= 1 ik
Compute the result Dn-1 by computing A2, A4, A8,... An-1, with the
modified matrix multiplication in log n steps
Parallella grafalgoritmer
Parallella grafalgoritmer
19
20
Source-partitioned
Every processor get one vertex and solves the 1-vertex-problem
sequentially for that vertex
No communication
Is optimal from a communication point of view, but can only use
n processors
Also requires p times as much memory!
Parallella grafalgoritmer
Parallella grafalgoritmer
21
22
Source-parallel
The processors are divided into n partitionseach with p/n processors
(p > n)
Each partition solves the 1-vertex-problem for 1 vertex with the
parallel 1-vertex-algorithm 2 levels of parallelism:
Coarse grain: Every node in the graph is handled independently of the others
Fine grain: p/n processors share the work with one vertex
On a 2-dimensionell mesh:
p1/2 x p1/2 mesh is divided into partitions each with (p/n)1/2 x (p/n)1/2
processors
No communication between processor groups
The parallel 1-vertex-algorithm for a 2-dimensionell mesh within
each group
Parallella grafalgoritmer
If the vertex vk is not in the path then pijk is the same as pijk-1
If vk is in the path then the path can be split into two paths: One
from v1 to vk and one from vk to vj where both paths uses
vertices in Vk-1 = {v1, v2, ..., vk-1}
I that case the the weight of the path is dijk = dijk-1 + dkjk-1
Parallella grafalgoritmer
23
k
dij =
k 1 k 1 k 1
1
min{dij , dik + dkj } om k 0
Parallella grafalgoritmer
24
Parallella grafalgoritmer
25
26
Parallella grafalgoritmer
Parallella grafalgoritmer
27
Transitive closure
If G = (V, E) is a graph then its transitive closure is a graph G* =
(V, E*), where E* = {(vi, vj)| exists a path from vi to vj in G}
Compute the connectivity-matrix A* such that
aij = 1 if i = j or a path from vi to vj exists and
aij = otherwise.
Method 1:
Set the weights in G to 1 and compute the shortest path
between all pairs. Interpret the resultat D such that
dij =
aij = and
i = j or dij > 0
aij = 1
(=> A*)
Method 2:
Modify Floyds algorithm by changing min and+ on line 7 to
logical or and logical and. dij(k) = dij(k-1) OR (dik(k-1) AND dkj(k-1))
Parallella grafalgoritmer
28
Connected Components
Depth-first-search based
algorithm:
- Given a forest of depth-first trees
- Each tree only contains
components that does not belong to
another tree
Parallella grafalgoritmer
(Start i 1)
(Start i 9)
29
30
Given the spanning forests A and B is the following done for each
edge (u, v) in A:
If the vertices u and v are in the same tree in B do nothing
Otherwise, take Bs tree containing u and unite with Bs tree with v
Parallella grafalgoritmer
Parallella grafalgoritmer
31
32
Work distribution
Matrix representation
The matrix is evenly distributed on the processors
Balanced work load
Little communication (each processor have consecutive rows/columns)
List representation
The number of lists are distributed evenly on the proc.
Can give an unbalanced work load as the lists often are of different length
The number of edges are distributed evenly on the proc.
May demand that the lists are shared between processors ==> increased
communication
Parallella grafalgoritmer
Parallella grafalgoritmer
33
34
Johnsons algorithm
Parallella grafalgoritmer
35
Parallella grafalgoritmer
36
from s to v
executes Johnsons algorithm on their own subgraph
Parallella grafalgoritmer
37
38
If l[u] + w(u,w) sp[v] then the already found path is shorter. Then Pj does
not have to do anything.
If sp[v] > l[u] + w(u,w) then the path via u is shorter than the shortest path
found so far.
Pj lets l[v] = l[u] + w(u,w), removes the value of sp[v] and puts back v into Qj.
Parallella grafalgoritmer
Parallella grafalgoritmer
39
40
Parallella grafalgoritmer
Parallella grafalgoritmer
41
Parallella grafalgoritmer
42
Parallella grafalgoritmer