fork download
  1. #ifdef USE_TBB
  2. #include <tbb/parallel_for.h>
  3. #include <tbb/blocked_range.h>
  4. #endif //USE_TBB
  5.  
  6. #include <iostream>
  7. #include <vector>
  8.  
  9. int main() {
  10. std::vector<int> data(100);
  11. #ifdef USE_TBB
  12. tbb::parallel_for(tbb::blocked_range<int>(0, data.size()), [&](const tbb::blocked_range<int>& r) {
  13. for (int i = r.begin(); i != r.end(); ++i) {
  14. std::cout << "i = " << i << std::endl;
  15. data[i] = i * 2; // Example operation
  16. }
  17. });
  18. #endif
  19.  
  20. for (int val : data) {
  21. std::cout << val << " ";
  22. }
  23. std::cout << std::endl;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0