Skip to content

Commit c9d9197

Browse files
committed
Merge pull request #489 from moloney/enh-mpicommand
ENH: Provide base interface for MPI capable command line software.
2 parents a3797fc + 8b3bd1b commit c9d9197

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

nipype/interfaces/base.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,46 @@ def _gen_filename(self, name):
12611261
def _gen_outfilename(self):
12621262
raise NotImplementedError
12631263

1264+
class MpiCommandLineInputSpec(CommandLineInputSpec):
1265+
use_mpi = traits.Bool(False,
1266+
desc="Whether or not to run the command with mpiexec",
1267+
usedefault=True)
1268+
n_procs = traits.Int(desc="Num processors to specify to mpiexec. Do not "
1269+
"specify if this is managed externally (e.g. through "
1270+
"SGE)")
1271+
1272+
1273+
class MpiCommandLine(CommandLine):
1274+
'''Implements functionality to interact with command line programs
1275+
that can be run with MPI (i.e. using 'mpiexec').
1276+
1277+
Examples
1278+
--------
1279+
>>> from nipype.interfaces.base import MpiCommandLine
1280+
>>> mpi_cli = MpiCommandLine(command='my_mpi_prog')
1281+
>>> mpi_cli.inputs.args = '-v'
1282+
>>> mpi_cli.cmdline
1283+
'my_mpi_prog -v'
1284+
1285+
>>> mpi_cli.inputs.use_mpi = True
1286+
>>> mpi_cli.inputs.n_procs = 8
1287+
>>> mpi_cli.cmdline
1288+
1289+
'mpiexec -n 8 my_mpi_prog -v'
1290+
'''
1291+
input_spec = MpiCommandLineInputSpec
1292+
1293+
@property
1294+
def cmdline(self):
1295+
"""Adds 'mpiexec' to begining of command"""
1296+
result = []
1297+
if self.inputs.use_mpi:
1298+
result.append('mpiexec')
1299+
if self.inputs.n_procs:
1300+
result.append('-n %d' % self.inputs.n_procs)
1301+
result.append(super(MpiCommandLine, self).cmdline)
1302+
return ' '.join(result)
1303+
12641304
class SEMLikeCommandLine(CommandLine):
12651305
"""By default in SEM derived interface all outputs have corresponding inputs.
12661306
However, some SEM commands create outputs that are not defined in the XML.

0 commit comments

Comments
 (0)