equivalent openmp section in tbb??

equivalent openmp section in tbb??

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.

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

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

void DummyLoad() {
    for( volatile int x=0; x!=100000000; ++x )

class X: public tbb::task {
    tbb::task* execute() {
        std::printf("X is runningn");
        std::printf("X finished runningn");
        return NULL;

class Y: public tbb::task {
    tbb::task* execute() {
        std::printf("Y is runningn");
        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
    X* x = new( e->allocate_child() ) X;
    Y* y = new( e->allocate_child() ) Y;
    // Wait for childen to finish
    return 0;

Leave a Comment

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