Skip to content

Commit 57b053e

Browse files
committed
introduce get_parallel_ec_param_value function to determine value for 'parallel' easyconfig parameter for easyblock and extensions
1 parent 50030cd commit 57b053e

4 files changed

Lines changed: 48 additions & 21 deletions

File tree

easybuild/framework/easyblock.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
from easybuild.base import fancylogger
5656
from easybuild.framework.easyconfig import EASYCONFIGS_PKG_SUBDIR
5757
from easybuild.framework.easyconfig.easyconfig import ITERATE_OPTIONS, EasyConfig, ActiveMNS, get_easyblock_class
58-
from easybuild.framework.easyconfig.easyconfig import get_module_path, letter_dir_for, resolve_template
58+
from easybuild.framework.easyconfig.easyconfig import get_module_path, get_parallel_ec_param_value
59+
from easybuild.framework.easyconfig.easyconfig import letter_dir_for, resolve_template
5960
from easybuild.framework.easyconfig.format.format import SANITY_CHECK_PATHS_DIRS, SANITY_CHECK_PATHS_FILES
6061
from easybuild.framework.easyconfig.parser import fetch_parameters_from_easyconfig
6162
from easybuild.framework.easyconfig.style import MAX_LINE_LENGTH
@@ -92,7 +93,7 @@
9293
from easybuild.tools.package.utilities import package
9394
from easybuild.tools.py2vs3 import extract_method_name, string_type
9495
from easybuild.tools.repository.repository import init_repository
95-
from easybuild.tools.systemtools import check_linked_shared_libs, det_parallelism, get_shared_lib_ext, use_group
96+
from easybuild.tools.systemtools import check_linked_shared_libs, get_shared_lib_ext, use_group
9697
from easybuild.tools.utilities import INDENT_4SPACES, get_class_for, nub, quote_str
9798
from easybuild.tools.utilities import remove_unwanted_chars, time2str, trace_msg
9899
from easybuild.tools.version import this_is_easybuild, VERBOSE_VERSION, VERSION
@@ -212,6 +213,8 @@ def __init__(self, ec):
212213
self.postmsg = '' # allow a post message to be set, which can be shown as last output
213214
self.current_step = None
214215

216+
self.orig_parallel = None
217+
215218
# list of loaded modules
216219
self.loaded_modules = []
217220

@@ -1789,20 +1792,13 @@ def det_iter_cnt(self):
17891792

17901793
def set_parallel(self):
17911794
"""Set 'parallel' easyconfig parameter to determine how many cores can/should be used for parallel builds."""
1792-
# set level of parallelism for build
1793-
par = build_option('parallel')
1794-
cfg_par = self.cfg['parallel']
1795-
if cfg_par is None:
1796-
self.log.debug("Desired parallelism specified via 'parallel' build option: %s", par)
1797-
elif par is None:
1798-
par = cfg_par
1799-
self.log.debug("Desired parallelism specified via 'parallel' easyconfig parameter: %s", par)
1800-
else:
1801-
par = min(int(par), int(cfg_par))
1802-
self.log.debug("Desired parallelism: minimum of 'parallel' build option/easyconfig parameter: %s", par)
1795+
# keep track of original value for 'parallel', so it can be restored before determining level
1796+
# of parallelism that can be used for extensions
1797+
self.orig_parallel = self.cfg['parallel']
1798+
1799+
par = get_parallel_ec_param_value(self.cfg, self.log)
18031800

1804-
par = det_parallelism(par, maxpar=self.cfg['maxparallel'])
1805-
self.log.info("Setting parallelism: %s" % par)
1801+
self.log.info("Setting parallelism: %s", par)
18061802
self.cfg['parallel'] = par
18071803

18081804
def remove_module_file(self):

easybuild/framework/easyconfig/easyconfig.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
from easybuild.tools.module_naming_scheme.utilities import det_hidden_modname, is_valid_module_name
7474
from easybuild.tools.modules import modules_tool
7575
from easybuild.tools.py2vs3 import OrderedDict, create_base_metaclass, string_type
76-
from easybuild.tools.systemtools import check_os_dependency, pick_dep_version
76+
from easybuild.tools.systemtools import check_os_dependency, det_parallelism, pick_dep_version
7777
from easybuild.tools.toolchain.toolchain import SYSTEM_TOOLCHAIN_NAME, is_system_toolchain
7878
from easybuild.tools.toolchain.toolchain import TOOLCHAIN_CAPABILITIES, TOOLCHAIN_CAPABILITY_CUDA
7979
from easybuild.tools.toolchain.utilities import get_toolchain, search_toolchain
@@ -1830,6 +1830,30 @@ def get_cuda_cc_template_value(self, key):
18301830
raise EasyBuildError(error_msg, key)
18311831

18321832

1833+
def get_parallel_ec_param_value(cfg, log):
1834+
"""
1835+
Get value for 'parallel' easyconfig parameter for given EasyConfig instance.
1836+
Takes into account:
1837+
* --parallel EasyBuild configuration option (if defined)
1838+
* 'parallel' easyconfig parameter (if defined)
1839+
* 'maxparallel' easyconfig parameter (if defined)
1840+
* number of available cores (incl. affinity of active EasyBuild session)
1841+
"""
1842+
# set level of parallelism for build
1843+
par = build_option('parallel')
1844+
cfg_par = cfg['parallel']
1845+
if cfg_par is None:
1846+
log.debug("Desired parallelism specified via 'parallel' build option: %s", par)
1847+
elif par is None:
1848+
par = cfg_par
1849+
log.debug("Desired parallelism specified via 'parallel' easyconfig parameter: %s", par)
1850+
else:
1851+
par = min(int(par), int(cfg_par))
1852+
log.debug("Desired parallelism: minimum of 'parallel' build option/easyconfig parameter: %s", par)
1853+
1854+
return det_parallelism(par, maxpar=cfg['maxparallel'])
1855+
1856+
18331857
def det_installversion(version, toolchain_name, toolchain_version, prefix, suffix):
18341858
"""Deprecated 'det_installversion' function, to determine exact install version, based on supplied parameters."""
18351859
old_fn = 'framework.easyconfig.easyconfig.det_installversion'

easybuild/framework/extension.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import copy
3737
import os
3838

39-
from easybuild.framework.easyconfig.easyconfig import resolve_template
39+
from easybuild.framework.easyconfig.easyconfig import get_parallel_ec_param_value, resolve_template
4040
from easybuild.framework.easyconfig.templates import TEMPLATE_NAMES_EASYBLOCK_RUN_STEP, template_constant_dict
4141
from easybuild.tools.build_log import EasyBuildError, raise_nosupport
4242
from easybuild.tools.filetools import change_dir
@@ -138,9 +138,11 @@ def __init__(self, mself, ext, extra_params=None):
138138
self.log.debug("Skipping unknown custom easyconfig parameter '%s' for extension %s/%s: %s",
139139
key, name, version, value)
140140

141-
if self.cfg['maxparallel'] and self.cfg['parallel'] > self.cfg['maxparallel']:
142-
self.cfg['parallel'] = self.cfg['maxparallel']
143-
self.log.info("Setting parallelism to %d for extension %s", self.cfg['parallel'], name)
141+
self.cfg['parallel'] = self.master.orig_parallel
142+
par = get_parallel_ec_param_value(self.cfg, self.log)
143+
self.log.info("Setting parallelism: %s", par)
144+
self.log.info("Setting parallelism to %d for extension %s", par, name)
145+
self.cfg['parallel'] = par
144146

145147
self.sanity_check_fail_msgs = []
146148

test/framework/easyblock.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,7 @@ def test_init_extensions(self):
10261026
test_ec = os.path.join(self.test_prefix, 'test.eb')
10271027
test_ec_txt = toy_ec_txt.replace("('barbar', '0.0', {", "('barbar', '0.0', {'easyblock': 'DummyExtension',")
10281028
test_ec_txt = test_ec_txt.replace("('barbar', '0.0', {", "('barbar', '0.0', {'maxparallel': 3,")
1029+
test_ec_txt = test_ec_txt.replace("('bar', '0.0', {", "('bar', '0.0', {'maxparallel': 1,")
10291030
test_ec_txt += "\nparallel = 5"
10301031
write_file(test_ec, test_ec_txt)
10311032
ec = process_easyconfig(test_ec)[0]
@@ -1048,9 +1049,13 @@ def test_init_extensions(self):
10481049
# default parallel is inherited from parent
10491050
self.assertEqual(eb.cfg['parallel'], 5)
10501051
self.assertEqual(eb.ext_instances[0].cfg['parallel'], 5)
1051-
self.assertEqual(eb.ext_instances[1].cfg['parallel'], 5)
10521052
self.assertEqual(eb.ext_instances[3].cfg['parallel'], 5)
10531053

1054+
bar_ext = eb.ext_instances[1]
1055+
self.assertEqual(bar_ext.name, 'bar')
1056+
# parallel should be set to 1 for barbar, due to maxparallel
1057+
self.assertEqual(bar_ext.cfg['parallel'], 1)
1058+
10541059
barbar_ext = eb.ext_instances[2]
10551060
self.assertEqual(barbar_ext.name, 'barbar')
10561061
# parallel should be set to 3 for barbar, due to maxparallel

0 commit comments

Comments
 (0)