thrust

◆ sort() [1/4]

template<typename DerivedPolicy , typename RandomAccessIterator >
__host__ __device__ void thrust::sort ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
RandomAccessIterator  first,
RandomAccessIterator  last 
)

sort sorts the elements in [first, last) into ascending order, meaning that if i and j are any two valid iterators in [first, last) such that i precedes j, then *j is not less than *i. Note: sort is not guaranteed to be stable. That is, suppose that *i and *j are equivalent: neither one is less than the other. It is not guaranteed that the relative order of these two elements will be preserved by sort.

This version of sort compares objects using operator<.

The algorithm's execution is parallelized as determined by exec.

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the sequence.
lastThe end of the sequence.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
RandomAccessIteratoris a model of Random Access Iterator, RandomAccessIterator is mutable, and RandomAccessIterator's value_type is a model of LessThan Comparable, and the ordering relation on RandomAccessIterator's value_type is a strict weak ordering, as defined in the LessThan Comparable requirements.

The following code snippet demonstrates how to use sort to sort a sequence of integers using the thrust::host execution policy for parallelization:

#include <thrust/sort.h>
...
const int N = 6;
int A[N] = {1, 4, 2, 8, 5, 7};
// A is now {1, 2, 4, 5, 7, 8}
See also
http://www.sgi.com/tech/stl/sort.html
stable_sort
sort_by_key