Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct task_system
- {
- task_system(int start, int end, int step):
- n_tasks(static_cast<int>(
- std::floor((end-start)/step)
- )),
- _barrier(n_tasks)
- {
- }
- template<typename F>
- void call(const F & f)
- {
- std::vector<F> vec(n_tasks, f);
- for(int i = 0; i < n_tasks; ++i) {
- vec[i](*this, i);
- }
- }
- private:
- int n_tasks;
- };
- template<typename F>
- void spawn(int start, int end, int step, const F & f)
- {
- task_system tasks(start, end, step);
- tasks.call(f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement