sort
#
Overloads#
sort(exec, first, last)
#
-
template<typename DerivedPolicy, typename RandomAccessIterator>
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 ifi
andj
are any two valid iterators in[first, last)
such thati
precedesj
, 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 bysort
.This version of
sort
compares objects usingoperator<
.The algorithm’s execution is parallelized as determined by
exec
.The following code snippet demonstrates how to use
sort
to sort a sequence of integers using thethrust::host
execution policy for parallelization:#include <thrust/sort.h> #include <thrust/execution_policy.h> ... const int N = 6; int A[N] = {1, 4, 2, 8, 5, 7}; thrust::sort(thrust::host, A, A + N); // A is now {1, 2, 4, 5, 7, 8}
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the sequence.
last – The end of the sequence.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
RandomAccessIterator – is a model of Random Access Iterator,
RandomAccessIterator
is mutable, andRandomAccessIterator's
value_type
is a model of LessThan Comparable, and the ordering relation onRandomAccessIterator's
value_type
is a strict weak ordering, as defined in the LessThan Comparable requirements.
sort(first, last)
#
-
template<typename RandomAccessIterator>
void thrust::sort( - RandomAccessIterator first,
- RandomAccessIterator last,
sort
sorts the elements in[first, last)
into ascending order, meaning that ifi
andj
are any two valid iterators in[first, last)
such thati
precedesj
, 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 bysort
.This version of
sort
compares objects usingoperator<
.The following code snippet demonstrates how to use
sort
to sort a sequence of integers.#include <thrust/sort.h> ... const int N = 6; int A[N] = {1, 4, 2, 8, 5, 7}; thrust::sort(A, A + N); // A is now {1, 2, 4, 5, 7, 8}
See also
See also
- Parameters:
first – The beginning of the sequence.
last – The end of the sequence.
- Template Parameters:
RandomAccessIterator – is a model of Random Access Iterator,
RandomAccessIterator
is mutable, andRandomAccessIterator's
value_type
is a model of LessThan Comparable, and the ordering relation onRandomAccessIterator's
value_type
is a strict weak ordering, as defined in the LessThan Comparable requirements.
sort(exec, first, last, comp)
#
-
template<typename DerivedPolicy, typename RandomAccessIterator, typename StrictWeakOrdering>
void thrust::sort( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- RandomAccessIterator first,
- RandomAccessIterator last,
- StrictWeakOrdering comp,
sort
sorts the elements in[first, last)
into ascending order, meaning that ifi
andj
are any two valid iterators in[first, last)
such thati
precedesj
, 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 bysort
.This version of
sort
compares objects using a function objectcomp
.The algorithm’s execution is parallelized as determined by
exec
.The following code demonstrates how to sort integers in descending order using the greater<int> comparison operator using the
thrust::host
execution policy for parallelization:#include <thrust/sort.h> #include <thrust/functional.h> #include <thrust/execution_policy.h> ... const int N = 6; int A[N] = {1, 4, 2, 8, 5, 7}; thrust::sort(thrust::host, A, A + N, ::cuda::std::greater<int>()); // A is now {8, 7, 5, 4, 2, 1};
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the sequence.
last – The end of the sequence.
comp – Comparison operator.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
RandomAccessIterator – is a model of Random Access Iterator,
RandomAccessIterator
is mutable, andRandomAccessIterator's
value_type
is convertible toStrictWeakOrdering's
first argument type and second argument type.StrictWeakOrdering – is a model of Strict Weak Ordering.
sort(first, last, comp)
#
-
template<typename RandomAccessIterator, typename StrictWeakOrdering>
void thrust::sort( - RandomAccessIterator first,
- RandomAccessIterator last,
- StrictWeakOrdering comp,
sort
sorts the elements in[first, last)
into ascending order, meaning that ifi
andj
are any two valid iterators in[first, last)
such thati
precedesj
, 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 bysort
.This version of
sort
compares objects using a function objectcomp
.The following code demonstrates how to sort integers in descending order using the greater<int> comparison operator.
#include <thrust/sort.h> #include <thrust/functional.h> ... const int N = 6; int A[N] = {1, 4, 2, 8, 5, 7}; thrust::sort(A, A + N, ::cuda::std::greater<int>()); // A is now {8, 7, 5, 4, 2, 1};
See also
See also
- Parameters:
first – The beginning of the sequence.
last – The end of the sequence.
comp – Comparison operator.
- Template Parameters:
RandomAccessIterator – is a model of Random Access Iterator,
RandomAccessIterator
is mutable, andRandomAccessIterator's
value_type
is convertible toStrictWeakOrdering's
first argument type and second argument type.StrictWeakOrdering – is a model of Strict Weak Ordering.