main.cpp 2.15 KB
Newer Older
FritzFlorian committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#include "pls/internal/scheduling/scheduler.h"
#include "pls/internal/scheduling/parallel_result.h"
#include "pls/internal/scheduling/scheduler_memory.h"
#include "pls/internal/helpers/profiler.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;

parallel_result<int> pls_fib(int n) {
  if (n <= 1) {
    return parallel_result<int>{1};
  }

  return scheduler::par([=]() {
    return pls_fib(n - 1);
  }, [=]() {
    return pls_fib(n - 2);
  }).then([=](int a, int b) {
    return parallel_result<int>{a + b};
  });
}

constexpr int MAX_NUM_THREADS = 8;
constexpr int MAX_NUM_TASKS = 64;
constexpr int MAX_NUM_CONTS = 64;
constexpr int MAX_CONT_SIZE = 256;

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";
  string full_directory = directory + "/PLS_v2/";
  benchmark_runner runner{full_directory, test_name};

  static_scheduler_memory<MAX_NUM_THREADS,
                          MAX_NUM_TASKS,
                          MAX_NUM_CONTS,
                          MAX_CONT_SIZE> static_scheduler_memory;

  scheduler scheduler{static_scheduler_memory, (unsigned int) num_threads};

  volatile int res;
  for (int i = 0; i < fib::NUM_WARMUP_ITERATIONS; i++) {
    scheduler.perform_work([&]() {
      return scheduler::par([&]() {
        return pls_fib(fib::INPUT_N);
      }, []() {
        return parallel_result<int>{0};
      }).then([&](int result, int) {
        res = result;
        return parallel_result<int>{0};
      });
    });
  }

  for (int i = 0; i < fib::NUM_ITERATIONS; i++) {
    scheduler.perform_work([&]() {
      runner.start_iteration();

      return scheduler::par([&]() {
        return pls_fib(fib::INPUT_N);
      }, []() {
        return parallel_result<int>{0};
      }).then([&](int result, int) {
        res = result;
        runner.end_iteration();
        return parallel_result<int>{0};
      });
    });
  }
  runner.commit_results(true);

  return 0;
}