mirror of
https://github.com/boostorg/ublas.git
synced 2026-02-22 03:42:19 +00:00
Simplified and consolidated
much replicated code consolidated bad compiler workarounds removed Simpiler output format
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
void header (std::string text) {
|
||||
std::cout << text << std::endl;
|
||||
std::cerr << text << std::endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -38,9 +37,6 @@ struct peak_c_plus {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class T>
|
||||
@@ -60,9 +56,6 @@ struct peak_c_multiplies {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,163 +70,57 @@ void peak<T>::operator () (int runs) {
|
||||
peak_c_multiplies<T> () (runs);
|
||||
}
|
||||
|
||||
template struct peak<float>;
|
||||
template struct peak<double>;
|
||||
template struct peak<std::complex<float> >;
|
||||
template struct peak<std::complex<double> >;
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
int __cdecl std_new_handler (unsigned) {
|
||||
throw std::bad_alloc ();
|
||||
template <typename scalar>
|
||||
void do_bench (std::string type_string, int scale)
|
||||
{
|
||||
header (type_string);
|
||||
peak<scalar> () (1000000 * scale);
|
||||
|
||||
header (type_string + ", 3");
|
||||
bench_1<scalar, 3> () (1000000 * scale);
|
||||
bench_2<scalar, 3> () (300000 * scale);
|
||||
bench_3<scalar, 3> () (100000 * scale);
|
||||
|
||||
header (type_string + ", 10");
|
||||
bench_1<scalar, 10> () (300000 * scale);
|
||||
bench_2<scalar, 10> () (30000 * scale);
|
||||
bench_3<scalar, 10> () (3000 * scale);
|
||||
|
||||
header (type_string + ", 30");
|
||||
bench_1<scalar, 30> () (100000 * scale);
|
||||
bench_2<scalar, 30> () (3000 * scale);
|
||||
bench_3<scalar, 30> () (100 * scale);
|
||||
|
||||
header (type_string + ", 100");
|
||||
bench_1<scalar, 100> () (30000 * scale);
|
||||
bench_2<scalar, 100> () (300 * scale);
|
||||
bench_3<scalar, 100> () (3 * scale);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main (int argc, char *argv []) {
|
||||
#ifdef BOOST_MSVC
|
||||
_set_new_handler (std_new_handler);
|
||||
#endif
|
||||
|
||||
#ifdef USE_FLOAT
|
||||
header ("float");
|
||||
peak<float> () (100000000);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("double");
|
||||
peak<double> () (100000000);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
#ifdef USE_FLOAT
|
||||
header ("std:complex<float>");
|
||||
peak<std::complex<float> > () (100000000);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("std:complex<double>");
|
||||
peak<std::complex<double> > () (100000000);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int scale = 1;
|
||||
if (argc > 1)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
scale = std::atoi (argv [1]);
|
||||
#else
|
||||
scale = ::atoi (argv [1]);
|
||||
#endif
|
||||
|
||||
#ifdef USE_FLOAT
|
||||
header ("float, 3");
|
||||
|
||||
bench_1<float, 3> () (1000000 * scale);
|
||||
bench_2<float, 3> () (300000 * scale);
|
||||
bench_3<float, 3> () (100000 * scale);
|
||||
|
||||
header ("float, 10");
|
||||
|
||||
bench_1<float, 10> () (300000 * scale);
|
||||
bench_2<float, 10> () (30000 * scale);
|
||||
bench_3<float, 10> () (3000 * scale);
|
||||
|
||||
header ("float, 30");
|
||||
|
||||
bench_1<float, 30> () (100000 * scale);
|
||||
bench_2<float, 30> () (3000 * scale);
|
||||
bench_3<float, 30> () (100 * scale);
|
||||
|
||||
header ("float, 100");
|
||||
|
||||
bench_1<float, 100> () (30000 * scale);
|
||||
bench_2<float, 100> () (300 * scale);
|
||||
bench_3<float, 100> () (3 * scale);
|
||||
do_bench<float> ("FLOAT", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("double, 3");
|
||||
|
||||
bench_1<double, 3> () (1000000 * scale);
|
||||
bench_2<double, 3> () (300000 * scale);
|
||||
bench_3<double, 3> () (100000 * scale);
|
||||
|
||||
header ("double, 10");
|
||||
|
||||
bench_1<double, 10> () (300000 * scale);
|
||||
bench_2<double, 10> () (30000 * scale);
|
||||
bench_3<double, 10> () (3000 * scale);
|
||||
|
||||
header ("double, 30");
|
||||
|
||||
bench_1<double, 30> () (100000 * scale);
|
||||
bench_2<double, 30> () (3000 * scale);
|
||||
bench_3<double, 30> () (100 * scale);
|
||||
|
||||
header ("double, 100");
|
||||
|
||||
bench_1<double, 100> () (30000 * scale);
|
||||
bench_2<double, 100> () (300 * scale);
|
||||
bench_3<double, 100> () (3 * scale);
|
||||
do_bench<double> ("DOUBLE", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
#ifdef USE_FLOAT
|
||||
header ("std::complex<float>, 3");
|
||||
|
||||
bench_1<std::complex<float>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<float>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<float>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<float>, 10");
|
||||
|
||||
bench_1<std::complex<float>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<float>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<float>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<float>, 30");
|
||||
|
||||
bench_1<std::complex<float>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<float>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<float>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<float>, 100");
|
||||
|
||||
bench_1<std::complex<float>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<float>, 100> () (300 * scale);
|
||||
bench_3<std::complex<float>, 100> () (3 * scale);
|
||||
do_bench<std::complex<float> > ("COMPLEX<FLOAT>", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("std::complex<double>, 3");
|
||||
|
||||
bench_1<std::complex<double>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<double>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<double>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<double>, 10");
|
||||
|
||||
bench_1<std::complex<double>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<double>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<double>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<double>, 30");
|
||||
|
||||
bench_1<std::complex<double>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<double>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<double>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<double>, 100");
|
||||
|
||||
bench_1<std::complex<double>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<double>, 100> () (300 * scale);
|
||||
bench_3<std::complex<double>, 100> () (3 * scale);
|
||||
do_bench<std::complex<double> > ("COMPLEX<DOUBLE>", scale);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -38,10 +38,6 @@ struct footer {
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
std::cerr << "elapsed: " << elapsed << " s, "
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -56,18 +52,9 @@ struct c_matrix_traits {
|
||||
|
||||
template<class T, int N>
|
||||
struct initialize_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
for (int i = 0; i < N; ++ i)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
v [i] = std::rand () * 1.f;
|
||||
#else
|
||||
v [i] = ::rand () * 1.f;
|
||||
#endif
|
||||
// v [i] = 0.f;
|
||||
}
|
||||
};
|
||||
@@ -76,29 +63,16 @@ BOOST_UBLAS_INLINE
|
||||
void initialize_vector (V &v) {
|
||||
int size = v.size ();
|
||||
for (int i = 0; i < size; ++ i)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
v [i] = std::rand () * 1.f;
|
||||
#else
|
||||
v [i] = ::rand () * 1.f;
|
||||
#endif
|
||||
// v [i] = 0.f;
|
||||
}
|
||||
|
||||
template<class T, int N, int M>
|
||||
struct initialize_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (typename c_matrix_traits<T, N, M>::type &m) {
|
||||
#endif
|
||||
for (int i = 0; i < N; ++ i)
|
||||
for (int j = 0; j < M; ++ j)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
m [i] [j] = std::rand () * 1.f;
|
||||
#else
|
||||
m [i] [j] = ::rand () * 1.f;
|
||||
#endif
|
||||
// m [i] [j] = 0.f;
|
||||
}
|
||||
};
|
||||
@@ -109,11 +83,7 @@ void initialize_matrix (M &m) {
|
||||
int size2 = m.size2 ();
|
||||
for (int i = 0; i < size1; ++ i)
|
||||
for (int j = 0; j < size2; ++ j)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
m (i, j) = std::rand () * 1.f;
|
||||
#else
|
||||
m (i, j) = ::rand () * 1.f;
|
||||
#endif
|
||||
// m (i, j) = 0.f;
|
||||
}
|
||||
|
||||
@@ -125,12 +95,7 @@ void sink_scalar (const T &s) {
|
||||
|
||||
template<class T, int N>
|
||||
struct sink_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (const typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
static typename c_vector_traits<T, N>::type g_v;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
g_v [i] = v [i];
|
||||
@@ -144,12 +109,7 @@ void sink_vector (const V &v) {
|
||||
|
||||
template<class T, int N, int M>
|
||||
struct sink_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type &m) {
|
||||
#endif
|
||||
static typename c_matrix_traits<T, N, M>::type g_m;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
for (int j = 0; j < M; ++ j)
|
||||
@@ -185,7 +145,7 @@ struct bench_3 {
|
||||
struct safe_tag {};
|
||||
struct fast_tag {};
|
||||
|
||||
#define USE_FLOAT
|
||||
//#define USE_FLOAT
|
||||
#define USE_DOUBLE
|
||||
// #define USE_STD_COMPLEX
|
||||
|
||||
@@ -193,7 +153,7 @@ struct fast_tag {};
|
||||
// #define USE_BOUNDED_ARRAY
|
||||
#define USE_UNBOUNDED_ARRAY
|
||||
// #define USE_STD_VALARRAY
|
||||
#define USE_STD_VECTOR
|
||||
//#define USE_STD_VECTOR
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -38,9 +38,6 @@ struct bench_c_inner_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -63,9 +60,6 @@ struct bench_my_inner_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -88,9 +82,6 @@ struct bench_cpp_inner_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -115,9 +106,6 @@ struct bench_c_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -139,9 +127,6 @@ struct bench_my_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -158,9 +143,6 @@ struct bench_my_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -182,9 +164,6 @@ struct bench_cpp_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -308,5 +287,3 @@ template struct bench_1<std::complex<double>, 30>;
|
||||
template struct bench_1<std::complex<double>, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -40,9 +40,6 @@ struct bench_c_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -65,9 +62,6 @@ struct bench_my_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -85,9 +79,6 @@ struct bench_my_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -114,9 +105,6 @@ struct bench_cpp_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -145,9 +133,6 @@ struct bench_c_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -170,9 +155,6 @@ struct bench_my_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -190,9 +172,6 @@ struct bench_my_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -218,9 +197,6 @@ struct bench_cpp_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -247,9 +223,6 @@ struct bench_c_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
@@ -271,9 +244,6 @@ struct bench_my_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -290,9 +260,6 @@ struct bench_my_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
@@ -314,9 +281,6 @@ struct bench_cpp_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -525,5 +489,3 @@ template struct bench_2<std::complex<double>, 30>;
|
||||
template struct bench_2<std::complex<double>, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -42,9 +42,6 @@ struct bench_c_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
@@ -66,9 +63,6 @@ struct bench_my_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -85,9 +79,6 @@ struct bench_my_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
@@ -115,9 +106,6 @@ struct bench_cpp_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -206,6 +194,3 @@ template struct bench_3<std::complex<double>, 30>;
|
||||
template struct bench_3<std::complex<double>, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
void header (std::string text) {
|
||||
std::cout << text << std::endl;
|
||||
std::cerr << text << std::endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -38,9 +37,6 @@ struct peak_c_plus {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class T>
|
||||
@@ -60,9 +56,6 @@ struct peak_c_multiplies {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,160 +70,57 @@ void peak<T>::operator () (int runs) {
|
||||
peak_c_multiplies<T> () (runs);
|
||||
}
|
||||
|
||||
template struct peak<float>;
|
||||
template struct peak<double>;
|
||||
template struct peak<std::complex<float> >;
|
||||
template struct peak<std::complex<double> >;
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
int __cdecl std_new_handler (unsigned) {
|
||||
throw std::bad_alloc ();
|
||||
template <typename scalar>
|
||||
void do_bench (std::string type_string, int scale)
|
||||
{
|
||||
header (type_string);
|
||||
peak<scalar> () (1000000 * scale);
|
||||
|
||||
header (type_string + ", 3");
|
||||
bench_1<scalar, 3> () (1000000 * scale);
|
||||
bench_2<scalar, 3> () (300000 * scale);
|
||||
bench_3<scalar, 3> () (100000 * scale);
|
||||
|
||||
header (type_string + ", 10");
|
||||
bench_1<scalar, 10> () (300000 * scale);
|
||||
bench_2<scalar, 10> () (30000 * scale);
|
||||
bench_3<scalar, 10> () (3000 * scale);
|
||||
|
||||
header (type_string + ", 30");
|
||||
bench_1<scalar, 30> () (100000 * scale);
|
||||
bench_2<scalar, 30> () (3000 * scale);
|
||||
bench_3<scalar, 30> () (100 * scale);
|
||||
|
||||
header (type_string + ", 100");
|
||||
bench_1<scalar, 100> () (30000 * scale);
|
||||
bench_2<scalar, 100> () (300 * scale);
|
||||
bench_3<scalar, 100> () (3 * scale);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main (int argc, char *argv []) {
|
||||
#ifdef BOOST_MSVC
|
||||
_set_new_handler (std_new_handler);
|
||||
#endif
|
||||
|
||||
#ifdef USE_FLOAT
|
||||
header ("float");
|
||||
peak<float> () (100000000);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("double");
|
||||
peak<double> () (100000000);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
#ifdef USE_FLOAT
|
||||
header ("std:complex<float>");
|
||||
peak<std::complex<float> > () (100000000);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("std:complex<double>");
|
||||
peak<std::complex<double> > () (100000000);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int scale = 1;
|
||||
if (argc > 1)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
scale = std::atoi (argv [1]);
|
||||
#else
|
||||
scale = ::atoi (argv [1]);
|
||||
#endif
|
||||
|
||||
#ifdef USE_FLOAT
|
||||
header ("float, 3");
|
||||
|
||||
bench_1<float, 3> () (1000000 * scale);
|
||||
bench_2<float, 3> () (300000 * scale);
|
||||
bench_3<float, 3> () (100000 * scale);
|
||||
|
||||
header ("float, 10");
|
||||
|
||||
bench_1<float, 10> () (300000 * scale);
|
||||
bench_2<float, 10> () (30000 * scale);
|
||||
bench_3<float, 10> () (3000 * scale);
|
||||
|
||||
header ("float, 30");
|
||||
|
||||
bench_1<float, 30> () (100000 * scale);
|
||||
bench_2<float, 30> () (3000 * scale);
|
||||
bench_3<float, 30> () (100 * scale);
|
||||
|
||||
header ("float, 100");
|
||||
|
||||
bench_1<float, 100> () (30000 * scale);
|
||||
bench_2<float, 100> () (300 * scale);
|
||||
bench_3<float, 100> () (3 * scale);
|
||||
do_bench<float> ("FLOAT", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("double, 3");
|
||||
|
||||
bench_1<double, 3> () (1000000 * scale);
|
||||
bench_2<double, 3> () (300000 * scale);
|
||||
bench_3<double, 3> () (100000 * scale);
|
||||
|
||||
header ("double, 10");
|
||||
|
||||
bench_1<double, 10> () (300000 * scale);
|
||||
bench_2<double, 10> () (30000 * scale);
|
||||
bench_3<double, 10> () (3000 * scale);
|
||||
|
||||
header ("double, 30");
|
||||
|
||||
bench_1<double, 30> () (100000 * scale);
|
||||
bench_2<double, 30> () (3000 * scale);
|
||||
bench_3<double, 30> () (100 * scale);
|
||||
|
||||
header ("double, 100");
|
||||
|
||||
bench_1<double, 100> () (30000 * scale);
|
||||
bench_2<double, 100> () (300 * scale);
|
||||
bench_3<double, 100> () (3 * scale);
|
||||
do_bench<double> ("DOUBLE", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
#ifdef USE_FLOAT
|
||||
header ("std::complex<float>, 3");
|
||||
|
||||
bench_1<std::complex<float>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<float>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<float>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<float>, 10");
|
||||
|
||||
bench_1<std::complex<float>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<float>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<float>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<float>, 30");
|
||||
|
||||
bench_1<std::complex<float>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<float>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<float>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<float>, 100");
|
||||
|
||||
bench_1<std::complex<float>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<float>, 100> () (300 * scale);
|
||||
bench_3<std::complex<float>, 100> () (3 * scale);
|
||||
do_bench<std::complex<float> > ("COMPLEX<FLOAT>", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("std::complex<double>, 3");
|
||||
|
||||
bench_1<std::complex<double>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<double>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<double>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<double>, 10");
|
||||
|
||||
bench_1<std::complex<double>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<double>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<double>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<double>, 30");
|
||||
|
||||
bench_1<std::complex<double>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<double>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<double>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<double>, 100");
|
||||
|
||||
bench_1<std::complex<double>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<double>, 100> () (300 * scale);
|
||||
bench_3<std::complex<double>, 100> () (3 * scale);
|
||||
do_bench<std::complex<double> > ("COMPLEX<DOUBLE>", scale);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,10 +39,6 @@ struct footer {
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
std::cerr << "elapsed: " << elapsed << " s, "
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -57,18 +53,9 @@ struct c_matrix_traits {
|
||||
|
||||
template<class T, int N>
|
||||
struct initialize_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
for (int i = 0; i < N; ++ i)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
v [i] = std::rand () * 1.f;
|
||||
#else
|
||||
v [i] = ::rand () * 1.f;
|
||||
#endif
|
||||
// v [i] = 0.f;
|
||||
}
|
||||
};
|
||||
@@ -77,29 +64,16 @@ BOOST_UBLAS_INLINE
|
||||
void initialize_vector (V &v) {
|
||||
int size = v.size ();
|
||||
for (int i = 0; i < size; ++ i)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
v [i] = std::rand () * 1.f;
|
||||
#else
|
||||
v [i] = ::rand () * 1.f;
|
||||
#endif
|
||||
// v [i] = 0.f;
|
||||
}
|
||||
|
||||
template<class T, int N, int M>
|
||||
struct initialize_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (typename c_matrix_traits<T, N, M>::type &m) {
|
||||
#endif
|
||||
for (int i = 0; i < N; ++ i)
|
||||
for (int j = 0; j < M; ++ j)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
m [i] [j] = std::rand () * 1.f;
|
||||
#else
|
||||
m [i] [j] = ::rand () * 1.f;
|
||||
#endif
|
||||
// m [i] [j] = 0.f;
|
||||
}
|
||||
};
|
||||
@@ -110,11 +84,7 @@ void initialize_matrix (M &m, ublas::row_major_tag) {
|
||||
int size2 = m.size2 ();
|
||||
for (int i = 0; i < size1; ++ i)
|
||||
for (int j = 0; j < size2; ++ j)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
m (i, j) = std::rand () * 1.f;
|
||||
#else
|
||||
m (i, j) = ::rand () * 1.f;
|
||||
#endif
|
||||
// m (i, j) = 0.f;
|
||||
}
|
||||
template<class M>
|
||||
@@ -124,11 +94,7 @@ void initialize_matrix (M &m, ublas::column_major_tag) {
|
||||
int size2 = m.size2 ();
|
||||
for (int j = 0; j < size2; ++ j)
|
||||
for (int i = 0; i < size1; ++ i)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
m (i, j) = std::rand () * 1.f;
|
||||
#else
|
||||
m (i, j) = ::rand () * 1.f;
|
||||
#endif
|
||||
// m (i, j) = 0.f;
|
||||
}
|
||||
template<class M>
|
||||
@@ -146,12 +112,7 @@ void sink_scalar (const T &s) {
|
||||
|
||||
template<class T, int N>
|
||||
struct sink_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (const typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
static typename c_vector_traits<T, N>::type g_v;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
g_v [i] = v [i];
|
||||
@@ -165,12 +126,7 @@ void sink_vector (const V &v) {
|
||||
|
||||
template<class T, int N, int M>
|
||||
struct sink_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type &m) {
|
||||
#endif
|
||||
static typename c_matrix_traits<T, N, M>::type g_m;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
for (int j = 0; j < M; ++ j)
|
||||
@@ -224,5 +180,3 @@ struct fast_tag {};
|
||||
#define USE_COORDINATE_MATRIX
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -38,9 +38,6 @@ struct bench_c_inner_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -63,9 +60,6 @@ struct bench_my_inner_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -88,9 +82,6 @@ struct bench_cpp_inner_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -115,9 +106,6 @@ struct bench_c_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -139,9 +127,6 @@ struct bench_my_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -158,9 +143,6 @@ struct bench_my_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -182,9 +164,6 @@ struct bench_cpp_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -303,5 +282,3 @@ template struct bench_1<std::complex<double>, 30>;
|
||||
template struct bench_1<std::complex<double>, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -40,9 +40,6 @@ struct bench_c_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -65,9 +62,6 @@ struct bench_my_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -85,9 +79,6 @@ struct bench_my_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -114,9 +105,6 @@ struct bench_cpp_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -145,9 +133,6 @@ struct bench_c_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -170,9 +155,6 @@ struct bench_my_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -190,9 +172,6 @@ struct bench_my_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -218,9 +197,6 @@ struct bench_cpp_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -247,9 +223,6 @@ struct bench_c_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
@@ -271,9 +244,6 @@ struct bench_my_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -290,9 +260,6 @@ struct bench_my_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
@@ -314,9 +281,6 @@ struct bench_cpp_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -503,5 +467,3 @@ template struct bench_2<std::complex<double>, 30>;
|
||||
template struct bench_2<std::complex<double>, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -42,9 +42,6 @@ struct bench_c_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M1, class M2, int N>
|
||||
@@ -67,9 +64,6 @@ struct bench_my_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -87,9 +81,6 @@ struct bench_my_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
@@ -117,9 +108,6 @@ struct bench_cpp_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -210,5 +198,3 @@ template struct bench_3<std::complex<double>, 30>;
|
||||
template struct bench_3<std::complex<double>, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
void header (std::string text) {
|
||||
std::cout << text << std::endl;
|
||||
std::cerr << text << std::endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -38,9 +37,6 @@ struct peak_c_plus {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class T>
|
||||
@@ -60,9 +56,6 @@ struct peak_c_multiplies {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,160 +70,57 @@ void peak<T>::operator () (int runs) {
|
||||
peak_c_multiplies<T> () (runs);
|
||||
}
|
||||
|
||||
template struct peak<float>;
|
||||
template struct peak<double>;
|
||||
template struct peak<std::complex<float> >;
|
||||
template struct peak<std::complex<double> >;
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
int __cdecl std_new_handler (unsigned) {
|
||||
throw std::bad_alloc ();
|
||||
template <typename scalar>
|
||||
void do_bench (std::string type_string, int scale)
|
||||
{
|
||||
header (type_string);
|
||||
peak<scalar> () (1000000 * scale);
|
||||
|
||||
header (type_string + ", 3");
|
||||
bench_1<scalar, 3> () (1000000 * scale);
|
||||
bench_2<scalar, 3> () (300000 * scale);
|
||||
bench_3<scalar, 3> () (100000 * scale);
|
||||
|
||||
header (type_string + ", 10");
|
||||
bench_1<scalar, 10> () (300000 * scale);
|
||||
bench_2<scalar, 10> () (30000 * scale);
|
||||
bench_3<scalar, 10> () (3000 * scale);
|
||||
|
||||
header (type_string + ", 30");
|
||||
bench_1<scalar, 30> () (100000 * scale);
|
||||
bench_2<scalar, 30> () (3000 * scale);
|
||||
bench_3<scalar, 30> () (100 * scale);
|
||||
|
||||
header (type_string + ", 100");
|
||||
bench_1<scalar, 100> () (30000 * scale);
|
||||
bench_2<scalar, 100> () (300 * scale);
|
||||
bench_3<scalar, 100> () (3 * scale);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main (int argc, char *argv []) {
|
||||
#ifdef BOOST_MSVC
|
||||
_set_new_handler (std_new_handler);
|
||||
#endif
|
||||
|
||||
#ifdef USE_FLOAT
|
||||
header ("float");
|
||||
peak<float> () (100000000);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("double");
|
||||
peak<double> () (100000000);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
#ifdef USE_FLOAT
|
||||
header ("std:complex<float>");
|
||||
peak<std::complex<float> > () (100000000);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("std:complex<double>");
|
||||
peak<std::complex<double> > () (100000000);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int scale = 1;
|
||||
if (argc > 1)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
scale = std::atoi (argv [1]);
|
||||
#else
|
||||
scale = ::atoi (argv [1]);
|
||||
#endif
|
||||
|
||||
#ifdef USE_FLOAT
|
||||
header ("float, 3");
|
||||
|
||||
bench_1<float, 3> () (1000000 * scale);
|
||||
bench_2<float, 3> () (300000 * scale);
|
||||
bench_3<float, 3> () (100000 * scale);
|
||||
|
||||
header ("float, 10");
|
||||
|
||||
bench_1<float, 10> () (300000 * scale);
|
||||
bench_2<float, 10> () (30000 * scale);
|
||||
bench_3<float, 10> () (3000 * scale);
|
||||
|
||||
header ("float, 30");
|
||||
|
||||
bench_1<float, 30> () (100000 * scale);
|
||||
bench_2<float, 30> () (3000 * scale);
|
||||
bench_3<float, 30> () (100 * scale);
|
||||
|
||||
header ("float, 100");
|
||||
|
||||
bench_1<float, 100> () (30000 * scale);
|
||||
bench_2<float, 100> () (300 * scale);
|
||||
bench_3<float, 100> () (3 * scale);
|
||||
do_bench<float> ("FLOAT", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("double, 3");
|
||||
|
||||
bench_1<double, 3> () (1000000 * scale);
|
||||
bench_2<double, 3> () (300000 * scale);
|
||||
bench_3<double, 3> () (100000 * scale);
|
||||
|
||||
header ("double, 10");
|
||||
|
||||
bench_1<double, 10> () (300000 * scale);
|
||||
bench_2<double, 10> () (30000 * scale);
|
||||
bench_3<double, 10> () (3000 * scale);
|
||||
|
||||
header ("double, 30");
|
||||
|
||||
bench_1<double, 30> () (100000 * scale);
|
||||
bench_2<double, 30> () (3000 * scale);
|
||||
bench_3<double, 30> () (100 * scale);
|
||||
|
||||
header ("double, 100");
|
||||
|
||||
bench_1<double, 100> () (30000 * scale);
|
||||
bench_2<double, 100> () (300 * scale);
|
||||
bench_3<double, 100> () (3 * scale);
|
||||
do_bench<double> ("DOUBLE", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
#ifdef USE_FLOAT
|
||||
header ("std::complex<float>, 3");
|
||||
|
||||
bench_1<std::complex<float>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<float>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<float>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<float>, 10");
|
||||
|
||||
bench_1<std::complex<float>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<float>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<float>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<float>, 30");
|
||||
|
||||
bench_1<std::complex<float>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<float>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<float>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<float>, 100");
|
||||
|
||||
bench_1<std::complex<float>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<float>, 100> () (300 * scale);
|
||||
bench_3<std::complex<float>, 100> () (3 * scale);
|
||||
do_bench<std::complex<float> > ("COMPLEX<FLOAT>", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("std::complex<double>, 3");
|
||||
|
||||
bench_1<std::complex<double>, 3> () (1000000 * scale);
|
||||
bench_2<std::complex<double>, 3> () (300000 * scale);
|
||||
bench_3<std::complex<double>, 3> () (100000 * scale);
|
||||
|
||||
header ("std::complex<double>, 10");
|
||||
|
||||
bench_1<std::complex<double>, 10> () (300000 * scale);
|
||||
bench_2<std::complex<double>, 10> () (30000 * scale);
|
||||
bench_3<std::complex<double>, 10> () (3000 * scale);
|
||||
|
||||
header ("std::complex<double>, 30");
|
||||
|
||||
bench_1<std::complex<double>, 30> () (100000 * scale);
|
||||
bench_2<std::complex<double>, 30> () (3000 * scale);
|
||||
bench_3<std::complex<double>, 30> () (100 * scale);
|
||||
|
||||
header ("std::complex<double>, 100");
|
||||
|
||||
bench_1<std::complex<double>, 100> () (30000 * scale);
|
||||
bench_2<std::complex<double>, 100> () (300 * scale);
|
||||
bench_3<std::complex<double>, 100> () (3 * scale);
|
||||
do_bench<std::complex<double> > ("COMPLEX<DOUBLE>", scale);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,10 +39,6 @@ struct footer {
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
std::cerr << "elapsed: " << elapsed << " s, "
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -57,18 +53,9 @@ struct c_matrix_traits {
|
||||
|
||||
template<class T, int N>
|
||||
struct initialize_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
for (int i = 0; i < N; ++ i)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
v [i] = std::rand () * 1.f;
|
||||
#else
|
||||
v [i] = ::rand () * 1.f;
|
||||
#endif
|
||||
// v [i] = 0.f;
|
||||
}
|
||||
};
|
||||
@@ -77,29 +64,16 @@ BOOST_UBLAS_INLINE
|
||||
void initialize_vector (V &v) {
|
||||
int size = v.size ();
|
||||
for (int i = 0; i < size; ++ i)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
v [i] = std::rand () * 1.f;
|
||||
#else
|
||||
v [i] = ::rand () * 1.f;
|
||||
#endif
|
||||
// v [i] = 0.f;
|
||||
}
|
||||
|
||||
template<class T, int N, int M>
|
||||
struct initialize_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (typename c_matrix_traits<T, N, M>::type &m) {
|
||||
#endif
|
||||
for (int i = 0; i < N; ++ i)
|
||||
for (int j = 0; j < M; ++ j)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
m [i] [j] = std::rand () * 1.f;
|
||||
#else
|
||||
m [i] [j] = ::rand () * 1.f;
|
||||
#endif
|
||||
// m [i] [j] = 0.f;
|
||||
}
|
||||
};
|
||||
@@ -110,11 +84,7 @@ void initialize_matrix (M &m) {
|
||||
int size2 = m.size2 ();
|
||||
for (int i = 0; i < size1; ++ i)
|
||||
for (int j = 0; j < size2; ++ j)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
m (i, j) = std::rand () * 1.f;
|
||||
#else
|
||||
m (i, j) = ::rand () * 1.f;
|
||||
#endif
|
||||
// m (i, j) = 0.f;
|
||||
}
|
||||
|
||||
@@ -126,12 +96,7 @@ void sink_scalar (const T &s) {
|
||||
|
||||
template<class T, int N>
|
||||
struct sink_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (const typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
static typename c_vector_traits<T, N>::type g_v;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
g_v [i] = v [i];
|
||||
@@ -145,12 +110,7 @@ void sink_vector (const V &v) {
|
||||
|
||||
template<class T, int N, int M>
|
||||
struct sink_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type &m) {
|
||||
#endif
|
||||
static typename c_matrix_traits<T, N, M>::type g_m;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
for (int j = 0; j < M; ++ j)
|
||||
@@ -197,5 +157,3 @@ struct fast_tag {};
|
||||
#define USE_STD_VECTOR
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -38,9 +38,6 @@ struct bench_c_inner_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -65,9 +62,6 @@ struct bench_my_inner_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -90,9 +84,6 @@ struct bench_cpp_inner_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -117,9 +108,6 @@ struct bench_c_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -145,9 +133,6 @@ struct bench_my_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -167,9 +152,6 @@ struct bench_my_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
@@ -191,9 +173,6 @@ struct bench_cpp_vector_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -317,5 +296,3 @@ template struct bench_1<std::complex<double>, 30>;
|
||||
template struct bench_1<std::complex<double>, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -40,9 +40,6 @@ struct bench_c_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -68,9 +65,6 @@ struct bench_my_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -91,9 +85,6 @@ struct bench_my_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -120,9 +111,6 @@ struct bench_cpp_outer_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -151,9 +139,6 @@ struct bench_c_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -179,9 +164,6 @@ struct bench_my_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -202,9 +184,6 @@ struct bench_my_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
@@ -230,9 +209,6 @@ struct bench_cpp_matrix_vector_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -259,9 +235,6 @@ struct bench_c_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
@@ -283,9 +256,6 @@ struct bench_my_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -302,9 +272,6 @@ struct bench_my_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
@@ -326,9 +293,6 @@ struct bench_cpp_matrix_add {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -537,5 +501,3 @@ template struct bench_2<std::complex<double>, 30>;
|
||||
template struct bench_2<std::complex<double>, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -42,9 +42,6 @@ struct bench_c_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
@@ -69,9 +66,6 @@ struct bench_my_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
@@ -91,9 +85,6 @@ struct bench_my_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
@@ -121,9 +112,6 @@ struct bench_cpp_matrix_prod {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -212,5 +200,3 @@ template struct bench_3<std::complex<double>, 30>;
|
||||
template struct bench_3<std::complex<double>, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
// GeNeSys mbH & Co. KG in producing this work.
|
||||
//
|
||||
|
||||
#include "bench4.hpp"
|
||||
#include <boost/numeric/interval.hpp>
|
||||
#include <boost/numeric/interval/io.hpp>
|
||||
#include "../bench1/bench1.hpp"
|
||||
|
||||
void header (std::string text) {
|
||||
std::cout << text << std::endl;
|
||||
std::cerr << text << std::endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -38,9 +39,6 @@ struct peak_c_plus {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class T>
|
||||
@@ -60,9 +58,6 @@ struct peak_c_multiplies {
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -87,155 +82,58 @@ template struct peak<boost::complex<boost::numeric::interval<double> > >;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// Standard new handler is not standard compliant.
|
||||
#include <new.h>
|
||||
int __cdecl std_new_handler (unsigned) {
|
||||
throw std::bad_alloc ();
|
||||
|
||||
|
||||
template <typename scalar>
|
||||
void do_bench (std::string type_string, int scale)
|
||||
{
|
||||
header (type_string);
|
||||
peak<scalar> () (1000000 * scale);
|
||||
|
||||
header (type_string + ", 3");
|
||||
bench_1<scalar, 3> () (1000000 * scale);
|
||||
bench_2<scalar, 3> () (300000 * scale);
|
||||
bench_3<scalar, 3> () (100000 * scale);
|
||||
|
||||
header (type_string + ", 10");
|
||||
bench_1<scalar, 10> () (300000 * scale);
|
||||
bench_2<scalar, 10> () (30000 * scale);
|
||||
bench_3<scalar, 10> () (3000 * scale);
|
||||
|
||||
header (type_string + ", 30");
|
||||
bench_1<scalar, 30> () (100000 * scale);
|
||||
bench_2<scalar, 30> () (3000 * scale);
|
||||
bench_3<scalar, 30> () (100 * scale);
|
||||
|
||||
header (type_string + ", 100");
|
||||
bench_1<scalar, 100> () (30000 * scale);
|
||||
bench_2<scalar, 100> () (300 * scale);
|
||||
bench_3<scalar, 100> () (3 * scale);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main (int argc, char *argv []) {
|
||||
#ifdef BOOST_MSVC
|
||||
_set_new_handler (std_new_handler);
|
||||
#endif
|
||||
|
||||
int scale = 1;
|
||||
if (argc > 1)
|
||||
scale = std::atoi (argv [1]);
|
||||
|
||||
#ifdef USE_FLOAT
|
||||
header ("boost::numeric::interval<float>");
|
||||
peak<boost::numeric::interval<float> > () (100000000);
|
||||
do_bench<boost::numeric::interval<float> > ("boost::numeric::interval<FLOAT>", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("boost::numeric::interval<double>");
|
||||
peak<boost::numeric::interval<double> > () (100000000);
|
||||
do_bench<boost::numeric::interval<double> > ("boost::numeric::interval<DOUBLE>", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_COMPLEX
|
||||
#ifdef USE_FLOAT
|
||||
header ("std:complex<boost::numeric::interval<float> >");
|
||||
peak<boost::complex<boost::numeric::interval<float> > > () (100000000);
|
||||
do_bench<std::complex<boost::numeric::interval<float> > > ("boost::numeric::interval<COMPLEX<FLOAT>>", scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("std:complex<boost::numeric::interval<double> >");
|
||||
peak<boost::complex<boost::numeric::interval<double> > > () (100000000);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int scale = 1;
|
||||
if (argc > 1)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
scale = std::atoi (argv [1]);
|
||||
#else
|
||||
scale = ::atoi (argv [1]);
|
||||
#endif
|
||||
|
||||
#ifdef USE_FLOAT
|
||||
header ("boost::numeric::interval<float>, 3");
|
||||
|
||||
bench_1<boost::numeric::interval<float>, 3> () (1000000 * scale);
|
||||
bench_2<boost::numeric::interval<float>, 3> () (300000 * scale);
|
||||
bench_3<boost::numeric::interval<float>, 3> () (100000 * scale);
|
||||
|
||||
header ("boost::numeric::interval<float>, 10");
|
||||
|
||||
bench_1<boost::numeric::interval<float>, 10> () (300000 * scale);
|
||||
bench_2<boost::numeric::interval<float>, 10> () (30000 * scale);
|
||||
bench_3<boost::numeric::interval<float>, 10> () (3000 * scale);
|
||||
|
||||
header ("boost::numeric::interval<float>, 30");
|
||||
|
||||
bench_1<boost::numeric::interval<float>, 30> () (100000 * scale);
|
||||
bench_2<boost::numeric::interval<float>, 30> () (3000 * scale);
|
||||
bench_3<boost::numeric::interval<float>, 30> () (100 * scale);
|
||||
|
||||
header ("boost::numeric::interval<float>, 100");
|
||||
|
||||
bench_1<boost::numeric::interval<float>, 100> () (30000 * scale);
|
||||
bench_2<boost::numeric::interval<float>, 100> () (300 * scale);
|
||||
bench_3<boost::numeric::interval<float>, 100> () (3 * scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("boost::numeric::interval<double>, 3");
|
||||
|
||||
bench_1<boost::numeric::interval<double>, 3> () (1000000 * scale);
|
||||
bench_2<boost::numeric::interval<double>, 3> () (300000 * scale);
|
||||
bench_3<boost::numeric::interval<double>, 3> () (100000 * scale);
|
||||
|
||||
header ("boost::numeric::interval<double>, 10");
|
||||
|
||||
bench_1<boost::numeric::interval<double>, 10> () (300000 * scale);
|
||||
bench_2<boost::numeric::interval<double>, 10> () (30000 * scale);
|
||||
bench_3<boost::numeric::interval<double>, 10> () (3000 * scale);
|
||||
|
||||
header ("boost::numeric::interval<double>, 30");
|
||||
|
||||
bench_1<boost::numeric::interval<double>, 30> () (100000 * scale);
|
||||
bench_2<boost::numeric::interval<double>, 30> () (3000 * scale);
|
||||
bench_3<boost::numeric::interval<double>, 30> () (100 * scale);
|
||||
|
||||
header ("boost::numeric::interval<double>, 100");
|
||||
|
||||
bench_1<boost::numeric::interval<double>, 100> () (30000 * scale);
|
||||
bench_2<boost::numeric::interval<double>, 100> () (300 * scale);
|
||||
bench_3<boost::numeric::interval<double>, 100> () (3 * scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOOST_COMPLEX
|
||||
#ifdef USE_FLOAT
|
||||
header ("boost::complex<boost::numeric::interval<float> >, 3");
|
||||
|
||||
bench_1<boost::complex<boost::numeric::interval<float> >, 3> () (1000000 * scale);
|
||||
bench_2<boost::complex<boost::numeric::interval<float> >, 3> () (300000 * scale);
|
||||
bench_3<boost::complex<boost::numeric::interval<float> >, 3> () (100000 * scale);
|
||||
|
||||
header ("boost::complex<boost::numeric::interval<float> >, 10");
|
||||
|
||||
bench_1<boost::complex<boost::numeric::interval<float> >, 10> () (300000 * scale);
|
||||
bench_2<boost::complex<boost::numeric::interval<float> >, 10> () (30000 * scale);
|
||||
bench_3<boost::complex<boost::numeric::interval<float> >, 10> () (3000 * scale);
|
||||
|
||||
header ("boost::complex<boost::numeric::interval<float> >, 30");
|
||||
|
||||
bench_1<boost::complex<boost::numeric::interval<float> >, 30> () (100000 * scale);
|
||||
bench_2<boost::complex<boost::numeric::interval<float> >, 30> () (3000 * scale);
|
||||
bench_3<boost::complex<boost::numeric::interval<float> >, 30> () (100 * scale);
|
||||
|
||||
header ("boost::complex<boost::numeric::interval<float> >, 100");
|
||||
|
||||
bench_1<boost::complex<boost::numeric::interval<float> >, 100> () (30000 * scale);
|
||||
bench_2<boost::complex<boost::numeric::interval<float> >, 100> () (300 * scale);
|
||||
bench_3<boost::complex<boost::numeric::interval<float> >, 100> () (3 * scale);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
header ("boost::complex<boost::numeric::interval<double> >, 3");
|
||||
|
||||
bench_1<boost::complex<boost::numeric::interval<double> >, 3> () (1000000 * scale);
|
||||
bench_2<boost::complex<boost::numeric::interval<double> >, 3> () (300000 * scale);
|
||||
bench_3<boost::complex<boost::numeric::interval<double> >, 3> () (100000 * scale);
|
||||
|
||||
header ("boost::complex<boost::numeric::interval<double> >, 10");
|
||||
|
||||
bench_1<boost::complex<boost::numeric::interval<double> >, 10> () (300000 * scale);
|
||||
bench_2<boost::complex<boost::numeric::interval<double> >, 10> () (30000 * scale);
|
||||
bench_3<boost::complex<boost::numeric::interval<double> >, 10> () (3000 * scale);
|
||||
|
||||
header ("boost::complex<boost::numeric::interval<double> >, 30");
|
||||
|
||||
bench_1<boost::complex<boost::numeric::interval<double> >, 30> () (100000 * scale);
|
||||
bench_2<boost::complex<boost::numeric::interval<double> >, 30> () (3000 * scale);
|
||||
bench_3<boost::complex<boost::numeric::interval<double> >, 30> () (100 * scale);
|
||||
|
||||
header ("boost::complex<boost::numeric::interval<double> >, 100");
|
||||
|
||||
bench_1<boost::complex<boost::numeric::interval<double> >, 100> () (30000 * scale);
|
||||
bench_2<boost::complex<boost::numeric::interval<double> >, 100> () (300 * scale);
|
||||
bench_3<boost::complex<boost::numeric::interval<double> >, 100> () (3 * scale);
|
||||
do_bench<std::complex<doublboost::numeric::interval<double> > > ("boost::numeric::interval<COMPLEX<DOUBLE>>", scale);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2000-2002
|
||||
// Joerg Walter, Mathias Koch
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appear in all copies and
|
||||
// that both that copyright notice and this permission notice appear
|
||||
// in supporting documentation. The authors make no representations
|
||||
// about the suitability of this software for any purpose.
|
||||
// It is provided "as is" without express or implied warranty.
|
||||
//
|
||||
// The authors gratefully acknowledge the support of
|
||||
// GeNeSys mbH & Co. KG in producing this work.
|
||||
//
|
||||
|
||||
#ifndef BENCH4_H
|
||||
#define BENCH4_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <valarray>
|
||||
|
||||
#include <boost/numeric/interval.hpp>
|
||||
#include <boost/numeric/interval/io.hpp>
|
||||
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
namespace ublas = boost::numeric::ublas;
|
||||
|
||||
void header (std::string text);
|
||||
|
||||
template<class T>
|
||||
struct footer {
|
||||
void operator () (int multiplies, int plus, int runs, double elapsed) {
|
||||
std::cout << "elapsed: " << elapsed << " s, "
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
std::cerr << "elapsed: " << elapsed << " s, "
|
||||
<< (multiplies * ublas::type_traits<T>::multiplies_complexity +
|
||||
plus * ublas::type_traits<T>::plus_complexity) * runs /
|
||||
(1024 * 1024 * elapsed) << " Mflops" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct c_vector_traits {
|
||||
typedef T type [N];
|
||||
};
|
||||
template<class T, int N, int M>
|
||||
struct c_matrix_traits {
|
||||
typedef T type [N] [M];
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct initialize_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
for (int i = 0; i < N; ++ i)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
v [i] = std::rand () * 1.f;
|
||||
#else
|
||||
v [i] = ::rand () * 1.f;
|
||||
#endif
|
||||
// v [i] = 0.f;
|
||||
}
|
||||
};
|
||||
template<class V>
|
||||
BOOST_UBLAS_INLINE
|
||||
void initialize_vector (V &v) {
|
||||
int size = v.size ();
|
||||
for (int i = 0; i < size; ++ i)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
v [i] = std::rand () * 1.f;
|
||||
#else
|
||||
v [i] = ::rand () * 1.f;
|
||||
#endif
|
||||
// v [i] = 0.f;
|
||||
}
|
||||
|
||||
template<class T, int N, int M>
|
||||
struct initialize_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (typename c_matrix_traits<T, N, M>::type &m) {
|
||||
#endif
|
||||
for (int i = 0; i < N; ++ i)
|
||||
for (int j = 0; j < M; ++ j)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
m [i] [j] = std::rand () * 1.f;
|
||||
#else
|
||||
m [i] [j] = ::rand () * 1.f;
|
||||
#endif
|
||||
// m [i] [j] = 0.f;
|
||||
}
|
||||
};
|
||||
template<class M>
|
||||
BOOST_UBLAS_INLINE
|
||||
void initialize_matrix (M &m) {
|
||||
int size1 = m.size1 ();
|
||||
int size2 = m.size2 ();
|
||||
for (int i = 0; i < size1; ++ i)
|
||||
for (int j = 0; j < size2; ++ j)
|
||||
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||
m (i, j) = std::rand () * 1.f;
|
||||
#else
|
||||
m (i, j) = ::rand () * 1.f;
|
||||
#endif
|
||||
// m (i, j) = 0.f;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_scalar (const T &s) {
|
||||
static T g_s = s;
|
||||
}
|
||||
|
||||
template<class T, int N>
|
||||
struct sink_c_vector {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_vector_traits<T, N>::type v) {
|
||||
#else
|
||||
void operator () (const typename c_vector_traits<T, N>::type &v) {
|
||||
#endif
|
||||
static typename c_vector_traits<T, N>::type g_v;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
g_v [i] = v [i];
|
||||
}
|
||||
};
|
||||
template<class V>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_vector (const V &v) {
|
||||
static V g_v (v);
|
||||
}
|
||||
|
||||
template<class T, int N, int M>
|
||||
struct sink_c_matrix {
|
||||
#ifdef BOOST_MSVC
|
||||
BOOST_UBLAS_INLINE
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type m) {
|
||||
#else
|
||||
void operator () (const typename c_matrix_traits<T, N, M>::type &m) {
|
||||
#endif
|
||||
static typename c_matrix_traits<T, N, M>::type g_m;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
for (int j = 0; j < M; ++ j)
|
||||
g_m [i] [j] = m [i] [j];
|
||||
}
|
||||
};
|
||||
template<class M>
|
||||
BOOST_UBLAS_INLINE
|
||||
void sink_matrix (const M &m) {
|
||||
static M g_m (m);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct peak {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_1 {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_2 {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_3 {
|
||||
void operator () (int runs);
|
||||
};
|
||||
|
||||
struct safe_tag {};
|
||||
struct fast_tag {};
|
||||
|
||||
// #define USE_FLOAT
|
||||
#define USE_DOUBLE
|
||||
// #define USE_STD_COMPLEX
|
||||
|
||||
#define USE_C_ARRAY
|
||||
// #define USE_BOUNDED_ARRAY
|
||||
#define USE_UNBOUNDED_ARRAY
|
||||
// #define USE_STD_VALARRAY
|
||||
#define USE_STD_VECTOR
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -14,270 +14,10 @@
|
||||
// GeNeSys mbH & Co. KG in producing this work.
|
||||
//
|
||||
|
||||
#include "bench4.hpp"
|
||||
#include <boost/numeric/interval.hpp>
|
||||
#include <boost/numeric/interval/io.hpp>
|
||||
#include "../bench1/bench11.cpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_inner_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (v2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
static value_type s (0);
|
||||
for (int j = 0; j < N; ++ j) {
|
||||
s += v1 [j] * v2 [j];
|
||||
}
|
||||
// sink_scalar (s);
|
||||
}
|
||||
footer<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
struct bench_my_inner_prod {
|
||||
typedef typename V::value_type value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static V v1 (N), v2 (N);
|
||||
initialize_vector (v1);
|
||||
initialize_vector (v2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
static value_type s (0);
|
||||
s = ublas::inner_prod (v1, v2);
|
||||
// sink_scalar (s);
|
||||
}
|
||||
footer<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
struct bench_cpp_inner_prod {
|
||||
typedef typename V::value_type value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static V v1 (N), v2 (N);
|
||||
initialize_vector (v1);
|
||||
initialize_vector (v2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
static value_type s (0);
|
||||
s = (v1 * v2).sum ();
|
||||
// sink_scalar (s);
|
||||
}
|
||||
footer<value_type> () (N, N - 1, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_vector_add {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_vector_traits<T, N>::type v1, v2, v3;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (v2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
for (int j = 0; j < N; ++ j) {
|
||||
v3 [j] = - (v1 [j] + v2 [j]);
|
||||
}
|
||||
// sink_c_vector<T, N> () (v3);
|
||||
}
|
||||
footer<value_type> () (0, 2 * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
struct bench_my_vector_add {
|
||||
typedef typename V::value_type value_type;
|
||||
|
||||
void operator () (int runs, safe_tag) const {
|
||||
try {
|
||||
static V v1 (N), v2 (N), v3 (N);
|
||||
initialize_vector (v1);
|
||||
initialize_vector (v2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
v3 = - (v1 + v2);
|
||||
// sink_vector (v3);
|
||||
}
|
||||
footer<value_type> () (0, 2 * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
static V v1 (N), v2 (N), v3 (N);
|
||||
initialize_vector (v1);
|
||||
initialize_vector (v2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
v3.assign (- (v1 + v2));
|
||||
// sink_vector (v3);
|
||||
}
|
||||
footer<value_type> () (0, 2 * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class V, int N>
|
||||
struct bench_cpp_vector_add {
|
||||
typedef typename V::value_type value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static V v1 (N), v2 (N), v3 (N);
|
||||
initialize_vector (v1);
|
||||
initialize_vector (v2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
v3 = - (v1 + v2);
|
||||
// sink_vector (v3);
|
||||
}
|
||||
footer<value_type> () (0, 2 * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Benchmark O (n)
|
||||
template<class T, int N>
|
||||
void bench_1<T, N>::operator () (int runs) {
|
||||
header ("bench_1");
|
||||
|
||||
header ("inner_prod");
|
||||
|
||||
header ("C array");
|
||||
bench_c_inner_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_vector");
|
||||
bench_my_inner_prod<ublas::c_vector<T, N>, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("vector<bounded_array>");
|
||||
bench_my_inner_prod<ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("vector<unbounded_array>");
|
||||
bench_my_inner_prod<ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("vector<std::valarray>");
|
||||
bench_my_inner_prod<ublas::vector<T, std::valarray<T> >, N> () ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("vector<std::vector>");
|
||||
bench_my_inner_prod<ublas::vector<T, std::vector<T> >, N> () (runs);
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_inner_prod<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("vector + vector");
|
||||
|
||||
header ("C array");
|
||||
bench_c_vector_add<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_vector safe");
|
||||
bench_my_vector_add<ublas::c_vector<T, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_vector fast");
|
||||
bench_my_vector_add<ublas::c_vector<T, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("vector<bounded_array> safe");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<bounded_array> fast");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("vector<unbounded_array> safe");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<unbounded_array> fast");
|
||||
bench_my_vector_add<ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("vector<std::valarray> safe");
|
||||
bench_my_vector_add<ublas::vector<T, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<std::valarray> fast");
|
||||
bench_my_vector_add<ublas::vector<T, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("vector<std::vector> safe");
|
||||
bench_my_vector_add<ublas::vector<T, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("vector<std::vector> fast");
|
||||
bench_my_vector_add<ublas::vector<T, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_vector_add<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_FLOAT
|
||||
template struct bench_1<boost::numeric::interval<float>, 3>;
|
||||
@@ -308,5 +48,3 @@ template struct bench_1<boost::complex<boost::numeric::interval<double> >, 30>;
|
||||
template struct bench_1<boost::complex<boost::numeric::interval<double> >, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -14,487 +14,10 @@
|
||||
// GeNeSys mbH & Co. KG in producing this work.
|
||||
//
|
||||
|
||||
#include "bench4.hpp"
|
||||
#include <boost/numeric/interval.hpp>
|
||||
#include <boost/numeric/interval/io.hpp>
|
||||
#include "../bench1/bench12.cpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_outer_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m;
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
initialize_c_vector<T, N> () (v2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
for (int j = 0; j < N; ++ j) {
|
||||
for (int k = 0; k < N; ++ k) {
|
||||
m [j] [k] = - v1 [j] * v2 [k];
|
||||
}
|
||||
}
|
||||
// sink_c_matrix<T, N, N> () (m);
|
||||
}
|
||||
footer<value_type> () (N * N, N * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
struct bench_my_outer_prod {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
void operator () (int runs, safe_tag) const {
|
||||
try {
|
||||
static M m (N, N);
|
||||
static V v1 (N), v2 (N);
|
||||
initialize_vector (v1);
|
||||
initialize_vector (v2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
m = - ublas::outer_prod (v1, v2);
|
||||
// sink_matrix (m);
|
||||
}
|
||||
footer<value_type> () (N * N, N * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
static M m (N, N);
|
||||
static V v1 (N), v2 (N);
|
||||
initialize_vector (v1);
|
||||
initialize_vector (v2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
m.assign (- ublas::outer_prod (v1, v2));
|
||||
// sink_matrix (m);
|
||||
}
|
||||
footer<value_type> () (N * N, N * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
struct bench_cpp_outer_prod {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static M m (N * N);
|
||||
static V v1 (N), v2 (N);
|
||||
initialize_vector (v1);
|
||||
initialize_vector (v2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
for (int j = 0; j < N; ++ j) {
|
||||
for (int k = 0; k < N; ++ k) {
|
||||
m [N * j + k] = - v1 [j] * v2 [k];
|
||||
}
|
||||
}
|
||||
// sink_vector (m);
|
||||
}
|
||||
footer<value_type> () (N * N, N * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_matrix_vector_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m;
|
||||
static typename c_vector_traits<T, N>::type v1, v2;
|
||||
initialize_c_matrix<T, N, N> () (m);
|
||||
initialize_c_vector<T, N> () (v1);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
for (int j = 0; j < N; ++ j) {
|
||||
v2 [j] = 0;
|
||||
for (int k = 0; k < N; ++ k) {
|
||||
v2 [j] += m [j] [k] * v1 [k];
|
||||
}
|
||||
}
|
||||
// sink_c_vector<T, N> () (v2);
|
||||
}
|
||||
footer<value_type> () (N * N, N * (N - 1), runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
struct bench_my_matrix_vector_prod {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
void operator () (int runs, safe_tag) const {
|
||||
try {
|
||||
static M m (N, N);
|
||||
static V v1 (N), v2 (N);
|
||||
initialize_matrix (m);
|
||||
initialize_vector (v1);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
v2 = ublas::prod (m, v1);
|
||||
// sink_vector (v2);
|
||||
}
|
||||
footer<value_type> () (N * N, N * (N - 1), runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
static M m (N, N);
|
||||
static V v1 (N), v2 (N);
|
||||
initialize_matrix (m);
|
||||
initialize_vector (v1);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
v2.assign (ublas::prod (m, v1));
|
||||
// sink_vector (v2);
|
||||
}
|
||||
footer<value_type> () (N * N, N * (N - 1), runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, class V, int N>
|
||||
struct bench_cpp_matrix_vector_prod {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static M m (N * N);
|
||||
static V v1 (N), v2 (N);
|
||||
initialize_vector (m);
|
||||
initialize_vector (v1);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
for (int j = 0; j < N; ++ j) {
|
||||
std::valarray<value_type> row (m [std::slice (N * j, N, 1)]);
|
||||
v2 [j] = (row * v1).sum ();
|
||||
}
|
||||
// sink_vector (v2);
|
||||
}
|
||||
footer<value_type> () (N * N, N * (N - 1), runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_matrix_add {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m1, m2, m3;
|
||||
initialize_c_matrix<T, N, N> () (m1);
|
||||
initialize_c_matrix<T, N, N> () (m2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
for (int j = 0; j < N; ++ j) {
|
||||
for (int k = 0; k < N; ++ k) {
|
||||
m3 [j] [k] = - (m1 [j] [k] + m2 [j] [k]);
|
||||
}
|
||||
}
|
||||
// sink_c_matrix<T, N, N> () (m3);
|
||||
}
|
||||
footer<value_type> () (0, 2 * N * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
struct bench_my_matrix_add {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
void operator () (int runs, safe_tag) const {
|
||||
try {
|
||||
static M m1 (N, N), m2 (N, N), m3 (N, N);
|
||||
initialize_matrix (m1);
|
||||
initialize_matrix (m2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
m3 = - (m1 + m2);
|
||||
// sink_matrix (m3);
|
||||
}
|
||||
footer<value_type> () (0, 2 * N * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
static M m1 (N, N), m2 (N, N), m3 (N, N);
|
||||
initialize_matrix (m1);
|
||||
initialize_matrix (m2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
m3.assign (- (m1 + m2));
|
||||
// sink_matrix (m3);
|
||||
}
|
||||
footer<value_type> () (0, 2 * N * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
struct bench_cpp_matrix_add {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static M m1 (N * N), m2 (N * N), m3 (N * N);
|
||||
initialize_vector (m1);
|
||||
initialize_vector (m2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
m3 = - (m1 + m2);
|
||||
// sink_vector (m3);
|
||||
}
|
||||
footer<value_type> () (0, 2 * N * N, runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Benchmark O (n ^ 2)
|
||||
template<class T, int N>
|
||||
void bench_2<T, N>::operator () (int runs) {
|
||||
header ("bench_2");
|
||||
|
||||
header ("outer_prod");
|
||||
|
||||
header ("C array");
|
||||
bench_c_outer_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix, c_vector safe");
|
||||
bench_my_outer_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix, c_vector fast");
|
||||
bench_my_outer_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array>, vector<bounded_array> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array>, vector<bounded_array> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray>, vector<std::valarray> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray>, vector<std::valarray> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector>, vector<std::vector> safe");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector>, vector<std::vector> fast");
|
||||
bench_my_outer_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_outer_prod<std::valarray<T>, std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("prod (matrix, vector)");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_vector_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix, c_vector safe");
|
||||
bench_my_matrix_vector_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix, c_vector fast");
|
||||
bench_my_matrix_vector_prod<ublas::c_matrix<T, N, N>,
|
||||
ublas::c_vector<T, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array>, vector<bounded_array> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array>, vector<bounded_array> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >,
|
||||
ublas::vector<T, ublas::bounded_array<T, N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array>, vector<unbounded_array> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >,
|
||||
ublas::vector<T, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray>, vector<std::valarray> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray>, vector<std::valarray> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >,
|
||||
ublas::vector<T, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector>, vector<std::vector> safe");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector>, vector<std::vector> fast");
|
||||
bench_my_matrix_vector_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >,
|
||||
ublas::vector<T, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_vector_prod<std::valarray<T>, std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
|
||||
header ("matrix + matrix");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_add<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix safe");
|
||||
bench_my_matrix_add<ublas::c_matrix<T, N, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix fast");
|
||||
bench_my_matrix_add<ublas::c_matrix<T, N, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector> safe");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector> fast");
|
||||
bench_my_matrix_add<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_add<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_FLOAT
|
||||
template struct bench_2<boost::numeric::interval<float>, 3>;
|
||||
@@ -525,5 +48,3 @@ template struct bench_2<boost::complex<boost::numeric::interval<double> >, 30>;
|
||||
template struct bench_2<boost::complex<boost::numeric::interval<double> >, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -14,168 +14,10 @@
|
||||
// GeNeSys mbH & Co. KG in producing this work.
|
||||
//
|
||||
|
||||
#include "bench4.hpp"
|
||||
#include <boost/numeric/interval.hpp>
|
||||
#include <boost/numeric/interval/io.hpp>
|
||||
#include "../bench1/bench13.cpp"
|
||||
|
||||
template<class T, int N>
|
||||
struct bench_c_matrix_prod {
|
||||
typedef T value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static typename c_matrix_traits<T, N, N>::type m1, m2, m3;
|
||||
initialize_c_matrix<T, N, N> () (m1);
|
||||
initialize_c_matrix<T, N, N> () (m2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
for (int j = 0; j < N; ++ j) {
|
||||
for (int k = 0; k < N; ++ k) {
|
||||
m3 [j] [k] = 0;
|
||||
for (int l = 0; l < N; ++ l) {
|
||||
m3 [j] [k] += m1 [j] [l] * m2 [l] [k];
|
||||
}
|
||||
}
|
||||
}
|
||||
// sink_c_matrix<T, N, N> () (m3);
|
||||
}
|
||||
footer<value_type> () (N * N * N, N * N * (N - 1), runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
struct bench_my_matrix_prod {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
void operator () (int runs, safe_tag) const {
|
||||
try {
|
||||
static M m1 (N, N), m2 (N, N), m3 (N, N);
|
||||
initialize_matrix (m1);
|
||||
initialize_matrix (m2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
m3 = ublas::prod (m1, m2);
|
||||
// sink_matrix (m3);
|
||||
}
|
||||
footer<value_type> () (N * N * N, N * N * (N - 1), runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
void operator () (int runs, fast_tag) const {
|
||||
try {
|
||||
static M m1 (N, N), m2 (N, N), m3 (N, N);
|
||||
initialize_matrix (m1);
|
||||
initialize_matrix (m2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
m3.assign (ublas::prod (m1, m2));
|
||||
// sink_matrix (m3);
|
||||
}
|
||||
footer<value_type> () (N * N * N, N * N * (N - 1), runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
template<class M, int N>
|
||||
struct bench_cpp_matrix_prod {
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
void operator () (int runs) const {
|
||||
try {
|
||||
static M m1 (N * N), m2 (N * N), m3 (N * N);
|
||||
initialize_vector (m1);
|
||||
initialize_vector (m2);
|
||||
boost::timer t;
|
||||
for (int i = 0; i < runs; ++ i) {
|
||||
for (int j = 0; j < N; ++ j) {
|
||||
std::valarray<value_type> row (m1 [std::slice (N * j, N, 1)]);
|
||||
for (int k = 0; k < N; ++ k) {
|
||||
std::valarray<value_type> column (m2 [std::slice (k, N, N)]);
|
||||
m3 [N * j + k] = (row * column).sum ();
|
||||
}
|
||||
}
|
||||
// sink_vector (m3);
|
||||
}
|
||||
footer<value_type> () (N * N * N, N * N * (N - 1), runs, t.elapsed ());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what () << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "unknown exception" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Benchmark O (n ^ 3)
|
||||
template<class T, int N>
|
||||
void bench_3<T, N>::operator () (int runs) {
|
||||
header ("bench_3");
|
||||
|
||||
header ("prod (matrix, matrix)");
|
||||
|
||||
header ("C array");
|
||||
bench_c_matrix_prod<T, N> () (runs);
|
||||
|
||||
#ifdef USE_C_ARRAY
|
||||
header ("c_matrix safe");
|
||||
bench_my_matrix_prod<ublas::c_matrix<T, N, N>, N> () (runs, safe_tag ());
|
||||
|
||||
header ("c_matrix fast");
|
||||
bench_my_matrix_prod<ublas::c_matrix<T, N, N>, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_BOUNDED_ARRAY
|
||||
header ("matrix<bounded_array> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<bounded_array> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::bounded_array<T, N * N> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNBOUNDED_ARRAY
|
||||
header ("matrix<unbounded_array> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<unbounded_array> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, ublas::unbounded_array<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("matrix<std::valarray> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::valarray> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::valarray<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VECTOR
|
||||
header ("matrix<std::vector> safe");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, safe_tag ());
|
||||
|
||||
header ("matrix<std::vector> fast");
|
||||
bench_my_matrix_prod<ublas::matrix<T, ublas::row_major, std::vector<T> >, N> () (runs, fast_tag ());
|
||||
#endif
|
||||
|
||||
#ifdef USE_STD_VALARRAY
|
||||
header ("std::valarray");
|
||||
bench_cpp_matrix_prod<std::valarray<T>, N> () (runs);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_FLOAT
|
||||
template struct bench_3<boost::numeric::interval<float>, 3>;
|
||||
@@ -206,5 +48,3 @@ template struct bench_3<boost::complex<boost::numeric::interval<double> >, 30>;
|
||||
template struct bench_3<boost::complex<boost::numeric::interval<double> >, 100>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=doc/index.htm">
|
||||
</head>
|
||||
<body>
|
||||
Awaiting automatic redirection to uBLAS documentation index.
|
||||
Please go to <a href="doc/index.htm">doc/index.htm</a>.
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user