main.cpp 2.32 KB
Newer Older
1
#include "pls/internal/scheduling/scheduler.h"
2
#include "pls/internal/scheduling/static_scheduler_memory.h"
3

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

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

9
using namespace comparison_benchmarks::base;
10

11
#include <atomic>
12

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

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

27
  return count;
28 29
}

30 31 32
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);
33 34
}

35 36 37
constexpr int MAX_NUM_THREADS = 8;
constexpr int MAX_NUM_TASKS = 256;
constexpr int MAX_STACK_SIZE = 1024 * 2;
38

39 40 41
static_scheduler_memory<MAX_NUM_THREADS,
                        MAX_NUM_TASKS,
                        MAX_STACK_SIZE> global_scheduler_memory;
42

43 44 45 46
int main(int argc, char **argv) {
  int num_threads;
  string directory;
  benchmark_runner::read_args(argc, argv, num_threads, directory);
47

48 49 50
  string test_name = to_string(num_threads) + ".csv";
  string full_directory = directory + "/PLS_v3/";
  benchmark_runner runner{full_directory, test_name};
51

52
  scheduler scheduler{global_scheduler_memory, (unsigned) num_threads};
53

54 55 56 57 58 59
  runner.run_iterations(unbalanced::NUM_ITERATIONS, [&]() {
    scheduler.perform_work([&]() {
      unbalanced_tree_search(unbalanced::SEED,
                             unbalanced::ROOT_CHILDREN,
                             unbalanced::Q,
                             unbalanced::NORMAL_CHILDREN);
60
    });
61 62
  }, unbalanced::WARMUP_ITERATIONS);
  runner.commit_results(true);
63 64

}
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

//int main() {
//  PROFILE_ENABLE
//  pls::malloc_scheduler_memory my_scheduler_memory{8, 2u << 18};
//  pls::scheduler scheduler{&my_scheduler_memory, 8};
//
//  scheduler.perform_work([&] {
//    PROFILE_MAIN_THREAD
//    for (int i = 0; i < 50; i++) {
//      PROFILE_WORK_BLOCK("Top Level")
//      int result = unbalanced_tree_search(SEED, ROOT_CHILDREN, Q, NORMAL_CHILDREN);
//      std::cout << result << std::endl;
//    }
//  });
//
//  PROFILE_SAVE("test_profile.prof")
//}