I want to execute a for-loop in parallel (using TBB) over a set of blocks, where each block will be processed using a user-supplied function. Normally, I would do this using tbb::parallel_for()
. For various reasons, I want to be able to limit the number of threads processing the blocks to a prescribed number, call it j
. Normally, I would do this using tbb::task_scheduler_init(j)
.
However, I would like the user to have the option to use TBB and, specifically, let the user-supplied function use however many cores remain. So I think tbb::task_scheduler_init()
is out. The only solution I can see is to let the user call tbb::task_scheduler_init()
(or ignore it all together), and just spin j
instances of tbb::tbb_thread
on my own in a normal for-loop. Am I missing anything? Is there a more natural way to do this in TBB? Is there some kind of a hierarchical version of tbb::task_scheduler_init()
?