#include "pls/pls.h"

using namespace pls;

#include "benchmark_runner.h"
#include "benchmark_base/matrix.h"
#include <iostream>

using namespace comparison_benchmarks::base;

template<typename T, int SIZE>
class pls_matrix : public matrix::matrix<T, SIZE> {
 public:
  pls_matrix() : matrix::matrix<T, SIZE>() {}

  void multiply(const matrix::matrix<T, SIZE> &a, const matrix::matrix<T, SIZE> &b) override {
    pls::algorithm::for_each_range(0, SIZE, [&](int i) {
      this->multiply_column(i, a, b);
    });
  }
};

constexpr int MAX_NUM_TASKS = 32;
constexpr int MAX_STACK_SIZE = 4096 * 1;

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_v3/";
  benchmark_runner runner{full_directory, test_name};
  runner.enable_memory_stats();
  runner.pre_allocate_stats();

  pls_matrix<double, matrix::MATRIX_SIZE> a;
  pls_matrix<double, matrix::MATRIX_SIZE> b;
  pls_matrix<double, matrix::MATRIX_SIZE> result;

  scheduler scheduler{(unsigned) num_threads, MAX_NUM_TASKS, MAX_STACK_SIZE};

//  scheduler.get_profiler().disable_memory_measure();
  runner.run_iterations(matrix::NUM_ITERATIONS, [&]() {
    scheduler.perform_work([&]() {
      result.multiply(a, b);
    });
  }, matrix::WARMUP_ITERATIONS);
//  scheduler.get_profiler().current_run().print_dag(std::cout);
//  scheduler.get_profiler().current_run().print_stats();

  runner.commit_results(true);
}
