OpenMP strange behaviour
Hello I have the following code, which I compile with gcc (>4.2) with -fopenmp flag:
int main(void)
{
#pragma omp parallel for
int i;
for(i=0;i<4;i++) while(1);
return 0;
}
I get a SIGSEGV on OSX Lion (ver 1.7.3, llvm-gcc 4.2.1) and CentOS 6.2 . What am I doing wrong here? Thanks
Not sure if this is relevant to the compiler version and configuration but while(true){}
terminates
More precisely, if you write a loop which
and does not terminate, you have undefined behaviour.
This may end up not applying to your situation, but as C++11 becomes more established, watch out.
Very interesting.
I changed the code a little so
int main(void)
{
int i;
#pragma omp parallel
{
while(1);
}
return 0;
}
and so
inline void func() {
while (1) ;
}
int main(void)
{
int i;
#pragma omp parallel for
for(i=0;i<8;i++) {
func();
}
return 0;
}
And they both worked OK.
There was a bug in the gcc regarding this issue, I reported it and they will provide a fix. Here is the link: GCC bug
链接地址: http://www.djcxy.com/p/57374.html上一篇: 我应该混合发展成为主,然后在标签后回来?
下一篇: OpenMP奇怪的行为