CS 584. Sorting n One of the most common operations n Definition: –Arrange an unordered collection of elements into a monotonically increasing or decreasing.

Slides:



Advertisements
Similar presentations
Advanced Sorting Methods: Shellsort Shellsort is an extension of insertion sort, which gains speed by allowing exchanges of elements that are far apart.
Advertisements

Parallel Sorting Sathish Vadhiyar. Sorting  Sorting n keys over p processors  Sort and move the keys to the appropriate processor so that every key.
Counting Sort Non-comparison sort. Precondition: n numbers in the range 1..k. Key ideas: For each x count the number C(x) of elements ≤ x Insert x at output.
Introduction to Algorithms
1 Sorting Problem: Given a sequence of elements, find a permutation such that the resulting sequence is sorted in some order. We have already seen: –Insertion.
High Performance Comparison-Based Sorting Algorithm on Many-Core GPUs Xiaochun Ye, Dongrui Fan, Wei Lin, Nan Yuan, and Paolo Ienne Key Laboratory of Computer.
Parallel Sorting Algorithms Comparison Sorts if (A>B) { temp=A; A=B; B=temp; } Potential Speed-up –Optimal Comparison Sort: O(N lg N) –Optimal Parallel.
Comp 122, Spring 2004 Elementary Sorting Algorithms.
1 Tuesday, November 14, 2006 “UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever.
Sorting Algorithms CS 524 – High-Performance Computing.
Design of parallel algorithms Sorting J. Porras. Problem Rearrange numbers (x 1,...,x n ) into ascending order ? What is your intuitive approach –Take.
Sorting Chapter 10.
Sorting Algorithms: Topic Overview
CS 684.
Sorting Algorithms Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar To accompany the text ``Introduction to Parallel Computing'', Addison Wesley,
CS 584. Algorithm Analysis Assumptions n Consider ring, mesh, and hypercube. n Each process can either send or receive a single message at a time. n No.
CS 584. Sorting n One of the most common operations n Definition: –Arrange an unordered collection of elements into a monotonically increasing or decreasing.
1 CSC401 – Analysis of Algorithms Lecture Notes 9 Radix Sort and Selection Objectives  Introduce no-comparison-based sorting algorithms: Bucket-sort and.
Bitonic and Merging sorting networks Efficient Parallel Algorithms COMP308.
Sorting Chapter 10. Chapter 10: Sorting2 Chapter Objectives To learn how to use the standard sorting methods in the Java API To learn how to implement.
CSCI-455/552 Introduction to High Performance Computing Lecture 22.
Sorting Chapter 12 Objectives Upon completion you will be able to:
CSE 373 Data Structures Lecture 15
Network Topologies Topology – how nodes are connected – where there is a wire between 2 nodes. Routing – the path a message takes to get from one node.
Lecture 12: Parallel Sorting Shantanu Dutt ECE Dept. UIC.
1 Parallel Sorting Algorithms. 2 Potential Speedup O(nlogn) optimal sequential sorting algorithm Best we can expect based upon a sequential sorting algorithm.
Adaptive Parallel Sorting Algorithms in STAPL Olga Tkachyshyn, Gabriel Tanase, Nancy M. Amato
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Outline  introduction  Sorting Networks  Bubble Sort and its Variants 2.
Sorting Chapter 10. Chapter Objectives  To learn how to use the standard sorting methods in the Java API  To learn how to implement the following sorting.
Elementary Sorting Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Lecture 6 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Sorting Fun1 Chapter 4: Sorting     29  9.
Simple Iterative Sorting Sorting as a means to study data structures and algorithms Historical notes Swapping records Swapping pointers to records Description,
The Fundamentals: Algorithms, the Integers & Matrices.
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
Sorting Sorting: –Task of rearranging data in an order. –Order can be: Ascending Order: –1,2,3,4,5,6,7,8,9 Descending Order: –9,8,7,6,5,4,3,2,1 Lexicographic.
Comparison of Optimization Algorithms By Jonathan Lutu.
Lecture 4 Sorting Networks. Comparator comparator.
UNIT 5.  The related activities of sorting, searching and merging are central to many computer applications.  Sorting and merging provide us with a.
1 Radix Sort. 2 Classification of Sorting algorithms Sorting algorithms are often classified using different metrics:  Computational complexity: classification.
A Comparison of Parallel Sorting Algorithms on Different Architectures Nancy M. Amato, Ravishankar Iyer, Sharad Sundaresan and Yan Wu Texas A&M University.
1 Parallel Sorting Algorithm. 2 Bitonic Sequence A bitonic sequence is defined as a list with no more than one LOCAL MAXIMUM and no more than one LOCAL.
“Sorting networks and their applications”, AFIPS Proc. of 1968 Spring Joint Computer Conference, Vol. 32, pp
Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar
Data Structures and Algorithms in Parallel Computing Lecture 8.
+ Even Odd Sort & Even-Odd Merge Sort Wolfie Herwald Pengfei Wang Rachel Celestine.
Parallel Programming - Sorting David Monismith CS599 Notes are primarily based upon Introduction to Parallel Programming, Second Edition by Grama, Gupta,
Chapter 9: Sorting1 Sorting & Searching Ch. # 9. Chapter 9: Sorting2 Chapter Outline  What is sorting and complexity of sorting  Different types of.
Linear Sorting. Comparison based sorting Any sorting algorithm which is based on comparing the input elements has a lower bound of Proof, since there.
QuickSort. Yet another sorting algorithm! Usually faster than other algorithms on average, although worst-case is O(n 2 ) Divide-and-conquer: –Divide:
Unit-8 Sorting Algorithms Prepared By:-H.M.PATEL.
Sorting: Parallel Compare Exchange Operation A parallel compare-exchange operation. Processes P i and P j send their elements to each other. Process P.
Advanced Sorting 7 2  9 4   2   4   7
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
Sorting.
Lecture 4 Sorting Networks
NEW SORTING ALGORITHMS
May 17th – Comparison Sorts
Auburn University COMP8330/7330/7336 Advanced Parallel and Distributed Computing Interconnection Networks (Part 2) Dr.
CMU : Internet Search Technologies
Chapter 2 (16M) Sorting and Searching
Radish-Sort 11/11/ :01 AM Quick-Sort     2 9  9
Advanced Sorting Methods: Shellsort
Bitonic Sorting and Its Circuit Design
Sorting … and Insertion Sort.
Bitonic and Merging sorting networks
Lecture 6 Algorithm Analysis
Lecture 6 Algorithm Analysis
Parallel Sorting Algorithms
Presentation transcript:

CS 584

Sorting n One of the most common operations n Definition: –Arrange an unordered collection of elements into a monotonically increasing or decreasing order. n Two categories of sorting –internal (fits in memory) –external (uses auxiliary storage)

Sorting Algorithms n Comparison based –compare-exchange –O(n log n) n Noncomparison based –Uses known properties of the elements –O(n) - bucket sort etc.

Parallel Sorting Issues n Input and Output sequence storage –Where? –Local to one processor or distributed n Comparisons –How compare elements on different nodes n # of elements per processor –One (compare-exchange --> comm.) –Multiple (compare-split --> comm.)

Compare-Exchange

Compare-Split

Sorting Networks n Specialized hardware for sorting –based on comparator xyxyxyxy max{x,y} min{x,y} max{x,y}

Sorting Network

Parallel Sorting Algorithms n Merge Sort n Quick Sort n Bitonic Sort n Others …

Merge Sort n Simplest parallel sorting algorithm? n Steps –Distribute the elements –Everybody sort their own sequence –Merge the lists n Problem –How to merge the lists

Bitonic Sort n Key operation: –rearrange a bitonic sequence to ordered n Bitonic Sequence –sequence of elements –sequence of elements n There exists i such that is monotonically increasing and is monotonically decreasing or n There exists a cyclic shift of indicies such that the above is satisfied.

Bitonic Sequences n n –First it increases then decreases – i = 3 n n –Consider a cyclic shift –i will equal 3

Rearranging a Bitonic Sequence n Let s = n Let s = –a n/2 is the beginning of the decreasing seq. n Let s 1 = n Let s 1 = n Let s 2 = n Let s 2 = n In sequence s 1 there is an element b i = min{a i, a n/2+i } –all elements before b i are from increasing –all elements after b i are from decreasing n Sequence s 2 has a similar point n Sequences s 1 and s 2 are bitonic

Rearranging a Bitonic Sequence n Every element of s 1 is smaller than every element of s 2 n Thus, we have reduced the problem of rearranging a bitonic sequence of size n to rearranging two bitonic sequences of size n/2 then concatenating the sequences.

Rearranging a Bitonic Sequence

Bitonic Merging Network

What about unordered lists? n To use the bitonic merge for n items, we must first have a bitonic sequence of n items. n Two elements form a bitonic sequence n Any unsorted sequence is a concatenation of bitonic sequences of size 2 n Merge those into larger bitonic sequences until we end up with a bitonic sequence of size n

Mapping onto a hypercube n One element per processor n Start with the sorting network maps n Each wire represents a processor n Map processors to wires to minimize the distance traveled during exchange

Bitonic Merging Network

Bitonic Merge on Hypercube

Bitonic Sort Procedure BitonicSort for i = 0 to d -1 for j = i downto 0 if (i + 1) st bit of iproc <> j th bit of iproc comp_exchange_max(j, item) else comp_exchange_min(j, item) endif endfor comp_exchange_max and comp_exchange_min compare and exchange the item with the neighbor on the j th dimension

Bitonic Sort Stages

Assignment n Pick 16 random integers n Draw the Bitonic Sort network n Step through the Bitonic sort network to produce a sorted list of integers. n Explain how the if statement in the Bitonic sort algorithm works.