Skip to content

Commit

Permalink
Add test to check for old and new optarch syntax. Add deprecation war…
Browse files Browse the repository at this point in the history
…ning.
  • Loading branch information
Micket committed Nov 12, 2024
1 parent 47d824e commit b4d7001
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 40 deletions.
7 changes: 6 additions & 1 deletion easybuild/tools/toolchain/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Damian Alvarez (Forschungszentrum Juelich GmbH)
"""
from easybuild.tools import systemtools
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.build_log import EasyBuildError, print_warning
from easybuild.tools.config import build_option
from easybuild.tools.toolchain.constants import COMPILER_VARIABLES
from easybuild.tools.toolchain.toolchain import Toolchain
Expand Down Expand Up @@ -349,6 +349,11 @@ def _set_optimal_architecture(self, default_optarch=None):
optarch = self.COMPILER_OPTIMAL_ARCHITECTURE_OPTION[(self.arch, self.cpu_family)]

if optarch is not None:
if not optarch.startswith('-'):
print_warning(f'Specifying optarch "{optarch}" without initial dash is deprecated in EasyBuild 5.')
# Add flags for backwards compatibility
optarch = '-' + optarch

optarch_log_str = optarch or 'no flags'
self.log.info("_set_optimal_architecture: using %s as optarch for %s/%s.",
optarch_log_str, self.arch, self.cpu_family)
Expand Down
79 changes: 41 additions & 38 deletions test/framework/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2189,47 +2189,50 @@ def test_independence(self):
"""Test independency of toolchain instances."""

# tweaking --optarch is required for Cray toolchains (craypre-<optarch> module must be available)
init_config(build_options={'optarch': 'test', 'silent': True})
custom_optarchs = ['test', '-test'] # specifying without initial - is deprecated but should still work
for custom_optarch in custom_optarchs:
init_config(build_options={'optarch': custom_optarch, 'silent': True})

tc_cflags = {
'CrayCCE': "-O2 -homp -craype-verbose",
'CrayGNU': "-O2 -fno-math-errno -fopenmp -craype-verbose",
'CrayIntel': "-O2 -ftz -fp-speculation=safe -fp-model source -fopenmp -craype-verbose",
'GCC': "-O2 -ftree-vectorize -test -fno-math-errno -fopenmp",
'iccifort': "-O2 -test -ftz -fp-speculation=safe -fp-model source -fopenmp",
'intel-compilers': "-O2 -test -ftz -fp-speculation=safe -fp-model precise -qopenmp",
}

tc_cflags = {
'CrayCCE': "-O2 -homp -craype-verbose",
'CrayGNU': "-O2 -fno-math-errno -fopenmp -craype-verbose",
'CrayIntel': "-O2 -ftz -fp-speculation=safe -fp-model source -fopenmp -craype-verbose",
'GCC': "-O2 -ftree-vectorize -test -fno-math-errno -fopenmp",
'iccifort': "-O2 -test -ftz -fp-speculation=safe -fp-model source -fopenmp",
'intel-compilers': "-O2 -test -ftz -fp-speculation=safe -fp-model precise -qopenmp",
}
toolchains = [
('CrayCCE', '2015.06-XC'),
('CrayGNU', '2015.06-XC'),
('CrayIntel', '2015.06-XC'),
('GCC', '6.4.0-2.28'),
('iccifort', '2018.1.163'),
('intel-compilers', '2022.1.0'),
]

toolchains = [
('CrayCCE', '2015.06-XC'),
('CrayGNU', '2015.06-XC'),
('CrayIntel', '2015.06-XC'),
('GCC', '6.4.0-2.28'),
('iccifort', '2018.1.163'),
('intel-compilers', '2022.1.0'),
]
# purposely obtain toolchains several times in a row, value for $CFLAGS should not change
for _ in range(3):
for tcname, tcversion in toolchains:
# Cray* modules do not unload other Cray* modules thus loading a second Cray* module
# makes environment inconsistent which is not allowed by Environment Modules tool
if isinstance(self.modtool, EnvironmentModules):
self.modtool.purge()
tc = get_toolchain({'name': tcname, 'version': tcversion}, {},
mns=ActiveMNS(), modtool=self.modtool)
# also check whether correct compiler flag for OpenMP is used while we're at it
# and options for oneAPI compiler for Intel
if tcname == 'intel-compilers':
tc.set_options({'oneapi': True, 'openmp': True})
else:
tc.set_options({'openmp': True})
with self.mocked_stdout_stderr():
tc.prepare()
expected_cflags = tc_cflags[tcname]
msg = "Expected $CFLAGS found for toolchain %s: %s" % (tcname, expected_cflags)
self.assertEqual(str(tc.variables['CFLAGS']), expected_cflags, msg)
self.assertEqual(os.environ['CFLAGS'], expected_cflags, msg)

# purposely obtain toolchains several times in a row, value for $CFLAGS should not change
for _ in range(3):
for tcname, tcversion in toolchains:
# Cray* modules do not unload other Cray* modules thus loading a second Cray* module
# makes environment inconsistent which is not allowed by Environment Modules tool
if isinstance(self.modtool, EnvironmentModules):
self.modtool.purge()
tc = get_toolchain({'name': tcname, 'version': tcversion}, {},
mns=ActiveMNS(), modtool=self.modtool)
# also check whether correct compiler flag for OpenMP is used while we're at it
# and options for oneAPI compiler for Intel
if tcname == 'intel-compilers':
tc.set_options({'oneapi': True, 'openmp': True})
else:
tc.set_options({'openmp': True})
with self.mocked_stdout_stderr():
tc.prepare()
expected_cflags = tc_cflags[tcname]
msg = "Expected $CFLAGS found for toolchain %s: %s" % (tcname, expected_cflags)
self.assertEqual(str(tc.variables['CFLAGS']), expected_cflags, msg)
self.assertEqual(os.environ['CFLAGS'], expected_cflags, msg)

def test_pgi_toolchain(self):
"""Tests for PGI toolchain."""
Expand Down
2 changes: 1 addition & 1 deletion test/framework/toolchainvariables.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class TCV(ToolchainVariables):

tcv.nappend('MPICH_CC', 'icc', var_class=CommandFlagList)
self.assertEqual(str(tcv['MPICH_CC']), "icc")
tcv.nappend('MPICH_CC', 'test')
tcv.nappend('MPICH_CC', '-test')
self.assertEqual(str(tcv['MPICH_CC']), "icc -test")


Expand Down

0 comments on commit b4d7001

Please sign in to comment.