Il'ya Zhenin
Il'ya Zhenin

Reputation: 1332

How to run one function twice in parallel with Intel TBB?

I have a function that I need to run twice with different data parameters. This function takes long time to run and does heavy computational job.

How I can do that, with which TBB mechanism? Or not even TBB, if I can do this with STL, please give me an example.

UPD:

For example I have a function that takes as a parameter image and does some processing to it:

int Compute(cv::Mat I)
{

    /*    computations    */

    return 0;
}
void callf(cv::Mat I1, cv::Mat I2)
{
    // make call of this functions parallel
    Compute(I1);
    Compute(I2);
}

Upvotes: 3

Views: 762

Answers (1)

Anton
Anton

Reputation: 6587

You can use tbb::task_group or tbb::parallel_invoke in conjunction with lambda functions like here:

void callf(cv::Mat I1, cv::Mat I2)
{
    // make call of this functions parallel
    tbb::parallel_invoke(
        [&]{ Compute(I1); },
        [&]{ Compute(I2); }
    );
}

Upvotes: 5

Related Questions