main.cpp 1.79 KB
Newer Older
1
#include "pls/pls.h"
2

3
using namespace pls;
4

5 6
#include "benchmark_runner.h"
#include "benchmark_base/matrix.h"
FritzFlorian committed
7
#include <iostream>
8

9
using namespace comparison_benchmarks::base;
10

11 12
template<typename T>
class pls_matrix : public matrix::matrix<T> {
13
 public:
14
  explicit pls_matrix(size_t size) : matrix::matrix<T>(size) {}
15

16 17
  void multiply(const matrix::matrix<T> &a, const matrix::matrix<T> &b) override {
    pls::algorithm::for_each_range(0, this->size_, [&](int i) {
18 19 20 21 22
      this->multiply_column(i, a, b);
    });
  }
};

23
constexpr int MAX_NUM_TASKS = 10;
24
constexpr int MAX_STACK_SIZE = 4096 * 1;
25

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

29 30 31 32 33 34
  pls_matrix<double> a{settings.size_};
  pls_matrix<double> b{settings.size_};
  pls_matrix<double> result{settings.size_};

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

37
  pls::scheduler scheduler{(unsigned) settings.num_threads_, MAX_NUM_TASKS, MAX_STACK_SIZE};
38

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

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    runner.run_iterations(settings.iterations_, [&]() {
      scheduler.perform_work([&]() {
        result.multiply(a, b);
      });
    });
    runner.commit_results(true);
  } else {
    printf("Running periodic measurement...\n");
    runner.enable_wall_time_stats();
    runner.pre_allocate_stats();

    runner.run_periodic(settings.iterations_, settings.interval_period_, settings.interval_deadline_, [&]() {
      scheduler.perform_work([&]() {
        result.multiply(a, b);
      });
59
    });
60 61
    runner.commit_results(true);
  }
FritzFlorian committed
62

63
}