concurrent disjoint set union · 2020-01-03 · concurrent disjoint set union robert e. tarjan...
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/1.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/2.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/3.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/4.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/5.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/6.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/7.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/8.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/9.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/10.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/11.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/12.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/13.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/14.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/15.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/16.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/17.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/18.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/19.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/20.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/21.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/22.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/23.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/24.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/25.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/26.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/27.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/28.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/29.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/30.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/31.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/32.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/33.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/34.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/35.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/36.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/37.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/38.jpg)
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:](https://reader036.vdocuments.mx/reader036/viewer/2022062604/5f93fef50ebb5344e327e414/html5/thumbnails/39.jpg)
Thanks!