Commit 49c254b4 by Marcus Winter

moved ExecutionPolicy from algorithms to mtapi_cpp, removed Affinity

parent 650dec9d
......@@ -34,7 +34,6 @@
*/
#include <embb/algorithms/count.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/algorithms/for_each.h>
#include <embb/algorithms/identity.h>
#include <embb/algorithms/invoke.h>
......
......@@ -27,7 +27,8 @@
#ifndef 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 algorithms {
......@@ -70,7 +71,7 @@ typename std::iterator_traits<RAI>::difference_type Count(
const ValueType& value,
/**< [IN] Value that the elements in the range are compared to using
\c operator== */
const ExecutionPolicy& policy = ExecutionPolicy(),
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the counting algorithm */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
......@@ -110,7 +111,7 @@ typename std::iterator_traits<RAI>::difference_type CountIf(
ComparisonFunction comparison,
/**< [IN] Unary predicate used to test the elements in the range. Elements for
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 */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
......@@ -124,6 +125,18 @@ typename std::iterator_traits<RAI>::difference_type CountIf(
#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.
*/
template<typename RAI, typename ValueType>
......@@ -132,7 +145,7 @@ typename std::iterator_traits<RAI>::difference_type Count(
RAI last,
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(
RAI first,
RAI last,
const ValueType& value,
const ExecutionPolicy& policy
const embb::mtapi::ExecutionPolicy& policy
) {
return Count(first, last, value, policy, 0);
}
......@@ -151,12 +164,12 @@ typename std::iterator_traits<RAI>::difference_type Count(
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ValueType>
typename std::iterator_traits<RAI>::difference_type Count(
template<typename RAI, typename ComparisonFunction>
typename std::iterator_traits<RAI>::difference_type CountIf(
RAI first,
RAI last,
const ValueType& value,
const ExecutionPolicy& policy,
ComparisonFunction comparison,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
......@@ -169,7 +182,7 @@ typename std::iterator_traits<RAI>::difference_type CountIf(
RAI last,
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(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy
const embb::mtapi::ExecutionPolicy& policy
) {
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
/**
......
......@@ -27,7 +27,7 @@
#ifndef 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 algorithms {
......@@ -67,7 +67,7 @@ void ForEach(
range */
Function unary,
/**< [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 */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
......@@ -81,16 +81,16 @@ void ForEach(
#else // DOXYGEN
/**
* Overload of above described Doxygen dummy with less arguments.
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename Function>
void ForEach(
RAI first,
RAI last,
Function unary
) {
ForEach(first, last, unary, ExecutionPolicy(), 0);
}
Function unary,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy with less arguments.
......@@ -99,23 +99,23 @@ template<typename RAI, typename Function>
void ForEach(
RAI first,
RAI last,
Function unary,
const ExecutionPolicy& policy
Function unary
) {
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>
void ForEach(
RAI first,
RAI last,
Function unary,
const ExecutionPolicy& policy,
size_t block_size
);
const embb::mtapi::ExecutionPolicy& policy
) {
ForEach(first, last, unary, policy, 0);
}
#endif // else DOXYGEN
......
......@@ -80,7 +80,7 @@ class FunctionComparisonFunction{
template<typename RAI, typename ValueType>
typename std::iterator_traits<RAI>::difference_type
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;
return Reduce(first, last, Difference(0), std::plus<Difference>(),
internal::ValueComparisonFunction<ValueType>(value), policy,
......@@ -90,7 +90,7 @@ typename std::iterator_traits<RAI>::difference_type
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) {
const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
typedef typename std::iterator_traits<RAI>::difference_type Difference;
return Reduce(first, last, Difference(0), std::plus<Difference>(),
internal::FunctionComparisonFunction<ComparisonFunction>
......
......@@ -46,7 +46,7 @@ class ForEachFunctor {
* Constructs a for-each functor with arguments.
*/
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),
block_size_(block_size) {
}
......@@ -68,10 +68,10 @@ class ForEachFunctor {
mtapi::Node& node = mtapi::Node::GetInstance();
mtapi::Task taskL = node.Spawn(mtapi::Action(base::MakeFunction(
functorL, &ForEachFunctor<RAI, Function>::Action),
policy_.GetAffinity()), policy_.GetPriority());
policy_));
mtapi::Task taskR = node.Spawn(mtapi::Action(base::MakeFunction(
functorR, &ForEachFunctor<RAI, Function>::Action),
policy_.GetAffinity()), policy_.GetPriority());
policy_));
taskL.Wait(MTAPI_INFINITE);
taskR.Wait(MTAPI_INFINITE);
}
......@@ -81,7 +81,7 @@ class ForEachFunctor {
RAI first_;
RAI last_;
Function unary_;
const ExecutionPolicy& policy_;
const embb::mtapi::ExecutionPolicy& policy_;
size_t block_size_;
/**
......@@ -92,7 +92,7 @@ class ForEachFunctor {
template<typename RAI, typename Function>
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;
difference_type distance = std::distance(first, last);
assert(distance > 0);
......@@ -113,13 +113,13 @@ void ForEachRecursive(RAI first, RAI last, Function unary,
mtapi::Task task = node.Spawn(mtapi::Action(
base::MakeFunction(functor,
&ForEachFunctor<RAI, Function>::Action),
policy.GetAffinity()), policy.GetPriority());
policy));
task.Wait(MTAPI_INFINITE);
}
template<typename RAI, typename Function>
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) {
return ForEachRecursive(first, last, unary, policy, block_size);
}
......@@ -127,8 +127,8 @@ void ForEachIteratorCheck(RAI first, RAI last, Function unary,
} // namespace internal
template<typename RAI, typename Function>
void ForEach(RAI first, RAI last, Function unary, const ExecutionPolicy& policy,
size_t block_size) {
void ForEach(RAI first, RAI last, Function unary,
const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
typename std::iterator_traits<RAI>::iterator_category category;
internal::ForEachIteratorCheck(first, last, unary, policy, block_size,
category);
......
......@@ -49,7 +49,7 @@ class MergeSortFunctor {
typedef typename std::iterator_traits<RAI>::value_type value_type;
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)
: first_(first), last_(last), temp_first_(temporary_first),
comparison_(comparison), policy_(policy), block_size_(block_size),
......@@ -82,10 +82,10 @@ class MergeSortFunctor {
mtapi::Node& node = mtapi::Node::GetInstance();
mtapi::Task taskL = node.Spawn(mtapi::Action(base::MakeFunction(functorL,
&MergeSortFunctor<RAI, RAITemp, ComparisonFunction>::Action),
policy_.GetAffinity()), policy_.GetPriority());
policy_));
mtapi::Task taskR = node.Spawn(mtapi::Action(base::MakeFunction(functorR,
&MergeSortFunctor<RAI, RAITemp, ComparisonFunction>::Action),
policy_.GetAffinity()), policy_.GetPriority());
policy_));
taskL.Wait(MTAPI_INFINITE);
taskR.Wait(MTAPI_INFINITE);
}
......@@ -118,7 +118,7 @@ class MergeSortFunctor {
RAI last_;
RAITemp temp_first_;
ComparisonFunction comparison_;
const ExecutionPolicy &policy_;
const embb::mtapi::ExecutionPolicy& policy_;
size_t block_size_;
const RAI& global_first_;
int depth_;
......@@ -162,7 +162,7 @@ void MergeSort(
RAI last,
RAITemp temporary_first,
ComparisonFunction comparison,
const ExecutionPolicy& policy,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
) {
typedef typename std::iterator_traits<RAI>::difference_type difference_type;
......@@ -184,7 +184,7 @@ void MergeSort(
first, last, temporary_first, comparison, policy, block_size, first, 0);
mtapi::Task task = node.Spawn(mtapi::Action(base::MakeFunction(functor,
&internal::MergeSortFunctor<RAI, RAITemp, ComparisonFunction>::Action),
policy.GetAffinity()), policy.GetPriority());
policy));
task.Wait(MTAPI_INFINITE);
}
......
......@@ -48,7 +48,7 @@ class QuickSortFunctor {
* Constructs a functor.
*/
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),
block_size_(block_size) {
}
......@@ -87,7 +87,7 @@ class QuickSortFunctor {
RAI first_;
RAI last_;
ComparisonFunction comparison_;
const ExecutionPolicy& policy_;
const embb::mtapi::ExecutionPolicy& policy_;
size_t block_size_;
typedef typename std::iterator_traits<RAI>::difference_type Difference;
......@@ -190,7 +190,7 @@ class QuickSortFunctor {
template <typename RAI, typename ComparisonFunction>
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();
typename std::iterator_traits<RAI>::difference_type distance = last - first;
assert(distance > 0);
......
......@@ -45,7 +45,7 @@ class ReduceFunctor {
ReduceFunctor(RAI first, RAI last, ReturnType neutral,
ReductionFunction reduction,
TransformationFunction transformation,
const ExecutionPolicy &policy, size_t block_size,
const embb::mtapi::ExecutionPolicy &policy, size_t block_size,
ReturnType& result)
:
first_(first), last_(last), neutral_(neutral), reduction_(reduction),
......@@ -78,11 +78,9 @@ class ReduceFunctor {
block_size_, result_r);
mtapi::Node& node = mtapi::Node::GetInstance();
mtapi::Task task_l = node.Spawn(mtapi::Action(base::MakeFunction(
functor_l, &ReduceFunctor::Action), policy_.GetAffinity()),
policy_.GetPriority());
functor_l, &ReduceFunctor::Action), policy_));
mtapi::Task task_r = node.Spawn(mtapi::Action(base::MakeFunction(
functor_r, &ReduceFunctor::Action), policy_.GetAffinity()),
policy_.GetPriority());
functor_r, &ReduceFunctor::Action), policy_));
task_l.Wait(MTAPI_INFINITE);
task_r.Wait(MTAPI_INFINITE);
result_ = reduction_(result_l, result_r);
......@@ -95,7 +93,7 @@ class ReduceFunctor {
ReturnType neutral_;
ReductionFunction reduction_;
TransformationFunction transformation_;
const ExecutionPolicy& policy_;
const embb::mtapi::ExecutionPolicy& policy_;
size_t block_size_;
ReturnType& result_;
......@@ -108,7 +106,8 @@ template<typename RAI, typename ReturnType, typename ReductionFunction,
ReturnType ReduceRecursive(RAI first, RAI last, ReturnType neutral,
ReductionFunction reduction,
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;
difference_type distance = std::distance(first, last);
assert(distance > 0);
......@@ -132,7 +131,7 @@ ReturnType ReduceRecursive(RAI first, RAI last, ReturnType neutral,
Functor functor(first, last, neutral, reduction, transformation, policy,
used_block_size, result);
mtapi::Task task = node.Spawn(mtapi::Action(base::MakeFunction(
functor, &Functor::Action), policy.GetAffinity()), policy.GetPriority());
functor, &Functor::Action), policy));
task.Wait(MTAPI_INFINITE);
return result;
}
......@@ -142,7 +141,8 @@ template<typename RAI, typename TransformationFunction,
ReturnType ReduceIteratorCheck(RAI first, RAI last, ReductionFunction reduction,
TransformationFunction transformation,
ReturnType neutral,
const ExecutionPolicy& policy, size_t block_size,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size,
std::random_access_iterator_tag) {
return ReduceRecursive(first, last, neutral, reduction, transformation,
policy, block_size);
......@@ -155,7 +155,8 @@ template<typename RAI, typename ReturnType, typename ReductionFunction,
ReturnType Reduce(RAI first, RAI last, ReturnType neutral,
ReductionFunction reduction,
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;
return internal::ReduceIteratorCheck(first, last, reduction, transformation,
neutral, policy, block_size, category);
......
......@@ -30,7 +30,7 @@
#include <cassert>
#include <embb/base/exceptions.h>
#include <embb/mtapi/mtapi.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <embb/algorithms/internal/partition.h>
namespace embb {
......@@ -44,7 +44,7 @@ class ScanFunctor {
ScanFunctor(RAIIn first, RAIIn last, RAIOut output_iterator,
ReturnType neutral, ScanFunction scan,
TransformationFunction transformation,
const ExecutionPolicy& policy,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size, ReturnType* tree_values, size_t node_id,
bool going_down)
: policy_(policy), first_(first), last_(last),
......@@ -104,12 +104,10 @@ class ScanFunctor {
mtapi::Node& node = mtapi::Node::GetInstance();
mtapi::Task task_l = node.Spawn(mtapi::Action(base::MakeFunction(
functor_l, &ScanFunctor::Action),
policy_.GetAffinity()),
policy_.GetPriority());
policy_));
mtapi::Task task_r = node.Spawn(mtapi::Action(base::MakeFunction(
functor_r, &ScanFunctor::Action),
policy_.GetAffinity()),
policy_.GetPriority());
policy_));
task_l.Wait(MTAPI_INFINITE);
task_r.Wait(MTAPI_INFINITE);
SetTreeValue(scan_(functor_l.GetTreeValue(), functor_r.GetTreeValue()));
......@@ -125,7 +123,7 @@ class ScanFunctor {
}
private:
const ExecutionPolicy& policy_;
const embb::mtapi::ExecutionPolicy& policy_;
RAIIn first_;
RAIIn last_;
RAIOut output_iterator_;
......@@ -162,7 +160,8 @@ typename ScanFunction, typename TransformationFunction>
void ScanIteratorCheck(RAIIn first, RAIIn last, RAIOut output_iterator,
ReturnType neutral, ScanFunction scan,
TransformationFunction transformation,
const ExecutionPolicy& policy, size_t block_size,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size,
std::random_access_iterator_tag) {
typedef typename std::iterator_traits<RAIIn>::difference_type difference_type;
difference_type distance = std::distance(first, last);
......@@ -191,7 +190,7 @@ void ScanIteratorCheck(RAIIn first, RAIIn last, RAIOut output_iterator,
true);
mtapi::Task task_down = node.Spawn(mtapi::Action(base::MakeFunction(
functor_down, &Functor::Action),
policy.GetAffinity()), policy.GetPriority());
policy));
task_down.Wait(MTAPI_INFINITE);
// 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,
transformation, policy, used_block_size, values, 0, false);
mtapi::Task task_up = node.Spawn(mtapi::Action(base::MakeFunction(
functor_up, &Functor::Action),
policy.GetAffinity()), policy.GetPriority());
policy));
task_up.Wait(MTAPI_INFINITE);
}
......@@ -209,7 +208,7 @@ template<typename RAIIn, typename RAIOut, typename ReturnType,
typename ScanFunction, typename TransformationFunction>
void Scan(RAIIn first, RAIIn last, RAIOut output_iterator, ReturnType neutral,
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;
internal::ScanIteratorCheck(first, last, output_iterator, neutral,
scan, transformation, policy, block_size, category());
......
......@@ -28,7 +28,7 @@
#define EMBB_ALGORITHMS_INVOKE_H_
#include <embb/base/function.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/mtapi.h>
namespace embb {
namespace algorithms {
......@@ -74,7 +74,7 @@ void Invoke(
Function1 func1,
/**< [in] Function to invoke */
...,
const ExecutionPolicy & policy /**< [in] ExecutionPolicy to use */
const embb::mtapi::ExecutionPolicy & policy /**< [in] ExecutionPolicy to use */
);
#else // DOXYGEN
......@@ -92,11 +92,11 @@ class TaskWrapper {
*/
explicit TaskWrapper(
Function function,
const ExecutionPolicy& policy)
const embb::mtapi::ExecutionPolicy& policy)
: function_(function), task_() {
mtapi::Action action(embb::base::MakeFunction(*this, &TaskWrapper::Run),
policy.GetAffinity());
task_ = mtapi::Node::GetInstance().Spawn(action, policy.GetPriority());
policy);
task_ = mtapi::Node::GetInstance().Spawn(action);
}
/**
......@@ -118,75 +118,104 @@ class TaskWrapper {
template<typename Function1>
void Invoke(
Function1 func1) {
Invoke(func1, ExecutionPolicy());
Function1 func1,
const embb::mtapi::ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
}
template<typename Function1, typename Function2>
void Invoke(
Function1 func1,
Function2 func2) {
Invoke(func1, func2, ExecutionPolicy());
Function2 func2,
const embb::mtapi::ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
}
template<typename Function1, typename Function2, typename Function3>
void Invoke(
Function1 func1,
Function2 func2,
Function3 func3) {
Invoke(func1, func2, func3, ExecutionPolicy());
Function3 func3,
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,
typename Function4>
void Invoke(
void Invoke(
Function1 func1,
Function2 func2,
Function3 func3,
Function4 func4) {
Invoke(func1, func2, func3, func4, ExecutionPolicy());
Function4 func4,
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,
typename Function4, typename Function5>
void Invoke(
void Invoke(
Function1 func1,
Function2 func2,
Function3 func3,
Function4 func4,
Function5 func5) {
Invoke(func1, func2, func3, func4, func5, ExecutionPolicy());
Function5 func5,
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,
typename Function4, typename Function5, typename Function6>
void Invoke(
void Invoke(
Function1 func1,
Function2 func2,
Function3 func3,
Function4 func4,
Function5 func5,
Function6 func6) {
Invoke(func1, func2, func3, func4, func5, func6, ExecutionPolicy());
Function6 func6,
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,
typename Function4, typename Function5, typename Function6,
typename Function7>
void Invoke(
void Invoke(
Function1 func1,
Function2 func2,
Function3 func3,
Function4 func4,
Function5 func5,
Function6 func6,
Function7 func7) {
Invoke(func1, func2, func3, func4, func5, func6, func7, ExecutionPolicy());
Function7 func7,
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,
typename Function4, typename Function5, typename Function6,
typename Function7, typename Function8>
void Invoke(
void Invoke(
Function1 func1,
Function2 func2,
Function3 func3,
......@@ -194,15 +223,22 @@ void Invoke(
Function5 func5,
Function6 func6,
Function7 func7,
Function8 func8) {
Invoke(func1, func2, func3, func4, func5, func6, func7, func8,
ExecutionPolicy());
Function8 func8,
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);
internal::TaskWrapper<Function8> wrap8(func8, policy);
}
template<typename Function1, typename Function2, typename Function3,
typename Function4, typename Function5, typename Function6,
typename Function7, typename Function8, typename Function9>
void Invoke(
void Invoke(
Function1 func1,
Function2 func2,
Function3 func3,
......@@ -211,16 +247,24 @@ void Invoke(
Function6 func6,
Function7 func7,
Function8 func8,
Function9 func9) {
Invoke(func1, func2, func3, func4, func5, func6, func7, func8, func9,
ExecutionPolicy());
Function9 func9,
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);
internal::TaskWrapper<Function8> wrap8(func8, policy);
internal::TaskWrapper<Function9> wrap9(func9, policy);
}
template<typename Function1, typename Function2, typename Function3,
typename Function4, typename Function5, typename Function6,
typename Function7, typename Function8, typename Function9,
typename Function10>
void Invoke(
void Invoke(
Function1 func1,
Function2 func2,
Function3 func3,
......@@ -230,36 +274,38 @@ void Invoke(
Function7 func7,
Function8 func8,
Function9 func9,
Function10 func10) {
Invoke(func1, func2, func3, func4, func5, func6, func7, func8, func9, func10,
ExecutionPolicy());
Function10 func10,
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);
internal::TaskWrapper<Function8> wrap8(func8, policy);
internal::TaskWrapper<Function9> wrap9(func9, policy);
internal::TaskWrapper<Function10> wrap10(func10, policy);
}
template<typename Function1>
void Invoke(
Function1 func1,
const ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
Function1 func1) {
Invoke(func1, embb::mtapi::ExecutionPolicy());
}
template<typename Function1, typename Function2>
void Invoke(
Function1 func1,
Function2 func2,
const ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
Function2 func2) {
Invoke(func1, func2, embb::mtapi::ExecutionPolicy());
}
template<typename Function1, typename Function2, typename Function3>
void Invoke(
Function1 func1,
Function2 func2,
Function3 func3,
const ExecutionPolicy& policy) {
internal::TaskWrapper<Function1> wrap1(func1, policy);
internal::TaskWrapper<Function2> wrap2(func2, policy);
internal::TaskWrapper<Function3> wrap3(func3, policy);
Function3 func3) {
Invoke(func1, func2, func3, embb::mtapi::ExecutionPolicy());
}
template<typename Function1, typename Function2, typename Function3,
......@@ -268,12 +314,8 @@ void Invoke(
Function1 func1,
Function2 func2,
Function3 func3,
Function4 func4,
const 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);
Function4 func4) {
Invoke(func1, func2, func3, func4, embb::mtapi::ExecutionPolicy());
}
template<typename Function1, typename Function2, typename Function3,
......@@ -283,13 +325,8 @@ void Invoke(
Function2 func2,
Function3 func3,
Function4 func4,
Function5 func5,
const 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);
Function5 func5) {
Invoke(func1, func2, func3, func4, func5, embb::mtapi::ExecutionPolicy());
}
template<typename Function1, typename Function2, typename Function3,
......@@ -300,14 +337,9 @@ void Invoke(
Function3 func3,
Function4 func4,
Function5 func5,
Function6 func6,
const 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);
Function6 func6) {
Invoke(func1, func2, func3, func4, func5, func6,
embb::mtapi::ExecutionPolicy());
}
template<typename Function1, typename Function2, typename Function3,
......@@ -320,15 +352,9 @@ void Invoke(
Function4 func4,
Function5 func5,
Function6 func6,
Function7 func7,
const 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);
Function7 func7) {
Invoke(func1, func2, func3, func4, func5, func6, func7,
embb::mtapi::ExecutionPolicy());
}
template<typename Function1, typename Function2, typename Function3,
......@@ -342,16 +368,9 @@ void Invoke(
Function5 func5,
Function6 func6,
Function7 func7,
Function8 func8,
const 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);
internal::TaskWrapper<Function8> wrap8(func8, policy);
Function8 func8) {
Invoke(func1, func2, func3, func4, func5, func6, func7, func8,
embb::mtapi::ExecutionPolicy());
}
template<typename Function1, typename Function2, typename Function3,
......@@ -366,17 +385,9 @@ void Invoke(
Function6 func6,
Function7 func7,
Function8 func8,
Function9 func9,
const 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);
internal::TaskWrapper<Function8> wrap8(func8, policy);
internal::TaskWrapper<Function9> wrap9(func9, policy);
Function9 func9) {
Invoke(func1, func2, func3, func4, func5, func6, func7, func8, func9,
embb::mtapi::ExecutionPolicy());
}
template<typename Function1, typename Function2, typename Function3,
......@@ -393,18 +404,9 @@ void Invoke(
Function7 func7,
Function8 func8,
Function9 func9,
Function10 func10,
const 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);
internal::TaskWrapper<Function8> wrap8(func8, policy);
internal::TaskWrapper<Function9> wrap9(func9, policy);
internal::TaskWrapper<Function10> wrap10(func10, policy);
Function10 func10) {
Invoke(func1, func2, func3, func4, func5, func6, func7, func8, func9, func10,
embb::mtapi::ExecutionPolicy());
}
#endif // else DOXYGEN
......
......@@ -28,7 +28,7 @@
#define EMBB_ALGORITHMS_MERGE_SORT_H_
#include <functional>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <embb/base/memory_allocation.h>
namespace embb {
......@@ -77,7 +77,7 @@ void MergeSortAllocate(
\c a appears before an element \c b in the sorted range if
<tt>comparison(a, b) == true</tt>. The default value uses the
less-than relation. */
const ExecutionPolicy& policy = ExecutionPolicy(),
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the merge sort algorithm */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
......@@ -127,7 +127,7 @@ void MergeSort(
\c a appears before an element \c b in the sorted range if
<tt>comparison(a, b) == true</tt>. The default value uses the
less-than relation. */
const ExecutionPolicy& policy = ExecutionPolicy(),
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the merge sort algorithm */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
......@@ -141,28 +141,49 @@ void MergeSort(
#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(
RAI first,
RAI last
RAI last,
ComparisonFunction comparison,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
) {
MergeSortAllocate(first, last,
std::less<typename std::iterator_traits<RAI>::value_type>(),
ExecutionPolicy(), 0);
typedef base::Allocation Alloc;
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);
}
/**
* Overload of above described Doxygen dummy with less arguments.
*/
template<typename RAI, typename ComparisonFunction>
template<typename RAI>
void MergeSortAllocate(
RAI first,
RAI last,
ComparisonFunction comparison
RAI last
) {
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>
void MergeSortAllocate(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy
ComparisonFunction comparison
) {
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>
void MergeSortAllocate(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy,
size_t block_size
const embb::mtapi::ExecutionPolicy& policy
) {
typedef base::Allocation Alloc;
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);
MergeSortAllocate(first, last, comparison, policy, 0);
}
/**
......@@ -209,7 +222,7 @@ void MergeSort(
) {
MergeSort(first, last, temporary_first,
std::less<typename std::iterator_traits<RAI>::value_type>(),
ExecutionPolicy(), 0);
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -222,7 +235,8 @@ void MergeSort(
RAITemp temporary_first,
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(
RAI last,
RAITemp temporary_first,
ComparisonFunction comparison,
const ExecutionPolicy& policy
const embb::mtapi::ExecutionPolicy& policy
) {
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
/**
......
......@@ -28,7 +28,7 @@
#define EMBB_ALGORITHMS_QUICK_SORT_H_
#include <functional>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
namespace embb {
namespace algorithms {
......@@ -72,7 +72,7 @@ void QuickSort(
\c a appears before an element \c b in the sorted range if
<tt>comparison(a, b) == true</tt>. The default value uses the
less-than relation. */
const ExecutionPolicy& policy = ExecutionPolicy(),
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the quick sort algorithm */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
......@@ -88,6 +88,18 @@ void QuickSort(
#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.
*/
template <typename RAI>
......@@ -97,7 +109,7 @@ void QuickSort(
) {
QuickSort(first, last,
std::less<typename std::iterator_traits<RAI>::value_type>(),
ExecutionPolicy(), 0);
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -109,7 +121,7 @@ void QuickSort(
RAI last,
ComparisonFunction comparison
) {
QuickSort(first, last, comparison, ExecutionPolicy(), 0);
QuickSort(first, last, comparison, embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -120,23 +132,11 @@ void QuickSort(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy
const embb::mtapi::ExecutionPolicy& policy
) {
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
/**
......
......@@ -27,7 +27,7 @@
#ifndef 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>
namespace embb {
......@@ -89,7 +89,7 @@ ReturnType Reduce(
TransformationFunction transformation = Identity(),
/**< [IN] Transforms the elements of the range before the reduction operation
is applied */
const ExecutionPolicy& policy = ExecutionPolicy(),
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the reduction computation */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
......@@ -103,6 +103,21 @@ ReturnType Reduce(
#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.
*/
template<typename RAI, typename ReturnType, typename ReductionFunction>
......@@ -112,8 +127,8 @@ ReturnType Reduce(
ReturnType neutral,
ReductionFunction reduction
) {
return Reduce(first, last, neutral, reduction, Identity(), ExecutionPolicy(),
0);
return Reduce(first, last, neutral, reduction, Identity(),
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -129,7 +144,7 @@ ReturnType Reduce(
TransformationFunction transformation
) {
return Reduce(first, last, neutral, reduction, transformation,
ExecutionPolicy(), 0);
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -143,26 +158,11 @@ ReturnType Reduce(
ReturnType neutral,
ReductionFunction reduction,
TransformationFunction transformation,
const ExecutionPolicy& policy
const embb::mtapi::ExecutionPolicy& policy
) {
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
/**
......
......@@ -27,7 +27,7 @@
#ifndef 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>
namespace embb {
......@@ -96,7 +96,7 @@ void Scan(
TransformationFunction transformation = Identity(),
/**< [IN] Transforms the elements of the input range before the scan operation
is applied */
const ExecutionPolicy& policy = ExecutionPolicy(),
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the scan computation */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
......@@ -110,36 +110,35 @@ void Scan(
#else // DOXYGEN
/**
* Overload of above described Doxygen dummy with less arguments.
* Overload of above described Doxygen dummy.
*/
template<typename RAIIn, typename RAIOut, typename ReturnType,
typename ScanFunction>
typename ScanFunction, typename TransformationFunction>
void Scan(
RAIIn first,
RAIIn last,
RAIOut output_iterator,
ReturnType neutral,
ScanFunction scan
) {
Scan(first, last, output_iterator, neutral, scan, Identity(),
ExecutionPolicy(), 0);
}
ScanFunction scan,
TransformationFunction transformation,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy with less arguments.
*/
template<typename RAIIn, typename RAIOut, typename ReturnType,
typename ScanFunction, typename TransformationFunction>
typename ScanFunction>
void Scan(
RAIIn first,
RAIIn last,
RAIOut output_iterator,
ReturnType neutral,
ScanFunction scan,
TransformationFunction transformation
ScanFunction scan
) {
Scan(first, last, output_iterator, neutral, scan, transformation,
ExecutionPolicy(), 0);
Scan(first, last, output_iterator, neutral, scan, Identity(),
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -153,14 +152,14 @@ void Scan(
RAIOut output_iterator,
ReturnType neutral,
ScanFunction scan,
TransformationFunction transformation,
const ExecutionPolicy& policy
TransformationFunction transformation
) {
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,
typename ScanFunction, typename TransformationFunction>
......@@ -171,9 +170,10 @@ void Scan(
ReturnType neutral,
ScanFunction scan,
TransformationFunction transformation,
const ExecutionPolicy& policy,
size_t block_size
);
const embb::mtapi::ExecutionPolicy& policy
) {
Scan(first, last, output_iterator, neutral, scan, transformation, policy, 0);
}
#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 @@
#include <count_test.h>
#include <embb/algorithms/count.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <deque>
#include <vector>
#include <functional>
......@@ -122,7 +122,7 @@ void CountTest::TestBlockSizes() {
void CountTest::TestPolicy() {
using embb::algorithms::Count;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
int a[] = { 10, 20, 30, 30, 20, 10, 10, 20, 20, 20 };
std::vector<int> vector(a, a + (sizeof a / sizeof a[0]));
PT_EXPECT_EQ(Count(vector.begin(), vector.end(), 10, ExecutionPolicy()), 3);
......
......@@ -26,7 +26,7 @@
#include <for_each_test.h>
#include <embb/algorithms/for_each.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <vector>
#include <deque>
#include <sstream>
......@@ -166,7 +166,7 @@ void ForEachTest::TestRanges() {
void ForEachTest::TestBlockSizes() {
using embb::algorithms::ForEach;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = 4;
std::vector<int> init(count);
std::vector<int> vector(count);
......@@ -186,7 +186,7 @@ void ForEachTest::TestBlockSizes() {
void ForEachTest::TestPolicy() {
using embb::algorithms::ForEach;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = 4;
std::vector<int> init(count);
std::vector<int> vector(count);
......@@ -221,7 +221,7 @@ void ForEachTest::TestPolicy() {
void ForEachTest::StressTest() {
using embb::algorithms::ForEach;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10;
std::vector<int> large_vector(count);
for (size_t i = 0; i < count; i++) {
......
......@@ -26,7 +26,7 @@
#include <merge_sort_test.h>
#include <embb/algorithms/merge_sort.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <vector>
#include <deque>
#include <sstream>
......@@ -50,7 +50,7 @@ MergeSortTest::MergeSortTest() {
void MergeSortTest::TestDataStructures() {
using embb::algorithms::MergeSortAllocate;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
int array[kCountSize];
std::vector<int> vector(kCountSize);
std::deque<int> deque(kCountSize);
......@@ -75,7 +75,7 @@ void MergeSortTest::TestDataStructures() {
void MergeSortTest::TestFunctionPointers() {
using embb::algorithms::MergeSortAllocate;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
std::vector<int> vector(kCountSize);
for (size_t i = kCountSize - 1; i > 0; i--) {
......@@ -181,7 +181,7 @@ void MergeSortTest::TestRanges() {
void MergeSortTest::TestPolicy() {
using embb::algorithms::MergeSortAllocate;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = 4;
std::vector<int> init(count);
std::vector<int> vector(count);
......
......@@ -26,7 +26,7 @@
#include <quick_sort_test.h>
#include <embb/algorithms/quick_sort.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <vector>
#include <deque>
#include <sstream>
......@@ -54,7 +54,7 @@ QuickSortTest::QuickSortTest() {
void QuickSortTest::TestDataStructures() {
using embb::algorithms::QuickSort;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
int array[kCountSize];
std::vector<int> vector(kCountSize);
......@@ -163,7 +163,7 @@ void QuickSortTest::TestRanges() {
void QuickSortTest::TestBlockSizes() {
using embb::algorithms::QuickSort;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = 4;
std::vector<int> init(count);
......@@ -187,7 +187,7 @@ void QuickSortTest::TestBlockSizes() {
void QuickSortTest::TestPolicy() {
using embb::algorithms::QuickSort;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = 4;
std::vector<int> init(count);
std::vector<int> vector(count);
......
......@@ -26,7 +26,7 @@
#include <reduce_test.h>
#include <embb/algorithms/reduce.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <deque>
#include <vector>
#include <functional>
......@@ -163,7 +163,7 @@ void ReduceTest::TestBlockSizes() {
void ReduceTest::TestPolicy() {
using embb::algorithms::Reduce;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity;
size_t count = 4;
int sum = 0;
......@@ -187,7 +187,7 @@ void ReduceTest::TestPolicy() {
void ReduceTest::StressTest() {
using embb::algorithms::Reduce;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity;
size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10;
std::vector<int> large_vector(count);
......
......@@ -228,7 +228,7 @@ void ScanTest::TestRanges() {
void ScanTest::TestBlockSizes() {
using embb::algorithms::Scan;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity;
size_t count = 4;
std::vector<int> init(count);
......@@ -253,7 +253,7 @@ void ScanTest::TestBlockSizes() {
void ScanTest::TestPolicy() {
using embb::algorithms::Scan;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity;
size_t count = 4;
std::vector<int> init(count);
......@@ -304,7 +304,7 @@ void ScanTest::TestPolicy() {
void ScanTest::StressTest() {
using embb::algorithms::Scan;
using embb::algorithms::Identity;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10;
std::vector<int> large_vector(count);
std::vector<int> large_vector_output(count);
......
......@@ -136,7 +136,7 @@ void ZipIteratorTest::TestZipScan() {
Scan(embb::algorithms::Zip(vectorA.begin(), vectorB.begin()),
embb::algorithms::Zip(vectorA.end(), vectorB.end()),
vectorOut.begin(), 0, std::plus<int>(), DotProductFunctor(),
embb::algorithms::ExecutionPolicy(), 0);
embb::mtapi::ExecutionPolicy(), 0);
long sum = 0;
for (size_t i = 0; i < kCountSize; i++) {
......
......@@ -29,7 +29,7 @@
#include <embb/base/function.h>
#include <embb/mtapi/taskcontext.h>
#include <embb/mtapi/affinity.h>
#include <embb/mtapi/execution_policy.h>
namespace embb {
namespace mtapi {
......@@ -46,7 +46,7 @@ class Action {
*/
Action()
: function_()
, affinity_() {
, execution_policy_() {
// empty
}
......@@ -60,7 +60,7 @@ class Action {
operator() (TaskContext &). */
)
: function_(func)
, affinity_() {
, execution_policy_() {
// empty
}
......@@ -72,10 +72,10 @@ class Action {
Action(
Function func, /**< [in] Anything that provides an
operator() (TaskContext &). */
Affinity affinity /**< [in] Core affinity */
ExecutionPolicy execution_policy /**< [in] Execution policy */
)
: function_(func)
, affinity_(affinity) {
, execution_policy_(execution_policy) {
// empty
}
......@@ -90,17 +90,17 @@ class Action {
}
/**
* Returns the Affinity specified during creation.
* \return The Affinity of the Action
* Returns the ExecutionPolicy specified during creation.
* \return The ExecutionPolicy of the Action
* \waitfree
*/
Affinity GetAffinity() const {
return affinity_;
ExecutionPolicy GetExecutionPolicy() const {
return execution_policy_;
}
private:
embb::base::Function<void, TaskContext &> function_;
Affinity affinity_;
ExecutionPolicy execution_policy_;
};
} // 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 {
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.
* \notthreadsafe
*/
Task Spawn(
mtapi_uint_t priority /**< [in] The priority to use */
ExecutionPolicy execution_policy /**< [in] The execution policy to use */
);
friend class Node;
......@@ -97,8 +97,6 @@ class Continuation {
ContinuationStage * first_;
ContinuationStage * last_;
mtapi_uint_t priority_;
};
} // namespace mtapi
......
......@@ -24,21 +24,20 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef EMBB_ALGORITHMS_EXECUTION_POLICY_H_
#define EMBB_ALGORITHMS_EXECUTION_POLICY_H_
#ifndef EMBB_MTAPI_EXECUTION_POLICY_H_
#define EMBB_MTAPI_EXECUTION_POLICY_H_
#include <embb/mtapi/mtapi.h>
#include <embb/mtapi/affinity.h>
#include <embb/mtapi/c/mtapi.h>
namespace embb {
namespace algorithms {
namespace mtapi {
/**
* Describes the execution policy of a parallel algorithm.
* The execution policy comprises
* - the affinity of tasks to MTAPI worker threads (not CPU cores) and
* - the priority of the spawned tasks.
*
* \ingroup CPP_ALGORITHMS
* \ingroup CPP_MTAPI
*/
class ExecutionPolicy{
public:
......@@ -53,11 +52,11 @@ class ExecutionPolicy{
* Constructs an execution policy with the specified affinity and priority.
*/
ExecutionPolicy(
bool initial_affinity, /**<
[IN] \c true sets the affinity to all worker threads, \c false to no
bool initial_affinity, /**< [in] \c true sets the affinity to
all worker threads, \c false to no
worker threads. */
mtapi_uint_t priority /**<
[IN] Priority for the execution policy. */
mtapi_uint_t priority /**< [in] Priority for the execution
policy. */
);
/**
......@@ -65,8 +64,8 @@ class ExecutionPolicy{
* Sets the affinity to all worker threads.
*/
explicit ExecutionPolicy(
mtapi_uint_t priority /**<
[IN] Priority for the execution policy. */
mtapi_uint_t priority /**< [in] Priority for the execution
policy. */
);
/**
......@@ -74,8 +73,8 @@ class ExecutionPolicy{
* Sets the priority to the default value.
*/
explicit ExecutionPolicy(
bool initial_affinity /**<
[IN] \c true sets the affinity to all worker threads, \c false to no
bool initial_affinity /**< [in] \c true sets the affinity to
all worker threads, \c false to no
worker threads. */
);
......@@ -83,16 +82,14 @@ class ExecutionPolicy{
* Sets affinity to a specific worker thread.
*/
void AddWorker(
mtapi_uint_t worker
/**< [IN] Worker thread index */
mtapi_uint_t worker /**< [in] Worker thread index */
);
/**
* Removes affinity to a specific worker thread.
*/
void RemoveWorker(
mtapi_uint_t worker
/**< [IN] Worker thread index */
mtapi_uint_t worker /**< [in] Worker thread index */
);
/**
......@@ -101,8 +98,7 @@ class ExecutionPolicy{
* \return \c true if affinity is set, otherwise \c false
*/
bool IsSetWorker(
mtapi_uint_t worker
/**< [IN] Worker thread index */
mtapi_uint_t worker /**< [in] Worker thread index */
);
/**
......@@ -110,7 +106,7 @@ class ExecutionPolicy{
*
* \return the affinity
*/
const mtapi::Affinity &GetAffinity() const;
const mtapi_affinity_t &GetAffinity() const;
/** Returns the priority
*
......@@ -118,6 +114,8 @@ class ExecutionPolicy{
*/
mtapi_uint_t GetPriority() const;
friend class Task;
private:
/**
* Default priority.
......@@ -129,14 +127,14 @@ class ExecutionPolicy{
* Task Affinity.
* Maps the affinity of tasks to MTAPI worker threads (not CPU cores).
*/
mtapi::Affinity affinity_;
mtapi_affinity_t affinity_;
/**
* Task Priority.
*/
mtapi_uint_t priority_;
};
} // namespace algorithms
} // namespace mtapi
} // namespace embb
#endif // EMBB_ALGORITHMS_EXECUTION_POLICY_H_
#endif // EMBB_MTAPI_EXECUTION_POLICY_H_
......@@ -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().
* \return A Task identifying the Action to run
* \throws ErrorException if the Task object could not be constructed.
......@@ -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.
* \return The status of the Task that finished execution
* \threadsafe
......
......@@ -42,8 +42,8 @@
#define MTAPI_CPP_AUTOMATIC_NODE_ID 1
#endif
#include <embb/mtapi/execution_policy.h>
#include <embb/mtapi/action.h>
#include <embb/mtapi/affinity.h>
#include <embb/mtapi/continuation.h>
#include <embb/mtapi/group.h>
#include <embb/mtapi/node.h>
......
......@@ -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.
* \return A Continuation chain
* \threadsafe
......
......@@ -80,38 +80,31 @@ class Task {
private:
Task(
Action action,
mtapi_uint_t priority
);
Action action);
Task(
Action action,
mtapi_group_hndl_t group,
mtapi_uint_t priority);
mtapi_group_hndl_t group);
Task(
mtapi_task_id_t id,
Action action,
mtapi_group_hndl_t group,
mtapi_uint_t priority);
mtapi_group_hndl_t group);
Task(
Action action,
mtapi_queue_hndl_t queue,
mtapi_uint_t priority);
mtapi_queue_hndl_t queue);
Task(
Action action,
mtapi_queue_hndl_t queue,
mtapi_group_hndl_t group,
mtapi_uint_t priority);
mtapi_group_hndl_t group);
Task(
mtapi_task_id_t id,
Action action,
mtapi_queue_hndl_t queue,
mtapi_group_hndl_t group,
mtapi_uint_t priority);
mtapi_group_hndl_t group);
mtapi_task_hndl_t handle_;
};
......
......@@ -53,7 +53,7 @@ void Continuation::ExecuteContinuation(TaskContext &) {
mtapi::ContinuationStage * stage = first_;
mtapi::Node & node = mtapi::Node::GetInstance();
while (NULL != stage) {
mtapi::Task task = node.Spawn(stage->action, priority_);
mtapi::Task task = node.Spawn(stage->action);
task.Wait(MTAPI_INFINITE);
stage = stage->next;
}
......@@ -79,15 +79,17 @@ Continuation & Continuation::Then(Action action) {
}
Task Continuation::Spawn() {
return Spawn(0);
return Spawn(ExecutionPolicy());
}
Task Continuation::Spawn(mtapi_uint_t priority) {
priority_ = priority;
Task Continuation::Spawn(ExecutionPolicy execution_policy) {
Node & node = Node::GetInstance();
return node.Spawn(
Action(
embb::base::MakeFunction(*this, &Continuation::ExecuteContinuation),
priority);
ExecutionPolicy(execution_policy)
)
);
}
} // namespace mtapi
......
......@@ -24,15 +24,15 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <cassert>
#include <embb/mtapi/execution_policy.h>
#include <embb/base/exceptions.h>
#include <embb/mtapi/mtapi.h>
#include <cassert>
namespace embb {
namespace mtapi {
Affinity::Affinity() {
ExecutionPolicy::ExecutionPolicy() :
priority_(DefaultPriority) {
#if MTAPI_CPP_AUTOMATIC_INITIALIZE
Node::GetInstance(); // MTAPI has to be initialized
#endif
......@@ -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
Node::GetInstance(); // MTAPI has to be initialized
#endif
mtapi_status_t status;
mtapi_boolean_t aff = initial_affinity ? MTAPI_TRUE : MTAPI_FALSE;
mtapi_affinity_init(&affinity_, aff, &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 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_affinity_set(&affinity_, worker, MTAPI_TRUE, &status);
assert(MTAPI_SUCCESS == status);
}
void Affinity::Remove(mtapi_uint_t worker) {
void ExecutionPolicy::RemoveWorker(mtapi_uint_t worker) {
mtapi_status_t status;
mtapi_affinity_set(&affinity_, worker, MTAPI_FALSE, &status);
assert(MTAPI_SUCCESS == status);
}
bool Affinity::IsSet(mtapi_uint_t worker) {
bool ExecutionPolicy::IsSetWorker(mtapi_uint_t worker) {
mtapi_status_t status;
mtapi_boolean_t aff = mtapi_affinity_get(&affinity_, worker, &status);
assert(MTAPI_SUCCESS == status);
return MTAPI_TRUE == aff;
}
const mtapi_affinity_t &ExecutionPolicy::GetAffinity() const {
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() {
}
Task Group::Spawn(Action action) {
return Spawn(action, 0);
}
Task Group::Spawn(Action action, mtapi_uint_t priority) {
return Task(action, handle_, priority);
return Task(action, handle_);
}
Task Group::Spawn(mtapi_task_id_t id, Action action) {
return Spawn(id, action, 0);
}
Task Group::Spawn(mtapi_task_id_t id, Action action, mtapi_uint_t priority) {
return Task(id, action, handle_, priority);
return Task(id, action, handle_);
}
mtapi_status_t Group::WaitAny(mtapi_timeout_t timeout) {
......
......@@ -259,11 +259,7 @@ void Node::DestroyQueue(Queue & queue) {
}
Task Node::Spawn(Action action) {
return Spawn(action, 0);
}
Task Node::Spawn(Action action, mtapi_uint_t priority) {
return Task(action, priority);
return Task(action);
}
Continuation Node::First(Action action) {
......
......@@ -79,11 +79,11 @@ void Queue::Disable() {
}
Task Queue::Spawn(Action action) {
return Task(action, handle_, 0);
return Task(action, handle_);
}
Task Queue::Spawn(Group const * group, Action action) {
return Task(action, handle_, group->handle_, 0);
return Task(action, handle_, group->handle_);
}
} // namespace mtapi
......
......@@ -45,18 +45,17 @@ Task::Task(Task const & task)
}
Task::Task(
Action action,
mtapi_uint_t priority) {
Action action) {
mtapi_status_t status;
mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity();
ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status);
&policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status);
&policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status);
mtapi_domain_t domain_id = mtapi_domain_id_get(&status);
assert(MTAPI_SUCCESS == status);
......@@ -73,18 +72,17 @@ Task::Task(
Task::Task(
Action action,
mtapi_group_hndl_t group,
mtapi_uint_t priority) {
mtapi_group_hndl_t group) {
mtapi_status_t status;
mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity();
ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status);
&policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status);
&policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status);
mtapi_domain_t domain_id = mtapi_domain_id_get(&status);
assert(MTAPI_SUCCESS == status);
......@@ -102,18 +100,17 @@ Task::Task(
Task::Task(
mtapi_task_id_t id,
Action action,
mtapi_group_hndl_t group,
mtapi_uint_t priority) {
mtapi_group_hndl_t group) {
mtapi_status_t status;
mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity();
ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status);
&policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status);
&policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status);
mtapi_domain_t domain_id = mtapi_domain_id_get(&status);
assert(MTAPI_SUCCESS == status);
......@@ -132,18 +129,17 @@ Task::Task(
Task::Task(
Action action,
mtapi_queue_hndl_t queue,
mtapi_uint_t priority) {
mtapi_queue_hndl_t queue) {
mtapi_status_t status;
mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity();
ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status);
&policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status);
&policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status);
Action* holder = embb::base::Allocation::New<Action>(action);
handle_ = mtapi_task_enqueue(MTAPI_TASK_ID_NONE, queue,
......@@ -157,18 +153,17 @@ Task::Task(
Task::Task(
Action action,
mtapi_queue_hndl_t queue,
mtapi_group_hndl_t group,
mtapi_uint_t priority) {
mtapi_group_hndl_t group) {
mtapi_status_t status;
mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity();
ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status);
&policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status);
&policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status);
Action* holder = embb::base::Allocation::New<Action>(action);
handle_ = mtapi_task_enqueue(MTAPI_TASK_ID_NONE, queue,
......@@ -183,18 +178,17 @@ Task::Task(
mtapi_task_id_t id,
Action action,
mtapi_queue_hndl_t queue,
mtapi_group_hndl_t group,
mtapi_uint_t priority) {
mtapi_group_hndl_t group) {
mtapi_status_t status;
mtapi_task_attributes_t attr;
Affinity affinity = action.GetAffinity();
ExecutionPolicy policy = action.GetExecutionPolicy();
mtapi_taskattr_init(&attr, &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY,
&priority, sizeof(priority), &status);
&policy.priority_, sizeof(policy.priority_), &status);
assert(MTAPI_SUCCESS == status);
mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY,
&affinity.affinity_, sizeof(affinity.affinity_), &status);
&policy.affinity_, sizeof(policy.affinity_), &status);
assert(MTAPI_SUCCESS == status);
Action* holder = embb::base::Allocation::New<Action>(action);
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