1

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.

3
  • Are you concerned that there will be compiler errors because of false positives? Commented Apr 29, 2019 at 6:48
  • I don't know whether it's giving false positives or not.Any suggestions how to check for false positives Commented Apr 29, 2019 at 6:56
  • Have you considered this closely related answer. Commented Apr 29, 2019 at 7:39

1 Answer 1

1

Unless you are concerned about false positives (compiler diagnosing data races when there are none) I find the question (as it is posted) should be reversed. It should have been: Should I use thread sanitizer for openmp programs?

If your aim is to detect data races that might result from using openmp constructs, then you should definitely use thread sanitizer with such programs.

And if your question is really about avoiding false positives when using thread sanitizers with openmp programs, this is covered in this post.

Sign up to request clarification or add additional context in comments.

6 Comments

How do you identify a false positive BTW?
false positive in this case is when the compiler detects that there is a data race when there is no data race. The post I have linked to contains one such example.
Some thread checkers identify race conditions when the OpenMP runtime starts the parallel region. There is usually some unprotected data exchange from the master thread to its workers that is not a true race, as the OpenMP runtime knows about this and was carefully crafted to be correct.
@SameeranJoshi: Does this answer your question?
@SameeranJoshi: Nice article. BTW, you can accept/upvote this answer. See stackoverflow.com/help/someone-answers
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.