-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into task_group_extensions
# Conflicts: # source/elements/oneTBB/source/task_scheduler/task_arena/task_arena_cls.rst
- Loading branch information
Showing
157 changed files
with
2,666 additions
and
2,320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
source/elements/oneTBB/source/algorithms/examples/blocked_rangeNd_example.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...ce/elements/oneTBB/source/algorithms/functions/collaborative_call_once_func.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
.. SPDX-FileCopyrightText: 2021 Intel Corporation | ||
.. | ||
.. SPDX-License-Identifier: CC-BY-4.0 | ||
======================= | ||
collaborative_call_once | ||
======================= | ||
**[algorithms.collaborative_call_once]** | ||
|
||
Function template that executes function exactly once. | ||
|
||
.. code:: cpp | ||
// Defined in header <oneapi/tbb/collaborative_call_once.h> | ||
namespace oneapi { | ||
namespace tbb { | ||
template<typename Func, typename... Args> | ||
void collaborative_call_once(collaborative_once_flag& flag, Func&& func, Args&&... args); | ||
} // namespace tbb | ||
} // namespace oneapi | ||
Requirements: | ||
|
||
* ``Func`` type must meet the ``Function Objects`` | ||
requirements from the [function.objects] section of the ISO C++ Standard section. | ||
|
||
Executes the ``Func`` object only once, even if it is called concurrently. It allows other threads | ||
blocked on the same ``collaborative_once_flag`` to join oneTBB parallel construction called | ||
within the ``Func`` object. | ||
|
||
In case of the exception thrown from the ``Func`` object, the thread calling the ``Func`` object | ||
receives this exception. One of the threads blocked on the same ``collaborative_once_flag`` | ||
calls the ``Func`` object again. | ||
|
||
collaborative_once_flag Class | ||
----------------------------- | ||
|
||
.. toctree:: | ||
:titlesonly: | ||
|
||
collaborative_once_flag_cls.rst | ||
|
||
|
||
Example | ||
------- | ||
|
||
The following example shows a class in which the "Lazy initialization" pattern is implemented on | ||
the "cachedProperty" field. | ||
|
||
|
||
.. code:: cpp | ||
#include "oneapi/tbb/collaborative_call_once.h" | ||
extern double foo(int i); | ||
class LazyData { | ||
oneapi::tbb::collaborative_once_flag flag; | ||
double cachedProperty; | ||
public: | ||
double getProperty() { | ||
oneapi::tbb::collaborative_call_once(flag, [&] { | ||
// serial part | ||
double result{}; | ||
// parallel part where threads can collaborate | ||
result = oneapi::tbb::parallel_reduce(oneapi::tbb::blocked_range<int>(0, 1000), | ||
[&] (auto r, double r) { | ||
for(int i = r.begin(); i != r.end(); ++i) { | ||
r += foo(i); | ||
} | ||
return r; | ||
}, | ||
std::plus<double, double>{} | ||
); | ||
// continue serial part | ||
cachedProperty = result; | ||
}); | ||
return cachedProperty; | ||
} | ||
}; |
Oops, something went wrong.