Skip to content

Commit 84dd926

Browse files
committed
Merge remote-tracking branch 'upstream/main' into task_group_extensions
# Conflicts: # source/elements/oneTBB/source/task_scheduler/task_arena/task_arena_cls.rst
2 parents 25d14e7 + 247ef9c commit 84dd926

File tree

157 files changed

+2666
-2320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+2666
-2320
lines changed

source/elements/oneTBB/source/algorithms.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. SPDX-FileCopyrightText: 2019-2020 Intel Corporation
1+
.. SPDX-FileCopyrightText: 2019-2021 Intel Corporation
22
..
33
.. SPDX-License-Identifier: CC-BY-4.0
44
@@ -15,6 +15,8 @@ Parallel Functions
1515
.. toctree::
1616
:titlesonly:
1717

18+
algorithms/functions/collaborative_call_once_func.rst
19+
1820
algorithms/functions/parallel_for_func.rst
1921
algorithms/functions/parallel_reduce_func.rst
2022
algorithms/functions/parallel_deterministic_reduce_func.rst

source/elements/oneTBB/source/algorithms/blocked_ranges/blocked_range2d_cls.rst

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,41 @@ A ``blocked_range2d`` meets the :doc:`Range requirements <../../named_requiremen
1717

1818
.. code:: cpp
1919
20-
// Defined in header <tbb/blocked_range2d.h>
21-
22-
namespace tbb {
23-
24-
template<typename RowValue, typename ColValue=RowValue>
25-
class blocked_range2d {
26-
public:
27-
// Types
28-
using row_range_type = blocked_range<RowValue>;
29-
using col_range_type = blocked_range<ColValue>;
30-
31-
// Constructors
32-
blocked_range2d(
33-
RowValue row_begin, RowValue row_end,
34-
typename row_range_type::size_type row_grainsize,
35-
ColValue col_begin, ColValue col_end,
36-
typename col_range_type::size_type col_grainsize);
37-
blocked_range2d( RowValue row_begin, RowValue row_end,
38-
ColValue col_begin, ColValue col_end );
39-
// Splitting constructors
40-
blocked_range2d( blocked_range2d& r, split );
41-
blocked_range2d( blocked_range2d& r, proportional_split proportion );
42-
43-
// Capacity
44-
bool empty() const;
45-
46-
// Access
47-
bool is_divisible() const;
48-
const row_range_type& rows() const;
49-
const col_range_type& cols() const;
50-
};
51-
52-
} // namespace tbb
20+
// Defined in header <oneapi/tbb/blocked_range2d.h>
21+
22+
namespace oneapi {
23+
namespace tbb {
24+
25+
template<typename RowValue, typename ColValue=RowValue>
26+
class blocked_range2d {
27+
public:
28+
// Types
29+
using row_range_type = blocked_range<RowValue>;
30+
using col_range_type = blocked_range<ColValue>;
31+
32+
// Constructors
33+
blocked_range2d(
34+
RowValue row_begin, RowValue row_end,
35+
typename row_range_type::size_type row_grainsize,
36+
ColValue col_begin, ColValue col_end,
37+
typename col_range_type::size_type col_grainsize);
38+
blocked_range2d( RowValue row_begin, RowValue row_end,
39+
ColValue col_begin, ColValue col_end );
40+
// Splitting constructors
41+
blocked_range2d( blocked_range2d& r, split );
42+
blocked_range2d( blocked_range2d& r, proportional_split proportion );
43+
44+
// Capacity
45+
bool empty() const;
46+
47+
// Access
48+
bool is_divisible() const;
49+
const row_range_type& rows() const;
50+
const col_range_type& cols() const;
51+
};
52+
53+
} // namespace tbb
54+
} // namespace oneapi
5355
5456
Requirements:
5557

source/elements/oneTBB/source/algorithms/blocked_ranges/blocked_range3d_cls.rst

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,42 @@ A ``blocked_range3d`` is the three-dimensional extension of ``blocked_range2d``.
1313

1414
.. code:: cpp
1515
16-
namespace tbb {
17-
template<typename PageValue, typename RowValue=PageValue, typename ColValue=RowValue>
18-
class blocked_range3d {
19-
public:
20-
// Types
21-
using page_range_type = blocked_range<PageValue>;
22-
using row_range_type = blocked_range<RowValue>;
23-
using col_range_type = blocked_range<ColValue>;
24-
25-
// Constructors
26-
blocked_range3d(
27-
PageValue page_begin, PageValue page_end,
28-
typename page_range_type::size_type page_grainsize,
29-
RowValue row_begin, RowValue row_end,
30-
typename row_range_type::size_type row_grainsize,
31-
ColValue col_begin, ColValue col_end,
32-
typename col_range_type::size_type col_grainsize );
33-
blocked_range3d( PageValue page_begin, PageValue page_end
34-
RowValue row_begin, RowValue row_end,
35-
ColValue col_begin, ColValue col_end );
36-
blocked_range3d( blocked_range3d& r, split );
37-
blocked_range3d( blocked_range3d& r, proportional_split& proportion );
38-
39-
// Capacity
40-
bool empty() const;
41-
42-
// Access
43-
bool is_divisible() const;
44-
const page_range_type& pages() const;
45-
const row_range_type& rows() const;
46-
const col_range_type& cols() const;
47-
};
48-
}
16+
namespace oneapi {
17+
namespace tbb {
18+
template<typename PageValue, typename RowValue=PageValue, typename ColValue=RowValue>
19+
class blocked_range3d {
20+
public:
21+
// Types
22+
using page_range_type = blocked_range<PageValue>;
23+
using row_range_type = blocked_range<RowValue>;
24+
using col_range_type = blocked_range<ColValue>;
25+
26+
// Constructors
27+
blocked_range3d(
28+
PageValue page_begin, PageValue page_end,
29+
typename page_range_type::size_type page_grainsize,
30+
RowValue row_begin, RowValue row_end,
31+
typename row_range_type::size_type row_grainsize,
32+
ColValue col_begin, ColValue col_end,
33+
typename col_range_type::size_type col_grainsize );
34+
blocked_range3d( PageValue page_begin, PageValue page_end
35+
RowValue row_begin, RowValue row_end,
36+
ColValue col_begin, ColValue col_end );
37+
blocked_range3d( blocked_range3d& r, split );
38+
blocked_range3d( blocked_range3d& r, proportional_split& proportion );
39+
40+
// Capacity
41+
bool empty() const;
42+
43+
// Access
44+
bool is_divisible() const;
45+
const page_range_type& pages() const;
46+
const row_range_type& rows() const;
47+
const col_range_type& cols() const;
48+
};
49+
50+
} // namespace tbb
51+
} // namespace oneapi
4952
5053
Requirements:
5154

source/elements/oneTBB/source/algorithms/blocked_ranges/blocked_range_cls.rst

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,38 @@ to the loop templates ``parallel_for``, ``parallel_reduce``, or ``parallel_scan`
2121

2222
.. code:: cpp
2323
24-
// Defined in header <tbb/blocked_range.h>
25-
26-
namespace tbb {
27-
28-
template<typename Value>
29-
class blocked_range {
30-
public:
31-
// types
32-
using size_type = size_t;
33-
using const_iterator = Value;
34-
35-
// constructors
36-
blocked_range( Value begin, Value end, size_type grainsize=1 );
37-
blocked_range( blocked_range& r, split );
38-
blocked_range( blocked_range& r, proportional_split& proportion );
39-
40-
// capacity
41-
size_type size() const;
42-
bool empty() const;
43-
44-
// access
45-
size_type grainsize() const;
46-
bool is_divisible() const;
47-
48-
// iterators
49-
const_iterator begin() const;
50-
const_iterator end() const;
51-
};
52-
}
24+
// Defined in header <oneapi/tbb/blocked_range.h>
25+
26+
namespace oneapi {
27+
namespace tbb {
28+
29+
template<typename Value>
30+
class blocked_range {
31+
public:
32+
// types
33+
using size_type = size_t;
34+
using const_iterator = Value;
35+
36+
// constructors
37+
blocked_range( Value begin, Value end, size_type grainsize=1 );
38+
blocked_range( blocked_range& r, split );
39+
blocked_range( blocked_range& r, proportional_split& proportion );
40+
41+
// capacity
42+
size_type size() const;
43+
bool empty() const;
44+
45+
// access
46+
size_type grainsize() const;
47+
bool is_divisible() const;
48+
49+
// iterators
50+
const_iterator begin() const;
51+
const_iterator end() const;
52+
};
53+
54+
} // namespace tbb
55+
} // namespace oneapi
5356
5457
Requirements:
5558

source/elements/oneTBB/source/algorithms/examples/blocked_rangeNd_example.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include "tbb/tbb_config.h"
1+
#include "oneapi/tbb/tbb_config.h"
22

33
#if __TBB_CPP11_PRESENT && __TBB_CPP11_ARRAY_PRESENT && __TBB_CPP11_TEMPLATE_ALIASES_PRESENT
44
#include "blocked_rangeNd_example.h"
55
#endif
66

7-
#include "tbb/tbb_stddef.h"
7+
#include "oneapi/tbb/tbb_stddef.h"
88
#include <vector>
99

1010
int main() {

source/elements/oneTBB/source/algorithms/examples/blocked_rangeNd_example.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#define TBB_PREVIEW_BLOCKED_RANGE_ND 1
2-
#include "tbb/blocked_rangeNd.h"
2+
#include "oneapi/tbb/blocked_rangeNd.h"
33

4-
#include "tbb/parallel_for.h"
5-
#include "tbb/parallel_reduce.h"
4+
#include "oneapi/tbb/parallel_for.h"
5+
#include "oneapi/tbb/parallel_reduce.h"
66

77
template<typename Features>
88
float kernel3d(const Features& feature_maps, int i, int j, int k,
@@ -21,9 +21,9 @@ template<typename Features, typename Output>
2121
void convolution3d(const Features& feature_maps, Output& out,
2222
int out_length, int out_width, int out_heigth,
2323
int kernel_length, int kernel_width, int kernel_height) {
24-
using range_t = tbb::blocked_rangeNd<int, 3>;
24+
using range_t = oneapi::tbb::blocked_rangeNd<int, 3>;
2525

26-
tbb::parallel_for(
26+
oneapi::tbb::parallel_for(
2727
range_t({0, out_length}, {0, out_width}, {0, out_heigth}),
2828
[&](const range_t& out_range) {
2929
auto out_x = out_range.dim(0);

source/elements/oneTBB/source/algorithms/examples/range_concept.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <tbb/tbb_stddef.h> // for split tags
1+
#include <oneapi/tbb/tbb_stddef.h> // for split tags
22

33
struct TrivialNaturalRange {
44
// restore the default constructor
@@ -10,14 +10,14 @@ struct TrivialNaturalRange {
1010
bool is_divisible() const { return upper > lower + 1; }
1111

1212
// basic splitting constructor
13-
TrivialNaturalRange(TrivialNaturalRange& r, tbb::split) {
13+
TrivialNaturalRange(TrivialNaturalRange& r, oneapi::tbb::split) {
1414
size_t m = r.lower + (r.upper - r.lower) / 2;
1515
upper = r.upper;
1616
r.upper = lower = m;
1717
}
1818

1919
// optional proportional splitting constructor
20-
TrivialNaturalRange(TrivialNaturalRange& r, tbb::proportional_split p) {
20+
TrivialNaturalRange(TrivialNaturalRange& r, oneapi::tbb::proportional_split p) {
2121
size_t m = r.lower + ((r.upper - r.lower) * p.left()) / (p.left() + p.right());
2222
if (m == r.lower)
2323
m++;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
.. SPDX-FileCopyrightText: 2021 Intel Corporation
2+
..
3+
.. SPDX-License-Identifier: CC-BY-4.0
4+
5+
=======================
6+
collaborative_call_once
7+
=======================
8+
**[algorithms.collaborative_call_once]**
9+
10+
Function template that executes function exactly once.
11+
12+
.. code:: cpp
13+
14+
// Defined in header <oneapi/tbb/collaborative_call_once.h>
15+
16+
namespace oneapi {
17+
namespace tbb {
18+
19+
template<typename Func, typename... Args>
20+
void collaborative_call_once(collaborative_once_flag& flag, Func&& func, Args&&... args);
21+
22+
} // namespace tbb
23+
} // namespace oneapi
24+
25+
Requirements:
26+
27+
* ``Func`` type must meet the ``Function Objects``
28+
requirements from the [function.objects] section of the ISO C++ Standard section.
29+
30+
Executes the ``Func`` object only once, even if it is called concurrently. It allows other threads
31+
blocked on the same ``collaborative_once_flag`` to join oneTBB parallel construction called
32+
within the ``Func`` object.
33+
34+
In case of the exception thrown from the ``Func`` object, the thread calling the ``Func`` object
35+
receives this exception. One of the threads blocked on the same ``collaborative_once_flag``
36+
calls the ``Func`` object again.
37+
38+
collaborative_once_flag Class
39+
-----------------------------
40+
41+
.. toctree::
42+
:titlesonly:
43+
44+
collaborative_once_flag_cls.rst
45+
46+
47+
Example
48+
-------
49+
50+
The following example shows a class in which the "Lazy initialization" pattern is implemented on
51+
the "cachedProperty" field.
52+
53+
54+
.. code:: cpp
55+
56+
#include "oneapi/tbb/collaborative_call_once.h"
57+
58+
extern double foo(int i);
59+
60+
class LazyData {
61+
oneapi::tbb::collaborative_once_flag flag;
62+
double cachedProperty;
63+
public:
64+
double getProperty() {
65+
oneapi::tbb::collaborative_call_once(flag, [&] {
66+
// serial part
67+
double result{};
68+
69+
// parallel part where threads can collaborate
70+
result = oneapi::tbb::parallel_reduce(oneapi::tbb::blocked_range<int>(0, 1000),
71+
[&] (auto r, double r) {
72+
for(int i = r.begin(); i != r.end(); ++i) {
73+
r += foo(i);
74+
}
75+
return r;
76+
},
77+
std::plus<double, double>{}
78+
);
79+
80+
// continue serial part
81+
cachedProperty = result;
82+
});
83+
84+
return cachedProperty;
85+
}
86+
};

0 commit comments

Comments
 (0)