110 likes | 148 Views
Explore efficient sorting methods including Odd/Even Interchange, 26-way parallelism, and Batcher's Bitonic Sort for alphabetizing records. Learn about scaling techniques and synchronization processes.
E N D
Sorting • We will be sorting records based on some key. • The records will be stored in “global” memory. • We will use the following helper functions
Unlimited Parallelism Solution • Use P=N-1 processors • All odd processors compare their value with the next processor (an even processor) • Swap if needed • Then all even processors compare their value with the next odd processor. • Swap if needed • Continue until no swap • Will need O(n) passes; each pass O(1) • Swap is NOT local
Odd/Even Interchange to alphabetize a list L of records on field x.
Limited Parallelism • Use 26 way parallelism, one processor for each letter • Scatter a part of the array to each processor • Each processor locally counts the number of items beginning with each letter • Do a reduce on the array of counts • Now have how many items begin with each letter • Indirectly have starting position of each letter in sorted array • Each processor grabs the items beginning with that processor’s letter. Sort locally. Store in proper position of global array
Fixed 26-way parallel solution to alphabetizing. The function letRank(x) returns the 0-origin rank of the Latin letter x. index 1. Gets values from global L 2. Saves values into global L – Synchronization concern 3.Synchronization point
Scalable Parallelism – Batcher’s Bitonic Sort • Must have a power of 2 processes • Each processor sorts its local records • Some ascending, some descending (more later) • Pairs merge in an elegant manner. • Merging uses (p,d) • p: which pairs merge • Processor i and j merge if the bit pattern for i and j differ only in bit p • d: which direction – look at bit d of the process’ id
Merging • A sequence is sorted if it is non-increasing or non-decreasing. • Merging will make a bitonic (not monotonic) sequence (i.e. will go up then down, or down then up)
Peril-L program using Batcher’s sort to alphabetize records in L. Setting up Pointer Sort >=
Peril-L program using Batcher’s sort to alphabetize records in L. (cont.)