diff --git a/openmc/executor.py b/openmc/executor.py index a20437e1c..3b9b8abd8 100644 --- a/openmc/executor.py +++ b/openmc/executor.py @@ -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 diff --git a/tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py b/tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py index 7dc679b1f..f9f9a7509 100644 --- a/tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py +++ b/tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py @@ -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) diff --git a/tests/test_statepoint_restart/test_statepoint_restart.py b/tests/test_statepoint_restart/test_statepoint_restart.py index d39bf7cd5..61522ee05 100644 --- a/tests/test_statepoint_restart/test_statepoint_restart.py +++ b/tests/test_statepoint_restart/test_statepoint_restart.py @@ -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) diff --git a/tests/testing_harness.py b/tests/testing_harness.py index b833615c7..fc3b4f934 100644 --- a/tests/testing_harness.py +++ b/tests/testing_harness.py @@ -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)