D
D
domu2014-07-18 16:57:16
C++ / C#
domu, 2014-07-18 16:57:16

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

4 answer(s)
M
Misha Krinkin, 2014-07-18
@domu

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.

A
Andrey Burov, 2014-07-18
@BuriK666

use OpenMP

#pragma omp parallel sections
{ 
  #pragma omp section  
  {  
    func1();
  }
  #pragma omp section  
  {  
    func2();
  }
  #pragma omp section  
  {
    func3();
  }
}

P
Puma Thailand, 2014-07-18
@opium

make a lot of threads or use mpi

T
Trrrrr, 2014-07-20
@Trrrrr

there is an additive to boost threadpool.sourceforge.net/tutorial/intro.html
threadpool. I threw it just to the folder with the boost. Use elementary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question