9 #include "imstkMacros.h" 12 DISABLE_WARNING_PADDING
18 namespace ParallelUtils
27 template<
class IndexType,
class Function>
29 parallelFor(
const IndexType beginIdx,
const IndexType endIdx, Function&&
function,
const bool doParallel =
true)
33 tbb::parallel_for(tbb::blocked_range<IndexType>(beginIdx, endIdx),
34 [&](
const tbb::blocked_range<IndexType>& r) {
35 for (IndexType i = r.begin(), iEnd = r.end(); i < iEnd; ++i)
43 for (IndexType i = beginIdx; i < endIdx; i++)
53 template<
class IndexType,
class Function>
55 parallelFor(
const IndexType endIdx, Function&&
function,
const bool doParallel =
true)
57 parallelFor(IndexType(0), endIdx, std::forward<Function>(
function), doParallel);
64 template<
class IndexType,
class Function>
66 parallelFor2Dx(
const IndexType beginX,
const IndexType endX,
67 const IndexType beginY,
const IndexType endY,
70 parallelFor(beginX, endX,
72 for (IndexType j = beginY; j < endY; ++j)
83 template<
class IndexType,
class Function>
85 parallelFor2Dy(
const IndexType beginX,
const IndexType endX,
86 const IndexType beginY,
const IndexType endY,
89 parallelFor(beginY, endY,
91 for (IndexType i = beginX; i < endX; ++i)
102 template<
class IndexType,
class Function>
104 parallelFor3Dx(
const IndexType beginX,
const IndexType endX,
105 const IndexType beginY,
const IndexType endY,
106 const IndexType beginZ,
const IndexType endZ,
109 parallelFor(beginX, endX,
111 for (IndexType j = beginY; j < endY; ++j)
113 for (IndexType k = beginZ; k < endZ; ++k)
125 template<
class IndexType,
class Function>
127 parallelFor3Dy(
const IndexType beginX,
const IndexType endX,
128 const IndexType beginY,
const IndexType endY,
129 const IndexType beginZ,
const IndexType endZ,
132 parallelFor(beginY, endY,
134 for (IndexType i = beginX; i < endX; ++i)
136 for (IndexType k = beginZ; k < endZ; ++k)
148 template<
class IndexType,
class Function>
150 parallelFor3Dz(
const IndexType beginX,
const IndexType endX,
151 const IndexType beginY,
const IndexType endY,
152 const IndexType beginZ,
const IndexType endZ,
155 parallelFor(beginX, endX,
157 for (IndexType j = beginY; j < endY; ++j)
159 for (IndexType k = beginZ; k < endZ; ++k)