main.cpp 2.28 KB
Newer Older
1
#include "pls/pls.h"
2

3
using namespace pls::internal::scheduling;
4

5 6
#include "benchmark_runner.h"
#include "benchmark_base/unbalanced.h"
7

8
using namespace comparison_benchmarks::base;
9

10
#include <atomic>
11

12 13 14
int count_child_nodes(unbalanced::node &node) {
  if (node.get_num_children() < 1) {
    return 1;
15 16
  }

17 18
  std::atomic<int> count{1};
  for (int i = 0; i < node.get_num_children(); i++) {
19
    pls::spawn([i, &count, &node] {
20 21 22
      unbalanced::node child_node = node.spawn_child_node(i);
      count.fetch_add(count_child_nodes(child_node));
    });
23
  }
24
  pls::sync();
25

26
  return count;
27 28
}

29 30 31
int unbalanced_tree_search(int seed, int root_children, double q, int normal_children) {
  unbalanced::node root(seed, root_children, q, normal_children);
  return count_child_nodes(root);
32 33
}

34
constexpr int MAX_NUM_TASKS = 256;
35
constexpr int MAX_STACK_SIZE = 4096 * 1;
36

37
int main(int argc, char **argv) {
38
  auto settings = benchmark_runner::parse_parameters(argc, argv);
39

40 41
  string test_name = to_string(settings.num_threads_) + ".csv";
  string full_directory = settings.output_directory_ + "/PLS_v3/";
42
  benchmark_runner runner{full_directory, test_name};
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

  pls::scheduler scheduler{(unsigned) settings.num_threads_, MAX_NUM_TASKS, MAX_STACK_SIZE};

  if (settings.type_ == benchmark_runner::benchmark_settings::ISOLATED) {
    printf("Running isolated measurement...\n");
    runner.enable_memory_stats();
    runner.pre_allocate_stats();

    runner.run_iterations(settings.iterations_, [&]() {
      scheduler.perform_work([&]() {
        unbalanced_tree_search(unbalanced::SEED,
                               unbalanced::ROOT_CHILDREN,
                               unbalanced::Q,
                               unbalanced::NORMAL_CHILDREN);
      });
58
    });
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    runner.commit_results(true);
  } else {
    printf("Running periodic measurement...\n");
    runner.enable_wall_time_stats();
    runner.pre_allocate_stats();

    runner.run_periodic(settings.iterations_, settings.interval_period_, settings.interval_deadline_, [&]() {
      scheduler.perform_work([&]() {
        unbalanced_tree_search(unbalanced::SEED,
                               unbalanced::ROOT_CHILDREN,
                               unbalanced::Q,
                               unbalanced::NORMAL_CHILDREN);
      });
    });
    runner.commit_results(true);
  }
75 76

}
77

78