• Aucun résultat trouvé

Another algorithm for local orientation

Dans le document Message-Passing Systems (Page 41-44)

2.2 Computations on anonymous systems

2.2.3 Another algorithm for local orientation

In addition to Algorithm S_Compute_AND, another example of how to employ many fewer messages than those required by Algorithm A_Compute_f comes from considering a synchronous algorithm tailored specifically to establishing a local orientation on the ring. By Theorem 2.6, such an algorithm may only exist if n is odd, as we assume henceforth in this section.

The basic strategy behind this algorithm employs the following terminology. Say that two nodes ni and nj are segment ends if (ni, nj) ∊ E and furthermore (ni, nj) = lefti = leftj. Segment ends delimit segments, which are subsets of N inducing connected subgraphs of G with at least two nodes. If ni and nj are segment ends and (ni, nj) ∊ E, then ni, and nj belong to different segments, unless the number of segments in the ring is exactly one. Clearly, a locally oriented ring contains no segment ends, while a ring that is not locally oriented contains a nonzero even number of segment ends, and half as many segments. Because n is odd, an odd number of segments must have an odd number of nodes each.

The synchronous algorithm proceeds in iterations, each one comprising two phases. Initially, all nodes are said to be active, and the goal of each of the iterations is to reduce the number of active nodes. During an iteration, nodes that are not active function solely as message relays, so that the computation can always be looked at as being carried out on a ring containing the active nodes only, called the active ring. Iterations proceed until exactly one active node remains or until an active ring is reached which is locally oriented (in this case with more than one active node). A local orientation can then be established on the entire ring by the last active nodes.

The number of iterations that the algorithm requires depends largely on how active nodes are eliminated from one iteration to the next. In Algorithm S_Locally_Orient, given next, this elimination takes place as follows. In the first phase of an iteration, segment ends are identified on the active ring. Then, in the second phase, the nodes, called center nodes, occupying the central positions in the segments having an odd number of nodes are

identified and selected to be the only active nodes to remain through to the next iteration. By our preceding discussion, the number of center nodes must be odd, and then so must the number of nodes in every active ring, thereby guaranteeing the feasibility of every iteration.

The last iteration is characterized by the absence of segment ends among the active nodes.

Because at each iteration segments with an even number of nodes do not contribute with any active node to the next iteration, and considering that segments with odd numbers of nodes have at least three nodes each, clearly the number of iterations required is no larger than

⌈log3n⌉ = O (log n).

Letting σ ≥ O indicate the pulses within each of the iterations, the following is how the two aforementioned phases within an iteration are implemented. At pulse σ = O, node ni, if active, sends token on edge righti. Active nodes then idle throughout the following n − 1 pulses,

while nodes that are not active simply relay token onward if they at all receive it. An active node ni that by pulse σ = n has not received token on lefti is a segment end, and at pulse σ = n sends the integer O on righti. Throughout the following n − 1 pulses (i.e., from pulse σ = n+1 through pulse σ = 2n − 1), active nodes forward the integer z + 1 upon receiving integer z, for some z ≥ 0, while the other nodes continue to function as relays. An active node ni that by pulse σ = 2n has received the same integer over lefti and righti during the same interval is a center node. This is the last iteration if ni did not receive any message during intervals n through 2n − 1, otherwise only center nodes remain active for the next iteration. A message orient is sent on, say, lefti by an active node ni after the last iteration. This message, if received on lefti by a node ni that is not active, causes lefti and righti to be interchanged.

The reader should notice that the characteristics of the synchronous model are used profusely in this strategy to establish a local orientation. Indeed, both the determination of segment ends and of center nodes rely heavily on the assumed synchronism, as does the determination of when an iteration is the last one.

In Algorithm S_Locally_Orient, k identifies the iteration and is then such that 1 ≤ k ≤ K, where K is the last iteration, therefore such that K ≤ ⌈log3 n⌉. Pulses within the kth iteration are numbered s = 2n(k − 1) + σ, that is, from s = 2n(k − 1) through s = 2nk. After the last

iteration, additional n − 1 pulses must elapse before termination. The only variable employed by ni is the Boolean variable activei, initially set to true, used to indicate whether ni is active.

Because initially activei = true for all ni ∊ N, in this algorithm N0 = N. Because K has to be determined as the algorithm progresses, it is assumed to be equal to infinity initially.

Algorithm S_Locally_Orient:

Variables:

activei = true.

Listing 2.14 Input:

s = 2n(k − 1), MSGi(s) = . Action (if ni ∊ N0, for k = 1):

if activei then

Send token on righti.

Listing 2.15 Input:

2n(k − 1) + 1 ≤ s ≤ 2nk − n − 1, MSGi(s).

Action:

if not activei then begin

if there exists token ∊ MSGi(s) such that origini(token) = lefti then

Send token on righti;

if there exists token ∊ MSGi(s) such that origini (token) = righti then

Send token on lefti

end.

Listing 2.16 Input:

s = 2nk − n, MSGi(2n(k − 1) + 1),…, MSGi(2nk − n).

Action:

if activei then

if there does not exist token MSGi(r) such that origini (token) = lefti then

Send 0 on righti.

Listing 2.17 Input:

2nk − n + 1 ≤ s ≤ 2nk − 1, MSGi(s).s Action:

if activei then begin

if there exists z ∊ MSGi(s) such that origini(z) = lefti

then

Send z + 1 on righti;

if there exists z ∊ MSGi(s) such that origini(z) = righti

then

Send z + 1 on lefti

end else begin

if there exists z ∊ MSGi(s) such that origini(z) = lefti

then

Send z on righti;

if there exists z ∊ MSGi(s) such that origini (z) = righti

then

Send z on lefti

end.

Listing 2.18 Input:

s = 2nk, MSGi(2nk − n + 1),…, MSGi(2nk).

Action:

if activei then

if MSGi(r) = for all r ∊ {2nk − n,…,2nk − 1} then begin

K ≔ k;

Send orient on lefti

end else

if there do not exist r ∊ {2nk − n,…, 2nk − 1} and z1, z2 ∊ MSGi(r) with z1 = z2 such that origini(z1) = lefti

and origini(z2) = righti then activei ≔ false.

Listing 2.19 Input:

2nK + 1 ≤ s ≤ 2nK + n − 1, MSGi(s) Action:

if not activei then begin

if there exists orient ∊ MSGi(s) such that origini(orient) = lefti then

Interchange lefti and righti; Send orient on lefti

end.

In Algorithm S_Locally_Orient, (2.14) implements the sending of token at the beginning of each iteration, while in (2.15) the relaying of token by nodes that are not active appears. In (2.16), segment ends are identified and initiate the propagation of integers, which are relayed as appropriate by (2.17). Center nodes are identified in (2.18), which, in the last iteration, also includes the propagation of orient, relayed onward by (2.19). In no action does a node send more than two messages, and then the number of messages per iteration is clearly O(n). It follows from our earlier determination of the maximum number of iterations that the message complexity of Algorithm S_Locally_Orient is O(n log n).

Dans le document Message-Passing Systems (Page 41-44)