From d44dfd20d9c77be545e3560fa3f05e949d860db6 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sat, 7 Sep 2013 20:29:18 -0400 Subject: [PATCH] Add OpenMP tests (also fix PEP8 compliance in test_compile.py). --- tests/run_tests.py | 13 +++--- tests/test_compile/test_compile.py | 75 +++++++++++++++++++++++------- 2 files changed, 66 insertions(+), 22 deletions(-) diff --git a/tests/run_tests.py b/tests/run_tests.py index 5e261fba7..1a1a05e83 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -55,7 +55,7 @@ def run_suite(name=None, mpi=False): results.append((name, result)) # set mpiexec path -if os.environ.has_key('COMPILER'): +if 'COMPILER' in os.environ: compiler = os.environ['COMPILER'] else: compiler = 'gnu' @@ -67,8 +67,9 @@ sys.path.append(pwd) # Set list of tests, either default or from command line flags = [] -tests = ['compile', 'normal', 'debug', 'optimize', 'hdf5', 'mpi', 'phdf5', - 'petsc', 'phdf5-petsc', 'phdf5-petsc-optimize'] +tests = ['compile', 'normal', 'debug', 'optimize', 'mpi', 'omp', 'hdf5', + 'petsc', 'mpi-omp', 'omp-hdf5', 'phdf5', 'phdf5-petsc', + 'phdf5-petsc-optimize', 'omp-phdf5-petsc-optimize'] if len(sys.argv) > 1: flags = [i for i in sys.argv[1:] if i.startswith('-')] tests_ = [i for i in sys.argv[1:] if not i.startswith('-')] @@ -79,10 +80,10 @@ results = [] for name in tests: if name == 'compile': run_compile() - elif name in ['normal', 'debug', 'optimize', 'hdf5']: + elif name in ['normal', 'debug', 'optimize', 'omp', 'hdf5', 'omp-hdf5']: run_suite(name=name) - elif name in ['mpi', 'phdf5', 'petsc', 'phdf5-petsc', - 'phdf5-petsc-optimize']: + elif name in ['mpi', 'mpi-omp' 'phdf5', 'petsc', 'phdf5-petsc', + 'phdf5-petsc-optimize', 'omp-phdf5-petsc-optimize']: run_suite(name=name, mpi=True) # print out summary of results diff --git a/tests/test_compile/test_compile.py b/tests/test_compile/test_compile.py index 72e4dd653..66368c08a 100644 --- a/tests/test_compile/test_compile.py +++ b/tests/test_compile/test_compile.py @@ -3,8 +3,8 @@ """Compilation tests This set of tests makes sure that OpenMC can compile for many different -combinations of compilation flags and options. By default, only the gfortran and -ifort compilers are tested. This requires that the MPI, HDF5, and PETSC +combinations of compilation flags and options. By default, only the gfortran +and ifort compilers are tested. This requires that the MPI, HDF5, and PETSC libraries are already set up appropriately in the Makefile. """ @@ -15,80 +15,123 @@ import shutil pwd = os.path.dirname(__file__) -if os.environ.has_key('COMPILER'): +if 'COMPILER' in os.environ: compiler = 'COMPILER=' + os.environ['COMPILER'] else: compiler = 'COMPILER=gnu' + def setup(): # Change to source directory os.chdir(pwd + '/../../src') + def test_normal(): - returncode = run(['make','distclean']) + returncode = run(['make', 'distclean']) returncode = run(['make', compiler]) assert returncode == 0 shutil.move('openmc', 'openmc-normal') + def test_debug(): - returncode = run(['make','distclean']) + returncode = run(['make', 'distclean']) returncode = run(['make', compiler, 'DEBUG=yes']) assert returncode == 0 shutil.move('openmc', 'openmc-debug') + def test_profile(): - returncode = run(['make','distclean']) + returncode = run(['make', 'distclean']) returncode = run(['make', compiler, 'PROFILE=yes']) assert returncode == 0 + def test_optimize(): - returncode = run(['make','distclean']) + returncode = run(['make', 'distclean']) returncode = run(['make', compiler, 'OPTIMIZE=yes']) assert returncode == 0 shutil.move('openmc', 'openmc-optimize') + def test_mpi(): - returncode = run(['make','distclean']) + returncode = run(['make', 'distclean']) returncode = run(['make', compiler, 'MPI=yes']) assert returncode == 0 shutil.move('openmc', 'openmc-mpi') + +def test_omp(): + returncode = run(['make', 'distclean']) + returncode = run(['make', compiler, 'OPENMP=yes']) + assert returncode == 0 + shutil.move('openmc', 'openmc-omp') + + def test_hdf5(): - returncode = run(['make','distclean']) + returncode = run(['make', 'distclean']) returncode = run(['make', compiler, 'HDF5=yes']) assert returncode == 0 shutil.move('openmc', 'openmc-hdf5') + def test_petsc(): - returncode = run(['make','distclean']) + returncode = run(['make', 'distclean']) returncode = run(['make', compiler, 'MPI=yes', 'PETSC=yes']) assert returncode == 0 shutil.move('openmc', 'openmc-petsc') + +def test_mpi_omp(): + returncode = run(['make', 'distclean']) + returncode = run(['make', compiler, 'MPI=yes', 'OPENMP=yes']) + assert returncode == 0 + shutil.move('openmc', 'openmc-mpi-omp') + + +def test_omp_hdf5(): + returncode = run(['make', 'distclean']) + returncode = run(['make', compiler, 'MPI=yes', 'OPENMP=yes', 'HDF5=yes']) + assert returncode == 0 + shutil.move('openmc', 'openmc-omp-hdf5') + + def test_mpi_hdf5(): - returncode = run(['make','distclean']) + returncode = run(['make', 'distclean']) returncode = run(['make', compiler, 'MPI=yes', 'HDF5=yes']) assert returncode == 0 shutil.move('openmc', 'openmc-phdf5') + def test_mpi_hdf5_petsc(): - returncode = run(['make','distclean']) + returncode = run(['make', 'distclean']) returncode = run(['make', compiler, 'MPI=yes', 'HDF5=yes', 'PETSC=yes']) assert returncode == 0 shutil.move('openmc', 'openmc-phdf5-petsc') + def test_mpi_hdf5_petsc_optimize(): - returncode = run(['make','distclean']) - returncode = run(['make', compiler, 'MPI=yes', 'HDF5=yes', 'PETSC=yes', 'OPTIMIZE=yes']) + returncode = run(['make', 'distclean']) + returncode = run(['make', compiler, 'MPI=yes', 'HDF5=yes', 'PETSC=yes', + 'OPTIMIZE=yes']) assert returncode == 0 shutil.move('openmc', 'openmc-phdf5-petsc-optimize') + +def test_mpi_omp_hdf5_petsc_optimize(): + returncode = run(['make', 'distclean']) + returncode = run(['make', compiler, 'MPI=yes', 'OMP=yes', 'HDF5=yes', + 'PETSC=yes', 'OPTIMIZE=yes']) + assert returncode == 0 + shutil.move('openmc', 'openmc-omp-phdf5-petsc-optimize') + + def run(commands): proc = Popen(commands, stderr=STDOUT, stdout=PIPE) returncode = proc.wait() print(proc.communicate()[0]) return returncode + def teardown(commands): - returncode = run(['make','distclean']) - shutil.copy('openmc-normal','openmc') + returncode = run(['make', 'distclean']) + shutil.copy('openmc-normal', 'openmc')