Skip to content

Commit 47b9aa7

Browse files
committed
enh: add threading option to Eddy
1 parent 154f5e2 commit 47b9aa7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

nipype/interfaces/fsl/epi.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ class EddyInputSpec(FSLCommandInputSpec):
424424
'squares)'))
425425
repol = traits.Bool(False, argstr='--repol',
426426
desc='Detect and replace outlier slices')
427+
num_threads = traits.Int(1, usedefault=True, nohash=True,
428+
desc="Number of openmp threads to use")
427429

428430

429431
class EddyOutputSpec(TraitedSpec):
@@ -465,6 +467,25 @@ class Eddy(FSLCommand):
465467
input_spec = EddyInputSpec
466468
output_spec = EddyOutputSpec
467469

470+
_num_threads = 1
471+
472+
def __init__(self, **inputs):
473+
super(Eddy, self).__init__(**inputs)
474+
self.inputs.on_trait_change(self._num_threads_update, 'num_threads')
475+
476+
if not isdefined(self.inputs.num_threads):
477+
self.inputs.num_threads = self._num_threads
478+
else:
479+
self._num_threads_update()
480+
481+
def _num_threads_update(self):
482+
self._num_threads = self.inputs.num_threads
483+
if not isdefined(self.inputs.num_threads):
484+
if 'OMP_NUM_THREADS' in self.inputs.environ:
485+
del self.inputs.environ['OMP_NUM_THREADS']
486+
else:
487+
self.inputs.environ['OMP_NUM_THREADS'] = self.inputs.num_threads
488+
468489
def _format_arg(self, name, spec, value):
469490
if name == 'in_topup_fieldcoef':
470491
return spec.argstr % value.split('_fieldcoef')[0]

nipype/interfaces/fsl/tests/test_auto_Eddy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def test_Eddy_inputs():
4242
),
4343
niter=dict(argstr='--niter=%s',
4444
),
45+
num_threads=dict(nohash=True,
46+
usedefault=True,
47+
),
4548
out_base=dict(argstr='--out=%s',
4649
),
4750
output_type=dict(),

0 commit comments

Comments
 (0)