Professional Documents
Culture Documents
DISTRIBUTED COMPUTING
18CS3109
1
Session Outcome: Student will be able to describe the Leader Election
Problem.
Active Learning
Teaching– Learning Methods
Time(min) Topic BTL
Method
Introduction to Leader
15 1 Lecturing
Election Problem
5 Queries discussion Discussion
Understand the Leader Lecturing/ Discussion on
20 2
election Problem Problem Assignment
5 Quiz Quiz
© 2019 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED 2
1. LEADER ELECTION IN RINGS
Introduction:
The topology of the Message Passing system is a ring. Rings are a convenient
structure for Message Passing systems and corresponding to physical
communication systems, for example, token rings.
Group of processors much choose one among them to be the leader – Leader
Election problem.
2. ELECTION ALGORITHMS
1. Bully Algorithm
2. Ring Algorithm
3. MUTUAL EXCLUSION IN SHARED
MEMORY
1. Formal Model for Shared Memory Systems
i) Systems
ii) Complexity Measures
iii) Pseudo code Conventions
2. The Mutual Exclusion Problem
3. Mutual Exclusion using Powerful Primitives
i) Binary Test & Set Registers
ii) Read-Modify-Write Registers
4. CLASSICAL ALGORITHMS
18CS3109
1
Session Outcome: Student will be able to describe the Leader Election
Problem.
Active Learning
Methods
Time(min) Topic BTL Teaching– Learning Method
© 2019 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED 2
LEADER ELECTION IN RINGS
Analysis of 𝑶(𝒏𝟐) Algorithm
2
LEADER ELECTION IN RINGS
Analysis of 𝑶(𝒏𝟐) Algorithm
➢Clearly algorithm never sends more than 𝑂(𝑛 2) messages in any
admissible execution.
➢Message Complexity:
❖ Each message belongs to a particular phase and is
initiated by a particular processor.
❖ Probe distance in phase i is 2𝑖 .
❖ Number of messages initiated by a processor in phase i is
at most 4·2𝑖 (probes and replies in both directions).
LEADER ELECTION IN RINGS
How many processors initiate probes in phase k ?
➢For k = 0, every proc. does
➢For k > 0, every proc. that is a "winner" in phase k-1
does
• "winner" means has largest id in its 2k-1 neighborhood
LEADER ELECTION IN RINGS
➢Maximum number of phase k-1 winners occurs when
they are packed as densely as possible:
≤ 4n + n + 4•2k•n/(2k-1+1)
phase 0 msgs
termination
msgs < 8n(log n + 2) + 5n
msgs for
phases 1 to
= O(n log n) log(n–1)+1
ELECTION ALGORITHMS
Bully Algorithm
➢The bully algorithm is a method for dynamically electing a
coordinator or leader from a group of processes.
Complexity:
➢2n messages always.
ELECTION ALGORITHMS
•SESSION 14
DISTRIBUTED COMPUTING
18CS3109
1
Session Number: 14 Type B
Session Outcome: Student will be able to summarize Mutual Exclusion
Teaching– Active Learning
Time(min) Topic BTL Learning Methods
Method
05 Poll/Recap Discussion/ Quiz
Introduction to
15 Mutual Exclusion 1 Lecturing
in Shared Memory
Clarifying doubts
05 Discussion
through public chat
➢No two process can be in the same CS at the same time. This is
called mutual exclusion.
MUTUAL EXCLUSION IN SHARED
MEMORY
Assume the program of a processor is partitioned into the
following lines:
❖Entry(trying): The code executed in preparation for entering
the critical section.
Entry
Remainder Critical
Exit
MUTUAL EXCLUSION IN SHARED
MEMORY
➢Each processor cycles through these sections in the order:
❖ Remainder
❖ Entry
❖ Critical
❖ Exit
➢If a processor wants to enter the critical section it first executes
the entry section
➢After that, the processor enters the critical section
➢Then the processor releases the critical section by executing the
exit section and returning to the remainder section.
MUTUAL EXCLUSION IN SHARED
MEMORY
➢A mutual exclusion algorithm consists of code for entry and
exit sections and should work no matter what goes in the
critical and remainder sections.
➢We assume that the variables, both shared and local, accessed in
the entry and exit sections are not accessed in the critical and
remainder section.
MUTUAL EXCLUSION IN SHARED
MEMORY
An algorithm for a shared memory system solves the mutual
exclusion problem with no deadlock (or no lockout) if the following
hold:
<Entry>:
1: wait until test&set(V)=0
<Critical Section>
<Exit>:
2: reset(V):
<Remainder>
MUTUAL EXCLUSION IN SHARED
MEMORY
No Deadlock:
➢Claim: V = 0 if no processor is in CS.
➢Proof is by induction on events in execution,and relies on fact that
mutual exclusion holds.
➢Suppose there is a time after which a processor p is in its entry section
but no processor ever enters CS.
No Lockout
➢One processor could always grab V (i.e., win the test&set competition)
and starve the others.
➢No Lockout does not hold.
➢Thus Bounded Waiting does not hold.
MUTUAL EXCLUSION IN SHARED
MEMORY
ii) Read-Modify-Write Registers
➢The state of this kind of variable can be anything and of any
size.
➢n-Bounded Waiting:
❖ FIFO order of enqueue, and fact that no processor stays in CS
forever, give this result.
MUTUAL EXCLUSION IN SHARED
MEMORY
Space Complexity
➢The shared RMW variable V has two components in its state,
first and last.
DISTRIBUTED COMPUTING
18CS3109
1
Session Number: 15 Type A
Session Outcome: Student will able to understand the concept of token based algorithms
© 2019 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED 2
CLASSICAL ALGORITHMS
1. Token Based Algorithm
i) Central Solution
➢ Elect a central master (or leader)
• Use one of our election algorithms!
➢ Master keeps
• A queue of waiting requests from processes who wish to access the CS
• A special token which allows its holder to access CS
➢ Actions of any process in group:
• enter()
• Send a request to master
• Wait for token from master
• exit()
• Send back token to master
CLASSICAL ALGORITHMS
➢Master Actions:
• On receiving a request from process Pi
if (master has token)
Send token to Pi
else
Add Pi to queue
• On receiving a token from process Pi
if (queue is not empty)
Dequeue head of queue (say Pj), send that process the token
else
Retain token
CLASSICAL ALGORITHMS
➢Safety – at most one process in CS
• Exactly one token
DISTRIBUTED COMPUTING
18CS3109
1
Session Number: 16 Type B
Session Outcome: Student will be able to summarize about Ring based Mutual Exclusion
Teaching– Active
Time(min) Topic BTL Learning Learning
Method Methods
05 Poll/Recap Lecturing/Quiz
Introduction to
15 Ring based 1 Lecturing
Algorithm
Queries
05 Discussion
explanation
Ring Based Analytical
20 Mutual 3 Lecturing Problem as
Exclusion Assignment
Summary of the
5 1 Lecturing
session
© 2019 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED 2
CLASSICAL ALGORITHMS
ii) Ring Based Mutual Exclusion
N6
N32
N80 N5
Token:
CLASSICAL ALGORITHMS
Cannot access CS anymore
N12 N3
Here’s the token!
N6
N32
N80 N5
Token:
CLASSICAL ALGORITHMS
N12 N3
N80 N5
Token:
CLASSICAL ALGORITHMS
➢N Processes organized in a virtual ring
➢Each process can send message to its successor in ring
➢Exactly 1 token
➢enter()
• Wait until you get token
➢exit() // already have token
• Pass on token to ring successor
➢If receive token, and not currently in enter(), just pass on
token to ring successor
CLASSICAL ALGORITHMS
➢Safety
• Exactly one token
➢Liveness
• Token eventually loops around ring and reaches requesting process (no
failures)
➢Bandwidth
• Per enter(), 1 message by requesting process but up to N messages
throughout system
• 1 message sent per exit()
CLASSICAL ALGORITHMS
➢Client delay: 0 to N message transmissions after entering enter()
• Best case: already have token
• Worst case: just sent token to neighbor
➢Synchronization delay between one process’ exit() from the CS and the next
process’ enter():
• Between 1 and (N-1) message transmissions.
• Best case: process in enter() is successor of process in exit()
• Worst case: process in enter() is predecessor of process in exit()