aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/sparse_lu.cpp
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2008-10-19 17:06:11 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2008-10-19 17:06:11 +0000
commit76fe2e1b34b4388ea3d9585bc840a0bab20ee5be (patch)
treea8d14974b78f46796a934a10b867286aaa88316d /bench/sparse_lu.cpp
parentecc6c43dba2ca00d2f9d525dcd0d94941bea3fda (diff)
add/update some benchmark files used to test/compare sparse module features
Diffstat (limited to 'bench/sparse_lu.cpp')
-rw-r--r--bench/sparse_lu.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/bench/sparse_lu.cpp b/bench/sparse_lu.cpp
new file mode 100644
index 000000000..35e7e8a3a
--- /dev/null
+++ b/bench/sparse_lu.cpp
@@ -0,0 +1,112 @@
+
+// g++ -I.. sparse_lu.cpp -O3 -g0 -I /usr/include/superlu/ -lsuperlu -lgfortran -DSIZE=1000 -DDENSITY=.05 && ./a.out
+
+// #define EIGEN_TAUCS_SUPPORT
+// #define EIGEN_CHOLMOD_SUPPORT
+#define EIGEN_SUPERLU_SUPPORT
+#include <Eigen/Sparse>
+
+#define NOGMM
+#define NOMTL
+
+#ifndef SIZE
+#define SIZE 10
+#endif
+
+#ifndef DENSITY
+#define DENSITY 0.01
+#endif
+
+#ifndef REPEAT
+#define REPEAT 1
+#endif
+
+#include "BenchSparseUtil.h"
+
+#ifndef MINDENSITY
+#define MINDENSITY 0.0004
+#endif
+
+#ifndef NBTRIES
+#define NBTRIES 10
+#endif
+
+#define BENCH(X) \
+ timer.reset(); \
+ for (int _j=0; _j<NBTRIES; ++_j) { \
+ timer.start(); \
+ for (int _k=0; _k<REPEAT; ++_k) { \
+ X \
+ } timer.stop(); }
+
+typedef Matrix<Scalar,Dynamic,1> VectorX;
+
+#include <Eigen/LU>
+
+int main(int argc, char *argv[])
+{
+ int rows = SIZE;
+ int cols = SIZE;
+ float density = DENSITY;
+ BenchTimer timer;
+
+ VectorX b = VectorX::Random(cols);
+ VectorX x = VectorX::Random(cols);
+
+ bool densedone = false;
+
+ //for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
+// float density = 0.5;
+ {
+ EigenSparseMatrix sm1(rows, cols);
+ fillMatrix(density, rows, cols, sm1);
+
+ // dense matrices
+ #ifdef DENSEMATRIX
+ if (!densedone)
+ {
+ densedone = true;
+ std::cout << "Eigen Dense\t" << density*100 << "%\n";
+ DenseMatrix m1(rows,cols);
+ eiToDense(sm1, m1);
+
+ BenchTimer timer;
+ timer.start();
+ LU<DenseMatrix> lu(m1);
+ timer.stop();
+ std::cout << "Eigen/dense:\t" << timer.value() << endl;
+
+ timer.reset();
+ timer.start();
+ lu.solve(b,&x);
+ timer.stop();
+ std::cout << " solve:\t" << timer.value() << endl;
+// std::cout << b.transpose() << "\n";
+ std::cout << x.transpose() << "\n";
+ }
+ #endif
+
+ // eigen sparse matrices
+ {
+ x.setZero();
+ BenchTimer timer;
+ timer.start();
+ SparseLU<EigenSparseMatrix,SuperLU> lu(sm1);
+ timer.stop();
+ std::cout << "Eigen/SuperLU:\t" << timer.value() << endl;
+
+ timer.reset();
+ timer.start();
+ lu.solve(b,&x);
+ timer.stop();
+ std::cout << " solve:\t" << timer.value() << endl;
+
+ std::cout << x.transpose() << "\n";
+
+ }
+
+ }
+
+ return 0;
+}
+