thrust
Modules | Functions
Copying

Modules

 Gathering
 
 Scattering
 

Functions

template<typename DerivedPolicy , typename InputIterator , typename OutputIterator >
__host__ __device__ OutputIterator thrust::copy (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, OutputIterator result)
 
template<typename DerivedPolicy , typename InputIterator , typename Size , typename OutputIterator >
__host__ __device__ OutputIterator thrust::copy_n (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, Size n, OutputIterator result)
 
template<typename InputIterator , typename OutputIterator >
OutputIterator thrust::copy (InputIterator first, InputIterator last, OutputIterator result)
 
template<typename InputIterator , typename Size , typename OutputIterator >
OutputIterator thrust::copy_n (InputIterator first, Size n, OutputIterator result)
 
template<typename DerivedPolicy , typename ForwardIterator1 , typename ForwardIterator2 >
__host__ __device__
ForwardIterator2 
thrust::swap_ranges (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2)
 
template<typename ForwardIterator1 , typename ForwardIterator2 >
ForwardIterator2 thrust::swap_ranges (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2)
 
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)
 
template<typename InputIterator , typename ForwardIterator >
ForwardIterator thrust::uninitialized_copy (InputIterator first, InputIterator last, ForwardIterator result)
 
template<typename DerivedPolicy , typename InputIterator , typename Size , typename ForwardIterator >
__host__ __device__ ForwardIterator thrust::uninitialized_copy_n (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, Size n, ForwardIterator result)
 
template<typename InputIterator , typename Size , typename ForwardIterator >
ForwardIterator thrust::uninitialized_copy_n (InputIterator first, Size n, ForwardIterator result)
 

Detailed Description

Function Documentation

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

copy copies elements from the range [first, last) to the range [result, result + (last - first)). That is, it performs the assignments *result = *first, *(result + 1) = *(first + 1), and so on. Generally, for every integer n from 0 to last - first, copy performs the assignment *(result + n) = *(first + n). Unlike std::copy, copy offers no guarantee on order of operation. As a result, calling copy with overlapping source and destination ranges has undefined behavior.

The return value is result + (last - first).

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the sequence to copy.
lastThe end of the sequence to copy.
resultThe destination sequence.
Returns
The end of the destination sequence.
See Also
http://www.sgi.com/tech/stl/copy.html
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratormust be a model of Input Iterator and InputIterator's value_type must be convertible to OutputIterator's value_type.
OutputIteratormust be a model of Output Iterator.
Precondition
result may be equal to first, but result shall not be in the range [first, last) otherwise.

The following code snippet demonstrates how to use copy to copy from one range to another using the thrust::device parallelization policy:

#include <thrust/copy.h>
...
thrust::device_vector<int> vec0(100);
...
thrust::copy(thrust::device, vec0.begin(), vec0.end(), vec1.begin());
// vec1 is now a copy of vec0
template<typename InputIterator , typename OutputIterator >
OutputIterator thrust::copy ( InputIterator  first,
InputIterator  last,
OutputIterator  result 
)

copy copies elements from the range [first, last) to the range [result, result + (last - first)). That is, it performs the assignments *result = *first, *(result + 1) = *(first + 1), and so on. Generally, for every integer n from 0 to last - first, copy performs the assignment *(result + n) = *(first + n). Unlike std::copy, copy offers no guarantee on order of operation. As a result, calling copy with overlapping source and destination ranges has undefined behavior.

The return value is result + (last - first).

Parameters
firstThe beginning of the sequence to copy.
lastThe end of the sequence to copy.
resultThe destination sequence.
Returns
The end of the destination sequence.
See Also
http://www.sgi.com/tech/stl/copy.html
Template Parameters
InputIteratormust be a model of Input Iterator and InputIterator's value_type must be convertible to OutputIterator's value_type.
OutputIteratormust be a model of Output Iterator.
Precondition
result may be equal to first, but result shall not be in the range [first, last) otherwise.

The following code snippet demonstrates how to use copy to copy from one range to another.

#include <thrust/copy.h>
...
thrust::device_vector<int> vec0(100);
...
thrust::copy(vec0.begin(), vec0.end(),
vec1.begin());
// vec1 is now a copy of vec0
template<typename DerivedPolicy , typename InputIterator , typename Size , typename OutputIterator >
__host__ __device__ OutputIterator thrust::copy_n ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
Size  n,
OutputIterator  result 
)

copy_n copies elements from the range [first, first + n) to the range [result, result + n). That is, it performs the assignments *result = *first, *(result + 1) = *(first + 1), and so on. Generally, for every integer i from 0 to n, copy performs the assignment *(result + i) = *(first + i). Unlike std::copy_n, copy_n offers no guarantee on order of operation. As a result, calling copy_n with overlapping source and destination ranges has undefined behavior.

The return value is result + n.

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the range to copy.
nThe number of elements to copy.
resultThe beginning destination range.
Returns
The end of the destination range.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratormust be a model of Input Iterator and InputIterator's value_type must be convertible to OutputIterator's value_type.
Sizeis an integral type.
OutputIteratormust be a model of Output Iterator.
Precondition
result may be equal to first, but result shall not be in the range [first, first + n) otherwise.

The following code snippet demonstrates how to use copy to copy from one range to another using the thrust::device parallelization policy:

#include <thrust/copy.h>
...
size_t n = 100;
...
thrust::copy_n(thrust::device, vec0.begin(), n, vec1.begin());
// vec1 is now a copy of vec0
See Also
http://www.sgi.com/tech/stl/copy_n.html
thrust::copy
template<typename InputIterator , typename Size , typename OutputIterator >
OutputIterator thrust::copy_n ( InputIterator  first,
Size  n,
OutputIterator  result 
)

copy_n copies elements from the range [first, first + n) to the range [result, result + n). That is, it performs the assignments *result = *first, *(result + 1) = *(first + 1), and so on. Generally, for every integer i from 0 to n, copy performs the assignment *(result + i) = *(first + i). Unlike std::copy_n, copy_n offers no guarantee on order of operation. As a result, calling copy_n with overlapping source and destination ranges has undefined behavior.

The return value is result + n.

Parameters
firstThe beginning of the range to copy.
nThe number of elements to copy.
resultThe beginning destination range.
Returns
The end of the destination range.
Template Parameters
InputIteratormust be a model of Input Iterator and InputIterator's value_type must be convertible to OutputIterator's value_type.
Sizeis an integral type.
OutputIteratormust be a model of Output Iterator.
Precondition
result may be equal to first, but result shall not be in the range [first, first + n) otherwise.

The following code snippet demonstrates how to use copy to copy from one range to another.

#include <thrust/copy.h>
...
size_t n = 100;
...
thrust::copy_n(vec0.begin(), n, vec1.begin());
// vec1 is now a copy of vec0
See Also
http://www.sgi.com/tech/stl/copy_n.html
thrust::copy
template<typename DerivedPolicy , typename ForwardIterator1 , typename ForwardIterator2 >
__host__ __device__ ForwardIterator2 thrust::swap_ranges ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator1  first1,
ForwardIterator1  last1,
ForwardIterator2  first2 
)

swap_ranges swaps each of the elements in the range [first1, last1) with the corresponding element in the range [first2, first2 + (last1 - first1)). That is, for each integer n such that 0 <= n < (last1 - first1), it swaps *(first1 + n) and *(first2 + n). The return value is first2 + (last1 - first1).

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

Parameters
execThe execution policy to use for parallelization.
first1The beginning of the first sequence to swap.
last1One position past the last element of the first sequence to swap.
first2The beginning of the second sequence to swap.
Returns
An iterator pointing to one position past the last element of the second sequence to swap.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIterator1is a model of Forward Iterator, and ForwardIterator1's value_type must be convertible to ForwardIterator2's value_type.
ForwardIterator2is a model of Forward Iterator, and ForwardIterator2's value_type must be convertible to ForwardIterator1's value_type.
Precondition
first1 may equal first2, but the range [first1, last1) shall not overlap the range [first2, first2 + (last1 - first1)) otherwise.

The following code snippet demonstrates how to use swap_ranges to swap the contents of two thrust::device_vectors using the thrust::device execution policy for parallelization:

#include <thrust/swap.h>
...
thrust::device_vector<int> v1(2), v2(2);
v1[0] = 1;
v1[1] = 2;
v2[0] = 3;
v2[1] = 4;
thrust::swap_ranges(thrust::device, v1.begin(), v1.end(), v2.begin());
// v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2
See Also
http://www.sgi.com/tech/stl/swap_ranges.html
swap
template<typename ForwardIterator1 , typename ForwardIterator2 >
ForwardIterator2 thrust::swap_ranges ( ForwardIterator1  first1,
ForwardIterator1  last1,
ForwardIterator2  first2 
)

swap_ranges swaps each of the elements in the range [first1, last1) with the corresponding element in the range [first2, first2 + (last1 - first1)). That is, for each integer n such that 0 <= n < (last1 - first1), it swaps *(first1 + n) and *(first2 + n). The return value is first2 + (last1 - first1).

Parameters
first1The beginning of the first sequence to swap.
last1One position past the last element of the first sequence to swap.
first2The beginning of the second sequence to swap.
Returns
An iterator pointing to one position past the last element of the second sequence to swap.
Template Parameters
ForwardIterator1is a model of Forward Iterator, and ForwardIterator1's value_type must be convertible to ForwardIterator2's value_type.
ForwardIterator2is a model of Forward Iterator, and ForwardIterator2's value_type must be convertible to ForwardIterator1's value_type.
Precondition
first1 may equal first2, but the range [first1, last1) shall not overlap the range [first2, first2 + (last1 - first1)) otherwise.

The following code snippet demonstrates how to use swap_ranges to swap the contents of two thrust::device_vectors.

#include <thrust/swap.h>
...
thrust::device_vector<int> v1(2), v2(2);
v1[0] = 1;
v1[1] = 2;
v2[0] = 3;
v2[1] = 4;
thrust::swap_ranges(v1.begin(), v1.end(), v2.begin());
// v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2
See Also
http://www.sgi.com/tech/stl/swap_ranges.html
swap
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
template<typename InputIterator , typename ForwardIterator >
ForwardIterator thrust::uninitialized_copy ( 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.

Parameters
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
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.

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(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
template<typename DerivedPolicy , typename InputIterator , typename Size , typename ForwardIterator >
__host__ __device__ ForwardIterator thrust::uninitialized_copy_n ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
Size  n,
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 + n) points to uninitialized memory, then uninitialized_copy_n creates a copy of [first, first + n) in that range. That is, for each iterator i in the input, uninitialized_copy_n creates a copy of *i in the location pointed to by the corresponding iterator in the output range by InputIterator'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.
nThe number of elements to copy.
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.
Sizeis an integral type.
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, first + n) and the range [result, result + n) 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_n(thrust::device, input.begin(), N, array);
// Int x = array[i];
// x.val == 46 for all 0 <= i < N
See Also
http://www.sgi.com/tech/stl/uninitialized_copy.html
uninitialized_copy
copy
uninitialized_fill
device_new
device_malloc
template<typename InputIterator , typename Size , typename ForwardIterator >
ForwardIterator thrust::uninitialized_copy_n ( InputIterator  first,
Size  n,
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 + n) points to uninitialized memory, then uninitialized_copy_n creates a copy of [first, first + n) in that range. That is, for each iterator i in the input, uninitialized_copy_n creates a copy of *i in the location pointed to by the corresponding iterator in the output range by InputIterator's value_type's copy constructor with *i as its argument.

Parameters
firstThe first element of the input range to copy from.
nThe number of elements to copy.
resultThe first element of the output range to copy to.
Returns
An iterator pointing to the last element of the output range.
Template Parameters
InputIteratoris a model of Input Iterator.
Sizeis an integral type.
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, first + n) and the range [result, result + n) shall not overlap otherwise.

The following code snippet demonstrates how to use uninitialized_copy to initialize a range of uninitialized memory.

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_n(input.begin(), N, array);
// Int x = array[i];
// x.val == 46 for all 0 <= i < N
See Also
http://www.sgi.com/tech/stl/uninitialized_copy.html
uninitialized_copy
copy
uninitialized_fill
device_new
device_malloc