c++ - 错误 C3017 : termination test in OpenMP 'for' statement has improper form

标签 c++ visual-studio-2012 for-loop parallel-processing openmp

我有一个定义了所有变量的for循环

#pragma omp parallel for
for(long long l = 1; l<=sqrtt; l++) ...

当我在 Visual Studio 2012 中使用 /openmp 命令行选项编译它时,它给了我

error C3017: termination test in OpenMP 'for' statement has improper form

我不知道为什么 'for' 语句的格式不正确

OpenMP 的正确 for 语句是什么?我如何将它应用于我的 for 循环?

最佳答案

OpenMP 3.1标准为 for-loop 构造规定了非常严格的形式(参见 pag.39):

for (init-expr; test-expr; incr-expr) structured-block

特别是,test-expr必须类似于以下内容之一:

var relational-op b
b relational-op var

其中 relational-op<,<=,>,>= 之一和 b是与 var 类型兼容的类型的循环不变表达式。

除此之外,您必须确保:

The values of the loop control expressions of the loops associated with the loop construct must be the same for all the threads in the team.

所以,回到你的案例,我会检查 sqrtt成为循环不变的并且对所有线程具有相同的值。

一点旁注

long long在 C++11 之前的 C++ 中不是标准的,例如参见 this question在 SO 上。

关于c++ - 错误 C3017 : termination test in OpenMP 'for' statement has improper form,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22770856/

相关文章:

r - 如何跨不同年份使用for循环并将多个地 block 放在一起?

JavaScript:动态翻转函数中的 for 循环不起作用

python - for - else 与 elif

c++ - 静态局部变量会被错误优化吗?

c++ - Qt 资源不工作

c++ - 递归地扩展类和函数的可变参数模板

c# - 设计器中的 ContextMenuStrip 事件

visual-studio - 适用于 Visual Studio 2012 项目的 Mercurial .hgignore

c++ - CUDA 内核第二次运行时运行速度更快 - 为什么?

visual-studio-2012 - TFS:无法创建映射