为什么!=运算符不使用OpenMP允许? [英] Why is the != operator not allowed with OpenMP?

查看:483
本文介绍了为什么!=运算符不使用OpenMP允许?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译以下code:

I was trying to compiled the following code:

#pragma omp parallel shared (j)
{
   #pragma omp for schedule(dynamic)
   for(i = 0; i != j; i++)
   {
    // do something
   }
}

我得到这个错误:错误:无效的控股predicate

我检查的OpenMP 参考指南和它说,对于平行它仅仅允许以下运营商之一:其中, < =>> =。

I check the openMP reference guide and it says that for the parallel for it "only" allows one of the following operators: < <= > >=.

我不明白为什么不能让我!= j的。我还可以理解,如果它是静态调度中,由于OPENMP需要$ P $对计算分配给每个线程的迭代次数。但我不明白为什么这种限制在这样的情况下,例如。任何线索?

I don't understand why not allow i != j. I could understand if it was the static schedule, since openMP need to pre-compute the number of iterations assigned to each thread. But i can't understand why this limitation in such case for example. Any clues ?

编辑:就算我做的(!I = 0; i = 100;我++),虽然我可能只是把&LT;或&LT; =

even if I make for(i = 0; i != 100; i++), although I could just put "<" or "<=" .

推荐答案

有关符号整数,围绕行为包是不确定的。如果我们允许!=,程序员可能会得到意外tripcount。问题是编译器是否能产生code来计算循环之旅计数。

For signed int, the wrap around behavior is undefined. If we allow !=, programmers may get unexpected tripcount. The problem is whether the compiler can generate code to compute a trip count for the loop.

对于一个简单的循环,如:

For a simple loop, like:

for( i = 0; i < n; ++i )

编译器能够确定有N次迭代,如果n> = 0 ,然后反复零的如果n&LT; 0

对于这样一个循环:

for( i = 0; i != n; ++i ) 

再次,编译器应该能够确定有N次迭代,如果n> = 0 ; 如果n&LT; 0 ,我们不知道有多少次迭代了。

again, a compiler should be able to determine that there are 'n' iterations, if n >= 0; if n < 0, we don't know how many iterations it has.

对于这样一个循环:

for( i = 0; i < n; i += 2 )

编译器可以生成code来计算行程计数(循环迭代计数)为楼((N + 1)/ 2)如果n> = 0 和0 如果n&LT; 0

对于这样一个循环:

for( i = 0; i != n; i += 2 )

编译器不能确定是否'我'都不会打'N'。如果n是什么奇数?

the compiler can't determine whether 'i' will ever hit 'n'. What if 'n' is an odd number?

对于这样一个循环:

for( i = 0; i < n; i += k )

编译器可以生成code来计算行程计数为楼((N + K-1)/ K)如果n> = 0 0 若n&LT ; 0 ,因为编译器知道该回路必须计数;在这种情况下,如果的 K&下; 0 ,它不是一个合法的OpenMP程序。

the compiler can generate code to compute the trip count as floor((n+k-1)/k) if n >= 0, and 0 if n < 0, because the compiler knows that the loop must count up; in this case, if k < 0, it's not a legal OpenMP program.

对于这样一个循环:

for( i = 0; i != n; i += k )

编译器甚至不知道我是否是或计数了。它不知道'我'都不会打'N'。它可能是一个无限循环

the compiler doesn't even know if i is counting up or down. It doesn't know if 'i' will ever hit 'n'. It may be an infinite loop.

Credites :OpenMP的ARB

Credites: OpenMP ARB

这篇关于为什么!=运算符不使用OpenMP允许?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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