Docsity

Parallel Processing in Mesh-Based Architectures: Routing Algorithms and Sorting, Study notes of Theatre

Partial preview of the text

Download Parallel Processing in Mesh-Based Architectures: Routing Algorithms and Sorting and more Study notes Theatre in PDF only on Docsity!

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 1

Part III

Mesh-Based Architectures

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 2

About This Presentation Edition

Released

Revised

Revised

First

Spring 2005

Spring 2006

This presentation is intended to support the use of the textbook Introduction to Parallel Processing: Algorithms and Architectures (Plenum Press, 1999, ISBN 0-306-45970-1). It was prepared bythe author in connection with teaching the graduate-level courseECE 254B: Advanced Computer Architecture: Parallel Processing,at the University of California, Santa Barbara. Instructors can usethese slides in classroom teaching and for other educationalpurposes. Any other use is strictly prohibited. © Behrooz Parhami

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 4

9 Sorting on a 2D Mesh or Torus

Introduce the mesh model (processors, links, communication):• Develop 2D mesh sorting algorithms• Learn about strengths and weaknesses of 2D meshes

Topics in This Chapter 9.^

Mesh-Connected Computers

9.^

The Shearsort Algorithm

9.^

Variants of Simple Shearsort

9.^

Recursive Sorting Algorithms

9.^

A Nontrivial Lower Bound

9.^

Achieving the Lower Bound

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 5

9.1 Mesh-Connected Computers Fig. 9.

Two-dimensional mesh-connected computer.

2D, four-neighbor(NEWS) mesh; othertypes in Chapter 12Square

1/2^ p ×

1/2^ p or

rectangular

r^ ×^ p

/ r

MIMD, SPMD, SIMD,Weak SIMDSingle/All-port modelDiameter-based orbisection-basedlower bound: O(

1/2^ p )

Row wrap-around link for torus Input/output via boundary processors?

Column wraparound link for torus

Row wraparound link for torus

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 7

Torus Implementation without Long Wires

Fig. 9.

A 5

×^ 5 torus folded along its columns. Folding this diagram along the rows will produce a layout with only short links.

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 8

Processor Indexing in Mesh or Torus

0

1

2

3

4

5

6

7

8

9 10

11 12

13

14

15

a. Row-major

0

1

2

3

7

6

5

4

8

9 10

11 15

14

13

12

b. Snakelike row-major

0

1

4

5

2

3

6

7

8

9 12

13 10

11

14

15

c. Shuffled row-major

1

2

5

6

0

3

4

7

15

12

11

8

14

13

10

9

--- d. Proximity order

--- |^

|^

|^

| ---

**|

|**^

|^

|^

|

--^

--

Fig. 9.

Some linear indexingschemes for theprocessors in a2D mesh.^ Our focus willbe on row-majorand snakelikerow-majorindexing

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 10

9.2 The Shearsort Algorithm

Fig. 9.5 Descriptionof the shearsortalgorithm on an r -row 2D mesh. T shearsort

=^ ⎡log

r ⎤^ ( p 2

/ r^ +^ r ) +

p / r

thensort thecolumns(top-to-bottom)

repeat^ Sort therows(snake-like)

log r^

times endrepeatSort the rows

Snakelike

Row-Major

... ...... ...

(depending on the desired final sorted order)

or

⎤ ⎡^2 Shearsort algorihm for a 2D mesh with r rows

On a square mesh: T shearsort

1/2= p (log p^2

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 11

Proving Shearsort Correct

Fig. 9.

A pair of dirty rows create at least one clean row in each shearsort iteration

Assume thatin doing thecolumnsorts, we firstsort pairs ofelements inthe columnand then sortthe entirecolumn

0 0 0

1 1

1 1 1

0 0

0 0 0 0 0

0 1

1

1 1 1 0 0

0 0

0

0 0 1 1 1

1 1

1

1 1 1 1 1

0 0

0

0 0 0 1 1

1 1

1

1 1 1 0 0

0 0

0

0 0

0 0

0 0 0 0 1 1

1 0

0 0 1 1 0 0

1 1

1 0 0 0 1 1

1 1

1 1 1 1 0 0

0 0

0 0 0 0 1 1

1 1

1 1 1 1

Row 2iRow 2i + 1Case (a):More 0sCase (b):More 1sCase (c):Equal #0s & 1s

⇒ ⇒ ⇒

Bubbles up in thenext column sort Sinks down in thenext column sort

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 13

Shearsort Example Fig. 9.8 Example of shearsort on a 4

×^ 4 mesh.

1 12 21

4 15 20

13

2 5 9 18

7 22 3 14

17

1 4 12

21 20 15

13

2 5 7 9

18 22 17

14

3 1 4 9

2 5 7 12

3 20 15

13

18 22 17

14

21

1 2 4

9 12 7 5 3 13 15

18

20 22 21

17

14 1 2 4

3 12 7 5 9 13 15

17

14 22 21

18

20

1 2 3

4 12 9 7

5 13 14

15

17 22 21

20

18 1 2 3

4 5 7 9

12 13 14

15

17 18 20

21

22

After first row sort(snakelike)

After second row sort(snakelike)

After final row sort(snakelike)

Column sort

Column sort

(left to right)

Initial arrangementof keys in the mesh

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 14

9.3 Variants of Simple Shearsort

Observation: On a linear array, odd-even transposition sort needs only

k

steps if the “dirty” (unsorted) part of the array is of length

k

Unsorted part

Dirty^

Dirty x dirtyrows

At most x/2dirty rows

(^01)

(^01) ⇒

⎡^ ⎤

In shearsort, we do not have to sortcolumns completely, because only aportion of the column is unsorted(the portion shrinks in each phase)

On a square mesh: T opt shearsort

1/2^ p (½ log

p^ + 3) – 2 2

T opt shearsort

= ( p^ /^ r )(⎡log

r ⎤^ + 1) + 2 r^ +^ r /2 +... + 2

2 r^ – 2

Thus, 2

r^ – 2 replaces

r^ log

r^ in 2

simple shearsort

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 16

9.4 Recursive Sorting Algorithms

Fig. 9.

Graphical depiction Snakelike sorting orderon a square mesh of the first recursive algorithmfor sorting on a 2D meshbased on four-way divide andconquer.

... ...

  1. Sort quadrants
  2. Sort rows
  3. Sort columns
  4. Apply 4¦p steps of odd-eventransposition along the snake ...
  5. Sort quadrants
  6. Sort rows
  7. Sort columns
  8. Apply 4

√ p^ steps of odd-even transpositionalong the overall snake

1/2 T ( p

) =^ T

1/2^ ( p /2) + 5.

1/2 p

Note that row sort in phase 2needs fewer steps^ T recursive 1

≅^11

1/2 p

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 17

Proof of the 11

1/2 p

-Time Sorting Algorithm

Fig. 9.11The proofof the firstrecursivesortingalgorithmfor 2Dmeshes.

x^ +^ x'

≥^ b^ +

c^ +^ ⎣

( a^ –^ b

)/2⎦^ +

⎣( d^ –

c )/2⎦

+^ a'^

+^ d'^ +

⎣( b'^ –

a' )/

⎦^ +^ ⎣(

c'^ –^ d'

≥^ b^ +

c^ +^ a'

+^ d'^

  • ( a^ –

b )/2 + (

d^ –^ c

b'^ –^ a'

c'^ –^ d'

×½

= ( a^

+^ a' )/2 + (

b^ +^ b'

c^ +^ c'

d^ +^ d'

1/2 ≥ p

x^ ≥^ b

+^ c^ +

⎣( a^ –

b )/2⎦

+^ ⎣( d

-^ c )/

⎦^

A similar inequality applies to

x'

(^0) Dirty^1

x rows x' rows

0

(^00) 0

1 1

1 1 a a'

b b'

c c'

d d'

Numbers of clean rows ineach of the four quadrants

p – x – x'rows

State of the arrayafter Phase 3

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 19

Proof of the 9

1/2 p

-Time Sorting Algorithm

Fig. 9.

The proof of the second recursive sortingalgorithm for 2D meshes. 0

0

(^00) 0

1 1

1 1 a^

b

c

d

Numbers of clean 0 rowsin the four quadrants

...... a^ Numbers of 0s in two differentdouble-columns differ by Š 2

b

c^

d

......

Š 2¦p elements

(^0 )

(^0 )

(^00)

(^0 ) 0

0 0

0

0

0

1

1

≤ 1 2 √ p^ elements

Numbers of 0s in two differentdouble-columns differ by

≤^2

Numbers of clean 0 rowsin the four quadrants

Spring 2006

Parallel Processing, Mesh-Based Architectures

Slide 20

Typical complexity classes

Improving upper bounds

Shifting lower bounds log

n^

(^2) log^ n

n^ / log

n^

n^

n^ log log

n^

n^ log^ n

(^2) n

(^1988) Zak’s thm. Ω(log^ n )

(^1994) Ying’s thm.^2 Ω(log^ n )

(^1996) Dana’s alg.O( n )

(^1991) Chin’s alg.O( n log log

n )

(^1988) Bert’s alg.O( n^ log^ n

)

(^1982) Anne’s alg.^2 O( n^ )

Optimalalgorithm? Sublinear

Linear

Superlinear

Our Progress in Mesh Sorting Thus Far

Upper bounds:

Deriving/analyzing

algorithms and proving them correct

Lower bounds:

Theoretical arguments

based on bisection width, and the like

1/2^ p log

p 2 Shearsort 1/2 11 p 1/2 9 p

1/2 2 p Diameter

1/2 3 p For snakelikeorder only(proved next)

Problem9.

Schnorr/Shamiralgorithm