0% found this document useful (0 votes)
91 views7 pages

Lesson1-7 Parallel Pointers Graphs PDF

This document discusses parallelizing breadth-first search (BFS) on graphs. It describes how to perform a standard sequential BFS, then explores using level-synchronous traversal and processing entire levels in parallel using bags to represent vertex sets. The goal is to reduce the span of the algorithm from number of vertices to the diameter of the graph.

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)
91 views7 pages

Lesson1-7 Parallel Pointers Graphs PDF

This document discusses parallelizing breadth-first search (BFS) on graphs. It describes how to perform a standard sequential BFS, then explores using level-synchronous traversal and processing entire levels in parallel using bags to represent vertex sets. The goal is to reduce the span of the algorithm from number of vertices to the diameter of the graph.

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

ParallelPointers:Graphs

BreadthfirstSearch(BFS)101
GivenavertexS,whatisthedistanceofalltheotherverticesfromS?

Whywouldthisbeuseful?Tofindthefastestroutethroughanetwork.

TodoaBFSkeepadistanceforeachvertex.
1.
Sisthefirstvertexitis0distancefromitself.Setalltheotherverticestoinfinity.
2.
BeginatS.Lookatitsimmediateneighbors.TheirdistanceforSis1.
3.
Nowmovetotheseimmediateneighborsandmarkthedistancebetweenthese
neighborsasone.
4.
Dothisforeachvertexinthegraph.

EachsuccessiveadvancementverticesbeingexaminediscalledaFrontier.

StartwithagraphG.
Setallthedistancestoinfinity
Setthesourcedistanceto0

DeterminethefrontierFofS

Lookateachvertexinthefrontier
Examineeachneighborwofeach
vertex

Ifthedistanceofthatneighboris
infinity,ithasnotbeenvisited.

Ifithasnotbeenvisitedthe
neighborsdistanceisthevertexs
distance+1

Dothisforallverticesinthesearch.

Whatdoesthisalgorithmcost?Bycostwemeanrunningtime.
1.
Thefrontieronlygrowswhenanunvisitedverticesisinserted.Whichmeansthefrontier
canonlybeaslargeasthenumberofvertices.
2.
Eachedgeisvisitedatmostonce,ifthegraphisdirected.

3.
Ifthegraphisundirected,eachedgewillbevisitedatmosttwice.
Thismeanstheruntimeislinearandthesizeofthegraph

BFSQuizNotethisisadirectedgraph.

WhenlookingforneighborsofSlookonlyat
thoseverticesthatgoINTOS,notoutofit.For
example,disaneighborofSandfisNOT.

AnalysisIsBFSInherentlySequential?
Canthisalgorithmbeparallelized?
Thereisabottleneckintherelationshipbetweenextractingv,insertingw.

TheavailableparallelismisW/Dwhichisdependentupon
|E|/|V|.

Isthisagoodthingornot?

Inreallife,graphsaresparse.So|E|=O(|V|).Thismeansthe
averageavailableparallelismwillbeaconstantandthatisbad.

Thisleadstotheconclusionthatthesequentialalgorithmisbad.

IntuitionWhywemightdobetter

TheBFSvisitsthegraphinwaves.Therearetwoimportantimplicationsfromthisfact:
1.
Theupperboundonthespanshouldbethenumberofwaves,notthenumberof
vertices.Thesewavesarecalledlevels.Alevelisalloftheverticesequidistanttothe
source.
Thediameterofagraphisthemaximumshortestdistancebetweenanypairofvertices.
Diameterisapropertyofthewholegraph,andisanupperboundonthenumberoflevels
ofanystartingvertex.
Levelsynchronoustransversalisvisitingthenodeslevelbylevel.

2.
IfyouperformalevelsynchronousBFS,thentheorderinwhichyouvisiteachvertexofa
givenfrontierisimmaterial.Thismeanswecanvisitthematthesametime.

Sothisisanopportunityforparallelismalltheverticesofafrontiercanbevisitedatthe
sametime.

HighLevelApproachtoParallelBFS

1.
2.

CarryouttheBFSlevelbylevel(notvertexbyvertex)
Processtheentirelevelinparallelwecandothisbecausetheorderinwhichthe
verticesarevisitedshouldnotmatter.

Thisisverysimilartotheserialversion,withafew
exceptions.

l0..thecodeislevelsynchronous.
Thisisthelevelcountersetto0

Thefrontiersreferencedarealsolevelspecific(Fl)

ll+1.incrementsthecounter

Thespan(definedbythewhileloop)willbeno
largerthanthediameterofthegraph

Processlevelwill:takethegraphandthecurrent
frontier.Itwillproduceanewfrontierandupdatethe
distances(D)

Bag:KeyProperties
ThedatastructuretobeusedwiththeparallelBFSisabag.
Abaghasthefollowingdataproperties:
Thedataisanunorderedcollection
Itwillallowrepetition
Allowredundantinsertionsofthesamevertex,ifnecessary

Abaghasthefollowingoperationalproperties:

Fasttraversal
Fastandlogicallyassociativeunionandsplit

LogicallyassociativemeansifAUB==BUA

ThiswillalsogivetheabilitytoapplyReducerHyperObjects.

Pennant,BuildingBlocksforBags

Pennantis:atreewith2knodesandaunaryroot
havingachild.thechildistherootofacompletebinary
tree.

Xistheroot
Xsisthecompletebinarytree

Iftherearetwopennants,andtheyareEXACTLYTHE
SAMESIZE(|X|==|Y|)

Thenthetwopennantscanbe
combined.

1.
Chooseoneoftherootstobe
therootofthecombinedpennant.
2.
Thetwopennantsarenow
childrenoftheroot.

Thecombinationisalsoapennant.
Therewillnowbe2k+1nodes.

Thiswasfairlyeasy,itinvolvedrearrangingpointers.

Thereverse,splittingapennantintotwopennantscan
bedoneusingthereverseofthegivenmethod.

CombiningPennantsintoBags
Pennantsaregoodforrepresentingcollectionsthathaveasize2N,butthereneedstobe
somethingforothersizecollections.

Abagneedstocontainanysizecollection.Howcanpennantsbeusedtoformbags?

Anexampleofpennantsusedtoputacollectioninabag.
23items.Dividedintogroupsofpowersof2.(23=10111)

Toconnectthesegroups,useanarrayofpointers,usethenullpointerforanyemptybits.
Thisarrayiscalledaspine.

Toinsertanewelementintothecollection.
1.
TrytoinsertitintotheLSB
2.
IftheLSBisoccupied,combinetheLSBwiththenewelementandcarryit.
3.
MovetothenextLSB,repeattheprocess.

WhatistheCostofInsertion?
Rememberwheninsertinganelement,youmayneedtotraversetheentirespine.
AnintegerofsizeNneedsNbitstostoreitspower.
Insertinganelementissimplyamatterofshufflingpointers.

IttakesthesameasymptotictimetoinsertNelementsintoabagasitdoestoinsert1.
Theamortizedtimetoinsertelementsintoabagisconstant.

BagSplitting

Arightbitshiftisthesameadivisionbytwo.

Tosplitabaganemptybagisalsonecessary.
Splitthepennantinhalf.
Store1ofthehalvesinthesparebagandoneinthenextlowerbitonthebag.

Thecostofsplittingabag..

FinishingtheParallelBFSwithBags

Ifthebagisbigenoughusedivideand
conquerotherwiseusethesequentialmethod.

Thedifferencewiththissequentialmethodisthe
forloopthisusesaparallelforloop.

Thereisadataracehereaseachtasktriesto
updatetheneighbors.Thisisperfectlysafe
here.

Thecostsaretrickyforthisexperiment.
Spanisaffectedbythenumberoflevels.
Spanofprocesslevelhas3parts:depth,costofsplitting,costofthebasecase.

You might also like