- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have developed network based application by using the pthread library. Now, to best utilize the Multi-core platform, I want to give a trial to TBB library. I have just started to get in depth of TBB. In my application there is combination of functional and data decomposition. I am unable to get(understand) the TBB API, which can be used to model the functional decomposition.
Let say, application has three independent functional unit :
Now, to do the same thing using TBB, how we should start these task independently(There is no data dependency among these tasks).
I have developed network based application by using the pthread library. Now, to best utilize the Multi-core platform, I want to give a trial to TBB library. I have just started to get in depth of TBB. In my application there is combination of functional and data decomposition. I am unable to get(understand) the TBB API, which can be used to model the functional decomposition.
Let say, application has three independent functional unit :
- FUN1()
- FUN2()
- and FUN3()
Now, to do the same thing using TBB, how we should start these task independently(There is no data dependency among these tasks).
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well, this is pretty straighforward (as long as you do not mind a bit of C++ class writing and placement-new calling
, tutorial has easy samples for all this stuff).
1) You create 3 classes derived from tbb::task. Their methods execute() should invoke FUN1, FUN2, and FUN3 correspondingly.
2) Then you allocate instances of these tasks by means of tbb::allocate_root() functions,
3) and place them into tbb::task_list container.
4) At last you call tbb::spawn_root_and_wait() passing it the task list (that now contains 3 instances of your tasks).
The call to tbb::spawn_root_and_wait() will execute your tasks in parallel (depending on the number of available threads), and return when the last of them finishes. Note that this simple form of functional parallelism usually results in significant imbalance (which is really bad as you certainly know). But if your FUNX functions have a potential for data parallelizm, then you'll be all right. You can safely use TBB data parallel algorithms (like parallel_for, parallel_do or pipeline) from inside other TBB tasks. This does not incur any additional overhead, while allows you to achieve great load balance (that is maximally engages all the available computational resourses in doing the work for you).
And do not forget to initialize TBB (by creating an instance of tbb_scheduler_init class) in the main function of your app before you do what is described above.
1) You create 3 classes derived from tbb::task. Their methods execute() should invoke FUN1, FUN2, and FUN3 correspondingly.
2) Then you allocate instances of these tasks by means of tbb::allocate_root() functions,
3) and place them into tbb::task_list container.
4) At last you call tbb::spawn_root_and_wait() passing it the task list (that now contains 3 instances of your tasks).
The call to tbb::spawn_root_and_wait() will execute your tasks in parallel (depending on the number of available threads), and return when the last of them finishes. Note that this simple form of functional parallelism usually results in significant imbalance (which is really bad as you certainly know). But if your FUNX functions have a potential for data parallelizm, then you'll be all right. You can safely use TBB data parallel algorithms (like parallel_for, parallel_do or pipeline) from inside other TBB tasks. This does not incur any additional overhead, while allows you to achieve great load balance (that is maximally engages all the available computational resourses in doing the work for you).
And do not forget to initialize TBB (by creating an instance of tbb_scheduler_init class) in the main function of your app before you do what is described above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also see my bloghttp://softwareblogs.intel.com/2008/07/02/implementing-task_group-interface-in-tbb/. There's a small piece of code there that you can copy and paste, which provides aconvenient task_group interface.

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