1.45k likes | 1.58k Views
Selecting leader in a clique in O (n log n) By Pierre A.Humblet Presented by: Anat Berkman, 236357 Distributed Algorithms , Technion. Problem background. Arbitrary non empty subset wake up spontaneously ans start executing common asynchronous distributed algorithm. 5. 17. 4. 3. 1. 2.
E N D
Selecting leader in a clique in O (n log n) By Pierre A.Humblet Presented by: Anat Berkman, 236357 Distributed Algorithms , Technion
Problem background Arbitrary non empty subset wake up spontaneously ans start executing common asynchronous distributed algorithm 5 17 4 3 1 2 1 2 19 2 3 67 4
Assumption Messages arrive without error after an arbitrary but finite delay
The algorithm Main idea : as long as a node did not surrender he tries to capture other nodes according to the edges. First he tries to capture the node at the end point of edge #1, then #2 and so on. 5 17 4 3 1 2 1 2 19 2 3 67 4
5 wants to capture 17 1. TEST: I want to capture you! 3. Master, 5 want to have a fight 17 5 17 4. Lets have a fight: 5 vs 17 2. Let me ask my master
5 wants to capture 17 1. TEST: I want to capture you! 3. Master, 5 want to have a fight 17 5 17 4. Lets have a fight: 5 vs 17 2. Let me ask my master 5. Answer to the fight 6. If 5 won- tell him
Wake up call A: B: WINNER(A)
Wake up call A: STATE:activeSIZE:0MASTER:A B: STATE:activeSIZE:0MASTER:B WINNER(A) STATE is active\stopped. Active means he was not captured yetSIZE is the size of my kingdom MASTER is the identity of my master
A process the message of type “WINNER” A: STATE:activeSIZE:0MASTER:A B: STATE:activeSIZE:0MASTER:B WINNER(A) If ID=id (yes) if state='active' then SIZE=SIZE+1 If SIZE=N stop if STATE='active' then send TEST(SIZE,ID) on edge SIZE
A process the message of type “WINNER” A: STATE:activeSIZE:1MASTER:A B: STATE:activeSIZE:0MASTER:B WINNER(A) If ID=id (yes) if state='active' then SIZE=SIZE+1if SIZE=N stop! if STATE='active' then send TEST(SIZE,ID) on edge SIZE
A process the message of type “WINNER” A: STATE:activeSIZE:1MASTER:A B: STATE:activeSIZE:0MASTER:B WINNER(A) If ID=id (yes) if state='active' then SIZE=SIZE+1 if SIZE=N stop! if STATE='active' then send TEST(SIZE,ID) on edge SIZE
A process the message of type “WINNER” A: STATE:activeSIZE:1MASTER:A B: STATE:activeSIZE:0MASTER:B TEST(1,A) WINNER(A) If ID=id (yes) If STATE='active' then SIZE=SIZE+1 If SIZE=N stop if STATE='active' thenSend TEST(SIZE,ID) on edge SIZE
B process the message of type “TEST” on edge 1 A: STATE:activeSIZE:1MASTER:A B: STATE:activeSIZE:0MASTER:B EDGE_TO(MASTER)= -1 TEST(1,A) WINNER(A) If e >= SIZE then: \\{not in our domain, tell the master} EDGE_TO(id)=e PENDING=PENDING+1 IF PENDING=1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,if) in PENDING_SET
B process the message of type “TEST” on edge 1 A: STATE:activeSIZE:1MASTER:A B: STATE:activeSIZE:0MASTER:B EDGE_TO(MASTER)=-1EDGE_TO(A)=1 TEST(1,A) WINNER(A) If e >= SIZE then: \\{not in our domain, tell the master} EDGE_TO(id)=e \\{not in our domain, tell the master} PENDING=PENDING+1 IF PENDING=1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,if) in PENDING_SET
B process the message of type “TEST” on edge 1 A: STATE:activeSIZE:1MASTER:A B: STATE:activeSIZE:0MASTER:B EDGE_TO(MASTER)=-1EDGE_TO(A)=1PENDING=0+1=1 TEST(1,A) WINNER(A) If e >= SIZE then: \\{not in our domain, tell the master} EDGE_TO(id)=ePENDING=PENDING+1 IF PENDING=1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,if) in PENDING_SET PENDING is the number of messages I received but did not finished responding
B process the message of type “TEST” on edge 1 EDGE_TO(MASTER)=-1EDGE_TO(A)=1PENDING=0+1=1 A: STATE:activeSIZE:1MASTER:A B: STATE:activeSIZE:0MASTER:B TEST(1,A) WINNER(A) TEST(1,A) If e >= SIZE then: \\{not in our domain, tell the master} EDGE_TO(id)=e PENDING=PENDING+1 IF PENDING=1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,if) in PENDING_SET
B process the message of type “TEST” on edge -1 EDGE_TO(MASTER)=-1EDGE_TO(A)=1PENDING=0+1=1 A: STATE:activeSIZE:1MASTER:A B: STATE:activeSIZE:0MASTER:B TEST(1,A) WINNER(A) TEST(1,A) If e >= SIZE then: \\{not in our domain, tell the master} EDGE_TO(id)=e PENDING=PENDING+1 IF PENDING=1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,if) in PENDING_SET
B process the message of type “TEST” on edge -1 EDGE_TO(MASTER)=-1EDGE_TO(A)=1PENDING=0+1=1 A: STATE:activeSIZE:1MASTER:A B: STATE:stoppedSIZE:0MASTER:B TEST(1,A) WINNER(A) TEST(1,A) If e >= SIZE then: \\{not in our domain, tell the master} EDGE_TO(id)=e PENDING=PENDING+1 IF PENDING=1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,if) in PENDING_SETelse \\(e<SIZE) If (size,id) > (SIZE,ID) then STATE='stopped' send WINNER(id) on edge e
B process the message of type “TEST” on edge -1 EDGE_TO(MASTER)=-1EDGE_TO(A)=1PENDING=0+1=1 A: STATE:activeSIZE:1MASTER:A B: STATE:stoppedSIZE:0MASTER:B TEST(1,A) WINNER(A) TEST(1,A)WINNER(A) If e >= SIZE then: \\{not in our domain, tell the master} EDGE_TO(id)=e PENDING=PENDING+1 IF PENDING=1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,if) in PENDING_SETelse \\(e<SIZE) If (size,id) > (SIZE,ID) then \\if (1,A) > (0,B) YES!!!! lexicographic order STATE='stopped' send WINNER(id) on edge e
B process the message of type “WINNER(A)” on edge -1 EDGE_TO(MASTER)=-1EDGE_TO(A)=1PENDING=0+1=1 A: STATE:activeSIZE:1MASTER:A B: STATE:stoppedSIZE:0MASTER:A TEST(1,A) WINNER(A) TEST(1,A)WINNER(A) If ID=idElse If MASTER <> id //if B<>A MASTER=id send WINNER(id) on EDGE_TO(A) PENDING=PENDING-1 If PENDING > 0 then ..
B process the message of type “WINNER(A)” on edge -1 EDGE_TO(MASTER)=-1EDGE_TO(A)=1PENDING=0+1=1 A: STATE:activeSIZE:1MASTER:A B: STATE:stoppedSIZE:0MASTER:A TEST(1,A) WINNER(A) WINNER(A) TEST(1,A)WINNER(A) If ID=idElse If MASTER <> id //if B<>A MASTER=id send WINNER(id) on EDGE_TO(A) PENDING=PENDING-1 If PENDING > 0 then ..
B process the message of type “WINNER(A)” on edge -1 EDGE_TO(MASTER)=-1EDGE_TO(A)=1PENDING=1-1=0 A: STATE:activeSIZE:1MASTER:A B: STATE:stoppedSIZE:0MASTER:A TEST(1,A) WINNER(A) WINNER(A) TEST(1,A)WINNER(A) If ID=idElse If MASTER <> id //if B<>A send WINNER(id) on EDGE_TO(A) PENDING=PENDING-1 If PENDING > 0 then ..
A process the message of type “WINNER(A)” on edge 1 EDGE_TO(MASTER)=-1EDGE_TO(A)=1PENDING=1-1=0 A: STATE:activeSIZE:1MASTER:A B: STATE:stoppedSIZE:0MASTER:A TEST(1,A) WINNER(A) WINNER(A) TEST(1,A)WINNER(A) If ID=idElse If MASTER <> id //if B<>A send WINNER(id) on EDGE_TO(A) PENDING=PENDING-1 If PENDING > 0 then ..
A process the message of type “WINNER(A)” on edge 1 EDGE_TO(MASTER)=-1EDGE_TO(A)=1PENDING=1-1=0 A: STATE:activeSIZE:2MASTER:A B: STATE:stoppedSIZE:0MASTER:A TEST(1,A) WINNER(A) WINNER(A) TEST(1,A)WINNER(A) If ID=id \\ if A=A if STATE='active then SIZE=SIZE+1 if SIZE=N then STOPElse If MASTER <> id //if B<>A send WINNER(id) on EDGE_TO(A) PENDING=PENDING-1 If PENDING > 0 then ..
A process the message of type “WINNER(A)” on edge 1 EDGE_TO(MASTER)=-1EDGE_TO(A)=1PENDING=1-1=0 A: STATE:activeSIZE:1MASTER:A B: STATE:stoppedSIZE:0MASTER:A TEST(1,A) WINNER(A) WINNER(A) TEST(1,A)WINNER(A) If ID=id \\ if A=A if STATE='active then SIZE=SIZE+1 if SIZE=N then STOP – you are the leader!!!!!!!!!!Else If MASTER <> id //if B<>A send WINNER(id) on EDGE_TO(A) PENDING=PENDING-1 If PENDING > 0 then ..
The algorithm When node ID receive WINNER(id) :if ID=id then if STATE='active' then SIZE=SIZE+1 if SIZE=N then stop! If STATE='active' then \\no fight has been lost send TEST(SIZE,ID) on edge SIZE else if MASTER <>id then MASTER=id send WINNER(id) on EDGE_TO(id) PENDING=PENDING-1 if PENDING > 0 then send a message from PENDING_SET on edge EDGE_TO(MASTER)
The algorithm When node ID receive TEST(size,id) on edge e: if e < SIZE then//message comes from our domain if (size,id) > (SIZE,ID) then //lexicographic STATE='stopped' send WINNER(id) on edge e else send WINNER(ID) on edge eelse //message from outsize the domain EDGE_TO(id) = e PENDING = PENDING +1 if PENDING =1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,id) in PENDING_SET
Example A: B: WINNER(A) D: WINNER(D) C: E: WINNER(C) F F G H I J
A<B<C<D<... A: B: WINNER(A) D: WINNER(D) C: E: WINNER(C) F F G H I J
A if ID=id then if STATE='active' then SIZE=SIZE+1 if SIZE=N then stop! If STATE='active' then \\no fight has been lost send TEST(SIZE,ID) on edge SIZE A: B: WINNER(A) D: WINNER(D) C: E: WINNER(C) F F G H I J
A if ID=id then if STATE='active' then SIZE=SIZE+1if SIZE=N then stop! If STATE='active' then \\no fight has been lost send TEST(SIZE,ID) on edge SIZE A: B: WINNER(A) D: WINNER(D) C: E: WINNER(C) F F G H I J
A TEST(1,A) if ID=id then if STATE='active' then SIZE=SIZE+1 if SIZE=N then stop!If STATE='active' then \\no fight has been lost send TEST(SIZE,ID) on edge SIZE A: B: WINNER(A) D: WINNER(D) C: E: WINNER(C) F F G H I J
C if ID=id then if STATE='active' then SIZE=SIZE+1 if SIZE=N then stop!If STATE='active' then \\no fight has been lost send TEST(SIZE,ID) on edge SIZE A: B: WINNER(A) D: WINNER(D) TEST(1,C) C: E: WINNER(C) F F G H I J
B-process A's message If e < SIZE //message comes from our Else //message from outsize the domain EDGE_TO(id) = e PENDING = PENDING +1 If PENDING =1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,id) in PENDING_SET TEST(1,A) A: B: WINNER(A) D: WINNER(D) C: E: WINNER(C) F F G H I J
B-process C's message(1,C) If e < SIZE //message comes from our Else //message from outsize the domain EDGE_TO(id) = e PENDING = PENDING +1 If PENDING =1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,id) in PENDING_SET A: B: WINNER(A) D: WINNER(D) C: E: WINNER(C) F F G H I J
B-process B's message (test(1,A)) If e < SIZE //message comes from our Else //message from outsize the domain EDGE_TO(id) = e PENDING = PENDING +1 If PENDING =1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,id) in PENDING_SET A: B: WINNER(A) D: WINNER(D) C: E: WINNER(C) F F G H I J
B-process B's message (test(1,A)) If e < SIZE //message comes from our If (size,id) > (SIZE,ID) then //lexicographicSTATE='stopped' Send WINNER(id) on edge e Else Send WINNER(ID) on edge e A: B: WINNER(A) D: WINNER(A) WINNER(D) C: E: WINNER(C) F F G H I J
B-process B's message WINNER(A) • if ID=id then • ELSE if MASTER <>id then MASTER=id send WINNER(id) on EDGE_TO(id) PENDING=PENDING-1 • if PENDING > 0 then send a message from PENDING_SET on edge EDGE_TO(MASTER) WINNER(A) A: B: WINNER(A) D: TEST(1,C) WINNER(D) C: E: WINNER(C) F F G H I J
A-process B's message WINNER(A) • if ID=id then • if STATE='active' then SIZE=SIZE+1 if SIZE=N then stop! If STATE='active' then \\no fight has been lost send TEST(SIZE,ID) on edge SIZE A: B: D: TEST(2,A) C: E: F F G H I J
A-process B's message TEST(1,C) If e < SIZE //message comes from our domain If (size,id) > (SIZE,ID) then //lexicographic STATE='stopped' Send WINNER(id) on edge e Else Send WINNER(ID) on edge e A: B: D: WINNER(A) C: E: F F G H I J
B-process A's message WINNER(A) • if ID=id then • else if MASTER <>id then MASTER=id send WINNER(id) on EDGE_TO(id) PENDING=PENDING-1 • if PENDING > 0 then send a message from PENDING_SET on edge EDGE_TO(MASTER) A: B: D: C: E: F F G H I J
C-process A's message TEST(2,A) If e < SIZEElse //message from outsize the domain EDGE_TO(id) = e PENDING = PENDING +1 If PENDING =1 then send TEST(size,id) on EDGE_TO(MASTER) Else put TEST(size,id) in PENDING_SET A: B: D: C: E: F F G TEST(2,A) H I J
C-process C's message TEST(2,A) If e < SIZE //message comes from our domain If (size,id) > (SIZE,ID) then //lexicographic STATE='stopped' Send WINNER(id) on edge e Else Send WINNER(ID) on edge e A: B: D: C: E: F F G WINNER(A) H I J
C-process C's message WINNER(A) if ID=id then else if MASTER <>id then MASTER=id send WINNER(id) on EDGE_TO(id) PENDING=PENDING-1 if PENDING > 0 then send a message from PENDING_SET on edge EDGE_TO(MASTER) A: B: D: WINNER(A) C: E: F F G H I J
A-process C's message WINNER(A) • if ID=id then if STATE='active' then SIZE=SIZE+1 if SIZE=N then stop! If STATE='active' then \\no fight has been lost send TEST(SIZE,ID) on edge SIZE A: B: D: TEST(3,A) C: E: F F G H I J
D-process awake WINNER(D) • if ID=id then if STATE='active' then SIZE=SIZE+1 if SIZE=N then stop! If STATE='active' then \\no fight has been lost send TEST(SIZE,ID) on edge SIZE A: B: D: TEST(1,D) C: E: F F G H I J
D-process A message TEST(3,A) If e < SIZEElse //message from outsize the domain EDGE_TO(id) = e PENDING = PENDING +1 If PENDING =1 then send TEST(size,id) on EDGE_TO(MASTER) else put TEST(size,id) in PENDING_SET A: B: D: TEST(3,A) C: E: F F G H I J
D-process D message TEST(3,A) If e < SIZE //message comes from our domain If (size,id) > (SIZE,ID) then //lexicographic STATE='stopped' Send WINNER(id) on edge e Else Send WINNER(ID) on edge e A: B: D: WINNER(A) C: E: F F G H I J
D-process D message WINNER(A) if ID=id then else if MASTER <>id then MASTER=id send WINNER(id) on EDGE_TO(id) PENDING=PENDING-1 if PENDING > 0 then send a message from PENDING_SET on edge EDGE_TO(MASTER) A: B: D: WINNER(A) C: E: F F G H I J
A-process D message WINNER(A) • if ID=id then if STATE='active' then SIZE=SIZE+1 if SIZE=N then stop! If STATE='active' then \\no fight has been lost send TEST(SIZE,ID) on edge SIZE A: B: D: TEST(4,A) C: E: F F G H I J