main.cpp 1.57 KB
Newer Older
FritzFlorian committed
1
#include "pls/internal/scheduling/scheduler.h"
2
#include "pls/internal/scheduling/static_scheduler_memory.h"
FritzFlorian committed
3 4 5 6

using namespace pls::internal::scheduling;

#include <iostream>
7
#include <cstdio>
FritzFlorian committed
8 9 10 11 12 13

#include "benchmark_runner.h"
#include "benchmark_base/fib.h"

using namespace comparison_benchmarks::base;

14
int pls_fib(int n) {
15 16 17 18
  if (n == 0) {
    return 0;
  }
  if (n == 1) {
19
    return 1;
FritzFlorian committed
20 21
  }

22 23 24 25 26 27 28
  int a, b;
  scheduler::spawn([n, &a]() {
    a = pls_fib(n - 1);
  });
  scheduler::spawn([n, &b]() {
    b = pls_fib(n - 2);
  });
29
  scheduler::sync();
30

31
  return a + b;
FritzFlorian committed
32 33
}

34
constexpr int MAX_NUM_THREADS = 4;
35 36
constexpr int MAX_NUM_TASKS = 32;
constexpr int MAX_STACK_SIZE = 1024 * 32;
37 38 39 40

static_scheduler_memory<MAX_NUM_THREADS,
                        MAX_NUM_TASKS,
                        MAX_STACK_SIZE> global_scheduler_memory;
FritzFlorian committed
41 42 43 44 45 46 47

int main(int argc, char **argv) {
  int num_threads;
  string directory;
  benchmark_runner::read_args(argc, argv, num_threads, directory);

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

51
  scheduler scheduler{global_scheduler_memory, (unsigned) num_threads, false};
FritzFlorian committed
52 53

  volatile int res;
54 55
  scheduler.perform_work([&]() {
    for (int i = 0; i < fib::NUM_WARMUP_ITERATIONS; i++) {
56
      res = pls_fib(fib::INPUT_N);
57 58
    }
  });
FritzFlorian committed
59

60
  scheduler.perform_work([&]() {
61
    for (int i = 0; i < fib::NUM_ITERATIONS * 100; i++) {
FritzFlorian committed
62
      runner.start_iteration();
63 64
      res = pls_fib(fib::INPUT_N);
      runner.end_iteration();
65 66
    }
  });
FritzFlorian committed
67 68 69 70
  runner.commit_results(true);

  return 0;
}