Top Banner
1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” - H. Jackson Brown
45

1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

1

Friday, November 17, 2006

“In the confrontation between the stream and the rock,

the stream always wins, not through strength but by perseverance.”

- H. Jackson Brown

Page 2: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

2

Bubble Sort

Sequential bubble sort algorithm.

Page 3: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

3

2 5 8 1 4 6

2 5 8 1 4 6

Bubble Sort

Page 4: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

4

2 5 8 1 4 6

2 5 8 1 4 6

2 5 8 1 4 6

Bubble Sort

Page 5: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

5

2 5 8 1 4 6

2 5 8 1 4 6

2 5 8 1 4 6

2 5 8 1 4 6

Bubble Sort

Page 6: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

6

2 5 8 1 4 6

2 5 8 1 4 6

2 5 8 1 4 6

2 5 8 1 4 6

2 5 1 8 4 6

Bubble Sort

Page 7: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

7

2 5 8 1 4 6

2 5 8 1 4 6

2 5 8 1 4 6

2 5 8 1 4 6

2 5 1 8 4 6

2 5 1 4 8 6

Bubble Sort

Page 8: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

8

2 5 8 1 4 6

2 5 8 1 4 6

2 5 8 1 4 6

2 5 8 1 4 6

2 5 1 8 4 6

2 5 1 4 8 6

2 5 1 4 6 8

Complexity?

Bubble Sort

Page 9: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

9

2 5 8 1 4 6

2 5 8 1 4 6

2 5 8 1 4 6

2 5 8 1 4 6

2 5 1 8 4 6

2 5 1 4 8 6

2 5 1 4 6 8

O(n2)

Inherently sequential

Bubble Sort

Page 10: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

10

Odd-Even Transposition

Sorting n = 8 elements, using the odd-even transposition sort algorithm.

Page 11: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

11

Odd-Even Transposition

Sequential odd-even transposition sort algorithm.

Complexity?

Page 12: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

12

8 7 6 5 4 3 2 1

7 8 5 6 3 4 1 2

7 5 8 3 6 1 4 2

5 7 3 8 1 6 2 4

5 3 7 1 8 2 6 4

3 5 1 7 2 8 4 6

3 1 5 2 7 4 8 6

1 3 2 5 4 7 6 8

1 2 3 4 5 6 7 8

Odd

Even

Odd

Even

Odd

Even

Odd

Even

Odd

Page 13: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

13

Odd-Even

After n phases of odd-even exchanges, the sequence is sorted.

Each phase of the algorithm (either odd or even) requires Θ(n) comparisons.

Serial complexity is Θ(n2).

Page 14: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

14

Parallel Odd-Even Transposition

Consider the one item per processor case.

Assume processes are arranged in one-dimensional array.

There are n iterations, in each iteration, each processor does one compare-exchange.

The parallel run time is ?

Page 15: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

15

Parallel Odd-Even Transposition

Consider the one item per processor case.

There are n iterations, in each iteration, each processor does one compare-exchange.

The parallel run time of this formulation is Θ(n).

Cost optimal?

Page 16: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

16

Parallel Odd-Even Transposition Consider a block of n/p elements per

processor.

The first step is a local sort.

In each subsequent step, the compare exchange operation is replaced by the compare-split operation.

How many odd-even phases will be executed?

Page 17: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

17

Compare Split Operation

A compare-split operation. Each process sends its block of size n/p to the other process. Each process merges the received block with its own block and retains only the appropriate half of the merged

block.

Page 18: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

18

Parallel Odd-Even Transposition The first step is a local sort.

There are p phases.

The parallel run time of the formulation is

Page 19: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

19

Odd Even Sorting

Page 20: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

20

Odd Even Sorting

Page 21: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

21

Odd Even Sorting

Page 22: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

22

Odd Even Sorting

Page 23: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

23

2 3 4 5 6 7 8 1

2 3 4 5 6 7 1 8

2 3 4 5 6 1 7 8

2 3 4 5 1 6 7 8

2 3 4 1 5 6 7 8

2 3 1 4 5 6 7 8

2 1 3 4 5 6 7 8

1 2 3 4 5 6 7 8

Odd

Even

Odd

Even

Odd

Even

Odd

Even

Page 24: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

24

Shellsort

Let n be the number of elements to be sorted and p be the number of processes.

During the first phase, processes that are far away from each other in the array compare-split their elements.

During the second phase, the algorithm switches to an odd-even transposition sort.

Page 25: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

25

0 3 4 5 6 7 2 1

0 2 4 5 6 7 3 1

0 2 4 5 1 3 7 6

0 2 4 5 1 3 6 7

An example of the first phase of parallel shellsort on an eight-process array.

Parallel

Shellsort

Page 26: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

26

0 2 4 5 1 3 6 7

0 2 4 5 1 3 6 7

0 2 4 1 5 3 6 7

0 2 1 4 3 5 6 7

0 1 2 3 4 5 6 7

Odd

Even

Odd

Even

Odd

Page 27: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

27

Parallel Shellsort Each process performs d = log p compare-split

operations.

With O(p) bisection width, each communication can be performed in time Θ(n/p) for a total time of Θ((nlog p)/p).

In the second phase, l odd and even phases are performed, each requiring time Θ(n/p).

The parallel run time of the algorithm is:

Page 28: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

28

Quicksort

Quicksort selects one of the entries in the sequence to be the pivot and divides the sequence into two - one with all elements less than the pivot and other greater.

The process is recursively applied to each of the sublists.

Page 29: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

29

Page 30: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

30

Quicksort

The performance of quicksort depends critically on the quality of the pivot.

Page 31: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

31

Quicksort

Parallel formulation of quick sort.

Do we start with a single process?

Page 32: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

32

Parallel Quicksort

Consider a list of size n equally divided across p processors.

A pivot is selected by one of the processors and made known to all processors.

Each processor partitions its list into two, say Li and Ui, based on the selected pivot.

Page 33: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

33

Parallel Quicksort

All of the Li lists are merged and all of the Ui lists are merged separately.

The set of processors is partitioned into two (in proportion of the size of lists L and U).

The process is recursively applied to each of the lists.

The recursion stops when a particular sub-block is assigned to a single process. At which point, the lists are sorted locally using serial quick sort.

Page 34: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

34

Page 35: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

35

Page 36: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

36

Page 37: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

37

Page 38: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

38

Pivot selection

Page 39: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

39

OpenMP and MPI

Suitable for multiprocessors?Suitable for multi-computers?

Page 40: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

40

Combining MPI and OpenMP

Many commercial multi-computers are collections of centralized multiprocessors.

Page 41: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

41

Combining MPI and OpenMP

Hybrid parallel program

Page 42: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

42

Combining MPI and OpenMP

Suppose we are executing on a cluster of m multiprocessors, where each multiprocessor has k CPUs

In order to utilize every CPU, MPI program has o create mk processes During communication mk processes are active

Hybrid needs ?

Page 43: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

43

Combining MPI and OpenMP

Suppose we are executing on a cluster of m multiprocessors, where each multiprocessor has k CPUs

In order to utilize every CPU, MPI program has o create mk processes

During communication mk processes are active

Hybrid needs m processes and workload is divided among k threads on each multiprocessor.

Page 44: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

44

Combining MPI and OpenMP

Suppose we are executing on a cluster of m multiprocessors, where each multiprocessor has k CPUs

In order to utilize every CPU, MPI program has o create mk processes

During communication mk processes are activeHybrid needs m processes and workload is divided

among k threads on each multiprocessor. Lower communication overhead

Page 45: 1 Friday, November 17, 2006 “In the confrontation between the stream and the rock, the stream always wins, not through strength but by perseverance.” -H.

45

Combining MPI and OpenMP

Suppose a serial program executes in 100 seconds.

5 seconds in inherently sequential operations.

90 seconds are perfectly parallelizable.Remaining 5 percent can be done in parallel

but has a large communication overhead so we replicate these operations.