Answer the question
In order to leave comments, you need to log in
How to distribute execution of m tasks to n cores (C++)?
There are m tasks (functions), they are executed sequentially, they do not intersect with each other, how to distribute their execution over several threads so that their execution is as efficient as possible?
Roughly speaking, I want to do the same as make -jN does for compilation purposes.
Answer the question
In order to leave comments, you need to log in
You probably want to implement Thread Pool? Then you can look in the book C ++ Concurrency in action, there is an example of a simple Thread Pool, if your tasks are not too small, then it may be enough. If your tasks are short enough, then you can look at the Intel TBB library, somewhere in the bowels there is a very high-quality thread pool, perhaps this is what you need.
use OpenMP
#pragma omp parallel sections
{
#pragma omp section
{
func1();
}
#pragma omp section
{
func2();
}
#pragma omp section
{
func3();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question