Skip to content

Commit 1c4c93f

Browse files
authored
Update documentation for oneTBB 2021.13.0 (#1422)
1 parent 003b086 commit 1c4c93f

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

doc/main/reference/reference.rst

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ It also describes features that are not included in the oneTBB specification.
1919
parallel_for_each_semantics
2020
parallel_sort_ranges_extension
2121
scalable_memory_pools/malloc_replacement_log
22+
rvalue_reduce
2223

2324
Preview features
2425
****************

doc/main/reference/rvalue_reduce.rst

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
.. _rvalue_reduce:
2+
3+
Parallel Reduction for rvalues
4+
==============================
5+
6+
.. contents::
7+
:local:
8+
:depth: 1
9+
10+
Description
11+
***********
12+
13+
|full_name| implementation extends the `ParallelReduceFunc <https://spec.oneapi.io/versions/latest/elements/oneTBB/source/named_requirements/algorithms/par_reduce_func.html>`_ and
14+
`ParallelReduceReduction <https://spec.oneapi.io/versions/latest/elements/oneTBB/source/named_requirements/algorithms/par_reduce_reduction.html>`_
15+
to optimize operating with ``rvalues`` using functional form of ``tbb::parallel_reduce`` and ``tbb::parallel_deterministic_reduce`` algorithms.
16+
17+
API
18+
***
19+
20+
Header
21+
------
22+
23+
.. code:: cpp
24+
25+
#include <oneapi/tbb/parallel_reduce.h>
26+
27+
ParallelReduceFunc Requirements: Pseudo-Signature, Semantics
28+
------------------------------------------------------------
29+
30+
.. cpp:function:: Value Func::operator()(const Range& range, Value&& x) const
31+
32+
or
33+
34+
.. cpp:function:: Value Func::operator()(const Range& range, const Value& x) const
35+
36+
Accumulates the result for a subrange, starting with initial value ``x``. The ``Range`` type must meet the `Range requirements <https://spec.oneapi.io/versions/latest/elements/oneTBB/source/named_requirements/algorithms/range.html>_`.
37+
The ``Value`` type must be the same as a corresponding template parameter for the `parallel_reduce algorithm <https://spec.oneapi.io/versions/latest/elements/oneTBB/source/algorithms/functions/parallel_reduce_func.html>`_.
38+
39+
If both ``rvalue`` and ``lvalue`` forms are provided, the ``rvalue`` is preferred.
40+
41+
ParallelReduceReduction Requirements: Pseudo-Signature, Semantics
42+
-----------------------------------------------------------------
43+
44+
.. cpp:function:: Value Reduction::operator()(Value&& x, Value&& y) const
45+
46+
or
47+
48+
.. cpp:function:: Value Reduction::operator()(const Value& x, const Value& y) const
49+
50+
Combines the ``x`` and ``y`` results. The ``Value`` type must be the same as a corresponding template parameter for the `parallel_reduce algorithm <https://spec.oneapi.io/versions/latest/elements/oneTBB/source/algorithms/functions/parallel_reduce_func.html>`_.
51+
52+
If both ``rvalue`` and ``lvalue`` forms are provided, the ``rvalue`` is preferred.
53+
54+
Example
55+
*******
56+
57+
.. code:: cpp
58+
// C++17
59+
#include <oneapi/tbb/parallel_reduce.h>
60+
#include <oneapi/tbb/blocked_range.h>
61+
#include <vector>
62+
#include <set>
63+
64+
int main() {
65+
std::vector<std::set<int>> sets = ...;
66+
67+
oneapi::tbb::parallel_reduce(oneapi::tbb::blocked_range<size_t>(0, sets.size()),
68+
std::set<int>{}, // identity element - empty set
69+
[&](const oneapi::tbb::blocked_range<size_t>& range, std::set<int>&& value) {
70+
for (size_t i = range.begin(); i < range.end(); ++i) {
71+
// Having value as a non-const rvalue reference allows to efficiently
72+
// transfer nodes from sets[i] without copying/moving the data
73+
value.merge(std::move(sets[i]));
74+
}
75+
return value;
76+
},
77+
[&](std::set<int>&& x, std::set<int>&& y) {
78+
x.merge(std::move(y));
79+
return x;
80+
}
81+
);
82+
}
83+
84+
.. rubric:: See also
85+
86+
* `oneapi::tbb::parallel_reduce specification <https://spec.oneapi.io/versions/latest/elements/oneTBB/source/algorithms/functions/parallel_reduce_func.html>`_
87+
* `oneapi::tbb::parallel_deterministic_reduce specification <https://spec.oneapi.io/versions/latest/elements/oneTBB/source/algorithms/functions/parallel_deterministic_reduce_func.html>`_
88+
* `ParallelReduceFunc specification <https://spec.oneapi.io/versions/latest/elements/oneTBB/source/named_requirements/algorithms/par_reduce_func.html>`_
89+
* `ParallelReduceReduction specification <https://spec.oneapi.io/versions/latest/elements/oneTBB/source/named_requirements/algorithms/par_reduce_reduction.html>`_

0 commit comments

Comments
 (0)