pfor/src/pfor/traits.h

65 lines
1.8 KiB
C++

#ifndef PFOR_PFOR_TRAITS_H
#define PFOR_PFOR_TRAITS_H
#include "algorithm.h"
#include "clusters.h"
#include "expression/traits.h"
#include "range.h"
namespace pfor {
/**
* @brief tests if the given expression can be run in parallel
*
* @param[in] Range ignored range (runtime information)
* @param[in] E the expression
*
* @return true if the expression can be run in parallel
*/
template<
typename Range, typename E,
std::enable_if_t<expr::isExpression<E>>* = nullptr
>
bool parallelTest(Range const&, E const&) {
using Expressions = expr::SplitComma<E>;
return accumulate<Parallelizable, Expressions>(true, std::logical_and<bool>{});
}
/**
* @brief tests if the given expression can be run in parallel given a range
*
* @param[in] begin the initial value of the index
* @param[in] step the step of the index
* @param[in] E the expression
*
* @return true if the expression can be run in parallel given (begin, step)
*/
template<
typename E, typename RT, index::Value begin, index::Value step,
std::enable_if_t<expr::isExpression<E>>* = nullptr
>
bool parallelTest(TRangeCT<RT, begin, step> const&, E const&) {
using Expressions = PackForEach<expr::SplitComma<E>, GenSubstituteVariableInExpression<step, begin>::template type>;
return accumulate<Parallelizable, Expressions>(true, std::logical_and<bool>{});
}
/**
* @brief tests if the given expressions can be run in parallel, possibly given a range
*
* @param[in] Range possibly compile-time known information about the index values
* @param[in] es a pack of expressions
*
* @return true if merged expressions can be run in parallel
*/
template<
typename Range, typename... Es,
std::enable_if_t<expr::allExpression<Es...>>* = nullptr
>
bool parallelTest(Range const& range, Es const&... es) {
return parallelTest(range, commaMerger(es...));
}
}
#endif