thrust

◆ uninitialized_fill_n() [1/2]

template<typename DerivedPolicy , typename ForwardIterator , typename Size , typename T >
__host__ __device__ ForwardIterator thrust::uninitialized_fill_n ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
Size  n,
const T &  x 
)

In thrust, the function thrust::device_new allocates memory for an object and then creates an object at that location by calling a constructor. Occasionally, however, it is useful to separate those two operations. If each iterator in the range [first, first+n) points to uninitialized memory, then uninitialized_fill creates copies of x in that range. That is, for each iterator i in the range [first, first+n), uninitialized_fill creates a copy of x in the location pointed to i by calling ForwardIterator's value_type's copy constructor.

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

Parameters
execThe execution policy to use for parallelization.
firstThe first element of the range of interest.
nThe size of the range of interest.
xThe value to use as the exemplar of the copy constructor.
Returns
first+n
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, ForwardIterator is mutable, and ForwardIterator's value_type has a constructor that takes a single argument of type T.

The following code snippet demonstrates how to use uninitialized_fill to initialize a range of uninitialized memory using the thrust::device execution policy for parallelization:

struct Int
{
__host__ __device__
Int(int x) : val(x) {}
int val;
};
...
const int N = 137;
Int val(46);
thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N);
// Int x = array[i];
// x.val == 46 for all 0 <= i < N
See also
http://www.sgi.com/tech/stl/uninitialized_fill.html
uninitialized_fill
fill
uninitialized_copy_n
device_new
device_malloc