alsk/plot/main.cpp
2021-05-10 18:14:13 +02:00

114 lines
3.2 KiB
C++

#include <algorithm>
#include <fstream>
#include "common.h"
#include "executor/firstlevelequi.h"
#include "executor/firstlevelgreedy.h"
#include "executor/opti.h"
void displaySplit(Split const& split) {
for(auto const& e: split)
std::printf("%zu, ", e);
std::puts("");
}
std::ostream& operator<<(std::ostream& os, CoresList const& cl) {
os << '{';
for(auto k: cl) os << k << ',';
return os << '}';
}
CoresList coresLinUpTo(std::size_t n) {
CoresList cl(n);
std::generate_n(std::begin(cl), n, [i=0]() mutable { return ++i; });
return cl;
}
CoresList coresExpUpTo(std::size_t n) {
CoresList cl;
std::size_t min = 1;
while(min <= n) {
cl.push_back(min);
min *= 2;
}
return cl;
}
/* *** */
void genFixedCores(std::string const& o, CoresList const& coresList, std::size_t first, std::size_t last, SplitFn split) {
std::ofstream f{o};
if(!f) return;
f << *coresList.rbegin() << ',' << first << ',' << last << '\n';
for(std::size_t n = first; n <= last; ++n)
f << n << ',' << split(n, coresList).size() << '\n';
}
void genFixedTasksLin(std::string const& o, std::size_t tasks, std::size_t last, SplitFn split) {
std::ofstream f{o};
if(!f) return;
f << tasks << ',' << 1 << ',' << last << '\n';
for(std::size_t i = 1; i <= last; ++i)
f << i << ',' << split(i, coresLinUpTo(i)).size() << '\n';
}
void genFixedTasksExp(std::string const& o, std::size_t tasks, std::size_t last, SplitFn split) {
std::ofstream f{o};
if(!f) return;
f << tasks << ',' << 1 << ',' << last << '\n';
for(std::size_t i = 1; i <= last; i *= 2)
f << i << ',' << split(i, coresExpUpTo(i)).size() << '\n';
}
void genAll() {
#define OUTPREFIX "plot_data/fig"
{
auto cores = coresLinUpTo(64);
constexpr unsigned start = 50;
constexpr unsigned num = 1000;
genFixedCores(OUTPREFIX "1a", cores, start, start+num, firstLevelEqui);
genFixedCores(OUTPREFIX "1b", cores, start, start+num, firstLevelGreedy);
genFixedCores(OUTPREFIX "1c", cores, start, start+num, fictiveOpti);
}
{
auto cores = coresLinUpTo(64);
constexpr unsigned start = 50;
constexpr unsigned num = 1000;
genFixedCores(OUTPREFIX "2a", cores, start, start+num, firstLevelEqui);
genFixedCores(OUTPREFIX "2b", cores, start, start+num, firstLevelGreedy);
genFixedCores(OUTPREFIX "2c", cores, start, start+num, fictiveOpti);
}
{
auto cores = coresLinUpTo(64);
constexpr unsigned start = 50;
constexpr unsigned num = 1000;
genFixedCores(OUTPREFIX "3a", cores, start, start+num, firstLevelEqui);
genFixedCores(OUTPREFIX "3b", coresExpUpTo(64), start, start+num, firstLevelEqui);
genFixedCores(OUTPREFIX "3c", cores, start, start+num, fictiveOpti);
}
{
constexpr unsigned tasks = 1000;
genFixedTasksLin(OUTPREFIX "4a", tasks, 256, firstLevelEqui);
genFixedTasksLin(OUTPREFIX "4b", tasks, 256, firstLevelGreedy);
}
{
constexpr unsigned tasks = 10'000;
genFixedTasksLin(OUTPREFIX "5a", tasks, 256, firstLevelEqui);
genFixedTasksLin(OUTPREFIX "5b", tasks, 256, firstLevelGreedy);
}
{
constexpr unsigned tasks = 1'000'000;
genFixedTasksLin(OUTPREFIX "6a", tasks, 256, firstLevelEqui);
genFixedTasksLin(OUTPREFIX "6b", tasks, 256, firstLevelGreedy);
}
}
int main() {
genAll();
}