22namespace BitSetParallel
25template <
typename IndexType>
30 return tbb::blocked_range<size_t>( beginBlock, endBlock );
36 const size_t endBlock = ( bs.size() + BS::bits_per_block - 1 ) / BS::bits_per_block;
37 return tbb::blocked_range<size_t>( 0, endBlock );
46template <
typename IndexType>
56using Range = tbb::blocked_range<size_t>;
64 FunctionRef<
void* ()> ctx, ProgressCallback progressCb,
size_t reportProgressEveryBit = 1024 );
66template <
typename BS,
typename F,
typename ...Cb>
69 if constexpr (
sizeof...( cb ) == 0 )
71 return forAllRanged( { (size_t)0, bs.size() }, [&] (
size_t i,
const Range& range )
73 using Id =
typename BS::IndexType;
74 std::forward<F>( f )(
Id{ i },
IdRange<Id>{
Id{ range.begin() },
Id{ range.end() } } );
79 return forAllRanged( { (size_t)0, bs.size() }, [&] (
size_t i,
const Range& range,
void* )
81 using Id =
typename BS::IndexType;
82 std::forward<F>( f )(
Id{ i },
IdRange<Id>{
Id{ range.begin() },
Id{ range.end() } } );
86 }, std::forward<Cb>( cb )... );
90template <
typename BS,
typename L,
typename F,
typename ...Cb>
91auto ForAllRanged(
const BS & bs, tbb::enumerable_thread_specific<L>& e, F && f, Cb && ... cb )
93 return forAllRanged( { (size_t)0, bs.size() }, [&] (
size_t i,
const Range& range,
void* ctx )
95 using Id =
typename BS::IndexType;
96 std::forward<F>( f )(
Id{ i },
IdRange<Id>{
Id{ range.begin() },
Id{ range.end() } }, *(L*)ctx );
99 return (
void*)&e.local();
100 }, std::forward<Cb>( cb )... );
110template <
typename BS,
typename ...F>
122template <
typename BS,
typename L,
typename ...F>
132template <
typename BS,
typename F,
typename ...Cb>
143template <
typename BS,
typename L,
typename F,
typename ...Cb>
146 return BitSetParallel::ForAllRanged( bs, e, [&] (
auto bit,
auto &&,
auto & tls ) { std::forward<F>( f )( bit, tls ); }, std::forward<Cb>( cb )... );
153template <
typename BS,
typename F,
typename ...Cb>
156 return BitSetParallelForAll( bs, [&] (
auto bit ) {
if ( bs.test( bit ) ) std::forward<F>( f )( bit ); }, std::forward<Cb>( cb )... );
164template <
typename BS,
typename L,
typename F,
typename ...Cb>
165inline auto BitSetParallelFor(
const BS& bs, tbb::enumerable_thread_specific<L> & e, F && f, Cb&&... cb )
167 return BitSetParallelForAll( bs, e, [&] (
auto bit,
auto & tls ) {
if ( bs.test( bit ) ) std::forward<F>( f )( bit, tls ); }, std::forward<Cb>( cb )... );
static constexpr size_t bits_per_block
Definition MRBitSet.h:27
Definition MRFunctional.h:15
stores index of some element, it is made as template class to avoid mixing faces, edges and vertices
Definition MRId.h:19
auto BitSetParallelForAll(const BS &bs, F &&f, Cb &&... cb)
Definition MRBitSetParallelFor.h:133
auto BitSetParallelForAllRanged(const BS &bs, F &&... f)
namespace BitSetParallel
Definition MRBitSetParallelFor.h:111
auto BitSetParallelFor(const BS &bs, F &&f, Cb &&... cb)
Definition MRBitSetParallelFor.h:154
MRMESH_API void forAllRanged(const Range &bitRange, FunctionRef< void(size_t, const Range &)> f)
auto ForAllRanged(const BS &bs, F &&f, Cb &&... cb)
Definition MRBitSetParallelFor.h:67
tbb::blocked_range< size_t > Range
Definition MRBitSetParallelFor.h:56
auto bitRange(const BS &bs)
Definition MRBitSetParallelFor.h:41
auto blockRange(const IdRange< IndexType > &bitRange)
Definition MRBitSetParallelFor.h:26
auto bitSubRange(const IdRange< IndexType > &bitRange, const tbb::blocked_range< size_t > &range, const tbb::blocked_range< size_t > &subRange)
Definition MRBitSetParallelFor.h:47
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
range of indices [beg, end)
Definition MRBitSetParallelFor.h:17
auto size() const
Definition MRBitSetParallelFor.h:19
Id beg
Definition MRBitSetParallelFor.h:18
Id end
Definition MRBitSetParallelFor.h:18