#ifndef PXR_EXTRAS_USD_EXAMPLES_WORK_TASKFLOW_EXAMPLE_LOOPS_H
#define PXR_EXTRAS_USD_EXAMPLES_WORK_TASKFLOW_EXAMPLE_LOOPS_H
#include <taskflow/taskflow.hpp>
#include <taskflow/algorithm/for_each.hpp>
#include <taskflow/utility/iterator.hpp>
template <typename Fn>
void
WorkImpl_ParallelForN(size_t n, Fn &&callback, size_t grainSize)
{
tf::Taskflow taskflow;
tf::Executor executor;
tf::IndexRange<size_t> range(0, n, 1);
taskflow.for_each_by_index(range, [&](tf::IndexRange<size_t> subrange){
std::forward<Fn>(callback)(subrange.begin(),subrange.end());
});
executor.run(taskflow).wait();
}
template <typename InputIterator, typename Fn>
void
WorkImpl_ParallelForEach(
InputIterator first, InputIterator last, Fn &&fn)
{
tf::Taskflow taskflow;
tf::Executor executor(1);
taskflow.for_each(first, last, std::forward<Fn>(fn));
executor.run(taskflow).wait();
}
#endif