@@ -81,7 +81,7 @@ def get_parser():
81
81
g_perfm = parser .add_argument_group ('Options to handle performance' )
82
82
g_perfm .add_argument ('--debug' , action = 'store_true' , default = False ,
83
83
help = 'run debug version of workflow' )
84
- g_perfm .add_argument ('--nthreads' , '--n_cpus' , '-n-cpus' , action = 'store' , default = 0 , type = int ,
84
+ g_perfm .add_argument ('--nthreads' , '--n_cpus' , '-n-cpus' , action = 'store' , type = int ,
85
85
help = 'maximum number of threads across all processes' )
86
86
g_perfm .add_argument ('--omp-nthreads' , action = 'store' , type = int , default = 0 ,
87
87
help = 'maximum number of threads per-process' )
@@ -416,28 +416,35 @@ def build_workflow(opts, retval):
416
416
subject_list = collect_participants (
417
417
bids_dir , participant_label = opts .participant_label )
418
418
419
- # Setting up MultiProc
420
- nthreads = opts .nthreads
421
- if nthreads < 1 :
422
- nthreads = cpu_count ()
423
-
424
- plugin_settings = {
425
- 'plugin' : 'MultiProc' ,
426
- 'plugin_args' : {
427
- 'n_procs' : nthreads ,
428
- 'raise_insufficient' : False ,
429
- 'maxtasksperchild' : 1 ,
430
- }
431
- }
432
-
433
- if opts .mem_mb :
434
- plugin_settings ['plugin_args' ]['memory_gb' ] = opts .mem_mb / 1024
435
-
436
- # Overload plugin_settings if --use-plugin
419
+ # Load base plugin_settings from file if --use-plugin
437
420
if opts .use_plugin is not None :
438
421
from yaml import load as loadyml
439
422
with open (opts .use_plugin ) as f :
440
423
plugin_settings = loadyml (f )
424
+ plugin_settings .set_default ('plugin_args' , {})
425
+ else :
426
+ # Defaults
427
+ plugin_settings = {
428
+ 'plugin' : 'MultiProc' ,
429
+ 'plugin_args' : {
430
+ 'raise_insufficient' : False ,
431
+ 'maxtasksperchild' : 1 ,
432
+ }
433
+ }
434
+
435
+ # Resource management options
436
+ # Note that we're making strong assumptions about valid plugin args
437
+ # This may need to be revisited if people try to use batch plugins
438
+ nthreads = plugin_settings ['plugin_args' ].get ('n_procs' )
439
+ # Permit overriding plugin config with specific CLI options
440
+ if nthreads is None or opts .nthreads is not None :
441
+ nthreads = opts .nthreads
442
+ if nthreads is None or nthreads < 1 :
443
+ nthreads = cpu_count ()
444
+ plugin_settings ['plugin_args' ]['n_procs' ] = nthreads
445
+
446
+ if opts .mem_mb :
447
+ plugin_settings ['plugin_args' ]['memory_gb' ] = opts .mem_mb / 1024
441
448
442
449
omp_nthreads = opts .omp_nthreads
443
450
if omp_nthreads == 0 :
0 commit comments