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

Select OpenMP data sharing mode based on specific GCC versions #3823

Merged

Conversation

SunBlack
Copy link
Contributor

Starting with Clang 10 (released some days ago) clang supports OpenMP 4.5 (201511) instead of 3.1 (201107). As value of _GNUC is still 4, we need to extend our exception for GCC, so that Clang can use the newer data sharing model.

Note: Clang 10 can OpenMP 5.0, too, if you add compiler flag -fopenmp-version=50. But as far as I can see we don't get additional compiler errors with OpenMP 5.0 (only short check via godbolt).

@kunaltyagi
Copy link
Member

kunaltyagi commented Mar 28, 2020

We should be checking for clang version in this case too, right? Or is the clang version strictly dependent on the OpenMP version?

PS: maybe some more parenthesis in the macro would help

@SunBlack
Copy link
Contributor Author

We should be checking for clang version in this case too, right? Or is the clang version strictly dependent on the OpenMP version?

I don't think so, as we only need a version check for GCC (as already mentioned here). And as currently all Clang versions are working on gobolt with this macro, I don't believe Clang requires it too.

PS: maybe some more parenthesis in the macro would help

So you suggest (?):

#if (defined _OPENMP && (_OPENMP <= 201307)) || (__GNUC__ < 9 && !defined __clang__)

@kunaltyagi
Copy link
Member

The macro reads funny. Perhaps refactor it by compiler behavior. If GCC then this, else if clang then this. This might be more manageable in case clang changes behavior (or we add support MSVC + OpenMP. Do we already?)

@SunBlack
Copy link
Contributor Author

SunBlack commented Mar 29, 2020

There is no specific flag where I can see it GCC or not. Alternatively I could use (__GNUC__ => 6 && __GNUC__ < 9) (GCC 6 is the first Version which have the wrong data sharing rule), as clang reports always __GNUC__ == 4. But I have no idea if there are other compilers which defines __GNUC__, so no idea which check is the best.

Or do we have a value we are getting from CMake?

If we would not support GCC #if (defined _OPENMP && (_OPENMP <= 201307)) would be enough, as all other compilers seem to stick to the data sharing role that matches the OpenMP version.

@kunaltyagi
Copy link
Member

all other compilers seem to stick to the data sharing role that matches the OpenMP version

In that case, just make en exception for GCC using the 2 diff rules (one for GCC version, one for OpenMP). No need to drag other compilers in 😄

@SunBlack
Copy link
Contributor Author

all other compilers seem to stick to the data sharing role that matches the OpenMP version

In that case, just make en exception for GCC using the 2 diff rules (one for GCC version, one for OpenMP). No need to drag other compilers in 😄

You are right. In case someone has trouble with any other compiler, which define itself as Gnu compiler, we can check what we do then.

I adjusted the code as it was currently a bit lucky that it worked, as I didn't checked if __GNUC__ is defined before I checked the value.

…3.1 (201107). As value of __GNUC_ is still 4, we need to extend our exception for GCC, so that Clang can use the newer data sharing model.
Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

Much better now 😄

@kunaltyagi
Copy link
Member

kunaltyagi commented Mar 29, 2020

A better title for the changelog...

And two more eyes

@kunaltyagi kunaltyagi added module: common needs: author reply Specify why not closed/merged yet needs: code review Specify why not closed/merged yet labels Mar 29, 2020
@SergioRAgostinho SergioRAgostinho removed needs: author reply Specify why not closed/merged yet needs: code review Specify why not closed/merged yet labels Mar 30, 2020
@SergioRAgostinho SergioRAgostinho merged commit eecf609 into PointCloudLibrary:master Mar 30, 2020
@SergioRAgostinho SergioRAgostinho added the changelog: fix Meta-information for changelog generation label Mar 30, 2020
@SunBlack SunBlack deleted the clang10_openmp_fix branch March 30, 2020 09:14
@kunaltyagi kunaltyagi changed the title Fix OpenMP code for Clang 10 Select OpenMP data sharing mode based on specific GCC versions Mar 30, 2020
@mvieth mvieth mentioned this pull request Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: fix Meta-information for changelog generation module: common
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants