为什么不允许未签名的OpenMP索引变量? [英] Why aren't unsigned OpenMP index variables allowed?

查看:793
本文介绍了为什么不允许未签名的OpenMP索引变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C ++ / OpenMP代码中有一个循环,如下所示:

I have a loop in my C++/OpenMP code that looks like this:

#pragma omp parallel for
for(unsigned int i=0; i<count; i++)
{
    // do stuff
}

当我编译它(使用Visual Studio 2005)时,我得到以下错误:

When I compile it (with Visual Studio 2005) I get the following error:

错误C3016:'i':OpenMP中的索引变量'for'语句必须有签名的整数类型

我理解错误发生,因为 i 是无符号的而不是signed,并且更改 i 以进行签名删除此错误。我想知道的是为什么是这个错误?为什么不允许未签名的索引变量?查看此错误的 MSDN 页面,我没有提供任何线索。 / p>

I understand that the error occurs because i is unsigned instead of signed, and changing i to be signed removed this error. What I want to know is why is this an error? Why aren't unsigned index variables allowed? Looking at the MSDN page for this error gives me no clues.

推荐答案

根据 OpenMP 2.0 C / C ++ API规范(pdf),第2.4.1节,这是 for 循环的限制之一。没有给出原因,但我怀疑它只是简化了代码和编译器必须做的假设,因为有特殊的代码,以确保范围不会溢出类型的最大值。

According to the OpenMP 2.0 C/C++ API specification (pdf), section 2.4.1, that's one of the restrictions of the for loop. No reason is given for it, but I suspect it's just to simplify the assumptions that the code and compiler have to make, since there's special code to ensure that the range doesn't overflow the maximum value of the type.

OpenMP 3.0显然允许未签名的类型,但我还没有看到它在操作中。

OpenMP 3.0 apparently allows for unsigned types too, but I haven't seen it in action yet.

这篇关于为什么不允许未签名的OpenMP索引变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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