92 lines
2.6 KiB
C++
92 lines
2.6 KiB
C++
#ifndef ALSK_ALSK_IMPL_BONE_FARMSEL_H
|
|
#define ALSK_ALSK_IMPL_BONE_FARMSEL_H
|
|
|
|
#include <cmath>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
#include "../boneimplbase.h"
|
|
#include "../../skeleton/bone/farmsel.h"
|
|
|
|
namespace alsk {
|
|
|
|
/**
|
|
* @brief FarmSel implementation for sequential execution
|
|
*/
|
|
/*
|
|
template<typename R, typename... Args, typename... Tasks, typename Executor, typename State>
|
|
struct Impl<FarmSel<R(Args...), Tasks...>, tag::Sequential, Executor, State>:
|
|
BoneImplBase<FarmSel<R(Args...), Tasks...>, tag::Sequential, Executor, State>
|
|
{
|
|
using This = Impl;
|
|
using Task = Execute<typename This::Skeleton::TaskLinks>;
|
|
using Select = Execute<typename This::Skeleton::SelectLinks>;
|
|
|
|
typename This::Skeleton skeleton;
|
|
typename This::Executor executor;
|
|
typename This::StateRef state;
|
|
|
|
constexpr Impl() = default;
|
|
template<typename S>
|
|
constexpr Impl(S&& skeleton, Executor executor, State& state):
|
|
skeleton{std::forward<S>(skeleton)},
|
|
executor{executor},
|
|
state{state}
|
|
{}
|
|
|
|
constexpr typename This::Return operator()(Args... args) {
|
|
using Value = typename This::Return;
|
|
|
|
auto tupleP = std::forward_as_tuple(args...);
|
|
|
|
Value best{};
|
|
|
|
if(skeleton.n)
|
|
best = executor.template execute<Task>(*this, skeleton.task, tupleP, std::tuple<>{});
|
|
for(std::size_t i = 1; i < skeleton.n; ++i) {
|
|
Value current = executor.template execute<Task>(*this, skeleton.task, tupleP, std::tuple<>{});
|
|
best = executor.template execute<Select>(
|
|
*this, skeleton.select, tupleP, std::tuple<>{}, std::move(current), std::move(best)
|
|
);
|
|
}
|
|
|
|
return best;
|
|
}
|
|
};
|
|
*/
|
|
|
|
/**
|
|
* @brief FarmSel implementation for parallel execution
|
|
*/
|
|
template<typename R, typename... Args, typename... Tasks, typename Tag, typename Executor, typename State>
|
|
struct Impl<FarmSel<R(Args...), Tasks...>, Tag, Executor, State>:
|
|
BoneImplBase<FarmSel<R(Args...), Tasks...>, Tag, Executor, State>
|
|
{
|
|
using This = Impl;
|
|
using Task = Execute<typename This::Skeleton::TaskLinks>;
|
|
using Select = Execute<typename This::Skeleton::SelectLinks>;
|
|
|
|
typename This::Skeleton skeleton;
|
|
typename This::Executor executor;
|
|
typename This::StateRef state;
|
|
|
|
constexpr Impl() = default;
|
|
template<typename S>
|
|
constexpr Impl(S&& skeleton, Executor executor, State& state):
|
|
skeleton{std::forward<S>(skeleton)},
|
|
executor{executor},
|
|
state{state}
|
|
{}
|
|
|
|
constexpr typename This::Return operator()(Args... args) {
|
|
auto tupleP = std::forward_as_tuple(args...);
|
|
return executor.template executeParallelAccumulate<typename This::Return, Task, Select>(
|
|
*this, skeleton.task, skeleton.select, tupleP, skeleton.n
|
|
);
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|