piranha  0.10
tuning.hpp
1 /* Copyright 2009-2017 Francesco Biscani (bluescarni@gmail.com)
2 
3 This file is part of the Piranha library.
4 
5 The Piranha library is free software; you can redistribute it and/or modify
6 it under the terms of either:
7 
8  * the GNU Lesser General Public License as published by the Free
9  Software Foundation; either version 3 of the License, or (at your
10  option) any later version.
11 
12 or
13 
14  * the GNU General Public License as published by the Free Software
15  Foundation; either version 3 of the License, or (at your option) any
16  later version.
17 
18 or both in parallel, as here.
19 
20 The Piranha library is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24 
25 You should have received copies of the GNU General Public License and the
26 GNU Lesser General Public License along with the Piranha library. If not,
27 see https://www.gnu.org/licenses/. */
28 
29 #ifndef PIRANHA_TUNING_HPP
30 #define PIRANHA_TUNING_HPP
31 
32 #include <atomic>
33 #include <stdexcept>
34 
35 #include <piranha/config.hpp>
36 #include <piranha/exceptions.hpp>
37 #include <piranha/runtime_info.hpp>
38 
39 namespace piranha
40 {
41 
42 namespace detail
43 {
44 
45 template <typename = int>
46 struct base_tuning {
47  static std::atomic<bool> s_parallel_memory_set;
48  static std::atomic<unsigned long> s_mult_block_size;
49  static std::atomic<unsigned long> s_estimate_threshold;
50 };
51 
52 template <typename T>
53 std::atomic<bool> base_tuning<T>::s_parallel_memory_set(true);
54 
55 template <typename T>
56 std::atomic<unsigned long> base_tuning<T>::s_mult_block_size(256u);
57 
58 template <typename T>
59 std::atomic<unsigned long> base_tuning<T>::s_estimate_threshold(200u);
60 }
61 
63 
67 class tuning : private detail::base_tuning<>
68 {
69 public:
71 
82  {
83  return s_parallel_memory_set.load();
84  }
86 
91  static void set_parallel_memory_set(bool flag)
92  {
93  s_parallel_memory_set.store(flag);
94  }
96 
102  {
103  s_parallel_memory_set.store(true);
104  }
106 
117  static unsigned long get_multiplication_block_size()
118  {
119  return s_mult_block_size.load();
120  }
122 
129  static void set_multiplication_block_size(unsigned long size)
130  {
131  if (unlikely(size < 16u || size > 4096u)) {
132  piranha_throw(std::invalid_argument, "invalid block size");
133  }
134  s_mult_block_size.store(size);
135  }
137 
143  {
144  s_mult_block_size.store(256u);
145  }
147 
159  static unsigned long get_estimate_threshold()
160  {
161  return s_estimate_threshold.load();
162  }
164 
169  static void set_estimate_threshold(unsigned long size)
170  {
171  s_estimate_threshold.store(size);
172  }
174 
180  {
181  s_estimate_threshold.store(200u);
182  }
183 };
184 }
185 
186 #endif
Performance tuning.
Definition: tuning.hpp:67
Exceptions.
static void reset_parallel_memory_set()
Reset the parallel_memory_set flag.
Definition: tuning.hpp:101
static void reset_estimate_threshold()
Reset the series estimation threshold.
Definition: tuning.hpp:179
static void set_estimate_threshold(unsigned long size)
Set the series estimation threshold.
Definition: tuning.hpp:169
static void set_parallel_memory_set(bool flag)
Set the parallel_memory_set flag.
Definition: tuning.hpp:91
#define piranha_throw(exception_type,...)
Exception-throwing macro.
Definition: exceptions.hpp:118
static void set_multiplication_block_size(unsigned long size)
Set the multiplication block size.
Definition: tuning.hpp:129
static unsigned long get_estimate_threshold()
Get the series estimation threshold.
Definition: tuning.hpp:159
Root piranha namespace.
Definition: array_key.hpp:52
static void reset_multiplication_block_size()
Reset the multiplication block size.
Definition: tuning.hpp:142
static unsigned long get_multiplication_block_size()
Get the multiplication block size.
Definition: tuning.hpp:117
static bool get_parallel_memory_set()
Get the parallel_memory_set flag.
Definition: tuning.hpp:81