76 lines
1.9 KiB
C
76 lines
1.9 KiB
C
|
#ifndef ALSK_ALSK_IMPL_BONE_FARM_H
|
||
|
#define ALSK_ALSK_IMPL_BONE_FARM_H
|
||
|
|
||
|
#include <cmath>
|
||
|
#include <thread>
|
||
|
#include <tuple>
|
||
|
#include <utility>
|
||
|
#include <vector>
|
||
|
|
||
|
#include "../boneimplbase.h"
|
||
|
#include "../../skeleton/bone/farm.h"
|
||
|
|
||
|
namespace alsk {
|
||
|
|
||
|
/**
|
||
|
* @brief Farm implementation for sequential execution
|
||
|
*/
|
||
|
template<typename R, typename... Args, typename TTask, typename Executor, typename State>
|
||
|
struct Impl<Farm<R(Args...), TTask>, tag::Sequential, Executor, State>:
|
||
|
BoneImplBase<Farm<R(Args...), TTask>, tag::Sequential, Executor, State>
|
||
|
{
|
||
|
using This = Impl;
|
||
|
using Task = Execute<typename This::Skeleton::TaskLinks>;
|
||
|
|
||
|
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 void operator()(Args... args) {
|
||
|
executor.template executeSequential<Task>(
|
||
|
*this, skeleton.task, std::forward_as_tuple(args...), skeleton.n
|
||
|
);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* @brief Farm implementation for parallel execution
|
||
|
*/
|
||
|
template<typename R, typename... Args, typename TTask, typename Executor, typename State>
|
||
|
struct Impl<Farm<R(Args...), TTask>, tag::Parallel, Executor, State>:
|
||
|
BoneImplBase<Farm<R(Args...), TTask>, tag::Parallel, Executor, State>
|
||
|
{
|
||
|
using This = Impl;
|
||
|
using Task = Execute<typename This::Skeleton::TaskLinks>;
|
||
|
|
||
|
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 void operator()(Args... args) {
|
||
|
executor.template executeParallel<Task>(
|
||
|
*this, skeleton.task, std::forward_as_tuple(args...), skeleton.n
|
||
|
);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
#endif
|