@@ -1261,6 +1261,46 @@ def _gen_filename(self, name):
1261
1261
def _gen_outfilename (self ):
1262
1262
raise NotImplementedError
1263
1263
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
+
1264
1304
class SEMLikeCommandLine (CommandLine ):
1265
1305
"""By default in SEM derived interface all outputs have corresponding inputs.
1266
1306
However, some SEM commands create outputs that are not defined in the XML.
0 commit comments