Skip to content

Instantly share code, notes, and snippets.

@mcopik
Last active June 6, 2019 13:19
Show Gist options
  • Save mcopik/f51ad4d262674ad2067e37b27096e21d to your computer and use it in GitHub Desktop.
Save mcopik/f51ad4d262674ad2067e37b27096e21d to your computer and use it in GitHub Desktop.
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment