gorithms, we use the classical ones, for instance the Dijkstra-Scholten algorithm. [7], or the ...... Edsger W. Dijkstra, W. H. J. Feijen, and A. J. M. van Gasteren.
Termination Detection of Distributed Algorithms by Graph Relabelling Systems Emmanuel Godard, Yves M´etivier, Mohamed Mosbah, and Afif Sellami LaBRI - Universit´e Bordeaux1 351 Cours de la Lib´eration 33405 Talence, France {godard,metivier,mosbah|sellami}@labri.fr
Abstract. A unified and general scheme for detecting the termination of distributed computations is proposed. This scheme uses the encoding of distributed algorithms in form of graph rewriting systems to transform the problem of adding termination detection to a distributed computation into an operation on graph rewriting systems. Various examples are used to illustrate this approach.
1
Introduction
Distributed termination detection is one of the most important problems in distributed computing due to its numerous practical and theoretical applications. It is closely related to many other problems such as determining a causally consistent global state [4], detecting deadlocks [5], distributed garbage collection [17], and to universal graph reconstruction [14]. Many algorithms have been already designed for particular models and under various assumptions. However, general approaches and unifying methods for dealing with the termination detection problem have been rarely suggested. In this paper, we propose a general framework based on graph relabelling systems to add termination detection to a distributed algorithm. Our work is motivated by the recent result of M´etivier and Tel [16] which characterizes the families of networks in which the local detection of the global termination is possible. We give here effective and practical solutions to add termination detection to a distributed algorithm. Graph Relabelling Systems (GRS) [3] are suitable for encoding and implementing distributed algorithms, for proving their correctness and for understanding their power. These systems do not modify the underlying structure of the graph on which they are applied, but only modify the labels of vertices or edges. Each relabelling step is local, that is on a subgraph of fixed size according to some rules depending on such a subgraph. The power of relabelling systems can be increased using priorities (PGRS) or forbidden contexts (FCGRS). A priority relation (see [3,10,11]) is a partial order on the set of relabelling rules. In PGRS systems, the priority relation determines the order in which rules have to be
This work is a part of the Visidia project [15], and has been supported by the “Conseil R´egional d’Aquitaine”.
A. Corradini et al. (Eds.): ICGT 2002, LNCS 2505, pp. 106–119, 2002. c Springer-Verlag Berlin Heidelberg 2002
Termination Detection of Distributed Algorithms
107
applied if they overlap. In FCGRS [12], relabelling rules are equipped with forbidden context, that is graphs which disable the application of the corresponding rule if they are included in the context. Consider a network represented by a graph whose vertices denote processors, and whose edges denote communication links. The local state of a processor (resp. link) is encoded by the labels attached to the corresponding vertex (resp. edge). Processors communicate only by asynchronous message passing. A relabelling rule is a rewriting rule which has the same underlying fixed graph for its left-hand side and its right-hand side, but with an update of the labels. Relabelling rules can be applied in parallel on the graph unless the occurrences of their left-hand sides share an edge or a vertex. The relabelling is performed until no rule can be applied. By using various types of relabelling systems, it is possible to capture various paradigms of the distributed computation. These paradigms include sequential or distributed computation, local detection of the global termination, and correctness of computation. For example, there are three relabelling systems for the distributed computation of a spanning tree in an anonymous network [10,2,13,1] depending on whether such a computation is parallel, or whether it detects locally the global termination. We propose a practical and unified method to transform a graph relabelling system into another equivalent one which is equipped with the local detection of the global termination. If A is a distributed algorithm encoded by a graph relabelling system RA , and if T is a termination detection algorithm encoded by a graph relabelling system RT , then the superposition of A and T is obtained by a particular operation of the corresponding relabelling systems RA and RT . That is, we exploit the high level encoding of distributed algorithms by graph relabelling systems to simplify the combination of both algorithms. We illustrate this method through examples including the computation of a spanning tree and the coloration of a ring. For the termination detection algorithms, we use the classical ones, for instance the Dijkstra-Scholten algorithm [7], or the algorithm to detect stability [18]. The paper is organized as follows. In Section 2, we recall formal definitions of graph relabelling systems and present a few examples. Section 3 introduces the product operation of graph relabelling systems. In Section 4, we use a variation of the product to add the termination detection to a distributed algorithm, and we give a few examples. A generalization of our method is given in Section 5. All the examples discussed in this paper have been implemented and tested on the Visidia tool [15].
2 2.1
Graph Relabelling Systems Labelled Graphs
Throughout the paper we consider only simple connected graphs where vertices and edges are labelled with labels from a possibly infinite alphabet L. A graph labelled over L will be denoted by (G, λ), where G is a graph and λ : V (G) ∪ E(G) → L is the function labelling vertices and edges. The graph
108
Emmanuel Godard et al.
G is called the underlying graph, and the mapping λ is a labelling of G. The class of labelled graphs over some fixed alphabet L will be denoted by GL . Let (G, λ) and (G , λ ) be two labelled graphs. Then (G, λ) is a subgraph of (G , λ ), denoted by (G, λ) ⊆ (G , λ ), if G is a subgraph of G and λ is the restriction of the labelling λ to V (G) ∪ E(G). A mapping ϕ : V (G) → V (G ) is an homomorphism from (G, λ) to (G , λ ) if ϕ is a graph homomorphism from G to G which preserves the labelling, i.e., for all vertices v, w ∈ V (G) λ (ϕ(v)) = λ(v), and λ ({ϕ(v), ϕ(w)}) = λ({v, w}). The mapping ϕ is an isomorphism if it is bijective. An occurrence of (G, λ) in (G , λ ) is an isomorphism ϕ between (G, λ) and a subgraph (H, η) of (G , λ ). 2.2
Graph Relabelling Systems
We describe in this section the formal notion of graph relabelling systems. Definition 1. A (graph) relabelling rule is a triple R = (GR , λR , λR ) such that (GR , λR ) and (GR , λR ) are two labelled graphs. The labelled graph (GR , λR ) is the left-hand side and the labelled graph (GR , λR ) is the right-hand side of R. Definition 2. A graph relabelling system (GRS for short) is a triple R = (L, I, P ) where L is a set of labels, I a subset of L called the set of initial labels and P a finite set of relabelling rules. The intuitive notion of computation step will then correspond to the notion of relabelling step: Definition 3. A R−relabelling step is a 5-tuple (G, λ, R, ϕ, λ ) such that R is a relabelling rule in P and ϕ is both an occurrence of (GR , λR ) in (G, λ) and an occurrence of (GR , λR ) in (G, λ ). Intuitively speaking, the labelling λ of G is obtained from λ by modifying all the labels of the elements of ϕ(GR , λR ) according to the labelling λR . Such a relabelling step will be denoted by (G, λ) −−→ (G, λ ). R,ϕ
The notion of computation then corresponds to the notion of relabelling sequence: Definition 4. A R−relabelling sequence is a tuple (G, λ0 , R0 , ϕ0 , λ1 , R1 , ϕ1 , λ2 , . . . , λn−1 , Rn−1 , ϕn−1 , λn ) such that for every i, 0 ≤ i < n, (G, λi , Ri , ϕi , λi+1 ) is a R−relabelling step. The existence of such a relabelling sequence will be denoted ∗ by (G, λ0 ) −−−−→ (G, λn ). R
The computation stops when the graph is labelled in such a way that no relabelling rule can be applied: Definition 5. A labelled graph (G, λ) is said to be R−irreducible if there exists no occurrence of (GR , λR ) in (G, λ) for every relabelling rule R in P .
Termination Detection of Distributed Algorithms
109
For every labelled graph (G, λ) in GI we denote by IrredR ((G, λ)) the set ∗ of all R−irreducible labelled graphs (G, λ) such that (G, λ) −−−−→ (G, λ ). InR
tuitively speaking, the set IrredR ((G, λ)) contains all the final labellings that can be obtained from a I−labelled graph (G, λ) by applying relabelling rules in P and may be viewed as the set of all the possible results of the computations encoded by the system R. Example 1. We give here an example of a graph relabelling system which computes a spanning tree. The system is given by R1 = (L1 , I1 , P1 ) defined by L1 = {N, A, 0, 1}, I1 = {N, A, 0} and P1 = {R} where R is the following relabelling rule: A R:
0
N
A
A
1
We assume that initially a unique vertex has label A, all other vertices having label N and all edges having label 0. At each step of the computation, an A-labelled vertex u may activate any of its neutral neighbours, say v. In that case, u keeps its label, v becomes A-labelled and the edge {u, v} becomes 1-labelled. Hence, several vertices may be active at the same time. Concurrent steps will be allowed provided that two such steps involve distinct vertices. The computation stops as soon as all the vertices have been activated. The spanning tree is given by the 1-labelled edges. We give an example of the execution of this system in Figure 1. 0
N 0
N 0
0
A 0
0
N 0
N
0
0
N 0
0 1
A
0
N A
1
A
0
0
0
N
N
0
N
N
0
A
0
N
A
0
N
A
0
0 1
A 0
N
1
A 1
0
1
A 0
A
A
1
0
A
1
A
A 1
0
A
A
1
A
1
A 1
N
1
N 0
A 1
1
A
Fig. 1. Distributed computation of a spanning tree
Example 2. It is possible to color a ring with 3 colors using relabelling systems. Let {c1 , c2 , c3 } be the set of colors. Let R2 = (L2 , I2 , P2 ) be the relabelling system defined by L2 = {c1 , c2 , c3 }, I2 = L2 and P2 = {R1 , R2 } where R1 , R2 are the following relabelling rules:
110
Emmanuel Godard et al.
R1 :
x
x
x
x
y
x
R2 :
x
x
y
x
z
y
; y = x x = y
; z = x z = y
x, y, z ∈ L2
Initially, vertices are labelled at random. This relabelling system assigns a correct 3-coloring to the vertices of a ring. Intuitively, the application of a rule will assign a correct and definite color to the middle vertex. Therefore, a finite ring with arbitrary initial coloring can be colored by applying a finite number of times the rules above. Note that it is an example of a self-stabilizing algorithm [8]. 2.3
Graph Relabelling Systems with Forbidden Contexts
The idea we develop here is to prevent the application of a relabelling rule whenever the corresponding occurrence is “included” in some special configuration, called a context. More formally, we have: Definition 6. Let (G, λ) be a labelled graph. A context of (G, λ) is a triple (H, µ, ψ) such that (H, µ) is a labelled graph and ψ an occurrence of (G, λ) in (H, µ). Definition 7. A relabelling rule with forbidden contexts is a 4-tuple R = (GR , λR , λR , FR ) such that (GR , λR , λR ) is a relabelling rule and FR is a finite set of contexts of (GR , λR ). Definition 8. A graph relabelling system with forbidden contexts (FCGRS for short) is a triple R = (L, I, P ) defined as a GRS except that the set P is a set of relabelling rules with forbidden contexts. A relabelling rule with forbidden contexts may be applied on some occurrence if and only if this occurrence is not “included” in an occurrence of any of its forbidden contexts. More formally: Definition 9. A R−relabelling step is a 5-tuple (G, λ, R, ϕ, λ ) such that R is a relabelling rule with forbidden contexts in P , ϕ is both an occurrence of (GR , λR ) in (G, λ) and an occurrence of (GR , λR ) in (G, λ ), and for every context (Hi , µi , ψi ) of (GR , λR ), there is no occurrence ϕi of (Hi , µi ) in (G, λ) such that ϕi (ψi (GR , λR )) = ϕ(GR , λR ). Example 3. In this example, we give a relabelling system encoding a tree election algorithm. Let R3 = (L3 , I3 , P3 ) be the FCGRS defined by L3 = {N, F, E, 0}, I3 = {N, 0} and P3 = {R1 , R2 } where R1 , R2 are the following relabelling rules with forbidden contexts :
Termination Detection of Distributed Algorithms R1 :
N
0
N
F
0
N
,
{
N
0
N
111
}
0
N N R2 :
N
E
,
{
0
}
N
Let us call a pendant vertex any N −labelled vertex having exactly one N – labelled neighbour. The rule R1 then consists in “cutting” a pendant vertex in the tree (since the forbidden context ensures that this vertex has no other N −labelled neighbour) by giving it a F −label. Thus, if (G, λ) is a labelled tree where all vertices are N −labelled and all edges are 0−labelled then this cutting procedure leads to a unique N −labelled vertex which becomes elected thanks to the rule R2 . It is not difficult to observe that every vertex in the tree may be elected by this algorithm.
3
Products of Relabelling Systems
In this section, we will introduce the product of two relabelling systems. This operation will be used to add termination detection to a distributed algorithm. The main idea is to apply this product to combine two relabelling systems (one encoding the distributed algorithm, and another encoding a termination detection algorithm). Definition 10. Let G = (V, E) be a graph. Let L1 and L2 be two finite alphabets and let λ1 and λ2 be two labelling functions. The result of the product of the labellings λ1 and λ2 , denoted λ1 × λ2 , is defined as follows : λ1 × λ2 : V ∪ E −→ L1 × L2 . λ1 × λ2 (v) = (λ1 (v), λ2 (v)). Let λ = λ1 × λ2 . Without loss of generality, we will extend the labelling function λ1 (resp. λ2 ) to λ as follows. We will write λ(1) (resp. λ(2)) for the projection of the ith component of the codomain of λ, i.e. λ(i) : V ∪ E → Li with λ(i)(x) = yi for λ(x) = (y1 , y2 ). In fact, sometimes we need to handle rather the labelling of only one system within the product. Definition 11. Let R1 = (L1 , I1 , P1 ) and R2 = (L2 , I2 , P2 ) be two relabelling systems. The product of R1 and R2 is the relabelling system R = R1 × R2 defined by (L, I, P ) where L = L1 × L2 , I = I1 × I2 and P = P1 ∪ P2 . The set of relabelling rules of R is the union of the relabelling rules of R1 and R2 by extending the labelling. That is, for every rule R1 = (GR1 , λR1 , λR1 ) in R1 , the relabelling system R contains all rules R = (GR , λR , λR ) with GR = GR1 ,
112
Emmanuel Godard et al.
λR (1) = λR1 and λR (1) = λR1 . Similarly, the rules of R2 are extended to be added to R. Example 4. Let us illustrate the previous definition by an example. Consider the following relabelling system S = (L4 , I4 , P4 ) where L4 = {B, C, 0, b}, I4 = {B, 0} and P4 contains the following relabelling rule: B
B
0
b
R:
C
B
Now, the product R1 ×S, where R1 is the relabelling system given in Example 1, is the relabelling system (L, I, P ) where L = L1 × L4 , I = I1 × I4 and P contains the following relabelling rules: (A, X)
(A, X)
R1 :
R2 :
Where X, X ∈ {B, C},
(1, z)
(0, z) (N, X )
(A, X )
(Y, B)
(Y, B)
(z , 0)
Y, Y ∈ {A, N }, z ∈ {0, b}, z ∈ {0, 1}.
(z , b)
(Y , B)
(Y , C)
An example of execution of this system is given by the following figure. (A, B) (A, B)
(N, B)
(N, B) (N, B)
(N, B)
(A, B) (A, C) (1, 0)
(A, B) (1, 0) (A, B)
(N, C) (0, b) (N, B)
(0, b) (N, C) (N, B)
(A, B) (A, C) (1, 0) (1, 0) (0, b) (A, B) (0, b) (N, C) (1, 0) (0, b) (A, C) (N, B)
(A, B) (A, C) (1, 0)
(1, b) (0, b) (A, C) (0, b) (N, C)
(1, b) (1, b) (A, C) (0, b) (A, C)
(1, 0) (1, b) (A, C) (A, B)
(1, 0) (1, b) (A, C) (A, B)
Lemma 1. Let R1 = (L1 , I1 , P1 ) and R2 = (L2 , I2 , P2 ) be two relabelling systems and let R = R1 × R2 be the product of R1 and R2 . Whenever R1 and R2 terminate, so does R. Lemma 2. Let R1 = (L1 , I1 , P1 ) and R2 = (L2 , I2 , P2 ) be two relabelling systems and let R = R1 × R2 be the product of R1 and R2 . The set of invariants of R is the union of the sets of invariants of the two relabelling systems R1 and R2 .
Termination Detection of Distributed Algorithms
4 4.1
113
Termination Detection of a Graph Relabelling System The Termination Detection Problem
Consider a distributed system where processors communicate only by message passing. In such a system, a processor exchanges messages exclusively with its neighbours. Therefore, it is not trivial for a processor to have an up-to-date knowledge on the global state of the system, and to decide whether a distributed computation has finished. There are two types of termination. In an implicitly terminating algorithm, each execution is finite and in the last state of the execution each node has the correct result. However, the nodes are not aware that their state is the last one in the execution. Termination is said to be explicit in a process if that process is in a terminal configuration and its state is terminal. There were many proposals for termination detection algorithms: such algorithms transform implicitly into explicitly terminating algorithms. Several conditions were found to allow such algorithms and for each of these conditions a specific algorithm was given (see [16]). In this paper, by termination we mean explicit termination. In the next section, we give a solution to make a graph relabelling system detect locally the global termination. We use termination detection techniques such as the Dijkstra-Scholten algorithm [7], or the algorithm to detect stable property [18]. In fact, we reduce the problem of termination detection to a product of two relabelling systems. We start by a description of some termination detection algorithms expressed as relabelling systems. Then we will show how to use them for detecting termination of other distributed algorithms. 4.2
Examples of Termination Detection Algorithms
In this section, we present some distributed algorithms which detect the global termination of a graph relabelling system. The Dijkstra-Scholten Algorithm. Consider a network of processors modeled by a graph. Each processor, represented by a vertex, is always in one of two states active or passive. The processors communicate solely by messages. Some of these messages are referred to as activation messages; they may set the receiver into an active state. An active processor maintains a count of the number of activations it has sent which have not yet been acknowledged. Initially, exactly one processor is active; then it activates its neighbours. The set of active nodes forms a dynamic tree where the root is the initial active node, and a node is the father of the nodes it activates. A leaf node is deleted from the tree if it has no active descendants; i.e., it has received acknowledgments for the activation messages it has sent. In this case, it sends a signal to acknowledge the activation to its father who will decrease its own count of active sons. We will call this tree the control tree. The computation terminates when the root has no active descendants.
114
Emmanuel Godard et al.
We give now a relabelling system to encode this algorithm. To do so, we equip each vertex of the graph with a counter (say sc) and with a flag describing its activity status (say a value in {Ac, P a}). Hence, a vertex will be labelled by a triple (X, Y, sc), where X is its label M, B, B ; Y is its activity status, and sc the counter described above. We will use the label M for vertices which have never been activated, B for the initial vertex and B for vertices beeing active at least once. An edge will be labelled by a label in {Ac, P a} indicating whether or not it belongs to the control tree. Initially, each edge is labelled P a and each node labelled (M, P a, 0); a distinguished node is labelled (B, Ac, 0) will be the root of the control tree. This node initializes the algorithm. We assume that the initial graph is finite. In this case, the value of the counter sc for each vertex is finite. Let R5 = (L5 , I5 , P5 ) be the relabelling system defined by L5 = {{B, B , M } × {Ac, P a} × [0..n]} ∪ {P a, Ac}, I5 = {(B, Ac, 0), (M, P a, 0), P a}, and P5 consisting of the following relabelling rules: (X, Ac, sc)
R1 :
Pa (M, P a, 0) (X, Ac, sc)
R2 :
Ac (B , Ac, 0)
(X, Ac, sc + 1) ; X ∈ {B, B }
Ac (B , Ac, 0)
(X, Ac, sc − 1)
Pa (B , P a, 0)
;
{
}
(M, P a, 0)
Pa (B , Ac, 0)
To prove the correctness of this algorithm, we give the following invariants. Let G(V, E, λ) be a connected labelled graph such that a distinguished vertex is labelled (B, Ac, 0), all other vertices are labelled (M, P a, 0) and every edge is la∗ belled P a. Let G (V, E, λ ) be a graph such that: G(V, E, λ) −−−−→ G (V, E, λ ). The graph G (V, E, λ ) satisfies:
R
1. 2. 3. 4.
All edges incident to a (M, P a, 0)-labelled vertex are labelled P a. A (B, Ac, sc)-labelled vertex has at least Ac-labelled incident edge, (sc = 0). The subgraph induced by the edges labelled Ac has no cycle. The (B, Ac, sc) and (B , Ac, sc ) labelled vertices are connected by Aclabelled edges. 5. A (X, P a, 0)-labelled vertex has no (M, P a, 0)-labelled neighbours, where X ∈ {B, B }. 6. If G be an irreducible graph obtained from G then all vertices are (B , P a, 0)labelled except one are (B, P a, 0)-labelled. The detection of termination of the algorithm occurs as soon as the counter (sc) of the root becomes zero (0). Other examples of termination detection algorithms can be described by graph relabelling systems [9]. These include in particular the Dijkstra-FeijenVan Gasteren algorithm [6].
Termination Detection of Distributed Algorithms
115
SSP. We describe the algorithm by Szymanski, Shi and Prywes (the SSP algorithm for short) [18]. We consider a distributed algorithm which terminates when all processes reach their local termination conditions. Each process is able to determine only its own termination condition. The SSP algorithm detects an instant in which the entire computation is achieved. Let G be a graph. To each node v are associated a predicate P (v) and an integer a(v). Initially P (v) is false and a(v) is equal to −1. Transformations of the value of a(v) are defined by the following rules. Each local computation acts on the integer a(v0 ) associated to the vertex v0 ; the new value of a(v0 ) depends on values associated with the neighbors of v. More precisely, let v0 be a vertex and let {v1 , ..., vd } the set of vertices adjacent to v0 . We consider in this section the following assumption. For each node v, the value P (v) eventually becomes true and remains true forever. – If P (v0 ) = f alse then a(v0 ) = −1; – if P (v0 ) = true then a(v0 ) = 1 + M in{a(vk ) | 0 ≤ k ≤ d}. 4.3
Composing Graph Relabelling Systems to Detect the Global Termination
Let RA = (LA , IA , PA ) be a graph relabelling system encoding a distributed algorithm for which termination detection will be added. We assume that within a finite number of steps, each vertex locally terminates; that is, no rule of PA can be applied. Note that such a configuration can be easily tested by using forbidden contexts consisting of the set of rules of PA . For the relabelling system in Example 1 of Section 2, the local termination for a vertex is reached if it is labelled A and its neighbours are labelled A. Our aim is to apply the termination detection algorithm on the vertices being in a terminal state to build a global termination detection. More precisely, let RT = (LT , IT , PT ) be a relabelling system encoding a termination detection algorithm. Assume that the rule of PT changing the state of a processor from an active to a passive state (or from False state to True State like in the SSP algorithm) is RP a . In order to detect the global termination of RA by using RT , we build the product RA × RT and add to the rule RP a a set of forbidden contexts indicating the local termination of the algorithm for the current vertex (no rule of the algorithm involving the current vertex will be applied). We denote the resulting relabelling system by RA ⊗ RT . Theorem 1. Let RA = (LA , IA , PA ) be a graph relabelling system encoding a distributed algorithm A. Let RT = (LT , IT , PT ) be a relabelling system encoding a termination detection algorithm T . The relabelling system RT A = RA ⊗ RT encodes the algorithm A with the termination detection property. Proof: We sketch the proof and use the following examples to illustrate this method. Termination and correctness of RT A are obvious, since they can be
116
Emmanuel Godard et al.
obtained from those of RA and RT . Now, to prove the termination detection property, it suffices to observe that an “active” processor becomes “passive” only if it terminates locally the execution of A (no rule of RA is applied). In such a case, the termination detection algorithm is executed (in fact, the rule RP a is applied). Since RT is expected to have the termination detection property, so is RT A . Computation of a Spanning Tree with the Dijkstra-Scholten Termination Detection. Now, given a relabelling system encoding a distributed algorithm which is initialized by exactly one vertex, to detect termination by the previous technique, one has to embed the relabelling computation into the control tree. A node will be passive if it has locally terminated (no rule can be applied on its context). The rules of the relabelling system are mapped using the new triple labelling. In order to keep up with the control tree of the termination algorithm, a relabelling rule encoding local termination and acknowledgment must be added. The relabelling system in Example 1 of Section 2.2 combined with Dijkstra termination techniques becomes the relabelling system with forbidden contexts R6 = (L6 , I6 , P6 ), defined by L6 = {{A, A , N }×{B, B , M }×{Ac, P a}×[0..n]}∪ {{0, 1} × {Ac, P a}}, I6 = {(A, M, Ac, 0), (N, B, Ac, 0), (N, M, P a, 0), (0, P a)}, and P6 consisting of the following relabelling rules: (A, X, AC, sc) (A, X, AC, sc)
R1 : P A
0
Where X, X ∈ {B, B , M }, Y, Y ∈ {A, N }, Z ∈ {B, B }, AC, AC ∈ {Ac, P a}, P A ∈ {Ac, P a}, S, S ∈ {0, 1}.
PA 1
(N, X , AC , sc ) (A, X , AC , sc ) (Y, Z, Ac, sc) (Y, Z, Ac, sc + 1)
R2 :
Pa S
Ac S
(Y, M, P a, 0) (Y, B , Ac, 0) (Y, Z, Ac, sc) (Y, Z, Ac, sc − 1)
R3 :
Ac S
(A, B , Ac, 0)
Pa S (A, B , P a, 0)
;
{
}
(Y, M, P a, 0) (N, Z, AC, sc ) P a S (A, B , Ac, 0)
,
PA 0
(A, B , Ac, 0)
Note that we give here a simplified system of the combination of the relabelling system of Section 2 with that of the Dijkstra-Scholten relabelling system. It is a relabelling system with forbidden contexts. The rules R1 and R2 are similar to the original ones, however, the rule R3 has another forbidden context as explained previously. A node locally terminates if it has no neighbour labelled N which has not been yet active. Such a node will be set in passive status, and will send an acknowledgment to its father if its counter is null. In the relabelling rule, we just decrement the counter sc of the father. The whole computation terminates if the root becomes passive and has no active descendants.
Termination Detection of Distributed Algorithms
117
Theorem 2. The relabelling system R6 computes a spanning tree. This algorithm has the property of detection of the global termination. The proof of this theorem is based on the invariants given for the DijkstraScholten algorithm and those of Example 1. 3-Coloration of a Ring with the Dijkstra-Scholten termination Detection. Consider the relabelling system of Section 2. It colors a ring with 3 colors, but it does not detect termination. Now, we show by the method described before how to add the termination detection. The local termination detection property is that a node with the label X has no neighbour labelled X, where X ∈ {c1 , c2 , c3 }. We will add this property to the second rule of the Dijkstra-Scholten Algorithm. The obtained algorithm is the following. Let R7 = (L7 , I7 , P7 ), defined by L7 = {{c1 , c2 , c3 } × {B, B , M } × {Ac, P a} × [0..n]} ∪ {Ac, P a}, I7 = {(X, B, Ac, 0), (X , M, P a, 0), P a}, where X and X ∈ {c1 , c2 , c3 }, and P7 consisting of the following relabelling rules: (X, Y1 , AP1 , sc ) Z
(X, Y3 , AP3 , sc ) Z
R1 :
(X, Y1 , AP1 , sc ) Z
(X, Y3 , AP3 , sc ) Z X = X1 X1 = X2 (X1 , Y2 , AP2 , sc) (X, Y1 , AP1 , sc ) (X1 , Y3 , AP3 , sc ) X2 = X Z Z
(X, Y2 , AP2 , sc) (X, Y1 , AP1 , sc ) (X1 , Y3 , AP3 , sc ) Z Z
R2 :
(X, Y2 , AP2 , sc)
(X2 , Y2 , AP2 , sc)
(X1 , Y, Ac, sc) (X1 , Y, Ac, sc + 1)
R3 :
Pa
Ac
(X2 , N, P a, 0) (X2 , A , Ac, 0) (X1 , A , Ac, 0)
R4 :
Ac
(X1 , A , P a, 0) Pa
{
;
(X2 , Y, Ac, sc) (X2 , Y, Ac, sc − 1)
Where X, X1 , X2 ∈ {c1 , c2 , c3 }, Y1 , Y2 , Y3 ∈ {A, A , N }, Y ∈ {A, A }, AP, AP1 , AP2 , AP3 ∈ {Ac, P a}, Z, Z , ∈ {Ac, P a},
(X1 , A , Ac, 0) (X1 , A , Ac, 0)
;
Pa
Z
}
(X, N, P a, 0) (X1 , Y1 , AP, sc )
3-Coloration of a Ring with the Detection of Stable Properties. We consider the same example as before but produced with the SSP algorithm [18] and moreover each vertex knows the size of the graph. Let R8 = (L8 , I8 , P8 ), defined by L8 = {{c1 , c2 , c3 } × {T, F } × [−1..n]}, I8 = {(X, F, −1)}, where X ∈ {c1 , c2 , c3 }, and P8 consisting of the following relabelling rules: R1 : R2 : R3 : R4 :
(X, V1 , n1 )
(X, V2 , n2 )
(X, F, −1) (X, V1 , n1 )
(Y, V2 , n2 )
(X, F, −1) (Y , V2 , n2 )
(Y, V1 , n1 )
(X, F, −1) (Y , T, n2 )
(Y, T, n1 ) (X, T, n)
(X, V1 , n1 )
(X, V2 , n2 )
(Y, T, min(n1 , n2 ) + 1) (X, V1 , n1 )
(Y, V2 , n2 )
(Z, T, min(n1 , n2 ) + 1) (Y, V1 , n1 )
(Y , V2 , n2 )
X, Y, Z ∈ {c1 , c2 , c3 } V1 , V2 ∈ {T, F } X = Z X = Y Y = Z Y = X
(X, T, min(n1 , n2 ) + 1) (Y, T, n1 )
(Y , T, n2 )
(X, T, min(n1 , n2 ) + 1)
The algorithm terminates if each node has the n-label greater or equal to the diameter of the graph, i.e. n ≥ S, where S is the diameter of the graph.
118
5
Emmanuel Godard et al.
Generalization of Termination Detection
In this section, we give general results obtained using the SSP algorithm to detect locally the global termination. First, we consider the case where each vertex is able to detect locally its own local termination, and where the diameter or the size of the graph is known. Then, we consider a variant of the SSP algorithm and give a more general result. 5.1
From Local Termination Detection to Global Termination Detection
For the last example (the 3-Coloration), it is clear that when a vertex is correctly colored, it sets the predicate P to the value true. In such a case, it detects locally the local termination. The predicate P remains true until the local detection of the global termination. More generally, the SSP’s algorithm can transform a relabelling system for which each vertex is able to detect its local termination into another relabelling system with the local detection of the global termination. Theorem 3. Let R be a graph relabelling system. Suppose that for an initial graph with known size, each vertex is able to detect its local termination. The system R can be transformed to a graph relabelling system with the local detection of the global termination. The proof is based on the SSP algorithm, and is similar to the 3-Coloration example. By assigning true predicates to vertices which detect the local termination, and by spreading the values of the integers a(v), it is possible to detect the global termination. 5.2
Termination Detection by a Variant of the SSP Algorithm
For the previous Theorem, we assumed that each vertex is able to detect its own local termination. We can weaken this assumption by dealing only with the applicability or not of relabelling rules. That is, during the relabelling process, if for a vertex v none of the rules is applicable to v (and its context), then the value of the predicate P for v is set temporarily to true. The computation process continues like for the previous case. Now, if later on, the vertex v is relabelled (for instance by one of its neighbours), then the value of the predicate P is reinitialized to false for v and a(v) is set to −1. Again, if P becomes true, then a(v) is set to 0 and so on. Therefore, we use a generalization of the SSP algorithm by dropping the last assumption. We can prove that it is possible to detect locally the global termination. Theorem 4. Let R be a graph relabelling system. Suppose that the diameter of the initial graph is known. The system R can be transformed to a graph relabelling system with the local detection of the global termination.
Termination Detection of Distributed Algorithms
119
References 1. M. Bauderon, S. Gruner, Y. M´etivier, M. Mosbah, and A. Sellami. Visualization of distributed algorithms based on labeled rewriting systems. In Second International Workshop on Graph Transformation and Visual Modeling Techniques, Crete, Greece, July 12-13, 2001. 2. M. Bauderon, Y. M´etivier, M. Mosbah, and A. Sellami. From local computations to asynchronous message passing systems. Technical Report RR-1271-02, LaBRI, 2002. 3. M. Billaud, P. Lafon, Y. M´etivier, and E. Sopena. Graph rewriting systems with priorities. Lecture notes in computer science, 411:94–106, 1989. 4. K. M. Chandy and L. Lamport. Distributed snapshots: Determining global states of distributed systems. ACM Transations on Computer Systems, 3(1):63–75, 1985. 5. K. Mani Chandy, Laura M. Haas, and Jayadev Misra. Distributed deadlock detection. ACM Transactions on Computer Systems, 1(2):144–156, May 1983. 6. Edsger W. Dijkstra, W. H. J. Feijen, and A. J. M. van Gasteren. Derivation of a termination detection algorithm for distributed computations. Information Processing Letters, 16(5):217–219, 1983. 7. E.W. Dijkstra and C.S. Sholten. Termination detection for diffusing computations. Information Processing Letters, 11(1):1–4, 1980. 8. S. Dolev. Self-stabilization. The MIT Press, 2000. 9. E. Godard, Y. M´etivier, M. Mosbah, and A. Sellami. Termination detection of distributed algorithms by graph relabelling systems. Technical report, LaBRIUniversity of Bordeaux 1, 2002. 10. I. Litovsky and Y. M´etivier. Computing trees with graph rewriting systems with priorities. Tree automata and languages, pages 115–139, 1992. 11. I. Litovsky and Y. M´etivier. Computing with graph rewriting systems with priorities. Theoret. Comput. Sci., 115:191–224, 1993. 12. I. Litovsky, Y. M´etivier, and E. Sopena. Different local controls for graph relabelling systems. Math. Syst. Theory, 28:41–65, 1995. 13. Y. M´etivier, M. Mosbah, and A. Sellami. Proving distributed algorithms by graph relabeling systems: Examples of trees in networks with processor identities. In Applied Graph Transformations, Grenoble, April, 2002. 14. Y. M´etivier and G. Tel. Termination detection and universal graph reconstruction. In International Colloquium on structural information and communication complexity, pages 237–251. Carleton scientific press, 2000. 15. M. Mosbah and A. Sellami. Visidia: A tool for the visualization and similation of distributed algorithms. http://www.labri.fr/visidia/. 16. G. Tel. Introduction to distributed algorithms. Cambridge University Press, 2000. 17. Gerard Tel and Friedemann Mattern. The derivation of distributed termination detection algorithms from garbage collection schemes. ACM Transactions on Programming Languages and Systems, 15(1):1–35, January 1993. 18. B. Szymanski Y. Shi and N. Prywes. Terminating iterative solutions of simultaneous equations in distributed message passing systems. In 4th International Conference on Distributed Computing Systems, pages 287–292, 1985.