- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
How can one control number of threads? For example, if I specify through scheduler some number of threads, e.g.,
tbb::task_scheduler_init TBBinit(nthreads);
and then I want to change available number of threads in middle of the program, how do I do that?
How can one control number of threads? For example, if I specify through scheduler some number of threads, e.g.,
tbb::task_scheduler_init TBBinit(nthreads);
and then I want to change available number of threads in middle of the program, how do I do that?
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, your code for changing worker threads number is ok. There is no analog of omp_get_num_threads() in TBB, so you can't know what exactly number of threads actively work at the moment. In OpenMP number of threadsavailablefor parallel region is determined before entering to the region and is not changed during processing of the region. So calling omp_get_num_threads() inside the region can easily provide you this previosly defined value.
In TBB work load is balanced dynamically between worker threads every time.Number of worker threads processing a parallel construction always changesdepending on workload. Threads stealtasks from each otherdynamically.So there is no reason to request scheduler about currently active threads - this value can be changed next moment.
Regards,
Kirill
In TBB work load is balanced dynamically between worker threads every time.Number of worker threads processing a parallel construction always changesdepending on workload. Threads stealtasks from each otherdynamically.So there is no reason to request scheduler about currently active threads - this value can be changed next moment.
Regards,
Kirill
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Akhal,
You can change number of threads by removing old task_scheduler_init object and creating new one after this with new number of threads. If number of threads is reduced, those threads that should be stopped will complete their current job and than exit.
Regards,
Kirill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I did like,
task_scheduler_init TBBinit(nrthreads);
Then when I want to reduce or increase threads; I put these lines,
TBBinit.terminate();
TBBinit.initialize(new_nrthreads);
Is this okay? also how can I querry about current number of threads if I want to now at any time like in OpenMP, we use omp_get_num_threads(), whats TBB alternative for this function?
task_scheduler_init TBBinit(nrthreads);
Then when I want to reduce or increase threads; I put these lines,
TBBinit.terminate();
TBBinit.initialize(new_nrthreads);
Is this okay? also how can I querry about current number of threads if I want to now at any time like in OpenMP, we use omp_get_num_threads(), whats TBB alternative for this function?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, your code for changing worker threads number is ok. There is no analog of omp_get_num_threads() in TBB, so you can't know what exactly number of threads actively work at the moment. In OpenMP number of threadsavailablefor parallel region is determined before entering to the region and is not changed during processing of the region. So calling omp_get_num_threads() inside the region can easily provide you this previosly defined value.
In TBB work load is balanced dynamically between worker threads every time.Number of worker threads processing a parallel construction always changesdepending on workload. Threads stealtasks from each otherdynamically.So there is no reason to request scheduler about currently active threads - this value can be changed next moment.
Regards,
Kirill
In TBB work load is balanced dynamically between worker threads every time.Number of worker threads processing a parallel construction always changesdepending on workload. Threads stealtasks from each otherdynamically.So there is no reason to request scheduler about currently active threads - this value can be changed next moment.
Regards,
Kirill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh thank you so much. Your information is so helpful.

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