From: Timo Heister Date: Mon, 25 May 2020 18:43:30 +0000 (-0400) Subject: fix TBB initialization X-Git-Tag: v9.3.0-rc1~1538^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9f7c8ed955cd08d7dcd99ba502e0b8dbab01ef7;p=dealii.git fix TBB initialization --- diff --git a/source/base/multithread_info.cc b/source/base/multithread_info.cc index 44545adec0..410ce1b8b8 100644 --- a/source/base/multithread_info.cc +++ b/source/base/multithread_info.cc @@ -27,7 +27,7 @@ #include -#ifdef DEAL_II_WITH_THREADS +#ifdef DEAL_II_WITH_TBB # define TBB_SUPPRESS_DEPRECATED_MESSAGES 1 # include # undef TBB_SUPPRESS_DEPRECATED_MESSAGES @@ -35,8 +35,6 @@ DEAL_II_NAMESPACE_OPEN -#ifdef DEAL_II_WITH_THREADS - /* Detecting how many processors a given machine has is something that varies greatly between operating systems. For a few operating systems, we have figured out how to do that below, but some others @@ -45,8 +43,7 @@ DEAL_II_NAMESPACE_OPEN */ -# if defined(__linux__) || defined(__sun__) || defined(__osf__) || \ - defined(_AIX) +#if defined(__linux__) || defined(__sun__) || defined(__osf__) || defined(_AIX) unsigned int MultithreadInfo::get_n_cpus() @@ -54,7 +51,7 @@ MultithreadInfo::get_n_cpus() return sysconf(_SC_NPROCESSORS_ONLN); } -# elif (defined(__MACH__) && defined(__APPLE__)) || defined(__FreeBSD__) +#elif (defined(__MACH__) && defined(__APPLE__)) || defined(__FreeBSD__) // This is only tested on a dual G5 2.5GHz running MacOSX 10.3.6 // and on an Intel Mac Book Pro. // If it doesn't work please contact the mailinglist. @@ -73,7 +70,7 @@ MultithreadInfo::get_n_cpus() return n_cpus; } -# else +#else // If you get n_cpus=1 although you are on a multi-processor machine, // then this may have two reasons: either because the system macros, @@ -103,7 +100,7 @@ MultithreadInfo::get_n_cpus() return 1; } -# endif +#endif unsigned int MultithreadInfo::n_cores() @@ -152,6 +149,8 @@ MultithreadInfo::set_thread_limit(const unsigned int max_threads) n_max_threads = max_threads_env; } } + +#ifdef DEAL_II_WITH_TBB // Without restrictions from the user query TBB for the recommended number // of threads: if (n_max_threads == numbers::invalid_unsigned_int) @@ -162,9 +161,13 @@ MultithreadInfo::set_thread_limit(const unsigned int max_threads) if (dummy.is_active()) dummy.terminate(); dummy.initialize(n_max_threads); +#endif + if (n_max_threads == numbers::invalid_unsigned_int) + n_max_threads = get_n_cpus(); } + unsigned int MultithreadInfo::n_threads() { @@ -173,32 +176,6 @@ MultithreadInfo::n_threads() } -#else // not in MT mode - -unsigned int -MultithreadInfo::get_n_cpus() -{ - return 1; -} - -unsigned int -MultithreadInfo::n_cores() -{ - return 1; -} - -unsigned int -MultithreadInfo::n_threads() -{ - return 1; -} - -void -MultithreadInfo::set_thread_limit(const unsigned int) -{} - -#endif - bool MultithreadInfo::is_running_single_threaded() @@ -207,6 +184,7 @@ MultithreadInfo::is_running_single_threaded() } + std::size_t MultithreadInfo::memory_consumption() { @@ -216,6 +194,7 @@ MultithreadInfo::memory_consumption() } + void MultithreadInfo::initialize_multithreading() {