Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence Thread Sanitizer in InitRandom #4281

Closed
wants to merge 3 commits into from

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Jan 2, 2025

Summary

Either making the shared variables constant (not sensible in the function signature) or using firstprivate should silence the warnings we see.

Additional background

Fix #4279
cc @EZoni

Checklist

The proposed changes:

  • fix a bug or incorrect behavior in AMReX
  • add new capabilities to AMReX
  • changes answers in the test suite to more than roundoff level
  • are likely to significantly affect the results of downstream AMReX users
  • include documentation in the code and/or rst files, if appropriate

Either making the shared variables constant (not sensible in
the function signature) or using `firstprivate` should silence
the warnings we see.
@WeiqunZhang
Copy link
Member

It does not seem to make thread sanitizer happy.

Another thing you can try is to turn omp parallel into omp parallel for and add a for-loop with nthreads iterations so that we don't need call OpenMP::get_thread_num(). Maybe its issue is thread sanitizer does not understand the omp thread id is unique.

Comment on lines 100 to 103
#ifdef AMREX_USE_OMP
#pragma omp parallel
#pragma omp parallel for
#endif
for (int tid = 0; tid < nthreads; tid++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifdef AMREX_USE_OMP
#pragma omp parallel
#pragma omp parallel for
#endif
for (int tid = 0; tid < nthreads; tid++) {
for (int tid = 0; tid < nthreads; tid++)

With the for loop, the parallel region isn't even required anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was thinking the same. Not sure it matters...

Src/Base/AMReX_Random.cpp Outdated Show resolved Hide resolved
@WeiqunZhang
Copy link
Member

I think it's a false positive. In the past on our own machines, we had to compile gcc from source with certain flags to make thread sanitizer work for OpenMP. For the WarpX CI, maybe similar things need to be done for clang. Not sure if this old stackoverflow post is still relevant. https://stackoverflow.com/questions/33004809/can-i-use-thread-sanitizer-for-openmp-programs

For this particular case, we could simply not using openmp. However, this is probably the first OMP parallel region in the code. I believe the later ones would fail too even if we remove OMP here.

@ax3l
Copy link
Member Author

ax3l commented Jan 6, 2025

Agreed, I would not change it and rather make sure an OpenMP-enabled sanitizer is used.

@ax3l ax3l closed this Jan 6, 2025
@ax3l ax3l deleted the silence-omp-thread-race branch January 6, 2025 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ThreadSanitizer: data race amrex::InitRandom w/ OMP
3 participants