thrust

◆ tabulate() [1/2]

template<typename DerivedPolicy , typename ForwardIterator , typename UnaryOperation >
__host__ __device__ void thrust::tabulate ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
UnaryOperation  unary_op 
)

tabulate fills the range [first, last) with the value of a function applied to each element's index.

For each iterator i in the range [first, last), tabulate performs the assignment *i = unary_op(i - first).

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the range.
lastThe end of the range.
unary_opThe unary operation to apply.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable, and if x and y are objects of ForwardIterator's value_type, then x + y is defined, and if T is ForwardIterator's value_type, then T(0) is defined.
UnaryOperationis a model of Unary Function and UnaryFunction's result_type is convertible to OutputIterator's value_type.

The following code snippet demonstrates how to use tabulate to generate the first n non-positive integers using the thrust::host execution policy for parallelization:

...
const int N = 10;
int A[N];
// A is now {0, -1, -2, -3, -4, -5, -6, -7, -8, -9}
See also
thrust::fill
thrust::generate
thrust::sequence