• Aucun résultat trouvé

Breadth-First Spanning Tree Built Without Centralized ControlBuilt Without Centralized Control

Learning the Communication Graph

1.3 Breadth-First Spanning Tree

1.3.1 Breadth-First Spanning Tree Built Without Centralized ControlBuilt Without Centralized Control

Principle of the Algorithm This algorithm, which is due to T.-Y. Cheung (1983), is based on parallel traversals of the communication graph. These traversals are con-current and some of them can stop others. In addition to the local variables parenti, childreni, and expexted_msgi, each process pi manages a local variable, denoted leveli, which represents its current approximation of its distance to the root. More-over, each messageGO()carries now the current level of the sending process.

Then, when a processpireceives a messageGO(d), there are two cases according to the current state ofpi and the value ofd.

• The message GO(d) is the first message GO() received by pi. In that case, pi initializes leveli tod+1 and forwards the messageGO(d+1)to its neighbors (except the sender of the messageGO(d)).

• The messageGO(d)is not the first message GO()received by pi and leveli >

d+1. In that case, pi (a) updates its variable leveli tod +1, (b) defines the sender of the messageGO(d)just received as its new parent, and (c) forwards a messageGO(d+1)to each of its other neighborspkin order that they recompute their distances to the root.

As we can see, these simple principles consist of a chaotic distributed iterative computation. They are used to extend the basic parallel network traversal algorithm of Fig.1.7with a forward/discard strategy that allows processes to converge to their final position in the breadth-first spanning tree.

Description of the Algorithm The algorithm is described in Fig. 1.11. As just indicated, it uses the parallel network traversal described in Fig.1.7as a skeleton on which are grafted appropriate statements to obtain a breadth-first rooted span-ning tree. These new statements implement the convergence of the local variables parenti, childreni, and leveli to their final values. More precisely, we have the fol-lowing.

Initially, a single processpireceives an external messageSTART(). This process, which will be the root of the tree, sends a messageGO(−1)to itself (line1). When it receives the message,pi sets parenti =i(hence it is the root) and its distance to itself is set to leveli=0.

As previously indicated, there are two cases when a processpi receives a mes-sageGO(d). Let us remember that d represents the current approximation of the distance of the sender of the messageGO()to the root. If parenti= ⊥, this message is the first messageGO()received by pi (line2). In that case,pi enters the tree at leveld+1 (line3) and propagates the network traversal to its other neighbors by sending them the messageGO(d+1)in order that they enter the tree or improve their position in the tree under construction (line5). If the sender of the message

GO(d)is its only neighbor, pi sends by return the messageBACK(yes, d+1)to inform it that it is one of its children at leveld+1 (line6).

whenSTART()is received do % only the distinguished process receives this message %

whenBACK(resp, d)is received frompjdo (19) if(d=leveli+1)

(20) then if(resp=yes)then childrenichildreni∪ {j}end if;

(21) expected_msgiexpected_msgi1;

(22) if(expected_msgi=0)

(23) then if(parenti=i)thensendBACK(yes,leveli)topparenti (24) else pilearns that the breadth-first tree is built

(25) end if

(26) end if

(27) end if.

Fig. 1.11 Construction of a breadth-first spanning tree without centralized control (code forpi)

If the messageGO(d)is not the first messageGO()received bypi, there are two cases. Letpjbe the sender of the messageGO(d).

If levelid+1,picannot improve its position in the tree. It then sends by return the messageBACK(no, d+1)to inform the sender of the messageGO()that it cannot be its child at distanced +1 of the tree (line 16). Hence,pi stops the network traversal associated with the messageGO(d)it has received.

If leveli> d+1,pi has to improve its position in the tree under construction. To that end, it propagates the network traversal associated with the messageGO(d)it has received in order to allow its other neighbors to improve their positions in the tree. Hence, it executes the same statements as those executed when it received its first messageGO(d)(lines10–15are exactly the same as lines3–8).

When a process pi receives a message BACK(resp, d), it considers it only if leveli=d−1 (line19). This is because this message is meaningful only if its sender pjsent it when its level was levelj=d=leveli+1. In the other cases, the message

1.3 Breadth-First Spanning Tree 19

Fig. 1.12 An execution of the algorithm of Fig.1.11

BACK()is discarded. If the message is meaningful and resp=yes,pi addspj to its children (and those are at level leveli+1, line20).

Finally, as in a simple parallel network traversal, if it has received a mes-sageBACK(,leveli +1)from each of its other neighbors, pi sends a message

BACK(yes,leveli)to its current parent. Ifpi is the root, it learns that the breadth-first tree is built. Let us observe that, ifpi is not the root, it is possible that it later receives other messagesGO()that will improve the current value of leveli.

Termination It follows from line 23that the root learns the termination of the algorithm.

On the other hand, the local variable leveli of a processpi, which is not the root, can be updated each time it receives a messageGO(). Unfortunately, the number of such messages received bypi is not limited to the number of its neighbors but depends on (a) the number of neighbors of its neighbors, etc. (i.e., the structure of the communication graph), and (b) the speed of messages (i.e., asynchrony). As its knowledge of the communication graph is local (it is restricted to its neighbors), a process cannot define a local predicate indicating that its local variables have con-verged to their final values. But, as the root can discover when the construction of the tree has terminated, it can send a message (which will be propagated along the tree) to inform the other processes that their local variables parenti, childreni, and leveli have their final values.

A Simple Example Let us consider the communication graph described on the left of Fig.1.12. As the graph is a clique, a single breadth-first tree can be obtained, namely the star graph centered at the distinguished process (herep1). This star is depicted on the right of the figure.

A worst case execution of the algorithm of Fig.1.11is depicted in the middle of Fig.1.12(worst case with respect to the number of messages). Only the message

GO()from a processpi to a processpj withi < j is represented in the space-time diagram. The worst case occurs when the messageGO() sent byp1 top3arrives after the messageGO()sent byp2, and both the messageGO()sent byp1top4and the messageGO()sent byp2top4arrive after the messageGO()sent byp3top4. It follows that, with this pattern of message arrivals,p2discovers it is at distance 1 when it receives its first messageGO(),p3discovers that it is at distance 1 when it receives the messageGO()sent byp1, and similarly andp4discovers it when it receives the messageGO()sent byp1.

Cost There are two type of messages, and each message carries an integer whose value is bounded by the diameterDof the communication graph. Moreover, a mes-sageBACK() carries an additional Boolean value. It follows that the size of each message is upper bounded by 2+log2Dbits. It is easy to see that the time com-plexity isO(D), i.e.,O(n)in the worst case.

As far as the message complexity is concerned, the worst case is a fully connected communication graph (i.e., any pair of processes is connected by a channel) and a process at distancedof the root updates leveli dtimes (as in Fig.1.12). This means that among the(n−1)processes which are not the root, one updates its level once, another one updates it twice, etc., and one updates it(n−1)times. Moreover, each time a process updates its level, a process forwards the messagesGO()to(n−2) of its neighbors (all processes but itself and the sender of theGO()that entailed the update of its own level). The root sends(n−1)messages GO(). Hence the total number of messagesGO()is

As at most one messageBACK()is associated with each messageGO(), it follows that, in a fully connected network, the message complexity is upper bounded by O(n3).

Outline

Documents relatifs