16 #ifndef dealii_parallel_h
17 #define dealii_parallel_h
32 #ifdef DEAL_II_WITH_TBB
33 # include <tbb/blocked_range.h>
34 # include <tbb/parallel_for.h>
35 # include <tbb/parallel_reduce.h>
36 # include <tbb/partitioner.h>
39 #ifdef DEAL_II_HAVE_CXX20
57 template <
typename Number>
63 #ifdef __INTEL_COMPILER
71 static const bool value =
false;
76 #ifdef DEAL_II_WITH_TBB
80 template <
typename Iterator,
typename Functor>
84 const Functor & functor,
85 const unsigned int grainsize)
89 tbb::auto_partitioner());
97 template <
typename Iterator,
typename Functor>
101 const Functor & functor,
102 const unsigned int grainsize,
103 const std::shared_ptr<tbb::affinity_partitioner> &partitioner)
135 template <
typename InputIterator,
typename OutputIterator,
typename Function>
137 (std::invocable<
Function, decltype(*std::declval<InputIterator>())> &&
138 std::assignable_from<
139 decltype(*std::declval<OutputIterator>()),
141 decltype(*std::declval<InputIterator>())>>))
143 const InputIterator &end_in,
146 const
unsigned int grainsize)
148 #ifndef DEAL_II_WITH_TBB
153 for (OutputIterator in = begin_in; in != end_in;)
154 *out++ =
function(*in++);
156 using Iterators = std::tuple<InputIterator, OutputIterator>;
158 Iterators x_begin(begin_in, out);
159 Iterators x_end(end_in, OutputIterator());
161 SyncIterators(x_begin),
162 SyncIterators(x_end),
163 [
function](
const auto &range) {
164 for (
const auto &p : range)
165 *std::get<1>(p) =
function(*std::get<0>(p));
196 template <
typename InputIterator1,
197 typename InputIterator2,
198 typename OutputIterator,
202 decltype(*std::declval<InputIterator1>()),
203 decltype(*std::declval<InputIterator2>())> &&
204 std::assignable_from<
205 decltype(*std::declval<OutputIterator>()),
207 decltype(*std::declval<InputIterator1>()),
208 decltype(*std::declval<InputIterator2>())>>))
210 const InputIterator1 &end_in1,
214 const
unsigned int grainsize)
216 #ifndef DEAL_II_WITH_TBB
221 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
222 *out++ =
function(*in1++, *in2++);
225 std::tuple<InputIterator1, InputIterator2, OutputIterator>;
227 Iterators x_begin(begin_in1, in2, out);
228 Iterators x_end(end_in1, InputIterator2(), OutputIterator());
230 SyncIterators(x_begin),
231 SyncIterators(x_end),
232 [
function](
const auto &range) {
233 for (
const auto &p : range)
234 *std::get<2>(p) =
function(*std::get<0>(p), *std::get<1>(p));
265 template <
typename InputIterator1,
266 typename InputIterator2,
267 typename InputIterator3,
268 typename OutputIterator,
272 decltype(*std::declval<InputIterator1>()),
273 decltype(*std::declval<InputIterator2>()),
274 decltype(*std::declval<InputIterator3>())> &&
275 std::assignable_from<
276 decltype(*std::declval<OutputIterator>()),
278 decltype(*std::declval<InputIterator1>()),
279 decltype(*std::declval<InputIterator2>()),
280 decltype(*std::declval<InputIterator3>())>>))
282 const InputIterator1 &end_in1,
287 const
unsigned int grainsize)
289 #ifndef DEAL_II_WITH_TBB
294 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
295 *out++ =
function(*in1++, *in2++, *in3++);
297 using Iterators = std::
298 tuple<InputIterator1, InputIterator2, InputIterator3, OutputIterator>;
300 Iterators x_begin(begin_in1, in2, in3, out);
301 Iterators x_end(end_in1,
306 SyncIterators(x_begin),
307 SyncIterators(x_end),
308 [
function](
const auto &range) {
309 for (
const auto &p : range)
311 function(*std::get<0>(p), *std::get<1>(p), *std::get<2>(p));
320 #ifdef DEAL_II_WITH_TBB
325 template <
typename Iterator,
typename Function>
330 f(range.begin(), range.end());
405 template <
typename Iterator,
typename Function>
410 const
unsigned int grainsize)
412 #ifndef DEAL_II_WITH_TBB
422 [&f](
const tbb::blocked_range<Iterator> &range) {
423 internal::apply_to_subranges<Iterator, Function>(range, f);
476 const std::size_t
end,
551 template <
typename ResultType,
typename Iterator,
typename Function>
553 (std::invocable<Function, Iterator, Iterator> &&
554 std::convertible_to<std::invoke_result_t<Function, Iterator, Iterator>,
558 const Iterator &
begin,
560 const
unsigned int grainsize)
562 #ifndef DEAL_II_WITH_TBB
570 tbb::blocked_range<Iterator>(
begin,
end, grainsize),
572 [f](
const auto &range,
const ResultType &starting_value) {
573 ResultType value = starting_value;
574 value += f(range.begin(), range.end());
577 std::plus<ResultType>(),
578 tbb::auto_partitioner());
604 #ifdef DEAL_II_WITH_TBB
617 std::shared_ptr<tbb::affinity_partitioner>
653 namespace VectorImplementation
673 namespace SparseMatrixImplementation
692 const std::size_t
begin,
693 const std::size_t
end,
696 #ifndef DEAL_II_WITH_TBB
706 [
this](
const tbb::blocked_range<std::size_t> &range) {
std::shared_ptr< tbb::affinity_partitioner > acquire_one_partitioner()
std::shared_ptr< tbb::affinity_partitioner > my_partitioner
void release_one_partitioner(std::shared_ptr< tbb::affinity_partitioner > &p)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
VectorType::value_type * begin(VectorType &V)
VectorType::value_type * end(VectorType &V)
unsigned int minimum_parallel_grain_size
unsigned int minimum_parallel_grain_size
void parallel_reduce(const Operation &op, const size_type start, const size_type end, ResultType &result, const std::shared_ptr<::parallel::internal::TBBPartitioner > &partitioner)
void parallel_for(Iterator x_begin, Iterator x_end, const Functor &functor, const unsigned int grainsize)
void parallel_for(Iterator x_begin, Iterator x_end, const Functor &functor, const unsigned int grainsize, const std::shared_ptr< tbb::affinity_partitioner > &partitioner)
void apply_to_subranges(const tbb::blocked_range< Iterator > &range, const Function &f)
void apply_to_subranges(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, const Function &f, const unsigned int grainsize)
void transform(const InputIterator &begin_in, const InputIterator &end_in, OutputIterator out, const Function &function, const unsigned int grainsize)
ResultType accumulate_from_subranges(const Function &f, const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, const unsigned int grainsize)
typename type_identity< T >::type type_identity_t
virtual ~ParallelForInteger()=default
virtual void apply_to_subrange(const std::size_t, const std::size_t) const =0
void apply_parallel(const std::size_t begin, const std::size_t end, const std::size_t minimum_parallel_grain_size) const