0% found this document useful (0 votes)
208 views

Parallel Sorting Algorithms

This presentation covers parallel sorting algorithms such as Odd-Even Transposition sort, Rank sort and Bitonic sort.

Uploaded by

Shyam536
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
208 views

Parallel Sorting Algorithms

This presentation covers parallel sorting algorithms such as Odd-Even Transposition sort, Rank sort and Bitonic sort.

Uploaded by

Shyam536
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 22

PARALLEL SORTING ALGORITHMS ON MULTI-CORE PROCESSOR

Contents
2

Introduction Parallelism Types of parallelism Sorting techniques Example (Analysis) Conclusion References

Why do we need sorting ?


3

Sorting makes it possible to search a particular data element in a collection quickly by applying the binary search technique. Sorting is the most important operations for many commercial applications, especially database management systems.

Sequential sorting algorithms


4

Bubble sort Insertion sort Selection sort Merge sort

O(n2)

Heap sort
Quick sort

O(nlog(n))

Parallelism
5

Parallelism is a concept of computing task simultaneously at a time. Types of parallelism


Instruction level parallelism Data level parallelism Task level parallelism

Instruction level parallelism


6

Instruction-level parallelism (ILP) is a measure of how many of the operations in a computer program can be performed simultaneously. The potential overlap among instructions is called instruction level parallelism Consider the following program: 1. e = a + b 2. f = c + d

3. m = e * f

int a=2,b=3,c=4,d=7

e=a+b

f=c+d

m=e*f

Data level parallelism:


7

It focuses on distributing the data across different parallel computing nodes. The program below expressed in pseudo code. lower_limit := 1 upper_limit := round(d.length/2)

if CPU = "a

else if CPU = "b" lower_limit := round(d.length/2) + 1 upper_limit := d.length for i from lower_limit to upper_limit by 1 foo(d[i])

Task level parallelism:


8

Task level parallelism focuses on distributing execution processes (threads) across different parallel computing nodes. In a multiprocessor system, task parallelism is achieved when each processor executes a different thread (or process) on the same or different data The pseudo code below illustrates task parallelism: if CPU="a" then

do task "A
else if CPU="b" then do task "B end if...

end program

Parallel sorting algorithm


9

Odd Even transposition sort Rank sort Bitonic sort

Odd-Even transposition sort


10

Odd even transposition algorithm is a parallel sorting which is a development of the sequential bubble sort algorithm. It is designed for linear array computer networks. The algorithm performs n/2 iterations each of which has 2 phases phase1: odd-even exchange phase2: even-odd exchange

Odd-Even Transposition Sort example(p=n)


11

P1

P2

P3

P4 P8

P5

P6

P7

time complexity:

Tpar = (n)

(for P=n)

Odd Even sort algorithm


12

for j=1...[ N/2] do sequentially begin for i=1,3,..,2[ N/2]-1 do in_parallel if xi > xi+1 then swap(xi,xi+1); for i=2,4,..,2[ (N-1)/2] do in_parallel if xi > xi+1 then swap(xi,xi+1); end

Parallel Rank sort


13

Number of elements that are smaller than each selected element is counted. This count provides the position of the selected number, its rank in the sorted list. First a[0] is read and compared with each of the other numbers, a[1] a[n-1], recording the number of elements less than a[0]. The number a[0] is copied into the final sorted list b[0] b[n-1], at location b[rank]. Actions repeated with the other numbers.

Overall sequential time complexity of rank sort: Tseq = O(n2)

Parallel rank sort example (p=n)


14

Unsorted list

p1
Rank= 2

p2
Rank= 0

p3
Rank= 1

p4
Rank= 3

p5
Rank= 4

Sorted list

5 7

Parallel Rank Sort


15

(P=n)

One number is assigned to each processor . Pi finds the final index of a[i] in O(n) steps.

forall (i = 0; i < n; i++) { rank = 0; for (j = 0; j < n; j++) b[rank] = a[i]; }

/* for each no. in parallel*/ /* count number less than it */ /* copy no. into correct place */

if (a[i] > a[j]) rank++;

Parallel time complexity, O(n), as good as any sorting algorithm so far. time complexity: Tpar = O(n)
(for P=n)

Bitonic sorting
16

A bitonic sequence is composed of two subsequences, one is increasing and the other decreasing.

example:
2 5 7 12 increasing 32 26 14 9 decreasing

Bitonic sort example


17

Step 1:

12

32

26

14

Step 2: Step 3: Sorted :

2 2 2

5 5 5

7 7 7

9 9 9

32 14 12

26 12 14

14 32 26

12 26 32

Unsorted list -> bitonic sequence -> sorted list Step 1: Step 2: Step 3: Step 4: Step 5: 19 16 16 15 15 16 19 15 16 16 15 42 42 19 9 42 15 19 42 8 31 9 18 31 31 9 31 31 18 18 8 18 9 9 19 18 8 8 8 42

Step 6:

9 8

8 9

15 15

16 16

19 18

18 19

31 31

42 42

18

Bitonic sort example


19

9
4 1 3 7 5 2 8

4
9 3 1

a
b

3
1 4 9

1
3 4 9

1
3 4 2

1
2 4 3

1
2 3 4

5 7 8
2

8
c d 7 5 2

8
7 5 2

8
7 5 9

5
7 8 9

5
7 8 9

Number of steps (P=n)


20

The solution of this recurrence equation is T(n) = log(n) + log(n)-1 + log(n)-2 + ... + 1 = log(n) (log(n)+1) / 2 =[(log2 n)+(log(n)]/2 time complexity = O(log2 n)

Conclusion
21

By using the parallelism time complexity for sorting has been reduced from O(n 2) to O(log2n).

From the above three methods described bitonic sort method is more appropriate because time complexity of bitonic sort is less compare to other two methods.
Parallelism is not used in most of the sorting problems because it requires high processing speeds and high power consumption.

References
22

Analysis of Fast Parallel Sorting Algorithms for GPU Architectures by fiaz.khan ,omar.khan,bartolomeo.montrucchio.

Minimizing Communication in the Bitonic Sort by Jae-Dong Lee and Kenneth E. Batcher.
fast parallel sorting algorithms on gpus byBilal Jan, Bartolomeo Montrucchio, Carlo Ragusa, Fiaz Gul Khan and Omar Khan

You might also like