Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

How to get optimum number of threads

smallb
Beginner
621 Views
Guys, I have a tbb::concurrent_unsorted_set loaded with path's to files (100.000+ files), and I'd like to set a optimum no of threads to create via tbb::task_scheduler_init, so there isn't oversubscription present while processing those files. Do I have to do it anyway? Will tbb do it better for me? In any case I'd like to know the optimum no of threads to spawnby me or by tbb (I need to display this info in a window) . Is there a way to do it?
Thank you.
0 Kudos
1 Solution
ahelwer
New Contributor I
621 Views
If you do it right, the optimum number of threads should be set automatically - that is, one thread for every core on the system. The key is to use the TBB task scheduler in the way it was designed, and just spawn a TBB task for processing any given file. The scheduler will map those tasks dynamically onto available threads, resulting in zero oversubscription - if no thread is available to run the task, it is put onto a work queue. The tutorial makes for a good introduction to the inner workings of the task scheduler.

View solution in original post

0 Kudos
4 Replies
ahelwer
New Contributor I
622 Views
If you do it right, the optimum number of threads should be set automatically - that is, one thread for every core on the system. The key is to use the TBB task scheduler in the way it was designed, and just spawn a TBB task for processing any given file. The scheduler will map those tasks dynamically onto available threads, resulting in zero oversubscription - if no thread is available to run the task, it is put onto a work queue. The tutorial makes for a good introduction to the inner workings of the task scheduler.
0 Kudos
RafSchietekat
Valued Contributor III
621 Views
That depends on the program design. Normally you shouldn't be doing any I/O inside TBB code, but if you want to do that anyway, and need to deploy more threads than normal to counter undersubscription, your penalty is to tune the program yourself (because the outcome is unpredictable).
0 Kudos
smallb
Beginner
621 Views

Hi,

Thank you for your answer. You mention some tutorial, could you please give me a link to it so that I could download it?

Thanks

0 Kudos
SergeyKostrov
Valued Contributor II
621 Views
Please take a look at a very good article regarding oversubscription of threads:

http://blogs.msdn.com/b/visualizeparallel/archive/2009/12/01/oversubscription-a-classic-parallel-performance-problem.aspx

Best regards,
Sergey
0 Kudos
Reply