Ability to run volume calculation with MPI from Python API

This commit is contained in:
Paul Romano 2017-02-27 07:32:38 -06:00
parent a4dbcca90d
commit fdd7b292ca
2 changed files with 38 additions and 21 deletions

View file

@ -8,9 +8,9 @@ from six import string_types
_summary_indicator = "TIMING STATISTICS"
def _run(command, output, cwd):
def _run(args, output, cwd):
# Launch a subprocess
p = subprocess.Popen(command, shell=True, cwd=cwd, stdout=subprocess.PIPE,
p = subprocess.Popen(args, cwd=cwd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, universal_newlines=True)
storage_flag = False
@ -51,24 +51,44 @@ def plot_geometry(output=True, openmc_exec='openmc', cwd='.'):
Path to working directory to run in. Defaults to the current working directory.
"""
return _run(openmc_exec + ' -p', output, cwd)
if output:
output = 'full'
return _run([openmc_exec, '-p'], output, cwd)
def run_volume_calculation(output=True, openmc_exec='openmc', cwd='.'):
def run_volume_calculation(threads=None, output=True, cwd='.',
openmc_exec='openmc', mpi_args=None):
"""Run stochastic volume calculations in OpenMC
Parameters
----------
output : bool
threads : int, optional
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
:envvar:`OMP_NUM_THREADS` environment variable).
output : bool, optional
Capture OpenMC output from standard out
openmc_exec : str
Path to OpenMC executable
openmc_exec : str, optional
Path to OpenMC executable. Defaults to 'openmc'.
mpi_args : list of str, optional
MPI execute command and any additional MPI arguments to pass,
e.g. ['mpiexec', '-n', '8'].
cwd : str, optional
Path to working directory to run in. Defaults to the current working directory.
Path to working directory to run in. Defaults to the current working
directory.
"""
return _run(openmc_exec + ' --volume', output, cwd)
args = [openmc_exec, '--volume']
if isinstance(threads, Integral) and threads > 0:
args += ['-s', str(threads)]
if mpi_args is not None:
args = mpi_args + args
if output:
output = 'full'
return _run(args, output, cwd)
def run(particles=None, threads=None, geometry_debug=False,
@ -106,27 +126,24 @@ def run(particles=None, threads=None, geometry_debug=False,
"""
post_args = ' '
pre_args = ''
args = [openmc_exec]
if isinstance(particles, Integral) and particles > 0:
post_args += '-n {0} '.format(particles)
args += ['-n', str(particles)]
if isinstance(threads, Integral) and threads > 0:
post_args += '-s {0} '.format(threads)
args += ['-s', str(threads)]
if geometry_debug:
post_args += '-g '
args.append('-g')
if isinstance(restart_file, string_types):
post_args += '-r {0} '.format(restart_file)
args += ['-r', restart_file]
if tracks:
post_args += '-t'
args.append('-t')
if mpi_args is not None:
pre_args = ' '.join(mpi_args) + ' '
args = mpi_args + args
command = pre_args + openmc_exec + ' ' + post_args
return _run(command, output, cwd)
return _run(args, output, cwd)

View file

@ -7,5 +7,5 @@ from testing_harness import ParticleRestartTestHarness
if __name__ == '__main__':
harness = ParticleRestartTestHarness('particle_10_1030.*')
harness = ParticleRestartTestHarness('particle_10_1030.h5')
harness.main()