-
-
Notifications
You must be signed in to change notification settings - Fork 829
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
Fix broken openmp atomic usage #1234
Conversation
This must come from an old legacy code that has been merge. And it's indeed disturbing. |
@simogasp
OpenMP requires a separate variable in the expression to be modified. E.g.
I would also like to point out that usage of OpenMP does not change the underlying memory model that is defined by the C++ standard. As a consequence we can use whatever synchronization primitives we want without risk of breakage. This PR should be viewed in light of #1236 which would move off OpenMP synchronization primitives in the rest of codebase. |
3ef0603
to
dcd9ce6
Compare
@fabiencastan @simogasp Is there anything missing from this PR that prevents it from being merged? It fixes a quite important issue in a way that prevents the issue from happening ever again and is actually more convenient compared to proper usage of |
a7e6791
to
a6107e1
Compare
@fabiencastan @simogasp Just a friendly ping :-) It would be great if you could indicate if this PR will potentially be accepted. If not, I will create a separate PR that fixes the bug and refactor my other code to not assume that related changes will be accepted upstream. |
OMP_ATOMIC_UPDATE and OMP_ATOMIC_WRITE are currently completely broken. Currently OMP_ATOMIC_UPDATE and OMP_ATOMIC_WRITE are defined as follows: > #define OMP_ATOMIC_UPDATE _Pragma("omp atomic update") > #define OMP_ATOMIC_WRITE _Pragma("omp atomic write") These macros are used as follows: > #pragma OMP_ATOMIC_UPDATE > #pragma OMP_ATOMIC_WRITE Which results in the following code after preprocessor expansion: > #pragma _Pragma("omp atomic update") > #pragma _Pragma("omp atomic write") This is invalid pragma which is ignored by the compiler. The correct usage of _Pragma is without #pragma as follows: > _Pragma("omp atomic update") > _Pragma("omp atomic write") Fixing this issue reveals another problem that "omp atomic" is very restrictive in what expressions it accepts. In many cases the expressions include access to std::vector and so on, which "omp atomic" does not support. This problem is addressed by using boost::atomic_ref which allows to apply atomic operations on any variable. Because "omp atomic" is hard to use, it is replaced with boost::atomic_ref in all cases.
a6107e1
to
d80d1ff
Compare
Thanks Fabien. |
OMP_ATOMIC_UPDATE and OMP_ATOMIC_WRITE are currently completely broken.
Currently OMP_ATOMIC_UPDATE and OMP_ATOMIC_WRITE are defined as follows:
These macros are used as follows:
Which results in the following code after preprocessor expansion:
This is invalid pragma which is ignored by the compiler. The correct usage of _Pragma is without #pragma as follows:
Fixing this issue reveals another problem that "omp atomic" is very restrictive in what expressions it accepts. In many cases the expressions include access to std::vector and so on, which "omp atomic" does not support.
This problem is addressed by using boost::atomic_ref which allows to apply atomic operations on any variable. Because "omp atomic" is hard to use, it is replaced with boost::atomic_ref in all cases.
As a result of this change we need to bump Boost dependency to 1.73.