alsk/plot/executor/opti.cpp

68 lines
1.2 KiB
C++
Raw Permalink Normal View History

2021-05-10 16:14:13 +00:00
#include "opti.h"
Split fictiveOpti(std::size_t tasks, CoresList const& coresList) {
Split split;
auto equi = [&](unsigned k) {
std::vector<unsigned> ntasks;
unsigned const step = tasks/k;
unsigned remain = tasks - k*step;
for(unsigned int i = 0; i < k; ++i) {
unsigned q = step;
if(remain) {
++q;
--remain;
}
ntasks.push_back(q);
}
return ntasks;
};
auto greedy = [&](unsigned k) {
std::vector<unsigned> ntasks;
unsigned step = (tasks+k-1)/k;
unsigned n = tasks;
while(n) {
if(n < step) step = n;
n -= step;
ntasks.push_back(step);
}
return ntasks;
};
static_cast<void>(equi);
static_cast<void>(greedy);
for(auto k: coresList) {
// for(unsigned int k = cores; k > 1; --k) {
// for(unsigned int k = 2; k <= cores; ++k) {
auto ntasks = equi(k);
{
unsigned start{};
while(ntasks.size() > 1) {
auto v = std::end(ntasks);
for(auto it = std::begin(ntasks);
v == std::end(ntasks) && it != std::end(ntasks);
++it)
{
if(split.count(start+*it))
v = it;
}
if(v == std::end(ntasks)) v = std::begin(ntasks);
start += *v;
split.insert(start);
ntasks.erase(v);
}
}
}
return split;
}