Skip to content

Commit 02bba79

Browse files
committed
Enable OMP independent of nipype parallelism
Many of the programs used in C-PAC support OMP parallelism. Here we decouple OMP threads from nipype n_cpus, so that we can use OMP without graph-level parallelism.
1 parent bfa1ccd commit 02bba79

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

CPAC/utils/utils.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,7 @@ def check_system_deps(check_ants=False,
13861386
def check_config_resources(c):
13871387
# Import packages
13881388
import psutil
1389+
import warnings
13891390
from multiprocessing import cpu_count
13901391

13911392
# Init variables
@@ -1433,39 +1434,29 @@ def check_config_resources(c):
14331434
'num_participants_at_once']
14341435

14351436
# Now check ANTS
1436-
if 'ANTS' in c.registration_workflows['anatomical_registration'][
1437-
'registration']['using']:
1438-
if c.pipeline_setup['system_config']['num_ants_threads'] is None:
1439-
num_ants_cores = num_cores_per_sub
1440-
elif c.pipeline_setup['system_config']['num_ants_threads'] > \
1441-
c.pipeline_setup['system_config'][
1442-
'max_cores_per_participant']:
1443-
err_msg = 'Number of threads for ANTS: %d is greater than the ' \
1444-
'number of threads per subject: %d. Change this and ' \
1445-
'try again.' % (
1446-
c.pipeline_setup['system_config']['num_ants_threads'],
1447-
c.pipeline_setup['system_config'][
1448-
'max_cores_per_participant'])
1449-
raise Exception(err_msg)
1450-
else:
1451-
num_ants_cores = c.pipeline_setup['system_config'][
1452-
'num_ants_threads']
1437+
if c.pipeline_setup['system_config']['num_ants_threads'] is None:
1438+
num_ants_cores = num_cores_per_sub
14531439
else:
1454-
num_ants_cores = 1
1440+
if c.pipeline_setup['system_config']['num_ants_threads'] > \
1441+
c.pipeline_setup['system_config']['max_cores_per_participant']:
1442+
warn_msg = 'Number of threads for ANTS: %d is greater than the ' \
1443+
'number of threads per subject: %d.' % (
1444+
c.pipeline_setup['system_config']['num_ants_threads'],
1445+
c.pipeline_setup['system_config']['max_cores_per_participant'])
1446+
warnings.warn(warn_msg)
1447+
num_ants_cores = c.pipeline_setup['system_config']['num_ants_threads']
14551448

14561449
# Now check OMP
14571450
if c.pipeline_setup['system_config']['num_OMP_threads'] is None:
14581451
num_omp_cores = 1
1459-
elif c.pipeline_setup['system_config']['num_OMP_threads'] > \
1460-
c.pipeline_setup['system_config']['max_cores_per_participant']:
1461-
err_msg = 'Number of threads for OMP: %d is greater than the ' \
1462-
'number of threads per subject: %d. Change this and ' \
1463-
'try again.' % (c.pipeline_setup['system_config'][
1464-
'num_OMP_threads'],
1465-
c.pipeline_setup['system_config'][
1466-
'max_cores_per_participant'])
1467-
raise Exception(err_msg)
14681452
else:
1453+
if c.pipeline_setup['system_config']['num_OMP_threads'] > \
1454+
c.pipeline_setup['system_config']['max_cores_per_participant']:
1455+
warn_msg = 'Number of threads for OMP: %d is greater than the ' \
1456+
'number of threads per subject: %d.' % (
1457+
c.pipeline_setup['system_config']['num_OMP_threads'],
1458+
c.pipeline_setup['system_config']['max_cores_per_participant'])
1459+
warnings.warn(warn_msg)
14691460
num_omp_cores = c.pipeline_setup['system_config']['num_OMP_threads']
14701461

14711462
# Return memory and cores

dev/docker_data/run.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,12 @@ def run_main():
573573
args.num_ants_threads = c['pipeline_setup', 'system_config',
574574
'num_ants_threads']
575575
except KeyError:
576-
args.num_ants_threads = 3
576+
args.num_ants_threads = 1
577577
c['pipeline_setup', 'system_config', 'num_ants_threads'] = int(
578578
args.num_ants_threads)
579-
580-
c['pipeline_setup']['system_config']['num_ants_threads'] = min(
581-
c['pipeline_setup']['system_config']['max_cores_per_participant'],
582-
int(c['pipeline_setup']['system_config']['num_ants_threads'])
583-
)
579+
# couple together OMP and ANTs threads
580+
c['pipeline_setup', 'system_config', 'num_OMP_threads'] = int(
581+
args.num_ants_threads)
584582

585583
if args.random_seed:
586584
c['pipeline_setup']['system_config']['random_seed'] = \
@@ -657,6 +655,8 @@ def run_main():
657655
c['pipeline_setup']['system_config']['max_cores_per_participant']))
658656
print("Number of threads for ANTs: {0}".format(
659657
c['pipeline_setup']['system_config']['num_ants_threads']))
658+
print("Number of threads for OMP: {0}".format(
659+
c['pipeline_setup']['system_config']['num_OMP_threads']))
660660

661661
# create a timestamp for writing config files
662662
# pylint: disable=invalid-name

0 commit comments

Comments
 (0)