Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions nipype/interfaces/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,46 @@ def _gen_filename(self, name):
def _gen_outfilename(self):
raise NotImplementedError

class MpiCommandLineInputSpec(CommandLineInputSpec):
use_mpi = traits.Bool(False,
desc="Whether or not to run the command with mpiexec",
usedefault=True)
n_procs = traits.Int(desc="Num processors to specify to mpiexec. Do not "
"specify if this is managed externally (e.g. through "
"SGE)")


class MpiCommandLine(CommandLine):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a docstring and an example cmdline generated by this class.

'''Implements functionality to interact with command line programs
that can be run with MPI (i.e. using 'mpiexec').

Examples
--------
>>> from nipype.interfaces.base import MpiCommandLine
>>> mpi_cli = MpiCommandLine(command='my_mpi_prog')
>>> mpi_cli.inputs.args = '-v'
>>> mpi_cli.cmdline
'my_mpi_prog -v'

>>> mpi_cli.inputs.use_mpi = True
>>> mpi_cli.inputs.n_procs = 8
>>> mpi_cli.cmdline

'mpiexec -n 8 my_mpi_prog -v'
'''
input_spec = MpiCommandLineInputSpec

@property
def cmdline(self):
"""Adds 'mpiexec' to begining of command"""
result = []
if self.inputs.use_mpi:
result.append('mpiexec')
if self.inputs.n_procs:
result.append('-n %d' % self.inputs.n_procs)
result.append(super(MpiCommandLine, self).cmdline)
return ' '.join(result)

class SEMLikeCommandLine(CommandLine):
"""By default in SEM derived interface all outputs have corresponding inputs.
However, some SEM commands create outputs that are not defined in the XML.
Expand Down