29 #ifndef PIRANHA_SETTINGS_HPP 30 #define PIRANHA_SETTINGS_HPP 36 #include <piranha/config.hpp> 38 #include <piranha/runtime_info.hpp> 39 #include <piranha/thread_pool.hpp> 47 template <
typename =
int>
48 struct base_settings {
49 static std::mutex m_mutex;
50 static unsigned m_cache_line_size;
51 static unsigned long m_max_term_output;
52 static const unsigned long m_default_max_term_output = 20ul;
53 static std::atomic_ullong s_min_work_per_thread;
56 static const unsigned long long s_default_min_work_per_thread = 250000ull;
60 std::mutex base_settings<T>::m_mutex;
66 unsigned long base_settings<T>::m_max_term_output = base_settings<T>::m_default_max_term_output;
69 const unsigned long base_settings<T>::m_default_max_term_output;
72 const unsigned long long base_settings<T>::s_default_min_work_per_thread;
75 std::atomic_ullong base_settings<T>::s_min_work_per_thread(base_settings<T>::s_default_min_work_per_thread);
88 template <
typename =
void>
168 std::lock_guard<std::mutex> lock(m_mutex);
169 return m_cache_line_size;
182 std::lock_guard<std::mutex> lock(m_mutex);
183 m_cache_line_size = n;
193 std::lock_guard<std::mutex> lock(m_mutex);
204 std::lock_guard<std::mutex> lock(m_mutex);
205 return m_max_term_output;
215 std::lock_guard<std::mutex> lock(m_mutex);
216 m_max_term_output = n;
226 std::lock_guard<std::mutex> lock(m_mutex);
227 m_max_term_output = m_default_max_term_output;
235 return s_min_work_per_thread.load();
245 if (unlikely(n == 0u)) {
246 piranha_throw(std::invalid_argument,
"the minimum work per thread value must be strictly positive");
248 return s_min_work_per_thread.store(n);
256 s_min_work_per_thread.store(s_default_min_work_per_thread);
static void set_min_work_per_thread(unsigned long long n)
Set the minimum work per thread.
static unsigned get_cache_line_size()
Size of the data cache line.
static void reset_cache_line_size()
Reset the cache line size.
static void set_max_term_output(unsigned long n)
Set max term output.
static void reset_max_term_output()
Reset max term output.
static unsigned get_cache_line_size()
Get the cache line size.
static bool get_thread_binding()
Get the thread binding policy.
static unsigned long get_max_term_output()
Get max term output.
static void reset_min_work_per_thread()
Reset the minimum work per thread.
static void set_cache_line_size(unsigned n)
Set the cache line size.
#define piranha_throw(exception_type,...)
Exception-throwing macro.
static void set_n_threads(unsigned n)
Set the number of threads available for use by piranha.
static void reset_n_threads()
Reset the number of threads available for use by piranha.
static void set_thread_binding(bool flag)
Set the thread binding policy.
static unsigned size()
Size.
static unsigned get_hardware_concurrency()
Hardware concurrency.
static unsigned get_n_threads()
Get the number of threads available for use by piranha.
static void set_binding(bool flag)
Set the thread binding policy.
static unsigned long long get_min_work_per_thread()
Get the minimum work per thread.
static void resize(unsigned new_size)
Change the number of threads.
static bool get_binding()
Get the thread binding policy.