Small openmp programm freezes sometimes (gcc, c, linux)

Posted by osgx on Stack Overflow See other posts from Stack Overflow or by osgx
Published on 2010-12-20T15:28:20Z Indexed on 2010/12/22 18:54 UTC
Read the original article Hit count: 203

Filed under:
|
|
|

Hello

Just write a small omp test, and it does not work correctly all the times:

#include <omp.h>
int main() {
  int i,j=0;
#pragma omp parallel
  for(i=0;i<1000;i++)
  {
#pragma omp barrier
    j+= j^i;
  }
  return j;
}

The usage of j for writing from all threads is incorrect in this example, BUT

  • there must be only nondeterministic value of j

  • I have a freeze.

Compiled with gcc-4.3.1 -fopenmp a.c -o gcc -static

Run on 4-core x86_Core2 Linux server: $ ./gcc and got freeze (sometimes; like 1 freeze for 4-5 fast runs).

Strace:

[pid 13118] <... futex resumed> )       = 0
[pid 13118] futex(0x80d3014, FUTEX_WAIT, 2, NULL <unfinished ...>
[pid 13120] <... futex resumed> )       = 0
[pid 13119] futex(0x80d3014, FUTEX_WAIT, 2, NULL <unfinished ...>
[pid 13120] futex(0x80d3014, FUTEX_WAKE, 1) = 1
[pid 13120] futex(0x80cd798, FUTEX_WAIT, 1, NULL <unfinished ...>
[pid 13109] <... futex resumed> )       = 0
[pid 13109] futex(0x80d3014, FUTEX_WAKE, 1) = 1
[pid 13109] futex(0x80d3020, FUTEX_WAIT, 251, NULL <unfinished ...>
[pid 13118] <... futex resumed> )       = 0
[pid 13118] futex(0x80d3014, FUTEX_WAKE, 1) = 1
[pid 13119] <... futex resumed> )       = 0
[pid 13118] futex(0x80d3020, FUTEX_WAIT, 251, NULL <unfinished ...>
[pid 13119] futex(0x80d3014, FUTEX_WAKE, 1) = 0
[pid 13119] futex(0x80d3020, FUTEX_WAIT, 251, NULL                       
                        <freeze>

Why do I have a freeze (deadlock)?

© Stack Overflow or respective owner

Related posts about gcc

Related posts about deadlock