thrust::uninitialized_copy_n#
Overloads#
uninitialized_copy_n(exec, first, n, result)#
-
template<typename DerivedPolicy, typename InputIterator, typename Size, typename ForwardIterator>
ForwardIterator thrust::uninitialized_copy_n( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- Size n,
- ForwardIterator result,
In
thrust, the functionthrust::device_newallocates 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 + n)points to uninitialized memory, thenuninitialized_copy_ncreates a copy of[first, first + n)in that range. That is, for each iteratoriin the input,uninitialized_copy_ncreates a copy of*iin the location pointed to by the corresponding iterator in the output range byInputIterator'svalue_type'scopy constructor with *i as its argument.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
uninitialized_copyto initialize a range of uninitialized memory using thethrust::deviceexecution policy for parallelization:#include <thrust/uninitialized_copy.h> #include <thrust/device_malloc.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> struct Int { __host__ __device__ Int(int x) : val(x) {} int val; }; ... const int N = 137; Int val(46); thrust::device_vector<Int> input(N, val); thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N); thrust::uninitialized_copy_n(thrust::device, input.begin(), N, array); // Int x = array[i]; // x.val == 46 for all 0 <= i < N
See also
See also
See also
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The first element of the input range to copy from.
n – The number of elements to copy.
result – The first element of the output range to copy to.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator – is a model of Input Iterator.
Size – is an integral type.
ForwardIterator – is a model of Forward Iterator,
ForwardIteratoris mutable, andForwardIterator'svalue_typehas a constructor that takes a single argument whose type isInputIterator'svalue_type.
- Returns:
An iterator pointing to the last element of the output range.
- Pre:
firstmay equalresult, but the range[first, first + n)and the range[result, result + n)shall not overlap otherwise.
uninitialized_copy_n(first, n, result)#
-
template<typename InputIterator, typename Size, typename ForwardIterator>
ForwardIterator thrust::uninitialized_copy_n( - InputIterator first,
- Size n,
- ForwardIterator result,
In
thrust, the functionthrust::device_newallocates 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 + n)points to uninitialized memory, thenuninitialized_copy_ncreates a copy of[first, first + n)in that range. That is, for each iteratoriin the input,uninitialized_copy_ncreates a copy of*iin the location pointed to by the corresponding iterator in the output range byInputIterator'svalue_type'scopy constructor with *i as its argument.The following code snippet demonstrates how to use
uninitialized_copyto initialize a range of uninitialized memory.#include <thrust/uninitialized_copy.h> #include <thrust/device_malloc.h> #include <thrust/device_vector.h> struct Int { __host__ __device__ Int(int x) : val(x) {} int val; }; ... const int N = 137; Int val(46); thrust::device_vector<Int> input(N, val); thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N); thrust::uninitialized_copy_n(input.begin(), N, array); // Int x = array[i]; // x.val == 46 for all 0 <= i < N
See also
See also
See also
See also
See also
- Parameters:
first – The first element of the input range to copy from.
n – The number of elements to copy.
result – The first element of the output range to copy to.
- Template Parameters:
InputIterator – is a model of Input Iterator.
Size – is an integral type.
ForwardIterator – is a model of Forward Iterator,
ForwardIteratoris mutable, andForwardIterator'svalue_typehas a constructor that takes a single argument whose type isInputIterator'svalue_type.
- Returns:
An iterator pointing to the last element of the output range.
- Pre:
firstmay equalresult, but the range[first, first + n)and the range[result, result + n)shall not overlap otherwise.