lecture #14 distributed algorithms (ii) cs492 special topics in computer science: distributed...

15
Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

Upload: gertrude-richard

Post on 17-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

Lecture #14Distributed Algorithms (II)

CS492 Special Topics in Computer Science:Distributed Algorithms and Systems

Page 2: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

2

Admin Stuff

• Cloud computing article• Lynch’s book chapters

Page 3: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

3

Topics to Cover

• Synchronous Network Model (Ch. 2-4)– Leader election in a synchronous ring– Breadth-first search– Shortest paths– Min spanning tree– Maximal independent set

• Asynchronous System Model (Ch. 8-9)– Asynchronous shared memory model

Page 4: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

Leader Election in a Synchronous Ring

• Electing a unique leader– In a ring, exactly one process should output the

decision that it is the leader.

Page 5: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

5

LCR algorithm (informal)

• Le Lann, Chang, and Roberts• Each process sends its identifier around the ring.

When a process receives an incoming identifier, it compares that identifier to its own. If the incoming identifier is greater than its own, it keeps passing the identifier; if it is less than its own, it discards the in-coming identifier; if it is equal to its own, the process declares itself the leader.

Page 6: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

6

LCR algorithm (formal)

• For each i, statesi consist of:u: initially i‘s UIDsend: a UID or null, initially i‘s UID status: with values in {unknown, leader}, initially un-

known

• For each i, msgsi defined by:send the current value of send to process i+1

Page 7: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

7

LCR algorithm (formal)

• For each i, transi defined by:u: initially i‘s UIDsend: = nullif the incoming message is v, a UID, then case v > u : send: = v v = u : status := leader v < u : do nothing endcase

Page 8: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

8

How to prove its correctness?

• Process imax outputs leader by the end of round n

• No other process ever performs such an out-put

Page 9: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

9

Lemma 3.2

• Process imax outputs leader by the end of round n

• Assertion 3.3.1 After n rounds, status(imax) = leader

• Assertion 3.3.2 For 0 <= r <= n-1, after r rounds, send(imax+r) = umax

Page 10: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

10

Lemma 3.3

• No process other than imax ever outputs the value leader.

• Assertion 3.3.3 For any r and any i, j, the fol-lowing holds. After r rounds, if i ≠ imax and j \in [imax, i) then sendj ≠ ui

Page 11: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

11

Theorem 3.4

• LCR solves the leader-election problem

Page 12: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

12

Questions

• How can other processes halt?• What is the complexity?– Time– Communication

Page 13: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

13

An algorithm w/ O(n log n) complexity

• Assumptions:– Ring size unknown– Bidirection communication

Page 14: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

14

HS Algorithm (informal)Each process i operates in phases 0,1,2,…. In each phase l, process i sends out “tokens” containing its UID ui in

both directions. These are intended to travel distance 2l, then return to their origin i.

If both tokens make it back safely, process i continues with the following phase. However, the tokens might not make it back safely. While a ui token is proceeding in the outbound direction, each other process j on ui ’s path compares ui with its own UID uj.

If ui < uj, then j simply discards the token, whereas if ui > uj, then j relays ui.

If ui = uj, then it means that process j has received its own UID before the token has turned around, so process j elects itself as the leader.

Page 15: Lecture #14 Distributed Algorithms (II) CS492 Special Topics in Computer Science: Distributed Algorithms and Systems

Non-Comparison-Based Algortihms

• Question: is it possible to elect a leader with fewer than O(n log n) messages?

• The TimeSlice algorithm– ring size n is known

• The VariableSpeeds algorithm– Each process i sends a msg at every 2v rounds.