+ All Categories
Home > Documents > Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan...

Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan...

Date post: 05-Aug-2020
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
39
Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with Siddhartha JayanB, Princeton
Transcript
Page 1: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

ConcurrentDisjointSetUnion

RobertE.TarjanPrincetonUniversity&IntertrustTechnologiesjointworkwithSiddharthaJayanB,Princeton

Page 2: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

KeymessagesIdeasandresultsfromsequenBalalgorithmscancarryovertoconcurrentalgorithms,butnewideasareneeded:thedesignspaceisdifferent

ininteresBngwaysDesignandanalysisofconcurrentdata

structuresandalgorithmsissBllarichareatoexplore

ConcurrencycreatesnewandsubtlecomplicaBons!

Page 3: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

ThisTalk

•  Disjointsetunionproblem•  MoBvaBngapplicaBon:

Strongcomponentsformodelchecking•  SequenBalsetunion•  Concurrencymodel•  Previouswork•  Ourresults

Page 4: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

a

b

same-set(a,b)

unite(a,b)

same-set(a,b) True

b

Disjointsetunion

False

DeviseadatastructurewiththefollowingoperaBons:make-set(x) same-set(x,y):trueifx,y

insameset,elsefalseunite(x,y):combinesets

containingx,yEachelementisinoneset(setsaredisjoint)

Page 5: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

ApplicaBons

FORTRANcompilers:COMMONandEQUIVALENCEstatements

Kruskal’sminimumspanningtreealgorithmIncrementalconnectedcomponentsingraphs

PercolaBonFindingdominatorsinflowgraphs

Findingstrongcomponentsindigraphs

Page 6: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

StrongComponentsStrongComponent:AmaximalsetofmutuallyreachableverBcesinadirectedgraph.Strongcomponentsarevertex-disjointandcanbetopologicallyordered:numberedsonoarcleadsfromalargertoasmallercomponent.Goal:Findcomponents,andatopologicalorder.

Two Topological Orders

Page 7: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Model-checkingforprogramverificaBon

Inapossiblyhuge,implicitlydefineddigraph,discoverwhethercertainsetsofstatescanbevisitedinfinitelyo\en.Equivalently,arethesestatesinacommonstrongcomponent?EventhoughstrongcomponentscanbefoundinlinearBmesequenBally(viaaspecialcaseofdisjointsetunion)thismaynotbefastenough.

Canconcurrencyhelp?

Page 8: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

DisjointSets:Compressed-treeImplementaBon

Representeachsetbyarootedtree•  Eachsetelementisatreenode•  Eachnodexhasaparentx.parent•  SetinformaBon(suchasvalue)isstoredintheroot•  Thetreeshapeisarbitrary

c

f g

b

da e

Page 9: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Auxiliary(internal)operaBons

find(x):Returntherootofthetreecontainingnodex.

NaïveimplementaBonoffind:returnifx.parent=xthenxelsereturnfind(x.p)link(x,y):Unitethetreeswithrootsxandy.

ImplementaBonoflink:makeytheparentofx(orxtheparentofy):

x.parent←y(ory.parent←x)

Page 10: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

AlinktakesBmeO(1),afindtakesBmeO(depthofnodefound).

Page 11: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

SequenBalimplementaBonofoperaBons

make-set(x):x.parent←xsame-set(x,y):returnfind(x)=find(y)unite(x,y):iffind(x)≠find(y)thenlink(find(x),find(y))AsetoperaBontakesO(1)Bmeplustwofinds.

Page 12: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

EachlinktakesBmeO(1),eachfindtakesBmeO(depthofnodefound).

Goal:reducethe(amorBzed)Bmeperfindbyreducingnodedepths

Improvelinks:linkbysizeorrankorrandomindex

Improvefinds:compactfindpaths

Page 13: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Linkingbysize:maintainthenumberofnodesineachtree(storeinroot).Linkrootofsmallertreetolarger.BreakaBearbitrarily.

Linkingbyrank:Maintainanintegerrankforeachroot,iniBally0.Linkrootofsmallerranktorootoflargerrank.IfBe,increaserankofnewrootby1.

Linkingbyrandomindex:Giveeachelementauniquenumericindexchosenuniformlyandindependentlyatrandom.Linkrootofsmallerindextorootoflargerindex.

Page 14: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

EachoftheselinkingrulesreducesthemaximumpathlengthtoO(logn),wheren=#nodes:atmostn/2knodesofheightkorgreater.

Page 15: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

PathCompacBon

Compression:duringeachfind,maketheroottheparentofeachnodeonthefindpath.

Splihng:Duringeachfind,replacetheparentofeachnodeonthefindpathbyitsgrandparent.

Compressiontakestwopassesoverthefindpath,

splihngonlyone.

Page 16: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

10

8

5

2

1

7

3 4

Compressionoffind(1)path

Page 17: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

10

8

5

2

1

7

3 4

Splihngoffind(1)path

Page 18: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Original

A\erCompression A\erSplihng

Page 19: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

RunningTime

Assumen>1make-setoperaBonsaredonefirst,followedbym≥n/2intermixedsame-setanduniteoperaBons.

Defined,thefinddensity,tobe⎡m/n⎤.

Withlinkingbysize,rank,orrandomindex,andcompressionorsplihng,totalBmeis

O(mα(n,d))

Page 20: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Ackermann’sfuncBon(Péter&Robinson)

A0(n)=n+1Ak(0)=Ak–1(1)ifk>0Ak(n)=Ak–1(Ak(n–1))ifk>0,n>0A1(n)=n+2,A2(n)=2n+3,A3(n)>2n,A4(n)>towerofn2’s,A4(2)has19,729decimaldigits

Ak(n)isstrictlyincreasinginbothargumentsα(n,d)=min{k>0|Ak(d)>n}

Page 21: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Computermodel:SharedmemorymulBprocessor(APRAM)

p1 p2 p3 …. pi pk-1 pk….

SharedMemory

LocalMemory

LocalMemory

LocalMemory

LocalMemory

LocalMemory

LocalMemory

Asynchronous–ArbitrarydelaysbetweenoperaBons

ConcurrencyAnderson&Woll,1994

EachsetoperaBonisdonebyoneprocessSeveraloperaBonscanrunconcurrently(differentprocesses).

Page 22: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Correctness

Linearizable:EachoperaBoncanbeassignedalineariza<on<meduringitsexecuBon,differentforeachoperaBon,suchthattheoutcomeofalltheoperaBonsisthesameasiftheywereexecutedinstantaneouslyattheirlinearizaBonBmes.Wait-free:EachprocesscompleteseachofitsoperaBonsinaboundednumberofitsownsteps.

Page 23: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Linearizability[Herlihy, Wing 1990] p1

p2

p3

Time

Union(x, y)

Union(z, x)

SameSet(x, y)

Union(w, z)

SameSet(x, w) SameSet(x, y)

Union(w, y) SameSet(z, y)

SameSet(w, y)

Correctness

Page 24: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Efficiency

Totalwork:totalnumberofstepstakenbyallprocesses,asaworst-casefuncBonofn,m,andp(thenumberofprocesses).Goal:TotalworknottoomuchbiggerthanthesequenBalBmeboundandsublinearinp:thenconcurrencymayhelp.

Page 25: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

SynchronizaBonPrimiBvesforwait-freedom

Compare&SwapCAS(x,y,z):ifx=ythen{x←z;returntrue}elsereturnfalse

DoubleCompare&SwapDCAS(x,y,z,u,v,w):ifx=yandu=vthen{x←z;u←w;returntrue}elsereturnfalse

Page 26: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Previouswork:Anderson&Woll1994

ConcurrentversionoflinkingbyrankwithsplihngusingCAS.Bigproblem:CASseemstooweak:linkingbyrankrequireschangingarankinonenodeandapointerinanother.TheiralgorithmdoesnotavoidrankBes.WorkboundisO(m(α(n,1)+p)):notsogood,and“proof”isbuggy:theydidnotaccountforinteracBonsbetweendifferentprocessorsdoingsplihngalongoverlappingpaths.

Page 27: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Ourgoal

Simplealgorithmswithgoodworkbounds,sublinearinpifpossibleAnderson&Wollgaveasimplewait-freeimplementaBonoffindwithsplihngusingCAS,buttheiranalysisisnotcorrect.

Page 28: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Splihng:candoshortcutsviaCASbutconcurrentthreadscaninterfere

Page 29: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

5

4

3

2

1

ACAScanfailbecauseanotherCASdoesalessfavorablechange:Avisits1,2,3thenstalls;Bvisits2,3,4,changesparentof2to4;Cvisits1,2,4,triestochangeparentof1to4butAwakesup,changesparentof1to3.

A C

B

Page 30: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

OurResultsTwosplihngalgorithms:•  1-trysplihng:tryeachparentchangeoncebeforemovingtothenextnode

•  2-trysplihng:tryeachparentchangetwicebeforemovingtothenextnode

Wegetslightlybe~erboundsfor2-trysplihng

Page 31: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Linking

CandounrankedlinksusingCASbutDCASneededforrankedlinks

k

k

Page 32: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

LinkingAlgorithms

Fourconcurrentlinkingalgorithms:•  Linkingbyrank(DCAS)•  Linkingbyrandomindex(CAS)•  Hybridlinkingbyrankviacoin-flipping(CAS)•  HybridlinkingbyrankviadeterminisBccoin-flipping(CAS)

Page 33: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

OurBoundsWorst-caseBmeperoperaBon

O(logn)withorwithoutsplit/compressTotalworkwith“1-try”splihng

O(m(α(n,⎡m/(np2)⎤)+log(np2/m+1)))Totalworkwith“2-try”splihng

O(m(α(n,⎡m/(np)⎤)+log(np/m+1)))

Boundsareworst-casefordeterminisBclinking,Expectedforrandomizedlinking

Page 34: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Hybridlinking

link(v,w):ifvandwhaveequalrank,firstchangetheparentofv,ortherankofw?Flipafaircointodecide:whentryingtolinktwoequal-ranknodesvandw,withv<winsome(arbitrary)totalorder,ifheadstrytomakewtheparentofv;iftails,trytoadd1totherankofv

Page 35: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

AnalysisTreedepthislogarithmic(worst-caseforlinkingbyrank,high-probabilityforlinkingbyrandomizedindexorhybrid}.ThisgivesO(logn)BmeperoperaBon.Workbound:Letd=m/(np)(2-trysplihng)ord=m/(np2)(1-trysplihng).Ifd≥1,thesequenBalanalysisextendstogiveaboundofO(α(n,d))workperfindplusO(pd)orO(p2d)workpernode(porp2BmesthesequenBalbound).ThetotalworkisO(mα(n,d)).

Page 36: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

WorkboundconBnued

Theothercaseisd<1.Thenumberofnodesofrankatleastrisatmostn/2r.WeapplythesequenBalargumenttothenodesofrankatleastlg(1/d),ofwhichthereareatmostnd.ThesenodesaccountfortotalworkO(mα(n,1)+nkd)=O(mα(n,1)).Thelow-ranknodesonfindpathsaccountforanaddiBonalO(log(1/d))workperfind.

Page 37: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

CurrentWork

ImplementsetswithvaluesandsetswithiteraBonwhilepreservingefficiency:seemstorequirerelaxinglinearizaBon.Idea:AllowsubsetsofuniteoperaBonstobereplacedbyequivalentsubsets,implementusingabifurcaBngqueue.

Page 38: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

QuesBonsforthefuture

IsouramorBzedupperboundBghtfortheproblem?

Concurrentstrongcomponents?Otherconcurrentdatastructures:binarysearch

trees?

Page 39: Concurrent Disjoint Set Union · 2020-01-03 · Concurrent Disjoint Set Union Robert E. Tarjan Princeton University & Intertrust Technologies joint work with ... ideas are needed:

Thanks!


Recommended