2 // g++ -I.. sparse_lu.cpp -O3 -g0 -I /usr/include/superlu/ -lsuperlu -lgfortran -DSIZE=1000 -DDENSITY=.05 && ./a.out
4 #define EIGEN_SUPERLU_SUPPORT
5 #define EIGEN_UMFPACK_SUPPORT
6 #include <Eigen/Sparse>
23 #include "BenchSparseUtil.h"
26 #define MINDENSITY 0.0004
35 for (int _j=0; _j<NBTRIES; ++_j) { \
37 for (int _k=0; _k<REPEAT; ++_k) { \
41 typedef Matrix
<Scalar
,Dynamic
,1> VectorX
;
46 void doEigen(const char* name
, const EigenSparseMatrix
& sm1
, const VectorX
& b
, VectorX
& x
, int flags
= 0)
48 std::cout
<< name
<< "..." << std::flush
;
49 BenchTimer timer
; timer
.start();
50 SparseLU
<EigenSparseMatrix
,Backend
> lu(sm1
, flags
);
53 std::cout
<< ":\t" << timer
.value() << endl
;
56 std::cout
<< ":\t FAILED" << endl
;
61 timer
.reset(); timer
.start();
65 std::cout
<< " solve:\t" << timer
.value() << endl
;
67 std::cout
<< " solve:\t" << " FAILED" << endl
;
69 //std::cout << x.transpose() << "\n";
72 int main(int argc
, char *argv
[])
76 float density
= DENSITY
;
79 VectorX b
= VectorX::Random(cols
);
80 VectorX x
= VectorX::Random(cols
);
82 bool densedone
= false;
84 //for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
85 // float density = 0.5;
87 EigenSparseMatrix
sm1(rows
, cols
);
88 fillMatrix(density
, rows
, cols
, sm1
);
95 std::cout
<< "Eigen Dense\t" << density
*100 << "%\n";
96 DenseMatrix
m1(rows
,cols
);
101 FullPivLU
<DenseMatrix
> lu(m1
);
103 std::cout
<< "Eigen/dense:\t" << timer
.value() << endl
;
109 std::cout
<< " solve:\t" << timer
.value() << endl
;
110 // std::cout << b.transpose() << "\n";
111 // std::cout << x.transpose() << "\n";
115 #ifdef EIGEN_UMFPACK_SUPPORT
117 doEigen
<Eigen::UmfPack
>("Eigen/UmfPack (auto)", sm1
, b
, x
, 0);
120 #ifdef EIGEN_SUPERLU_SUPPORT
122 doEigen
<Eigen::SuperLU
>("Eigen/SuperLU (nat)", sm1
, b
, x
, Eigen::NaturalOrdering
);
123 // doEigen<Eigen::SuperLU>("Eigen/SuperLU (MD AT+A)", sm1, b, x, Eigen::MinimumDegree_AT_PLUS_A);
124 // doEigen<Eigen::SuperLU>("Eigen/SuperLU (MD ATA)", sm1, b, x, Eigen::MinimumDegree_ATA);
125 doEigen
<Eigen::SuperLU
>("Eigen/SuperLU (COLAMD)", sm1
, b
, x
, Eigen::ColApproxMinimumDegree
);