Featured post
deadlock - Small openmp programm freezes sometimes (gcc, c, linux) -
just write small omp test, , not work correctly 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
writing threads incorrect in example,
there must nondeterministic value of j
i have freeze.
compiled gcc-4.3.1 -fopenmp a.c -o gcc -static
run on 4-core x86_core2 linux server: $ ./gcc
, got freeze (sometimes; 1 freeze 4-5 fast runs).
strace:
[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 have freeze (deadlock)?
try making private each loop has it's own copy.
now have more time, try , explain. default variables in openmp shared. there couple of cases there defaults make variables private. parallel regions not 1 of them (so high performance mark's response wrong). in original program, have 2 race conditions - 1 on , 1 on j. problem 1 on i. each thread execute loop number of times, since being changed each thread, number of times thread executes loop indeterminate. since threads have execute barrrier barrier satisfied, come case hang on barrier never end, since not threads execute same number of times.
since openmp spec states (omp spec v3.0, section 2.8.3 barrier construct) "the sequence of worksharing regions , barrier regions encountered must same every thread in team", program non-compliant , such can have indeterminate behavior.
- Get link
- X
- Other Apps
Comments
Post a Comment