From 0dae314453a43a81cc358dce12ca87005d1cda5b Mon Sep 17 00:00:00 2001 From: David Wells Date: Thu, 8 Jun 2017 16:44:18 -0400 Subject: [PATCH] Set OMP_NUM_THREADS=2 in the test suite. --- cmake/scripts/run_test.sh | 2 ++ tests/base/openmp_threads.cc | 42 ++++++++++++++++++++++++++++++++ tests/base/openmp_threads.output | 2 ++ 3 files changed, 46 insertions(+) create mode 100644 tests/base/openmp_threads.cc create mode 100644 tests/base/openmp_threads.output diff --git a/cmake/scripts/run_test.sh b/cmake/scripts/run_test.sh index 4365a5ab33..d0b798e0b9 100644 --- a/cmake/scripts/run_test.sh +++ b/cmake/scripts/run_test.sh @@ -32,6 +32,8 @@ shift 2 # Ensure uniform sorting for pathname expansion export LC_ALL=C +# Prevent OpenMP from creating additional threads +export OMP_NUM_THREADS=2 case $STAGE in run) diff --git a/tests/base/openmp_threads.cc b/tests/base/openmp_threads.cc new file mode 100644 index 0000000000..2ea98356f5 --- /dev/null +++ b/tests/base/openmp_threads.cc @@ -0,0 +1,42 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// Ensure that, when executing test suite programs, the environment variable +// OMP_NUM_THREADS is set to 2. + +#include "../tests.h" + +#include + +int main() +{ + initlog(); + + // This might not work on Windows; always pass if we don't have getenv + // available +#ifdef _POSIX_C_SOURCE + const char *omp_env_variable = getenv("OMP_NUM_THREADS"); + AssertThrow(omp_env_variable != nullptr, + ExcMessage("The environment variable OMP_NUM_THREADS should be " + "defined when running the test suite.")); + if (std::string(omp_env_variable) == "2") + { + deallog << "OK" << std::endl; + } +#else + deallog << "OK" << std::endl; +#endif +} diff --git a/tests/base/openmp_threads.output b/tests/base/openmp_threads.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/base/openmp_threads.output @@ -0,0 +1,2 @@ + +DEAL::OK -- 2.39.5