Last active
June 6, 2019 13:19
-
-
Save mcopik/f51ad4d262674ad2067e37b27096e21d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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