Concerning the analysis from the previous section, we developed a method to answer the following question:
Given v→wfor workerp, ifwis neither part of a deadSCC nor part of the search stack for worker
p, can we detect if there is some statet∈uf[w] for whichtis part of the search stack for workerp?
We cannot lookup the representatives on local stacks in constant time. One could argue that it is possible if each worker keeps track of the representative for eachufset. If this is the case, the answer will then be provided by performing the check ifFind(w) is in the search stack.
We state that it is not possible to keep the representatives for each uf set on the local stacks for the workers. The reason being that any worker is able to update this uf set, with the implication that the representative might change. We show this with an example:
Assume that we have uf[v] ={v}for a state v on the local stack for workerp. Assume that for worker
q 6=pwe have uf[w] = {w}, where w is on the local stack for worker q. Suppose that any worker unites the states vand w, we obtainuf[v] =uf[w] ={v, w}. The representative for this set can either bev or w. Assuming w.l.o.g. that the representative for this set isw, we have that the local stack ofpdoes not contain the representative foruf[v] anymore.
v parent =v rank = 0 status =live Pset ={p1, p5} w parent =w rank = 0 status =live Pset ={p1, p2} Union(v, w)
=⇒
v parent =v rank =1 status =live Pset ={p1,p2, p5} w parent =v rank = 0 status =live Pset ={p1, p2}uf[v] uf[w] uf[v] uf[w]
Figure 4.2: Example on how a state’sPsetis updated after a Unioncall.
Extending the Union-Find structure with a worker set. We propose to maintain a global set for each state in theufset, in which we store all worker identifiers (IDs) that have visited this state. We refer to this set by Pset. Whenever a Union procedure is executed for two states v and w, we take the set- theoretical union for theirPset’s and store this as thePsetfor the representative. Thus, forUnion(v, w) we have, w.l.o.g. that if v is the representative in theuf set: v.Pset:=v.Pset ∪ w.Pset. We refer to Figure 4.2 for an example. By propagating all worker IDs to the representative of theufset, we ensure that all workers that have visited any state in this set have their worker ID in thePsetof the representative.
As a result of using thisPset, we can obtain which workers have visited any state in aufset. With respect to the the stated question, we can detect if workerphas visited somet∈uf[w] withp∈uf[Find(w)].Pset. We state this in Invariant 4.3 (whereSp denotes the search path for workerp). As a result, the algorithm is based on Proposition 4.3. The idea behind this proposition is that some (other) worker qhas detected the cycle w→∗ u→∗ w where w6∈ S
p and u∈Sp. We state that worker q must assure that state w is fully explored. From a notational aspect, we also denoteuf[Find(w)].PsetwithPset(w).
Invariant 4.3. If some workerp discovers the edge v → w , for w 6∈Sp and ¬IsDead(w), we have that
p∈Pset(w) =⇒w→∗v.
Proposition 4.3. If worker p discovers the cycle v → w →∗ v (and w 6∈ Sp) from the implication of
Invariant 4.3, workerpdoes not have to explicitly explore state w. We obtain from the invariant that some worker q 6=pis currently exploring state w. Assuming that worker q completely explores this state, hence this should not be necessary for worker p. As a result, each worker may only need to explore a subset of all reachable states.
Implementing the extended Union-Find structure Concerning the implementation ofPset, we can achieve this with a bitset of sizeP (the total number of workers). By applying a bitwise OR on twoPsets, we obtain the union of both sets. In contrast toRenault’s and Gabow’s algorithm, we do not include an artificial dead state for merging with completely explored SCCs. Instead, we keep track of a status field that is eitherunseen,live, or dead. This way, we can more easily derive the SCCs when the algorithm is finished. Algorithm 16 provides an overview on the design for the extendedUnion-Findstructure.
We highlight some features of the extendedUnion-Findstructure from Algorithm 16:
All lines in the structure are assumed to be executed atomically. Note that this is not always possible in practice (e.g. Line 34), however we conjecture that race-conditions remain prevented.
The methods in theUnion-Findstructure are designed to be lockless. As discussed in [1] and briefly touched in Section 2.3.2, we must consider the possibility that a Unionoperation can take place at any time, thus the parent andPsetfor a state may be updated after each line of the algorithm.
In Lines 2 and 20, we make use of the Compare&Swap operation (denoted as cas) to respectively update the status and parent for a state.
TheFindmethod is implemented usingpath compressionand theUnionmethod appliesweighing by rank (see Section 2.3.2 for details).
The AddWorker(x, p) procedure ensures that we have that p∈ Pset(x), thus the worker ID p is stored in thePset for the representable foruf[x].
TheMarkDead(x) procedure sets the status for uf[x] (for the complete set) todead. Note that it is not possible to change this status afterwards.
We present our designed naive algorithm utilizing this extendedUnion-Findin the next section. Algorithm 16 Extended locklessUnion-Findstructure for the naive approach (simplified)
1: procedure MakeSet(x)
2: cas(uf[x].status,unseen,live) 3: procedure Find(x)
4: if uf[x].parent6=xthen
5: uf[x].parent:=Find(uf[x].parent) 6: returnuf[x].parent
7: procedure SameSet(x, y) 8: xr:=Find(x)
9: yr:=Find(y)
10: if Find(xr)6=xr∨Find(yr)6=yr then 11: SameSet(xr, yr) 12: returnxr=yr 13: procedure AddWorker(x, p) 14: whilep6∈uf[Find(x)]do 15: xr:=Find(x) 16: uf[xr].Pset:=uf[xr].Pset∪ {p} 17: procedure HasWorker(x, p) 18: returnp∈uf[Find(x)].Pset
19: procedureUnionAux(x, y) 20: if cas(uf[y].parent, y, x)then
21: uf[x].Pset:=uf[x].Pset∪uf[y].Pset
22: if Find(x)6=x∨Find(y)6=xthen 23: UnionAux(Find(x),Find(y)) 24: procedureUnion(x, y)
25: xr:=Find(x) 26: yr:=Find(y)
27: if uf[xr].rank >uf[yr].rank then 28: UnionAux(xr, yr)
29: else
30: UnionAux(yr, xr)
31: if uf[xr].rank=uf[yr].rankthen 32: uf[yr].rank:=uf[yr].rank+ 1 33: procedureMarkDead(x)
34: uf[Find(x)].status:=dead
35: procedureIsDead(x)
36: returnuf[Find(x)].status=dead