Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
libnest2d::__parallel Namespace Reference

Typedefs

template<class It >
using TIteratorValue = typename std::iterator_traits< It >::value_type
 

Functions

template<class Iterator >
void enumerate (Iterator from, Iterator to, std::function< void(TIteratorValue< Iterator >, size_t)> fn, std::launch policy=std::launch::deferred|std::launch::async)
 

Typedef Documentation

◆ TIteratorValue

template<class It >
using libnest2d::__parallel::TIteratorValue = typedef typename std::iterator_traits<It>::value_type

Function Documentation

◆ enumerate()

template<class Iterator >
void libnest2d::__parallel::enumerate ( Iterator  from,
Iterator  to,
std::function< void(TIteratorValue< Iterator >, size_t)>  fn,
std::launch  policy = std::launch::deferred | std::launch::async 
)
inline
26{
27 using TN = size_t;
28 auto iN = to-from;
29 TN N = iN < 0? 0 : TN(iN);
30
31#ifdef LIBNEST2D_THREADING_tbb
32 if((policy & std::launch::async) == std::launch::async) {
33 tbb::parallel_for<TN>(0, N, [from, fn] (TN n) { fn(*(from + n), n); } );
34 } else {
35 for(TN n = 0; n < N; n++) fn(*(from + n), n);
36 }
37#endif
38
39#ifdef LIBNEST2D_THREADING_omp
40 if((policy & std::launch::async) == std::launch::async) {
41 #pragma omp parallel for
42 for(int n = 0; n < int(N); n++) fn(*(from + n), TN(n));
43 }
44 else {
45 for(TN n = 0; n < N; n++) fn(*(from + n), n);
46 }
47#endif
48
49#ifdef LIBNEST2D_THREADING_std
50 std::vector<std::future<void>> rets(N);
51
52 auto it = from;
53 for(TN b = 0; b < N; b++) {
54 rets[b] = std::async(policy, fn, *it++, unsigned(b));
55 }
56
57 for(TN fi = 0; fi < N; ++fi) rets[fi].wait();
58#endif
59}

Referenced by libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::calcnfp(), and libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::trypack().

+ Here is the caller graph for this function: