1 / 10

Sorting

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)

deanmiller
Télécharger la présentation

Sorting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. Odd/Even Interchange to alphabetize a list L of records on field x.

  4. 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

  5. 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

  6. 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

  7. 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)

  8. Figure 4.6

  9. Peril-L program using Batcher’s sort to alphabetize records in L. Setting up Pointer Sort >=

  10. Peril-L program using Batcher’s sort to alphabetize records in L. (cont.)

More Related