Commit 49c254b4 by Marcus Winter

moved ExecutionPolicy from algorithms to mtapi_cpp, removed Affinity

parent 650dec9d
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
*/ */
#include <embb/algorithms/count.h> #include <embb/algorithms/count.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/algorithms/for_each.h> #include <embb/algorithms/for_each.h>
#include <embb/algorithms/identity.h> #include <embb/algorithms/identity.h>
#include <embb/algorithms/invoke.h> #include <embb/algorithms/invoke.h>
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
#ifndef EMBB_ALGORITHMS_COUNT_H_ #ifndef EMBB_ALGORITHMS_COUNT_H_
#define EMBB_ALGORITHMS_COUNT_H_ #define EMBB_ALGORITHMS_COUNT_H_
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
#include <iterator>
namespace embb { namespace embb {
namespace algorithms { namespace algorithms {
...@@ -70,7 +71,7 @@ typename std::iterator_traits<RAI>::difference_type Count( ...@@ -70,7 +71,7 @@ typename std::iterator_traits<RAI>::difference_type Count(
const ValueType& value, const ValueType& value,
/**< [IN] Value that the elements in the range are compared to using /**< [IN] Value that the elements in the range are compared to using
\c operator== */ \c operator== */
const ExecutionPolicy& policy = ExecutionPolicy(), const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the counting algorithm */ /**< [IN] ExecutionPolicy for the counting algorithm */
size_t block_size = 0 size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that /**< [IN] Lower bound for partitioning the range of elements into blocks that
...@@ -110,7 +111,7 @@ typename std::iterator_traits<RAI>::difference_type CountIf( ...@@ -110,7 +111,7 @@ typename std::iterator_traits<RAI>::difference_type CountIf(
ComparisonFunction comparison, ComparisonFunction comparison,
/**< [IN] Unary predicate used to test the elements in the range. Elements for /**< [IN] Unary predicate used to test the elements in the range. Elements for
which \c comparison returns true are counted. */ which \c comparison returns true are counted. */
const ExecutionPolicy& policy = ExecutionPolicy(), const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the counting algorithm */ /**< [IN] ExecutionPolicy for the counting algorithm */
size_t block_size = 0 size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that /**< [IN] Lower bound for partitioning the range of elements into blocks that
...@@ -124,6 +125,18 @@ typename std::iterator_traits<RAI>::difference_type CountIf( ...@@ -124,6 +125,18 @@ typename std::iterator_traits<RAI>::difference_type CountIf(
#else // DOXYGEN #else // DOXYGEN
/** /**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ValueType>
typename std::iterator_traits<RAI>::difference_type Count(
RAI first,
RAI last,
const ValueType& value,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy with less arguments. * Overload of above described Doxygen dummy with less arguments.
*/ */
template<typename RAI, typename ValueType> template<typename RAI, typename ValueType>
...@@ -132,7 +145,7 @@ typename std::iterator_traits<RAI>::difference_type Count( ...@@ -132,7 +145,7 @@ typename std::iterator_traits<RAI>::difference_type Count(
RAI last, RAI last,
const ValueType& value const ValueType& value
) { ) {
return Count(first, last, value, ExecutionPolicy(), 0); return Count(first, last, value, embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
...@@ -143,7 +156,7 @@ typename std::iterator_traits<RAI>::difference_type Count( ...@@ -143,7 +156,7 @@ typename std::iterator_traits<RAI>::difference_type Count(
RAI first, RAI first,
RAI last, RAI last,
const ValueType& value, const ValueType& value,
const ExecutionPolicy& policy const embb::mtapi::ExecutionPolicy& policy
) { ) {
return Count(first, last, value, policy, 0); return Count(first, last, value, policy, 0);
} }
...@@ -151,12 +164,12 @@ typename std::iterator_traits<RAI>::difference_type Count( ...@@ -151,12 +164,12 @@ typename std::iterator_traits<RAI>::difference_type Count(
/** /**
* Overload of above described Doxygen dummy. * Overload of above described Doxygen dummy.
*/ */
template<typename RAI, typename ValueType> template<typename RAI, typename ComparisonFunction>
typename std::iterator_traits<RAI>::difference_type Count( typename std::iterator_traits<RAI>::difference_type CountIf(
RAI first, RAI first,
RAI last, RAI last,
const ValueType& value, ComparisonFunction comparison,
const ExecutionPolicy& policy, const embb::mtapi::ExecutionPolicy& policy,
size_t block_size size_t block_size
); );
...@@ -169,7 +182,7 @@ typename std::iterator_traits<RAI>::difference_type CountIf( ...@@ -169,7 +182,7 @@ typename std::iterator_traits<RAI>::difference_type CountIf(
RAI last, RAI last,
ComparisonFunction comparison ComparisonFunction comparison
) { ) {
return CountIf(first, last, comparison, ExecutionPolicy(), 0); return CountIf(first, last, comparison, embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
...@@ -180,23 +193,11 @@ typename std::iterator_traits<RAI>::difference_type CountIf( ...@@ -180,23 +193,11 @@ typename std::iterator_traits<RAI>::difference_type CountIf(
RAI first, RAI first,
RAI last, RAI last,
ComparisonFunction comparison, ComparisonFunction comparison,
const ExecutionPolicy& policy const embb::mtapi::ExecutionPolicy& policy
) { ) {
return CountIf(first, last, comparison, policy, 0); return CountIf(first, last, comparison, policy, 0);
} }
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ComparisonFunction>
typename std::iterator_traits<RAI>::difference_type CountIf(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy,
size_t block_size
);
#endif // else DOXYGEN #endif // else DOXYGEN
/** /**
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#ifndef EMBB_ALGORITHMS_FOR_EACH_H_ #ifndef EMBB_ALGORITHMS_FOR_EACH_H_
#define EMBB_ALGORITHMS_FOR_EACH_H_ #define EMBB_ALGORITHMS_FOR_EACH_H_
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
namespace embb { namespace embb {
namespace algorithms { namespace algorithms {
...@@ -67,7 +67,7 @@ void ForEach( ...@@ -67,7 +67,7 @@ void ForEach(
range */ range */
Function unary, Function unary,
/**< [IN] Unary function applied to each element in the range */ /**< [IN] Unary function applied to each element in the range */
const ExecutionPolicy& policy = ExecutionPolicy(), const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the foreach loop execution */ /**< [IN] ExecutionPolicy for the foreach loop execution */
size_t block_size = 0 size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that /**< [IN] Lower bound for partitioning the range of elements into blocks that
...@@ -81,16 +81,16 @@ void ForEach( ...@@ -81,16 +81,16 @@ void ForEach(
#else // DOXYGEN #else // DOXYGEN
/** /**
* Overload of above described Doxygen dummy with less arguments. * Overload of above described Doxygen dummy.
*/ */
template<typename RAI, typename Function> template<typename RAI, typename Function>
void ForEach( void ForEach(
RAI first, RAI first,
RAI last, RAI last,
Function unary Function unary,
) { const embb::mtapi::ExecutionPolicy& policy,
ForEach(first, last, unary, ExecutionPolicy(), 0); size_t block_size
} );
/** /**
* Overload of above described Doxygen dummy with less arguments. * Overload of above described Doxygen dummy with less arguments.
...@@ -99,23 +99,23 @@ template<typename RAI, typename Function> ...@@ -99,23 +99,23 @@ template<typename RAI, typename Function>
void ForEach( void ForEach(
RAI first, RAI first,
RAI last, RAI last,
Function unary, Function unary
const ExecutionPolicy& policy
) { ) {
ForEach(first, last, unary, policy, 0); ForEach(first, last, unary, embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
* Overload of above described Doxygen dummy. * Overload of above described Doxygen dummy with less arguments.
*/ */
template<typename RAI, typename Function> template<typename RAI, typename Function>
void ForEach( void ForEach(
RAI first, RAI first,
RAI last, RAI last,
Function unary, Function unary,
const ExecutionPolicy& policy, const embb::mtapi::ExecutionPolicy& policy
size_t block_size ) {
); ForEach(first, last, unary, policy, 0);
}
#endif // else DOXYGEN #endif // else DOXYGEN
......
...@@ -80,7 +80,7 @@ class FunctionComparisonFunction{ ...@@ -80,7 +80,7 @@ class FunctionComparisonFunction{
template<typename RAI, typename ValueType> template<typename RAI, typename ValueType>
typename std::iterator_traits<RAI>::difference_type typename std::iterator_traits<RAI>::difference_type
Count(RAI first, RAI last, const ValueType& value, Count(RAI first, RAI last, const ValueType& value,
const ExecutionPolicy& policy, size_t block_size) { const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
typedef typename std::iterator_traits<RAI>::difference_type Difference; typedef typename std::iterator_traits<RAI>::difference_type Difference;
return Reduce(first, last, Difference(0), std::plus<Difference>(), return Reduce(first, last, Difference(0), std::plus<Difference>(),
internal::ValueComparisonFunction<ValueType>(value), policy, internal::ValueComparisonFunction<ValueType>(value), policy,
...@@ -90,7 +90,7 @@ typename std::iterator_traits<RAI>::difference_type ...@@ -90,7 +90,7 @@ typename std::iterator_traits<RAI>::difference_type
template<typename RAI, typename ComparisonFunction> template<typename RAI, typename ComparisonFunction>
typename std::iterator_traits<RAI>::difference_type typename std::iterator_traits<RAI>::difference_type
CountIf(RAI first, RAI last, ComparisonFunction comparison, CountIf(RAI first, RAI last, ComparisonFunction comparison,
const ExecutionPolicy& policy, size_t block_size) { const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
typedef typename std::iterator_traits<RAI>::difference_type Difference; typedef typename std::iterator_traits<RAI>::difference_type Difference;
return Reduce(first, last, Difference(0), std::plus<Difference>(), return Reduce(first, last, Difference(0), std::plus<Difference>(),
internal::FunctionComparisonFunction<ComparisonFunction> internal::FunctionComparisonFunction<ComparisonFunction>
......
...@@ -46,7 +46,7 @@ class ForEachFunctor { ...@@ -46,7 +46,7 @@ class ForEachFunctor {
* Constructs a for-each functor with arguments. * Constructs a for-each functor with arguments.
*/ */
ForEachFunctor(RAI first, RAI last, Function unary, ForEachFunctor(RAI first, RAI last, Function unary,
const ExecutionPolicy& policy, size_t block_size) const embb::mtapi::ExecutionPolicy& policy, size_t block_size)
: first_(first), last_(last), unary_(unary), policy_(policy), : first_(first), last_(last), unary_(unary), policy_(policy),
block_size_(block_size) { block_size_(block_size) {
} }
...@@ -68,10 +68,10 @@ class ForEachFunctor { ...@@ -68,10 +68,10 @@ class ForEachFunctor {
mtapi::Node& node = mtapi::Node::GetInstance(); mtapi::Node& node = mtapi::Node::GetInstance();
mtapi::Task taskL = node.Spawn(mtapi::Action(base::MakeFunction( mtapi::Task taskL = node.Spawn(mtapi::Action(base::MakeFunction(
functorL, &ForEachFunctor<RAI, Function>::Action), functorL, &ForEachFunctor<RAI, Function>::Action),
policy_.GetAffinity()), policy_.GetPriority()); policy_));
mtapi::Task taskR = node.Spawn(mtapi::Action(base::MakeFunction( mtapi::Task taskR = node.Spawn(mtapi::Action(base::MakeFunction(
functorR, &ForEachFunctor<RAI, Function>::Action), functorR, &ForEachFunctor<RAI, Function>::Action),
policy_.GetAffinity()), policy_.GetPriority()); policy_));
taskL.Wait(MTAPI_INFINITE); taskL.Wait(MTAPI_INFINITE);
taskR.Wait(MTAPI_INFINITE); taskR.Wait(MTAPI_INFINITE);
} }
...@@ -81,7 +81,7 @@ class ForEachFunctor { ...@@ -81,7 +81,7 @@ class ForEachFunctor {
RAI first_; RAI first_;
RAI last_; RAI last_;
Function unary_; Function unary_;
const ExecutionPolicy& policy_; const embb::mtapi::ExecutionPolicy& policy_;
size_t block_size_; size_t block_size_;
/** /**
...@@ -92,7 +92,7 @@ class ForEachFunctor { ...@@ -92,7 +92,7 @@ class ForEachFunctor {
template<typename RAI, typename Function> template<typename RAI, typename Function>
void ForEachRecursive(RAI first, RAI last, Function unary, void ForEachRecursive(RAI first, RAI last, Function unary,
const ExecutionPolicy& policy, size_t block_size) { const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
typedef typename std::iterator_traits<RAI>::difference_type difference_type; typedef typename std::iterator_traits<RAI>::difference_type difference_type;
difference_type distance = std::distance(first, last); difference_type distance = std::distance(first, last);
assert(distance > 0); assert(distance > 0);
...@@ -113,13 +113,13 @@ void ForEachRecursive(RAI first, RAI last, Function unary, ...@@ -113,13 +113,13 @@ void ForEachRecursive(RAI first, RAI last, Function unary,
mtapi::Task task = node.Spawn(mtapi::Action( mtapi::Task task = node.Spawn(mtapi::Action(
base::MakeFunction(functor, base::MakeFunction(functor,
&ForEachFunctor<RAI, Function>::Action), &ForEachFunctor<RAI, Function>::Action),
policy.GetAffinity()), policy.GetPriority()); policy));
task.Wait(MTAPI_INFINITE); task.Wait(MTAPI_INFINITE);
} }
template<typename RAI, typename Function> template<typename RAI, typename Function>
void ForEachIteratorCheck(RAI first, RAI last, Function unary, void ForEachIteratorCheck(RAI first, RAI last, Function unary,
const ExecutionPolicy& policy, size_t block_size, const embb::mtapi::ExecutionPolicy& policy, size_t block_size,
std::random_access_iterator_tag) { std::random_access_iterator_tag) {
return ForEachRecursive(first, last, unary, policy, block_size); return ForEachRecursive(first, last, unary, policy, block_size);
} }
...@@ -127,8 +127,8 @@ void ForEachIteratorCheck(RAI first, RAI last, Function unary, ...@@ -127,8 +127,8 @@ void ForEachIteratorCheck(RAI first, RAI last, Function unary,
} // namespace internal } // namespace internal
template<typename RAI, typename Function> template<typename RAI, typename Function>
void ForEach(RAI first, RAI last, Function unary, const ExecutionPolicy& policy, void ForEach(RAI first, RAI last, Function unary,
size_t block_size) { const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
typename std::iterator_traits<RAI>::iterator_category category; typename std::iterator_traits<RAI>::iterator_category category;
internal::ForEachIteratorCheck(first, last, unary, policy, block_size, internal::ForEachIteratorCheck(first, last, unary, policy, block_size,
category); category);
......
...@@ -49,8 +49,8 @@ class MergeSortFunctor { ...@@ -49,8 +49,8 @@ class MergeSortFunctor {
typedef typename std::iterator_traits<RAI>::value_type value_type; typedef typename std::iterator_traits<RAI>::value_type value_type;
MergeSortFunctor(RAI first, RAI last, RAITemp temporary_first, MergeSortFunctor(RAI first, RAI last, RAITemp temporary_first,
ComparisonFunction comparison, const ExecutionPolicy& policy, ComparisonFunction comparison, const embb::mtapi::ExecutionPolicy& policy,
size_t block_size, const RAI& global_first, int depth) size_t block_size, const RAI& global_first, int depth)
: first_(first), last_(last), temp_first_(temporary_first), : first_(first), last_(last), temp_first_(temporary_first),
comparison_(comparison), policy_(policy), block_size_(block_size), comparison_(comparison), policy_(policy), block_size_(block_size),
global_first_(global_first), depth_(depth) { global_first_(global_first), depth_(depth) {
...@@ -82,10 +82,10 @@ class MergeSortFunctor { ...@@ -82,10 +82,10 @@ class MergeSortFunctor {
mtapi::Node& node = mtapi::Node::GetInstance(); mtapi::Node& node = mtapi::Node::GetInstance();
mtapi::Task taskL = node.Spawn(mtapi::Action(base::MakeFunction(functorL, mtapi::Task taskL = node.Spawn(mtapi::Action(base::MakeFunction(functorL,
&MergeSortFunctor<RAI, RAITemp, ComparisonFunction>::Action), &MergeSortFunctor<RAI, RAITemp, ComparisonFunction>::Action),
policy_.GetAffinity()), policy_.GetPriority()); policy_));
mtapi::Task taskR = node.Spawn(mtapi::Action(base::MakeFunction(functorR, mtapi::Task taskR = node.Spawn(mtapi::Action(base::MakeFunction(functorR,
&MergeSortFunctor<RAI, RAITemp, ComparisonFunction>::Action), &MergeSortFunctor<RAI, RAITemp, ComparisonFunction>::Action),
policy_.GetAffinity()), policy_.GetPriority()); policy_));
taskL.Wait(MTAPI_INFINITE); taskL.Wait(MTAPI_INFINITE);
taskR.Wait(MTAPI_INFINITE); taskR.Wait(MTAPI_INFINITE);
} }
...@@ -118,7 +118,7 @@ class MergeSortFunctor { ...@@ -118,7 +118,7 @@ class MergeSortFunctor {
RAI last_; RAI last_;
RAITemp temp_first_; RAITemp temp_first_;
ComparisonFunction comparison_; ComparisonFunction comparison_;
const ExecutionPolicy &policy_; const embb::mtapi::ExecutionPolicy& policy_;
size_t block_size_; size_t block_size_;
const RAI& global_first_; const RAI& global_first_;
int depth_; int depth_;
...@@ -162,7 +162,7 @@ void MergeSort( ...@@ -162,7 +162,7 @@ void MergeSort(
RAI last, RAI last,
RAITemp temporary_first, RAITemp temporary_first,
ComparisonFunction comparison, ComparisonFunction comparison,
const ExecutionPolicy& policy, const embb::mtapi::ExecutionPolicy& policy,
size_t block_size size_t block_size
) { ) {
typedef typename std::iterator_traits<RAI>::difference_type difference_type; typedef typename std::iterator_traits<RAI>::difference_type difference_type;
...@@ -184,7 +184,7 @@ void MergeSort( ...@@ -184,7 +184,7 @@ void MergeSort(
first, last, temporary_first, comparison, policy, block_size, first, 0); first, last, temporary_first, comparison, policy, block_size, first, 0);
mtapi::Task task = node.Spawn(mtapi::Action(base::MakeFunction(functor, mtapi::Task task = node.Spawn(mtapi::Action(base::MakeFunction(functor,
&internal::MergeSortFunctor<RAI, RAITemp, ComparisonFunction>::Action), &internal::MergeSortFunctor<RAI, RAITemp, ComparisonFunction>::Action),
policy.GetAffinity()), policy.GetPriority()); policy));
task.Wait(MTAPI_INFINITE); task.Wait(MTAPI_INFINITE);
} }
......
...@@ -48,7 +48,7 @@ class QuickSortFunctor { ...@@ -48,7 +48,7 @@ class QuickSortFunctor {
* Constructs a functor. * Constructs a functor.
*/ */
QuickSortFunctor(RAI first, RAI last, ComparisonFunction comparison, QuickSortFunctor(RAI first, RAI last, ComparisonFunction comparison,
const ExecutionPolicy& policy, size_t block_size) const embb::mtapi::ExecutionPolicy& policy, size_t block_size)
: first_(first), last_(last), comparison_(comparison), policy_(policy), : first_(first), last_(last), comparison_(comparison), policy_(policy),
block_size_(block_size) { block_size_(block_size) {
} }
...@@ -87,7 +87,7 @@ class QuickSortFunctor { ...@@ -87,7 +87,7 @@ class QuickSortFunctor {
RAI first_; RAI first_;
RAI last_; RAI last_;
ComparisonFunction comparison_; ComparisonFunction comparison_;
const ExecutionPolicy& policy_; const embb::mtapi::ExecutionPolicy& policy_;
size_t block_size_; size_t block_size_;
typedef typename std::iterator_traits<RAI>::difference_type Difference; typedef typename std::iterator_traits<RAI>::difference_type Difference;
...@@ -190,7 +190,7 @@ class QuickSortFunctor { ...@@ -190,7 +190,7 @@ class QuickSortFunctor {
template <typename RAI, typename ComparisonFunction> template <typename RAI, typename ComparisonFunction>
void QuickSort(RAI first, RAI last, ComparisonFunction comparison, void QuickSort(RAI first, RAI last, ComparisonFunction comparison,
const ExecutionPolicy& policy, size_t block_size) { const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
embb::mtapi::Node& node = embb::mtapi::Node::GetInstance(); embb::mtapi::Node& node = embb::mtapi::Node::GetInstance();
typename std::iterator_traits<RAI>::difference_type distance = last - first; typename std::iterator_traits<RAI>::difference_type distance = last - first;
assert(distance > 0); assert(distance > 0);
......
...@@ -45,7 +45,7 @@ class ReduceFunctor { ...@@ -45,7 +45,7 @@ class ReduceFunctor {
ReduceFunctor(RAI first, RAI last, ReturnType neutral, ReduceFunctor(RAI first, RAI last, ReturnType neutral,
ReductionFunction reduction, ReductionFunction reduction,
TransformationFunction transformation, TransformationFunction transformation,
const ExecutionPolicy &policy, size_t block_size, const embb::mtapi::ExecutionPolicy &policy, size_t block_size,
ReturnType& result) ReturnType& result)
: :
first_(first), last_(last), neutral_(neutral), reduction_(reduction), first_(first), last_(last), neutral_(neutral), reduction_(reduction),
...@@ -78,11 +78,9 @@ class ReduceFunctor { ...@@ -78,11 +78,9 @@ class ReduceFunctor {
block_size_, result_r); block_size_, result_r);
mtapi::Node& node = mtapi::Node::GetInstance(); mtapi::Node& node = mtapi::Node::GetInstance();
mtapi::Task task_l = node.Spawn(mtapi::Action(base::MakeFunction( mtapi::Task task_l = node.Spawn(mtapi::Action(base::MakeFunction(
functor_l, &ReduceFunctor::Action), policy_.GetAffinity()), functor_l, &ReduceFunctor::Action), policy_));
policy_.GetPriority());
mtapi::Task task_r = node.Spawn(mtapi::Action(base::MakeFunction( mtapi::Task task_r = node.Spawn(mtapi::Action(base::MakeFunction(
functor_r, &ReduceFunctor::Action), policy_.GetAffinity()), functor_r, &ReduceFunctor::Action), policy_));
policy_.GetPriority());
task_l.Wait(MTAPI_INFINITE); task_l.Wait(MTAPI_INFINITE);
task_r.Wait(MTAPI_INFINITE); task_r.Wait(MTAPI_INFINITE);
result_ = reduction_(result_l, result_r); result_ = reduction_(result_l, result_r);
...@@ -95,7 +93,7 @@ class ReduceFunctor { ...@@ -95,7 +93,7 @@ class ReduceFunctor {
ReturnType neutral_; ReturnType neutral_;
ReductionFunction reduction_; ReductionFunction reduction_;
TransformationFunction transformation_; TransformationFunction transformation_;
const ExecutionPolicy& policy_; const embb::mtapi::ExecutionPolicy& policy_;
size_t block_size_; size_t block_size_;
ReturnType& result_; ReturnType& result_;
...@@ -108,7 +106,8 @@ template<typename RAI, typename ReturnType, typename ReductionFunction, ...@@ -108,7 +106,8 @@ template<typename RAI, typename ReturnType, typename ReductionFunction,
ReturnType ReduceRecursive(RAI first, RAI last, ReturnType neutral, ReturnType ReduceRecursive(RAI first, RAI last, ReturnType neutral,
ReductionFunction reduction, ReductionFunction reduction,
TransformationFunction transformation, TransformationFunction transformation,
const ExecutionPolicy& policy, size_t block_size) { const embb::mtapi::ExecutionPolicy& policy,
size_t block_size) {
typedef typename std::iterator_traits<RAI>::difference_type difference_type; typedef typename std::iterator_traits<RAI>::difference_type difference_type;
difference_type distance = std::distance(first, last); difference_type distance = std::distance(first, last);
assert(distance > 0); assert(distance > 0);
...@@ -132,7 +131,7 @@ ReturnType ReduceRecursive(RAI first, RAI last, ReturnType neutral, ...@@ -132,7 +131,7 @@ ReturnType ReduceRecursive(RAI first, RAI last, ReturnType neutral,
Functor functor(first, last, neutral, reduction, transformation, policy, Functor functor(first, last, neutral, reduction, transformation, policy,
used_block_size, result); used_block_size, result);
mtapi::Task task = node.Spawn(mtapi::Action(base::MakeFunction( mtapi::Task task = node.Spawn(mtapi::Action(base::MakeFunction(
functor, &Functor::Action), policy.GetAffinity()), policy.GetPriority()); functor, &Functor::Action), policy));
task.Wait(MTAPI_INFINITE); task.Wait(MTAPI_INFINITE);
return result; return result;
} }
...@@ -142,7 +141,8 @@ template<typename RAI, typename TransformationFunction, ...@@ -142,7 +141,8 @@ template<typename RAI, typename TransformationFunction,
ReturnType ReduceIteratorCheck(RAI first, RAI last, ReductionFunction reduction, ReturnType ReduceIteratorCheck(RAI first, RAI last, ReductionFunction reduction,
TransformationFunction transformation, TransformationFunction transformation,
ReturnType neutral, ReturnType neutral,
const ExecutionPolicy& policy, size_t block_size, const embb::mtapi::ExecutionPolicy& policy,
size_t block_size,
std::random_access_iterator_tag) { std::random_access_iterator_tag) {
return ReduceRecursive(first, last, neutral, reduction, transformation, return ReduceRecursive(first, last, neutral, reduction, transformation,
policy, block_size); policy, block_size);
...@@ -155,7 +155,8 @@ template<typename RAI, typename ReturnType, typename ReductionFunction, ...@@ -155,7 +155,8 @@ template<typename RAI, typename ReturnType, typename ReductionFunction,
ReturnType Reduce(RAI first, RAI last, ReturnType neutral, ReturnType Reduce(RAI first, RAI last, ReturnType neutral,
ReductionFunction reduction, ReductionFunction reduction,
TransformationFunction transformation, TransformationFunction transformation,
const ExecutionPolicy& policy, size_t block_size) { const embb::mtapi::ExecutionPolicy& policy,
size_t block_size) {
typename std::iterator_traits<RAI>::iterator_category category; typename std::iterator_traits<RAI>::iterator_category category;
return internal::ReduceIteratorCheck(first, last, reduction, transformation, return internal::ReduceIteratorCheck(first, last, reduction, transformation,
neutral, policy, block_size, category); neutral, policy, block_size, category);
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <cassert> #include <cassert>
#include <embb/base/exceptions.h> #include <embb/base/exceptions.h>
#include <embb/mtapi/mtapi.h> #include <embb/mtapi/mtapi.h>
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
#include <embb/algorithms/internal/partition.h> #include <embb/algorithms/internal/partition.h>
namespace embb { namespace embb {
...@@ -44,7 +44,7 @@ class ScanFunctor { ...@@ -44,7 +44,7 @@ class ScanFunctor {
ScanFunctor(RAIIn first, RAIIn last, RAIOut output_iterator, ScanFunctor(RAIIn first, RAIIn last, RAIOut output_iterator,
ReturnType neutral, ScanFunction scan, ReturnType neutral, ScanFunction scan,
TransformationFunction transformation, TransformationFunction transformation,
const ExecutionPolicy& policy, const embb::mtapi::ExecutionPolicy& policy,
size_t block_size, ReturnType* tree_values, size_t node_id, size_t block_size, ReturnType* tree_values, size_t node_id,
bool going_down) bool going_down)
: policy_(policy), first_(first), last_(last), : policy_(policy), first_(first), last_(last),
...@@ -104,12 +104,10 @@ class ScanFunctor { ...@@ -104,12 +104,10 @@ class ScanFunctor {
mtapi::Node& node = mtapi::Node::GetInstance(); mtapi::Node& node = mtapi::Node::GetInstance();
mtapi::Task task_l = node.Spawn(mtapi::Action(base::MakeFunction( mtapi::Task task_l = node.Spawn(mtapi::Action(base::MakeFunction(
functor_l, &ScanFunctor::Action), functor_l, &ScanFunctor::Action),
policy_.GetAffinity()), policy_));
policy_.GetPriority());
mtapi::Task task_r = node.Spawn(mtapi::Action(base::MakeFunction( mtapi::Task task_r = node.Spawn(mtapi::Action(base::MakeFunction(
functor_r, &ScanFunctor::Action), functor_r, &ScanFunctor::Action),
policy_.GetAffinity()), policy_));
policy_.GetPriority());
task_l.Wait(MTAPI_INFINITE); task_l.Wait(MTAPI_INFINITE);
task_r.Wait(MTAPI_INFINITE); task_r.Wait(MTAPI_INFINITE);
SetTreeValue(scan_(functor_l.GetTreeValue(), functor_r.GetTreeValue())); SetTreeValue(scan_(functor_l.GetTreeValue(), functor_r.GetTreeValue()));
...@@ -125,7 +123,7 @@ class ScanFunctor { ...@@ -125,7 +123,7 @@ class ScanFunctor {
} }
private: private:
const ExecutionPolicy& policy_; const embb::mtapi::ExecutionPolicy& policy_;
RAIIn first_; RAIIn first_;
RAIIn last_; RAIIn last_;
RAIOut output_iterator_; RAIOut output_iterator_;
...@@ -162,7 +160,8 @@ typename ScanFunction, typename TransformationFunction> ...@@ -162,7 +160,8 @@ typename ScanFunction, typename TransformationFunction>
void ScanIteratorCheck(RAIIn first, RAIIn last, RAIOut output_iterator, void ScanIteratorCheck(RAIIn first, RAIIn last, RAIOut output_iterator,
ReturnType neutral, ScanFunction scan, ReturnType neutral, ScanFunction scan,
TransformationFunction transformation, TransformationFunction transformation,
const ExecutionPolicy& policy, size_t block_size, const embb::mtapi::ExecutionPolicy& policy,
size_t block_size,
std::random_access_iterator_tag) { std::random_access_iterator_tag) {
typedef typename std::iterator_traits<RAIIn>::difference_type difference_type; typedef typename std::iterator_traits<RAIIn>::difference_type difference_type;
difference_type distance = std::distance(first, last); difference_type distance = std::distance(first, last);
...@@ -191,7 +190,7 @@ void ScanIteratorCheck(RAIIn first, RAIIn last, RAIOut output_iterator, ...@@ -191,7 +190,7 @@ void ScanIteratorCheck(RAIIn first, RAIIn last, RAIOut output_iterator,
true); true);
mtapi::Task task_down = node.Spawn(mtapi::Action(base::MakeFunction( mtapi::Task task_down = node.Spawn(mtapi::Action(base::MakeFunction(
functor_down, &Functor::Action), functor_down, &Functor::Action),
policy.GetAffinity()), policy.GetPriority()); policy));
task_down.Wait(MTAPI_INFINITE); task_down.Wait(MTAPI_INFINITE);
// Second pass. Gives to each leaf the part of the prefix missing // Second pass. Gives to each leaf the part of the prefix missing
...@@ -199,7 +198,7 @@ void ScanIteratorCheck(RAIIn first, RAIIn last, RAIOut output_iterator, ...@@ -199,7 +198,7 @@ void ScanIteratorCheck(RAIIn first, RAIIn last, RAIOut output_iterator,
transformation, policy, used_block_size, values, 0, false); transformation, policy, used_block_size, values, 0, false);
mtapi::Task task_up = node.Spawn(mtapi::Action(base::MakeFunction( mtapi::Task task_up = node.Spawn(mtapi::Action(base::MakeFunction(
functor_up, &Functor::Action), functor_up, &Functor::Action),
policy.GetAffinity()), policy.GetPriority()); policy));
task_up.Wait(MTAPI_INFINITE); task_up.Wait(MTAPI_INFINITE);
} }
...@@ -209,7 +208,7 @@ template<typename RAIIn, typename RAIOut, typename ReturnType, ...@@ -209,7 +208,7 @@ template<typename RAIIn, typename RAIOut, typename ReturnType,
typename ScanFunction, typename TransformationFunction> typename ScanFunction, typename TransformationFunction>
void Scan(RAIIn first, RAIIn last, RAIOut output_iterator, ReturnType neutral, void Scan(RAIIn first, RAIIn last, RAIOut output_iterator, ReturnType neutral,
ScanFunction scan, TransformationFunction transformation, ScanFunction scan, TransformationFunction transformation,
const ExecutionPolicy& policy, size_t block_size) { const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
typedef typename std::iterator_traits<RAIIn>::iterator_category category; typedef typename std::iterator_traits<RAIIn>::iterator_category category;
internal::ScanIteratorCheck(first, last, output_iterator, neutral, internal::ScanIteratorCheck(first, last, output_iterator, neutral,
scan, transformation, policy, block_size, category()); scan, transformation, policy, block_size, category());
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#define EMBB_ALGORITHMS_INVOKE_H_ #define EMBB_ALGORITHMS_INVOKE_H_
#include <embb/base/function.h> #include <embb/base/function.h>
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/mtapi.h>
namespace embb { namespace embb {
namespace algorithms { namespace algorithms {
...@@ -74,7 +74,7 @@ void Invoke( ...@@ -74,7 +74,7 @@ void Invoke(
Function1 func1, Function1 func1,
/**< [in] Function to invoke */ /**< [in] Function to invoke */
..., ...,
const ExecutionPolicy & policy /**< [in] ExecutionPolicy to use */ const embb::mtapi::ExecutionPolicy & policy /**< [in] ExecutionPolicy to use */
); );
#else // DOXYGEN #else // DOXYGEN
...@@ -92,11 +92,11 @@ class TaskWrapper { ...@@ -92,11 +92,11 @@ class TaskWrapper {
*/ */
explicit TaskWrapper( explicit TaskWrapper(
Function function, Function function,
const ExecutionPolicy& policy) const embb::mtapi::ExecutionPolicy& policy)
: function_(function), task_() { : function_(function), task_() {
mtapi::Action action(embb::base::MakeFunction(*this, &TaskWrapper::Run), mtapi::Action action(embb::base::MakeFunction(*this, &TaskWrapper::Run),
policy.GetAffinity()); policy);
task_ = mtapi::Node::GetInstance().Spawn(action, policy.GetPriority()); task_ = mtapi::Node::GetInstance().Spawn(action);
} }
/** /**
...@@ -118,75 +118,104 @@ class TaskWrapper { ...@@ -118,75 +118,104 @@ class TaskWrapper {
template<typename Function1> template<typename Function1>
void Invoke( void Invoke(
Function1 func1) { Function1 func1,
Invoke(func1, ExecutionPolicy()); const embb::mtapi::ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
} }
template<typename Function1, typename Function2> template<typename Function1, typename Function2>
void Invoke( void Invoke(
Function1 func1, Function1 func1,
Function2 func2) { Function2 func2,
Invoke(func1, func2, ExecutionPolicy()); const embb::mtapi::ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
} }
template<typename Function1, typename Function2, typename Function3> template<typename Function1, typename Function2, typename Function3>
void Invoke( void Invoke(
Function1 func1, Function1 func1,
Function2 func2, Function2 func2,
Function3 func3) { Function3 func3,
Invoke(func1, func2, func3, ExecutionPolicy()); const embb::mtapi::ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
typename Function4> typename Function4>
void Invoke( void Invoke(
Function1 func1, Function1 func1,
Function2 func2, Function2 func2,
Function3 func3, Function3 func3,
Function4 func4) { Function4 func4,
Invoke(func1, func2, func3, func4, ExecutionPolicy()); const embb::mtapi::ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
typename Function4, typename Function5> typename Function4, typename Function5>
void Invoke( void Invoke(
Function1 func1, Function1 func1,
Function2 func2, Function2 func2,
Function3 func3, Function3 func3,
Function4 func4, Function4 func4,
Function5 func5) { Function5 func5,
Invoke(func1, func2, func3, func4, func5, ExecutionPolicy()); const embb::mtapi::ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
typename Function4, typename Function5, typename Function6> typename Function4, typename Function5, typename Function6>
void Invoke( void Invoke(
Function1 func1, Function1 func1,
Function2 func2, Function2 func2,
Function3 func3, Function3 func3,
Function4 func4, Function4 func4,
Function5 func5, Function5 func5,
Function6 func6) { Function6 func6,
Invoke(func1, func2, func3, func4, func5, func6, ExecutionPolicy()); const embb::mtapi::ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
internal::TaskWrapper<Function6> wrap6(func6, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
typename Function4, typename Function5, typename Function6, typename Function4, typename Function5, typename Function6,
typename Function7> typename Function7>
void Invoke( void Invoke(
Function1 func1, Function1 func1,
Function2 func2, Function2 func2,
Function3 func3, Function3 func3,
Function4 func4, Function4 func4,
Function5 func5, Function5 func5,
Function6 func6, Function6 func6,
Function7 func7) { Function7 func7,
Invoke(func1, func2, func3, func4, func5, func6, func7, ExecutionPolicy()); const embb::mtapi::ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
internal::TaskWrapper<Function6> wrap6(func6, policy);
internal::TaskWrapper<Function7> wrap7(func7, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
typename Function4, typename Function5, typename Function6, typename Function4, typename Function5, typename Function6,
typename Function7, typename Function8> typename Function7, typename Function8>
void Invoke( void Invoke(
Function1 func1, Function1 func1,
Function2 func2, Function2 func2,
Function3 func3, Function3 func3,
...@@ -194,15 +223,22 @@ void Invoke( ...@@ -194,15 +223,22 @@ void Invoke(
Function5 func5, Function5 func5,
Function6 func6, Function6 func6,
Function7 func7, Function7 func7,
Function8 func8) { Function8 func8,
Invoke(func1, func2, func3, func4, func5, func6, func7, func8, const embb::mtapi::ExecutionPolicy& policy) {
ExecutionPolicy()); internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
internal::TaskWrapper<Function6> wrap6(func6, policy);
internal::TaskWrapper<Function7> wrap7(func7, policy);
internal::TaskWrapper<Function8> wrap8(func8, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
typename Function4, typename Function5, typename Function6, typename Function4, typename Function5, typename Function6,
typename Function7, typename Function8, typename Function9> typename Function7, typename Function8, typename Function9>
void Invoke( void Invoke(
Function1 func1, Function1 func1,
Function2 func2, Function2 func2,
Function3 func3, Function3 func3,
...@@ -211,16 +247,24 @@ void Invoke( ...@@ -211,16 +247,24 @@ void Invoke(
Function6 func6, Function6 func6,
Function7 func7, Function7 func7,
Function8 func8, Function8 func8,
Function9 func9) { Function9 func9,
Invoke(func1, func2, func3, func4, func5, func6, func7, func8, func9, const embb::mtapi::ExecutionPolicy& policy) {
ExecutionPolicy()); internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
internal::TaskWrapper<Function6> wrap6(func6, policy);
internal::TaskWrapper<Function7> wrap7(func7, policy);
internal::TaskWrapper<Function8> wrap8(func8, policy);
internal::TaskWrapper<Function9> wrap9(func9, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
typename Function4, typename Function5, typename Function6, typename Function4, typename Function5, typename Function6,
typename Function7, typename Function8, typename Function9, typename Function7, typename Function8, typename Function9,
typename Function10> typename Function10>
void Invoke( void Invoke(
Function1 func1, Function1 func1,
Function2 func2, Function2 func2,
Function3 func3, Function3 func3,
...@@ -230,36 +274,38 @@ void Invoke( ...@@ -230,36 +274,38 @@ void Invoke(
Function7 func7, Function7 func7,
Function8 func8, Function8 func8,
Function9 func9, Function9 func9,
Function10 func10) { Function10 func10,
Invoke(func1, func2, func3, func4, func5, func6, func7, func8, func9, func10, const embb::mtapi::ExecutionPolicy& policy) {
ExecutionPolicy()); internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
internal::TaskWrapper<Function6> wrap6(func6, policy);
internal::TaskWrapper<Function7> wrap7(func7, policy);
internal::TaskWrapper<Function8> wrap8(func8, policy);
internal::TaskWrapper<Function9> wrap9(func9, policy);
internal::TaskWrapper<Function10> wrap10(func10, policy);
} }
template<typename Function1> template<typename Function1>
void Invoke( void Invoke(
Function1 func1, Function1 func1) {
const ExecutionPolicy& policy) { Invoke(func1, embb::mtapi::ExecutionPolicy());
internal::TaskWrapper<Function1> wrap1(func1, policy);
} }
template<typename Function1, typename Function2> template<typename Function1, typename Function2>
void Invoke( void Invoke(
Function1 func1, Function1 func1,
Function2 func2, Function2 func2) {
const ExecutionPolicy& policy) { Invoke(func1, func2, embb::mtapi::ExecutionPolicy());
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
} }
template<typename Function1, typename Function2, typename Function3> template<typename Function1, typename Function2, typename Function3>
void Invoke( void Invoke(
Function1 func1, Function1 func1,
Function2 func2, Function2 func2,
Function3 func3, Function3 func3) {
const ExecutionPolicy& policy) { Invoke(func1, func2, func3, embb::mtapi::ExecutionPolicy());
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
...@@ -268,12 +314,8 @@ void Invoke( ...@@ -268,12 +314,8 @@ void Invoke(
Function1 func1, Function1 func1,
Function2 func2, Function2 func2,
Function3 func3, Function3 func3,
Function4 func4, Function4 func4) {
const ExecutionPolicy& policy) { Invoke(func1, func2, func3, func4, embb::mtapi::ExecutionPolicy());
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
...@@ -283,13 +325,8 @@ void Invoke( ...@@ -283,13 +325,8 @@ void Invoke(
Function2 func2, Function2 func2,
Function3 func3, Function3 func3,
Function4 func4, Function4 func4,
Function5 func5, Function5 func5) {
const ExecutionPolicy& policy) { Invoke(func1, func2, func3, func4, func5, embb::mtapi::ExecutionPolicy());
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
...@@ -300,14 +337,9 @@ void Invoke( ...@@ -300,14 +337,9 @@ void Invoke(
Function3 func3, Function3 func3,
Function4 func4, Function4 func4,
Function5 func5, Function5 func5,
Function6 func6, Function6 func6) {
const ExecutionPolicy& policy) { Invoke(func1, func2, func3, func4, func5, func6,
internal::TaskWrapper<Function1> wrap1(func1, policy); embb::mtapi::ExecutionPolicy());
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
internal::TaskWrapper<Function6> wrap6(func6, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
...@@ -320,15 +352,9 @@ void Invoke( ...@@ -320,15 +352,9 @@ void Invoke(
Function4 func4, Function4 func4,
Function5 func5, Function5 func5,
Function6 func6, Function6 func6,
Function7 func7, Function7 func7) {
const ExecutionPolicy& policy) { Invoke(func1, func2, func3, func4, func5, func6, func7,
internal::TaskWrapper<Function1> wrap1(func1, policy); embb::mtapi::ExecutionPolicy());
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
internal::TaskWrapper<Function6> wrap6(func6, policy);
internal::TaskWrapper<Function7> wrap7(func7, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
...@@ -342,16 +368,9 @@ void Invoke( ...@@ -342,16 +368,9 @@ void Invoke(
Function5 func5, Function5 func5,
Function6 func6, Function6 func6,
Function7 func7, Function7 func7,
Function8 func8, Function8 func8) {
const ExecutionPolicy& policy) { Invoke(func1, func2, func3, func4, func5, func6, func7, func8,
internal::TaskWrapper<Function1> wrap1(func1, policy); embb::mtapi::ExecutionPolicy());
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
internal::TaskWrapper<Function6> wrap6(func6, policy);
internal::TaskWrapper<Function7> wrap7(func7, policy);
internal::TaskWrapper<Function8> wrap8(func8, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
...@@ -366,17 +385,9 @@ void Invoke( ...@@ -366,17 +385,9 @@ void Invoke(
Function6 func6, Function6 func6,
Function7 func7, Function7 func7,
Function8 func8, Function8 func8,
Function9 func9, Function9 func9) {
const ExecutionPolicy& policy) { Invoke(func1, func2, func3, func4, func5, func6, func7, func8, func9,
internal::TaskWrapper<Function1> wrap1(func1, policy); embb::mtapi::ExecutionPolicy());
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
internal::TaskWrapper<Function6> wrap6(func6, policy);
internal::TaskWrapper<Function7> wrap7(func7, policy);
internal::TaskWrapper<Function8> wrap8(func8, policy);
internal::TaskWrapper<Function9> wrap9(func9, policy);
} }
template<typename Function1, typename Function2, typename Function3, template<typename Function1, typename Function2, typename Function3,
...@@ -393,18 +404,9 @@ void Invoke( ...@@ -393,18 +404,9 @@ void Invoke(
Function7 func7, Function7 func7,
Function8 func8, Function8 func8,
Function9 func9, Function9 func9,
Function10 func10, Function10 func10) {
const ExecutionPolicy& policy) { Invoke(func1, func2, func3, func4, func5, func6, func7, func8, func9, func10,
internal::TaskWrapper<Function1> wrap1(func1, policy); embb::mtapi::ExecutionPolicy());
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
internal::TaskWrapper<Function4> wrap4(func4, policy);
internal::TaskWrapper<Function5> wrap5(func5, policy);
internal::TaskWrapper<Function6> wrap6(func6, policy);
internal::TaskWrapper<Function7> wrap7(func7, policy);
internal::TaskWrapper<Function8> wrap8(func8, policy);
internal::TaskWrapper<Function9> wrap9(func9, policy);
internal::TaskWrapper<Function10> wrap10(func10, policy);
} }
#endif // else DOXYGEN #endif // else DOXYGEN
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#define EMBB_ALGORITHMS_MERGE_SORT_H_ #define EMBB_ALGORITHMS_MERGE_SORT_H_
#include <functional> #include <functional>
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
#include <embb/base/memory_allocation.h> #include <embb/base/memory_allocation.h>
namespace embb { namespace embb {
...@@ -77,7 +77,7 @@ void MergeSortAllocate( ...@@ -77,7 +77,7 @@ void MergeSortAllocate(
\c a appears before an element \c b in the sorted range if \c a appears before an element \c b in the sorted range if
<tt>comparison(a, b) == true</tt>. The default value uses the <tt>comparison(a, b) == true</tt>. The default value uses the
less-than relation. */ less-than relation. */
const ExecutionPolicy& policy = ExecutionPolicy(), const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the merge sort algorithm */ /**< [IN] ExecutionPolicy for the merge sort algorithm */
size_t block_size = 0 size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that /**< [IN] Lower bound for partitioning the range of elements into blocks that
...@@ -127,7 +127,7 @@ void MergeSort( ...@@ -127,7 +127,7 @@ void MergeSort(
\c a appears before an element \c b in the sorted range if \c a appears before an element \c b in the sorted range if
<tt>comparison(a, b) == true</tt>. The default value uses the <tt>comparison(a, b) == true</tt>. The default value uses the
less-than relation. */ less-than relation. */
const ExecutionPolicy& policy = ExecutionPolicy(), const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the merge sort algorithm */ /**< [IN] ExecutionPolicy for the merge sort algorithm */
size_t block_size = 0 size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that /**< [IN] Lower bound for partitioning the range of elements into blocks that
...@@ -141,28 +141,49 @@ void MergeSort( ...@@ -141,28 +141,49 @@ void MergeSort(
#else // DOXYGEN #else // DOXYGEN
/** /**
* Overload of above described Doxygen dummy with less arguments. * Overload of above described Doxygen dummy.
*/ */
template<typename RAI> template<typename RAI, typename RAITemp, typename ComparisonFunction>
void MergeSort(
RAI first,
RAI last,
RAITemp temporary_first,
ComparisonFunction comparison,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ComparisonFunction>
void MergeSortAllocate( void MergeSortAllocate(
RAI first, RAI first,
RAI last RAI last,
ComparisonFunction comparison,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
) { ) {
MergeSortAllocate(first, last, typedef base::Allocation Alloc;
std::less<typename std::iterator_traits<RAI>::value_type>(), typename std::iterator_traits<RAI>::difference_type distance = last - first;
ExecutionPolicy(), 0); typedef typename std::iterator_traits<RAI>::value_type value_type;
value_type* temporary = static_cast<value_type*>(
Alloc::Allocate(distance * sizeof(value_type)));
MergeSort(first, last, temporary, comparison, policy, block_size);
Alloc::Free(temporary);
} }
/** /**
* Overload of above described Doxygen dummy with less arguments. * Overload of above described Doxygen dummy with less arguments.
*/ */
template<typename RAI, typename ComparisonFunction> template<typename RAI>
void MergeSortAllocate( void MergeSortAllocate(
RAI first, RAI first,
RAI last, RAI last
ComparisonFunction comparison
) { ) {
MergeSortAllocate(first, last, comparison, ExecutionPolicy(), 0); MergeSortAllocate(first, last,
std::less<typename std::iterator_traits<RAI>::value_type>(),
embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
...@@ -172,30 +193,22 @@ template<typename RAI, typename ComparisonFunction> ...@@ -172,30 +193,22 @@ template<typename RAI, typename ComparisonFunction>
void MergeSortAllocate( void MergeSortAllocate(
RAI first, RAI first,
RAI last, RAI last,
ComparisonFunction comparison, ComparisonFunction comparison
const ExecutionPolicy& policy
) { ) {
MergeSortAllocate(first, last, comparison, policy, 0); MergeSortAllocate(first, last, comparison, embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
* Overload of above described Doxygen dummy. * Overload of above described Doxygen dummy with less arguments.
*/ */
template<typename RAI, typename ComparisonFunction> template<typename RAI, typename ComparisonFunction>
void MergeSortAllocate( void MergeSortAllocate(
RAI first, RAI first,
RAI last, RAI last,
ComparisonFunction comparison, ComparisonFunction comparison,
const ExecutionPolicy& policy, const embb::mtapi::ExecutionPolicy& policy
size_t block_size
) { ) {
typedef base::Allocation Alloc; MergeSortAllocate(first, last, comparison, policy, 0);
typename std::iterator_traits<RAI>::difference_type distance = last - first;
typedef typename std::iterator_traits<RAI>::value_type value_type;
value_type* temporary = static_cast<value_type*>(
Alloc::Allocate(distance * sizeof(value_type)));
MergeSort(first, last, temporary, comparison, policy, block_size);
Alloc::Free(temporary);
} }
/** /**
...@@ -209,7 +222,7 @@ void MergeSort( ...@@ -209,7 +222,7 @@ void MergeSort(
) { ) {
MergeSort(first, last, temporary_first, MergeSort(first, last, temporary_first,
std::less<typename std::iterator_traits<RAI>::value_type>(), std::less<typename std::iterator_traits<RAI>::value_type>(),
ExecutionPolicy(), 0); embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
...@@ -222,7 +235,8 @@ void MergeSort( ...@@ -222,7 +235,8 @@ void MergeSort(
RAITemp temporary_first, RAITemp temporary_first,
ComparisonFunction comparison ComparisonFunction comparison
) { ) {
MergeSort(first, last, temporary_first, comparison, ExecutionPolicy(), 0); MergeSort(first, last, temporary_first, comparison,
embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
...@@ -234,24 +248,11 @@ void MergeSort( ...@@ -234,24 +248,11 @@ void MergeSort(
RAI last, RAI last,
RAITemp temporary_first, RAITemp temporary_first,
ComparisonFunction comparison, ComparisonFunction comparison,
const ExecutionPolicy& policy const embb::mtapi::ExecutionPolicy& policy
) { ) {
MergeSort(first, last, temporary_first, comparison, policy, 0); MergeSort(first, last, temporary_first, comparison, policy, 0);
} }
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename RAITemp, typename ComparisonFunction>
void MergeSort(
const ExecutionPolicy& policy,
RAI first,
RAI last,
RAITemp temporary_first,
ComparisonFunction comparison,
size_t block_size
);
#endif // else DOXYGEN #endif // else DOXYGEN
/** /**
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#define EMBB_ALGORITHMS_QUICK_SORT_H_ #define EMBB_ALGORITHMS_QUICK_SORT_H_
#include <functional> #include <functional>
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
namespace embb { namespace embb {
namespace algorithms { namespace algorithms {
...@@ -72,7 +72,7 @@ void QuickSort( ...@@ -72,7 +72,7 @@ void QuickSort(
\c a appears before an element \c b in the sorted range if \c a appears before an element \c b in the sorted range if
<tt>comparison(a, b) == true</tt>. The default value uses the <tt>comparison(a, b) == true</tt>. The default value uses the
less-than relation. */ less-than relation. */
const ExecutionPolicy& policy = ExecutionPolicy(), const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the quick sort algorithm */ /**< [IN] ExecutionPolicy for the quick sort algorithm */
size_t block_size = 0 size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that /**< [IN] Lower bound for partitioning the range of elements into blocks that
...@@ -88,6 +88,18 @@ void QuickSort( ...@@ -88,6 +88,18 @@ void QuickSort(
#else // DOXYGEN #else // DOXYGEN
/** /**
* Overload of above described Doxygen dummy.
*/
template <typename RAI, typename ComparisonFunction>
void QuickSort(
RAI first,
RAI last,
ComparisonFunction comparison,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy with less arguments. * Overload of above described Doxygen dummy with less arguments.
*/ */
template <typename RAI> template <typename RAI>
...@@ -97,7 +109,7 @@ void QuickSort( ...@@ -97,7 +109,7 @@ void QuickSort(
) { ) {
QuickSort(first, last, QuickSort(first, last,
std::less<typename std::iterator_traits<RAI>::value_type>(), std::less<typename std::iterator_traits<RAI>::value_type>(),
ExecutionPolicy(), 0); embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
...@@ -109,7 +121,7 @@ void QuickSort( ...@@ -109,7 +121,7 @@ void QuickSort(
RAI last, RAI last,
ComparisonFunction comparison ComparisonFunction comparison
) { ) {
QuickSort(first, last, comparison, ExecutionPolicy(), 0); QuickSort(first, last, comparison, embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
...@@ -120,23 +132,11 @@ void QuickSort( ...@@ -120,23 +132,11 @@ void QuickSort(
RAI first, RAI first,
RAI last, RAI last,
ComparisonFunction comparison, ComparisonFunction comparison,
const ExecutionPolicy& policy const embb::mtapi::ExecutionPolicy& policy
) { ) {
QuickSort(first, last, comparison, policy, 0); QuickSort(first, last, comparison, policy, 0);
} }
/**
* Overload of above described Doxygen dummy.
*/
template <typename RAI, typename ComparisonFunction>
void QuickSort(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy,
size_t block_size
);
#endif // else DOXYGEN #endif // else DOXYGEN
/** /**
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#ifndef EMBB_ALGORITHMS_REDUCE_H_ #ifndef EMBB_ALGORITHMS_REDUCE_H_
#define EMBB_ALGORITHMS_REDUCE_H_ #define EMBB_ALGORITHMS_REDUCE_H_
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
#include <embb/algorithms/identity.h> #include <embb/algorithms/identity.h>
namespace embb { namespace embb {
...@@ -89,7 +89,7 @@ ReturnType Reduce( ...@@ -89,7 +89,7 @@ ReturnType Reduce(
TransformationFunction transformation = Identity(), TransformationFunction transformation = Identity(),
/**< [IN] Transforms the elements of the range before the reduction operation /**< [IN] Transforms the elements of the range before the reduction operation
is applied */ is applied */
const ExecutionPolicy& policy = ExecutionPolicy(), const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the reduction computation */ /**< [IN] ExecutionPolicy for the reduction computation */
size_t block_size = 0 size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that /**< [IN] Lower bound for partitioning the range of elements into blocks that
...@@ -103,6 +103,21 @@ ReturnType Reduce( ...@@ -103,6 +103,21 @@ ReturnType Reduce(
#else // DOXYGEN #else // DOXYGEN
/** /**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ReturnType, typename ReductionFunction,
typename TransformationFunction>
ReturnType Reduce(
RAI first,
RAI last,
ReturnType neutral,
ReductionFunction reduction,
TransformationFunction transformation,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy with less arguments. * Overload of above described Doxygen dummy with less arguments.
*/ */
template<typename RAI, typename ReturnType, typename ReductionFunction> template<typename RAI, typename ReturnType, typename ReductionFunction>
...@@ -112,8 +127,8 @@ ReturnType Reduce( ...@@ -112,8 +127,8 @@ ReturnType Reduce(
ReturnType neutral, ReturnType neutral,
ReductionFunction reduction ReductionFunction reduction
) { ) {
return Reduce(first, last, neutral, reduction, Identity(), ExecutionPolicy(), return Reduce(first, last, neutral, reduction, Identity(),
0); embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
...@@ -129,7 +144,7 @@ ReturnType Reduce( ...@@ -129,7 +144,7 @@ ReturnType Reduce(
TransformationFunction transformation TransformationFunction transformation
) { ) {
return Reduce(first, last, neutral, reduction, transformation, return Reduce(first, last, neutral, reduction, transformation,
ExecutionPolicy(), 0); embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
...@@ -143,26 +158,11 @@ ReturnType Reduce( ...@@ -143,26 +158,11 @@ ReturnType Reduce(
ReturnType neutral, ReturnType neutral,
ReductionFunction reduction, ReductionFunction reduction,
TransformationFunction transformation, TransformationFunction transformation,
const ExecutionPolicy& policy const embb::mtapi::ExecutionPolicy& policy
) { ) {
return Reduce(first, last, neutral, reduction, transformation, policy, 0); return Reduce(first, last, neutral, reduction, transformation, policy, 0);
} }
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ReturnType, typename ReductionFunction,
typename TransformationFunction>
ReturnType Reduce(
RAI first,
RAI last,
ReturnType neutral,
ReductionFunction reduction,
TransformationFunction transformation,
const ExecutionPolicy& policy,
size_t block_size
);
#endif // else DOXYGEN #endif // else DOXYGEN
/** /**
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#ifndef EMBB_ALGORITHMS_SCAN_H_ #ifndef EMBB_ALGORITHMS_SCAN_H_
#define EMBB_ALGORITHMS_SCAN_H_ #define EMBB_ALGORITHMS_SCAN_H_
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
#include <embb/algorithms/identity.h> #include <embb/algorithms/identity.h>
namespace embb { namespace embb {
...@@ -96,7 +96,7 @@ void Scan( ...@@ -96,7 +96,7 @@ void Scan(
TransformationFunction transformation = Identity(), TransformationFunction transformation = Identity(),
/**< [IN] Transforms the elements of the input range before the scan operation /**< [IN] Transforms the elements of the input range before the scan operation
is applied */ is applied */
const ExecutionPolicy& policy = ExecutionPolicy(), const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the scan computation */ /**< [IN] ExecutionPolicy for the scan computation */
size_t block_size = 0 size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that /**< [IN] Lower bound for partitioning the range of elements into blocks that
...@@ -110,36 +110,35 @@ void Scan( ...@@ -110,36 +110,35 @@ void Scan(
#else // DOXYGEN #else // DOXYGEN
/** /**
* Overload of above described Doxygen dummy with less arguments. * Overload of above described Doxygen dummy.
*/ */
template<typename RAIIn, typename RAIOut, typename ReturnType, template<typename RAIIn, typename RAIOut, typename ReturnType,
typename ScanFunction> typename ScanFunction, typename TransformationFunction>
void Scan( void Scan(
RAIIn first, RAIIn first,
RAIIn last, RAIIn last,
RAIOut output_iterator, RAIOut output_iterator,
ReturnType neutral, ReturnType neutral,
ScanFunction scan ScanFunction scan,
) { TransformationFunction transformation,
Scan(first, last, output_iterator, neutral, scan, Identity(), const embb::mtapi::ExecutionPolicy& policy,
ExecutionPolicy(), 0); size_t block_size
} );
/** /**
* Overload of above described Doxygen dummy with less arguments. * Overload of above described Doxygen dummy with less arguments.
*/ */
template<typename RAIIn, typename RAIOut, typename ReturnType, template<typename RAIIn, typename RAIOut, typename ReturnType,
typename ScanFunction, typename TransformationFunction> typename ScanFunction>
void Scan( void Scan(
RAIIn first, RAIIn first,
RAIIn last, RAIIn last,
RAIOut output_iterator, RAIOut output_iterator,
ReturnType neutral, ReturnType neutral,
ScanFunction scan, ScanFunction scan
TransformationFunction transformation
) { ) {
Scan(first, last, output_iterator, neutral, scan, transformation, Scan(first, last, output_iterator, neutral, scan, Identity(),
ExecutionPolicy(), 0); embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
...@@ -153,14 +152,14 @@ void Scan( ...@@ -153,14 +152,14 @@ void Scan(
RAIOut output_iterator, RAIOut output_iterator,
ReturnType neutral, ReturnType neutral,
ScanFunction scan, ScanFunction scan,
TransformationFunction transformation, TransformationFunction transformation
const ExecutionPolicy& policy
) { ) {
Scan(first, last, output_iterator, neutral, scan, transformation, policy, 0); Scan(first, last, output_iterator, neutral, scan, transformation,
embb::mtapi::ExecutionPolicy(), 0);
} }
/** /**
* Overload of above described Doxygen dummy. * Overload of above described Doxygen dummy with less arguments.
*/ */
template<typename RAIIn, typename RAIOut, typename ReturnType, template<typename RAIIn, typename RAIOut, typename ReturnType,
typename ScanFunction, typename TransformationFunction> typename ScanFunction, typename TransformationFunction>
...@@ -171,9 +170,10 @@ void Scan( ...@@ -171,9 +170,10 @@ void Scan(
ReturnType neutral, ReturnType neutral,
ScanFunction scan, ScanFunction scan,
TransformationFunction transformation, TransformationFunction transformation,
const ExecutionPolicy& policy, const embb::mtapi::ExecutionPolicy& policy
size_t block_size ) {
); Scan(first, last, output_iterator, neutral, scan, transformation, policy, 0);
}
#endif // else DOXYGEN #endif // else DOXYGEN
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <embb/algorithms/execution_policy.h>
namespace embb {
namespace algorithms {
ExecutionPolicy::ExecutionPolicy() :
affinity_(), priority_(DefaultPriority) {
}
ExecutionPolicy::ExecutionPolicy(bool initial_affinity, mtapi_uint_t priority)
:affinity_(initial_affinity), priority_(priority) {
}
ExecutionPolicy::ExecutionPolicy(mtapi_uint_t priority)
:affinity_(), priority_(priority) {
}
ExecutionPolicy::ExecutionPolicy(bool initial_affinity)
:affinity_(initial_affinity), priority_(DefaultPriority) {
}
void ExecutionPolicy::AddWorker(mtapi_uint_t worker) {
affinity_.Add(worker);
}
void ExecutionPolicy::RemoveWorker(mtapi_uint_t worker) {
affinity_.Remove(worker);
}
bool ExecutionPolicy::IsSetWorker(mtapi_uint_t worker) {
return affinity_.IsSet(worker);
}
const mtapi::Affinity &ExecutionPolicy::GetAffinity() const {
return affinity_;
}
mtapi_uint_t ExecutionPolicy::GetPriority() const {
return priority_;
}
const mtapi_uint_t ExecutionPolicy::DefaultPriority = 0;
} // namespace algorithms
} // namespace embb
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <count_test.h> #include <count_test.h>
#include <embb/algorithms/count.h> #include <embb/algorithms/count.h>
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
#include <deque> #include <deque>
#include <vector> #include <vector>
#include <functional> #include <functional>
...@@ -122,7 +122,7 @@ void CountTest::TestBlockSizes() { ...@@ -122,7 +122,7 @@ void CountTest::TestBlockSizes() {
void CountTest::TestPolicy() { void CountTest::TestPolicy() {
using embb::algorithms::Count; using embb::algorithms::Count;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
int a[] = { 10, 20, 30, 30, 20, 10, 10, 20, 20, 20 }; int a[] = { 10, 20, 30, 30, 20, 10, 10, 20, 20, 20 };
std::vector<int> vector(a, a + (sizeof a / sizeof a[0])); std::vector<int> vector(a, a + (sizeof a / sizeof a[0]));
PT_EXPECT_EQ(Count(vector.begin(), vector.end(), 10, ExecutionPolicy()), 3); PT_EXPECT_EQ(Count(vector.begin(), vector.end(), 10, ExecutionPolicy()), 3);
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <for_each_test.h> #include <for_each_test.h>
#include <embb/algorithms/for_each.h> #include <embb/algorithms/for_each.h>
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
#include <vector> #include <vector>
#include <deque> #include <deque>
#include <sstream> #include <sstream>
...@@ -166,7 +166,7 @@ void ForEachTest::TestRanges() { ...@@ -166,7 +166,7 @@ void ForEachTest::TestRanges() {
void ForEachTest::TestBlockSizes() { void ForEachTest::TestBlockSizes() {
using embb::algorithms::ForEach; using embb::algorithms::ForEach;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
size_t count = 4; size_t count = 4;
std::vector<int> init(count); std::vector<int> init(count);
std::vector<int> vector(count); std::vector<int> vector(count);
...@@ -186,7 +186,7 @@ void ForEachTest::TestBlockSizes() { ...@@ -186,7 +186,7 @@ void ForEachTest::TestBlockSizes() {
void ForEachTest::TestPolicy() { void ForEachTest::TestPolicy() {
using embb::algorithms::ForEach; using embb::algorithms::ForEach;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
size_t count = 4; size_t count = 4;
std::vector<int> init(count); std::vector<int> init(count);
std::vector<int> vector(count); std::vector<int> vector(count);
...@@ -221,7 +221,7 @@ void ForEachTest::TestPolicy() { ...@@ -221,7 +221,7 @@ void ForEachTest::TestPolicy() {
void ForEachTest::StressTest() { void ForEachTest::StressTest() {
using embb::algorithms::ForEach; using embb::algorithms::ForEach;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10; size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10;
std::vector<int> large_vector(count); std::vector<int> large_vector(count);
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <merge_sort_test.h> #include <merge_sort_test.h>
#include <embb/algorithms/merge_sort.h> #include <embb/algorithms/merge_sort.h>
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
#include <vector> #include <vector>
#include <deque> #include <deque>
#include <sstream> #include <sstream>
...@@ -50,7 +50,7 @@ MergeSortTest::MergeSortTest() { ...@@ -50,7 +50,7 @@ MergeSortTest::MergeSortTest() {
void MergeSortTest::TestDataStructures() { void MergeSortTest::TestDataStructures() {
using embb::algorithms::MergeSortAllocate; using embb::algorithms::MergeSortAllocate;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
int array[kCountSize]; int array[kCountSize];
std::vector<int> vector(kCountSize); std::vector<int> vector(kCountSize);
std::deque<int> deque(kCountSize); std::deque<int> deque(kCountSize);
...@@ -75,7 +75,7 @@ void MergeSortTest::TestDataStructures() { ...@@ -75,7 +75,7 @@ void MergeSortTest::TestDataStructures() {
void MergeSortTest::TestFunctionPointers() { void MergeSortTest::TestFunctionPointers() {
using embb::algorithms::MergeSortAllocate; using embb::algorithms::MergeSortAllocate;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
std::vector<int> vector(kCountSize); std::vector<int> vector(kCountSize);
for (size_t i = kCountSize - 1; i > 0; i--) { for (size_t i = kCountSize - 1; i > 0; i--) {
...@@ -181,7 +181,7 @@ void MergeSortTest::TestRanges() { ...@@ -181,7 +181,7 @@ void MergeSortTest::TestRanges() {
void MergeSortTest::TestPolicy() { void MergeSortTest::TestPolicy() {
using embb::algorithms::MergeSortAllocate; using embb::algorithms::MergeSortAllocate;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
size_t count = 4; size_t count = 4;
std::vector<int> init(count); std::vector<int> init(count);
std::vector<int> vector(count); std::vector<int> vector(count);
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <quick_sort_test.h> #include <quick_sort_test.h>
#include <embb/algorithms/quick_sort.h> #include <embb/algorithms/quick_sort.h>
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
#include <vector> #include <vector>
#include <deque> #include <deque>
#include <sstream> #include <sstream>
...@@ -54,7 +54,7 @@ QuickSortTest::QuickSortTest() { ...@@ -54,7 +54,7 @@ QuickSortTest::QuickSortTest() {
void QuickSortTest::TestDataStructures() { void QuickSortTest::TestDataStructures() {
using embb::algorithms::QuickSort; using embb::algorithms::QuickSort;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
int array[kCountSize]; int array[kCountSize];
std::vector<int> vector(kCountSize); std::vector<int> vector(kCountSize);
...@@ -163,7 +163,7 @@ void QuickSortTest::TestRanges() { ...@@ -163,7 +163,7 @@ void QuickSortTest::TestRanges() {
void QuickSortTest::TestBlockSizes() { void QuickSortTest::TestBlockSizes() {
using embb::algorithms::QuickSort; using embb::algorithms::QuickSort;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
size_t count = 4; size_t count = 4;
std::vector<int> init(count); std::vector<int> init(count);
...@@ -187,7 +187,7 @@ void QuickSortTest::TestBlockSizes() { ...@@ -187,7 +187,7 @@ void QuickSortTest::TestBlockSizes() {
void QuickSortTest::TestPolicy() { void QuickSortTest::TestPolicy() {
using embb::algorithms::QuickSort; using embb::algorithms::QuickSort;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
size_t count = 4; size_t count = 4;
std::vector<int> init(count); std::vector<int> init(count);
std::vector<int> vector(count); std::vector<int> vector(count);
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <reduce_test.h> #include <reduce_test.h>
#include <embb/algorithms/reduce.h> #include <embb/algorithms/reduce.h>
#include <embb/algorithms/execution_policy.h> #include <embb/mtapi/execution_policy.h>
#include <deque> #include <deque>
#include <vector> #include <vector>
#include <functional> #include <functional>
...@@ -163,7 +163,7 @@ void ReduceTest::TestBlockSizes() { ...@@ -163,7 +163,7 @@ void ReduceTest::TestBlockSizes() {
void ReduceTest::TestPolicy() { void ReduceTest::TestPolicy() {
using embb::algorithms::Reduce; using embb::algorithms::Reduce;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity; using embb::algorithms::Identity;
size_t count = 4; size_t count = 4;
int sum = 0; int sum = 0;
...@@ -187,7 +187,7 @@ void ReduceTest::TestPolicy() { ...@@ -187,7 +187,7 @@ void ReduceTest::TestPolicy() {
void ReduceTest::StressTest() { void ReduceTest::StressTest() {
using embb::algorithms::Reduce; using embb::algorithms::Reduce;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity; using embb::algorithms::Identity;
size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10; size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10;
std::vector<int> large_vector(count); std::vector<int> large_vector(count);
......
...@@ -228,7 +228,7 @@ void ScanTest::TestRanges() { ...@@ -228,7 +228,7 @@ void ScanTest::TestRanges() {
void ScanTest::TestBlockSizes() { void ScanTest::TestBlockSizes() {
using embb::algorithms::Scan; using embb::algorithms::Scan;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity; using embb::algorithms::Identity;
size_t count = 4; size_t count = 4;
std::vector<int> init(count); std::vector<int> init(count);
...@@ -253,7 +253,7 @@ void ScanTest::TestBlockSizes() { ...@@ -253,7 +253,7 @@ void ScanTest::TestBlockSizes() {
void ScanTest::TestPolicy() { void ScanTest::TestPolicy() {
using embb::algorithms::Scan; using embb::algorithms::Scan;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity; using embb::algorithms::Identity;
size_t count = 4; size_t count = 4;
std::vector<int> init(count); std::vector<int> init(count);
...@@ -304,7 +304,7 @@ void ScanTest::TestPolicy() { ...@@ -304,7 +304,7 @@ void ScanTest::TestPolicy() {
void ScanTest::StressTest() { void ScanTest::StressTest() {
using embb::algorithms::Scan; using embb::algorithms::Scan;
using embb::algorithms::Identity; using embb::algorithms::Identity;
using embb::algorithms::ExecutionPolicy; using embb::mtapi::ExecutionPolicy;
size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10; size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10;
std::vector<int> large_vector(count); std::vector<int> large_vector(count);
std::vector<int> large_vector_output(count); std::vector<int> large_vector_output(count);
......
...@@ -136,7 +136,7 @@ void ZipIteratorTest::TestZipScan() { ...@@ -136,7 +136,7 @@ void ZipIteratorTest::TestZipScan() {
Scan(embb::algorithms::Zip(vectorA.begin(), vectorB.begin()), Scan(embb::algorithms::Zip(vectorA.begin(), vectorB.begin()),
embb::algorithms::Zip(vectorA.end(), vectorB.end()), embb::algorithms::Zip(vectorA.end(), vectorB.end()),
vectorOut.begin(), 0, std::plus<int>(), DotProductFunctor(), vectorOut.begin(), 0, std::plus<int>(), DotProductFunctor(),
embb::algorithms::ExecutionPolicy(), 0); embb::mtapi::ExecutionPolicy(), 0);
long sum = 0; long sum = 0;
for (size_t i = 0; i < kCountSize; i++) { for (size_t i = 0; i < kCountSize; i++) {
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <embb/base/function.h> #include <embb/base/function.h>
#include <embb/mtapi/taskcontext.h> #include <embb/mtapi/taskcontext.h>
#include <embb/mtapi/affinity.h> #include <embb/mtapi/execution_policy.h>
namespace embb { namespace embb {
namespace mtapi { namespace mtapi {
...@@ -46,7 +46,7 @@ class Action { ...@@ -46,7 +46,7 @@ class Action {
*/ */
Action() Action()
: function_() : function_()
, affinity_() { , execution_policy_() {
// empty // empty
} }
...@@ -60,7 +60,7 @@ class Action { ...@@ -60,7 +60,7 @@ class Action {
operator() (TaskContext &). */ operator() (TaskContext &). */
) )
: function_(func) : function_(func)
, affinity_() { , execution_policy_() {
// empty // empty
} }
...@@ -72,10 +72,10 @@ class Action { ...@@ -72,10 +72,10 @@ class Action {
Action( Action(
Function func, /**< [in] Anything that provides an Function func, /**< [in] Anything that provides an
operator() (TaskContext &). */ operator() (TaskContext &). */
Affinity affinity /**< [in] Core affinity */ ExecutionPolicy execution_policy /**< [in] Execution policy */
) )
: function_(func) : function_(func)
, affinity_(affinity) { , execution_policy_(execution_policy) {
// empty // empty
} }
...@@ -90,17 +90,17 @@ class Action { ...@@ -90,17 +90,17 @@ class Action {
} }
/** /**
* Returns the Affinity specified during creation. * Returns the ExecutionPolicy specified during creation.
* \return The Affinity of the Action * \return The ExecutionPolicy of the Action
* \waitfree * \waitfree
*/ */
Affinity GetAffinity() const { ExecutionPolicy GetExecutionPolicy() const {
return affinity_; return execution_policy_;
} }
private: private:
embb::base::Function<void, TaskContext &> function_; embb::base::Function<void, TaskContext &> function_;
Affinity affinity_; ExecutionPolicy execution_policy_;
}; };
} // namespace mtapi } // namespace mtapi
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef EMBB_MTAPI_AFFINITY_H_
#define EMBB_MTAPI_AFFINITY_H_
#include <embb/mtapi/c/mtapi.h>
namespace embb {
namespace mtapi {
/**
* Describes the Affinity of a Task to worker threads.
*
* \ingroup CPP_MTAPI
*/
class Affinity {
public:
/**
* Constructs an Affinity including all worker threads.
* \memory Calls embb::mtapi::Node::Initialize() which potentially allocates
* \throws ErrorException if the Affinity object could not be constructed.
*/
Affinity();
/**
* Constructs an Affinity including all or no worker threads.
* \memory Calls embb::mtapi::Node::Initialize() which potentially allocates
* \throws ErrorException if the Affinity object could not be constructed.
*/
Affinity(
bool initial_affinity /**< [in] Initial affinity
(true = all worker threads,
false = no worker threads) */
);
/**
* Sets Affinity to a specific worker thread.
* \threadsafe
*/
void Add(
mtapi_uint_t worker /**< [in] Worker thread index */
);
/**
* Removes Affinity to a specific worker thread.
* \threadsafe
*/
void Remove(
mtapi_uint_t worker /**< [in] Worker thread index */
);
/**
* Checks if Affinity to a specific worker thread is set.
* \return \c true if \c *this is affine to the given worker, otherwise
* \c false.
* \threadsafe
*/
bool IsSet(
mtapi_uint_t worker /**< [in] Worker thread index */
);
friend class Task;
private:
mtapi_affinity_t affinity_;
};
} // namespace mtapi
} // namespace embb
#endif // EMBB_MTAPI_AFFINITY_H_
...@@ -80,12 +80,12 @@ class Continuation { ...@@ -80,12 +80,12 @@ class Continuation {
Task Spawn(); Task Spawn();
/** /**
* Runs the Continuation chain with the specified priority. * Runs the Continuation chain with the specified execution_policy.
* \returns The Task representing the Continuation chain. * \returns The Task representing the Continuation chain.
* \notthreadsafe * \notthreadsafe
*/ */
Task Spawn( Task Spawn(
mtapi_uint_t priority /**< [in] The priority to use */ ExecutionPolicy execution_policy /**< [in] The execution policy to use */
); );
friend class Node; friend class Node;
...@@ -97,8 +97,6 @@ class Continuation { ...@@ -97,8 +97,6 @@ class Continuation {
ContinuationStage * first_; ContinuationStage * first_;
ContinuationStage * last_; ContinuationStage * last_;
mtapi_uint_t priority_;
}; };
} // namespace mtapi } // namespace mtapi
......
...@@ -24,21 +24,20 @@ ...@@ -24,21 +24,20 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef EMBB_ALGORITHMS_EXECUTION_POLICY_H_ #ifndef EMBB_MTAPI_EXECUTION_POLICY_H_
#define EMBB_ALGORITHMS_EXECUTION_POLICY_H_ #define EMBB_MTAPI_EXECUTION_POLICY_H_
#include <embb/mtapi/mtapi.h> #include <embb/mtapi/c/mtapi.h>
#include <embb/mtapi/affinity.h>
namespace embb { namespace embb {
namespace algorithms { namespace mtapi {
/** /**
* Describes the execution policy of a parallel algorithm. * Describes the execution policy of a parallel algorithm.
* The execution policy comprises * The execution policy comprises
* - the affinity of tasks to MTAPI worker threads (not CPU cores) and * - the affinity of tasks to MTAPI worker threads (not CPU cores) and
* - the priority of the spawned tasks. * - the priority of the spawned tasks.
* *
* \ingroup CPP_ALGORITHMS * \ingroup CPP_MTAPI
*/ */
class ExecutionPolicy{ class ExecutionPolicy{
public: public:
...@@ -53,11 +52,11 @@ class ExecutionPolicy{ ...@@ -53,11 +52,11 @@ class ExecutionPolicy{
* Constructs an execution policy with the specified affinity and priority. * Constructs an execution policy with the specified affinity and priority.
*/ */
ExecutionPolicy( ExecutionPolicy(
bool initial_affinity, /**< bool initial_affinity, /**< [in] \c true sets the affinity to
[IN] \c true sets the affinity to all worker threads, \c false to no all worker threads, \c false to no
worker threads. */ worker threads. */
mtapi_uint_t priority /**< mtapi_uint_t priority /**< [in] Priority for the execution
[IN] Priority for the execution policy. */ policy. */
); );
/** /**
...@@ -65,8 +64,8 @@ class ExecutionPolicy{ ...@@ -65,8 +64,8 @@ class ExecutionPolicy{
* Sets the affinity to all worker threads. * Sets the affinity to all worker threads.
*/ */
explicit ExecutionPolicy( explicit ExecutionPolicy(
mtapi_uint_t priority /**< mtapi_uint_t priority /**< [in] Priority for the execution
[IN] Priority for the execution policy. */ policy. */
); );
/** /**
...@@ -74,25 +73,23 @@ class ExecutionPolicy{ ...@@ -74,25 +73,23 @@ class ExecutionPolicy{
* Sets the priority to the default value. * Sets the priority to the default value.
*/ */
explicit ExecutionPolicy( explicit ExecutionPolicy(
bool initial_affinity /**< bool initial_affinity /**< [in] \c true sets the affinity to
[IN] \c true sets the affinity to all worker threads, \c false to no all worker threads, \c false to no
worker threads. */ worker threads. */
); );
/** /**
* Sets affinity to a specific worker thread. * Sets affinity to a specific worker thread.
*/ */
void AddWorker( void AddWorker(
mtapi_uint_t worker mtapi_uint_t worker /**< [in] Worker thread index */
/**< [IN] Worker thread index */
); );
/** /**
* Removes affinity to a specific worker thread. * Removes affinity to a specific worker thread.
*/ */
void RemoveWorker( void RemoveWorker(
mtapi_uint_t worker mtapi_uint_t worker /**< [in] Worker thread index */
/**< [IN] Worker thread index */
); );
/** /**
...@@ -101,8 +98,7 @@ class ExecutionPolicy{ ...@@ -101,8 +98,7 @@ class ExecutionPolicy{
* \return \c true if affinity is set, otherwise \c false * \return \c true if affinity is set, otherwise \c false
*/ */
bool IsSetWorker( bool IsSetWorker(
mtapi_uint_t worker mtapi_uint_t worker /**< [in] Worker thread index */
/**< [IN] Worker thread index */
); );
/** /**
...@@ -110,7 +106,7 @@ class ExecutionPolicy{ ...@@ -110,7 +106,7 @@ class ExecutionPolicy{
* *
* \return the affinity * \return the affinity
*/ */
const mtapi::Affinity &GetAffinity() const; const mtapi_affinity_t &GetAffinity() const;
/** Returns the priority /** Returns the priority
* *
...@@ -118,6 +114,8 @@ class ExecutionPolicy{ ...@@ -118,6 +114,8 @@ class ExecutionPolicy{
*/ */
mtapi_uint_t GetPriority() const; mtapi_uint_t GetPriority() const;
friend class Task;
private: private:
/** /**
* Default priority. * Default priority.
...@@ -129,14 +127,14 @@ class ExecutionPolicy{ ...@@ -129,14 +127,14 @@ class ExecutionPolicy{
* Task Affinity. * Task Affinity.
* Maps the affinity of tasks to MTAPI worker threads (not CPU cores). * Maps the affinity of tasks to MTAPI worker threads (not CPU cores).
*/ */
mtapi::Affinity affinity_; mtapi_affinity_t affinity_;
/** /**
* Task Priority. * Task Priority.
*/ */
mtapi_uint_t priority_; mtapi_uint_t priority_;
}; };
} // namespace algorithms } // namespace mtapi
} // namespace embb } // namespace embb
#endif // EMBB_ALGORITHMS_EXECUTION_POLICY_H_ #endif // EMBB_MTAPI_EXECUTION_POLICY_H_
...@@ -60,16 +60,6 @@ class Group { ...@@ -60,16 +60,6 @@ class Group {
); );
/** /**
* Runs an Action within the Group with the specified priority.
* \return A Task identifying the Action to run
* \threadsafe
*/
Task Spawn(
Action action, /**< [in] The Action to run */
mtapi_uint_t priority /**< [in] The priority to use */
);
/**
* Runs an Action within the Group. The \c id is returned by WaitAny(). * Runs an Action within the Group. The \c id is returned by WaitAny().
* \return A Task identifying the Action to run * \return A Task identifying the Action to run
* \throws ErrorException if the Task object could not be constructed. * \throws ErrorException if the Task object could not be constructed.
...@@ -82,20 +72,6 @@ class Group { ...@@ -82,20 +72,6 @@ class Group {
); );
/** /**
* Runs an Action within the Group with the specified priority. The \c id is
* returned by WaitAny().
* \return A Task identifying the Action to run
* \throws ErrorException if the Task object could not be constructed.
* \threadsafe
*/
Task Spawn(
mtapi_task_id_t id, /**< [in] The id to return by
WaitAny() */
Action action, /**< [in] The Action to run */
mtapi_uint_t priority /**< [in] The priority to use */
);
/**
* Waits for any Task in the Group to finish for \c timeout milliseconds. * Waits for any Task in the Group to finish for \c timeout milliseconds.
* \return The status of the Task that finished execution * \return The status of the Task that finished execution
* \threadsafe * \threadsafe
......
...@@ -42,8 +42,8 @@ ...@@ -42,8 +42,8 @@
#define MTAPI_CPP_AUTOMATIC_NODE_ID 1 #define MTAPI_CPP_AUTOMATIC_NODE_ID 1
#endif #endif
#include <embb/mtapi/execution_policy.h>
#include <embb/mtapi/action.h> #include <embb/mtapi/action.h>
#include <embb/mtapi/affinity.h>
#include <embb/mtapi/continuation.h> #include <embb/mtapi/continuation.h>
#include <embb/mtapi/group.h> #include <embb/mtapi/group.h>
#include <embb/mtapi/node.h> #include <embb/mtapi/node.h>
......
...@@ -174,17 +174,6 @@ class Node { ...@@ -174,17 +174,6 @@ class Node {
); );
/** /**
* Runs an Action with the specified priority.
* \return A Task identifying the Action to run
* \throws ErrorException if the Task object could not be constructed.
* \threadsafe
*/
Task Spawn(
Action action, /**< [in] The Action to execute */
mtapi_uint_t priority /**< [in] The priority to use */
);
/**
* Creates a Continuation. * Creates a Continuation.
* \return A Continuation chain * \return A Continuation chain
* \threadsafe * \threadsafe
......
...@@ -80,38 +80,31 @@ class Task { ...@@ -80,38 +80,31 @@ class Task {
private: private:
Task( Task(
Action action, Action action);
mtapi_uint_t priority
);
Task( Task(
Action action, Action action,
mtapi_group_hndl_t group, mtapi_group_hndl_t group);
mtapi_uint_t priority);
Task( Task(
mtapi_task_id_t id, mtapi_task_id_t id,
Action action, Action action,
mtapi_group_hndl_t group, mtapi_group_hndl_t group);
mtapi_uint_t priority);
Task( Task(
Action action, Action action,
mtapi_queue_hndl_t queue, mtapi_queue_hndl_t queue);
mtapi_uint_t priority);
Task( Task(
Action action, Action action,
mtapi_queue_hndl_t queue, mtapi_queue_hndl_t queue,
mtapi_group_hndl_t group, mtapi_group_hndl_t group);
mtapi_uint_t priority);
Task( Task(
mtapi_task_id_t id, mtapi_task_id_t id,
Action action, Action action,
mtapi_queue_hndl_t queue, mtapi_queue_hndl_t queue,
mtapi_group_hndl_t group, mtapi_group_hndl_t group);
mtapi_uint_t priority);
mtapi_task_hndl_t handle_; mtapi_task_hndl_t handle_;
}; };
......
...@@ -53,7 +53,7 @@ void Continuation::ExecuteContinuation(TaskContext &) { ...@@ -53,7 +53,7 @@ void Continuation::ExecuteContinuation(TaskContext &) {
mtapi::ContinuationStage * stage = first_; mtapi::ContinuationStage * stage = first_;
mtapi::Node & node = mtapi::Node::GetInstance(); mtapi::Node & node = mtapi::Node::GetInstance();
while (NULL != stage) { while (NULL != stage) {
mtapi::Task task = node.Spawn(stage->action, priority_); mtapi::Task task = node.Spawn(stage->action);
task.Wait(MTAPI_INFINITE); task.Wait(MTAPI_INFINITE);
stage = stage->next; stage = stage->next;
} }
...@@ -79,15 +79,17 @@ Continuation & Continuation::Then(Action action) { ...@@ -79,15 +79,17 @@ Continuation & Continuation::Then(Action action) {
} }
Task Continuation::Spawn() { Task Continuation::Spawn() {
return Spawn(0); return Spawn(ExecutionPolicy());
} }
Task Continuation::Spawn(mtapi_uint_t priority) { Task Continuation::Spawn(ExecutionPolicy execution_policy) {
priority_ = priority;
Node & node = Node::GetInstance(); Node & node = Node::GetInstance();
return node.Spawn( return node.Spawn(
embb::base::MakeFunction(*this, &Continuation::ExecuteContinuation), Action(
priority); embb::base::MakeFunction(*this, &Continuation::ExecuteContinuation),
ExecutionPolicy(execution_policy)
)
);
} }
} // namespace mtapi } // namespace mtapi
......
...@@ -24,15 +24,15 @@ ...@@ -24,15 +24,15 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <cassert> #include <embb/mtapi/execution_policy.h>
#include <embb/base/exceptions.h> #include <embb/base/exceptions.h>
#include <embb/mtapi/mtapi.h> #include <cassert>
namespace embb { namespace embb {
namespace mtapi { namespace mtapi {
Affinity::Affinity() { ExecutionPolicy::ExecutionPolicy() :
priority_(DefaultPriority) {
#if MTAPI_CPP_AUTOMATIC_INITIALIZE #if MTAPI_CPP_AUTOMATIC_INITIALIZE
Node::GetInstance(); // MTAPI has to be initialized Node::GetInstance(); // MTAPI has to be initialized
#endif #endif
...@@ -44,37 +44,75 @@ Affinity::Affinity() { ...@@ -44,37 +44,75 @@ Affinity::Affinity() {
} }
} }
Affinity::Affinity(bool initial_affinity) { ExecutionPolicy::ExecutionPolicy(bool initial_affinity, mtapi_uint_t priority)
:priority_(priority) {
#if MTAPI_CPP_AUTOMATIC_INITIALIZE #if MTAPI_CPP_AUTOMATIC_INITIALIZE
Node::GetInstance(); // MTAPI has to be initialized Node::GetInstance(); // MTAPI has to be initialized
#endif #endif
mtapi_status_t status; mtapi_status_t status;
mtapi_boolean_t aff = initial_affinity ? MTAPI_TRUE : MTAPI_FALSE; mtapi_affinity_init(&affinity_, initial_affinity ? MTAPI_TRUE : MTAPI_FALSE,
mtapi_affinity_init(&affinity_, aff, &status); &status);
if (MTAPI_SUCCESS != status) { if (MTAPI_SUCCESS != status) {
EMBB_THROW(embb::base::ErrorException, EMBB_THROW(embb::base::ErrorException,
"Could not default construct Affinity."); "Could not default construct Affinity.");
} }
} }
void Affinity::Add(mtapi_uint_t worker) { ExecutionPolicy::ExecutionPolicy(mtapi_uint_t priority)
:priority_(priority) {
#if MTAPI_CPP_AUTOMATIC_INITIALIZE
Node::GetInstance(); // MTAPI has to be initialized
#endif
mtapi_status_t status;
mtapi_affinity_init(&affinity_, MTAPI_TRUE, &status);
if (MTAPI_SUCCESS != status) {
EMBB_THROW(embb::base::ErrorException,
"Could not default construct Affinity.");
}
}
ExecutionPolicy::ExecutionPolicy(bool initial_affinity)
:priority_(DefaultPriority) {
#if MTAPI_CPP_AUTOMATIC_INITIALIZE
Node::GetInstance(); // MTAPI has to be initialized
#endif
mtapi_status_t status;
mtapi_affinity_init(&affinity_, initial_affinity ? MTAPI_TRUE : MTAPI_FALSE,
&status);
if (MTAPI_SUCCESS != status) {
EMBB_THROW(embb::base::ErrorException,
"Could not default construct Affinity.");
}
}
void ExecutionPolicy::AddWorker(mtapi_uint_t worker) {
mtapi_status_t status; mtapi_status_t status;
mtapi_affinity_set(&affinity_, worker, MTAPI_TRUE, &status); mtapi_affinity_set(&affinity_, worker, MTAPI_TRUE, &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
} }
void Affinity::Remove(mtapi_uint_t worker) { void ExecutionPolicy::RemoveWorker(mtapi_uint_t worker) {
mtapi_status_t status; mtapi_status_t status;
mtapi_affinity_set(&affinity_, worker, MTAPI_FALSE, &status); mtapi_affinity_set(&affinity_, worker, MTAPI_FALSE, &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
} }
bool Affinity::IsSet(mtapi_uint_t worker) { bool ExecutionPolicy::IsSetWorker(mtapi_uint_t worker) {
mtapi_status_t status; mtapi_status_t status;
mtapi_boolean_t aff = mtapi_affinity_get(&affinity_, worker, &status); mtapi_boolean_t aff = mtapi_affinity_get(&affinity_, worker, &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
return MTAPI_TRUE == aff; return MTAPI_TRUE == aff;
} }
} // namespace mtapi const mtapi_affinity_t &ExecutionPolicy::GetAffinity() const {
} // namespace embb return affinity_;
}
mtapi_uint_t ExecutionPolicy::GetPriority() const {
return priority_;
}
const mtapi_uint_t ExecutionPolicy::DefaultPriority = 0;
} // namespace mtapi
} // namespace embb
...@@ -53,19 +53,11 @@ void Group::Create() { ...@@ -53,19 +53,11 @@ void Group::Create() {
} }
Task Group::Spawn(Action action) { Task Group::Spawn(Action action) {
return Spawn(action, 0); return Task(action, handle_);
}
Task Group::Spawn(Action action, mtapi_uint_t priority) {
return Task(action, handle_, priority);
} }
Task Group::Spawn(mtapi_task_id_t id, Action action) { Task Group::Spawn(mtapi_task_id_t id, Action action) {
return Spawn(id, action, 0); return Task(id, action, handle_);
}
Task Group::Spawn(mtapi_task_id_t id, Action action, mtapi_uint_t priority) {
return Task(id, action, handle_, priority);
} }
mtapi_status_t Group::WaitAny(mtapi_timeout_t timeout) { mtapi_status_t Group::WaitAny(mtapi_timeout_t timeout) {
......
...@@ -259,11 +259,7 @@ void Node::DestroyQueue(Queue & queue) { ...@@ -259,11 +259,7 @@ void Node::DestroyQueue(Queue & queue) {
} }
Task Node::Spawn(Action action) { Task Node::Spawn(Action action) {
return Spawn(action, 0); return Task(action);
}
Task Node::Spawn(Action action, mtapi_uint_t priority) {
return Task(action, priority);
} }
Continuation Node::First(Action action) { Continuation Node::First(Action action) {
......
...@@ -79,11 +79,11 @@ void Queue::Disable() { ...@@ -79,11 +79,11 @@ void Queue::Disable() {
} }
Task Queue::Spawn(Action action) { Task Queue::Spawn(Action action) {
return Task(action, handle_, 0); return Task(action, handle_);
} }
Task Queue::Spawn(Group const * group, Action action) { Task Queue::Spawn(Group const * group, Action action) {
return Task(action, handle_, group->handle_, 0); return Task(action, handle_, group->handle_);
} }
} // namespace mtapi } // namespace mtapi
......
...@@ -45,18 +45,17 @@ Task::Task(Task const & task) ...@@ -45,18 +45,17 @@ Task::Task(Task const & task)
} }
Task::Task( Task::Task(
Action action, Action action) {
mtapi_uint_t priority) {
mtapi_status_t status; mtapi_status_t status;
mtapi_task_attributes_t attr; mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity(); ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status); mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status); &policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status); &policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_domain_t domain_id = mtapi_domain_id_get(&status); mtapi_domain_t domain_id = mtapi_domain_id_get(&status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
...@@ -73,18 +72,17 @@ Task::Task( ...@@ -73,18 +72,17 @@ Task::Task(
Task::Task( Task::Task(
Action action, Action action,
mtapi_group_hndl_t group, mtapi_group_hndl_t group) {
mtapi_uint_t priority) {
mtapi_status_t status; mtapi_status_t status;
mtapi_task_attributes_t attr; mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity(); ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status); mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status); &policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status); &policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_domain_t domain_id = mtapi_domain_id_get(&status); mtapi_domain_t domain_id = mtapi_domain_id_get(&status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
...@@ -102,18 +100,17 @@ Task::Task( ...@@ -102,18 +100,17 @@ Task::Task(
Task::Task( Task::Task(
mtapi_task_id_t id, mtapi_task_id_t id,
Action action, Action action,
mtapi_group_hndl_t group, mtapi_group_hndl_t group) {
mtapi_uint_t priority) {
mtapi_status_t status; mtapi_status_t status;
mtapi_task_attributes_t attr; mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity(); ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status); mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status); &policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status); &policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_domain_t domain_id = mtapi_domain_id_get(&status); mtapi_domain_t domain_id = mtapi_domain_id_get(&status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
...@@ -132,18 +129,17 @@ Task::Task( ...@@ -132,18 +129,17 @@ Task::Task(
Task::Task( Task::Task(
Action action, Action action,
mtapi_queue_hndl_t queue, mtapi_queue_hndl_t queue) {
mtapi_uint_t priority) {
mtapi_status_t status; mtapi_status_t status;
mtapi_task_attributes_t attr; mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity(); ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status); mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status); &policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status); &policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
Action* holder = embb::base::Allocation::New<Action>(action); Action* holder = embb::base::Allocation::New<Action>(action);
handle_ = mtapi_task_enqueue(MTAPI_TASK_ID_NONE, queue, handle_ = mtapi_task_enqueue(MTAPI_TASK_ID_NONE, queue,
...@@ -157,18 +153,17 @@ Task::Task( ...@@ -157,18 +153,17 @@ Task::Task(
Task::Task( Task::Task(
Action action, Action action,
mtapi_queue_hndl_t queue, mtapi_queue_hndl_t queue,
mtapi_group_hndl_t group, mtapi_group_hndl_t group) {
mtapi_uint_t priority) {
mtapi_status_t status; mtapi_status_t status;
mtapi_task_attributes_t attr; mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity(); ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status); mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status); &policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status); &policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
Action* holder = embb::base::Allocation::New<Action>(action); Action* holder = embb::base::Allocation::New<Action>(action);
handle_ = mtapi_task_enqueue(MTAPI_TASK_ID_NONE, queue, handle_ = mtapi_task_enqueue(MTAPI_TASK_ID_NONE, queue,
...@@ -183,18 +178,17 @@ Task::Task( ...@@ -183,18 +178,17 @@ Task::Task(
mtapi_task_id_t id, mtapi_task_id_t id,
Action action, Action action,
mtapi_queue_hndl_t queue, mtapi_queue_hndl_t queue,
mtapi_group_hndl_t group, mtapi_group_hndl_t group) {
mtapi_uint_t priority) {
mtapi_status_t status; mtapi_status_t status;
mtapi_task_attributes_t attr; mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity(); ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status); mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status); &policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status); &policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
Action* holder = embb::base::Allocation::New<Action>(action); Action* holder = embb::base::Allocation::New<Action>(action);
void * idptr = MTAPI_NULL; void * idptr = MTAPI_NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment