From 44861dcbfeee041223c4aac1ee075e92fa4daa01 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 18 Sep 2016 12:42:15 +0200 Subject: update --- eigen/bench/sparse_product.cpp | 323 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100644 eigen/bench/sparse_product.cpp (limited to 'eigen/bench/sparse_product.cpp') diff --git a/eigen/bench/sparse_product.cpp b/eigen/bench/sparse_product.cpp new file mode 100644 index 0000000..d2fc44f --- /dev/null +++ b/eigen/bench/sparse_product.cpp @@ -0,0 +1,323 @@ + +//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 + +#include + +#ifndef SIZE +#define SIZE 1000000 +#endif + +#ifndef NNZPERCOL +#define NNZPERCOL 6 +#endif + +#ifndef REPEAT +#define REPEAT 1 +#endif + +#include +#include "BenchTimer.h" +#include "BenchUtil.h" +#include "BenchSparseUtil.h" + +#ifndef NBTRIES +#define NBTRIES 1 +#endif + +#define BENCH(X) \ + timer.reset(); \ + for (int _j=0; _j +// void mkl_multiply(const Lhs& lhs, const Rhs& rhs, Res& res) +// { +// char n = 'N'; +// float alpha = 1; +// char matdescra[6]; +// matdescra[0] = 'G'; +// matdescra[1] = 0; +// matdescra[2] = 0; +// matdescra[3] = 'C'; +// mkl_scscmm(&n, lhs.rows(), rhs.cols(), lhs.cols(), &alpha, matdescra, +// lhs._valuePtr(), lhs._innerIndexPtr(), lhs.outerIndexPtr(), +// pntre, b, &ldb, &beta, c, &ldc); +// // mkl_somatcopy('C', 'T', lhs.rows(), lhs.cols(), 1, +// // lhs._valuePtr(), lhs.rows(), DST, dst_stride); +// } +// +// #endif + + +#ifdef CSPARSE +cs* cs_sorted_multiply(const cs* a, const cs* b) +{ +// return cs_multiply(a,b); + + cs* A = cs_transpose(a, 1); + cs* B = cs_transpose(b, 1); + cs* D = cs_multiply(B,A); /* D = B'*A' */ + cs_spfree (A) ; + cs_spfree (B) ; + cs_dropzeros (D) ; /* drop zeros from D */ + cs* C = cs_transpose (D, 1) ; /* C = D', so that C is sorted */ + cs_spfree (D) ; + return C; + +// cs* A = cs_transpose(a, 1); +// cs* C = cs_transpose(A, 1); +// return C; +} + +cs* cs_sorted_multiply2(const cs* a, const cs* b) +{ + cs* D = cs_multiply(a,b); + cs* E = cs_transpose(D,1); + cs_spfree(D); + cs* C = cs_transpose(E,1); + cs_spfree(E); + return C; +} +#endif + +void bench_sort(); + +int main(int argc, char *argv[]) +{ +// bench_sort(); + + int rows = SIZE; + int cols = SIZE; + float density = DENSITY; + + EigenSparseMatrix sm1(rows,cols), sm2(rows,cols), sm3(rows,cols), sm4(rows,cols); + + BenchTimer timer; + for (int nnzPerCol = NNZPERCOL; nnzPerCol>1; nnzPerCol/=1.1) + { + sm1.setZero(); + sm2.setZero(); + fillMatrix2(nnzPerCol, rows, cols, sm1); + fillMatrix2(nnzPerCol, rows, cols, sm2); +// std::cerr << "filling OK\n"; + + // dense matrices + #ifdef DENSEMATRIX + { + std::cout << "Eigen Dense\t" << nnzPerCol << "%\n"; + DenseMatrix m1(rows,cols), m2(rows,cols), m3(rows,cols); + eiToDense(sm1, m1); + eiToDense(sm2, m2); + + timer.reset(); + timer.start(); + for (int k=0; k m1(sm1), m2(sm2), m3(sm3); + std::cout << "Eigen dyn-sparse\t" << m1.nonZeros()/(float(m1.rows())*float(m1.cols()))*100 << "% * " + << m2.nonZeros()/(float(m2.rows())*float(m2.cols()))*100 << "%\n"; + +// timer.reset(); +// timer.start(); + BENCH(for (int k=0; k