我需要实现一个函数,该函数将使用ppl.h
.
我有这个代码,基于这个答案:
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 D:\Microsoft Visual Studio 14.0\VC\include\ ppl.h 2987
错误 C2780 'void Concurrency::_Parallel_for_each_impl(_Forward_iterator,const _Forward_iterator &,const _Function &,const Concurrency::auto_partitioner &,std::forward_iterator_tag)':需要 5 个参数 - 4 个提供的 parp D:\Microsoft Visual Studio 14.0\VC\包括\ppl.h 2987
错误 C2893 无法专门化函数模板 'iterator_traits<_Iter>::iterator_category std::_Iter_cat(const _Iter &)' parp D:\Microsoft Visual Studio 14.0\VC\include\ppl.h 2987
你能帮我解决这个问题吗?
如何重写代码以使用
parallel_for
?(我无法引用传递给parallel_for
块中函数的数组参数)