0% found this document useful (0 votes)
63 views

Lesson2 6DistributedBFS PDF

This document discusses representing graphs as adjacency matrices and using that representation to perform a distributed breadth-first search (BFS) algorithm. It explains how to construct an adjacency matrix from a graph and use matrix operations to represent the BFS frontier, updates, and propagation of distances. The key steps of the distributed 1D BFS algorithm are to partition the matrix columns, compute updates in parallel, locally update distances, identify the new frontier, and exchange the frontier using an all-to-all operation. The cost of the 1D algorithm scales linearly with the number of processors p, while a 2D partitioning provides a square root of p scaling.

Uploaded by

Projectlouis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Lesson2 6DistributedBFS PDF

This document discusses representing graphs as adjacency matrices and using that representation to perform a distributed breadth-first search (BFS) algorithm. It explains how to construct an adjacency matrix from a graph and use matrix operations to represent the BFS frontier, updates, and propagation of distances. The key steps of the distributed 1D BFS algorithm are to partition the matrix columns, compute updates in parallel, locally update distances, identify the new frontier, and exchange the frontier using an all-to-all operation. The cost of the 1D algorithm scales linearly with the number of processors p, while a 2D partitioning provides a square root of p scaling.

Uploaded by

Projectlouis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lesson26DistributedBFS

GraphsandAdjacencyMatrices
Itishelpfultolookatagraphasanadjacencymatrix.

Todothis:
1. Giveeachvertexanintegerlabel.
2. Thencreateamatrix,A,torepresentthegraph.Arowforeveryedge,andacolumnfor
everyvertex.
3. Foreachedge,puta1inthecorrespondingrow,column.Forthevertex0,ithastwo
edgesattachedtoit.Oneoftheedgesisgoingtovertex1andtheothertovertex5.

4. Undirectedgraphshavesymmetricmatrix.Soputa1inthecorrespondingcolumns.

5. Thefinalgraph

ForanyundirectedgraphG,
Assume:
n=numberofvertices
m=numberofedges

Itsadjacencymatrixwillbenxn.
Thenumberofnonzeros:nnz(A)=2m(#ofnonzeros)

TheAdjacencyMatrixforaDIRECTEDGraph

Arbitrarilynumberthegraph.
ThenrecordtheOUTGOINGedgesofeachvertex.

Nowtreatthematrixasabooleanmatrix:
1=True,0=False

Whatistheundirectedgraphforthisdirected
graph?

ThelogicalorofBanditstranspose.

BreadthFirstSearch:Review

First:calculatetheminimumdistanceofeachvertexfroms.
Letvertex0bes.

sis0distancefromitself,allotherverticesareinfinitedistancefroms.


Forlevel=0,theFrontierF
={0}.Foreachlevel,itisjustthedistanceoftheverticesfroms.
l

Sonowweneedtovisitallofthefrontiersneighbors,inthiscasetheneighborsofthefrontier
arevertices1and5.Theirdistancesareupdatedwiththecurrentdistance+1.(inthiscase0+
1=1)

Thesevisitedneighborsnowbecomethenewfrontier.Thelevelis1,soupdateallneighborsto
distances1+1=2.

Repeatforallnodes.
Thefinalresult:

Thecostofthealgorithmis:O(m+n)n=vertices,m=edges

MatrixbasedBFS

NowtranslatetheBFSalgorithmintothelanguageofMatrices.

Isthereanedgefromthefrontiertoi?Ifthereis,thedistance
shouldbeupdated.

Ifthereisanedgefromji,thentheadjacencymatrix
shouldhavea1(ortrue)ata
.
ji

ConsiderthegraphasamatrixAandthefrontierasa
booleanvectorf.
Todetermineifthereisanedgefromitothefrontier,thereneedstobeaniatthe
correspondingvertices.Torecordtheseedges,marktheminabooleanvectorcalledu(for
update).

Thiscanbesaidas:
Updateiifanyvertexjisinthefrontierandpointstoi.

(Vislogicalorandtheupcarrotisalogicaland)

Forasparsegraph,thevectorandthematrixcanbemaintainedwithsparsedatastructures.
togofromtheupdatevectortotheupdateddistances,

MATRIXBASEDBFSTHEQUIZ

Theexampleoffillingintheupdatevector.Use
thethematrixvectorproduct.

1DDistributedBFS
ThematrixgivesyouaneasywayfordistributingtheBFS.
Todothis:
Dividethenumberofcolumnsintoequalsectionsforeachprocessor.Thecolumnpartitioning
correspondstothepartitioningofthevertices.

Theupdatevectorwillbepartitioned
toeachprocess,butthefrontier
vectorwillneedtobereplicatedon
eachprocess.

Witheachupdate,youwillneedto
replicatethefrontieragain.
Usealltoall

TheDistributed1DAlgorithm
1. partitioncolumnsofAandentriesofu.
T
2. ComputeruA
f
3. Locallyupdatethelocaldistances
4. Identifylocalverticesofthenextfrontier
5. Toanalltoallexchangeofthefrontier

Thealltoallistheonlycommunicationstep,whatisthecost?

The1Dcostsscalelinearly.Whatisthecostwhenitis2D?Squarerootofp(pisthenumber
ofprocessors).

You might also like