Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The problem about tbb and Vector<mat.< h3="">
class ApplyFoo {
    vector<Mat>my_a;
public:
    void operator()( const blocked_range<size_t>& r ) const {
        vector<Mat> a = my_a;
        for( size_t i=r.begin(); i!=r.end(); ++i ) 
           //Foo(a[i]);
           pyrDown(a[i],a[i],cv::Size(),4);
    }
    ApplyFoo( vector<Mat> a ) :
        my_a(a)
    {}
};


void test(vector<Mat> &src)
{
    parallel_for(blocked_range<size_t>(0,3),ApplyFoo(src));
}

int main(int argc,char **argv)
{
    vector<Mat> Imgs(3);
    vector<Mat> omp(3);
    vector<Mat> tbb(3);
    Imgs[0] = imread("1.jpg",-1);
    Imgs[1] = imread("2.jpg",-1);
    Imgs[2] = imread("3.jpg",-1);
    tbb = Imgs;
    omp = Imgs;
    int64 t = getTickCount();
    for(size_t i = 0 ;i < Imgs.size(); ++i)
    {
        pyrDown(Imgs[i],Imgs[i],cv::Size(),4);
    }
    cout<<"serial cost is "<<(getTickCount() - t)/getTickFrequency()<<endl;
    t = getTickCount();
#pragma omp parallel num_threads(4)
    for(int i = 0 ;i < Imgs.size(); ++i)
    {
        pyrDown(omp[i],omp[i],cv::Size(),4);
    }
    cout<<"omp cost is "<<(getTickCount() - t)/getTickFrequency()<<endl;    
    t = getTickCount();
    test(tbb);
    cout<<"tbb cost is "<<(getTickCount() - t)/getTickFrequency()<<endl;    

    return 0;
}

I want to compare the results between openmp and tbb in the opencv code(as above),but in the section of tbb,the result image is the same as the origin img,it is not working.I don't use cv::ParallelLoopBody,because I think there is no difference between them . I am new to tbb and hope some point out error about tbb