• Aucun résultat trouvé

Application: Construction of a Logical Ring

Learning the Communication Graph

1.4 Depth-First Traversal

1.4.2 Application: Construction of a Logical Ring

The Notion of a Local Algorithm Both the previous algorithm (Fig.1.16) and its improvement are local in the sense that (a) each process has initially to know only its identity, that of its neighbors, and the fact no two processes have the same identity, and (b) the size of the information exchanged between any two neighbors is bounded.

Another Improvement of the Basic Depth-First Traversal Algorithm This part presents a depth-first traversal algorithm that is not local but whose message com-plexity and time comcom-plexity areO(n). The idea is to replace the local synchroniza-tion used by the improved version of the previous algorithm (implemented with the messages VISITED()andKNOWN()) by a global control information, namely, the set (denoted visited) of the processes which have been already visited by the net-work traversal (i.e., by messagesGO()). To that end, each messageGO()and each messageBACK()carry the current value of the set visited.

The corresponding depth-first traversal algorithm is described in Fig.1.17. When the distinguished processpareceives the external messageSTART(), it defines itself as the root (parenti=i, line1), and launches the depth-traversal by sending a mes-sageGO({i})to one of its neighbors that it includes in its set of children (lines2–3).

Then, when a processpireceives a messageGO(visited)from a neighbor process pj, it defines pj as its parent (line 4). If all of its neighbors have been visited, pi sends back the messageGO(visited∪ {i}) to its parent (line6). Otherwise, it

propagates the depth-first traversal to one of its neighborspk that has not yet been visited and initializes childrenito{k}(lines7–8).

Finally, when a process pi receives a message BACK(visited)such that all its neighbors have been visited (line10), it claims termination if it is the root (line12).

If it is not the root, it forwards the messageBACK(visited)to its parent (line13). If some of its neighbors have not yet been visited,pi selects one of them, propagates the network traversal by sending to it the messageGO(visited)and adds it to its set of children (lines15–16).

It is easy to see that this algorithm builds a depth-first spanning tree, and requires (n−1) messages GO()and (n−1) messages BACK(). As no two messages are concurrent, the time complexity is 2(n−1). As already indicated, this algorithm is not local: the set visited carried by each message grows until it contains all the process identities. Hence, the size of a message includes one bit for the message type and up tonlog2nbits for its content.

A Token Traveling Along a Logical Ring A token is a message that navigates a network. A simple way to exploit a token consists in using a logical unidirectional ring. The token progresses then from a process to the next process on the ring.

Assuming that no process keeps the token forever, it follows that no process that wants to use the token will miss it.

The problem that then has to be solved consists in building a logical unidirec-tional ring on top of a connected arbitrary network. Such a construction is presented below.

In order that the ring can be exploited by the token, the algorithm building the ring computes the value of two local variables at each processpi:

The local variable succi denotes the identity of the successor ofpi on the unidi-rectional ring.

The local variable routingi[j], wherepj is a neighbor ofpi, contains the identity of its neighbor to whichpi will have to forward the token when it receives it frompj.

The set of local variables routingi[j], 1≤in, defines the appropriate rout-ing (at the level of the underlyrout-ing communication graph) which ensures the cor-rect move of the token on the logical ring from any process to its logical successor.

Once these two local variables have been computed at each processpi, the navi-gation of the token is easily ensured by the statements described in Fig.1.18. When it leaves a process, the token carries the identity dest of its destination, i.e., the next process on the unidirectional ring. When it receives the token and dest=i, a pro-cesspi uses it. Before releasing it, the process sets the token field dest to succi, the next process on the ring (i.e., the next process allowed to use the token). Finally, (whether it was its previous destination or not)pisends the token to its neighborpk such thatk=routingi[j](wherepjis the process from which it received the token in the communication graph). Hence, when considering the underlying communi-cation graph, the token progresses frompi topk wherek=routingi[j], then top

where=routingk[i], then topmwherem=routing[k], etc., where the sequence

1.4 Depth-First Traversal 29 Fig. 1.18 Management

of the token at processpi whenTOKEN(dest)is received frompjdo

if(dest=i)then use the token; destsucciend if;

letk=routingi[j];sendTOKEN(dest)topk.

of successive neighbor processespj, pi, pk, p, . . . , pj constitutes the circuit im-plementing the logical unidirectional ring.

A Distributed Algorithm Building a Logical Ring The distributed depth-first traversal algorithm described in Fig. 1.17 constitutes the skeleton on which are grafted statements that build the logical ring, i.e., the statements that give their values to the local variables succi and routingi[j]of each processpi. The result-ing algorithm, which is due to J.-M. Hélary and M. Raynal (1988), is described in Fig.1.19.

As we can see, this algorithm is nearly the same as that of Fig.1.17. Its under-lying principle follows: As a process receives a single messageGO(), a process is added to the logical ring when it receives such a message. Moreover, in addition to the set of processes visited, each message is required to carry the identity (denoted last) of the last process that received a messageGO().

In order to establish the sense of direction of the ring and compute the distributed routing tables, the algorithm uses the total order in which processes are added to the ring, i.e., the order in which the processes receive a messageGO(). More precisely, the sense of direction of the ring is then defined as opposite to the order in which the processes are added to the ring during its construction. This is depicted in Fig.1.20.

whenSTART()is received do % onlypareceives this message % (1) parentii;

(2) letkneighborsi;

(3) sendGO({i}, i)topk; firstik.

whenGO(visited,last)is received frompjdo (4) parentij; succilast;

whenBACK(visited,last)is received frompjdo (10) if(neighborsivisited)

(11) then if(parenti=i)

(12) then succilast; routingi[firsti] ←j% the ring is built % (13) else sendBACK(visited,last)topparenti; routingi[parenti] ←j

(14) end if

(15) else letkneighborsi\visited;

(16) sendGO(visited,last)topk; routingi[k] ←j (17) end if.

Fig. 1.19 From a depth-first traversal to a ring (code forpi)

Fig. 1.20 Sense of direction of the ring and computation of routing tables

From an operational point of view, we have the following. When the distin-guished process receives the messageSTART()it defines itself as the starting pro-cess (parenti =i), selects one of its neighbors pk, and sends topk the message

GO(visited, i)where visited= {i}(lines1–3). Moreover, the starting process records the identitykin order to be able to close the ring when it discovers that the depth-first traversal has terminated (line12).

When a processpi receives a message GO(visited,last)(let us remember that it receives exactly one messageGO()), it defines (a) its parent with respect to the depth-first traversal as the senderpj of the messageGO()), and (b) its successor on the ring as the last process (before it) that received a messageGO(), i.e., the processplast (line4). Then, if all its neighbors have been visited by the depth-first traversal, it sends back to its parentpj the messageGO(visited∪ {i}, i)and defines the appropriate routing for the token, namely it sets routingi[j] =j (lines5–6). If there are neighbors ofpi that have not yet been visited,pi selects one of them (say pk) and propagates the depth-first traversal by sending the messageGO(visited∪ {i}, i)topk. As before, it also defines the appropriate routing for the token, namely it sets routingi[k] =j (lines7–8).

When a processpi receives a messageBACK(visited,last), it does the same as previously if some of its neighbors have not yet been visited (lines15–16are similar to lines7–8). If all its neighbors have been visited andpi is the starting process, it closes the ring by assigning to routingi[firsti]the identityj of the process that sent the message BACK(,) (lines 11–12). If pi is not the starting process, it forwards the messageBACK(visited,last)to its parent which will make the depth-first traversal progress. It also assigns the identityjto routingi[parenti]for the token to be correctly routed along the appropriate channel of the communication graph in order to attain its destination process on the logical ring.

Cost This ring construction requires always 2(n−1)messages: (n−1) mes-sagesGO()and(n−1)messagesBACK(). Moreover the ring hasnvirtual channels vc1, . . . , vcnand the lengthxofvcx, 1≤xn, is such that 1x(n−1)and Σ1xnx=2(n−1). Hence, both the cost of building the ring and ensuring a full turn of the token on it are 2(n−1)messages sent one after the other.

Remarks The two logical neighbors on the ring of each processpi depend on the way a process selects a non-visited neighbor when it has to propagate the depth-first traversal.

Allowing the messagesGO()andBACK()to carry more information (on the struc-ture of the network that has been visited—or has not been visited—by the depth-first

1.4 Depth-First Traversal 31 Fig. 1.21 An example

of a logical ring construction

traversal) allows the length of the ring at the communication graph level to be re-duced tox, wherex∈ [n . . .2(n−1)]. This numberx depends on the structure of the communication graph and the way neighbors are selected when a process prop-agates the network traversal.

An Example Let us consider the communication graph depicted Fig.1.21 (with-out the dotted arrows). The dotted arrows represent the logical ring constructed by the execution described below.

In this example, when a process has to send a messageGO()to one of its neigh-bors, it selects the neighbor with the smallest identity in the set neighborsi\visited.

1. The distinguished process sends the messageGO({1},1)to its neighborp2and saves the identity 2 into firstito be able to close the ring at the end of the network traversal.

2. Then, when it receives this message, p2 defines succ2 =1, forwards the depth-first traversal by sending the message GO({1,2},2) to p3 and defines routing2[3] =1.

3. When p3 receives this message, it defines succ3 =2, forwards the depth-first traversal by sending the message GO({1,2,3},3) to p4 and defines routing3[4] =2.

4. Whenp4receives this message, it defines succ4=3, and propagates the depth-first traversal by sending the message BACK({1,2,3,4},4) to its parent p3. Moreover, it defines routing4[3] =3.

5. When p3 receives this message, as neighbors3visited and it is not the starting process, it forwards BACK({1,2,3,4},4)to its parent p2 and defines routing3[2] =4.

6. Whenp2receives this message, as neighbors3is not included in visited, it selects its not yet visited neighborp5and sends it the messageGO({1,2,3,4},4). It also defines routing2[5] =3.

7. Whenp5receives this message, it definesp4as its successor on the logical ring (succ5=4), sends back to its parentp2the messageBACK({1,2,3,4,5},5)and defines routing5[2] =2.

8. When p2 receives this message, p2 forwards it to its parent p1 and defines routing2[1] =5.

Table 1.1 The paths implementing the virtual channels of the logical ring

Virtual channel of the ring Implemented by the path

2 1 2 1

1 5 1 2 5

5 4 5 2 3 4

4 3 4 3

3 2 3 2

9. Finally, when p1 receives the message BACK({1,2,3,4,5},5), all its neigh-bors have been visited. Hence, the depth-first traversal is terminated. Conse-quently,p1closes the ring by assigning its value to routing1[first1], i.e., it defines routing1[2] =2.

The routing tables at each process constitute a distributed implementation of the paths followed by the token to circulate on the ring from each process to its suc-cessor. These paths are summarized in Table1.1which describes the physical paths implementing thenvirtual channels of the logical ring.

1.5 Summary

After defining the notion of a distributed algorithm, this chapter has presented sev-eral traversal network algorithms, namely, parallel, breadth-first, and depth-first traversal algorithms. It has also presented algorithms that construct spanning trees or rings on top of a communication graph. In addition to being interesting in their own right, these algorithms show that distributed traversal techniques are different from their sequential counterparts.

Outline

Documents relatifs