• 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 "add.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 vector = ublas::vector<T>;
24   bm::add<vector(vector, vector)> a("add(vector<" + type + ">, vector<" + type + ">)");
25   a.run(std::vector<long>({1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096}));
26 }
27 
main(int argc,char ** argv)28 int main(int argc, char **argv)
29 {
30   po::variables_map vm;
31   try
32   {
33     po::options_description desc("Vector-vector addition\n"
34                                  "Allowed options");
35     desc.add_options()("help,h", "produce help message");
36     desc.add_options()("type,t", po::value<std::string>(), "select value-type (float, double, fcomplex, dcomplex)");
37 
38     po::store(po::parse_command_line(argc, argv, desc), vm);
39     po::notify(vm);
40 
41     if (vm.count("help"))
42     {
43       std::cout << desc << std::endl;
44       return 0;
45     }
46   }
47   catch(std::exception &e)
48   {
49     std::cerr << "error: " << e.what() << std::endl;
50     return 1;
51   }
52   std::string type = vm.count("type") ? vm["type"].as<std::string>() : "float";
53   if (type == "float")
54     benchmark<float>("float");
55   else if (type == "double")
56     benchmark<double>("double");
57   else if (type == "fcomplex")
58     benchmark<std::complex<float>>("std::complex<float>");
59   else if (type == "dcomplex")
60     benchmark<std::complex<double>>("std::complex<double>");
61   else
62     std::cerr << "unsupported value-type \"" << vm["type"].as<std::string>() << '\"' << std::endl;
63 }
64