Distributed Algorithms

Only available on StudyMode
  • Pages : 9 (928 words )
  • Download(s) : 416
  • Published : September 9, 2011
Open Document
Text Preview
DDA
Practical-2

1)Algorithm for leader election in general synchronous ring know as Flood Max algorithm and explanation of state diagram.

//leader election in a general synchronous ring

set

UID = {[3],[13],[12],[7],[19]}

const N = #UID

range ID = 1..N

set

M = {UID}

const Diam = 4 //should be 4

range Int = 0..Diam

//links or channels hold at most a single message

set Network = {[1][2], [2][3], [2][5], [5][3], [3][4], [4][1]}

CHAN(Ch='[0][0]) =(put[Ch][m:M] -> get[Ch][m] -> CHAN).

ALLOW = (get.Network.M->ALLOW)+{get[ID][ID][M]}.

||NETWORK = (forall[ch:Network] CHAN(ch) || ALLOW)

/{forall[i:ID] {put[i]/put[i][ID]}}.

//the synchronous model proceeds in two steps

ROUND = (step1 -> step2 -> ROUND).

//the processes

PROCESS(Id=1,U=19)

= (start->init[Id][U]->step1->MSGS[U][0]),

MSGS[max:M][rounds:Int]

= (put[Id][max] -> step2 -> TRANS[max][rounds+1]),

TRANS[max:M][rounds:Int]

= (get[ID][Id][m:M]

-> if (m>max) then

(display[Id][m]->TRANS[m][rounds])

else

(display[Id][max]->TRANS[max][rounds])

|step1 -> if (rounds==Diam) then LEADER[max] else MSGS[max][rounds]

),

LEADER[max:M]

= if (max == U) then

(leader[Id] -> STOP)

else

(notleader[Id] -> STOP).

||SYS = (forall[i:ID] PROCESS(i,@(UID,i-1)) || NETWORK)>>{step1,step2}.

property

ONELEADER

ELECTED[i:1..N]= (leader[i] -> ELECTED[i]).

= (leader[i:ID] -> ELECTED[i]),

menu RUN = {step1,step2}

animation NETWORK = "xml/network.xml"

actions{

init[i][u:UID]/display[i][u],

leader[i]/leader[i],

notleader[i]/notleader[i],

display[i][m:M]/display[i][m],

put[i][UID]/chan[i][ID].begin

}

controls {

start/init,

step1/round,

step2/{chan.Network.end}

}

Explanation:

The algorithm requires the processes know diameter of ring. The algorithm just floods the max UID throughout the network. so we call it flood max algorithm. Every process maintains a record of maximum UID it has seen so far (initially its own).At each round, each process propagates this maximum on all of its outgoing edges. After diameter rounds, if the value seen is the process own UID process selects itself a leader. Otherwise it is a non leader.

Complexity analysis: It is easy to see that the time until the leader is elected and all other processes know that they are not leader is diameter rounds. The number of messages is diam.E. where E is the number of directed edges in the graph bcoz message is sent on every directed edge for each of the first diameter round.

State Diagram:

[pic]

In this diagram node 1 sends uid 3 to node 2 and node 2 receives the uid and compares it with its own uid.

[pic]

In this diagram node 2 sends uid 13 to node 3 and node 3 receives it. And it will compare to its own uid.

2) Algorithm for leader election in synchronous ring know as flood opt algorithm and state diagram .

[pic]

In this diagram node 2 sends uid 13 to node 5 and node 5 receives it and compares it with it own uid and sends max of it.

[pic]

In this diagram node 5 sends uid 19 to node 3 and it receives it and compares it with its own uid.

[pic]
In this diagram node 3 sends uid 19 to node 4 and it receives it and compares it with its own uidand send max of it. [pic]

In this diagram node 4 sends uid 19 to node 1 and node 1 receives it and compares with its own and send max of it.

2)Algorithm for leader election in synchronous ring using floodmax opt algorithm .

FLOODMAX_OPT

//leader election in a general synchronous ring

const True = 1

const False = 0

range Bool = False..True

set

UID = {[3],[13],[12],[7],[19]}

const N = #UID

range ID = 1..N

set

M = {UID}

const Diam = 4 //should be 4

range Int = 0..Diam

//links or channels hold at most a single message

set Network = {[1][2], [2][3], [2][5], [5][3], [3][4], [4][1]}

CHAN(Ch='[0][0]) =(put[Ch][m:M] -> get[Ch][m] ->...
tracking img