mm_prod.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // Copyright (c) 2018 Stefan Seefeld
  3. // All rights reserved.
  4. //
  5. // This file is part of Boost.uBLAS. It is made available under the
  6. // Boost Software License, Version 1.0.
  7. // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt)
  8. #include <boost/numeric/ublas/matrix.hpp>
  9. #include <boost/program_options.hpp>
  10. #include "prod.hpp"
  11. #include <complex>
  12. #include <string>
  13. namespace po = boost::program_options;
  14. namespace ublas = boost::numeric::ublas;
  15. namespace bm = boost::numeric::ublas::benchmark;
  16. template <typename T>
  17. void benchmark(std::string const &type)
  18. {
  19. using matrix = ublas::matrix<T, ublas::basic_row_major<>>;
  20. bm::prod<matrix(matrix, matrix)> p("prod(matrix<" + type + ">)");
  21. p.run(std::vector<long>({1, 2, 4, 8, 16, 32, 64, 128, 256, 512}));//, 1024}));
  22. }
  23. int main(int argc, char **argv)
  24. {
  25. po::variables_map vm;
  26. try
  27. {
  28. po::options_description desc("Matrix product\n"
  29. "Allowed options");
  30. desc.add_options()("help,h", "produce help message");
  31. desc.add_options()("type,t", po::value<std::string>(), "select value-type (float, double, fcomplex, dcomplex)");
  32. po::store(po::parse_command_line(argc, argv, desc), vm);
  33. po::notify(vm);
  34. if (vm.count("help"))
  35. {
  36. std::cout << desc << std::endl;
  37. return 0;
  38. }
  39. }
  40. catch(std::exception &e)
  41. {
  42. std::cerr << "error: " << e.what() << std::endl;
  43. return 1;
  44. }
  45. std::string type = vm.count("type") ? vm["type"].as<std::string>() : "float";
  46. if (type == "float")
  47. benchmark<float>("float");
  48. else if (type == "double")
  49. benchmark<double>("double");
  50. else if (type == "fcomplex")
  51. benchmark<std::complex<float>>("std::complex<float>");
  52. else if (type == "dcomplex")
  53. benchmark<std::complex<double>>("std::complex<double>");
  54. else
  55. std::cerr << "unsupported value-type \"" << vm["type"].as<std::string>() << '\"' << std::endl;
  56. }