PRAM Sorting




CS255

Chris Pollett

Feb 23, 2015

Outline

Introduction

Sorting on a PRAM

We now work towards a ZNC algorithm for sorting which run in `O(log n)` time doing a total of `O(n log n)` operations on all processors (Reischuk 1985). Let `P_i` denote the `i`th processor.

We begin by considering a PRAM variant of Quicksort:

  1. If `n=1` stop.
  2. Otherwise, pick a splitter uniformly at random from the `n` input elements
  3. Each processor determines whether its element is bigger or smaller than the splitter.
  4. Let `j` denote the rank of the splitter. If `j` is not in `[n/4, (3n)/4]` the step is declared a failure and we go back to step 1. Otherwise, we move the splitter to processor `P_j`. Each element that is smaller than the splitter is moved to a distinct processor is `P_i` such that `i < j`. Each element that is larger than the splitter is moved to a distinct processor `P_k` where `k > j`.
  5. We sort recursively the data in the processors `P_1` through `P_(j-1)` and the data in `P_(j+1)` through `P_(n)`.

Notice this algorithm uses randomness, but it has zero error -- we can detect if we are in a bad case in which case we rerun -- it is in this sense it is a ZNC algorithm for sorting.

Analysis

Quiz

Which of the following is true?

  1. A determinancy race occurs when two logically parallel instructions access the same memory location and at least one of the instructions performs a write.
  2. JOCL executes Java code on the a computer's GPU.
  3. In the PRAM model there is no global clock used between processors.

Using More Splitters

Suppose we have n processors and `n` elements. Suppose the first `r` processors have values in sorted order.

A Good Choice for `r`, a Complete Algorithm (called BoxSort)

  1. If so, we could pick `n^(1/2)` elements at random. Then using all `n` processors sort them in `O(log n)` steps.
  2. Then using these sorted elements insert the remaining elements among them in `O(log n)` steps .
  3. Treat the remaining elements that are inserted between splitter as subproblems, recur on each subproblem whose size exceed `log n`, otherwise, use LogSort:
    • Compare each element in parallel with its neighbor first to its left, swap if necessary; then to its right, swap if necessary, do this O(log n) times.

Intuition on Splitting

Analysis of Splitting

The End of Sorting