From d7eb6e3852a57a4b358e01818d376ef7f2ec3635 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Tue, 30 Jun 2015 23:20:54 -0600 Subject: [PATCH] Specify mpi executable in Executor and TestHarness for PR #402 --- CMakeLists.txt | 2 +- openmc/executor.py | 18 ++++++++++++++-- tests/test_source_file/test_source_file.py | 11 +--------- .../test_statepoint_restart.py | 19 +++++++++-------- tests/testing_harness.py | 21 +++++++++---------- 5 files changed, 38 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5c5e62b67..e335dfd575 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -254,7 +254,7 @@ foreach(test ${TESTS}) add_test(NAME ${TEST_NAME} WORKING_DIRECTORY ${TEST_PATH} COMMAND ${PYTHON_EXECUTABLE} ${TEST_NAME} --exe $ - --mpi_exec) + --mpi_exec $ENV{MPI_DIR}/bin/mpiexec) else(${MPI_ENABLED}) diff --git a/openmc/executor.py b/openmc/executor.py index 76c3737079..74c56a9762 100644 --- a/openmc/executor.py +++ b/openmc/executor.py @@ -64,7 +64,7 @@ class Executor(object): def run_simulation(self, particles=None, threads=None, geometry_debug=False, restart_file=None, tracks=False, mpi_procs=1, output=True, - openmc_exec='openmc'): + openmc_exec='openmc', mpi_exec=None): """Run an OpenMC simulation. Parameters @@ -107,7 +107,21 @@ class Executor(object): post_args += '-t' if isinstance(mpi_procs, Integral) and mpi_procs > 1: - pre_args += 'mpirun -n {0} '.format(mpi_procs) + np_present = True + else: + np_present = False + + if mpi_exec is not None and isinstance(mpi_exec, basestring): + mpi_exec_present = True + else: + mpi_exec_present = False + + if np_present or mpi_exec_present: + if mpi_exec_present: + pre_args += mpi_exec + ' ' + else: + pre_args += 'mpirun ' + pre_args += '-n {0} '.format(mpi_procs) command = pre_args + openmc_exec + ' ' + post_args diff --git a/tests/test_source_file/test_source_file.py b/tests/test_source_file/test_source_file.py index 3e64d2d1a0..d9aaa9a0fa 100644 --- a/tests/test_source_file/test_source_file.py +++ b/tests/test_source_file/test_source_file.py @@ -77,12 +77,6 @@ class SourceFileTestHarness(TestHarness): 'Source file is not a binary or hdf5 file.' def _run_openmc_restart(self): - # Get the number of MPI processes. - if self._opts.mpi_exec: - mpi_procs = int(self._opts.mpi_np) - else: - mpi_procs = 1 - # Get the name of the source file. source = glob.glob(os.path.join(os.getcwd(), 'source.10.*')) @@ -91,10 +85,7 @@ class SourceFileTestHarness(TestHarness): fh.write(settings2.format(source[0].split('.')[-1])) # Run OpenMC. - executor = Executor() - returncode = executor.run_simulation(mpi_procs=mpi_procs, - openmc_exec=self._opts.exe) - assert returncode == 0, 'OpenMC did not exit successfully.' + self._run_openmc() def _cleanup(self): TestHarness._cleanup(self) diff --git a/tests/test_statepoint_restart/test_statepoint_restart.py b/tests/test_statepoint_restart/test_statepoint_restart.py index ad88d6b914..e20c717d6b 100644 --- a/tests/test_statepoint_restart/test_statepoint_restart.py +++ b/tests/test_statepoint_restart/test_statepoint_restart.py @@ -35,20 +35,21 @@ class StatepointRestartTestHarness(TestHarness): self._cleanup() def _run_openmc_restart(self): - # Get the number of MPI processes. - if self._opts.mpi_exec: - mpi_procs = int(self._opts.mpi_np) - else: - mpi_procs = 1 - # Get the name of the statepoint file. statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name)) # Run OpenMC executor = Executor() - returncode = executor.run_simulation(mpi_procs=mpi_procs, - restart_file=statepoint, - openmc_exec = self._opts.exe) + + if self._opts.mpi_exec is not None: + returncode = executor.run_simulation(mpi_procs=mpi_procs, + restart_file=statepoint, + openmc_exec=self._opts.exe, + mpi_exec=self._opts.mpi_exec) + + else: + returncode = executor.run_simulation(openmc_exec=self._opts.exe) + assert returncode == 0, 'OpenMC did not exit successfully.' diff --git a/tests/testing_harness.py b/tests/testing_harness.py index 54096d6726..6cf85ae233 100644 --- a/tests/testing_harness.py +++ b/tests/testing_harness.py @@ -58,24 +58,23 @@ class TestHarness(object): def _parse_args(self): parser = OptionParser() parser.add_option('--exe', dest='exe', default='openmc') - parser.add_option('--mpi_exec', dest='mpi_exec', action='store_true', - default=False) + parser.add_option('--mpi_exec', dest='mpi_exec', default=None) parser.add_option('--mpi_np', dest='mpi_np', type=int, default=3) parser.add_option('--update', dest='update', action='store_true', default=False) (self._opts, self._args) = parser.parse_args() def _run_openmc(self): - print('******') - print(self._opts.exe) - if self._opts.mpi_exec: - mpi_procs = self._opts.mpi_np - else: - mpi_procs = 1 - executor = Executor() - returncode = executor.run_simulation(mpi_procs=mpi_procs, - openmc_exec=self._opts.exe) + + if self._opts.mpi_exec is not None: + returncode = executor.run_simulation(mpi_procs=mpi_procs, + openmc_exec=self._opts.exe, + mpi_exec=self._opts.mpi_exec) + + else: + returncode = executor.run_simulation(openmc_exec=self._opts.exe) + assert returncode == 0, 'OpenMC did not exit successfully.' def _test_output_created(self):