- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Need help.
What is the equivalent implementation of openmp's parallel section in tbb??
Can you cite an example??
I still dont know how to run two different tasks at the same time using tbb.
What is the equivalent implementation of openmp's parallel section in tbb??
Can you cite an example??
I still dont know how to run two different tasks at the same time using tbb.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A general solution is to use an empty task as a dummy parent. See http://software.intel.com/en-us/blogs/2008/07/02/implementing-task_group-interface-in-tbb for code that implements a general task group interface using this approach. It's on our to-do list to add something like this to TBB and add a general template for running a fixed number of functors concurrently.
For exposition, below is a simple example that runs two tasks concurrently.
#include "tbb/task_scheduler_init.h" #include "tbb/task.h" #includevoid DummyLoad() { for( volatile int x=0; x!=100000000; ++x ) continue; } class X: public tbb::task { tbb::task* execute() { std::printf("X is runningn"); DummyLoad(); std::printf("X finished runningn"); return NULL; } }; class Y: public tbb::task { tbb::task* execute() { std::printf("Y is runningn"); DummyLoad(); std::printf("Y finished runningn"); return NULL; } }; int main() { tbb::task_scheduler_init init; tbb::empty_task* e = new( tbb::task::allocate_root() ) tbb::empty_task; // 3 = 1 for each child plus 1 for the wait e->set_ref_count(3); X* x = new( e->allocate_child() ) X; Y* y = new( e->allocate_child() ) Y; e->spawn(*x); e->spawn(*y); // Wait for childen to finish e->wait_for_all(); e->destroy(*e); return 0; }

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