我正在尝试使用openmp通过std :: set多线程循环.当我写下面的代码 -
#pragma omp parallel for
for (std::set<A>::const_iterator i = s.begin(); i != s.end(); ++i) {
const A a = *i;
operate(a);
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
error: invalid type for iteration variable 'i'
error: invalid controlling predicate
error: invalid increment expression.
Run Code Online (Sandbox Code Playgroud)
是否有另一种正确的方法来使用openmp迭代std容器?
我知道我可以使用int i和迭代0到s.size()迭代器或operator[]循环体,但这看起来不那么干净.
我正在尝试使用 openMP 在 C++ 中迭代映射,但是我收到三个错误消息,说
我的循环的初始化、终止和增量形式不正确,而且我在使用 openmp 方面很新,所以有什么方法可以在获得与串行结果相同的结果的同时解决这个问题?以下是我使用的代码
map< int,string >::iterator datIt;
#pragma omp parallel for
for(datIt=dat.begin();datIt!=dat.end();datIt++) //construct the distance matrix
{
...............
}
Run Code Online (Sandbox Code Playgroud)