24 #ifndef FUB_EXT_OMP_HPP
25 #define FUB_EXT_OMP_HPP
42 template <
typename T,
typename Allocator = std::allocator<T>>
class OmpLocal {
45 explicit OmpLocal(
const T& value, Allocator alloc = Allocator());
48 const T&
Get() const noexcept;
50 T* operator->() noexcept;
51 const T* operator->() const noexcept;
53 T& operator*() noexcept;
54 const T& operator*() const noexcept;
56 const T&
Min() const noexcept;
58 template <typename BinaryOperation = std::plus<>>
59 auto
Accumulate(BinaryOperation op = BinaryOperation()) const noexcept;
66 template <
typename T,
typename Allocator>
68 : instances_(static_cast<std::size_t>(::omp_get_max_threads()), value,
71 template <
typename T,
typename Allocator>
73 const int thread_num = ::omp_get_thread_num();
75 const std::size_t
index =
static_cast<std::size_t
>(thread_num);
76 return instances_[
index];
79 template <
typename T,
typename Allocator>
81 const int thread_num = ::omp_get_thread_num();
83 const std::size_t
index =
static_cast<std::size_t
>(thread_num);
84 return instances_[
index];
87 template <
typename T,
typename Allocator>
89 : instances_(1, value, alloc) {}
91 template <
typename T,
typename Allocator>
96 template <
typename T,
typename Allocator>
102 template <
typename T,
typename Allocator>
107 template <
typename T,
typename Allocator>
112 template <
typename T,
typename Allocator>
117 template <
typename T,
typename Allocator>
122 template <
typename T,
typename Allocator>
124 return *std::min_element(instances_.begin(), instances_.end());
127 template <
typename T,
typename Allocator>
128 template <
typename BinaryOperator>
131 return std::accumulate(instances_.begin() + 1, instances_.end(), instances_[0], op);
#define FUB_ASSERT(x)
Definition: assert.hpp:39
std::vector< T, Allocator > instances_
Definition: omp.hpp:62
OmpLocal(const T &value, Allocator alloc=Allocator())
Definition: omp.hpp:88
T & Get() noexcept
Definition: omp.hpp:92
T * operator->() noexcept
Definition: omp.hpp:103
T & operator*() noexcept
Definition: omp.hpp:113
auto Accumulate(BinaryOperation op=BinaryOperation()) const noexcept
const T & Min() const noexcept
Definition: omp.hpp:123
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
std::ptrdiff_t index
Definition: type_traits.hpp:179