SlideShare a Scribd company logo
1 of 31
Parallel sorting Algorithms
By- Garima Shakya
Sorting in Parallel
● Why?
it is a frequent operation in many applications.
● Goal?
sorting a sequence of values in increasing order using n processors
● Potential speedup?
best sequential algorithm has complexity= O(n log n)
● the best we can aim with a parallel algorithm, using n processors is:
optimal complexity of a parallel sorting algorithm: O(n log n)/n = O(log n)
Parallel Sorting
Algorithms
● Parallel Bubble Sort
● Parallel Merge Sort
● Bitonic Sort
● Shear sort
Parallel Sorting
Algorithms
● Parallel Bubble Sort
● Parallel Merge Sort
● Bitonic Sort
● Shear sort
Bubble Sort
● One of the straight-forward sorting methods.
– Cycles through the list.
– Compares consecutive elements and swaps them if necessary.
– Stops when no more out of order pair.
● Slow & inefficient.
● Average performance is O(n^2 ).
Bubble Sort:
Parallel Bubble Sort:
● Also known as Odd-Even Bubble sort.
● operates in two alternate phases:
Phase-even:
even processes exchange values with right neighbors.
Phase-odd:
odd processes exchange values with right neighbors.
Parallel bubble sort:
Parallel Bubble Sort:
Algorithm:
1. For k = 0 to n-1
2. If k is even then
3. for i = 0 to (n/2) do in parallel
4. If A[2i] > A[2i+1] then
5. Exchange A[2i] ↔ A[2i+1]
6. Else
7. for i = 0 to (n/2)-1 do in parallel
8. If A[2i+1] > A[2i+2] then
9. Exchange A[2i+1] ↔ A[2i+2]
10. Next k
Parallel bubble sort : Analysis
● Steps 1-10 is a one big loop that is represented n times.
● Therefore, the parallel time complexity is O(n).
● The algorithm, odd-numbered steps need (n/2) - 1 processors and even-numbered
steps require (n/2) processors.
● Therefore, this needs O(n) processors.
Parallel Sorting
Algorithms
● Parallel Bubble Sort
● Parallel Merge Sort
● Bitonic Sort
● Shear sort
Mergesort:
● Example of a divide-and-conquer algorithm.
● Sorting method to sort a vector; first subdivides it in two parts,
● applies again the same method to each part and when they are both sorted (2 sorted
vectors/lists) with m and n elements,
● They are merged to produce a sorted vector that contains m + n elements of the initial
vector.
● The average complexity is O(n log n).
● T (n) = b n=1
=2T(n/2)+b(n) n>1
● Solve the recurrence relation, T(n) = O(nlogn)
Parallel Merge Sort:
● Collects sorted list onto one processor.
● Merges elements as they come together.
● Simple tree structure.
● Parallelism is limited when near the root.
Divide:
Parallel Merge Sort:
● Collects sorted list onto one processor.
● Merges elements as they come together.
● Simple tree structure.
● Parallelism is limited when near the root.
Conquer
:
Parallel Merge sort: Using a strategy to assign work to
processors organized in a tree.
Merge sort - Time complexity
● Sequential Merge sort, O(nlogn)
● In Parallel,We have n processors
● logn time is required to divide sequence
● logn is for merging it.
● logn+logn= 2 logn
● O(logn)
Parallel Sorting
Algorithms
● Parallel Bubble Sort
● Parallel Merge Sort
● Bitonic Sort
● Shear sort
Bitonic Sort :
● A Bitonic List is defined as a list with
no more than one LOCAL MAXIMUM and no
more than one LOCAL MINIMUM.
● (Endpoints must be considered - wraparound )
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 sort:
How many parallel steps does it take to sort ?
--> logN
How would you sort a bitonic list WHEN N is NOT A POWER OF 2 ?
-->Use as many processes as N' where N' is a power of 2 and the
smallest number larger than N. Assign a special value such as
"infinity" to all the extra processes (some kind of a padding).
Bitonic Sort:
How to divide a bitonic sequence into two
bitonic subsequences ??
● The compare-and-exchange
operation moves smaller values to
the left and greater values to the
right.
● Given a bitonic sequence, if we apply
recursively these operations we get a
sorted sequence.
Bitonic Sort:
How to divide a bitonic sequence into two
bitonic subsequences ??
● The compare-and-exchange
operation moves smaller values to
the left and greater values to the
right.
● Given a bitonic sequence, if we apply
recursively these operations we get a
sorted sequence.
Number of steps (P=n)
● In order to form a sorted sequence of length n from two sorted sequences of length n/2,
there are log(n) comparator stages required.
● T(n) = log(n) + T(n/2)
● The solution of this recurrence equation is,
● T(n) = log(n) + log(n)-1 + log(n)-2 + ... + 1 = log(n) · (log(n)+1) / 2
● Each stage of the sorting network consists of n/2 comparators. On the whole, these are
Θ(n·log2
(n)) comparators.
● For P=n, T(n)= Θ(n·log2
(n)) / n = Θ(log2
(n))
Bitonic Sort:
How processors
will be connected
at different
stages??
(when N=P).
Parallel Sorting
Algorithms
● Parallel Bubble Sort
● Parallel Merge Sort
● Bitonic Sort
● Shear sort
Two-Dimensional Sorting on a Mesh
● Two network structures have received
special attention:
mesh and hypercube
● The layout of a sorted sequence on a
mesh could be row by row or snake-like:
Shear Sort:
Input: unsorted nn-array.
Output: the array sorted in snake-like order
Method:
repeat log(n) times
i. sort the rows (in alternating direction);
ii. sort the columns;
sort the rows;
Sorting the rows in alternating direction means that even rows are sorted from left to right
and odd rows from right to left.
Shear sort:
Alternate row and column sorting until list is fully sorted.
Alternate row directions to get snake-like sorting:
Shear sort – Time complexity
ODD-PHASE:
Even Rows: sort ascending order (use O-E Transposition sort) O(n)
Odd Rows: sort descending order (use O-E Transposition sort) O(n)
EVEN-PHASE: Sort each column in ascending order.
It takes O(logn) phases to sort (n x n) numbers: T = O(nlogn)
Tpar
= O(logn)
Parallel sorting - summary
Computational time complexity using P=n processors
Parallel bubble sort - O(n)
Parallel merge sort - O(log n)
Bitonic sort - O(log2
n)
Parallel Shear sort - O(logn)
References:
● “Parallel Programming Techniques & Applications Using Networked Workstations &
Parallel Computers, 2nd ed.” B.Wilkinson)
● http://web.mst.edu/~ercal/387/Suppl/class.9.txt
● http://www.gel.usherbrooke.ca/mailhot/gei431/labos/labo2/oets_ss2.html
● http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/twodim/shear/shearsorten.
htm
● https://en.wikipedia.org/wiki/Bitonic_sorter
Thank You!

More Related Content

What's hot

Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systems
sumitjain2013
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
Ankit Katiyar
 

What's hot (20)

program partitioning and scheduling IN Advanced Computer Architecture
program partitioning and scheduling  IN Advanced Computer Architectureprogram partitioning and scheduling  IN Advanced Computer Architecture
program partitioning and scheduling IN Advanced Computer Architecture
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
All-Reduce and Prefix-Sum Operations
All-Reduce and Prefix-Sum Operations All-Reduce and Prefix-Sum Operations
All-Reduce and Prefix-Sum Operations
 
Distributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit ProtocolsDistributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit Protocols
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
 
SYNCHRONIZATION IN MULTIPROCESSING
SYNCHRONIZATION IN MULTIPROCESSINGSYNCHRONIZATION IN MULTIPROCESSING
SYNCHRONIZATION IN MULTIPROCESSING
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
Introduction to MPI
Introduction to MPI Introduction to MPI
Introduction to MPI
 
Course outline of parallel and distributed computing
Course outline of parallel and distributed computingCourse outline of parallel and distributed computing
Course outline of parallel and distributed computing
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systems
 
Problem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptProblem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.ppt
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 

Viewers also liked

Ai class
Ai classAi class
Ai class
meshaye
 

Viewers also liked (20)

August 29, Overview over Systems studied in the course
August 29, Overview over Systems studied in the courseAugust 29, Overview over Systems studied in the course
August 29, Overview over Systems studied in the course
 
Sensors update
Sensors updateSensors update
Sensors update
 
Transducer main
Transducer mainTransducer main
Transducer main
 
Transducer
TransducerTransducer
Transducer
 
Ai class
Ai classAi class
Ai class
 
active and passive sensors
active and passive sensorsactive and passive sensors
active and passive sensors
 
Parallel sorting
Parallel sortingParallel sorting
Parallel sorting
 
Difference between Sensor & Transducer
Difference between Sensor & TransducerDifference between Sensor & Transducer
Difference between Sensor & Transducer
 
Open-World Mission Specification for Reactive Robots - ICRA 2014
Open-World Mission Specification for Reactive Robots - ICRA 2014Open-World Mission Specification for Reactive Robots - ICRA 2014
Open-World Mission Specification for Reactive Robots - ICRA 2014
 
Ajm unit 2
Ajm unit 2Ajm unit 2
Ajm unit 2
 
Multisensor Data Fusion : Techno Briefing
Multisensor Data Fusion : Techno BriefingMultisensor Data Fusion : Techno Briefing
Multisensor Data Fusion : Techno Briefing
 
Robotics
RoboticsRobotics
Robotics
 
Introduction to robotics
Introduction to roboticsIntroduction to robotics
Introduction to robotics
 
sensors in robotics
sensors in roboticssensors in robotics
sensors in robotics
 
Passive infrared based human detection alive robot
Passive infrared based human detection alive robotPassive infrared based human detection alive robot
Passive infrared based human detection alive robot
 
Sensors
SensorsSensors
Sensors
 
August 31, Reactive Algorithms I
August 31, Reactive Algorithms IAugust 31, Reactive Algorithms I
August 31, Reactive Algorithms I
 
Application of image processing
Application of image processingApplication of image processing
Application of image processing
 
Data acquisition softwares
Data acquisition softwaresData acquisition softwares
Data acquisition softwares
 
Building Robots Tutorial
Building Robots TutorialBuilding Robots Tutorial
Building Robots Tutorial
 

Similar to Parallel sorting Algorithms

Similar to Parallel sorting Algorithms (20)

Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Chap9 slides
Chap9 slidesChap9 slides
Chap9 slides
 
Analysis and design of algorithms part2
Analysis and design of algorithms part2Analysis and design of algorithms part2
Analysis and design of algorithms part2
 
Merge sort
Merge sortMerge sort
Merge sort
 
Lecture23
Lecture23Lecture23
Lecture23
 
Selection sort lab mannual
Selection sort lab mannualSelection sort lab mannual
Selection sort lab mannual
 
Sorting
SortingSorting
Sorting
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Cs1311lecture23wdl
Cs1311lecture23wdlCs1311lecture23wdl
Cs1311lecture23wdl
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Module 2_ Divide and Conquer Approach.pptx
Module 2_ Divide and Conquer Approach.pptxModule 2_ Divide and Conquer Approach.pptx
Module 2_ Divide and Conquer Approach.pptx
 
Ada notes
Ada notesAda notes
Ada notes
 
Daa chapter5
Daa chapter5Daa chapter5
Daa chapter5
 
Cis435 week06
Cis435 week06Cis435 week06
Cis435 week06
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Sorting
SortingSorting
Sorting
 
sorting
sortingsorting
sorting
 
quick sort by deepak.pptx
quick sort by deepak.pptxquick sort by deepak.pptx
quick sort by deepak.pptx
 
Data Structure (MC501)
Data Structure (MC501)Data Structure (MC501)
Data Structure (MC501)
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 

Recently uploaded

Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
AroojKhan71
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptx
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
ELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptxELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptx
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 

Parallel sorting Algorithms

  • 2. Sorting in Parallel ● Why? it is a frequent operation in many applications. ● Goal? sorting a sequence of values in increasing order using n processors ● Potential speedup? best sequential algorithm has complexity= O(n log n) ● the best we can aim with a parallel algorithm, using n processors is: optimal complexity of a parallel sorting algorithm: O(n log n)/n = O(log n)
  • 3. Parallel Sorting Algorithms ● Parallel Bubble Sort ● Parallel Merge Sort ● Bitonic Sort ● Shear sort
  • 4. Parallel Sorting Algorithms ● Parallel Bubble Sort ● Parallel Merge Sort ● Bitonic Sort ● Shear sort
  • 5. Bubble Sort ● One of the straight-forward sorting methods. – Cycles through the list. – Compares consecutive elements and swaps them if necessary. – Stops when no more out of order pair. ● Slow & inefficient. ● Average performance is O(n^2 ).
  • 7. Parallel Bubble Sort: ● Also known as Odd-Even Bubble sort. ● operates in two alternate phases: Phase-even: even processes exchange values with right neighbors. Phase-odd: odd processes exchange values with right neighbors.
  • 9. Parallel Bubble Sort: Algorithm: 1. For k = 0 to n-1 2. If k is even then 3. for i = 0 to (n/2) do in parallel 4. If A[2i] > A[2i+1] then 5. Exchange A[2i] ↔ A[2i+1] 6. Else 7. for i = 0 to (n/2)-1 do in parallel 8. If A[2i+1] > A[2i+2] then 9. Exchange A[2i+1] ↔ A[2i+2] 10. Next k
  • 10. Parallel bubble sort : Analysis ● Steps 1-10 is a one big loop that is represented n times. ● Therefore, the parallel time complexity is O(n). ● The algorithm, odd-numbered steps need (n/2) - 1 processors and even-numbered steps require (n/2) processors. ● Therefore, this needs O(n) processors.
  • 11. Parallel Sorting Algorithms ● Parallel Bubble Sort ● Parallel Merge Sort ● Bitonic Sort ● Shear sort
  • 12. Mergesort: ● Example of a divide-and-conquer algorithm. ● Sorting method to sort a vector; first subdivides it in two parts, ● applies again the same method to each part and when they are both sorted (2 sorted vectors/lists) with m and n elements, ● They are merged to produce a sorted vector that contains m + n elements of the initial vector. ● The average complexity is O(n log n). ● T (n) = b n=1 =2T(n/2)+b(n) n>1 ● Solve the recurrence relation, T(n) = O(nlogn)
  • 13. Parallel Merge Sort: ● Collects sorted list onto one processor. ● Merges elements as they come together. ● Simple tree structure. ● Parallelism is limited when near the root. Divide:
  • 14. Parallel Merge Sort: ● Collects sorted list onto one processor. ● Merges elements as they come together. ● Simple tree structure. ● Parallelism is limited when near the root. Conquer :
  • 15. Parallel Merge sort: Using a strategy to assign work to processors organized in a tree.
  • 16. Merge sort - Time complexity ● Sequential Merge sort, O(nlogn) ● In Parallel,We have n processors ● logn time is required to divide sequence ● logn is for merging it. ● logn+logn= 2 logn ● O(logn)
  • 17. Parallel Sorting Algorithms ● Parallel Bubble Sort ● Parallel Merge Sort ● Bitonic Sort ● Shear sort
  • 18. Bitonic Sort : ● A Bitonic List is defined as a list with no more than one LOCAL MAXIMUM and no more than one LOCAL MINIMUM. ● (Endpoints must be considered - wraparound ) 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.
  • 19. Bitonic sort: How many parallel steps does it take to sort ? --> logN How would you sort a bitonic list WHEN N is NOT A POWER OF 2 ? -->Use as many processes as N' where N' is a power of 2 and the smallest number larger than N. Assign a special value such as "infinity" to all the extra processes (some kind of a padding).
  • 20. Bitonic Sort: How to divide a bitonic sequence into two bitonic subsequences ?? ● The compare-and-exchange operation moves smaller values to the left and greater values to the right. ● Given a bitonic sequence, if we apply recursively these operations we get a sorted sequence.
  • 21. Bitonic Sort: How to divide a bitonic sequence into two bitonic subsequences ?? ● The compare-and-exchange operation moves smaller values to the left and greater values to the right. ● Given a bitonic sequence, if we apply recursively these operations we get a sorted sequence.
  • 22. Number of steps (P=n) ● In order to form a sorted sequence of length n from two sorted sequences of length n/2, there are log(n) comparator stages required. ● T(n) = log(n) + T(n/2) ● The solution of this recurrence equation is, ● T(n) = log(n) + log(n)-1 + log(n)-2 + ... + 1 = log(n) · (log(n)+1) / 2 ● Each stage of the sorting network consists of n/2 comparators. On the whole, these are Θ(n·log2 (n)) comparators. ● For P=n, T(n)= Θ(n·log2 (n)) / n = Θ(log2 (n))
  • 23. Bitonic Sort: How processors will be connected at different stages?? (when N=P).
  • 24. Parallel Sorting Algorithms ● Parallel Bubble Sort ● Parallel Merge Sort ● Bitonic Sort ● Shear sort
  • 25. Two-Dimensional Sorting on a Mesh ● Two network structures have received special attention: mesh and hypercube ● The layout of a sorted sequence on a mesh could be row by row or snake-like:
  • 26. Shear Sort: Input: unsorted nn-array. Output: the array sorted in snake-like order Method: repeat log(n) times i. sort the rows (in alternating direction); ii. sort the columns; sort the rows; Sorting the rows in alternating direction means that even rows are sorted from left to right and odd rows from right to left.
  • 27. Shear sort: Alternate row and column sorting until list is fully sorted. Alternate row directions to get snake-like sorting:
  • 28. Shear sort – Time complexity ODD-PHASE: Even Rows: sort ascending order (use O-E Transposition sort) O(n) Odd Rows: sort descending order (use O-E Transposition sort) O(n) EVEN-PHASE: Sort each column in ascending order. It takes O(logn) phases to sort (n x n) numbers: T = O(nlogn) Tpar = O(logn)
  • 29. Parallel sorting - summary Computational time complexity using P=n processors Parallel bubble sort - O(n) Parallel merge sort - O(log n) Bitonic sort - O(log2 n) Parallel Shear sort - O(logn)
  • 30. References: ● “Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers, 2nd ed.” B.Wilkinson) ● http://web.mst.edu/~ercal/387/Suppl/class.9.txt ● http://www.gel.usherbrooke.ca/mailhot/gei431/labos/labo2/oets_ss2.html ● http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/twodim/shear/shearsorten. htm ● https://en.wikipedia.org/wiki/Bitonic_sorter