3#include <batmat/config.hpp>
20[[gnu::always_inline]]
inline void foreach_chunked(index_t i_begin, index_t i_end,
auto chunk_size,
21 auto func_chunk,
auto func_rem,
25 for (i = i_begin; i + chunk_size <= i_end; i += chunk_size)
27 index_t rem_i = i_end - i;
31 index_t rem_i = (i_end - i_begin) % chunk_size;
32 index_t i = i_end - rem_i;
35 for (i -= chunk_size; i >= i_begin; i -= chunk_size)
44 auto chunk_size,
auto func_chunk,
48 for (i = i_begin; i + chunk_size <= i_end; i += chunk_size)
49 func_chunk(i, chunk_size);
50 index_t rem_i = i_end - i;
54 index_t rem_i = (i_end - i_begin) % chunk_size;
55 index_t i = i_end - rem_i;
58 for (i -= chunk_size; i >= i_begin; i -= chunk_size)
59 func_chunk(i, chunk_size);
64[[deprecated, gnu::always_inline]]
inline void
67 const index_t rem_i = (i_end - i_begin) % chunk_size;
71 for (index_t i = i_begin; i <= i_end - chunk_size; i += chunk_size)
72 func_chunk(i, chunk_size);
75 func_chunk(i_end - rem_i, rem_i);
79 const index_t i_last = i_end - rem_i;
83 func_chunk(i_last, rem_i);
86 for (index_t i = i_last - chunk_size; i >= i_begin; i -= chunk_size)
87 func_chunk(i, chunk_size);
95 if (omp_get_max_threads() == 1) {
96 func(index_t{0}, index_t{1});
99 auto ni =
static_cast<index_t
>(omp_get_num_threads());
101 for (index_t i = 0; i < ni; ++i)
111[[deprecated, gnu::always_inline]]
inline void foreach_thread(index_t num_threads,
auto &&func) {
112#if BATMAT_WITH_OPENMP
113 if (num_threads == 1) {
114 func(index_t{0}, index_t{1});
116 BATMAT_OMP(parallel num_threads(num_threads)) {
117 auto ni =
static_cast<index_t
>(omp_get_num_threads());
119 for (index_t i = 0; i < ni; ++i)
void pool_sync_run_all(F &&f)
Run a function on all threads in the global thread pool, synchronously waiting for all threads.
void foreach_chunked(index_t i_begin, index_t i_end, auto chunk_size, auto func_chunk, auto func_rem, LoopDir dir=LoopDir::Forward)
Iterate over the range [i_begin, i_end) in chunks of size chunk_size, calling func_chunk for each ful...
void pool_sync_run_n(I n, F &&f)
Run a function on the first n threads in the global thread pool, synchronously waiting for those thre...
void foreach_chunked_merged(index_t i_begin, index_t i_end, auto chunk_size, auto func_chunk, LoopDir dir=LoopDir::Forward)
Iterate over the range [i_begin, i_end) in chunks of size chunk_size, calling func_chunk for each chu...
void foreach_thread(auto &&func)
void foreach_chunked_merged_parallel(index_t i_begin, index_t i_end, auto chunk_size, auto func_chunk, LoopDir dir=LoopDir::Forward)