Allow arbitrary MPI arguments in openmc.run()

This commit is contained in:
Paul Romano 2017-02-17 09:29:14 -06:00
parent aeffb739ec
commit f28a0fcdda
4 changed files with 25 additions and 29 deletions

View file

@ -44,8 +44,8 @@ def plot_geometry(output=True, openmc_exec='openmc', cwd='.'):
def run(particles=None, threads=None, geometry_debug=False,
restart_file=None, tracks=False, mpi_procs=1, output=True,
openmc_exec='openmc', mpi_exec='mpiexec', cwd='.'):
restart_file=None, tracks=False, output=True, cwd='.',
openmc_exec='openmc', mpi_args=None):
"""Run an OpenMC simulation.
Parameters
@ -56,23 +56,23 @@ def run(particles=None, threads=None, geometry_debug=False,
Number of OpenMP threads. If OpenMC is compiled with OpenMP threading
enabled, the default is implementation-dependent but is usually equal to
the number of hardware threads available (or a value set by the
OMP_NUM_THREADS environment variable).
:envvar:`OMP_NUM_THREADS` environment variable).
geometry_debug : bool, optional
Turn on geometry debugging during simulation. Defaults to False.
restart_file : str, optional
Path to restart file to use
tracks : bool, optional
Write tracks for all particles. Defaults to False.
mpi_procs : int, optional
Number of MPI processes.
output : bool, optional
Capture OpenMC output from standard out. Defaults to True.
cwd : str, optional
Path to working directory to run in. Defaults to the current working
directory.
openmc_exec : str, optional
Path to OpenMC executable. Defaults to 'openmc'.
mpi_exec : str, optional
MPI execute command. Defaults to 'mpiexec'.
cwd : str, optional
Path to working directory to run in. Defaults to the current working directory.
mpi_args : list of str, optional
MPI execute command and any additional MPI arguments to pass,
e.g. ['mpiexec', '-n', '8'].
"""
@ -94,8 +94,8 @@ def run(particles=None, threads=None, geometry_debug=False,
if tracks:
post_args += '-t'
if isinstance(mpi_procs, Integral) and mpi_procs > 1:
pre_args += '{} -n {} '.format(mpi_exec, mpi_procs)
if mpi_args is not None:
pre_args = ' '.join(mpi_args) + ' '
command = pre_args + openmc_exec + ' ' + post_args

View file

@ -41,10 +41,9 @@ class MGXSTestHarness(PyAPITestHarness):
def _run_openmc(self):
# Initial run
if self._opts.mpi_exec is not None:
returncode = openmc.run(mpi_procs=self._opts.mpi_np,
openmc_exec=self._opts.exe,
mpi_exec=self._opts.mpi_exec)
mpi_args = [self._opts.mpi_exec, '-n', self._opts.mpi_np]
returncode = openmc.run(openmc_exec=self._opts.exe,
mpi_args=mpi_args)
else:
returncode = openmc.run(openmc_exec=self._opts.exe)
@ -74,10 +73,9 @@ class MGXSTestHarness(PyAPITestHarness):
# Re-run MG mode.
if self._opts.mpi_exec is not None:
returncode = openmc.run(mpi_procs=self._opts.mpi_np,
openmc_exec=self._opts.exe,
mpi_exec=self._opts.mpi_exec)
mpi_args = [self._opts.mpi_exec, '-n', self._opts.mpi_np]
returncode = openmc.run(openmc_exec=self._opts.exe,
mpi_args=mpi_args)
else:
returncode = openmc.run(openmc_exec=self._opts.exe)

View file

@ -50,11 +50,10 @@ class StatepointRestartTestHarness(TestHarness):
# Run OpenMC
if self._opts.mpi_exec is not None:
returncode = openmc.run(mpi_procs=self._opts.mpi_np,
restart_file=statepoint,
mpi_args = [self._opts.mpi_exec, '-n', self._opts.mpi_np]
returncode = openmc.run(restart_file=statepoint,
openmc_exec=self._opts.exe,
mpi_exec=self._opts.mpi_exec)
mpi_args=mpi_args)
else:
returncode = openmc.run(openmc_exec=self._opts.exe,
restart_file=statepoint)

View file

@ -24,7 +24,7 @@ class TestHarness(object):
self.parser = OptionParser()
self.parser.add_option('--exe', dest='exe', default='openmc')
self.parser.add_option('--mpi_exec', dest='mpi_exec', default=None)
self.parser.add_option('--mpi_np', dest='mpi_np', type=int, default=2)
self.parser.add_option('--mpi_np', dest='mpi_np', default='2')
self.parser.add_option('--update', dest='update', action='store_true',
default=False)
self._opts = None
@ -62,9 +62,9 @@ class TestHarness(object):
def _run_openmc(self):
if self._opts.mpi_exec is not None:
returncode = openmc.run(mpi_procs=self._opts.mpi_np,
openmc_exec=self._opts.exe,
mpi_exec=self._opts.mpi_exec)
returncode = openmc.run(
openmc_exec=self._opts.exe,
mpi_args=[self._opts.mpi_exec, '-n', self._opts.mpi_np])
else:
returncode = openmc.run(openmc_exec=self._opts.exe)
@ -190,8 +190,7 @@ class ParticleRestartTestHarness(TestHarness):
# Set arguments
args = {'openmc_exec': self._opts.exe}
if self._opts.mpi_exec is not None:
args.update({'mpi_procs': self._opts.mpi_np,
'mpi_exec': self._opts.mpi_exec})
args['mpi_args'] = [self._opts.mpi_exec, '-n', self._opts.mpi_np]
# Initial run
returncode = openmc.run(**args)