我有一个定义了所有变量的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/