How to get optimum number of threads

How to get optimum number of threads

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.

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

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.

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).


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


Please take a look at a very good article regarding oversubscription of threads:

Best regards,

Leave a Comment

Please sign in to add a comment. Not a member? Join today