main.cpp 1.58 KB
Newer Older
1
#include "pls/pls.h"
FritzFlorian committed
2 3 4 5 6 7

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

using namespace comparison_benchmarks::base;

8 9 10
constexpr int MAX_NUM_TASKS = 32;
constexpr int MAX_STACK_SIZE = 4096 * 1;

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

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

28
  return a + b;
FritzFlorian committed
29 30 31
}

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

34 35
  string test_name = to_string(settings.num_threads_) + ".csv";
  string full_directory = settings.output_directory_ + "/PLS_v3/";
FritzFlorian committed
36 37
  benchmark_runner runner{full_directory, test_name};

38
  pls::scheduler scheduler{(unsigned) settings.num_threads_, MAX_NUM_TASKS, MAX_STACK_SIZE};
FritzFlorian committed
39 40

  volatile int res;
41 42 43 44 45 46 47 48 49
  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_);
      });
50
    });
51 52 53 54 55
    runner.commit_results(true);
  } else {
    printf("Running periodic measurement...\n");
    runner.enable_wall_time_stats();
    runner.pre_allocate_stats();
FritzFlorian committed
56

57 58 59 60 61 62 63
    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
64 65 66

  return 0;
}