• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
9 #include <boost/numeric/ublas/vector.hpp>
10 #include <boost/numeric/ublas/matrix.hpp>
11 #include <boost/program_options.hpp>
12 #include "prod.hpp"
13 #include <complex>
14 #include <string>
15 
16 namespace po = boost::program_options;
17 namespace ublas = boost::numeric::ublas;
18 namespace bm = boost::numeric::ublas::benchmark;
19 
20 template <typename T>
benchmark(std::string const & type)21 void benchmark(std::string const &type)
22 {
23   using matrix = ublas::matrix<T, ublas::basic_row_major<>>;
24   using vector = ublas::vector<T>;
25   bm::prod<vector(matrix, vector)> p("prod(matrix<" + type + ">, vector<" + type + ">)");
26   p.run(std::vector<long>({1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096}));
27 }
28 
main(int argc,char ** argv)29 int main(int argc, char **argv)
30 {
31   po::variables_map vm;
32   try
33   {
34     po::options_description desc("Matrix-vector product\n"
35                                  "Allowed options");
36     desc.add_options()("help,h", "produce help message");
37     desc.add_options()("type,t", po::value<std::string>(), "select value-type (float, double, fcomplex, dcomplex)");
38 
39     po::store(po::parse_command_line(argc, argv, desc), vm);
40     po::notify(vm);
41 
42     if (vm.count("help"))
43     {
44       std::cout << desc << std::endl;
45       return 0;
46     }
47   }
48   catch(std::exception &e)
49   {
50     std::cerr << "error: " << e.what() << std::endl;
51     return 1;
52   }
53   std::string type = vm.count("type") ? vm["type"].as<std::string>() : "float";
54   if (type == "float")
55     benchmark<float>("float");
56   else if (type == "double")
57     benchmark<double>("double");
58   else if (type == "fcomplex")
59     benchmark<std::complex<float>>("std::complex<float>");
60   else if (type == "dcomplex")
61     benchmark<std::complex<double>>("std::complex<double>");
62   else
63     std::cerr << "unsupported value-type \"" << vm["type"].as<std::string>() << '\"' << std::endl;
64 }
65