#include #include #include #include #include "NameGame.h" constexpr int group_size = 1000, T = 200; constexpr int cmsize_min = 200, cmsize_max = 400; constexpr int trials = 100; constexpr int workers = 6; constexpr const char* csv_file = "many-async-T200-exp.csv"; using RunVec = std::vector>; RunVec run_trials(int cmsize_start, int cmsize_end) { std::random_device seeder; tp::NameGame namegame(group_size, 0, 12); RunVec runs; for (int i = cmsize_start; i < cmsize_end; ++i) { for (int j = 0; j < trials; ++j) { namegame.setCMsize(i); namegame.initMemory(); namegame.clearRecord(); int a = namegame.run(group_size * T); runs.push_back({i, a}); } namegame.seed(seeder()); std::cout << "finished cmsize " << i << std::endl; } return runs; } int main(int argc, char* argv[]) { RunVec all_runs; std::vector> futs; for (int i = 0; i < workers; ++i) { int range_size = cmsize_max - cmsize_min + 1; int worker_range_size = range_size / workers; int worker_range_start = cmsize_min + worker_range_size * i; int worker_range_end = worker_range_start + worker_range_size + (i == workers - 1 ? range_size % workers : 0); std::cout << "worker " << i << " will work on range " << worker_range_start << " to " << worker_range_end << std::endl; futs.push_back( std::async(run_trials, worker_range_start, worker_range_end )); } for (int i = 0; i < workers; ++i) { RunVec v = futs[i].get(); all_runs.insert(all_runs.end(), v.begin(), v.end()); } std::ofstream f(csv_file); if (!f) { std::cerr << "ERROR: opening many-async.csv" << std::endl; return 1; } f << "cmsize,adopters\n"; for (const auto& p : all_runs) { f << p.first << ',' << p.second << '\n'; } return 0; }