]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add a test 13783/head
authorMatthias Maier <tamiko@43-1.org>
Sun, 22 May 2022 20:45:28 +0000 (15:45 -0500)
committerMatthias Maier <tamiko@43-1.org>
Sun, 22 May 2022 20:54:49 +0000 (15:54 -0500)
tests/multithreading/threads_01.cc [new file with mode: 0644]
tests/multithreading/threads_01.output [new file with mode: 0644]

diff --git a/tests/multithreading/threads_01.cc b/tests/multithreading/threads_01.cc
new file mode 100644 (file)
index 0000000..5e1bb1b
--- /dev/null
@@ -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 <deal.II/base/multithread_info.h>
+
+#ifdef DEAL_II_TBB_WITH_ONEAPI
+#  include <oneapi/tbb/global_control.h>
+#  include <tbb/info.h>
+#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 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.