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

using namespace pls::internal::scheduling;

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

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

using namespace comparison_benchmarks::base;

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

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

30
  return a + b;
FritzFlorian committed
31 32
}

33
constexpr int MAX_NUM_TASKS = 32;
34
constexpr int MAX_STACK_SIZE = 1024 * 4;
35

FritzFlorian committed
36 37 38 39 40 41
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";
42
  string full_directory = directory + "/PLS_v3/";
FritzFlorian committed
43 44
  benchmark_runner runner{full_directory, test_name};

45
  scheduler scheduler{(unsigned) num_threads, MAX_NUM_TASKS, MAX_STACK_SIZE};
FritzFlorian committed
46 47

  volatile int res;
48 49
  runner.run_iterations(fib::NUM_ITERATIONS, [&]() {
    scheduler.perform_work([&]() {
50
      res = pls_fib(fib::INPUT_N);
51 52
    });
  }, fib::NUM_WARMUP_ITERATIONS);
FritzFlorian committed
53 54 55 56
  runner.commit_results(true);

  return 0;
}