thrust

◆ uninitialized_copy() [1/2]

template<typename DerivedPolicy , typename InputIterator , typename ForwardIterator >
__host__ __device__ ForwardIterator thrust::uninitialized_copy ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
InputIterator  last,
ForwardIterator  result 
)

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 [result, result + (last - first)) points to uninitialized memory, then uninitialized_copy creates a copy of [first, last) in that range. That is, for each iterator i in the input, uninitialized_copy creates a copy of *i in the location pointed to by the corresponding iterator in the output range by ForwardIterator's value_type's copy constructor with *i as its argument.

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

Parameters
execThe execution policy to use for parallelization.
firstThe first element of the input range to copy from.
lastThe last element of the input range to copy from.
resultThe first element of the output range to copy to.
Returns
An iterator pointing to the last element of the output range.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratoris a model of Input Iterator.
ForwardIteratoris a model of Forward Iterator, ForwardIterator is mutable, and ForwardIterator's value_type has a constructor that takes a single argument whose type is InputIterator's value_type.
Precondition
first may equal result, but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise.

The following code snippet demonstrates how to use uninitialized_copy 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);
thrust::uninitialized_copy(thrust::device, input.begin(), input.end(), array);
// Int x = array[i];
// x.val == 46 for all 0 <= i < N
See also
http://www.sgi.com/tech/stl/uninitialized_copy.html
copy
uninitialized_fill
device_new
device_malloc