11#ifndef CUBBYFLOW_PARALLEL_IMPL_HPP
12#define CUBBYFLOW_PARALLEL_IMPL_HPP
17#if defined(CUBBYFLOW_TASKING_HPX)
18#include <hpx/include/future.hpp>
19#include <hpx/include/parallel_fill.hpp>
20#include <hpx/include/parallel_for_each.hpp>
21#include <hpx/include/parallel_for_loop.hpp>
22#include <hpx/include/parallel_reduce.hpp>
23#include <hpx/include/parallel_sort.hpp>
26#if defined(CUBBYFLOW_TASKING_TBB)
27#include <tbb/parallel_for.h>
28#include <tbb/parallel_reduce.h>
29#include <tbb/parallel_sort.h>
30#include <tbb/task_arena.h>
31#elif defined(CUBBYFLOW_TASKING_CPP11THREAD)
44#if defined(CUBBYFLOW_TASKING_HPX)
45template <
typename Task>
46using future = hpx::future<Task>;
48template <
typename Task>
52template <
typename TASK>
55template <
typename TASK>
58#if defined(CUBBYFLOW_TASKING_HPX)
59 return hpx::async(std::forward<TASK>(
fn));
60#elif defined(CUBBYFLOW_TASKING_TBB)
61 using package_t = std::packaged_task<operator_return_t<TASK>()>;
70 void operator()()
const
76 tbb::task_arena
arena{ tbb::task_arena::attach{} };
80#elif defined(CUBBYFLOW_TASKING_CPP11THREAD)
81 return std::async(std::launch::async, std::forward<TASK>(
fn));
83 return std::async(std::launch::deferred, std::forward<TASK>(
fn));
147 std::vector<future<void>>
pool;
181template <
typename RandomIterator,
typename T>
185 auto diff = end - begin;
191#if defined(CUBBYFLOW_TASKING_HPX)
192 hpx::parallel::fill(hpx::parallel::execution::par, begin, end, value);
194 size_t size =
static_cast<size_t>(
diff);
196 ZERO_SIZE,
size, [begin, value](
size_t i) { begin[i] = value; },
202template <
typename IndexType,
typename Function>
213#if defined(CUBBYFLOW_TASKING_TBB)
216#elif defined(CUBBYFLOW_TASKING_HPX)
218 hpx::parallel::for_loop(hpx::parallel::execution::par,
beginIndex,
220#elif defined(CUBBYFLOW_TASKING_CPP11THREAD)
241 std::vector<std::thread>
pool;
259 for (std::thread&
t :
pool)
269#if defined(CUBBYFLOW_TASKING_OPENMP)
270#pragma omp parallel for
271#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
297template <
typename IndexType,
typename Function>
308#if defined(CUBBYFLOW_TASKING_TBB)
327 std::vector<CubbyFlow::Internal::future<void>>
pool;
362template <
typename IndexType,
typename Function>
378template <
typename IndexType,
typename Function>
392template <
typename IndexType,
typename Function>
413template <
typename IndexType,
typename Function>
442#if defined(CUBBYFLOW_TASKING_TBB)
443 return tbb::parallel_reduce(
472 std::vector<CubbyFlow::Internal::future<void>>
pool;
523template <
typename RandomIterator>
525template <std::random_access_iterator RandomIterator>
532 std::less<
typename std::iterator_traits<RandomIterator>::value_type>(),
537template <
typename RandomIterator,
typename CompareFunction>
539template <std::random_access_iterator RandomIterator,
typename CompareFunction>
551#if defined(CUBBYFLOW_TASKING_HPX)
552 hpx::parallel::sort(hpx::parallel::execution::par, begin, end,
554#elif defined(CUBBYFLOW_TASKING_TBB)
558 size_t size =
static_cast<size_t>(end - begin);
561 typename std::iterator_traits<RandomIterator>::value_type;
Iterator begin()
Definition Matrix-Impl.hpp:272
Iterator end()
Definition Matrix-Impl.hpp:285
std::future< Task > future
Definition Parallel-Impl.hpp:49
void ParallelMergeSort(RandomIterator a, size_t size, RandomIterator2 temp, unsigned int numThreads, CompareFunction compareFunction)
Definition Parallel-Impl.hpp:138
typename std::invoke_result_t< TASK > operator_return_t
Definition Parallel-Impl.hpp:53
auto Async(TASK &&fn) -> future< operator_return_t< TASK > >
Definition Parallel-Impl.hpp:56
void Merge(RandomIterator a, size_t size, RandomIterator2 temp, CompareFunction compareFunction)
Definition Parallel-Impl.hpp:95
Definition pybind11Utils.hpp:22
constexpr size_t ZERO_SIZE
Zero size_t.
Definition Constants.hpp:20
void ParallelSort(RandomIterator begin, RandomIterator end, ExecutionPolicy policy)
Sorts a container in parallel.
Definition Parallel-Impl.hpp:527
void ParallelFill(const RandomIterator &begin, const RandomIterator &end, const T &value, ExecutionPolicy policy)
Fills from begin to end with value in parallel.
Definition Parallel-Impl.hpp:182
void ParallelFor(IndexType beginIndex, IndexType endIndex, const Function &function, ExecutionPolicy policy)
Makes a for-loop from beginIndex to endIndex in parallel.
Definition Parallel-Impl.hpp:203
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:719
unsigned int GetMaxNumberOfThreads()
Returns maximum number of threads to use.
void ParallelRangeFor(IndexType beginIndex, IndexType endIndex, const Function &function, ExecutionPolicy policy)
Makes a range-loop from beginIndex to endIndex in parallel.
Definition Parallel-Impl.hpp:298
Value ParallelReduce(IndexType beginIndex, IndexType endIndex, const Value &identity, const Function &function, const Reduce &reduce, ExecutionPolicy policy)
Performs reduce operation in parallel.
Definition Parallel-Impl.hpp:431
ExecutionPolicy
Execution policy tag.
Definition Parallel.hpp:20