Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. struct task_system
  2. {
  3. task_system(int start, int end, int step):
  4. n_tasks(static_cast<int>(
  5. std::floor((end-start)/step)
  6. )),
  7. _barrier(n_tasks)
  8. {
  9. }
  10.  
  11. template<typename F>
  12. void call(const F & f)
  13. {
  14. std::vector<F> vec(n_tasks, f);
  15. for(int i = 0; i < n_tasks; ++i) {
  16. vec[i](*this, i);
  17. }
  18. }
  19. private:
  20. int n_tasks;
  21. };
  22.  
  23. template<typename F>
  24. void spawn(int start, int end, int step, const F & f)
  25. {
  26. task_system tasks(start, end, step);
  27. tasks.call(f);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement