269 const
unsigned int grainsize)
274 const std::size_t n = [&]() ->
auto {
275 if constexpr (std::is_integral_v<Iterator>)
276 return static_cast<std::size_t
>(
end -
begin);
278 return static_cast<std::size_t
>(std::distance(
begin,
end));
281 const bool worth_doing_in_parallel =
284#ifdef DEAL_II_WITH_TASKFLOW
285 if (worth_doing_in_parallel)
288 tf::Taskflow taskflow;
290 if constexpr (std::is_integral_v<Iterator>)
293 using integral_type = Iterator;
295 tf::IndexRange<integral_type> range(0, n, 1);
297 taskflow.for_each_by_index(
299 [&,
begin](
const tf::IndexRange<integral_type> &subrange) {
300 integral_type subrange_begin =
301 begin +
static_cast<integral_type
>(subrange.begin());
303 integral_type subrange_end =
304 subrange_begin +
static_cast<integral_type
>(subrange.size());
306 f(subrange_begin, subrange_end);
308 tf::GuidedPartitioner(grainsize));
315 typename std::iterator_traits<Iterator>::difference_type;
317 tf::IndexRange<std::size_t> range(0, n, 1);
319 taskflow.for_each_by_index(
321 [&,
begin](
const tf::IndexRange<std::size_t> &subrange) {
322 Iterator subrange_begin =
begin;
323 std::advance(subrange_begin,
324 static_cast<diff_t
>(subrange.begin()));
326 Iterator subrange_end = subrange_begin;
327 std::advance(subrange_end,
328 static_cast<diff_t
>(subrange.size()));
330 f(subrange_begin, subrange_end);
332 tf::GuidedPartitioner(grainsize));
338 if (executor.this_worker_id() != -1)
339 executor.corun(taskflow);
341 executor.run(taskflow).wait();
345#elif defined(DEAL_II_WITH_TBB)
346 if (worth_doing_in_parallel)
351 [&f](
const tbb::blocked_range<Iterator> &range) {
352 internal::apply_to_subranges<Iterator, Function>(range, f);
359 (void)worth_doing_in_parallel;
498 std::convertible_to<std::invoke_result_t<Function, Iterator, Iterator>,
502 const Iterator &
begin,
504 const
unsigned int grainsize)
506#ifndef DEAL_II_WITH_TBB
513 return tbb::parallel_reduce(
514 tbb::blocked_range<Iterator>(
begin,
end, grainsize),
516 [f](
const auto &range,
const ResultType &starting_value) {
517 ResultType value = starting_value;
518 value += f(range.begin(), range.end());
521 std::plus<ResultType>(),
522 tbb::auto_partitioner());