parallel and distributed algorithms

206
Parallel and Distributed Algorithms

Upload: sol

Post on 23-Mar-2016

126 views

Category:

Documents


5 download

DESCRIPTION

Parallel and Distributed Algorithms. Overview. Parallel Algorithm vs Distributed Algorithm PRAM Maximal Independent Set Sorting using PRAM Choice coordination problem Real world applications. Introduction. CPUs with 1000 processors. A massively parallel processing machine. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Parallel and Distributed Algorithms

Parallel and Distributed Algorithms

Page 2: Parallel and Distributed Algorithms

Overview

Parallel Algorithm vs Distributed Algorithm

PRAM Maximal Independent Set Sorting using PRAMChoice coordination problemReal world applications

Page 3: Parallel and Distributed Algorithms

INTRODUCTION

Page 4: Parallel and Distributed Algorithms

Need of distributed processingA massively parallel processing machineCPUs with 1000 processorsMoore’s law coming to an end

Page 5: Parallel and Distributed Algorithms

Parallel AlgorithmA parallel algorithm is an algorithm which

can be executed a piece at a time on many different processing devices, and then combined together again at the end to get the correct result.*

* Blelloch, Guy E.; Maggs, Bruce M. Parallel Algorithms. USA: School of Computer Science, Carnegie Mellon University.

Page 6: Parallel and Distributed Algorithms

Distributed AlgorithmA distributed algorithm is an algorithm

designed to run on computer hardware constructed from interconnected processors.*

*Lynch, Nancy (1996). Distributed Algorithms. San Francisco, CA: Morgan Kaufmann Publishers. ISBN 978-1-55860-348-6.

Page 7: Parallel and Distributed Algorithms

PRAM

Page 8: Parallel and Distributed Algorithms

Random Access Machine

An abstract machine with unbounded number of local memory cells and with simple set of instruction sets

Time complexity: number of instructions executed

Space complexity: number of memory cells used

All operations take Unit time

Page 9: Parallel and Distributed Algorithms

PRAM (Parallel Random Access Machine)PRAM is a parallel version of RAM for designing the

algorithms applicable to parallel computers

Why PRAM ? The number of processor execute per one cycle on P processors is

at most P Any processor can read/write any shared memory cell in unit time It abstracts from overhead which makes the complexity of PRAM

algorithm easier It is a benchmark

Page 10: Parallel and Distributed Algorithms

Read A[i-1], Computation A[i]=A[i-1]+1, Write A[i]

Shared Memory (A)

P1

P2

Pn

A[0]A[1]=A[0]+1

A[2]=A[1]+1

A[n]=A[n-1]+1

A[1]

A[1]

A[2]

A[n-1]

A[n]

Page 11: Parallel and Distributed Algorithms

Share Memory Access ConflictsExclusive Read(ER) : all processors can

simultaneously read from distinct memory locations

Exclusive Write(EW) : all processors can simultaneously write to distinct memory locations

Concurrent Read(CR) : all processors can simultaneously read from any memory location

Concurrent Write(CW) : all processors can write to any memory location

EREW, CREW, CRCW

Page 12: Parallel and Distributed Algorithms

Complexity

Parallel time complexity: The number of synchronous steps in the algorithm

Space complexity: The number of share memory cell

Parallelism: The number of processors used

Page 13: Parallel and Distributed Algorithms

MAXIMAL INDEPENDENT SET

Lahiru SamarakoonSumanaruban Rajadurai

Page 14: Parallel and Distributed Algorithms

14

Independent Set (IS):Any set of nodes that are not adjacent

Page 15: Parallel and Distributed Algorithms

15

Maximal Independent Set (MIS):An independent set that is nosubset of any other independent set

Page 16: Parallel and Distributed Algorithms

16

Maximal vs. Maximum IS

a maximum independent seta maximal independent set

Page 17: Parallel and Distributed Algorithms

17

A Sequential Greedy algorithm

Suppose that will hold the final MISIInitially I

G

Page 18: Parallel and Distributed Algorithms

18

Pick a node and add it to I1v

1v

Phase 1:

1GG

Page 19: Parallel and Distributed Algorithms

19

Remove and neighbors )( 1vN1v

1G

Page 20: Parallel and Distributed Algorithms

20

Remove and neighbors )( 1vN1v

2G

Page 21: Parallel and Distributed Algorithms

21

Pick a node and add it to I2v

2v

Phase 2:

2G

Page 22: Parallel and Distributed Algorithms

22

2v

Remove and neighbors )( 2vN2v

2G

Page 23: Parallel and Distributed Algorithms

23

Remove and neighbors )( 2vN2v

3G

Page 24: Parallel and Distributed Algorithms

24

Repeat until all nodes are removedPhases 3,4,5,…:

3G

Page 25: Parallel and Distributed Algorithms

25

Repeat until all nodes are removed

No remaining nodes

Phases 3,4,5,…,x:

1xG

Page 26: Parallel and Distributed Algorithms

26

At the end, set will be an MIS of I G

G

Page 27: Parallel and Distributed Algorithms

27

Running time of algorithm: )(nO

Worst case graph:

n nodes

Page 28: Parallel and Distributed Algorithms

Intuition for parallelization

28

At each phase we may select any independent set (instead of a single node), remove S and neighbors of S from the graph.

Page 29: Parallel and Distributed Algorithms

29

Suppose that will hold the final MISIInitially I

Example:

G

Page 30: Parallel and Distributed Algorithms

30

Find any independent set S

Phase 1:

And insert to :I SII

1GG

S

Page 31: Parallel and Distributed Algorithms

31

remove and neighbors )(SN

2G

S

Page 32: Parallel and Distributed Algorithms

32

Phase 2:

Find any independent setAnd insert to :I SII

On new graph

2G

S

S

Page 33: Parallel and Distributed Algorithms

33

2G

remove and neighbors )(SNS

Page 34: Parallel and Distributed Algorithms

34

remove and neighbors )(SN

3G

S

Page 35: Parallel and Distributed Algorithms

35

Phase 3:

Find any independent setAnd insert to :I SII

On new graph

3G

S

S

Page 36: Parallel and Distributed Algorithms

36

3G

remove and neighbors )(SNS

Page 37: Parallel and Distributed Algorithms

37

No nodes are left

4G

remove and neighbors )(SNS

Page 38: Parallel and Distributed Algorithms

38

Final MIS I

G

Page 39: Parallel and Distributed Algorithms

39

The number of phases depends on the choice of independent set in each phase

The larger the independent set at eachphase the faster the algorithm

Observation:

Page 40: Parallel and Distributed Algorithms

40

1 2 )(vd

Let be the degree of node)(vd v

v

Randomized Maximal Independent Set ( MIS )

Page 41: Parallel and Distributed Algorithms

41

Each node elects itselfwith probability

At each phase :k

kI

)(21)(vd

vp

kGv

1 2 )(vd

v

degree ofin

Elected nodes are candidates for theindependent set

vkG

Page 42: Parallel and Distributed Algorithms

42

)(vd

v

z

)(zd

If two neighbors are elected simultaneously,then the higher degree node wins

Example:

)(vd

v

z

)(zd

1 21

2

1 21

2)()( vdzd

if

Page 43: Parallel and Distributed Algorithms

43

)(vd

v

z

)(zd

If both have the same degree, ties are broken arbitrarily

Example:

)(vd

v

z

)(zd

1 21

2

1 21

2)()( vdzd

if

Page 44: Parallel and Distributed Algorithms

44

Problematic nodeskG

Using previous rules, problematic nodesare removed

Page 45: Parallel and Distributed Algorithms

45

kG

The remaining elected nodes formindependent set S

Page 46: Parallel and Distributed Algorithms

46

mark lower-degree vertices with higher probability

Luby’s algorithm

Page 47: Parallel and Distributed Algorithms

47

Problematic nodeskG

Using previous rules, problematic nodesare removed

Page 48: Parallel and Distributed Algorithms

48

if both end-points of an edge is marked, unmark the one with the lower degree

Luby’s algorithm

Page 49: Parallel and Distributed Algorithms

49

kG

The remaining elected nodes formindependent set S

Page 50: Parallel and Distributed Algorithms

50

remove marked vertices with their neighbors and corresponding edges

add all marked vertices to MIS

Luby’s algorithm

Page 51: Parallel and Distributed Algorithms

ANALYSIS

Page 52: Parallel and Distributed Algorithms

6

2

Goodness property

G3

4

43

4 44

• A vertex v is good at least ⅓ of its neighbors have lesser degree than it. bad otherwise.

• An edge is bad if its both endpoints are bad. good otherwise.

Page 53: Parallel and Distributed Algorithms

Lemma 1Let v Є V be a good vertex with degree d(v) >

0.Then, the probability that some vertex w in N( v) gets marked is at least 1 - exp( -1 / 6).

Define L(v) is set of neighbors of v whose degree is lesser than v’s degree.

By definition, |L(v)|≥d(v)/3 if v is a GOOD vertex.

Page 54: Parallel and Distributed Algorithms
Page 55: Parallel and Distributed Algorithms

Lemma 2 During any iteration, if a vertex w is marked then it

is selected to be in S with probability at least 1/2.

Page 56: Parallel and Distributed Algorithms
Page 57: Parallel and Distributed Algorithms
Page 58: Parallel and Distributed Algorithms

• From lemma1 and 2 => The probability that a good vertex belongs to S U N(S) is at least (1 - exp(-1/6))/2.

• Good vertices get eliminated with a constant probability.

• It follows that the expected number of edges eliminated during an iteration is a constant fraction of the current set of edges.

• This implies that the expected number of iterations of the Parallel MIS algorithm is O(log n).

Page 59: Parallel and Distributed Algorithms

Lemma 3In a graph G(V,E), the number of good edges is at

least |E|/2.ProofDirect the edges in E from the lower degree

endpoint to the higher degree end-point, breaking ties arbitrarily.

for each bad vertex v

For all S, T С V, define the subset of the (oriented) edges E(S, T) as those edges that are directed from vertices in S to vertices in T

Page 60: Parallel and Distributed Algorithms

Let VG and VB be the set of good and bad vertices

Page 61: Parallel and Distributed Algorithms

SORTING ON PRAM

Jessica Makucka Puneet Dewan

Page 62: Parallel and Distributed Algorithms

SortingCurrent problem: sort n numbers

Best average case for sorting is O(nlog n)

Can we do better with more processors?

YES!

Page 63: Parallel and Distributed Algorithms

Notes about QuicksortSort n numbers on a PRAM with n

processorsAssume all numbers are distinctCREW PRAM for this caseEach of the n processors contains an

input element

Notation:Let Pi denote ith processor

Page 64: Parallel and Distributed Algorithms

Quicksort Algorithm0. If n=1 stop1. Pick a splitter at random from n elements2. Each processor determines whether its element is

bigger or smaller than the splitter3. Let j denote splitters rank:

• If j [n/4, 3n/4] means failure, go back to (1)• If j [n/4, 3n/4] means success and move splitter to Pj Every

element smaller than j is moved to distinct processor Pi for i < j and the larger elements are moved to distinct processor Pk for k > j

4. Sort elements recursively in processors P1 through Pj-

1, and the elements in processors Pj+1 through Pn

Page 65: Parallel and Distributed Algorithms

Quicksort Time AnalysisAlgorithm

1. Pick a successful splitter at random from n elements (assumption)

2. Each processor determines whether its element is bigger or smaller than the splitter

Time Analysis of each stage

1. O(logn) stages for every sequence or recursive split

2. Trivial – can be implemented in single CREW PRAM step

Page 66: Parallel and Distributed Algorithms

Quicksort Time Analysis3. Let j denote splitters

rank:• If j [n/4, 3n/4] go back

to 1.• If j [n/4, 3n/4] move

splitter to Pj Every element smaller than j is moved to distinct processor Pi for i < j and the larger elements are moved to distinct processor Pk for k > j

O(log n) PRAM steps needed for the single splitting stage

Page 67: Parallel and Distributed Algorithms

Comparison Splitting Stage (3)

P1 P2 P3 P4 P5 P6 P7 P8

12 3 7 5 11 2 1 14splitter

0 1 1 1 11 0

Assign bit depending on if Pi’s element is smaller or bigger than the splitter - 0 if element is bigger - 1 otherwise

Page 68: Parallel and Distributed Algorithms

Comparison Splitting Stage (3)

P1 P2 P3 P4 P5

12 3 7 5 11splitter

1 1 10

1 2

3

Step 1:

Step 2:

+ +

+

Page 69: Parallel and Distributed Algorithms

Overall Time AnalysisThis algorithm would terminate in O(log2

n) stepsEach step is O(log n) for splitting stageO(log n) steps

Derived from this solved equation:

Page 70: Parallel and Distributed Algorithms

Cons

In this algorithm, There is an assumption that split will always be successful and it will break the problem from N to a constant fraction of N.No Suitable method for successful

split.

Page 71: Parallel and Distributed Algorithms

Improvement

IdeaReduce the problem into size of n1-e where e<1 while keeping the time to split the same.

Page 72: Parallel and Distributed Algorithms

Benefitsif e=1/2

The total time for the entire problem size will be: log n + log n1/2+log n1/4+… resulting in O(log n)

Then we could hope for an overall running time of O(log n).

Page 73: Parallel and Distributed Algorithms

Long Story

Suppose that we have n processors and n elements.Suppose that processors P1 through Pr, contain r of the elements in sorted order, and that processors Pr+1 through Pn contain the remaining n - r elements.

1.Choose Random Splitters and sort them.Let the sorted elements in the first r processors the splitters. For 1 < =j <= r, let sj denote the jth largest splitter.

2. Insert Insert the n - r unsorted elements among the splitters.

3.Sort remaining elements among splitters a. Each processor should end up with a distinct input element. b. Let i(sj) denote the index of the processor containing sj following the insertion operation. Then, for all k < i(sj), processor Pk contains an element that is smaller than sj similarly, for all k > i(sj), processor Pk contains an element that is larger than sj.

Page 74: Parallel and Distributed Algorithms

Example

Choose Random Splitter5 9 8 10 7 6 12 11

Page 75: Parallel and Distributed Algorithms

Example (Contd.)Sort the random splitters.

Sorted List Unsorted List

6 11 5 9 8 7 10 12

Page 76: Parallel and Distributed Algorithms

Example(Contd.)Insert the unsorted elements among the

splitters

5 6 7 9 8 10 11 12

Page 77: Parallel and Distributed Algorithms

Example(Contd.)

Check the number of elements between the splitters has size less than or equal to (Log n ) or not.

Suppose S represents size

S=4 (exceeds log n i.e 3) S=1 S=1

56798101112

5 6 7 9 8 10 11 12

Page 78: Parallel and Distributed Algorithms

Example Contd.Recur on the sub problem whose size exceeds log n. Again choose random splitters and follow the same process

Random Splitters

5 6 7 9 8 10 11 12

Page 79: Parallel and Distributed Algorithms

Partitioning as tree

Tree formed from first partition.Now the size on the right exceeds log n, so we again split by

choosing random partitions. E.g 9,8

6

5 7

98

10

Size on right

exceeds log n

Page 80: Parallel and Distributed Algorithms

Contd.

Sorted because of partition

6

5 8

97

10

Page 81: Parallel and Distributed Algorithms

Lemma’s to be Used

1. A CREW PRAM having (n2) processors. Suppose that each of the processors P1 through Pn has an input element to be sorted.

Then the PRAM can sort these n elements in O(log n).2. For n processors, and n elements of which n1/2 are splitters , then the insertion process can be completed in O(log n) steps.

Page 82: Parallel and Distributed Algorithms

Box Sort

Algorithm :Input: A set of numbers S .Output: The elements of S sorted in increasing order. 1 . Select n1/2 (e is 1/2)elements at random from the n input elements. Using all n processors, sort them in O(log n) steps.(Fact 1) 2. Using the sorted elements from Stage 1 as splitters, insert the remaining elements among them in O(log n) steps(Fact 2) 3. Treating the elements that are inserted between adjacent splitters as subproblems , recur on each sub-problem whose size exceeds log n. For subproblems of size log n or less, invoke LogSort.

Page 83: Parallel and Distributed Algorithms

Sort Fact

A CREW PRAM with m processors can sort m elements in O(m) steps.

Page 84: Parallel and Distributed Algorithms

Example

Each Processor is assigned an element and compares its element with remaining elements simultaneously in O(m) steps.

Rank assigned implies elements are sorted.

4 7 6 5 8 2 3 15 9 8 7 10 3 4 2

P1 P2 P3 P4 P5 P6 P7 P8

Ranks Assigned

Page 85: Parallel and Distributed Algorithms

Things to remember Last statement of Box Sort algorithm. Idea on the previous slide.

Page 86: Parallel and Distributed Algorithms

Log SortWe will be having log n processors with

log n elements then we can sort in O(log n).

Page 87: Parallel and Distributed Algorithms

AnalysisConsider each node of the tree as a box.Choosing random splitters and sort them take time of

O(log n).Insert the unsorted elements among the splitters takes

O(log n).With high probability (assumption) the sub problems

resulting from splitting operation are very small(i.e the unsorted elements among the splitters).

So each leaf is a box of size at most log n.For calculating the time spent, we can use the Log Sort

which sorts the elements in O(log n)Total time is O(log n)

Page 88: Parallel and Distributed Algorithms

DISTRIBUTED RANDOMIZED ALGORITHM

Yogesh S RawatR. Ramanathan

Page 89: Parallel and Distributed Algorithms

CHOICE COORDINATION PROBLEM (CCP)

Page 90: Parallel and Distributed Algorithms

Biological Inspiration

mite (genus Myrmoyssus)

Page 91: Parallel and Distributed Algorithms

Biological Inspiration

mite (genus Myrmoyssus)

reside as parasites on the ear membrane

of the moths of family Phaenidae

Page 92: Parallel and Distributed Algorithms

Biological Inspiration

mite (genus Myrmoyssus)

reside as parasites on the ear membrane

of the moths of family Phaenidae

Moths are prey to bats and the only defense they have is that they can hear the sonar used by an approaching bat

Page 93: Parallel and Distributed Algorithms

Biological Inspiration

if both ears of the moth are infected by the mites, then their ability to detect the sonar is considerably diminished, thereby

severely decreasing the survival chances of both the moth and its colony of mites.

Page 94: Parallel and Distributed Algorithms

Biological Inspiration

The mites are therefore faced with a "choice coordination problem"

How does any collection of mites infecting a particular ear ensure that every other mite chooses the same ear?

Page 95: Parallel and Distributed Algorithms

Problem Specification

Set of N processors

Page 96: Parallel and Distributed Algorithms

Problem Specification

Set of N processors

M options to choose from

Page 97: Parallel and Distributed Algorithms

Problem Specification

Set of N processors

processors have to reach a consensus on unique choice

M options to choose from

Page 98: Parallel and Distributed Algorithms

Model for Communication

•Collection of M read-write registers accessible to all the processors

– Locking mechanism for conflicts•Each processor follow a protocol for making a

choice– A special symbol (√) is used to mark the choice

•At the end only one register contains the special symbol

Page 99: Parallel and Distributed Algorithms

Deterministic Solution

•Complexity is measured in terms of number of read and write operations

•For a deterministic solution– Complexity in terms of operations : Ω(n1/3)

• n - Number of processors

For more details - M. O. Rabin, “The choice coordination problem,” Acta Informatica, vol. 17, no. 2, pp. 121–134, Jun. 1982.

Page 100: Parallel and Distributed Algorithms

Randomized Solution

for any c > 0It will solve the problem using c operations

with a probability of success atleast 1-2-Ω(c)

For simplicity we will consider only the case where

n = m = 2

although the protocol can be easily generalized

Page 101: Parallel and Distributed Algorithms

Analogy from Real Life

? ?

Random Action - Give way or Move ahead

Page 102: Parallel and Distributed Algorithms

Analogy from Real Life

? ?

Random Action - Give way or Move ahead

Give way Give wayMove Ahead Move AheadMove Ahead Give way

Give way Move Ahead

Person 1 Person 2

Page 103: Parallel and Distributed Algorithms

Analogy from Real Life

? ?

Random Action - Give way or Move ahead

Give way Give wayMove Ahead Move AheadMove Ahead Give way

Give way Move Ahead

Breaking Symmetry

Person 1 Person 2

Page 104: Parallel and Distributed Algorithms

Synchronous CCP The two processors are synchronous Operate in lock-step according to some global clock

Used terminology Pi – processor i, where i ϵ {0,1} Ci – shared register for choices, where i ϵ {0,1} Bi – local variable for each processor, where i ϵ {0,1}

P0P1

B0B1

C0

C1

Page 105: Parallel and Distributed Algorithms

Synchronous CCP

P0P1

B0B1C0

C1

The processor Pi initially scans the register Ci Thereafter, the processors exchange registers after every

iteration At no time will the two processors scan the same register.

Page 106: Parallel and Distributed Algorithms

Synchronous CCP

P0P1

B0B1C0

C1

The processor Pi initially scans the register Ci Thereafter, the processors exchange registers after every

iteration At no time will the two processors scan the same register.

Page 107: Parallel and Distributed Algorithms

Synchronous CCP

P0P1

B0B1C1

C0

The processor Pi initially scans the register Ci

Thereafter, the processors exchange registers after every iteration

At no time will the two processors scan the same register.

Page 108: Parallel and Distributed Algorithms

AlgorithmInput: Registers C0 and C1initialized to 0Output: Exactly one of the two registers has the value √

Step 0 - Pi is initially scanning the register Ci

Step 1 - Read the current register and obtain a bit Ri

Step 2 - Select one of three cases

case: 2.1 [Ri = √]» halt

case: 2.2 [Ri = 0, Bi = 1 )» Write √ into the current register and halt

case: 2.3 [otherwise]» Assign an unbiased random bit to Bi

» write Bi into the current register

Step 3 - Pi exchanges its current register with P1 - i and returns to Step 1 .

Page 109: Parallel and Distributed Algorithms

AlgorithmInput: Registers C0 and C1initialized to 0Output: Exactly one of the two registers has the value √

Step 0 - Pi is initially scanning the register Ci

Step 1 - Read the current register and obtain a bit Ri

Step 2 - Select one of three cases

case: 2.1 [Ri = √]» halt

case: 2.2 [Ri = 0, Bi = 1 ]» Write √ into the current register and halt

case: 2.3 [otherwise]» Assign an unbiased random bit to Bi

» write Bi into the current register

Step 3 - Pi exchanges its current register with P1 - i and returns to Step 1 .

Read Operation

Page 110: Parallel and Distributed Algorithms

AlgorithmInput: Registers C0 and C1initialized to 0Output: Exactly one of the two registers has the value √

Step 0 - Pi is initially scanning the register Ci

Step 1 - Read the current register and obtain a bit Ri

Step 2 - Select one of three cases

case: 2.1 [Ri = √]» halt

case: 2.2 [Ri = 0, Bi = 1 )» Write √ into the current register and halt

case: 2.3 [otherwise]» Assign an unbiased random bit to Bi

» write Bi into the current register

Step 3 - Pi exchanges its current register with P1 - i and returns to Step 1 .

Choice has already been made by the other processor

Page 111: Parallel and Distributed Algorithms

Input: Registers C0 and C1initialized to 0Output: Exactly one of the two registers has the value √

Step 0 - Pi is initially scanning the register Ci

Step 1 - Read the current register and obtain a bit Ri

Step 2 - Select one of three cases

case: 2.1 [Ri = √]» halt

case: 2.2 [Ri = 0, Bi = 1 )» Write √ into the current register and halt

case: 2.3 [otherwise]» Assign an unbiased random bit to Bi

» write Bi into the current register

Step 3 - Pi exchanges its current register with P1 - i and returns to Step 1 .

Algorithm

Only condition for making a choice

Page 112: Parallel and Distributed Algorithms

Input: Registers C0 and C1initialized to 0Output: Exactly one of the two registers has the value √

Step 0 - Pi is initially scanning the register Ci

Step 1 - Read the current register and obtain a bit Ri

Step 2 - Select one of three cases

case: 2.1 [Ri = √]» halt

case: 2.2 [Ri = 0, Bi = 1 )» Write √ into the current register and halt

case: 2.3 [otherwise]» Assign an unbiased random bit to Bi

» write Bi into the current register

Step 3 - Pi exchanges its current register with P1 - i and returns to Step 1 .

Algorithm

Generate a random valueWrite operation

Page 113: Parallel and Distributed Algorithms

Input: Registers C0 and C1initialized to 0Output: Exactly one of the two registers has the value √

Step 0 - Pi is initially scanning the register Ci

Step 1 - Read the current register and obtain a bit Ri

Step 2 - Select one of three cases

case: 2.1 [Ri = √]» halt

case: 2.2 [Ri = 0, Bi = 1 )» Write √ into the current register and halt

case: 2.3 [otherwise]» Assign an unbiased random bit to Bi

» write Bi into the current register

Step 3 - Pi exchanges its current register with P1 - i and returns to Step 1 .

Algorithm

Exchange Registers

Page 114: Parallel and Distributed Algorithms

Correctness of Algorithm

We need to prove only one of the shared register has √ marked in it

Suppose that both are marked with √–This must have had in same iteration–Otherwise step 2.1 will halt the algorithm

Page 115: Parallel and Distributed Algorithms

Correctness of AlgorithmLet us assume that the error takes place during the tth

iterationAfter step 1 values for processor Pi

Bi(t) and Ri(t)By case 2.3

R0(t) = B1(t) R1(t) = B0(t)

Suppose Pi writes √ in the tth iteration, then Ri = 0 and Bi = 1 and R1-i = 1 and B1-i = 0 P1-i cannot write √ in ith iteration Breaking Symmetry

Page 116: Parallel and Distributed Algorithms

R0 B00 0

Read Operation

R1 B10 0

C0 C10 0

Processor 0 Shared Registers Processor 1

Page 117: Parallel and Distributed Algorithms

R0 B00 0

0 0

Write Operation

R1 B10 0

0 0

C0 C10 0

0 0

Processor 0 Shared Registers Processor 1

Random Random

Page 118: Parallel and Distributed Algorithms

R0 B00 0

0 0

0 0

Read Operation

R1 B10 0

0 0

0 0

C0 C10 0

0 0

0 0

Processor 0 Shared Registers Processor 1

Page 119: Parallel and Distributed Algorithms

R0 B00 0

0 0

0 0

0 1

Write Operation

R1 B10 0

0 0

0 0

0 1

C0 C10 0

0 0

0 0

1 1

Processor 0 Shared Registers Processor 1

Random Random

Page 120: Parallel and Distributed Algorithms

R0 B00 0

0 0

0 0

0 1

1 1

Read Operation

R1 B10 0

0 0

0 0

0 1

1 1

C0 C10 0

0 0

0 0

1 1

1 1

Processor 0 Shared Registers Processor 1

Page 121: Parallel and Distributed Algorithms

R0 B00 0

0 0

0 0

0 1

1 1

1 0

Write Operation

R1 B10 0

0 0

0 0

0 1

1 1

1 1

C0 C10 0

0 0

0 0

1 1

1 1

0 1

Processor 0 Shared Registers Processor 1

Random Random

Page 122: Parallel and Distributed Algorithms

R0 B00 0

0 0

0 0

0 1

1 1

1 0

1 0

Read Operation

R1 B10 0

0 0

0 0

0 1

1 1

1 1

0 1

HALT

C0 C10 0

0 0

0 0

1 1

1 1

0 1

0 1

Processor 0 Shared Registers Processor 1

Page 123: Parallel and Distributed Algorithms

R0 B00 0

0 0

0 0

0 1

1 1

1 0

1 0

1 0/1

Write Operation

R1 B10 0

0 0

0 0

0 1

1 1

1 1

0 1

HALT

C0 C10 0

0 0

0 0

1 1

1 1

0 1

0 1

√ 0/1

Processor 0 Shared Registers Processor 1

Random

Page 124: Parallel and Distributed Algorithms

R0 B00 0

0 0

0 0

0 1

1 1

1 0

1 0

1 0/1

√ 0/1

HALT

Read Operation

R1 B10 0

0 0

0 0

0 1

1 1

1 1

0 1

HALT

C0 C10 0

0 0

0 0

1 1

1 1

0 1

0 1

√ 0/1

√ 0/1

Processor 0 Shared Registers Processor 1

Page 125: Parallel and Distributed Algorithms

Complexity•Probability that both the random bits B0 and B1

are the same is 1/2•Therefore probability that number of steps

exceeds t is 1/2t.The algorithm will terminate in next two steps

as soon as B0 and B1are different.•Computation cost of each iteration is bounded

–Therefore, the protocol does O(t) work with probability 1-1/2t

Page 126: Parallel and Distributed Algorithms

The Problem

C1

C2

P2P1

Page 127: Parallel and Distributed Algorithms

C1

C2

P2P1

The Problem

Page 128: Parallel and Distributed Algorithms

C1

C2

P1 P2

The Problem

Page 129: Parallel and Distributed Algorithms

C1

C2

P1 P2

The Problem

Page 130: Parallel and Distributed Algorithms

C1

C2

P1 P2

The Problem

Page 131: Parallel and Distributed Algorithms

The processors are not synchronized

C1

C2

P1 P2

Page 132: Parallel and Distributed Algorithms

What can we do?

C1

C2

P1 P2

Page 133: Parallel and Distributed Algorithms

What can we do?

Idea: Timestamp

C1

C2

P1 P2

Page 134: Parallel and Distributed Algorithms

Read <timestamp,value>

P1 P2

B1 B2

C1

C2

T1 T2t2

t1

Timestamp of Processor: Ti

Timestamp of Register : ti

Page 135: Parallel and Distributed Algorithms

Input: Registers C1 and C2 initialized to <0,0>

Output: Exactly one of the two registers has Ö

Algorithm

Page 136: Parallel and Distributed Algorithms

0) Pi initially scans a randomly chosen register. <Ti, Bi> are initialized to <0,0>

1) Pi gets a lock on its current register and reads <ti, Ri>

2) Pi executes one of these cases:

2.1) If Ri = Ö : HALT

2.2) If Ti < ti : Ti    ti and Bi   Ri2.3) If Ti > ti : Write Ö into the current register and HALT

2.4) If Ti = ti, Ri = 0, Bi = 1 : Write Ö into the current register and HALT

2.5) Otherwise: Ti Ti + 1 and ti   ti + 1  Bi    Random (unbiased) bit

Write <ti, Bi> into the current register

3) Pi releases the lock on its current register, moves to the other register and returns to step 1.

Algorithm for a process Pi

Page 137: Parallel and Distributed Algorithms

Initial state

B2 T2B1 T1 C1 t1

0 0

C2 t2

0 0

Processor P1 Register R2Register R1 Processor P2

Page 138: Parallel and Distributed Algorithms

1) P1 chooses C1 and reads <0,0>

B2 T2B1 T1

0 0

C1 t1

0 0

C2 t2

0 0

History : P1==C1

Page 139: Parallel and Distributed Algorithms

1) P1 chooses C1 and reads <0,0>

B2 T2B1 T1

0 0

C1 t1

0 0

C2 t2

0 0

[None of the cases from 2.1 to 2.4 are met.Case 2.5 is satisfied]

History : P1==C1

Page 140: Parallel and Distributed Algorithms

B1 T1

0 0

1

C1 t1

0 0

1

2.5) T1 T1 + 1 and t1 t1 + 1

B2 T2C2 t2

0 0

History : P1==C1

Page 141: Parallel and Distributed Algorithms

2.5) P1 writes <t1, B1> into C1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

B2 T2C2 t2

0 0

History : P1==C1

Page 142: Parallel and Distributed Algorithms

3) P1 releases the lock on C1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

B2 T2C2 t2

0 0

[P1 moves to C2 and returns to step 1]

History : P1==C1

Page 143: Parallel and Distributed Algorithms

B2 T2

0 0

C2 t2

0 0

1) P2 chooses C2 and reads <0,0>

B1 T1

0 0

1 1

C1 t1

0 0

1 1

History : P1==C1 P2==C2

Page 144: Parallel and Distributed Algorithms

B2 T2

0 0

C2 t2

0 0

1) P2 chooses C2 and reads <0,0>

B1 T1

0 0

1 1

C1 t1

0 0

1 1

[None of the cases from 2.1 to 2.4 are met.Case 2.5 is satisfied]

History : P1==C1 P2==C2

Page 145: Parallel and Distributed Algorithms

B2 T2

0 0

1

C2 t2

0 0

1

2.5) T2 T2 + 1 and t2 t2 + 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

History : P1==C1 P2==C2

Page 146: Parallel and Distributed Algorithms

2.5) P2 writes <t2, B2> into C2

B2 T2

0 0

1 1

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

History : P1==C1 P2==C2

Page 147: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

3) P2 releases the lock on C2

[P2 moves to C1 and returns to step 1]

History : P1==C1 P2==C2

Page 148: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

1) P2 locks C1 and reads <1,1>

History : P1==C1 P2==C2 P2==C1

Page 149: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

1) P2 locks C1 and reads <1,1>

[None of the cases from 2.1 to 2.4 are met.Case 2.5 is satisfied]

History : P1==C1 P2==C2 P2==C1

Page 150: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

2

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

2

2.5) T2 T2 + 1 and t1 t1 + 1

History : P1==C1 P2==C2 P2==C1

Page 151: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

0 2

2.5) P2 writes <t1, B2> into C1

History : P1==C1 P2==C2 P2==C1

Page 152: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

0 2

3) P2 releases the lock on C1

[P2 moves to C2 and returns to step 1]

History : P1==C1 P2==C2 P2==C1

Page 153: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

0 2

1) P2 locks C2 and reads <1,1>

History : P1==C1 P2==C2 P2==C1 P2==C2

Page 154: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

0 2

1) P2 locks C2 and reads <1,1>

[Case 2.3: T2 > t2 is satisfied]

History : P1==C1 P2==C2 P2==C1 P2==C2

Page 155: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 T2

0 0

1 1

Ö

B1 T1

0 0

1 1

C1 t1

0 0

1 1

0 2

2.3) P2 writes Ö into C2

[P2 HALTS]

History : P1==C1 P2==C2 P2==C1 P2==C2

Page 156: Parallel and Distributed Algorithms

We’ll show another case of the algorithm

History : P1==C1 P2==C2 P2==C1 P2==C2

Page 157: Parallel and Distributed Algorithms

Let’s go back 1 iteration

History : P1==C1 P2==C2 P2==C1 P2==C2

Page 158: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

0 2

History : P1==C1 P2==C2 P2==C1

Let’s go back 1 iteration

Page 159: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

0 2

1) P1 locks C2 and reads <1,1>

History : P1==C1 P2==C2 P2==C1 P1==C2

Page 160: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 t2

0 0

1 1

B1 T1

0 0

1 1

C1 t1

0 0

1 1

0 2

1) P1 locks C2 and reads <1,1>

[None of the cases from 2.1 to 2.4 are met.Case 2.5 is satisfied]

History : P1==C1 P2==C2 P2==C1 P1==C2

Page 161: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 t2

0 0

1 1

2

B1 T1

0 0

1 1

2

C1 t1

0 0

1 1

0 2

2.5) T1 T1 + 1 and t2 t2 + 1

History : P1==C1 P2==C2 P2==C1 P1==C2

Page 162: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 t2

0 0

1 1

1 2

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

2.5) B1 Random (unbiased) bit

History : P1==C1 P2==C2 P2==C1 P1==C2

Page 163: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 t2

0 0

1 1

1 2

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

3) P1 releases the lock on C2

[P1 moves to C1 and returns to step 1]

History : P1==C1 P2==C2 P2==C1 P1==C2

Page 164: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 t2

0 0

1 1

1 2

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

1) P2 locks C2 and reads <1,2>

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2

Page 165: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

C2 t2

0 0

1 1

1 2

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

1) P2 locks C2 and reads <1,2>

[None of the cases from 2.1 to 2.4 are met.Case 2.5 is satisfied]

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2

Page 166: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

3

C2 t2

0 0

1 1

1 2

3

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

2.5) T2 T2 + 1 and t2 t2 + 1

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2

Page 167: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

1 3

C2 t2

0 0

1 1

1 2

1 3

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

2.5) P2 writes <t2, B2> into C2

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2

Page 168: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

1 3

C2 t2

0 0

1 1

1 2

1 3

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

3) P2 releases the lock on C2

[P2 moves to C1 and returns to step 1]

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2

Page 169: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

1 3

C2 t2

0 0

1 1

1 2

1 3

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

1) P1 locks C1 and reads <0,2>

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2 P1==C1

Page 170: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

1 3

C2 t2

0 0

1 1

1 2

1 3

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

1) P1 locks C1 and reads <0,2>

[Case 2.4: T1 = t1, R1 = 0, B1 = 1 is satisfied]

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2 P1==C1

Page 171: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

1 3

C2 t2

0 0

1 1

1 2

1 3

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

Ö

2.4) P1 writes Ö into C1

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2 P1==C1

Page 172: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

1 3

C2 t2

0 0

1 1

1 2

1 3

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

Ö

2.4) P1 HALTS

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2 P1==C1

Page 173: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

1 3

C2 t2

0 0

1 1

1 2

1 3

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

Ö

1) P2 locks C1 and reads Ö

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2 P1==C1 P2==C1

Page 174: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

1 3

C2 t2

0 0

1 1

1 2

1 3

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

Ö

1) P2 locks C1 and reads Ö

[Case 2.1: R1 = Ö is satisfied]

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2 P1==C1 P2==C1

Page 175: Parallel and Distributed Algorithms

B2 T2

0 0

1 1

0 2

1 3

C2 t2

0 0

1 1

1 2

1 3

B1 T1

0 0

1 1

1 2

C1 t1

0 0

1 1

0 2

Ö

2.1) P2 HALTS

History : P1==C1 P2==C2 P2==C1 P1==C2 P2==C2 P1==C1 P2==C1

Page 176: Parallel and Distributed Algorithms

Correctness

C1

C2

P1

Ö

P2

Page 177: Parallel and Distributed Algorithms

Correctness

When a processor writes Ö on a register, the other processor should NOT write Ö on the other register

Page 178: Parallel and Distributed Algorithms

Correctness

Case 2.3) Ti > ti: Write Ö into the current register and halt.

Case 2.4) Ti = ti, Ri = 0, Bi = 1: Write Ö into the current register and halt.

C1

C2

Ö

Page 179: Parallel and Distributed Algorithms

Ti * : Current timestamp of processor Pi

ti* : Current timestamp of register Ci

Whenever Pi finishes an iteration in Ci,

Ti = ti

Correctness

Page 180: Parallel and Distributed Algorithms

Ti * : Current timestamp of processor Pi

ti* : Current timestamp of register Ci

When a processor enters a register, it would have just left the other register

Correctness

Page 181: Parallel and Distributed Algorithms

2.3) Ti > ti: Write Ö into the current register and HALT

Consider P1 has just entered C1 with t1* < T1*

Page 182: Parallel and Distributed Algorithms

2.3) Ti > ti: Write Ö into the current register and HALT

C2 t2

0 0

1 1

0 2

(t2*)

B2 t2

0 0

1 1

(T2*)

B1 T1

0 0

1 1

0 2 (T1*)

C1 t1

0 0

1 1 (t1*)

Consider P1 has just entered C1 with t1* < T1*

History : P2==C2 P1==C1 P1==C2 P1==C1

Page 183: Parallel and Distributed Algorithms

2.3) Ti > ti: Write Ö into the current register and HALT

C2 t2

0 0

1 1

0 2

(t2*)

B2 t2

0 0

1 1

(T2*)

B1 T1

0 0

1 1

0 2 (T1*)

C1 t1

0 0

1 1 (t1*)

Consider P1 has just entered C1 with t1* < T1*

History : P2==C2 P1==C1 P1==C2 P1==C1

In prev iter, P1 must have left C2 with same T1*

Page 184: Parallel and Distributed Algorithms

2.3) Ti > ti: Write Ö into the current register and HALT

C2 t2

0 0

1 1

0 2

(t2*)

B2 t2

0 0

1 1

(T2*)

B1 T1

0 0

1 1

0 2 (T1*)

C1 t1

0 0

1 1 (t1*)

Consider P1 has just entered C1 with t1* < T1*

History : P2==C2 P1==C1 P1==C2 P1==C1

T1* ≤ t2

*

Page 185: Parallel and Distributed Algorithms

2.3) Ti > ti: Write Ö into the current register and HALT

C2 t2

0 0

1 1

0 2

(t2*)

B2 t2

0 0

1 1

(T2*)

B1 T1

0 0

1 1

0 2 (T1*)

C1 t1

0 0

1 1 (t1*)

Consider P1 has just entered C1 with t1* < T1*

History : P2==C2 P1==C1 P1==C2 P1==C1

T1* ≤ t2

*

Page 186: Parallel and Distributed Algorithms

2.3) Ti > ti: Write Ö into the current register and HALT

C2 t2

0 0

1 1

0 2

(t2*)

B2 t2

0 0

1 1

(T2*)

B1 T1

0 0

1 1

0 2 (T1*)

C1 t1

0 0

1 1 (t1*)

Consider P1 has just entered C1 with t1* < T1*

History : P2==C2 P1==C1 P1==C2 P1==C1

P2 must go to C2 only after C1

T1* ≤ t2

*

Page 187: Parallel and Distributed Algorithms

2.3) Ti > ti: Write Ö into the current register and HALT

C2 t2

0 0

1 1

0 2

(t2*)

B2 t2

0 0

1 1

(T2*)

B1 T1

0 0

1 1

0 2 (T1*)

C1 t1

0 0

1 1 (t1*)

Consider P1 has just entered C1 with t1* < T1*

History : P2==C2 P1==C1 P1==C2 P1==C1

T2* ≤ t1

*

T1* ≤ t2

*

Page 188: Parallel and Distributed Algorithms

2.3) Ti > ti: Write Ö into the current register and HALT

C2 t2

0 0

1 1

0 2

(t2*)

B2 t2

0 0

1 1

(T2*)

B1 T1

0 0

1 1

0 2 (T1*)

C1 t1

0 0

1 1 (t1*)

Consider P1 has just entered C1 with t1* < T1*

History : P2==C2 P1==C1 P1==C2 P1==C1

T1* ≤ t2

* T2* ≤ t1

*

Page 189: Parallel and Distributed Algorithms

2.3) Ti > ti: Write Ö into the current register and HALT

C2 t2

0 0

1 1

0 2

(t2*)

B2 t2

0 0

1 1

(T2*)

B1 T1

0 0

1 1

0 2 (T1*)

C1 t1

0 0

1 1 (t1*)

Consider P1 has just entered C1 with t1* < T1*

History : P2==C2 P1==C1 P1==C2 P1==C1

T1* ≤ t2

* T2* ≤ t1

*

Page 190: Parallel and Distributed Algorithms

2.3) Ti > ti: Write Ö into the current register and HALT

C2 t2

0 0

1 1

0 2

(t2*)

B2 t2

0 0

1 1

(T2*)

B1 T1

0 0

1 1

0 2 (T1*)

C1 t1

0 0

1 1 (t1*)

Consider P1 has just entered C1 with t1* < T1*

History : P2==C2 P1==C1 P1==C2 P1==C1

T1* ≤ t2

* T2* ≤ t1

*

Summing up : T2* ≤ t1

*< T1* ≤ t2

*

Page 191: Parallel and Distributed Algorithms

2.3) Ti > ti: Write Ö into the current register and HALT

C2 t2

0 0

1 1

0 2

(t2*)

B2 t2

0 0

1 1

(T2*)

B1 T1

0 0

1 1

0 2 (T1*)

C1 t1

0 0

1 1 (t1*)

Consider P1 has just entered C1 with t1* < T1*

History : P2==C2 P1==C1 P1==C2 P1==C1

T1* ≤ t2

* T2* ≤ t1

*

T2* < t2

* : T2 cannot write Ö

Page 192: Parallel and Distributed Algorithms

2.4) Ti = ti, Ri = 0, Bi = 1: Write Ö into register and HALT

Similarly consider P1 has entered C1 with t1* = T1*

Page 193: Parallel and Distributed Algorithms

2.4) Ti = ti, Ri = 0, Bi = 1: Write Ö into register and HALT

C2 t2

0 0

1 1

(t2*)

B2 t2

0 0

0 1

(T2*)

B1 T1

0 0

1 1(T1*)

C1 t1

0 0

0 1(t1*)

Similarly consider P1 has entered C1 with t1* = T1*

History : P1==C2 P2==C1 P1==C1

T1* ≤ t2

*

T2* ≤ t1

*

Summing up : T2* ≤ t1

*= T1* ≤ t2

*

Page 194: Parallel and Distributed Algorithms

2.4) Ti = ti, Ri = 0, Bi = 1: Write Ö into register and HALT

C2 t2

0 0

1 1

(t2*)

B2 t2

0 0

0 1

(T2*)

B1 T1

0 0

1 1(T1*)

C1 t1

0 0

0 1(t1*)

Similarly consider P1 has entered C1 with t1* = T1*

History : P1==C2 P2==C1 P1==C1

T1* ≤ t2

*

T2* ≤ t1

*

T2*≤ t2

*, R2 = 1, B2 = 0 : T2 cannot write Ö

Page 195: Parallel and Distributed Algorithms

• Cost is proportional to the largest timestamp

• Timestamp can go up only in case 2.5

• Processor’s current Bi value is set during a visit to the other register

• So, synchronous case complexity applies

Complexity

Page 196: Parallel and Distributed Algorithms

REAL WORLD APPLICATIONS

Pham Nam Khanh

Page 197: Parallel and Distributed Algorithms

Applications of parallel sorting• Sorting is fundamental algorithm in data processing:

» Parallel Database operations: Rank, Join, etc.» Search (rapid index/lookup after sort)

• Best record in sorting: 102.5 TB in 4,328 seconds using2100 nodes from Yahoo.

Page 198: Parallel and Distributed Algorithms

Applications of MISWireless and communicationScheduling problemPerfect matching => assignment problemFinance

Page 199: Parallel and Distributed Algorithms

Applications of Maximal independent set

Market graph

EAFE EM

Low latencyrequirement

Parallel MIS

Page 200: Parallel and Distributed Algorithms

Applications of Maximal independent set

Market graph

StocksCommoditiesBonds

Page 201: Parallel and Distributed Algorithms

Applications of Maximal independent set

Market graph

Page 202: Parallel and Distributed Algorithms

Applications of Maximal independent set

Market graph

ÞMIS form completely diversified portfolio, where all instruments are negatively correlated with each other => lower the risk

Page 203: Parallel and Distributed Algorithms

Applications of Choice coordination algorithm• Given n processes, each one can

choose between m options. They need to agree on unique choice. => belongs to class of distributed consensus algorithms.

• HW and SW task involving concurrency• Clock sync in wireless sensor networks• Multivehicle cooperative control 

Page 204: Parallel and Distributed Algorithms

Multivehicle cooperative control 

• Coordinate the movement of multiple vehicles in a certain way to accomplish an objective.

• Task Assignment, cooperative transport, cooperative role assignment, air traffic control, cooperative timing.

Page 205: Parallel and Distributed Algorithms

CONCLUSION

Page 206: Parallel and Distributed Algorithms

Conclusion

• PRAM model: CREW• Parallel algorithm Maximal Independent

Set with O(log n) and applications• Parallel sorting algorithm: QuickSort with

O(log2 n) BoxSort with O(log n) • Choice Coordination Problem: distributed

algorithms for synchronous and asynchronous system + applications