- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it possible to impose a maximum on the number of threads spun up by tbb as the graph is generated and edges are made?
Right now, tbb creates a number of threads equal to task_scheduler_init::default_num_threads(), pretty much regardless of the complexity of my graph. Setting max_threads via tbb::task_scheduler_init() appears to have no effect on the number of threads started.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you certain that you are setting tbb::task_scheduler_init before doing anything that might invoke the scheduler?
And that you are in fact putting the object on the stack for the duration of your application thread, rather than using it as a function, which would merely construct and immediately destroy a local object, with no lasting effect?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, worked like a charm. Put it at the top of main and declared tbb::task_scheduler_init object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suppose you can use task_arena class to limit number of thread for a particular graph. More details can be found in our article http://goparallel.sourceforge.net/wp-content/uploads/2014/07/PUM18_Threading_Building_Blocks.pdf or in the reference manual.
example:
#include <tbb/task_arena.h> ... // limit arena by 4 workers tbb::task_arena my_arena(4); ... tbb::flow::graph g; ... // create the graph here my_arena.enqueue([&]{ ... // start graph computations }); ... // do something else my_arena.execute([&]{ g.wait_for_all(); }); // does not return until the flow graph finishes

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