我只是通过在线教程和资源学习 OpenMP。我想使用 parallel for
循环对矩阵进行平方(将其与自身相乘)。在 IBM compiler documentation ,我发现了“迭代变量必须是有符号
整数”的要求。在 GCC 实现中也是如此吗?它是否在 OpenMP 标准中指定?如果是这样,是否有此要求的原因?
(这并不重要,因为预期的尺寸远小于 INT_MAX
,但它确实花费了我一些转换。)
最佳答案
引自Why aren't unsigned OpenMP index variables allowed? :
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 apparently allows for unsigned types too, but I haven't seen it in action yet.
简而言之,它是标准的一部分,下一个版本将允许无符号整数。
关于c++ - 为什么循环变量必须并行签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3988470/