main.cpp 1.47 KB
Newer Older
1
#include "pls/pls.h"
FritzFlorian committed
2 3 4

#include "benchmark_runner.h"

5 6
constexpr int MAX_STACK_SIZE = 4096 * 1;

7
int pls_fib(int n) {
8 9 10 11
  if (n == 0) {
    return 0;
  }
  if (n == 1) {
12
    return 1;
FritzFlorian committed
13 14
  }

15
  int a, b;
16 17
  pls::spawn([n, &a]() {
    a = pls_fib(n - 1);
18
  });
19
  pls::spawn_and_sync([n, &b]() {
20
    b = pls_fib(n - 2);
21
  });
22

23
  return a + b;
FritzFlorian committed
24 25 26
}

int main(int argc, char **argv) {
27
  auto settings = benchmark_runner::parse_parameters(argc, argv);
FritzFlorian committed
28

29 30
  string test_name = to_string(settings.num_threads_) + ".csv";
  string full_directory = settings.output_directory_ + "/PLS_v3/";
FritzFlorian committed
31 32
  benchmark_runner runner{full_directory, test_name};

33
  pls::scheduler scheduler{(unsigned) settings.num_threads_, settings.size_ + 2, MAX_STACK_SIZE};
FritzFlorian committed
34 35

  volatile int res;
36 37 38 39 40 41 42 43 44
  if (settings.type_ == benchmark_runner::benchmark_settings::ISOLATED) {
    printf("Running isolated measurement...\n");
    runner.enable_memory_stats();
    runner.pre_allocate_stats();

    runner.run_iterations(settings.iterations_, [&]() {
      scheduler.perform_work([&]() {
        res = pls_fib(settings.size_);
      });
45
    });
46 47 48 49 50
    runner.commit_results(true);
  } else {
    printf("Running periodic measurement...\n");
    runner.enable_wall_time_stats();
    runner.pre_allocate_stats();
FritzFlorian committed
51

52 53 54 55 56 57 58
    runner.run_periodic(settings.iterations_, settings.interval_period_, settings.interval_deadline_, [&]() {
      scheduler.perform_work([&]() {
        res = pls_fib(settings.size_);
      });
    });
    runner.commit_results(true);
  }
FritzFlorian committed
59 60 61

  return 0;
}