Skip to content

openblas: do not use OpenMP with Clang#806

Merged
tgamblin merged 1 commit intospack:developfrom
davydden:openblas_openmp_clang
May 10, 2016
Merged

openblas: do not use OpenMP with Clang#806
tgamblin merged 1 commit intospack:developfrom
davydden:openblas_openmp_clang

Conversation

@davydden
Copy link
Copy Markdown
Member

fixes #799 .

@adamjstewart @gartung ping.

# Note: Apple's Clang 7.3.0 does not support OpenMP.
# For now, disable OpenMP if we compile with clang.
if ('+openmp' in spec) and (self.compiler.name != 'clang'):
make_defs += ['USE_OPENMP=1']
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@davydden Please provide at least a warning : clang is not only Apple's Clang and it would be annoying if a spec like

openblas+openmp%clang

build without complaints discarding the openmp support. Have you considered just changing the default value for openmp and exit with failure if openblas+openmp%clang is built on OSX?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

how do I output warnings in Spack packages?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

print does not print to the terminal, there must be a command to display a warning, but i never used it.

@davydden davydden force-pushed the openblas_openmp_clang branch from ff81249 to b0c3a89 Compare April 20, 2016 08:41
# Note: Apple's Clang 7.3.0 does not support OpenMP.
# For now, disable OpenMP if we compile with clang on OSX.
if (sys.platform == 'darwin') and (self.compiler.name == 'clang'):
print "Warning: +openmp is ignored on OSX when building with Clang."
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this does not output warning to the terminal. How do I do that?

@davydden
Copy link
Copy Markdown
Member Author

Have you considered just changing the default value for openmp and exit with failure if openblas+openmp%clang is built on OSX?

that is another option, to do via raise InstallError('This package does not build on Mac OS X!').

@davydden davydden force-pushed the openblas_openmp_clang branch from b0c3a89 to b4c841b Compare April 20, 2016 08:49
@davydden
Copy link
Copy Markdown
Member Author

davydden commented Apr 20, 2016

@alalazo i updated PR as you suggested. But I would wait for a feedback from other guys.

# Note: Apple's Clang 7.3.0 does not support OpenMP.
# For now, raise an error if we compile with clang on OSX.
# TODO: one could still have a self-compiled clang-omp on OSX...
if (sys.platform == 'darwin') and (self.compiler.name == 'clang'):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please don't do this; OpenMP works fine e.g. with the MacPorts clang since version 3.7. (Current is 3.8.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@eschnett do you mind suggesting the alternative code to make it pick-up Apple's native Clang?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you want to pick up Apple's clang, or do you want to check whether the compiler supports OpenMP? The latter is more difficult, but the "right thing" to do. Using version numbers will always be iffy.

I would check the version number. Do you have an example of a broken version number? You could simply disallow versions >=7, with an appropriate comment, and open an issue with Spack to handle this in a cleaner way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i agree that a check whether the compiler supports OpenMP is the right thing to do, but it is on the different scale.

For now, it would be fine to make it work on native Clang. I will update the PR so that it hopefully does not break the usage of OpenMP with a non-native Clang.

@davydden davydden force-pushed the openblas_openmp_clang branch from b4c841b to ccbc4fb Compare April 20, 2016 12:17
@davydden
Copy link
Copy Markdown
Member Author

i updated the PR, @eschnett : could you please check that it does not break the usage of MacPorts clang which does support OpenMP? (i don't have Macports myself).

@davydden davydden force-pushed the openblas_openmp_clang branch 2 times, most recently from 1db989b to e781716 Compare April 20, 2016 12:25
@eschnett
Copy link
Copy Markdown
Contributor

@davydden I'll check.

Note that anybody can test this, as the current condition does not depend on whether one uses OS X or not. Testing with clang on Linux would answer the question as well.

Having said this, I don't think the test is right. This test will disallow all versions of clang up to and including 7.3.0. I don't think that Spack matches against the -apple suffix.

@davydden
Copy link
Copy Markdown
Member Author

davydden commented Apr 20, 2016

@eschnett i updated the test to @5.0.0-apple:7.3.0-apple. This would work for a while, at least until clang will get to version 5.

@eschnett
Copy link
Copy Markdown
Contributor

Funny, I just see this:

ifeq ($(C_COMPILER), CLANG)
$(error OpenBLAS: Clang didn't support OpenMP yet.)
CCOMMON_OPT    += -fopenmp
endif

That is, OpenBlas (!) hardcodes that OpenMP cannot be used with a compiler called clang. (This is OpenBLAS 0.2.17.) Given this, we should do the same in our package -- any compiler called clang (independent of the operating system) should be disallowed with +openmp.

That also means that the current check in package.py in this pull request is working fine.

@davydden
Copy link
Copy Markdown
Member Author

so are you suggesting to change from

if spec.satisfies('%[email protected]:7.3.0-apple'):

to

if spec.satisfies('%clang'):

with an appropriate comment that Openblas hardcoded that OpenMP cannot be used with any clang?

@eschnett
Copy link
Copy Markdown
Contributor

@davydden Yes, exactly.

@eschnett
Copy link
Copy Markdown
Contributor

Also, OpenBLAS 0.2.18 has been released. Let me check whether it handles things differently -- if so, we will need your more complex condition after all.

@davydden
Copy link
Copy Markdown
Member Author

ok...

@eschnett
Copy link
Copy Markdown
Contributor

eschnett commented Apr 20, 2016

No change with OpenBLAS 0.2.18; it still checks for clang.

@adamjstewart
Copy link
Copy Markdown
Member

Might as well add 0.2.18 as part of this PR then.

I agree that the easiest thing to do is probably just to remove the variant altogether and always build with OpenMP unless the compiler is %clang.

@davydden
Copy link
Copy Markdown
Member Author

@eschnett @adamjstewart i updated the PR to do OpenMP always unless we use clang.

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Apr 20, 2016

@davydden openblas~openmp is needed e.g. by multi-threaded applications whose logic is parallelized at a different level than lapack-blas

@davydden
Copy link
Copy Markdown
Member Author

@alalazo: ok, i see. I will put back the variant...

@adamjstewart
Copy link
Copy Markdown
Member

Great. I guess let's keep it as a variant then? Would everyone like to vote on defaulting to True or False?

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Apr 20, 2016

@davydden @adamjstewart Any default value for the variant would do for me.

@davydden davydden force-pushed the openblas_openmp_clang branch from c609975 to b4cb956 Compare April 20, 2016 14:38
@davydden
Copy link
Copy Markdown
Member Author

@adamjstewart @alalazo @eschnett : updated the PR with a variant.

@adamjstewart
Copy link
Copy Markdown
Member

Looks good to me!

# What is worse, Openblas (as of 0.2.18) hardcoded that OpenMP cannot
# be used with any (!) compiler named clang, bummer.
if spec.satisfies('%clang'):
raise InstallError('OpenMP is not currently supported by Openblas with Clang! Install without +openmp')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It'd say instead OpenBLAS does not support OpenMP with clang instead.

Yes, looks good.

@davydden
Copy link
Copy Markdown
Member Author

What if you revert the last change and open a new PR for this test?

will do.

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Apr 25, 2016

@davydden Thank you very much

@davydden
Copy link
Copy Markdown
Member Author

@alalazo for consistency, you may want to comment on this PR with which I was inspired with #812

@davydden davydden force-pushed the openblas_openmp_clang branch from 258bc43 to 2dd9f5a Compare April 25, 2016 11:31
@alalazo
Copy link
Copy Markdown
Member

alalazo commented Apr 25, 2016

@davydden Thanks for pointing me to that, I am quite behind the schedule of my notifications and missed #812 😄

@davydden
Copy link
Copy Markdown
Member Author

@alalazo i move this commit to another PR. This one is clean again and should be ready to merge.

@davydden
Copy link
Copy Markdown
Member Author

@tgamblin this is ready to merge 👍 😄

@davydden davydden force-pushed the openblas_openmp_clang branch from 8c0e1f8 to 26029ef Compare April 30, 2016 17:43
@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 7, 2016

@tgamblin @trws ping-ping 😄

@davydden davydden force-pushed the openblas_openmp_clang branch from 26029ef to 72b9175 Compare May 8, 2016 14:51
@trws
Copy link
Copy Markdown
Contributor

trws commented May 9, 2016

Changing the default seems reasonable. I'm coming to this late, but why have spack print an error rather than just let the package fail? Either way, the result is the same, but this way there will be more work to do in spack if and when they fix their clang+openmp handling right?

@adamjstewart
Copy link
Copy Markdown
Member

@trws: Openblas takes like 45 minutes to build. I would rather have Spack fail instantly than have Openblas fail much later. But what we could do is call compiler.openmp_flag. The flag itself wouldn't be useful, but it would be able to determine whether or not the compiler supports OpenMP and raise an error if it doesn't. Does that seem reasonable @davydden?

@trws
Copy link
Copy Markdown
Contributor

trws commented May 9, 2016

Is that functionality going in like that @adamjstewart? I'm all good with checking whether the compiler supports OpenMP and bailing early (really that's what their build system should do...), but encoding it the way they did just based on the compiler name feels wrong is all.

@alalazo
Copy link
Copy Markdown
Member

alalazo commented May 9, 2016

@adamjstewart Maybe I remember it the wrong way, but the clang+OpenMP combination fails immediatly...

@adamjstewart
Copy link
Copy Markdown
Member

Is that functionality going in like that @adamjstewart?

It will when #882 gets merged :)

@alalazo: That's good. I guess either one would be fine, but calling compiler.openmp_flag would produce a more useful error message and would be quicker than reading through a config.log. That's just my opinion on it.

@trws
Copy link
Copy Markdown
Contributor

trws commented May 9, 2016

I'll probably comment on #882, but having it be based on flags rather than capabilities feels odd. Build systems shouldn't count on spack to supply the right flag for a compiler like that, either way though checking functionality is a good thing.

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 9, 2016

@adamjstewart:

But what we could do is call compiler.openmp_flag.

That would rule out Apple's clang (after #882 is merged), which does not support openmp as of now, but we still need to fail with openmp+any clang as openblas assumes no clang can ever support openmp.

@trws

this way there will be more work to do in spack if and when they fix their clang+openmp handling right

correct. But I think it's still better to make it fail before with some reasonable message. Otherwise it fails to configure (hopefully during configure and not compilation) and then the user needs to dig into logs to see what's wrong.

@adamjstewart
Copy link
Copy Markdown
Member

Ah, you're right. In that case, I'm good with the way things are now.

@trws
Copy link
Copy Markdown
Contributor

trws commented May 9, 2016

It does, for now, but they will eventually regain their sanity and fix their build system. I'd rather not have to have someone come back in and special-case this again because of it.

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 9, 2016

@trws so you suggest to keep openmp false by default and let the user debug the logs in case he tries to compile with openmp and clang?

@trws
Copy link
Copy Markdown
Contributor

trws commented May 9, 2016

Either that, or do an actual check for whether it does or does not support OpenMP, yes.

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 9, 2016

whether it does or does not support OpenMP, yes.

by it you mean openblas or compiler? The current check is essentially an unconditional check for openblas.

@eschnett
Copy link
Copy Markdown
Contributor

eschnett commented May 9, 2016

I think Spack should contain logic to help people navigate broken build systems. If ./configure; make; make install worked fine, then there'd be little need for a tool such as Spack. But this is the real world, and things are broken and require work-arounds, and Spack should help people as much as it can. These helpers will necessarily be dirty and system-specific and version-specific, but there's no other place to put them but in Spack.

If all it takes is a single if statement to make things easier for myself down the line when I forgot about this conversation, then please, add it, even if it needs to be changed in the future.

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 9, 2016

i agree with @eschnett and would suggest to keep it the way it is now with a code comment which explains the problem and a readable error message for a user.

@tgamblin tgamblin merged commit ccccd7b into spack:develop May 10, 2016
@davydden davydden deleted the openblas_openmp_clang branch May 28, 2017 20:57
olupton pushed a commit to olupton/spack that referenced this pull request Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

default openblas fails with clang

6 participants