From 1c4c93fc5398c4a1acb3492c02db4699f3048dea Mon Sep 17 00:00:00 2001 From: Olga Malysheva Date: Wed, 26 Jun 2024 15:27:04 +0200 Subject: [PATCH] Update documentation for oneTBB 2021.13.0 (#1422) --- doc/main/reference/reference.rst | 1 + doc/main/reference/rvalue_reduce.rst | 89 ++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 doc/main/reference/rvalue_reduce.rst diff --git a/doc/main/reference/reference.rst b/doc/main/reference/reference.rst index ec9fb1e1f5..833a50ee70 100644 --- a/doc/main/reference/reference.rst +++ b/doc/main/reference/reference.rst @@ -19,6 +19,7 @@ It also describes features that are not included in the oneTBB specification. parallel_for_each_semantics parallel_sort_ranges_extension scalable_memory_pools/malloc_replacement_log + rvalue_reduce Preview features **************** diff --git a/doc/main/reference/rvalue_reduce.rst b/doc/main/reference/rvalue_reduce.rst new file mode 100644 index 0000000000..53880952aa --- /dev/null +++ b/doc/main/reference/rvalue_reduce.rst @@ -0,0 +1,89 @@ +.. _rvalue_reduce: + +Parallel Reduction for rvalues +============================== + +.. contents:: + :local: + :depth: 1 + +Description +*********** + +|full_name| implementation extends the `ParallelReduceFunc `_ and +`ParallelReduceReduction `_ +to optimize operating with ``rvalues`` using functional form of ``tbb::parallel_reduce`` and ``tbb::parallel_deterministic_reduce`` algorithms. + +API +*** + +Header +------ + +.. code:: cpp + + #include + +ParallelReduceFunc Requirements: Pseudo-Signature, Semantics +------------------------------------------------------------ + +.. cpp:function:: Value Func::operator()(const Range& range, Value&& x) const + +or + +.. cpp:function:: Value Func::operator()(const Range& range, const Value& x) const + + Accumulates the result for a subrange, starting with initial value ``x``. The ``Range`` type must meet the `Range requirements _`. + The ``Value`` type must be the same as a corresponding template parameter for the `parallel_reduce algorithm `_. + + If both ``rvalue`` and ``lvalue`` forms are provided, the ``rvalue`` is preferred. + +ParallelReduceReduction Requirements: Pseudo-Signature, Semantics +----------------------------------------------------------------- + +.. cpp:function:: Value Reduction::operator()(Value&& x, Value&& y) const + +or + +.. cpp:function:: Value Reduction::operator()(const Value& x, const Value& y) const + + Combines the ``x`` and ``y`` results. The ``Value`` type must be the same as a corresponding template parameter for the `parallel_reduce algorithm `_. + + If both ``rvalue`` and ``lvalue`` forms are provided, the ``rvalue`` is preferred. + +Example +******* + +.. code:: cpp + // C++17 + #include + #include + #include + #include + + int main() { + std::vector> sets = ...; + + oneapi::tbb::parallel_reduce(oneapi::tbb::blocked_range(0, sets.size()), + std::set{}, // identity element - empty set + [&](const oneapi::tbb::blocked_range& range, std::set&& value) { + for (size_t i = range.begin(); i < range.end(); ++i) { + // Having value as a non-const rvalue reference allows to efficiently + // transfer nodes from sets[i] without copying/moving the data + value.merge(std::move(sets[i])); + } + return value; + }, + [&](std::set&& x, std::set&& y) { + x.merge(std::move(y)); + return x; + } + ); + } + +.. rubric:: See also + +* `oneapi::tbb::parallel_reduce specification `_ +* `oneapi::tbb::parallel_deterministic_reduce specification `_ +* `ParallelReduceFunc specification `_ +* `ParallelReduceReduction specification `_