thrust::uninitialized_fill#
Overloads#
uninitialized_fill(exec, first, last, x)#
-
template<typename DerivedPolicy, typename ForwardIterator, typename T>
void thrust::uninitialized_fill( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- const T &x,
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[first, last)points to uninitialized memory, thenuninitialized_fillcreates copies ofxin that range. That is, for each iteratoriin the range[first, last),uninitialized_fillcreates a copy ofxin the location pointed toiby callingForwardIterator'svalue_type'scopy constructor.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
uninitialized_fillto initialize a range of uninitialized memory using thethrust::deviceexecution policy for parallelization:#include <thrust/uninitialized_fill.h> #include <thrust/device_malloc.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_ptr<Int> array = thrust::device_malloc<Int>(N); thrust::uninitialized_fill(thrust::device, array, array + N, val); // 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 range of interest.
last – The last element of the range of interest.
x – The value to use as the exemplar of the copy constructor.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator,
ForwardIteratoris mutable, andForwardIterator'svalue_typehas a constructor that takes a single argument of typeT.
uninitialized_fill(first, last, x)#
-
template<typename ForwardIterator, typename T>
void thrust::uninitialized_fill( - ForwardIterator first,
- ForwardIterator last,
- const T &x,
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[first, last)points to uninitialized memory, thenuninitialized_fillcreates copies ofxin that range. That is, for each iteratoriin the range[first, last),uninitialized_fillcreates a copy ofxin the location pointed toiby callingForwardIterator'svalue_type'scopy constructor.The following code snippet demonstrates how to use
uninitialized_fillto initialize a range of uninitialized memory.#include <thrust/uninitialized_fill.h> #include <thrust/device_malloc.h> 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_fill(array, array + N, val); // 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 range of interest.
last – The last element of the range of interest.
x – The value to use as the exemplar of the copy constructor.
- Template Parameters:
ForwardIterator – is a model of Forward Iterator,
ForwardIteratoris mutable, andForwardIterator'svalue_typehas a constructor that takes a single argument of typeT.