c++ - 使用#omp 时不匹配 'operator -'

标签 c++ openmp

我正在将 OpenMP 添加到现有代码中,并尝试并行化下面的 for 循环。 Block是代码实现的容器。运算符 < 和++ 是为 Block 容器实现的。

#pragma omp parallel for // code compiles without this line
for ( Block::iterator it = initValue; it < blockEnd; ++it ) {
  // LOOP BODY
}

当存在 OpenMP pragma 时,出现以下错误:

No match for 'operator-' (operand types are Block::iterator and Block::iterator)

如果我去掉 pragma,代码编译得很好,所以我确信我的运算符定义没问题。为什么 OpenMP 要求在此处实现“operator-”?

编译器:gcc 7.2.1 OpenMP 4.0

最佳答案

OpenMP 仅支持 RandomAccessIterator 的迭代器循环秒。显然,Block::iterator 不满足,缺少相应的operator-

编辑:另一个答案给出了一些关于 GCC 如何使用 operator- 的提示。然而,真正的答案仍然是:OpenMP 标准要求您实现 RandomAccessIterator具有所有必需的操作请注意,这更进一步.如果不这样做,可能会导致您的代码适用于特定的 GCC 版本,但不适用于其他版本或编译器。

关于c++ - 使用#omp 时不匹配 'operator -',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48871756/

相关文章:

c++ #include(什么函数在什么里面)

c++ - 是否有任何适用于 C++ Windows 开发人员的免费可移植(意思是 <100mb)IDE,其编译器能够进行代码提示并经过测试可与 Win32 API 一起使用?

c++ - 第二行的 Getline() 并按空格分隔 - C++

c++ - 如何将 RTF 格式转换为 HTML

c - 在 Visual Studio 2010 (OpenMP) 中并行化 for 循环

c++ - OpenMP 原子内存顺序

android - 我想在 android 中将音频服务器 (/frameworks/av/media/audioserver) 构建为 64 位,但它无法启动

c - OpenMP 基准并行计算

C++ OpenMP 程序

c - OpenMP 的 Eclipse 构建配置