Boost logo

Boost Users :

Subject: Re: [Boost-users] General design question about threading/concurrency
From: Belcourt, K. Noel (kbelco_at_[hidden])
Date: 2010-10-25 11:24:41


Hi Julien,

On Oct 25, 2010, at 4:53 AM, Julien Martin wrote:

> Thanks gast128,
> I just installed TBB. Can you please tell me what to look for (which
> class, method or concept) in TBB? It is pretty vast...

Start with the Intel TBB book, it's quite good and walks you through
the product in fairly detailed fashion.

In our application we do this. In a top-level routine (like main).

     empty_task *root = 0;
     task_scheduler_init *init = 0;
     if (1 < n_tasks) {
       init = new task_scheduler_init();
       root = new (tbb::task::allocate_root()) empty_task;
       root->set_ref_count(n_tasks+1);
     }

We're telling TBB thread manager how many TBB::threads we expect to
create (so n_tasks is the number of smp cores). Next we round up the
number of realizations we're going to run to load balance equally
across the system. The number of epistemic realizations is your N.

   if (1 < n_tasks && n_epistemic_realizations % n_tasks) {
     n_epistemic_realizations += n_tasks - (n_epistemic_realizations %
n_tasks);
   }

Our epistemic class inherits from tbb::thread so this code constructs
a thread for each core (task).

     unsigned int n = n_epistemic_realizations / n_tasks;
     epistemic* ep = new (root->allocate_child()) epistemic(n);

For 8 core blade (n_tasks = 8) with 10^4 realizations (N = 10000), n
is 1250.

Note that depending how long your discrete simulations run, you may
eventually want to use hybrid parallelism (MPI to leverage resources
on your networks and threads for each local smp machine, though you
can also use just straight MPI to manage both within and cross box
parallelism.

-- Noel


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net