26 return omp_get_max_threads();
40 return omp_get_thread_num();
65 if(n <= std::size_t(0))
71#if !defined(FEAT_HAVE_OMP)
74 for(std::size_t i = 0u; i < n; ++i)
78 const std::size_t max_threads(omp_get_max_threads());
79 if(n < 10u*max_threads)
83 for(std::size_t i = 0u; i < n; ++i)
89 std::vector<T_> vo(max_threads+1u, T_(0));
92 FEAT_PRAGMA_OMP(parallel shared(vo))
94 const std::size_t num_threads(omp_get_num_threads());
95 const std::size_t thread_id(omp_get_thread_num());
98 const std::size_t i0 = (n * thread_id) / num_threads;
99 const std::size_t i1 = (n * (thread_id+1u)) / num_threads;
103 for(std::size_t i = i0; i < i1; ++i)
109 vo[thread_id+1u] = k;
112 FEAT_PRAGMA_OMP(barrier)
115 FEAT_PRAGMA_OMP(master)
117 for(std::size_t i = 1u; i < num_threads; ++i)
124 FEAT_PRAGMA_OMP(barrier)
128 for(std::size_t i = i0; i < i1; ++i)
152 template<
typename T_>
155 if(n <= std::size_t(0))
161#if !defined(FEAT_HAVE_OMP)
164 for(std::size_t i = 0u; i < n; ++i)
172 const std::size_t max_threads(omp_get_max_threads());
173 if(n < 10u*max_threads)
177 for(std::size_t i = 0u; i < n; ++i)
187 std::vector<T_> vo(max_threads+1u, T_(0));
190 FEAT_PRAGMA_OMP(parallel shared(vo))
192 const std::size_t num_threads(omp_get_num_threads());
193 const std::size_t thread_id(omp_get_thread_num());
196 const std::size_t i0 = (n * thread_id) / num_threads;
197 const std::size_t i1 = (n * (thread_id+1u)) / num_threads;
201 for(std::size_t i = i0; i < i1; ++i)
209 vo[thread_id+1u] = k;
212 FEAT_PRAGMA_OMP(barrier)
215 FEAT_PRAGMA_OMP(master)
217 for(std::size_t i = 1u; i < num_threads; ++i)
224 FEAT_PRAGMA_OMP(barrier)
228 for(std::size_t i = i0; i < i1; ++i)
#define XASSERT(expr)
Assertion macro definition.
void feat_omp_ex_scan(std::size_t n, const T_ x[], T_ y[])
Computes an OpenMP-parallel exclusive scan a.k.a. a prefix sum of an array, i.e.
void feat_omp_in_scan(std::size_t n, const T_ x[], T_ y[])
Computes an OpenMP-parallel inclusive scan a.k.a. a prefix sum of an array, i.e.
int feat_omp_get_thread_num()
Returns the momentary omp thread.
int feat_omp_get_max_threads()
Returns the maximum number of omp threads.