Allpairs shortest paths: Floyds Algorithm - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Allpairs shortest paths: Floyds Algorithm

Description:

All-pairs shortest paths: Floyd's Algorithm. G = (V, E, w), V = {v1, v2, ..., vn} ... the length of the shortest path from vi to vj whose intermediate vertices belong ... – PowerPoint PPT presentation

Number of Views:226
Avg rating:3.0/5.0
Slides: 22
Provided by: euns1
Category:

less

Transcript and Presenter's Notes

Title: Allpairs shortest paths: Floyds Algorithm


1
All-pairs shortest paths Floyds Algorithm
  • G (V, E, w), V v1, v2, , vn
  • For a subnet v1, v2, , vk, k n,
  • the length of the shortest path from vi
    to vj whose intermediate vertices belong to the
    set v1, v2, , vk
  • Matrix

2
The matrix D (0)
G original graph
A the weighted adjacency matrix for G
1
2
3
4
1
1
1
3
2
5
AD(0)
2
3
3
1
4
2
4
3
The matrix D (0)
the length of the path from 1 to 3 is 3
  • Consider all paths going through the vertex 1 in
    D(0)
  • Example)

1
2
3
4
1
1
1
3
2
5
D(0)
2
3
3
the length of the path from 2 to 1 is 1
1
4
2
4
4
The matrix D (1)
  • Consider all paths going through the vertex 1in
    D(0)
  • Example)

1
2
3
4
1
1
1
3
4
2
5
D(0)
2
3
3
1
4
2
4
5
The matrix D(1)
  • Consider all paths going through the vertex 1 in
    D(0)

1
2
3
4
1
1
1
3
4
2
5
D(1)
2
4
3
3
1
4
2
4
6
The matrix D(2)
  • Consider all paths going through the vertex 2 in
    D(1)
  • Example)

1
2
3
4
1
1
1
3
2
5
D(1)
2
3
3
1
4
2
4
7
The matrix D(2)
  • Consider all paths going through the vertex 2 in
    D(1)

1
2
3
4
1
2
1
1
3
2
5
D(2)
2
3
3
2
1
4
2
4
8
The matrix D(3)
  • Consider all paths going through the vertex 3 in
    D(2)

1
2
3
4
1
1
1
3
2
5
D(3)
2
3
3
1
4
2
4
9
The matrix D(4)
  • Consider all paths going through the vertex 4 in
    D(3)

1
2
3
4
1
1
1
3
3
2
5
D(4)
2
3
3
3
1
4
2
4
10
Parallel Formulation
1
2
3
4
  • D(k) is partitioned into p parts
  • Each processor computes a partition of D(k)

1
2
3
4
p 4
11
2-D Block Mapping
  • Matrix D(k) is divided into p blocks of size
  • Each block is assigned to one of the p processors

n 8, p 16
D(k)
12
2-D Block Mapping
  • Example)

1
2
3
4
P1,2
P1,1
1
1
1
3
2
5
D(0)
2
3
3
1
4
2
4
P2.1
P2,2
13
The matrix D(1)
  • Consider all paths going through the vertex 1 in
    D(0)

1
2
3
4
P1,2
P1,1
1
1
1
3
2
5
D(1)
2
3
3
1
4
2
4
P2.1
P2,2
one-to-all broadcast
14
The matrix D(2)
  • Consider all paths going through the vertex 2 in
    D(1)

1
2
3
4
P1,2
P1,1
1
1
1
3
2
5
D(2)
2
3
3
1
4
2
4
P2.1
P2,2
one-to-all broadcast
15
The matrix D(3)
  • Consider all paths going through the vertex 3 in
    D(2)

1
3
2
4
P1,2
P1,1
1
1
1
3
2
5
D(3)
2
3
3
1
4
2
4
P2.1
P2,2
one-to-all broadcast
16
The matrix D(4)
  • Consider all paths going through the vertex 4 in
    D(3)

1
3
2
4
P1,2
P1,1
1
1
1
3
2
5
D(4)
2
3
3
1
4
2
4
P2.1
P2,2
one-to-all broadcast
17
Performance
  • Parallel computer with a cross-bisection
    bandwidth of ?(p)
  • Example) bisection width of hypercube is p/2
  • On the kth iteration,

k (5) column
Each processor sends elements of the
5th row or column
D(5)
k (5) row
18
Communication time
  • On the kth iteration,
  • (phase 1) each row performs one-to-all broadcast
    at the same time
  • (phase 2) each column performs one-to-all
    broadcast at the same time

k (5) column
This broadcast requires
D(5)
k (5) row
19
Time complexity of Floyds algorithm (parallel)
  • On the kth iteration,
  • Each processor is assigned n2/p elements of D(k)
  • The time to compute corresponding D(k) values is
    ?(n2/p).
  • The broadcast requires
  • The parallel run time is

computation
communication
20
Speedup and Efficiency
  • Speedup
  • Efficiency

21
Cost-optimal
  • For a cost-optical parallel formulation,
  • the cost of solving ASP in parallel grows at he
    same rate as does the cost of the serial
    algorithm.
Write a Comment
User Comments (0)
About PowerShow.com