thrust::reduce_into#
Overloads#
reduce_into(exec, first, last, output)#
-
template<typename DerivedPolicy, typename InputIterator, typename OutputIterator>
void thrust::reduce_into( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- InputIterator last,
- OutputIterator output,
reduce_intois a generalization of summation: it computes the sum (or some other binary operation) of all the elements in the range[first, last). This version ofreduce_intouses0as the initial value of the reduction.reduce_intois similar to the C++ Standard Template Library’sstd::accumulate. The primary difference between the two functions is thatstd::accumulateguarantees the order of summation, whilereduce_intorequires associativity of the binary operation to parallelize the reduction.Note that
reduce_intoalso assumes that the binary reduction operator (in this case operator+) is commutative. If the reduction operator is not commutative thenreduce_intoshould not be used. Instead, one could useinclusive_scan(which does not require commutativity) and select the last element of the output array.Unlike
reduce,reduce_intodoes not return the reduction result. Instead, it is written to*output. Thus, whenexecisthrust::cuda::par_nosync, this algorithm does not wait for the work it launches to complete. Additionally, you can usereduce_intoto avoid copying the reduction result from device memory to host memory.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
reduce_intoto compute the sum of a sequence of integers using thethrust::deviceexecution policy for parallelization:#include <thrust/reduce.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> thrust::device_vector<int> data{1, 0, 2, 2, 1, 3}; thrust::device_vector<int> output(1); thrust::reduce_into(thrust::device, data.begin(), data.end(), output.begin()); // output[0] == 9
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the sequence.
last – The end of the sequence.
output – The location the reduction will be written to.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator – is a model of Input Iterator and if
xandyare objects ofInputIterator'svalue_type, thenx + yis defined and is convertible toInputIterator'svalue_type. IfTisInputIterator'svalue_type, thenT(0)is defined.OutputIterator – is a model of Output Iterator and
OutputIterator'svalue_typeis assignable fromInputIterator'svalue_type.
reduce_into(first, last, output)#
-
template<typename InputIterator, typename OutputIterator>
void thrust::reduce_into( - InputIterator first,
- InputIterator last,
- OutputIterator output,
reduce_intois a generalization of summation: it computes the sum (or some other binary operation) of all the elements in the range[first, last). This version ofreduce_intouses0as the initial value of the reduction.reduce_intois similar to the C++ Standard Template Library’sstd::accumulate. The primary difference between the two functions is thatstd::accumulateguarantees the order of summation, whilereduce_intorequires associativity of the binary operation to parallelize the reduction.Note that
reduce_intoalso assumes that the binary reduction operator (in this case operator+) is commutative. If the reduction operator is not commutative thenreduce_intoshould not be used. Instead, one could useinclusive_scan(which does not require commutativity) and select the last element of the output array.Unlike
reduce,reduce_intodoes not return the reduction result. Instead, it is written to*output. Thus, whenexecisthrust::cuda::par_nosync, this algorithm does not wait for the work it launches to complete. Additionally, you can usereduce_intoto avoid copying the reduction result from device memory to host memory.The following code snippet demonstrates how to use
reduce_intoto compute the sum of a sequence of integers.#include <thrust/reduce.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> thrust::device_vector<int> data{1, 0, 2, 2, 1, 3}; thrust::device_vector<int> output(1); thrust::reduce_into(data.begin(), data.end(), output.begin()); // output[0] == 9
See also
- Parameters:
first – The beginning of the sequence.
last – The end of the sequence.
output – The location the reduction will be written to.
- Template Parameters:
InputIterator – is a model of Input Iterator and if
xandyare objects ofInputIterator'svalue_type, thenx + yis defined and is convertible toInputIterator'svalue_type. IfTisInputIterator'svalue_type, thenT(0)is defined.OutputIterator – is a model of Output Iterator and
OutputIterator'svalue_typeis assignable fromInputIterator'svalue_type.
reduce_into(exec, first, last, output, init)#
-
template<typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename T>
void thrust::reduce_into( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- InputIterator last,
- OutputIterator output,
- T init,
reduce_intois a generalization of summation: it computes the sum (or some other binary operation) of all the elements in the range[first, last). This version ofreduce_intousesinitas the initial value of the reduction.reduce_intois similar to the C++ Standard Template Library’sstd::accumulate. The primary difference between the two functions is thatstd::accumulateguarantees the order of summation, whilereduce_intorequires associativity of the binary operation to parallelize the reduction.Note that
reduce_intoalso assumes that the binary reduction operator (in this case operator+) is commutative. If the reduction operator is not commutative thenreduce_intoshould not be used. Instead, one could useinclusive_scan(which does not require commutativity) and select the last element of the output array.Unlike
reduce,reduce_intodoes not return the reduction result. Instead, it is written to*output. Thus, whenexecisthrust::cuda::par_nosync, this algorithm does not wait for the work it launches to complete. Additionally, you can usereduce_intoto avoid copying the reduction result from device memory to host memory.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
reduce_intoto compute the sum of a sequence of integers including an initialization value using thethrust::deviceexecution policy for parallelization:#include <thrust/reduce.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> thrust::device_vector<int> data{1, 0, 2, 2, 1, 3}; thrust::device_vector<int> output(1); thrust::reduce_into(thrust::device, data.begin(), data.end(), output.begin(), 1); // output[0] == 10
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the input sequence.
last – The end of the input sequence.
output – The location the reduction will be written to.
init – The initial value.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator – is a model of Input Iterator and if
xandyare objects ofInputIterator'svalue_type, thenx + yis defined and is convertible toT.OutputIterator – is a model of Output Iterator and
OutputIterator'svalue_typeis assignable fromT.T – is convertible to
InputIterator'svalue_type.
reduce_into(first, last, output, init)#
-
template<typename InputIterator, typename OutputIterator, typename T>
void thrust::reduce_into( - InputIterator first,
- InputIterator last,
- OutputIterator output,
- T init,
reduce_intois a generalization of summation: it computes the sum (or some other binary operation) of all the elements in the range[first, last). This version ofreduce_intousesinitas the initial value of the reduction.reduce_intois similar to the C++ Standard Template Library’sstd::accumulate. The primary difference between the two functions is thatstd::accumulateguarantees the order of summation, whilereduce_intorequires associativity of the binary operation to parallelize the reduction.Note that
reduce_intoalso assumes that the binary reduction operator (in this case operator+) is commutative. If the reduction operator is not commutative thenreduce_intoshould not be used. Instead, one could useinclusive_scan(which does not require commutativity) and select the last element of the output array.Unlike
reduce,reduce_intodoes not return the reduction result. Instead, it is written to*output. Thus, whenexecisthrust::cuda::par_nosync, this algorithm does not wait for the work it launches to complete. Additionally, you can usereduce_intoto avoid copying the reduction result from device memory to host memory.The following code snippet demonstrates how to use
reduce_intoto compute the sum of a sequence of integers including an initialization value.#include <thrust/reduce.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> thrust::device_vector<int> data{1, 0, 2, 2, 1, 3}; thrust::device_vector<int> output(1); thrust::reduce_into(data.begin(), data.end(), output.begin(), 1); // output[0] == 10
See also
- Parameters:
first – The beginning of the input sequence.
last – The end of the input sequence.
output – The location the reduction will be written to.
init – The initial value.
- Template Parameters:
InputIterator – is a model of Input Iterator and if
xandyare objects ofInputIterator'svalue_type, thenx + yis defined and is convertible toT.OutputIterator – is a model of Output Iterator and
OutputIterator'svalue_typeis assignable fromT.T – is convertible to
InputIterator'svalue_type.
reduce_into(exec, first, last, output, init, binary_op)#
-
template<typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename T, typename BinaryFunction>
void thrust::reduce_into( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- InputIterator last,
- OutputIterator output,
- T init,
- BinaryFunction binary_op,
reduce_intois a generalization of summation: it computes the sum (or some other binary operation) of all the elements in the range[first, last). This version ofreduce_intousesinitas the initial value of the reduction andbinary_opas the binary function used for summation.reduce_intois similar to the C++ Standard Template Library’sstd::accumulate. The primary difference between the two functions is thatstd::accumulateguarantees the order of summation, whilereduce_intorequires associativity ofbinary_opto parallelize the reduction.Note that
reduce_intoalso assumes that the binary reduction operator (in this casebinary_op) is commutative. If the reduction operator is not commutative thenreduce_intoshould not be used. Instead, one could useinclusive_scan(which does not require commutativity) and select the last element of the output array.Unlike
reduce,reduce_intodoes not return the reduction result. Instead, it is written to*output. Thus, whenexecisthrust::cuda::par_nosync, this algorithm does not wait for the work it launches to complete. Additionally, you can usereduce_intoto avoid copying the reduction result from device memory to host memory.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
reduce_intoto compute the maximum value of a sequence of integers using thethrust::deviceexecution policy for parallelization:#include <cuda/functional> #include <thrust/reduce.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> thrust::device_vector<int> data{1, 0, 2, 2, 1, 3}; thrust::device_vector<int> output(1); thrust::reduce_into(thrust::device, data.begin(), data.end(), output.begin(), -1, cuda::maximum{}); // output[0] == 3
See also
See also
See also
transform_reduce_into
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the input sequence.
last – The end of the input sequence.
output – The location the reduction will be written to.
init – The initial value.
binary_op – The binary function used to ‘sum’ values.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator – is a model of Input Iterator and
InputIterator'svalue_typeis convertible toT.OutputIterator – is a model of Output Iterator and
OutputIterator'svalue_typeis assignable fromT.T – is a model of Assignable, and is convertible to
BinaryFunction'sfirst and second argument type.BinaryFunction – The function’s return type must be convertible to
OutputType.
- Returns:
The result of the reduction.
reduce_into(first, last, output, init, binary_op)#
-
template<typename InputIterator, typename OutputIterator, typename T, typename BinaryFunction>
void thrust::reduce_into( - InputIterator first,
- InputIterator last,
- OutputIterator output,
- T init,
- BinaryFunction binary_op,
reduce_intois a generalization of summation: it computes the sum (or some other binary operation) of all the elements in the range[first, last). This version ofreduce_intousesinitas the initial value of the reduction andbinary_opas the binary function used for summation.reduce_intois similar to the C++ Standard Template Library’sstd::accumulate. The primary difference between the two functions is thatstd::accumulateguarantees the order of summation, whilereduce_intorequires associativity ofbinary_opto parallelize the reduction.Note that
reduce_intoalso assumes that the binary reduction operator (in this casebinary_op) is commutative. If the reduction operator is not commutative thenthrust::reduce_intoshould not be used. Instead, one could useinclusive_scan(which does not require commutativity) and select the last element of the output array.The following code snippet demonstrates how to use
reduce_intoto compute the maximum value of a sequence of integers.#include <cuda/functional> #include <thrust/reduce.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> thrust::device_vector<int> data{1, 0, 2, 2, 1, 3}; thrust::device_vector<int> output(1); thrust::reduce_into(data.begin(), data.end(), output.begin(), -1, cuda::maximum{}); // output[0] == 3
See also
See also
See also
transform_reduce_into
- Parameters:
first – The beginning of the input sequence.
last – The end of the input sequence.
output – An output iterator to write the result to.
init – The initial value.
binary_op – The binary function used to ‘sum’ values.
- Template Parameters:
InputIterator – is a model of Input Iterator and
InputIterator'svalue_typeis convertible toT.OutputIterator – is a model of Output Iterator and
OutputIterator'svalue_typeis assignable fromT.T – is a model of Assignable, and is convertible to
BinaryFunction'sfirst and second argument type.BinaryFunction – The function’s return type must be convertible to
OutputType.
- Returns:
The result of the reduction.