GO-V.ORG
As seen in

Cache-oblivious distribution sort

The cache-oblivious distribution sort is a comparison-based sorting algorithm. It is similar to quicksort, but it is a cache-oblivious algorithm, designed for a setting where the number of elements to sort is too large to fit in a cache where operations are done. In the external memory model, the number of memory transfers it needs to perform a sort of N items on a machine with cache of size Z and cache lines of length L is O(\frac{N {L \log_Z N) , under the tall cache assumption that Z = \Omega(L^2) . This number of memory transfers has been shown to be asymptotically optimal for comparison sorts. This distribution sort also achieves the asymptotically optimal runtime complexity of... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.

The cache-oblivious distribution sort is a comparison-based sorting algorithm. It is similar to quicksort, but it is a cache-oblivious algorithm, designed for a setting where the number of elements to sort is too large to fit in a cache where operations are done. In the external memory model, the number of memory transfers it needs to perform a sort of N items on a machine with cache of size Z and cache lines of length L is O(\frac{N}{L} \log_Z N) , under the tall cache assumption that Z = \Omega(L^2) . This number of memory transfers has been shown to be asymptotically optimal for comparison sorts. This distribution sort also achieves the asymptotically optimal runtime complexity of \Theta(N \log N) . To accomplish this, each subarray and bucket will have a state associated with it. The state of a subarray consists of an index next of the next element to be read from the subarray, and a bucket number indicating which bucket index the element should be copied to. By convention, bnum = \infty if all elements in the subarray have been distributed. (Note that when we split a bucket, we have to increment all values of all subarrays whose value is greater than the index of the bucket that is split.) The state of a bucket consists of the value of the bucket's pivot, and the number of elements currently in the bucket. Consider the follow basic strategy: iterate through each subarray, attempting to copy over its element at position next. If the element is smaller than the pivot of bucket , then place it in that bucket, possibly incurring a bucket split. Otherwise, increment until a bucket whose pivot is large enough is found. Though this correctly distributes all elements, it does not exhibit a good cache performance. Instead, the distribution step is performed in a recursive divide-and-conquer. The step will be performed as a call to the function distribute, which takes three parameters i, j, and m. distribute(i, j, m) will distribute elements from the i-th through (i+m-1)-th subarrays into buckets, starting from B_j . It requires as a precondition that each subarray r in the range i, \ldots, i+m-1 has its bnum[r] \ge j . The execution of distribute(i, j, m) will guarantee that each bnum[r] \ge j+m . The whole distribution step is distribute (1,1,\sqrt{N}) . Pseudocode for the implementation of distribute is shown below: def distribute(i, j, m: int) -> None: """Distribute through recursive divide-and-conquer.""" if m == 1: copy_elems(i, j) else: distribute(i, j, m / 2) distribute(i + m / 2, j, m / 2) distribute(i, j + m / 2, m / 2) distribute(i + m / 2, j + m / 2, m / 2) The base case, where =1, has a call to the subroutine copy_elems. In this base case, all elements from subarray that belong to bucket are added at once. If this leads to bucket having too many elements, it splits the bucket with the procedure described beforehand. ==References== Harald Prokop. . Masters thesis, MIT. 1999.

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Cache-oblivious distribution sort". 1761051902. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1318036854

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·