#include "tbb/parallel_for.h" #include "tbb/task_scheduler_init.h" #include #include struct mytask { mytask(size_t n) :_n(n) {} void operator()() { for (int i=0;i<1000000;++i) {} // Deliberately run slow std::cerr << "[" << _n << "]"; } size_t _n; }; int main(int,char**) { //tbb::task_scheduler_init init; // Automatic number of threads tbb::task_scheduler_init init(tbb::task_scheduler_init::default_num_threads()); // Explicit number of threads std::vector tasks; for (int i=0;i<1000;++i) tasks.push_back(mytask(i)); tbb::parallel_for( tbb::blocked_range(0,tasks.size()), [&tasks](const tbb::blocked_range& r) { for (size_t i=r.begin();i