Upload
margery-west
View
222
Download
0
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
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)
Compare and swap with message exchange
• Sequential version requires comparing and swapping values
• Parallel version requires an extra communication step
Method 1
• P1 send A to P2
• P2 compares B with A and sends to P1 the min(A,B)
Method 2
• P1 sends A to P2
• P2 sends B to P1
• P1 does A = min(A, B)
• P2 does B = max(A, B)
Data partitioning
– n numbers and p processors– n/p numbers assigned to each processorMethod 1
Data partitioning
• Method 2
Algorithms
• Bubblesort• Mergesort• Quicksort• Bitonic sort
Sequential bubblesort
Parallel bubblesort
• Run multiple iterations in parallel
Parallel mergesort
• Divide and conquer technique
Parallel quicksort
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.
Bitonic sorting networkUnsorted sequence bitonic sequence sorted sequencehttps://www.youtube.com/watch?v=GEQ8y26blEY
Example
What’s next?
• Parallel computational geometry• Parallel numerical algorithms• …