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 P 1 send A to P 2 P 2 compares B with A and sends to P 1 the min(A,B)
Method 2 P 1 sends A to P 2 P 2 sends B to P 1 P 1 does A = min(A, B) P 2 does B = max(A, B)
Data partitioning – n numbers and p processors – n/p numbers assigned to each processor Method 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. a 1 a i+1 > a i+2 >... > a n – 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 network Unsorted sequence bitonic sequence sorted sequence
Example
What’s next? Parallel computational geometry Parallel numerical algorithms …