我需要实现一个函数,它将使用ppl.h在浮点数数组中找到最大的元素。
我有这段代码,基于this answer
float find_largest_element_in_matrix_PPL(float* m, size_t dims)
{
float max_element;
int row, col;
concurrency::combinable<float> locals([] { return INT_MIN + 0.f; });
concurrency::parallel_for_each(size_t(0), dims * dims, [&locals](int curr)
{
float & localMax = locals.local();
localMax = max<float>(localMax, curr);
});
max_element = locals.combine([](float left, float right) { return max<float>(left, right); });
cout << max_element << endl;
return max_element;
}但是,这段代码存在一个问题:
错误C2780 'void Concurrency::_Parallel_for_each_impl(const _Random_iterator &,const _Random_iterator &,const _Function &,_Partitioner &,std::random_access_iterator_tag)':期望5个参数--4个提供parp:\Microsoft 14.0\VC\include\ppl.h 2987 Error C2780 'void C2780 const _Forward_iterator &,const _Function &,const Concurrency::auto_partitioner &,std::forward_iterator_tag]:期望5个参数--4个提供parp:\MicrosoftVisualStudio14.0\VC\include\ppl.h 2987 错误C2893未能专门化函数模板'iterator_traits<_Iter>::iterator_category std::_Iter_cat(const _Iter &)‘parp D:\Microsoft 14.0\VC\include\ppl.h 2987
parallel_for?(我不能引用传递给parallel_for块中函数的数组参数)发布于 2020-03-19 23:37:21
float SimpleTest::SimpleTestfind_largest_element_in_matrix_PPL(float* m, size_t dims)
{
float max_element;
concurrency::combinable<float> locals([&]{ return INT_MIN + 0.f; });
int last= dims*dims;
concurrency::parallel_for(0, last, [&](int curr)
{
float & localMax = locals.local();
localMax = max<float>(localMax, curr);
});
max_element = locals.combine([](float left, float right) { return max<float>(left, right); });
std::cout << max_element << endl;
return max_element;
}也许它会有用
https://stackoverflow.com/questions/34318366
复制相似问题