错误 C3017:OpenMP 'for' 语句中的终止测试形式不正确 [英] error C3017: termination test in OpenMP 'for' statement has improper form

查看:32
本文介绍了错误 C3017:OpenMP 'for' 语句中的终止测试形式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a for loop that has all variables defined

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

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

When I compile this with the /openmp command line option in Visual Studio 2012, it gives me

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

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

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

What is a proper for statement to OpenMP? How do I apply it to my for loop?

推荐答案

OpenMP 3.1 标准为 for-loop 结构规定了一种非常严格的形式(参见第 39 页):

The OpenMP 3.1 standard prescribes a very strict form for the for-loop construct (see pag.39):

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

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

In particular, test-expr must look like one of the following:

var relational-op b
b relational-op var

其中 relational-op<,<=,>,>= 之一,bloop invariant 类型与 var 类型兼容的表达式.

where relational-op is one of <,<=,>,>= and b is a loop invariant expressions of a type compatible with the type of var.

除此之外,您必须确保:

Other than that you must ensure that:

关联的循环的循环控制表达式的值对于循环中的所有线程,循环结构必须相同团队.

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 是否是循环不变的,并且所有线程都具有相同的值.

So, coming back to your case, I would check sqrtt to be a loop invariant and to have the same value for all threads.

long long 在 C++11 之前的 C++ 中不是标准的,参见例如 这个问题 关于 SO.

long long isn't standard in C++ prior to C++11, see for instance this question on SO.

这篇关于错误 C3017:OpenMP 'for' 语句中的终止测试形式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆