main.cpp 1.86 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
  if (settings.type_ == benchmark_runner::benchmark_settings::ISOLATED) {
37 38 39 40 41
#if PLS_PROFILING_ENABLED
    scheduler.get_profiler().disable_memory_measure();
    runner.add_custom_stats_field("T_1");
    runner.add_custom_stats_field("T_inf");
#endif
42 43 44 45 46 47 48 49
    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
    }, [&]() {}, [&]() {
#if PLS_PROFILING_ENABLED
      runner.store_custom_stat("T_1", scheduler.get_profiler().current_run().t_1_);
      runner.store_custom_stat("T_inf", scheduler.get_profiler().current_run().t_inf_);
#endif
55
    });
56 57 58 59 60
    runner.commit_results(true);
  } else {
    printf("Running periodic measurement...\n");
    runner.enable_wall_time_stats();
    runner.pre_allocate_stats();
FritzFlorian committed
61

62 63 64 65 66 67 68
    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
69 70 71

  return 0;
}