2016-05-12 40 views
2

我有一个函数,我需要用不同的数据参数运行两次。该功能需要很长时间才能运行,并且执行繁重的计算工作。如何与Intel TBB并行运行两次函数?

我该怎么做,用哪种TBB机制?或者甚至没有TBB,如果我可以用STL来做到这一点,请给我一个例子。

UPD:

例如,我有一个函数,它作为一个参数图像和做一些处理以它:

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); 
} 
+0

你的意思是模板?不知道你想要做什么,就很难建议任何STL数据结构。 –

+0

所以你的意思是线程?也许看看[std :: thread](http://en.cppreference.com/w/cpp/thread) –

回答

4

可以结合使用tbb::task_grouptbb::parallel_invoke与lambda函数等这里:

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