Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将第一个函数转换为与任务并行工作_C++_Tbb - Fatal编程技术网

C++ 将第一个函数转换为与任务并行工作

C++ 将第一个函数转换为与任务并行工作,c++,tbb,C++,Tbb,1.如何将第一个函数转换为与任务并行工作试图这样做,但我不知道我是否工作正常,请如果有人能帮助我,我将不胜感激 template<typename F> void matrix_sweep(int width, int height, const F& f) { for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) {

1.如何将第一个函数转换为与任务并行工作试图这样做,但我不知道我是否工作正常,请如果有人能帮助我,我将不胜感激

template<typename F>
void matrix_sweep(int width, int height, const F& f)
{
    for (int i = 0; i < height; ++i)
    {
        for (int j = 0; j < width; ++j)
        {
            f(i, j);
        }
    }
}

template<typename F>

void parallel_matrix_sweep(int width, int height, const F& f)
{
    struct invoke : public tbb::task;
    {
        tbb::task* invoke::execute();
        {
            tbb::task* barrier = new (allocate_continuation())tbb::empty_task();
            barrier->set_ref_count(1);
            tbb::task_list tl;
            tl.push_back(*new(barrier->allocate_child())run<F>(f));
            spawn(tl);
            
        }

        invoke(const F& f) : f(f), {} const F& f;
    };
}

tbb::tick_count t2 = tbb::tick_count::now();
cout << data.back().back() << endl;
cout << "Time: " << (t2 - t1).seconds() << endl;




模板
空心矩阵_扫掠(整型宽度、整型高度、常数F&F)
{
对于(int i=0;i设置参考计数(1);
tbb::任务列表tl;
tl.push_back(*新建(屏障->分配子项())运行(f));
产卵(tl);
}
调用(常量F&F):F(F),{}常量F&F;
};
}
tbb::tick_count t2=tbb::tick_count::now();
库特