Mesh Based APSP algorithm
Sathish Vadhiyar
Introduction
Mesh based Cartesian topology can
be used to solve APSP (all-pair
shortest path)
First, leading up to APSP
Prim’s MST
Dijikstra’s SSSP
Minimal Spanning Tree – Prim’s
Algorithm
Spanning tree of a graph, G (V,E) – tree
containing all vertices of G
MST – spanning tree with minimum sum
of weights
Vertices are added to a set Vt that
holds vertices of MST; Initially contains
an arbitrary vertex,r, as root vertex
Minimal Spanning Tree – Prim’s
Algorithm
An array d such that d[v in (V-Vt)] holds
weight of the edge with least weight
between v and any vertex in Vt; Initially
d[v] = w[r,v]
Find the vertex in d with minimum weight
and add to Vt
Update d
Time complexity – O(n2)
Parallelization
Vertex V and d array partitioned across P
processors
Each processor finds local minimum in d
Then global minimum across all d performed
by reduction on a processor
The processor finds the next vertex u, and
broadcasts to all processors
Parallelization
All processors update d; The owning
processor of u marks u as belonging to Vt
Process responsible for v must know w[u,v]
to update d[v]; 1-D block mapping of
adjacency matrix
Complexity – O(n2/P) + (OnlogP) for
communication
Single Source Shortest Path –
Dijikistra’s Algorithm
Finds shortest path from the source
vertex to all vertices
Follows a similar structure as Prim’s
Instead of d array, an array l that
maintains the shortest lengths are
maintained
Follow similar parallelization scheme
All-Pairs Shortest Paths
To find shortest paths between all pairs
of vertices
Dijikstra’s algorithm for single-source
shortest path can be used for all
vertices
Two approaches
All-Pairs Shortest Paths
Source-partitioned formulation: Partition the
vertices across processors
Works well if p<=n; No communication
Can at best use only n processors
Time complexity?
Source-parallel formulation: Parallelize SSSP for a
vertex across a subset of processors
Do for all vertices with different subsets of
processors
Hierarchical formulation
Exploits more parallelism
Time complexity?
All-Pairs Shortest Paths
Floyd’s Algorithm
Consider a subset S = {v1,v2,…,vk} of
vertices for some k <= n
Consider finding shortest path between
vi and vj
Consider all paths from vi to vj whose
intermediate vertices belong to the set
S; Let pi,j(k) be the minimum-weight path
among them with weight di,j(k)
All-Pairs Shortest Paths
Floyd’s Algorithm
If vk is not in the shortest path, then
pi,j(k) = pi,j(k-1)
If vk is in the shortest path, then the
path is broken into two parts – from vi to
vk, and from vk to vj
So di,j(k) = min{di,j(k-1) , di,k(k-1) + dk,j(k-1) }
The length of the shortest path from vi
to vj is given by di,j(n).
In general, solution is a matrix D(n)
Parallel Formulation
2-D Block Mapping
Processors laid in a 2D mesh
During kth iteration, each process Pi,j
needs certain segments of the kth row
and kth column of the D(k-1) matrix
For dl,r(k): following are needed
dl,k(k-1) (from a process along the same
process row)
dk,r(k-1) (from a process along the same
process column)
Figure 10.8
Parallel Formulation
2D Block Mapping
During kth iteration, each of the root(p)
processes containing part of the kth row
sends it to root(p)-1 in same column;
Similarly for the same row
Figure 10.8
Time complexity?
Sources/References
END
© Copyright 2026 Paperzz