Skip to content

Compiler::openmp_flag()#882

Merged
tgamblin merged 17 commits intospack:developfrom
davydden:openmp_compiler_flag
May 9, 2016
Merged

Compiler::openmp_flag()#882
tgamblin merged 17 commits intospack:developfrom
davydden:openmp_compiler_flag

Conversation

@davydden
Copy link
Copy Markdown
Member

@davydden davydden commented May 3, 2016

fixes #876

@adamjstewart ping.

@davydden davydden force-pushed the openmp_compiler_flag branch from 5053480 to 524230b Compare May 3, 2016 09:10
'fc' : 'intel/ifort' }

@property
def openmp_flag(self):
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.

I think it's -qopenmp in the latest version.

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.

do you know from which version?

Copy link
Copy Markdown
Member Author

@davydden davydden May 3, 2016

Choose a reason for hiding this comment

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

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.

I can't find a web page showcasing it, but the change should start from 16:

$ icc --version
icc (ICC) 16.0.2 20160204
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

$ icc -openmp main.c
icc: command line remark #10411: option '-openmp' is deprecated and will be removed in a future release. Please use the replacement option '-qopenmp'

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.

ok, i will add a check for 16.0...

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 3, 2016

there is a fancy issue. I am testing the two methods by calling them in package

    def install(self, spec, prefix):
        cxx11_compiler_flag  = self.compiler.cxx11_flag()
        openmp_compiler_flag = self.compiler.openmp_flag()

which ends up with an error

==> Building openblas
Traceback (most recent call last):
  File "/Users/davydden/spack/lib/spack/spack/build_environment.py", line 367, in fork
    function()
  File "/Users/davydden/spack/lib/spack/spack/package.py", line 913, in build_process
    self.install(self.spec, self.prefix)
  File "/Users/davydden/spack/var/spack/repos/builtin/packages/openblas/package.py", line 25, in install
    cxx11_compiler_flag  = self.compiler.cxx11_flag()
TypeError: 'str' object is not callable
==> Error: Installation process had nonzero exit code.

Interestingly enough this

def install(self, spec, prefix):
        # cxx11_compiler_flag  = self.compiler.cxx11_flag()
        openmp_compiler_flag = self.compiler.openmp_flag()

works just fine. I don't understand how this is possible. Any advices from the python gurus 😄 ?

@alalazo
Copy link
Copy Markdown
Member

alalazo commented May 3, 2016

Take a look at the @property decorator... 😄

You don't need the function call syntax to execute that code : from the client point of view it will look like accessing an attribute. What happens in your error is that you got a string returned with :

self.compiler.cxx11_flag

and then you try to __call__ the string, hence:

TypeError: 'str' object is not callable

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 3, 2016

@alalazo thanks for explanations 👍 I learned something new today 😄

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 3, 2016

Ok, i checked both functions and they work as expected for Apple's clang and gcc. So it should be good as far as I can see.

@davydden davydden force-pushed the openmp_compiler_flag branch from 355612e to bd850e4 Compare May 3, 2016 12:59
@davydden davydden changed the title Compiler::openmp_flag() plus minor fixes Compiler::openmp_flag() May 3, 2016
@davydden davydden force-pushed the openmp_compiler_flag branch 2 times, most recently from 3101db1 to 355612e Compare May 3, 2016 13:08
@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 3, 2016

@alalazo i deleted the last comment as I found out this is not the case.

if ver_string.endswith('-apple'):
return True
else:
return False
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.

I think a more Pythonic implementation would be:

return ver_string.endswith('-apple')

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.

Actually, this would be even better:

@property
def is_apple(self):
    ver_string = str(self.version)
    return ver_string.endswith('-apple')

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.

will do, looks much better!

@adamjstewart
Copy link
Copy Markdown
Member

Wow, this looks way better than my implementation. Can you add a default openmp_flag() and cxx11_flag() to the Compiler class in lib/spack/spack/compiler.py? They can either return a default string, or just return an error message saying that this function hasn't been implemented yet for this particular compiler. Then, each compiler will override it as necessary. This should handle compilers that don't implement cxx11_flag().

@property
def cxx11_flag(self):
tty.die("cxx11_flag() is not implemented for pgi. Consider creating a pull-request.")
return "-std=c++11"
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.

From the man page for pgc++, it appears that PGI accepts either -std=c++11 or --c++11 so you can remove this message.

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 3, 2016

@adamjstewart i (hopefully) addressed you comments.

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 3, 2016

there is also

    # argument used to get C++11 options
    cxx11_flag = "-std=c++11"

in the Compiler.py. I think this should be removed as all dervied classes use @property instead anyway and now Compiler class additionally has a default implementation

    @property
    def cxx11_flag(self):
        return "-std=c++11"

# Override in derived classes if needed
@property
def cxx11_flag(self):
return "-std=c++11"
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.

The more I think about it, these properties should probably look something like:

# This property should be overridden in the compiler subclass if
# OpenMP is supported by that compiler
@property
def openmp_flag(self):
    # If it is not overridden, assume it is not supported and warn the user
    tty.die("The compiler you have chosen does not currently support OpenMP. If you think it should, please edit the compiler subclass and submit a pull request or issue.")


# This property should be overridden in the compiler subclass if
# C++11 is supported by that compiler
@property
def cxx11_flag(self):
    # If it is not overridden, assume it is not supported and warn the user
    tty.die("The compiler you have chosen does not currently support C++11. If you think it should, please edit the compiler subclass and submit a pull request or issue.")

The benefit of this is that if someone adds a new compiler but forgets to override these properties, or the compiler does not support them, Spack warns the user. Otherwise, the current implementation will just use the wrong flag and crash. Feel free to shorten up the message if you want.

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.

sounds good to me, will change the behaviour.

@adamjstewart
Copy link
Copy Markdown
Member

@davydden: Yes, I agree about removing:

# argument used to get C++11 options
cxx11_flag = "-std=c++11"

from compilers.py. Your property is replacing this variable.

@davydden davydden force-pushed the openmp_compiler_flag branch from 6937081 to f84f045 Compare May 5, 2016 08:48
@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 5, 2016

@gartung since I substitute a cxx14_flag attributed introduced in #802 by a property with the same name, i though you might want give a quick look.

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 5, 2016

quickly documented the usage of compiler flags.

@gartung
Copy link
Copy Markdown
Member

gartung commented May 5, 2016

Submitted this a while back. Your feature is probably more correct. Feel free to remove my change if needed.

@eschnett
Copy link
Copy Markdown
Contributor

eschnett commented May 5, 2016

I notice there are efforts to add OpenMP flags, C++14 flags, and names of executables such as mpicc. For consistency, they should all use the same kind of mechanism. I didn't check -- is this already the case?

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 5, 2016

no, they don't. Flags are done using @property which is overriden in derived clasess. Compiler flags are queried directly in a package. Whereas mpicc and alike are set in setup_dependent_package as they are used in packages which depend on them. This follows the logic introduced here #657 . I personally don't see a problem with that and don't think one has to use the same mechanism as the two are different.

@property
def openmp_flag(self):
# If it is not overridden, assume it is not supported and warn the user
tty.die("The compiler you have chosen does not currently support OpenMP. If you think it should, please edit the compiler subclass and submit a pull request or issue.")
Copy link
Copy Markdown
Member

@tgamblin tgamblin May 9, 2016

Choose a reason for hiding this comment

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

can these lines be made <80chars?

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.

sure they can 😄 i am on it...

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.

[Commercial] pull-in #375 with line length 80 chars ? 😄

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.

@alalazo: good idea!

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.

@alalazo: pretty sure your screen is at like 120 or something

@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented May 9, 2016

@davydden @alalazo @adamjstewart @gartung thanks! this look great. I'll just shorten a few lines and merge.

@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented May 9, 2016

@eschnett: if compilers are made into dependencies eventually these could potentially use similar mechanisms. Right now since they're special they're a little different.

@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented May 9, 2016

@davydden: ok I'll let you shorten the lines :)

@davydden
Copy link
Copy Markdown
Member Author

davydden commented May 9, 2016

@tgamblin shortened 😄

@tgamblin tgamblin merged commit cbae986 into spack:develop May 9, 2016
@davydden davydden deleted the openmp_compiler_flag 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.

openmp link flags for compilers

6 participants