main.cpp 1.52 KB
Newer Older
FritzFlorian committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include "pls/internal/scheduling/scheduler.h"
#include "pls/internal/scheduling/scheduler_memory.h"

using namespace pls::internal::scheduling;

#include <iostream>
#include <complex>
#include <vector>

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

using namespace comparison_benchmarks::base;

15
int pls_fib(int n) {
FritzFlorian committed
16
  if (n <= 1) {
17
    return 1;
FritzFlorian committed
18 19
  }

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

  return a + b;
FritzFlorian committed
29 30
}

31
constexpr int MAX_NUM_THREADS = 1;
FritzFlorian committed
32
constexpr int MAX_NUM_TASKS = 64;
33
constexpr int MAX_STACK_SIZE = 256;
FritzFlorian committed
34 35 36 37 38 39 40

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

  static_scheduler_memory<MAX_NUM_THREADS,
                          MAX_NUM_TASKS,
46
                          MAX_STACK_SIZE> static_scheduler_memory;
FritzFlorian committed
47

48
  scheduler scheduler{static_scheduler_memory, (unsigned) num_threads};
FritzFlorian committed
49 50 51 52

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

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

  return 0;
}