4949from easybuild .framework .extensioneasyblock import ExtensionEasyBlock
5050from easybuild .tools import LooseVersion , config
5151from easybuild .tools .build_log import EasyBuildError
52- from easybuild .tools .config import get_module_syntax , update_build_option
52+ from easybuild .tools .config import get_module_syntax
5353from easybuild .tools .environment import modify_env
5454from easybuild .tools .filetools import change_dir , copy_dir , copy_file , mkdir , read_file , remove_dir , remove_file
5555from easybuild .tools .filetools import symlink , verify_checksum , write_file
@@ -2529,7 +2529,7 @@ def test_parallel(self):
25292529 write_file (toy_ec5 , toytxt + "\n maxparallel = False" )
25302530
25312531 # default: parallelism is derived from # available cores + ulimit
2532- # Note that maxparallel has a default of 16, so we need a lower auto_parallel value here
2532+ # Note that --max-parallel has a default of 16, so we need a lower auto_parallel value here
25332533 auto_parallel = 16 - 4 # Using + 3 below which must still be less
25342534 st .det_parallelism ._default_parallelism = auto_parallel
25352535
@@ -2565,7 +2565,10 @@ def test_parallel(self):
25652565 buildopt_parallel = 11
25662566 # When build option is given the auto-parallelism is ignored. Verify by setting it very low
25672567 st .det_parallelism ._default_parallelism = 2
2568- init_config (build_options = {'parallel' : str (buildopt_parallel ), 'validate' : False })
2568+ init_config (build_options = {
2569+ 'parallel' : str (buildopt_parallel ),
2570+ 'validate' : False ,
2571+ })
25692572
25702573 test_cases = {
25712574 '' : buildopt_parallel ,
@@ -2583,6 +2586,61 @@ def test_parallel(self):
25832586 'parallel = 8\n maxparallel = False' : 1 ,
25842587 }
25852588
2589+ for txt , expected in test_cases .items ():
2590+ with self .subTest (ec_params = txt ):
2591+ self .contents = toytxt + '\n ' + txt
2592+ self .writeEC ()
2593+ with self .temporarily_allow_deprecated_behaviour (), self .mocked_stdout_stderr ():
2594+ test_eb = EasyBlock (EasyConfig (self .eb_file ))
2595+ test_eb .post_init ()
2596+ self .assertEqual (test_eb .cfg .parallel , expected )
2597+ with self .temporarily_allow_deprecated_behaviour (), self .mocked_stdout_stderr ():
2598+ self .assertEqual (test_eb .cfg ['parallel' ], expected )
2599+
2600+ # re-check when --max-parallel is used instead
2601+ buildopt_max_parallel = 8
2602+ st .det_parallelism ._default_parallelism = 16
2603+ init_config (build_options = {
2604+ 'max_parallel' : buildopt_max_parallel ,
2605+ 'validate' : False ,
2606+ })
2607+
2608+ test_cases = {
2609+ '' : buildopt_max_parallel ,
2610+ 'parallel = False' : 1 ,
2611+ 'parallel = 1' : 1 ,
2612+ 'parallel = 6' : 6 ,
2613+ # --max-parallel value limits max. parallelism, so only 8 cores will be used when 'parallel = 10' is used
2614+ f'parallel = { buildopt_max_parallel + 2 } ' : buildopt_max_parallel ,
2615+ 'maxparallel = False' : 1 ,
2616+ 'maxparallel = 1' : 1 ,
2617+ 'maxparallel = 6' : 6 ,
2618+ # minimum of 'maxparallel' easyconfig parameter and --max-parallel configuration option is used
2619+ f'maxparallel = { buildopt_max_parallel + 2 } ' : buildopt_max_parallel ,
2620+ 'parallel = 8\n maxparallel = 6' : 6 ,
2621+ 'parallel = 8\n maxparallel = 9' : 8 ,
2622+ 'parallel = False\n maxparallel = 6' : 1 ,
2623+ 'parallel = 8\n maxparallel = False' : 1 ,
2624+ }
2625+
2626+ for txt , expected in test_cases .items ():
2627+ with self .subTest (ec_params = txt ):
2628+ self .contents = toytxt + '\n ' + txt
2629+ self .writeEC ()
2630+ with self .temporarily_allow_deprecated_behaviour (), self .mocked_stdout_stderr ():
2631+ test_eb = EasyBlock (EasyConfig (self .eb_file ))
2632+ test_eb .post_init ()
2633+ self .assertEqual (test_eb .cfg .parallel , expected )
2634+ with self .temporarily_allow_deprecated_behaviour (), self .mocked_stdout_stderr ():
2635+ self .assertEqual (test_eb .cfg ['parallel' ], expected )
2636+
2637+ # re-check when both --max-parallel and --parallel are used (--max-parallel wins)
2638+ init_config (build_options = {
2639+ 'max_parallel' : buildopt_max_parallel ,
2640+ 'parallel' : buildopt_parallel ,
2641+ 'validate' : False ,
2642+ })
2643+
25862644 for txt , expected in test_cases .items ():
25872645 with self .subTest (ec_params = txt ):
25882646 self .contents = toytxt + '\n ' + txt
@@ -2617,13 +2675,13 @@ def test_parallel(self):
26172675 self .writeEC ()
26182676 with self .temporarily_allow_deprecated_behaviour (), self .mocked_stdout_stderr ():
26192677 test_eb = EasyBlock (EasyConfig (self .eb_file ))
2620- parallel = buildopt_parallel - 2
2678+ parallel = buildopt_max_parallel - 2
26212679 test_eb .cfg ['parallel' ] = parallel # Old Easyblocks might change that before the ready step
26222680 test_eb .post_init ()
26232681 self .assertEqual (test_eb .cfg .parallel , parallel )
26242682 self .assertEqual (test_eb .cfg ['parallel' ], parallel )
26252683 # Afterwards it also gets reflected directly ignoring maxparallel
2626- parallel = buildopt_parallel * 3
2684+ parallel = buildopt_max_parallel * 3
26272685 test_eb .cfg ['parallel' ] = parallel
26282686 self .assertEqual (test_eb .cfg .parallel , parallel )
26292687 self .assertEqual (test_eb .cfg ['parallel' ], parallel )
0 commit comments