From f541539602ccd0f28d9f58425bce31f9c4e123b6 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Wed, 11 Feb 2015 19:06:58 -0500 Subject: [PATCH] rework MultithreadInfo to have static members only --- include/deal.II/base/multithread_info.h | 47 ++++++++++++++----------- source/base/multithread_info.cc | 18 ++++++---- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/include/deal.II/base/multithread_info.h b/include/deal.II/base/multithread_info.h index b03f566e04..f32677b46d 100644 --- a/include/deal.II/base/multithread_info.h +++ b/include/deal.II/base/multithread_info.h @@ -49,29 +49,27 @@ class MultithreadInfo { public: /** - * The constructor determines the number of CPUs in the system. At the - * moment detection of CPUs is only implemented on Linux computers with the - * /proc filesystem and on Sun machines. The number of CPUs present is set - * to one if detection failed or if detection is not supported. - */ - MultithreadInfo (); - - /** - * The number of CPUs in the system. It is one if detection is not - * implemented or failed. + * The number of CPUs in the system. At the moment detection of CPUs is only + * implemented on Linux, FreeBSD, and Mac computers. It is one if detection + * failed or is not implemented on your system. * * If it is one, although you are on a multi-processor machine, please refer * to the documentation in multithread_info.cc near to the * error directive. */ - const unsigned int n_cpus; + static unsigned int n_cores (); + + /** + * @deprecated Use n_cores() instead. + */ + static const unsigned int n_cpus DEAL_II_DEPRECATED; /** * Returns the number of threads to use. This is initially set to the number * of cores the system has (n_cpus) but can be further restricted by * set_thread_limit(). */ - unsigned int n_threads() const; + static unsigned int n_threads (); /** * Determine an estimate for the memory consumption (in bytes) of this @@ -94,7 +92,7 @@ public: * method will have any effect. Use the parameter of the MPI_InitFinalize if * you have an MPI based code. */ - void set_thread_limit(const unsigned int max_threads = numbers::invalid_unsigned_int); + static void set_thread_limit (const unsigned int max_threads = numbers::invalid_unsigned_int); /** @@ -103,12 +101,19 @@ public: * is used in the PETScWrappers to avoid using the interface that is not * thread-safe. */ - bool is_running_single_threaded(); + static bool is_running_single_threaded (); + /** * Exception */ DeclException0(ExcProcNotPresent); + /** + * @deprecated All members are static, so there is no need to construct an + * instance. + */ + MultithreadInfo () DEAL_II_DEPRECATED; + private: /** @@ -116,24 +121,24 @@ private: * Linux, OSF, SGI, and Sun machines; if no detection of the number of CPUs * is supported, or if detection fails, this function returns one. */ - static unsigned int get_n_cpus(); + static unsigned int get_n_cpus (); /** - * variable representing the maximum number of threads + * Variable representing the maximum number of threads. */ - unsigned int n_max_threads; + static unsigned int n_max_threads; }; /** - * Global variable of type MultithreadInfo which you may ask for the - * number of CPUs in your system, as well as for the default number of threads - * that multithreaded functions shall use. + * Global variable of type MultithreadInfo. + * + * @deprecated Use the static member functions instead. * * @ingroup threads */ -extern MultithreadInfo multithread_info; +extern MultithreadInfo multithread_info DEAL_II_DEPRECATED; diff --git a/source/base/multithread_info.cc b/source/base/multithread_info.cc index e47136f1e5..333aecb683 100644 --- a/source/base/multithread_info.cc +++ b/source/base/multithread_info.cc @@ -98,6 +98,15 @@ unsigned int MultithreadInfo::get_n_cpus() # endif +const unsigned int MultithreadInfo::n_cpus = MultithreadInfo::get_n_cpus(); +unsigned int MultithreadInfo::n_max_threads = numbers::invalid_unsigned_int; + +unsigned int MultithreadInfo::n_cores() +{ + return MultithreadInfo::n_cpus; +} + + void MultithreadInfo::set_thread_limit(const unsigned int max_threads) { Assert(n_max_threads==numbers::invalid_unsigned_int, @@ -148,7 +157,7 @@ void MultithreadInfo::set_thread_limit(const unsigned int max_threads) } -unsigned int MultithreadInfo::n_threads() const +unsigned int MultithreadInfo::n_threads() { if (n_max_threads == numbers::invalid_unsigned_int) return tbb::task_scheduler_init::default_num_threads(); @@ -164,7 +173,7 @@ unsigned int MultithreadInfo::get_n_cpus() return 1; } -unsigned int MultithreadInfo::n_threads() const +unsigned int MultithreadInfo::n_threads() { return 1; } @@ -183,9 +192,6 @@ bool MultithreadInfo::is_running_single_threaded() MultithreadInfo::MultithreadInfo () - : - n_cpus (get_n_cpus()), - n_max_threads (numbers::invalid_unsigned_int) {} @@ -199,8 +205,8 @@ MultithreadInfo::memory_consumption () } - // definition of the variable which is declared `extern' in the .h file MultithreadInfo multithread_info; + DEAL_II_NAMESPACE_CLOSE -- 2.39.5