From e965a9697735f964c0bd8e667777458e80f21313 Mon Sep 17 00:00:00 2001 From: heister Date: Wed, 2 Oct 2013 17:40:15 +0000 Subject: [PATCH] introduce new n_threads(), deprecate n_default_threads git-svn-id: https://svn.dealii.org/trunk@31073 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 7 ++++++ .../include/deal.II/base/multithread_info.h | 11 ++++++++- deal.II/source/base/multithread_info.cc | 24 ++++++++++++++----- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index bb840cebeb..4cd8154509 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -61,6 +61,13 @@ inconvenience this causes.
    +
  1. + Changed: if configured with TBB but the number of threads is set to 1, + do not bother to use TBB in workstream. +
    + (Timo Heister, 2013/10/02) +
  2. +
  3. New: step-51 demonstrates the use of hybridized discontinuous Galerkin methods in deal.II, using the face elements FE_FaceQ. The programs solves a diff --git a/deal.II/include/deal.II/base/multithread_info.h b/deal.II/include/deal.II/base/multithread_info.h index 3b72975556..38a3f21464 100644 --- a/deal.II/include/deal.II/base/multithread_info.h +++ b/deal.II/include/deal.II/base/multithread_info.h @@ -86,8 +86,17 @@ public: * At start time this is n_cpus or * one, if detection of the number * of CPUs is not possible. + * + * @deprecated: use set_thread_limit() instead. + */ + unsigned int n_default_threads DEAL_II_DEPRECATED; + + /* + * Returns the number of threads to use. This is governed by the number + * of cores the system has and can be further restricted by + * set_thread_limit(). */ - unsigned int n_default_threads; + unsigned int n_threads() const; /** * Determine an estimate for diff --git a/deal.II/source/base/multithread_info.cc b/deal.II/source/base/multithread_info.cc index e79373d0aa..6ea0b132a6 100644 --- a/deal.II/source/base/multithread_info.cc +++ b/deal.II/source/base/multithread_info.cc @@ -101,6 +101,9 @@ unsigned int MultithreadInfo::get_n_cpus() void MultithreadInfo::set_thread_limit(const unsigned int max_threads) { + Assert(n_max_threads==numbers::invalid_unsigned_int, + ExcMessage("Calling set_thread_limit() more than once is not supported!")); + unsigned int max_threads_env = numbers::invalid_unsigned_int; char *penv; penv = getenv ("DEAL_II_NUM_THREADS"); @@ -117,11 +120,13 @@ void MultithreadInfo::set_thread_limit(const unsigned int max_threads) } } -bool MultithreadInfo::is_running_single_threaded() + +unsigned int MultithreadInfo::n_threads() const { if (n_max_threads == numbers::invalid_unsigned_int) - n_max_threads = tbb::task_scheduler_init::default_num_threads(); - return n_max_threads == 1; + return tbb::task_scheduler_init::default_num_threads(); + else + return n_max_threads; } @@ -132,9 +137,9 @@ unsigned int MultithreadInfo::get_n_cpus() return 1; } -bool MultithreadInfo::is_running_single_threaded() +unsigned int MultithreadInfo::n_threads() const { - return true; + return 1; } void MultithreadInfo::set_thread_limit(const unsigned int) @@ -144,10 +149,17 @@ void MultithreadInfo::set_thread_limit(const unsigned int) #endif +bool MultithreadInfo::is_running_single_threaded() +{ + return n_threads() == 1; +} + + MultithreadInfo::MultithreadInfo () : n_cpus (get_n_cpus()), - n_default_threads (n_cpus) + n_default_threads (n_cpus), + n_max_threads (numbers::invalid_unsigned_int) {} -- 2.39.5