main.cpp 2.68 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 = 180;
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

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

  if (settings.type_ == benchmark_runner::benchmark_settings::ISOLATED) {
47 48 49 50 51
#if PLS_PROFILING_ENABLED
    scheduler.get_profiler().disable_memory_measure();
    runner.add_custom_stats_field("T_1");
    runner.add_custom_stats_field("T_inf");
#endif
52 53 54 55 56 57 58 59 60 61 62
    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);
      });
63 64 65 66 67
    }, [&]() {}, [&]() {
#if PLS_PROFILING_ENABLED
      runner.store_custom_stat("T_1", scheduler.get_profiler().current_run().t_1_);
      runner.store_custom_stat("T_inf", scheduler.get_profiler().current_run().t_inf_);
#endif
68
    });
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    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);
  }
85 86

}
87

88