From: Timo Heister Date: Mon, 9 Apr 2018 20:24:19 +0000 (-0400) Subject: make sure creating a task will initialize the thread_limit X-Git-Tag: v9.0.0-rc1~190^2^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ddef1bbaf8ed7b106e1be10d12f1a4b6cebb77ca;p=dealii.git make sure creating a task will initialize the thread_limit --- diff --git a/include/deal.II/base/multithread_info.h b/include/deal.II/base/multithread_info.h index 97a9b6bb68..3f07766096 100644 --- a/include/deal.II/base/multithread_info.h +++ b/include/deal.II/base/multithread_info.h @@ -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: /** diff --git a/include/deal.II/base/thread_management.h b/include/deal.II/base/thread_management.h index b2f534225b..c507019309 100644 --- a/include/deal.II/base/thread_management.h +++ b/include/deal.II/base/thread_management.h @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef DEAL_II_WITH_THREADS # include @@ -1909,6 +1910,7 @@ namespace Threads -> Task { typedef decltype(function_object()) return_type; + dealii::MultithreadInfo::initialize_multithreading(); return Task(std::function(function_object)); } diff --git a/source/base/multithread_info.cc b/source/base/multithread_info.cc index e17e171a86..229a96db96 100644 --- a/source/base/multithread_info.cc +++ b/source/base/multithread_info.cc @@ -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; }