main.cpp 2.19 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
  if (settings.type_ == benchmark_runner::benchmark_settings::ISOLATED) {
40 41 42 43 44 45
#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

46 47 48
    printf("Running isolated measurement...\n");
    runner.enable_memory_stats();
    runner.pre_allocate_stats();
49

50 51 52 53
    runner.run_iterations(settings.iterations_, [&]() {
      scheduler.perform_work([&]() {
        result.multiply(a, b);
      });
54 55 56 57 58
    }, [&]() {}, [&]() {
#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
59 60 61 62 63 64 65 66 67 68 69
    });
    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);
      });
70
    });
71 72
    runner.commit_results(true);
  }
FritzFlorian committed
73

74
}