thesis version
This commit is contained in:
75
inc/alsk/impl/bone/farm.h
Normal file
75
inc/alsk/impl/bone/farm.h
Normal file
@ -0,0 +1,75 @@
|
||||
#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
|
91
inc/alsk/impl/bone/farmsel.h
Normal file
91
inc/alsk/impl/bone/farmsel.h
Normal file
@ -0,0 +1,91 @@
|
||||
#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
|
57
inc/alsk/impl/bone/itersel.h
Normal file
57
inc/alsk/impl/bone/itersel.h
Normal file
@ -0,0 +1,57 @@
|
||||
#ifndef ALSK_ALSK_IMPL_BONE_ITERSEL_H
|
||||
#define ALSK_ALSK_IMPL_BONE_ITERSEL_H
|
||||
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "../boneimplbase.h"
|
||||
#include "../../skeleton/bone/itersel.h"
|
||||
|
||||
namespace alsk {
|
||||
|
||||
/**
|
||||
* @brief IterSel implementation for any execution
|
||||
*/
|
||||
template<typename R, typename... Args, typename... Tasks, typename Tag, typename Executor, typename State>
|
||||
struct Impl<IterSel<R(Args...), Tasks...>, Tag, Executor, State>:
|
||||
BoneImplBase<IterSel<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, typename O>
|
||||
constexpr Impl(S&& skeleton, O&& executor, State& state):
|
||||
skeleton{std::forward<S>(skeleton)},
|
||||
executor{std::forward<O>(executor)},
|
||||
state{state}
|
||||
{}
|
||||
|
||||
// TODO check repeatability with tag::Parallel
|
||||
constexpr typename This::Return operator()(Args... args) {
|
||||
using Value = typename This::Return;
|
||||
|
||||
auto tupleP = std::forward_as_tuple(args...);
|
||||
|
||||
Value best = ArgGet<arg::P<0>>::get(tupleP, std::tuple<>{}, std::tuple<>{});
|
||||
|
||||
for(std::size_t i = 0; i < skeleton.n; ++i) {
|
||||
Value current = executor.template execute<Task>(*this, skeleton.task, tupleP, std::tuple<>{}, best);
|
||||
best = executor.template execute<Select>(
|
||||
*this, skeleton.select, tupleP, std::tuple<>{}, std::move(current), std::move(best)
|
||||
);
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
41
inc/alsk/impl/bone/loop.h
Normal file
41
inc/alsk/impl/bone/loop.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef ALSK_ALSK_IMPL_BONE_LOOP_H
|
||||
#define ALSK_ALSK_IMPL_BONE_LOOP_H
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include "../boneimplbase.h"
|
||||
#include "../../skeleton/bone/loop.h"
|
||||
|
||||
namespace alsk {
|
||||
|
||||
/**
|
||||
* @brief Loop implementation for any execution
|
||||
*/
|
||||
template<typename R, typename... Args, typename Task, typename Tag, typename Executor, typename State>
|
||||
struct Impl<Loop<R(Args...), Task>, Tag, Executor, State>:
|
||||
BoneImplBase<Loop<R(Args...), Task>, Tag, Executor, State>
|
||||
{
|
||||
using This = Impl;
|
||||
using ETask = Execute<typename This::Skeleton::TaskLinks>;
|
||||
|
||||
typename This::Skeleton skeleton;
|
||||
typename This::Executor executor;
|
||||
typename This::StateRef state;
|
||||
|
||||
constexpr Impl() = default;
|
||||
template<typename S, typename O>
|
||||
constexpr Impl(S&& skeleton, O&& executor, State& state):
|
||||
skeleton{std::forward<S>(skeleton)},
|
||||
executor{std::forward<O>(executor)},
|
||||
state{state}
|
||||
{}
|
||||
|
||||
constexpr typename This::Return operator()(Args... args) {
|
||||
for(unsigned int i = 0; i < skeleton.n; ++i)
|
||||
executor.template execute<ETask>(*this, skeleton.task, std::forward_as_tuple(args...), std::tuple<>{});
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
82
inc/alsk/impl/bone/serial.h
Normal file
82
inc/alsk/impl/bone/serial.h
Normal file
@ -0,0 +1,82 @@
|
||||
#ifndef ALSK_ALSK_IMPL_BONE_SERIAL_H
|
||||
#define ALSK_ALSK_IMPL_BONE_SERIAL_H
|
||||
|
||||
#include "../boneimplbase.h"
|
||||
#include "../../skeleton/bone/serial.h"
|
||||
|
||||
namespace alsk {
|
||||
|
||||
/**
|
||||
* @brief Serial implementation for any execution
|
||||
*/
|
||||
template<typename R, typename... Args, typename... Tasks, typename Tag, typename Executor, typename State>
|
||||
struct Impl<Serial<R(Args...), Tasks...>, Tag, Executor, State>:
|
||||
BoneImplBase<Serial<R(Args...), Tasks...>, Tag, Executor, State>
|
||||
{
|
||||
using This = Impl;
|
||||
using Results = tmp::Repack<std::tuple, tmp::PackReplace<typename This::Skeleton::PackR, void, tmp::Void>>;
|
||||
|
||||
typename This::Skeleton skeleton;
|
||||
typename This::Executor executor;
|
||||
typename This::StateRef state;
|
||||
|
||||
Results results;
|
||||
|
||||
constexpr Impl() = default;
|
||||
template<typename S, typename O>
|
||||
constexpr Impl(S&& skeleton, O&& executor, State& state):
|
||||
skeleton{std::forward<S>(skeleton)},
|
||||
executor{std::forward<O>(executor)},
|
||||
state{state}
|
||||
{}
|
||||
|
||||
// out-of-class definition to silence -Winline
|
||||
~Impl() noexcept;
|
||||
|
||||
// TODO: what happens with rvalue references?
|
||||
constexpr typename This::Return operator()(Args... args) {
|
||||
return serial(std::forward_as_tuple(args...));
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename TupleP>
|
||||
constexpr decltype(auto) serial(TupleP&& p) {
|
||||
serial<0, typename This::Skeleton::Links>(skeleton.tasks, p);
|
||||
return ArgGet<R>::get(std::tuple<>{}, std::move(results), std::tuple<>{});
|
||||
}
|
||||
|
||||
/**
|
||||
* execute
|
||||
*/
|
||||
template<
|
||||
std::size_t I, typename LinksPack, typename TupleTasks,
|
||||
typename TupleP,
|
||||
std::enable_if_t<(I < std::tuple_size<std::decay_t<TupleTasks>>::value)>* = nullptr
|
||||
>
|
||||
constexpr void serial(TupleTasks& tasks, TupleP& p) {
|
||||
using Task = Execute<tmp::PackHead<LinksPack>>;
|
||||
|
||||
std::get<I>(results) = executor.template execute<Task>(
|
||||
*this, std::get<I>(tasks), p, results
|
||||
);
|
||||
serial<I+1, tmp::PackTrail<LinksPack>>(tasks, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* recursion terminaison
|
||||
*/
|
||||
template<
|
||||
std::size_t I, typename LinksPack, typename TupleTasks,
|
||||
typename TupleP,
|
||||
std::enable_if_t<(I == std::tuple_size<std::decay_t<TupleTasks>>::value)>* = nullptr
|
||||
>
|
||||
constexpr void serial(TupleTasks&&, TupleP&&) noexcept {}
|
||||
};
|
||||
|
||||
// out-of-class definition to silence -Winline
|
||||
template<typename R, typename... Args, typename... Tasks, typename Tag, typename Executor, typename State>
|
||||
Impl<Serial<R(Args...), Tasks...>, Tag, Executor, State>::~Impl() noexcept {}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
46
inc/alsk/impl/bone/while.h
Normal file
46
inc/alsk/impl/bone/while.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef ALSK_ALSK_IMPL_BONE_WHILE_H
|
||||
#define ALSK_ALSK_IMPL_BONE_WHILE_H
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
#include "../boneimplbase.h"
|
||||
#include "../../skeleton/bone/while.h"
|
||||
|
||||
namespace alsk {
|
||||
|
||||
/**
|
||||
* @brief While implementation for any execution
|
||||
*/
|
||||
template<typename R, typename... Args, typename... Tasks, typename Tag, typename Executor, typename State>
|
||||
struct Impl<While<R(Args...), Tasks...>, Tag, Executor, State>:
|
||||
BoneImplBase<While<R(Args...), Tasks...>, Tag, Executor, State>
|
||||
{
|
||||
using This = Impl;
|
||||
using Test = Execute<typename This::Skeleton::TestLinks>;
|
||||
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, typename O>
|
||||
constexpr Impl(S&& skeleton, O&& executor, State& state):
|
||||
skeleton{std::forward<S>(skeleton)},
|
||||
executor{std::forward<O>(executor)},
|
||||
state{state}
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
constexpr typename This::Return operator()(T& a, T const& b) {
|
||||
auto tupleP = std::forward_as_tuple(a, b);
|
||||
|
||||
while(executor.template execute<Test>(*this, skeleton.test, tupleP, std::tuple<>{}))
|
||||
executor.template execute<Task>(*this, skeleton.task, tupleP, std::tuple<>{});
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user