16
Data Structures and Algorithms in Parallel Computing Lecture 8

Data Structures and Algorithms in Parallel Computing Lecture 8

Embed Size (px)

DESCRIPTION

Compare and swap with message exchange Sequential version requires comparing and swapping values Parallel version requires an extra communication step

Citation preview

Page 1: Data Structures and Algorithms in Parallel Computing Lecture 8

Data Structures and Algorithms in Parallel Computing

Lecture 8

Page 2: Data Structures and Algorithms in Parallel Computing Lecture 8

Parallel sorting• Sorting is a problem that admits a variety of parallel solutions• Goal

– Sorting a sequence of values in increasing order using n processors• Why in parallel?

– Frequent operation in many applications– Best sequential algorithm is O(n log n)– In parallel on n processors we can aim for O(log n)

Page 3: Data Structures and Algorithms in Parallel Computing Lecture 8

Compare and swap with message exchange

• Sequential version requires comparing and swapping values

• Parallel version requires an extra communication step

Page 4: Data Structures and Algorithms in Parallel Computing Lecture 8

Method 1

• P1 send A to P2

• P2 compares B with A and sends to P1 the min(A,B)

Page 5: Data Structures and Algorithms in Parallel Computing Lecture 8

Method 2

• P1 sends A to P2

• P2 sends B to P1

• P1 does A = min(A, B)

• P2 does B = max(A, B)

Page 6: Data Structures and Algorithms in Parallel Computing Lecture 8

Data partitioning

– n numbers and p processors– n/p numbers assigned to each processorMethod 1

Page 7: Data Structures and Algorithms in Parallel Computing Lecture 8

Data partitioning

• Method 2

Page 8: Data Structures and Algorithms in Parallel Computing Lecture 8

Algorithms

• Bubblesort• Mergesort• Quicksort• Bitonic sort

Page 9: Data Structures and Algorithms in Parallel Computing Lecture 8

Sequential bubblesort

Page 10: Data Structures and Algorithms in Parallel Computing Lecture 8

Parallel bubblesort

• Run multiple iterations in parallel

Page 11: Data Structures and Algorithms in Parallel Computing Lecture 8

Parallel mergesort

• Divide and conquer technique

Page 12: Data Structures and Algorithms in Parallel Computing Lecture 8

Parallel quicksort

Page 13: Data Structures and Algorithms in Parallel Computing Lecture 8

Bitonic sort

• Bitonic sequences– complexity: O(log 2n)– a sequence is bitonic if it contains two sequences, one

increasing and one decreasing, i.e.• a1 < a2 < . . . < ai−1 < ai > ai+1 > ai+2 > . . . > an

– for some i such that (0 ≤ i ≤ n)

– a sequence is bitonic if the property described is attained by a circular rotation to the right of its elements.

Page 14: Data Structures and Algorithms in Parallel Computing Lecture 8

Bitonic sorting networkUnsorted sequence bitonic sequence sorted sequencehttps://www.youtube.com/watch?v=GEQ8y26blEY

Page 15: Data Structures and Algorithms in Parallel Computing Lecture 8

Example

Page 16: Data Structures and Algorithms in Parallel Computing Lecture 8

What’s next?

• Parallel computational geometry• Parallel numerical algorithms• …