Choose a Leader Example: find extrema in unidirectional ring - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Choose a Leader Example: find extrema in unidirectional ring

Description:

1. Choose a Leader Example: find extrema in unidirectional ring ... dinky initialisation, give process I smallest number */ atomic { proc = 1; do :: proc = N ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 7
Provided by: Muf7
Category:

less

Transcript and Presenter's Notes

Title: Choose a Leader Example: find extrema in unidirectional ring


1
Choose a Leader Example find extrema in
unidirectional ring
  • There are N processes configured into a
    unidirectional ring i.e. For 1ltiltn, process i
    can communicate with process i1 and process N
    can communicate with process 1.
  • Each process has an identification number. The
    problem is to find the largest such number.

2
Algorithm Idea
  • For each process there is a max, a just read
    number, and a neighbourR.
  • Alg
  • Set max to your own number.
  • Send numbers around once. Tag numbers with tag1
  • First time around, set neighbourR to the number
    just read (i.e. process i-1) and then send that
    number around for second round, with tag2.
  • Second time around, if neighbourR is bigger than
    just read number and bigger than max, set max to
    neighbourR and output neighbourR with tag1.
    Otherwise become inactive. If you are inactive,
    just pass along numbers.
  • You know you are the winner if you receive your
    own maximum.

3
/
Dolev, Klawe Rodeh An O(n log n)
unidirectional distributed algorithm for extrema
finding in a circle,' J. of Algs, Vol 3.
(1982), pp. 245-260 / define N 5 / nr of
processes (assume 5) /define I 3 / node given
the smallest number /define L 10 / size of
buffer (gt 2N) / mtype one, two, winner
chan qN L of mtype, byte byte
nr_leaders 0 proctype node (chan in, out
byte mynumber)bit Active 1, know_winner 0
byte nr, maximum mynumber, neighbourR 
printf("MSC d\n", mynumber)
out!one(mynumber) do in?one(nr)
-gt if Active -gt if nr
! maximum -gt out!two(nr) neighbourR
nr else -gt / maximum is greatest
number / know_winner 1

out!winner,nr
fi else -gt
out!one(nr) fi    
4
in?two(nr) -gt
if Active -gt if neighbourR
gt nr neighbourR gt maximum -gt
maximum neighbourR
out!one(neighbourR) else -gt Active
0 fi else -gt out!two(nr)
/just pass on number / fi   
in?winner,nr -gt if nr ! mynumber
-gt printf("MSC LOST\n") else
-gt printf("MSC LEADER\n")
nr_leaders fi if !
know_winner -gt out!winner,nr
else skip fi breakod
5
byte proc/ dinky
initialisation, give process I smallest number
/ atomic proc 1 do
proc lt N -gt run node (qproc-1,
qprocN, (NI-proc)N1) proc
proc gt N -gt breakod  
6
Assertions
  • in?one(nr) -gt if Active
    -gt if nr ! maximum -gt out!two(nr) neig
    hbourR nr else -gt / maximum is
    greatest number / know_winner 1
    assert (nrN)

  • fi
  •   in?winner,nr -gt if nr !
    mynumber -gt printf("MSC LOST\n")
    else -gt printf("MSC LEADER\n")
    nr_leaders assert
    (nr_leaders 1)
  • fi if ! know_winner -gt
    out!winner,nr else skip
    fi breakod
Write a Comment
User Comments (0)
About PowerShow.com