]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/ublas/benchmarks/reference/add.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / numeric / ublas / benchmarks / reference / add.cpp
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/matrix.hpp>
10 #include <boost/numeric/ublas/vector.hpp>
11 #include <boost/program_options.hpp>
12 #include "../init.hpp"
13 #include "../benchmark.hpp"
14 #include <complex>
15 #include <string>
16
17 namespace po = boost::program_options;
18 namespace ublas = boost::numeric::ublas;
19 namespace boost { namespace numeric { namespace ublas { namespace benchmark {
20
21 template <typename T>
22 class add : public benchmark
23 {
24 public:
25 add(std::string const &name) : benchmark(name) {}
26 virtual void setup(long l)
27 {
28 init(a, l, 200);
29 init(b, l, 200);
30 }
31 virtual void operation(long l)
32 {
33 for (int i = 0; i < l; ++i)
34 c(i) = a(i) + b(i);
35 }
36 private:
37 ublas::vector<T> a;
38 ublas::vector<T> b;
39 ublas::vector<T> c;
40 };
41
42 }}}}
43
44 namespace bm = boost::numeric::ublas::benchmark;
45
46 template <typename T>
47 void benchmark(std::string const &type)
48 {
49 bm::add<T> p("ref::add(vector<" + type + ">)");
50 p.run(std::vector<long>({1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096}));
51 }
52
53 int main(int argc, char **argv)
54 {
55 po::variables_map vm;
56 try
57 {
58 po::options_description desc("Vector-vector addition (reference implementation)\n"
59 "Allowed options");
60 desc.add_options()("help,h", "produce help message");
61 desc.add_options()("type,t", po::value<std::string>(), "select value-type (float, double, fcomplex, dcomplex)");
62
63 po::store(po::parse_command_line(argc, argv, desc), vm);
64 po::notify(vm);
65
66 if (vm.count("help"))
67 {
68 std::cout << desc << std::endl;
69 return 0;
70 }
71 }
72 catch(std::exception &e)
73 {
74 std::cerr << "error: " << e.what() << std::endl;
75 return 1;
76 }
77 std::string type = vm.count("type") ? vm["type"].as<std::string>() : "float";
78 if (type == "float")
79 benchmark<float>("float");
80 else if (type == "double")
81 benchmark<double>("double");
82 else if (type == "fcomplex")
83 benchmark<std::complex<float>>("std::complex<float>");
84 else if (type == "dcomplex")
85 benchmark<std::complex<double>>("std::complex<double>");
86 else
87 std::cerr << "unsupported value-type \"" << vm["type"].as<std::string>() << '\"' << std::endl;
88 }