Download presentation
Presentation is loading. Please wait.
1
Leader in a clique in O(nlog(n)) messages By Pierre A. Humblet and the help of Miki Asa
2
Rules of the game Initialization : Initialization : Each node has {1.. N-1} edges + edge (–1) to itself. Each node has {1.. N-1} edges + edge (–1) to itself. master(id) = id, state = active. master(id) = id, state = active. Node attempt to capture other nodes (increase the size of their domain). Node attempt to capture other nodes (increase the size of their domain). A node that has been captured stop capturing and it’s state = stopped. A node that has been captured stop capturing and it’s state = stopped. Node can be captured by many other nodes but has only one master the last one that captured it. Node can be captured by many other nodes but has only one master the last one that captured it. Node that captured all the nodes leader Node that captured all the nodes leader
3
How it’s done 2 messages TEST(size,id) TEST(size,id) An attempt to capture other node. An attempt to capture other node. A TEST from a node I didn’t captured forward to my master. A TEST from a node I didn’t captured forward to my master. A TEST from a node I captured answer it with WINNER(id). A TEST from a node I captured answer it with WINNER(id). WINNER(id) WINNER(id) The result of the fight id won the fight. The result of the fight id won the fight. Determined by who got bigger domain Determined by who got bigger domain (if equal bigger id)
4
AB State = active Master = A State = active Master = B
5
AB B wins A B : TEST(size(A),id(A)) B B : TEST(size(A),id(A)) B B : WINNER(B) B wins Waiting
6
B wins A B : TEST(size(A),id(A)) B B : TEST(size(A),id(A)) B B : WINNER(B) AB State = active Master = A State = active Master = B B wins
7
AB A wins A B : TEST(size(A),id(A)) B B : TEST(size(A),id(A)) B B : WINNER(A) B A : WINNER(A) A wins
8
A B : TEST(size(A),id(A)) B B : TEST(size(A),id(A)) B B : WINNER(A) B A : WINNER(A) AB State = active Master = A State = stop Master = A A wins
9
CB A State = active Master = C State = stop Master = A State = active Master = A
10
CB A A wins C B : TEST(size(C),id(C)) B A : TEST(size(C),id(C)) A B : WINNER(A) A wins Waiting
11
CB A A wins C B : TEST(size(C),id(C)) B A : TEST(size(C),id(C)) A B : WINNER(A) State = active Master = C State = stop Master = A State = active Master = A A wins
12
CB A C wins C B : TEST(size(C),id(C)) B A : TEST(size(C),id(C)) A B : WINNER(C) B C : WINNER(C) C wins
13
CB A C B : TEST(size(C),id(C)) B A : TEST(size(C),id(C)) A B : WINNER(C) B C : WINNER(C) State = active Master = C State = stop Master = C State = stop Master = A C wins
14
Variables STATE : active – won all the fights stopped – lost a fight won’t be a leader stopped – lost a fight won’t be a leader SIZE : number of nodes I captured (send me winner (ID)) including me (size of my domain). (size of my domain). MASTER : the id of my master. EDGE(id) : the edge leading to node id Dealing with messages PENDING_SET : messages waiting to be forward to the master PENDING : number of messages in PENDING_SET Initialization Each awaken node with ID receive winner(ID) on edge > 0.
15
Receiving WINNER(id) on edge e If (id = ID) // I won the fight { if (e > 0 & state = active)// fight that I initiated { SIZE ++ if SIZE = N // I capture all the nodes stop// announce elected else send TEST(SIZE,ID) on edge SIZE //continue } else// I didn’t initiate the fight do nothing }
16
Receiving WINNER(id) (cont.) Else// id != ID { if (MASTER != id)// my master lost { MASTER = id// change the master Send WINNER(id) on EDGE(id) // inform the new master } Else // my master won { do nothing } PENDING - -// continue as a slave if PENDING > 0 send from PENDING_SET on EDGE(MASTER) }
17
Receiving TEST(size,id) on edge e If e < SIZE// message from my domain { if (size,id) > (SIZE,ID) // I lost this fight { STATE = stopped // out of the game send WINNER(id) on EDGE e // inform the new master } else // I won send WINNER(ID) on EDGE e // inform my slave that I won } Else // not from my domain { EDGE(id) = e // update my data-base PENDING ++ // send TEST to the master If PENDING = 1 send TEST(size,id) on EDGE (MASTER) else put TEST(size,id) on EDGE (MASTER) on PENDING_SET }
18
1 6 5 4 3 2 state Size Master active 1 3 active 1 2 active 1 active 1 6 active 1 5 active 1 4
19
13 state Size Master stop 1 3 6 5 4 2 active 2 3 active 1 2 active 1 6 active 1 5 active 1 4
20
1 8 4 state Size Master active 2 4 stop 1 4 13 stop 1 3 6 5 4 2 active 2 3 active 1 2 active 1 6 active 1 5 active 1 4 Waiting
21
state Size Master 13 stop 1 3 6 5 4 2 active 2 3 active 1 2 active 1 6 active 1 4 Waiting active 1 5
22
state Size Master 13 stop 1 3 6 5 4 2 active 2 3 active 1 2 active 2 6 stop 1 6 Waiting active 1 5
23
state Size Master 13 stop 1 3 6 5 4 2 active 2 3 active 1 2 active 2 6 stop 1 6 Waiting active 1 5 Waiting
24
state Size Master 13 stop 1 3 6 5 4 2 active 2 3 active 1 2 active 2 6 stop 1 6 Waiting active 1 5 Waiting
25
state Size Master 13 stop 1 6 6 5 4 2 stop 2 3 active 1 2 active 3 6 stop 1 6 Waiting active 1 5 Waiting
26
state Size Master 13 stop 1 6 6 5 4 2 stop 2 3 active 1 2 active 3 6 stop 1 6 Waiting active 1 5 Waiting
27
state Size Master 13 stop 1 6 6 5 4 2 stop 2 3 active 1 2 active 3 6 stop 1 6 Waiting stop 1 3
28
state Size Master 13 stop 1 6 6 5 4 2 stop 2 3 active 1 2 active 3 6 stop 1 6 Waiting stop 1 3
29
state Size Master 13 stop 1 6 6 5 4 2 stop 2 6 active 1 2 active 4 6 stop 1 6 Waiting stop 1 3
30
state Size Master 13 stop 1 6 6 5 4 2 stop 2 6 active 1 2 active 4 6 stop 1 6 Waiting stop 1 3 Waiting
31
state Size Master 13 stop 1 6 6 5 4 2 stop 2 6 active 1 2 active 4 6 stop 1 6 Waiting stop 1 3 Waiting
32
state Size Master 13 stop 1 6 6 5 4 2 stop 2 6 active 1 6 active 5 6 stop 1 6 Waiting stop 1 3 Waiting
33
state Size Master 13 stop 1 6 6 5 4 2 stop 2 6 active 1 6 active 5 6 stop 1 6 Waiting stop 1 3 Waiting
34
state Size Master 13 stop 1 6 6 5 4 2 stop 2 6 active 1 6 active 6 stop 1 6 Waiting stop 1 6 Waiting
35
Termination Each node can’t send more then N-1 TEST. Each node can’t send more then N-1 TEST. Each TEST cause at the most 3 more messages. Each TEST cause at the most 3 more messages.
36
Correctness Lemma 1 At the end of the algorithm there will be a node with size = N. Proof Size only grows with time. Size only grows with time. For each TEST sent For each TEST sent size++ or size++ or Node is “Waiting” Node is “Waiting” Therefore Therefore Enough to prove there is no deadlock
37
Liveness Suppose there is a deadlock Suppose there is a deadlock Lets take the node with the biggest (size,ID) it’s active. Lets take the node with the biggest (size,ID) it’s active. Eventually it will get an answer for the last test it initiated. Winner(ID). Eventually it will get an answer for the last test it initiated. Winner(ID). Once he’ll get that answer size++ Once he’ll get that answer size++ Size = N leader Size = N leader Send TEST for the next node Send TEST for the next node
38
complexity My domain: the nodes from which I received winner(ID) while I was active + myself. Lemma 1 SIZE = size of my domain. If (id = ID) // I won the fight { if (e > 0 & state = active)// fight that I initiated { SIZE ++ Got winner(ID) from other node & state = active all conditions fulfill size++ Got winner(ID) from other node & state = active all conditions fulfill size++ Size++ all conditions fulfill Got winner(ID) from other node & state = active Size++ all conditions fulfill Got winner(ID) from other node & state = active
39
Lemma 2 If SIZE(A) at time Ta = SIZE(B) at time Tb then the domains at Ta & Tb are disjoint. Proof: Assume domain(A) & domain(B) are joint at Ta or Tb They are joint at max(Ta,Tb) There is a Tm < max(Ta,Tb) s.t. At Tm a node from domain(A) join domain(B) After Tm domain(A) doesn’t grow At Tm Size(A) >= SIZE Tm > Ta After Tm domain(B) > domain(A) >= SIZE Tm > Tb Contradiction
40
Lemma 3 Rank the nodes in decreasing order by their SIZE at termination. S 1, S 2, S 3,..., S n -1, S n Then S k <= N/k Proof S 1 – S k -1 had once the size of S k there all disjoint (lemma 2) conclusion There is only one node with SIZE=N one leader
41
Number of TEST sent If (id = ID) // I won the fight { if (e > 0 & state = active)// fight that I initiated { SIZE ++ if SIZE = N // I capture all the nodes stop// announce elected else send TEST(SIZE,ID) on EDGE(SIZE) //continue } For each TEST sent SIZE++ Each TEST cause at the most 3 more messages
42
Total number of messages is no more then 4*(N/1 + N/2 + N/3 +... + N/K) = O(N log(K)) = O(N log(K)) K = the number of nodes awake.
43
Improvements The bound for the number of messages can be tightened by noticing that the first TEST received by a generates at the most one more message. The bound for the number of messages can be tightened by noticing that the first TEST received by a generates at the most one more message. The algorithm can stop as soon as SIZE = N/2 (then announce elected). The algorithm can stop as soon as SIZE = N/2 (then announce elected).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.