【学习体会】OpenCV的cv::parallel_for_使用

仅仅只是多线程的话,cv::parallel_for_并不会比openmp快多少,不相上下

#include
#include
#include
#include 
#include 
#include
class LoopBody : public cv::ParallelLoopBody
{
public:
    LoopBody (int*_a,int*_b,int*_c):a(_a),b(_b),c(_c)
    {
    }
    virtual void operator()(const cv::Range& r) const
    {
        for (int i = r.start; i != r.end; i++)  //遍历
        {
            c[i] = a[i]+b[i];
        }
    }

protected:
    int *a;
    int *b;
    int *c;
};

int main(int argc, char** argv)
{
    int num = 10000;

    {
        int* a = new int[num];
        int* b = new int[num];
        int* c = new int[num];

        for(int i=0;i(end - start);
        std::cout << "openmp Spent " << double(duration.count()) * std::chrono::microseconds::period::num / std::chrono::microseconds::period::den << " seconds." << std::endl;

        if(num<=10){
            for(int i=0;i(end - start);
        std::cout << "parallel_for Spent " << double(duration.count()) * std::chrono::microseconds::period::num / std::chrono::microseconds::period::den << " seconds." << std::endl;
        if(num<=10){
            for(int i=0;i

你可能感兴趣的:(学习体会,opencv,c++,蓝桥杯)