- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm having trouble finding a way in TBB to get the current number of workers in the active task scheduler. For a contrived example:
void g() {
// how can I query from TBB here to get the maximum allowed number of workers that was set in f()?
}
void f(int num_workers) {
tbb::task_scheduler_init init(num_workers);
g();
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
You can check it with this function:
tbb::this_task_arena::max_concurrency()
Thanks,
Nikita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Nikita! However, it doesn't seem to behaving as I would expect/desire. It seems that something like this doesn't work:
tbb::task_scheduler_init init1; std::cerr << tbb::this_task_arena::max_concurrency() << "\n"; // prints 12 (the default) tbb::task_scheduler_init init2(6); std::cerr << tbb::this_task_arena::max_concurrency() << "\n"; // still prints 12 not 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is an expected and documented behavior: "To override the automatic defaults for task scheduling, a task_scheduler_init must become active before the first use of task scheduling services. "
So, the second call will have no effect.
From task_scheduler_init class comments also: "This class allows customizing properties of the TBB task pool to some extent. For example, it can limit concurrency level of parallel work initiated by the given thread. It also can be used to specify stack size of the TBB worker threads, though this setting is not effective if the thread pool has already been created."
Please note that task_scheduler_init is merely a reference to the scheduler, so the scheduler is created when the first reference appears and only destroyed when the last reference in the entire program goes away
Nikita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the clarification! Perhaps it would be useful if a note was added to the task_scheduler_init documentation to use a task_arena if one wants to control the amount of concurrency. While the example there is valid, I would think that the recommendation is there is to actually use a task_arena instead.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page