From ddef1bbaf8ed7b106e1be10d12f1a4b6cebb77ca Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Mon, 9 Apr 2018 16:24:19 -0400 Subject: [PATCH] make sure creating a task will initialize the thread_limit --- include/deal.II/base/multithread_info.h | 5 +++++ include/deal.II/base/thread_management.h | 2 ++ source/base/multithread_info.cc | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) 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; } -- 2.39.5