From cc6c4d807b107859f88947f7ec440666476fca26 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 17 Jan 2009 14:05:01 +0000 Subject: add a sparse setter bench --- bench/sparse_setter.cpp | 224 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 bench/sparse_setter.cpp (limited to 'bench/sparse_setter.cpp') diff --git a/bench/sparse_setter.cpp b/bench/sparse_setter.cpp new file mode 100644 index 000000000..90112954f --- /dev/null +++ b/bench/sparse_setter.cpp @@ -0,0 +1,224 @@ + +//g++ -O3 -g0 -DNDEBUG sparse_product.cpp -I.. -I/home/gael/Coding/LinearAlgebra/mtl4/ -DDENSITY=0.005 -DSIZE=10000 && ./a.out +//g++ -O3 -g0 -DNDEBUG sparse_product.cpp -I.. -I/home/gael/Coding/LinearAlgebra/mtl4/ -DDENSITY=0.05 -DSIZE=2000 && ./a.out +// -DNOGMM -DNOMTL -DCSPARSE +// -I /home/gael/Coding/LinearAlgebra/CSparse/Include/ /home/gael/Coding/LinearAlgebra/CSparse/Lib/libcsparse.a +#ifndef SIZE +#define SIZE 300000 +#endif + +#ifndef NBPERROW +#define NBPERROW 12 +#endif + +#ifndef REPEAT +#define REPEAT 1 +#endif + +#define EIGEN_GOOGLEHASH_SUPPORT +#include +#include "BenchSparseUtil.h" + + +#define BENCH(X) \ + timer.reset(); \ + for (int _j=0; _j Coordinates; +typedef std::vector Values; + +EIGEN_DONT_INLINE Scalar* setrand_eigen_gnu_hash(const Coordinates& coords, const Values& vals); +EIGEN_DONT_INLINE Scalar* setrand_eigen_google_dense(const Coordinates& coords, const Values& vals); +EIGEN_DONT_INLINE Scalar* setrand_eigen_google_sparse(const Coordinates& coords, const Values& vals); +EIGEN_DONT_INLINE Scalar* setrand_ublas_mapped(const Coordinates& coords, const Values& vals); +EIGEN_DONT_INLINE Scalar* setrand_ublas_coord(const Coordinates& coords, const Values& vals); +EIGEN_DONT_INLINE Scalar* setrand_ublas_compressed(const Coordinates& coords, const Values& vals); +EIGEN_DONT_INLINE Scalar* setrand_mtl(const Coordinates& coords, const Values& vals); + +int main(int argc, char *argv[]) +{ + int rows = SIZE; + int cols = SIZE; + //float density = float(NBPERROW)/float(SIZE); + + BenchTimer timer; + Coordinates coords; + Values values; + for (int i=0; i(0,rows-1),ei_random(0,cols-1))); + values.push_back(ei_random()); + } + std::cout << "nnz = " << coords.size() << "\n"; + + // dense matrices + #ifdef DENSEMATRIX + { + timer.reset(); + timer.start(); + for (int k=0; k mat(SIZE,SIZE); + { + RandomSetter, StdMapTraits > setter(mat); + for (int i=0; i mat(SIZE,SIZE); + { + RandomSetter, GoogleDenseHashMapTraits> setter(mat); + for (int i=0; i mat(SIZE,SIZE); + { + RandomSetter, GoogleSparseHashMapTraits> setter(mat); + for (int i=0; i aux(SIZE,SIZE); + for (int i=0; i mat(aux); + return 0;// &mat(coords[0].x(), coords[0].y()); +} +EIGEN_DONT_INLINE Scalar* setrand_ublas_coord(const Coordinates& coords, const Values& vals) +{ + using namespace boost; + using namespace boost::numeric; + using namespace boost::numeric::ublas; + coordinate_matrix aux(SIZE,SIZE); + for (int i=0; i mat(aux); + return 0;//&mat(coords[0].x(), coords[0].y()); +} +EIGEN_DONT_INLINE Scalar* setrand_ublas_compressed(const Coordinates& coords, const Values& vals) +{ + using namespace boost; + using namespace boost::numeric; + using namespace boost::numeric::ublas; + compressed_matrix mat(SIZE,SIZE); + for (int i=0; i