From: Matthias Maier Date: Sun, 22 May 2022 20:45:28 +0000 (-0500) Subject: add a test X-Git-Tag: v9.4.0-rc1~178^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13783%2Fhead;p=dealii.git add a test --- diff --git a/tests/multithreading/threads_01.cc b/tests/multithreading/threads_01.cc new file mode 100644 index 0000000000..5e1bb1b216 --- /dev/null +++ b/tests/multithreading/threads_01.cc @@ -0,0 +1,64 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2013 - 2021 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// +// Verify that MultithreadInfo::set_thread_limit works as advertised +// + +#include + +#ifdef DEAL_II_TBB_WITH_ONEAPI +# include +# include +#endif + +#include "../tests.h" + +int +main() +{ + initlog(); + +#ifdef DEAL_II_TBB_WITH_ONEAPI + // + // The thread concurrency of testsuite executables can be limited by + // various means. In particular, by design we cannot increase thread + // concurrency past the environment variable DEAL_II_NUM_THREADS. + // + // We thus do the following: We start with the current number of threads + // - which is a known good value - and iteratively decrease the number by + // one and check that the tbb thread pool adjusts accordingly: + // + + for (unsigned int n = MultithreadInfo::n_threads(); n > 0; --n) + { + dealii::MultithreadInfo::set_thread_limit(n); + + const auto n_threads = dealii::MultithreadInfo::n_threads(); + const auto n_tbb = tbb::global_control::active_value( + tbb::global_control::max_allowed_parallelism); + + if (n != n_threads || n != n_tbb) + deallog + << "Problem: Thread limits differ from what has been enforced:\n" + << "dealii::MultiThreadInfo::set_thread_limit(" << n << ")\n" + << "dealii::MultiThreadInfo::n_threads() == " << n_threads << "\n" + << "tbb::global_control::active_value(...) == " << n_tbb << "\n" + << std::endl; + } +#endif + + deallog << "OK" << std::endl; +} diff --git a/tests/multithreading/threads_01.output b/tests/multithreading/threads_01.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/multithreading/threads_01.output @@ -0,0 +1,2 @@ + +DEAL::OK