Skip to content

Commit

Permalink
Merge pull request #1565 from ocaisa/default_opt
Browse files Browse the repository at this point in the history
Allow user to define the default compiler optimsation level
  • Loading branch information
boegel committed Jan 23, 2016
2 parents 514db22 + f66f193 commit 1a33d35
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions easybuild/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def mk_full_default_path(name, prefix=DEFAULT_PREFIX):
GENERAL_CLASS: [
'suffix_modules_path',
],
'defaultopt': [
'default_opt_level',
]
}
# build option that do not have a perfectly matching command line option
BUILD_OPTIONS_OTHER = {
Expand Down
3 changes: 3 additions & 0 deletions easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from easybuild.tools.ordereddict import OrderedDict
from easybuild.tools.run import run_cmd
from easybuild.tools.package.utilities import avail_package_naming_schemes
from easybuild.tools.toolchain.compiler import DEFAULT_OPT_LEVEL, Compiler
from easybuild.tools.toolchain.utilities import search_toolchain
from easybuild.tools.repository.repository import avail_repositories
from easybuild.tools.version import this_is_easybuild
Expand Down Expand Up @@ -213,6 +214,8 @@ def override_options(self):
'cleanup-builddir': ("Cleanup build dir after successful installation.", None, 'store_true', True),
'cleanup-tmpdir': ("Cleanup tmp dir after successful run.", None, 'store_true', True),
'color': ("Allow color output", None, 'store_true', True),
'default-opt-level': ("Specify default optimisation level", 'choice', 'store', DEFAULT_OPT_LEVEL,
Compiler.COMPILER_OPT_FLAGS),
'deprecated': ("Run pretending to be (future) version, to test removal of deprecated code.",
None, 'store', None),
'download-timeout': ("Timeout for initiating downloads (in seconds)", float, 'store', None),
Expand Down
18 changes: 13 additions & 5 deletions easybuild/tools/toolchain/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
from easybuild.tools.toolchain.constants import COMPILER_VARIABLES
from easybuild.tools.toolchain.toolchain import Toolchain

# default optimization 'level' (see COMPILER_SHARED_OPTION_MAP/COMPILER_OPT_FLAGS)
DEFAULT_OPT_LEVEL = 'defaultopt'

# 'GENERIC' can beused to enable generic compilation instead of optimized compilation (which is the default)
# 'GENERIC' can be used to enable generic compilation instead of optimized compilation (which is the default)
# by doing eb --optarch=GENERIC
OPTARCH_GENERIC = 'GENERIC'

Expand Down Expand Up @@ -63,7 +65,7 @@ class Compiler(Toolchain):
'pic': (False, "Use PIC"), # also FFTW
'noopt': (False, "Disable compiler optimizations"),
'lowopt': (False, "Low compiler optimizations"),
'defaultopt': (False, "Default compiler optimizations"), # not set, but default
DEFAULT_OPT_LEVEL: (False, "Default compiler optimizations"), # not set, but default
'opt': (False, "High compiler optimizations"),
'optarch': (True, "Enable architecture optimizations"),
'strict': (False, "Strict (highest) precision"),
Expand Down Expand Up @@ -94,7 +96,7 @@ class Compiler(Toolchain):
'shared': 'shared',
'noopt': 'O0',
'lowopt': 'O1',
'defaultopt': 'O2',
DEFAULT_OPT_LEVEL: 'O2',
'opt': 'O3',
'32bit' : 'm32',
'cstd': 'std=%(value)s',
Expand All @@ -104,7 +106,7 @@ class Compiler(Toolchain):
COMPILER_GENERIC_OPTION = None

COMPILER_FLAGS = ['debug', 'verbose', 'static', 'shared', 'openmp', 'pic', 'unroll'] # any compiler
COMPILER_OPT_FLAGS = ['noopt', 'lowopt', 'defaultopt', 'opt'] # optimisation args, ordered !
COMPILER_OPT_FLAGS = ['noopt', 'lowopt', DEFAULT_OPT_LEVEL, 'opt'] # optimisation args, ordered !
COMPILER_PREC_FLAGS = ['strict', 'precise', 'defaultprec', 'loose', 'veryloose'] # precision flags, ordered !

COMPILER_CC = None
Expand Down Expand Up @@ -231,9 +233,15 @@ def _set_compiler_flags(self):
fflags = [self.options.option(x) for x in self.COMPILER_F_FLAGS + self.COMPILER_F_UNIQUE_FLAGS \
if self.options.get(x, False)]

# Allow a user-defined default optimisation
default_opt_level = build_option('default_opt_level')
if default_opt_level not in self.COMPILER_OPT_FLAGS:
raise EasyBuildError("Unknown value for default optimisation: %s (possibilities are %s)" %
(default_opt_level, self.COMPILER_OPT_FLAGS))

# 1st one is the one to use. add default at the end so len is at least 1
optflags = [self.options.option(x) for x in self.COMPILER_OPT_FLAGS if self.options.get(x, False)] + \
[self.options.option('defaultopt')]
[self.options.option(default_opt_level)]

optarchflags = []
if build_option('optarch') == OPTARCH_GENERIC:
Expand Down

0 comments on commit 1a33d35

Please sign in to comment.