X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=tbb%2Finclude%2Ftbb%2Fparallel_for.h;h=409534648619802d49cc02d812a27261aa4e299b;hb=4c96b4064a92f65beead3cb2453d727187bed40f;hp=31b9f98ccadfea84246aad3b408f372fad6ed036;hpb=46ab0514ba58ee00183ff0584c7ea7c9e3d76494;p=casparcg diff --git a/tbb/include/tbb/parallel_for.h b/tbb/include/tbb/parallel_for.h index 31b9f98cc..409534648 100644 --- a/tbb/include/tbb/parallel_for.h +++ b/tbb/include/tbb/parallel_for.h @@ -203,11 +203,6 @@ namespace strict_ppl { //! Parallel iteration over a range of integers with a step provided template void parallel_for(Index first, Index last, Index step, const Function& f) { - tbb::task_group_context context; - parallel_for(first, last, step, f, context); -} -template -void parallel_for(Index first, Index last, Index step, const Function& f, tbb::task_group_context &context) { if (step <= 0 ) internal::throw_exception(internal::eid_nonpositive_step); // throws std::invalid_argument else if (last > first) { @@ -215,20 +210,35 @@ void parallel_for(Index first, Index last, Index step, const Function& f, tbb::t Index end = (last - first - Index(1)) / step + Index(1); tbb::blocked_range range(static_cast(0), end); internal::parallel_for_body body(f, first, step); - tbb::parallel_for(range, body, tbb::auto_partitioner(), context); + tbb::parallel_for(range, body, tbb::auto_partitioner()); } } //! Parallel iteration over a range of integers with a default step value template void parallel_for(Index first, Index last, const Function& f) { - tbb::task_group_context context; - parallel_for(first, last, static_cast(1), f, context); + parallel_for(first, last, static_cast(1), f); } + +#if __TBB_TASK_GROUP_CONTEXT +//! Parallel iteration over a range of integers with explicit step and task group context +template +void parallel_for(Index first, Index last, Index step, const Function& f, tbb::task_group_context &context) { + if (step <= 0 ) + internal::throw_exception(internal::eid_nonpositive_step); // throws std::invalid_argument + else if (last > first) { + // Above "else" avoids "potential divide by zero" warning on some platforms + Index end = (last - first - Index(1)) / step + Index(1); + tbb::blocked_range range(static_cast(0), end); + internal::parallel_for_body body(f, first, step); + tbb::parallel_for(range, body, tbb::auto_partitioner(), context); + } +} +//! Parallel iteration over a range of integers with a default step value and explicit task group context template void parallel_for(Index first, Index last, const Function& f, tbb::task_group_context &context) { parallel_for(first, last, static_cast(1), f, context); } - +#endif /* __TBB_TASK_GROUP_CONTEXT */ //@} } // namespace strict_ppl