CALTECH CS137 Winter2006 -- DeHon 1 CS137: Electronic Design Automation Day 12: February 6, 2006 Sorting.

Slides:



Advertisements
Similar presentations
Garfield AP Computer Science
Advertisements

Lecture 19: Parallel Algorithms
Parallel Sorting Sathish Vadhiyar. Sorting  Sorting n keys over p processors  Sort and move the keys to the appropriate processor so that every key.
Lecture 3: Parallel Algorithm Design
Batcher’s merging network Efficient Parallel Algorithms COMP308.
CIS December '99 Introduction to Parallel Architectures Dr. Laurence Boxer Niagara University.
CALTECH CS137 Spring DeHon CS137: Electronic Design Automation Day 5: April 15, 2002 Systolic Algorithms Andre' DeHon.
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Suffix Sorting & Related Algoritmics Martin Farach-Colton Rutgers University USA.
Advanced Topics in Algorithms and Data Structures Lecture pg 1 Recursion.
CMPS1371 Introduction to Computing for Engineers SORTING.
CS 253: Algorithms Chapter 8 Sorting in Linear Time Credit: Dr. George Bebis.
CSE 373: Data Structures and 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.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
1 Lecture 25: Parallel Algorithms II Topics: matrix, graph, and sort algorithms Tuesday presentations:  Each group: 10 minutes  Describe the problem,
Lecture 21: Parallel Algorithms
Parallel Routing Bruce, Chiu-Wing Sham. Overview Background Routing in parallel computers Routing in hypercube network –Bit-fixing routing algorithm –Randomized.
Interconnection Network PRAM Model is too simple Physically, PEs communicate through the network (either buses or switching networks) Cost depends on network.
FALL 2006CENG 351 Data Management and File Structures1 External Sorting.
1 Parallel Algorithms III Topics: graph and sort algorithms.
Mesh connected networks. Sorting algorithms Efficient Parallel Algorithms COMP308.
Sorting Lower Bound Andreas Klappenecker based on slides by Prof. Welch 1.
Topic Overview One-to-All Broadcast and All-to-One Reduction
Analysis of Algorithms CS 477/677
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
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.
Outline  introduction  Sorting Networks  Bubble Sort and its Variants 2.
CSCE 3110 Data Structures & Algorithm Analysis Sorting (I) Reading: Chap.7, Weiss.
1 Lecture 16: Lists and vectors Binary search, Sorting.
Parallel and Distributed Algorithms Eric Vidal Reference: R. Johnsonbaugh and M. Schaefer, Algorithms (International Edition) Pearson Education.
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use by MSU Dept. of Computer Science.
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 and Searching. Selection Sort  “Search-and-Swap” algorithm 1) Find the smallest element in the array and exchange it with a[0], the first element.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
HEAPS Amihood Amir Bar Ilan University Sorting Bubblesort: Until no exchanges: For i=1 to n-1 if A[i]>A[i+1] then exchange their values end Time.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
1 CSC 421: Algorithm Design & Analysis Spring 2014 Complexity & lower bounds  brute force  decision trees  adversary arguments  problem reduction.
Searching and Sorting Searching: Sequential, Binary Sorting: Selection, Insertion, Shell.
CALTECH CS137 Winter DeHon 1 CS137: Electronic Design Automation Day 10: February 1, 2006 Dynamic Programming.
CSE 326: Data Structures Lecture 23 Spring Quarter 2001 Sorting, Part 1 David Kaplan
+ Even Odd Sort & Even-Odd Merge Sort Wolfie Herwald Pengfei Wang Rachel Celestine.
Week 13 - Wednesday.  What did we talk about last time?  NP-completeness.
Basic Communication Operations Carl Tropper Department of Computer Science.
Fast VLSI Implementation of Sorting Algorithm for Standard Median Filters Hyeong-Seok Yu SungKyunKwan Univ. Dept. of ECE, Vada Lab.
Unit-8 Sorting Algorithms Prepared By:-H.M.PATEL.
 2006 Pearson Education, Inc. All rights reserved. 1 Searching and Sorting.
Sorting & Lower Bounds Jeff Edmonds York University COSC 3101 Lecture 5.
CS6045: Advanced Algorithms Sorting Algorithms. Sorting So Far Insertion sort: –Easy to code –Fast on small inputs (less than ~50 elements) –Fast on nearly-sorted.
CALTECH CS137 Winter DeHon 1 CS137: Electronic Design Automation Day 8: January 27, 2006 Cellular Placement.
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
Sorting.
Algorithms for Big Data: Streaming and Sublinear Time Algorithms
Lecture 3: Parallel Algorithm Design
Mesh connected networks. Sorting algorithms
CS137: Electronic Design Automation
COMP108 Algorithmic Foundations Algorithm efficiency
Sorting Networks Characteristics The basic unit: a comparator
Teach A level Computing: Algorithms and Data Structures
Parallel Sorting Algorithms
Lecture 22: Parallel Algorithms
Algorithm design and Analysis
Parallel Sorting Algorithms
CS 101 – Oct. 21 Sorting Much-studied problem in CS – many ways to do it Given a list of data, need to arrange it “in order” Some methods do better based.
Parallel Sorting Algorithms
Divide-and-Conquer 7 2  9 4   2   4   7
Presentation transcript:

CALTECH CS137 Winter DeHon 1 CS137: Electronic Design Automation Day 12: February 6, 2006 Sorting

CALTECH CS137 Winter DeHon 2 Today Sequential Sorting Building on Parallel Prefix Systolic –Sort –Priority Queue Streaming Sort Mesh Sort (Shear Sort) Sorting Networks Parallel Merge Sort

CALTECH CS137 Winter DeHon 3 Sequential Sort What’s your favorite sequential sort? Runtime?

CALTECH CS137 Winter DeHon 4 Sequential Merge Sort Observe: can merge two sorted list of length N in O(N) time Start with N lists of length 1 Merge to for N/2 lists of length 2 Merge to form N/4 lists of length 4 …how many times? Each merge?

CALTECH CS137 Winter DeHon 5 Sequential Merge Sort Observe: can merge two sorted list of length N in O(N) time Merge successively longer lists log(N) merges Each takes time O(N) Sort in: O(N log(N))

CALTECH CS137 Winter DeHon 6 Parallel Sorting prefix

CALTECH CS137 Winter DeHon 7 Rank Finding Looking for I’th ordered element Do a prefix-sum on high-bit only –Know m=number of things > … High-low search on result –I.e. if number > I, recurse on half with leading zero –If number < I, search for (I-m)’th element in half with high-bit true Find I’th element in log 2 (N) time Day 9

CALTECH CS137 Winter DeHon 8 Rank-based Sort In O(log 2 (N)) time on N processors can find the I’th element Use separate groups of N processors to find the 1 st, 2 nd, 3 rd, … element in parallel Also count the number of such elements in O(log(N)) time using parallel prefix –Give each unique offset Send each element to its correct position  O(log 2 (N)) sorting algorithm with O(N 2 ) processors

CALTECH CS137 Winter DeHon 9 Rank Sort Analysis Area N 2 Time log 2 (N) Work: (N log(N)) 2  square of sequential work

CALTECH CS137 Winter DeHon 10 Systolic One Dimensional Array

CALTECH CS137 Winter DeHon 11 Sort as Data Arrives Often receive data as a sequential stream Can I sort the data as it arrive? Build a systolic solution? –Use only local interconnect Cell traps largest value

CALTECH CS137 Winter DeHon 12 Linear Systolic Sort Often receive data as a sequential stream Can I sort the data as it arrive? Build a systolic solution? –Use only local interconnect [Basic approach from Leighton]

CALTECH CS137 Winter DeHon 13 Linear Systolic Sort Analysis Area N Time N Work: N 2

CALTECH CS137 Winter DeHon 14 Priority Queue Insert top Extract Largest With O(N) cells O(1) Extract Allows interleave insert/delete

CALTECH CS137 Winter DeHon 15 Priority Queue Idea Trap Largest –Like Linear Sort Largest always at front –Always immediately available On extract –Shift up New value Largest Next Largest

CALTECH CS137 Winter DeHon 16 Priority Queue Cell If (Cin=insert) Alocal  largest Bout  smallest If (Cin=extract) Alocal  Ain Bout  Bin Cout  Cin

CALTECH CS137 Winter DeHon 17 Streaming Merge Sort

CALTECH CS137 Winter DeHon 18 Streaming Sort Can we sort streaming data with O(log(N)) hardware? How do you sort efficiently in SCORE? –Pipe-and-filter System Architecture?

CALTECH CS137 Winter DeHon 19 Build Merge Tree Merge Sort stream Observe: early merges run at lower frequency than later…

CALTECH CS137 Winter DeHon 20 Streaming Sort After log(N) merges, output stream is sorted.

CALTECH CS137 Winter DeHon 21 Streaming Sort Buffer lengths grow by 2× each stage. Total memory: 2×(N/2) + 2×(N/4) + 2×(N/8) +…  2N

CALTECH CS137 Winter DeHon 22 Streaming Sort Analysis Area log(N) compare/switch –O(N) memory –[also true of sequential case] Time O(N) Work: O(N log(N)) –Work efficient

CALTECH CS137 Winter DeHon 23 Mesh Sort

CALTECH CS137 Winter DeHon 24 Mesh Sort Start with N items in  N×  N mesh Sort into specified order Nearest-neighbor communication only

CALTECH CS137 Winter DeHon 25 Observation 1 Can sort m things on linear array in O(m) time –Perform Parallel Bubble sort in m steps –i.e. alternate odd/even swap pairings

CALTECH CS137 Winter DeHon 26 Shearsort Algorithm: alternate sorting rows and columns for log(N)+1 steps –i.e. sort rows on odd steps; columns on even steps –Sort odd rows ascending, even rows descending –Can use even/odd swapping for row/column sorts O(  N log(N))

CALTECH CS137 Winter DeHon 27 Simplifying Lemma 0-1 Sorting Lemma: If an oblivious comparison-exchange algorithm sorts all input sets consisting of solely 0’s and 1’s, then it sorts all input sets with arbitrary values –proof in Leighton Odd/even swapping is an oblivious comparison-exchange

CALTECH CS137 Winter DeHon 28 Shearsort Works? General form after column sort: –0 rows –Mixed (dirty) rows –1 rows Consider all row pairs: –3 cases More zeros, more ones, equal number –Row sort puts all zeros on one side, ones on other –Column sort  one of the pair ends up all ones/zeros –Therefore, each row/column sort cuts the number of “dirty” rows in half

CALTECH CS137 Winter DeHon 29 Shearsort Works? Consider all row pairs: –3 cases More zeros, more ones, equal number –Row sort puts all zeros on one side, ones on other –Column sort  one of the pair ends up all ones/zerso –Therefore, each row/column sort cuts the number of “dirty” rows in half Dirty Rows after column sort row column

CALTECH CS137 Winter DeHon 30 Rounding up Steps Each sort m=  N steps log(  N ) row/column sorts to remove dirty rows 2 log(  N ) =log(N) Total steps:  N log(N)

CALTECH CS137 Winter DeHon 31 Shear Sort Analysis Area N Time  N log(N) –Best could hope to do is  N w/ nearest- neighbor connections in 2D world –Asymptotically in any 2D world Work: N 1.5 log(N)

CALTECH CS137 Winter DeHon 32 Mesh Sort Can do Mesh sort in O(  N) steps –Best could hope to do More complicated…see Leighton

CALTECH CS137 Winter DeHon 33 Extend to 3D Array Can sort N numbers on N 1/3 × N 1/3 × N 1/3 array in O(N 1/3 ) steps –Sort zx into zx order –Sort yz into zy-order –Sort xy into yx-order (reversing order on every-other plane) –Two-steps of odd/even merging within each z-line –Sort xy into yx-order

CALTECH CS137 Winter DeHon 34 Sorting  Movement If you believe –We only have 3 dimensions –Signal transport is bounded by speed of light This is asymptotically tight –Cannot do any better. –Will take O(N 1/3 ) time just to transport an item from start location to destination

CALTECH CS137 Winter DeHon 35 Sorting Networks

CALTECH CS137 Winter DeHon 36 Sorting Network Build a spatial sorting network: (from Knuth) Too big, too fast?  bit serial datapath elements?

CALTECH CS137 Winter DeHon 37 Systematic Construction: Step 1: Merge Network Recursively swap large/small elements from halves of network –Merge in log(N) steps B0 B1 B2 B3 A3 A2 A1 A0

CALTECH CS137 Winter DeHon 38 Systematic Construction: Sorting Network Perform recursive merging –log(N) merge networks Of depth log(N), log(N)-1… –Depth: O(log 2 (N)) –Area: O(N log 2 (N)) Can be used in pipelined fashion –Only using O(N) hardware exclusively per step

CALTECH CS137 Winter DeHon 39 Parallel Merge Sort

CALTECH CS137 Winter DeHon 40 Parallel Merge Sort With O(N) processors Sort in O(log 2 (N)) steps Sequentially executing the O(log 2 (N)) pairwise swaps of the sorting network Randomized algorithm –Works in O(log(N)) steps With high probability …see Leighton

CALTECH CS137 Winter DeHon 41 Admin Wednesday, Friday: NC Project: two things due in two weeks –Sequential baseline –Proposed plan of attack