Top Qs
Timeline
Chat
Perspective

Bitonic sorter

Parallel sorting algorithm From Wikipedia, the free encyclopedia

Bitonic sorter
Remove ads

Bitonic mergesort is a parallel algorithm for sorting. It is also used as a construction method for building a sorting network. The algorithm was devised by Ken Batcher. [3] The resulting sorting networks consist of comparators and have a delay of , where is the number of items to be sorted[1][2]. This makes it a popular choice for sorting large numbers of elements on an architecture which itself contains a large number of parallel execution units running in lockstep, such as a typical GPU.

Quick facts Class, Data structure ...

A sorted sequence is a monotonically non-decreasing (or non-increasing) sequence. A sequence is bitonic if it consist of two sequences where exactly one sequence is non-decreasing and the other is non-increasing. Formally this means it exists a for which [3].

A bitonic sorter can only sort inputs that are bitonic. Bitonic sorter can be used to build a bitonic sort network that can sort arbitrary sequences by using the bitonic sorter with a sort by merge scheme. With the sort by merge scheme part solutions are merged together using bigger sorters. This is further described in the chapter about bitonic sorting networks.

In the following chapters the original algorithm is described, which needs input sequences with . Therefore, let in the following chapters. Therefore the next biggest bitonic sorter from a k-bitonic sorter is a (k+1)-bitonic sorter.

Remove ads

Bitonic Sorter

Summarize
Perspective
Thumb
A normal comparator with two inputs

With a bitonic sorter, only bitonic sequences can be used as inputs. To sort arbitrary input sequences, a bitonic sorting network can be created from bitonic sorters. For bitonic sorting networks, see the next chapter. A bitonic sorter for is trivially just a comparator[3]. This is illustrated by the given box layout with X and Y being the inputs and H the higher output and L the lower output, respectively.

With the sorter for , we can recursively create a sorter of higher order. For example, consider the following bitonic sorter[3].

Thumb
A bitonic merge sorter

The bitonic sorter consists of two layers: a recombination layer and bitonic sorters of a lower order. The recombination layer recombines the bitonic inputs into two new bitonic sequences that are half as big as the original sequence. In the bitonic sort layer, there are two bitonic sorters of order that take the bitonic input of the recombination and sort them again. This can be done recursively for each using an input of each monotonic sequence per comparator. The following illustration shows the connection of the recombination in order for this to work[3].

Thumb
test

As you can see, the first half of the input sequence is compared against the last half of the input sequence. Both subsequences are already monotonically decreasing or increasing, respectively. Comparing each element of the (green) subsequence with the element of the other (orange) subsequence at the respective index produces two bitonic subsequences. These two bitonic series (blue and red, respectively) can then be fed into the next lower-order bitonic sorter. This can be done because all elements in the red sequence are guaranteed to be higher than all elements in the blue series[3].

Proof of the bitonic sorter

Ken Batcher provided some mathematical proof sketch in his paper[3]. With out loss of generality the bitonic input sequence is assumed to be with . With out loss of generality the sequence can be reversed therefore, we can assume .

Case 1: If then every element of the two subsequences are smaller. In this case and with and therefore and are trivially bitonic.

Case 2: Otherwise there exists a such that the element of the first sub-sequence is bigger then of the second sub-sequence while it is the opposite for . This means that and are true for a specific . Therefore we now know that:

1. For the sequences are and

2. For the sequences are defined as the opposite of 1, with and

In the original paper he then claims the following inequalities result from those definitions[3]:

Following from 1:

  • For that
  • For that
  • For that

Following from 2:

  • For that
  • For that

From both:

From the paper claims follows that the sequences and are in fact bitonic[3].

Remove ads

Bitonic Sorting Networks (Bitonic Merge Sort)

Summarize
Perspective

A bitonic sorting network is created by using several bitonic sorters. These bitonic sorters are recursively used to create two monotonic sequences, one decreasing and one increasing, which are then put into the next stage. This creates a bitonic series for the next stage, which can then use this bitonic series as a monotonic series for the next stage. Consider the following example for an bitonic sort network [3].

Thumb
test

The bitonic sorting network for can be created by using a bitonic sorter and two sorters. The two sorters create a decreasingly or increas- ingly sorted sequence in order to create a bitonic input for the bitonic sorter. Bitonic sorting networks of a lower order are mostly used for the two pre-sorters; therefore, a recursive definition of a bitonic sorting network from bitonic sorters can be described. In the above example, the two bitonic sorting networks are networks; hence, they are just a comparator [3]. The following figure shows the overall scheme.

Thumb
test

This overall scheme requires the sorter to have an input of sequence that is a power of two. There are, however, possibilities to mitigate this by, for example, using sentinel values.

Remove ads

Complexity

Summarize
Perspective

In this chapter we assume that our sorter has input elements. Let therefore as previously.

Each recursion in a bitonic sorting network adds a sorter of order , which consists of bitonic sorter and the next recursion. As both sub-sorters can be done in parallel, only one level is added for each level in both sub-sorters. Each bitonic sorter has, therefore, one recombination layer and a lower-order bitonic sorter for its recursion. This results in levels per bitonic sorter. Therefore we can describe this construction's levels as the following sum: .

This sum can be reduced using the Gauss sum formula

Therefore, the number of levels in which each comparison can be done in parallel is given by [3]. Which gives us assuming comparisons can be performed in parallel.

Although the absolute number of comparisons is typically higher than Batcher's odd-even sort, many of the consecutive operations in a bitonic sort retain a locality of reference, making implementations more cache-friendly and typically more efficient in practice [3].

Remove ads

See also

References

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads