sorting algos in parallel system
TRANSCRIPT
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 1/23
Sorting Algorithms in
Parallel Systems
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 2/23
Parallel Systems
Parallel Processing is information processing that
emphasizes the concurrent manipulation of data
elements belonging to one or more processes
solving a single problem.
A parallel computer is a multiple processor
computer capable of parallel processing.
It increases speed of execution.
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 3/23
Odd-Even (Transposition) Sort
� Its a variant of bubble sort.
� The algo performs N/2 iterations
� It has 2 phases :
E
ven-odd exchange
Odd even exchange
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 4/23
Odd-Even Algo
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 5/23
Odd-Even
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 6/23
Odd-Even Transposition
�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).
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 7/23
Parallel Odd-Even Transposition
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 8/23
9
Parallel odd even transposition
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 9/23
9
Parallel odd even transposition
P0 P1 P2 P3
13 7 12 8 5 4 6 1 3 9 2 10
Local sort
7 12 13 4 5 8 1 3 6 2 9 10
O-E
4 5 7 8 12 13 1 2 3 6 9 10
E-O
4 5 7 1 2 3 8 12 13 6 9 10
O-E
1 2 3 4 5 7 6 8 9 10 12 13
E-O
SORTED: 1 2 3 4 5 6 7 8 9 10 12 13
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 10/23
Properties
� The parallel run time of the formulation is
�The efficiency is :
E=1 / [1 o( ( log p ) / ( log n ) ) + o(p / log n ) ]
� The parallel formulation is cost-optimal for p =
O(log n).
� The isoefficiency function of this parallel
formulation is ( p2 p).
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 11/23
Quick Sort
Quick sort is one of the most common sortingalgorithms because of its simplicity, low overhead, and
optimal average complexity.
Quick sort 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 sub
lists.
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 12/23
Quick Sort
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 13/23
Quick Sort
Example of quick sort algorithm sorting asequence of size n = 8.
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 14/23
ParallelizingQuick Sort
�Executing a quick sort can be visualized by constructing a binary tree.
�We select a pivot. Partition the array into 2 parts:
a) Left ( Smaller ) .
b) Right ( Larger).
�The formulation does not rearrange the elements .
�All the processes can read the pivot in const time .Henceknow which sub-array( smaller or larger) is assigned to it and
proceed to next iteration.
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 15/23
ParallelizingQuick Sort
� A binary tree generated by theexecution of the quick sortalgorithm.
� Each level of the treerepresents a different array-partitioning iteration.
� If pivot selection is optimal,then the height of the tree is(log n), which is also thenumber of iterations.
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 16/23
ParallelizingQuick Sort
� Consider a list of size n equally divided across pprocessors.
� A pivot is selected by one of the processors and made
known to all processors.
� Each processor partitions its list into two sub array, say
Liand U
i, based on the selected pivot.
� All of the Li lists are merged and all of the U i lists aremerged separately.
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 17/23
ParallelizingQuick Sort
� The set of processors is partitioned into two(in proportion of the size of lists L and U ). Theprocess is recursively applied to each of thelists.
� The recursion ends when a particular sub-block of element is assigned to a singleprocess.
� The processor than sorts than sorts theelements using a serial quick sort algo.
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 18/23
Parallelizing Quick Sort
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 19/23
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 20/23
Parallelizing Quick Sort
Therefore, the total parallel time is:
The corresponding isoefficiency is ( plog2 p) due to broadcast and
scan operations.
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 21/23
8/6/2019 Sorting Algos in parallel system
http://slidepdf.com/reader/full/sorting-algos-in-parallel-system 22/23
Conclusion
� In every real time systems we need to have
sorting.
� Sorted data is always easy to manipulate
than random data.