]> git.sesse.net Git - casparcg/blobdiff - tbb/include/tbb/parallel_for.h
2.0. Updated tbb library.
[casparcg] / tbb / include / tbb / parallel_for.h
index 31b9f98ccadfea84246aad3b408f372fad6ed036..409534648619802d49cc02d812a27261aa4e299b 100644 (file)
@@ -203,11 +203,6 @@ namespace strict_ppl {
 //! Parallel iteration over a range of integers with a step provided
 template <typename Index, typename Function>
 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 <typename Index, typename Function>
-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<Index> range(static_cast<Index>(0), end);
         internal::parallel_for_body<Function, Index> 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 <typename Index, typename Function>
 void parallel_for(Index first, Index last, const Function& f) {
-    tbb::task_group_context context;
-    parallel_for(first, last, static_cast<Index>(1), f, context);
+    parallel_for(first, last, static_cast<Index>(1), f);
 }
+
+#if __TBB_TASK_GROUP_CONTEXT
+//! Parallel iteration over a range of integers with explicit step and task group context
+template <typename Index, typename Function>
+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<Index> range(static_cast<Index>(0), end);
+        internal::parallel_for_body<Function, Index> 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 <typename Index, typename Function>
 void parallel_for(Index first, Index last, const Function& f, tbb::task_group_context &context) {
     parallel_for(first, last, static_cast<Index>(1), f, context);
 }
-
+#endif /* __TBB_TASK_GROUP_CONTEXT */
 //@}
 
 } // namespace strict_ppl