Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 984
sfa Avatar asked Feb 06 '12 15:02

sfa


People also ask

Is OpenMP still used?

OpenMP is extensively used as a second level to improve parallelism inside each MPI domain.

Why do we use OpenMP?

OpenMP is typically used for loop-level parallelism, but it also supports function-level parallelism. This mechanism is called OpenMP sections. The structure of sections is straightforward and can be useful in many instances. Consider one of the most important algorithms in computer science, the quicksort.


1 Answers

Not sure if this is relevant to the compiler version and configuration but while(true){} terminates

More precisely, if you write a loop which

  • makes no calls to library I/O functions, and
  • does not access or modify volatile objects, and
  • performs no synchronization operations (1.10) or atomic operations (Clause 29)

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.

like image 191
spraff Avatar answered Sep 19 '22 18:09

spraff