]> https://gitweb.dealii.org/ - dealii.git/commitdiff
make sure creating a task will initialize the thread_limit
authorTimo Heister <timo.heister@gmail.com>
Mon, 9 Apr 2018 20:24:19 +0000 (16:24 -0400)
committerTimo Heister <timo.heister@gmail.com>
Mon, 9 Apr 2018 20:24:19 +0000 (16:24 -0400)
include/deal.II/base/multithread_info.h
include/deal.II/base/thread_management.h
source/base/multithread_info.cc

index 97a9b6bb68c10f14cd1488a81a47abcaa5d56c4b..3f0776609657aa0badb6a19a6598c0cf6147f030 100644 (file)
@@ -101,6 +101,11 @@ public:
    */
   static bool is_running_single_threaded ();
 
+  /**
+   * Make sure the multithreading API is initialized. This normally does not need to be called in usercode.
+   */
+  static void initialize_multithreading ();
+
 private:
 
   /**
index b2f534225ba6c9e09f583a5129c838e1f7deaf31..c507019309ad2fd399d1a5b1fc74e744932ad857 100644 (file)
@@ -20,6 +20,7 @@
 #include <deal.II/base/config.h>
 #include <deal.II/base/exceptions.h>
 #include <deal.II/base/template_constraints.h>
+#include <deal.II/base/multithread_info.h>
 
 #ifdef DEAL_II_WITH_THREADS
 #  include <thread>
@@ -1909,6 +1910,7 @@ namespace Threads
   -> Task<decltype(function_object())>
   {
     typedef decltype(function_object()) return_type;
+    dealii::MultithreadInfo::initialize_multithreading();
     return Task<return_type>(std::function<return_type ()>(function_object));
   }
 
index e17e171a86d1bcae26172c1b92f2e849de491a04..229a96db9693a09901ae9ecafc6bd94b47dbb309 100644 (file)
@@ -198,6 +198,19 @@ MultithreadInfo::memory_consumption ()
 }
 
 
+void
+MultithreadInfo::initialize_multithreading()
+{
+  static bool done = false;
+  if (done)
+    return;
+
+  MultithreadInfo::set_thread_limit (numbers::invalid_unsigned_int);
+  done = true;
+}
+
+
+
 const unsigned int MultithreadInfo::n_cpus = MultithreadInfo::get_n_cpus();
 unsigned int MultithreadInfo::n_max_threads = numbers::invalid_unsigned_int;
 
@@ -210,7 +223,7 @@ namespace
   {
     DoOnce ()
     {
-      MultithreadInfo::set_thread_limit (numbers::invalid_unsigned_int);
+      MultithreadInfo::initialize_multithreading();
     }
   } do_once;
 }

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.