I am trying to use threadsanitizer on given piece of code(in ok.c file) as:
clang -fsanitize=thread ok.c -w -I../runtime
This works fine and no data race is detected, but when I try giving -fopenmp option to sanitizer it dumps the terminal with possible location of data race in the loop.
clang -fsanitize=thread -fopenmp ok.c -w -I../runtime
Terminal output:
$
WARNING: ThreadSanitizer: data race (pid=7980)
Atomic read of size 1 at 0x7d680001f700 by thread T2:
#0 pthread_mutex_lock <null> (a.out+0x000000439b00)
#1 __kmp_reap_worker <null> (libomp.so.5+0x0000000477a2)
int l_3438[10]; //shared
int i;
#pragma omp parallel for
for (i = 0; i < 10; i++){
l_3438[i] = (-10L);
}
I tried using shared and private attributes as well to make things more clear.
int l_3438[10]; //shared
int i;
#pragma omp parallel for shared(l_3438) private(i)
for (i = 0; i < 10; i++){
l_3438[i] = (-10L);
}
Question: Is -fopenmp flag necessary when using thread sanitizer? Thanks.