# parallel_reduce Function

**Visual Studio 2013**

Computes the sum of all elements in a specified range by computing successive partial sums, or computes the result of successive partial results similarly obtained from using a specified binary operation other than sum, in parallel. **parallel_reduce** is semantically similar to **std::accumulate**, except that it requires the binary operation to be associative, and requires an identity value instead of an initial value.

template< typename _Forward_iterator > inline typename std::iterator_traits<_Forward_iterator>::value_type parallel_reduce( _Forward_iterator_Begin, _Forward_iterator_End, const typename std::iterator_traits<_Forward_iterator>::value_type &_Identity ); template< typename _Forward_iterator, typename _Sym_reduce_fun > inline typename std::iterator_traits<_Forward_iterator>::value_type parallel_reduce( _Forward_iterator_Begin, _Forward_iterator_End, const typename std::iterator_traits<_Forward_iterator>::value_type &_Identity, _Sym_reduce_fun_Sym_fun ); template< typename _Reduce_type, typename _Forward_iterator, typename _Range_reduce_fun, typename _Sym_reduce_fun > inline _Reduce_type parallel_reduce( _Forward_iterator_Begin, _Forward_iterator_End, const _Reduce_type& _Identity, const _Range_reduce_fun &_Range_fun, const _Sym_reduce_fun &_Sym_fun );

To perform a parallel reduction, the function divides the range into chunks based on the number of workers available to the underlying scheduler. The reduction takes place in two phases, the first phase performs a reduction within each chunk, and the second phase performs a reduction between the partial results from each chunk.

The first overload requires that the iterator's **value_type**, **T**, be the same as the identity value type as well as the reduction result type. The element type T must provide the operator **T T::operator + (T)** to reduce elements in each chunk. The same operator is used in the second phase as well.

The second overload also requires that the iterator's **value_type** be the same as the identity value type as well as the reduction result type. The supplied binary operator _Sym_fun is used in both reduction phases, with the identity value as the initial value for the first phase.

For the third overload, the identity value type must be the same as the reduction result type, but the iterator's **value_type** may be different from both. The range reduction function _Range_fun is used in the first phase with the identity value as the initial value, and the binary function _Sym_reduce_fun is applied to sub results in the second phase.