Fix tbb assert when grainsize is lower then 1

This commit is contained in:
tamasmeszaros 2022-02-22 12:41:51 +01:00
parent d03b464dd3
commit 4ed411f211

View File

@ -5,6 +5,7 @@
#include <utility> #include <utility>
#include <cstddef> #include <cstddef>
#include <iterator> #include <iterator>
#include <algorithm>
#include "libslic3r/libslic3r.h" #include "libslic3r/libslic3r.h"
@ -44,7 +45,8 @@ size_t max_concurrency(const EP &ep)
template<class EP, class It, class Fn, class = ExecutionPolicyOnly<EP>> template<class EP, class It, class Fn, class = ExecutionPolicyOnly<EP>>
void for_each(const EP &ep, It from, It to, Fn &&fn, size_t granularity = 1) void for_each(const EP &ep, It from, It to, Fn &&fn, size_t granularity = 1)
{ {
AsTraits<EP>::for_each(ep, from, to, std::forward<Fn>(fn), granularity); AsTraits<EP>::for_each(ep, from, to, std::forward<Fn>(fn),
std::max(granularity, size_t(1)));
} }
// A reduce operation with the execution policy passed as argument. // A reduce operation with the execution policy passed as argument.
@ -68,7 +70,7 @@ T reduce(const EP & ep,
return AsTraits<EP>::reduce(ep, from, to, init, return AsTraits<EP>::reduce(ep, from, to, init,
std::forward<MergeFn>(mergefn), std::forward<MergeFn>(mergefn),
std::forward<AccessFn>(accessfn), std::forward<AccessFn>(accessfn),
granularity); std::max(granularity, size_t(1)));
} }
// An overload of reduce method to be used with iterators as 'from' and 'to' // An overload of reduce method to be used with iterators as 'from' and 'to'
@ -87,7 +89,7 @@ T reduce(const EP &ep,
{ {
return reduce( return reduce(
ep, from, to, init, std::forward<MergeFn>(mergefn), ep, from, to, init, std::forward<MergeFn>(mergefn),
[](const auto &i) { return i; }, granularity); [](const auto &i) { return i; }, std::max(granularity, size_t(1)));
} }
template<class EP, template<class EP,
@ -103,7 +105,8 @@ T accumulate(const EP & ep,
size_t granularity = 1) size_t granularity = 1)
{ {
return reduce(ep, from, to, init, std::plus<T>{}, return reduce(ep, from, to, init, std::plus<T>{},
std::forward<AccessFn>(accessfn), granularity); std::forward<AccessFn>(accessfn),
std::max(granularity, size_t(1)));
} }
@ -119,7 +122,7 @@ T accumulate(const EP &ep,
{ {
return reduce( return reduce(
ep, from, to, init, std::plus<T>{}, [](const auto &i) { return i; }, ep, from, to, init, std::plus<T>{}, [](const auto &i) { return i; },
granularity); std::max(granularity, size_t(1)));
} }
} // namespace execution_policy } // namespace execution_policy