You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.3 KiB

  1. //g++ -O3 -g0 -DNDEBUG sparse_transpose.cpp -I.. -I/home/gael/Coding/LinearAlgebra/mtl4/ -DDENSITY=0.005 -DSIZE=10000 && ./a.out
  2. // -DNOGMM -DNOMTL
  3. // -DCSPARSE -I /home/gael/Coding/LinearAlgebra/CSparse/Include/ /home/gael/Coding/LinearAlgebra/CSparse/Lib/libcsparse.a
  4. #ifndef SIZE
  5. #define SIZE 10000
  6. #endif
  7. #ifndef DENSITY
  8. #define DENSITY 0.01
  9. #endif
  10. #ifndef REPEAT
  11. #define REPEAT 1
  12. #endif
  13. #include "BenchSparseUtil.h"
  14. #ifndef MINDENSITY
  15. #define MINDENSITY 0.0004
  16. #endif
  17. #ifndef NBTRIES
  18. #define NBTRIES 10
  19. #endif
  20. #define BENCH(X) \
  21. timer.reset(); \
  22. for (int _j=0; _j<NBTRIES; ++_j) { \
  23. timer.start(); \
  24. for (int _k=0; _k<REPEAT; ++_k) { \
  25. X \
  26. } timer.stop(); }
  27. int main(int argc, char *argv[])
  28. {
  29. int rows = SIZE;
  30. int cols = SIZE;
  31. float density = DENSITY;
  32. EigenSparseMatrix sm1(rows,cols), sm3(rows,cols);
  33. BenchTimer timer;
  34. for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
  35. {
  36. fillMatrix(density, rows, cols, sm1);
  37. // dense matrices
  38. #ifdef DENSEMATRIX
  39. {
  40. DenseMatrix m1(rows,cols), m3(rows,cols);
  41. eiToDense(sm1, m1);
  42. BENCH(for (int k=0; k<REPEAT; ++k) m3 = m1.transpose();)
  43. std::cout << " Eigen dense:\t" << timer.value() << endl;
  44. }
  45. #endif
  46. std::cout << "Non zeros: " << sm1.nonZeros()/float(sm1.rows()*sm1.cols())*100 << "%\n";
  47. // eigen sparse matrices
  48. {
  49. BENCH(for (int k=0; k<REPEAT; ++k) sm3 = sm1.transpose();)
  50. std::cout << " Eigen:\t" << timer.value() << endl;
  51. }
  52. // CSparse
  53. #ifdef CSPARSE
  54. {
  55. cs *m1, *m3;
  56. eiToCSparse(sm1, m1);
  57. BENCH(for (int k=0; k<REPEAT; ++k) { m3 = cs_transpose(m1,1); cs_spfree(m3);})
  58. std::cout << " CSparse:\t" << timer.value() << endl;
  59. }
  60. #endif
  61. // GMM++
  62. #ifndef NOGMM
  63. {
  64. GmmDynSparse gmmT3(rows,cols);
  65. GmmSparse m1(rows,cols), m3(rows,cols);
  66. eiToGmm(sm1, m1);
  67. BENCH(for (int k=0; k<REPEAT; ++k) gmm::copy(gmm::transposed(m1),m3);)
  68. std::cout << " GMM:\t\t" << timer.value() << endl;
  69. }
  70. #endif
  71. // MTL4
  72. #ifndef NOMTL
  73. {
  74. MtlSparse m1(rows,cols), m3(rows,cols);
  75. eiToMtl(sm1, m1);
  76. BENCH(for (int k=0; k<REPEAT; ++k) m3 = trans(m1);)
  77. std::cout << " MTL4:\t\t" << timer.value() << endl;
  78. }
  79. #endif
  80. std::cout << "\n\n";
  81. }
  82. return 0;
  83. }