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>;
77template <
typename BS,
typename F,
typename ...Cb>
80 if constexpr (
sizeof...( cb ) == 0 )
82 return forAllRanged( { (size_t)0, bs.size() }, [&] (
size_t i,
const Range& range )
84 using Id =
typename BS::IndexType;
85 std::forward<F>( f )(
Id{ i },
IdRange<Id>{
Id{ range.begin() },
Id{ range.end() } } );
90 return forAllRanged( { (size_t)0, bs.size() }, [&] (
size_t i,
const Range& range,
void* )
92 using Id =
typename BS::IndexType;
93 std::forward<F>( f )(
Id{ i },
IdRange<Id>{
Id{ range.begin() },
Id{ range.end() } } );
97 }, std::forward<Cb>( cb )... );
101template <
typename BS,
typename L,
typename F,
typename ...Cb>
102auto ForAllRanged(
const BS & bs, tbb::enumerable_thread_specific<L>& e, F && f, Cb && ... cb )
104 return forAllRanged( { (size_t)0, bs.size() }, [&] (
size_t i,
const Range& range,
void* ctx )
106 using Id =
typename BS::IndexType;
107 std::forward<F>( f )(
Id{ i },
IdRange<Id>{
Id{ range.begin() },
Id{ range.end() } }, *(L*)ctx );
110 return (
void*)&e.local();
111 }, std::forward<Cb>( cb )... );
121template <
typename BS,
typename ...F>
133template <
typename BS,
typename L,
typename ...F>
143template <
typename BS,
typename F,
typename ...Cb>
152template <
typename BS,
typename F>
157 std::forward<F>( f )(
typename BS::IndexType{ i } );
166template <
typename BS,
typename L,
typename F,
typename ...Cb>
169 return BitSetParallel::ForAllRanged( bs, e, [&] (
auto bit,
auto &&,
auto & tls ) { std::forward<F>( f )( bit, tls ); }, std::forward<Cb>( cb )... );
176template <
typename BS,
typename F,
typename ...Cb>
179 if constexpr (
sizeof...( cb ) == 0 )
183 [] {
return (
void*)
nullptr; }, std::forward<Cb>( cb )... );
189template <
typename BS,
typename F>
200template <
typename BS,
typename L,
typename F,
typename ...Cb>
201inline auto BitSetParallelFor(
const BS& bs, tbb::enumerable_thread_specific<L> & e, F && f, Cb&&... cb )
204 [&] {
return (
void*)&e.local(); }, std::forward<Cb>( cb )... );
210template <
typename In,
typename Res,
typename Visit>
211void BitSetWalk(
const In & input, Res & res,
bool parallel, Visit && visit )
213 using I =
typename Res::IndexType;
215 BitSetParallelFor( input, [&](
typename In::IndexType x ) { visit( x, [&]( I i ) { res.atomicTestSet( i ); } ); } );
217 for (
auto x : input )
218 visit( x, [&]( I i ) { res.set( i ); } );
#define MRMESH_API
Definition MRMeshFwd.h:85
static constexpr size_t bits_per_block
Definition MRBitSet.h:75
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:20
auto BitSetParallelForAll(const BS &bs, F &&f, Cb &&... cb)
Definition MRBitSetParallelFor.h:144
auto BitSetParallelForAllRanged(const BS &bs, F &&... f)
Definition MRBitSetParallelFor.h:122
auto BitSetParallelFor(const BS &bs, F &&f, Cb &&... cb)
Definition MRBitSetParallelFor.h:177
void BitSetWalk(const In &input, Res &res, bool parallel, Visit &&visit)
Definition MRBitSetParallelFor.h:211
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:790
Definition MRBitSetParallelFor.h:23
auto ForAllRanged(const BS &bs, F &&f, Cb &&... cb)
Definition MRBitSetParallelFor.h:78
void forSetRanged(const BitSet &bs, FunctionRef< void(size_t, const Range &)> f)
calls f( bit, subBitRange ) for every set bit of bs in parallel threads, skipping the blocks without ...
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
void forAllRanged(const Range &bitRange, FunctionRef< void(size_t, const Range &)> f)
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 strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
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