rosa/inc/alsk/executor/impl/sequential.h

56 lines
1.5 KiB
C
Raw Permalink Normal View History

2021-05-10 16:14:24 +00:00
#ifndef ALSK_ALSK_EXECUTOR_IMPL_SEQUENTIAL_H
#define ALSK_ALSK_EXECUTOR_IMPL_SEQUENTIAL_H
#include <set>
#include <cmath>
#include <vector>
#include "../executorbase.h"
#include "../executorstate.h"
#include "../../skeleton/traits.h"
namespace alsk {
namespace exec {
template<typename S>
struct Sequential: ExecutorBase {
using Tag = alsk::tag::Sequential;
public:
template<typename Impl>
std::size_t contextIdCount(Impl&, std::size_t) { return 1; }
template<typename Impl>
std::size_t contextId(Impl&, std::size_t) { return 0; }
template<typename Task, typename Impl, typename BTask, typename Parameters>
void executeParallel(Impl& impl, BTask& task, Parameters const& parameters, std::size_t n) {
Info info;
for(std::size_t i = 0; i < n; ++i)
Task::execute(impl, task, i, info, parameters, std::tuple<>{});
}
template<typename Value, typename Task, typename Select, typename Impl, typename BTask, typename BSelect, typename Parameters>
Value executeParallelAccumulate(Impl& impl, BTask& task, BSelect& select, Parameters const& parameters, std::size_t n) {
Info info;
Value best{};
if(n)
best = Task::execute(impl, task, 0, info, parameters, std::tuple<>{});
for(std::size_t i = 1; i < n; ++i) {
Value current = Task::execute(impl, task, i, info, parameters, std::tuple<>{});
best = Select::execute(impl, select, i, info, parameters, std::tuple<>{}, std::move(current), std::move(best));
}
return best;
}
};
template<typename S>
struct ExecutorState<Sequential<S>> {};
}
}
#endif