sparse_lu.cpp File Reference
#include <Eigen/Sparse>
#include "BenchSparseUtil.h"
#include <Eigen/LU>

Macros

#define EIGEN_SUPERLU_SUPPORT
 
#define EIGEN_UMFPACK_SUPPORT
 
#define NOGMM
 
#define NOMTL
 
#define SIZE   10
 
#define DENSITY   0.01
 
#define REPEAT   1
 
#define MINDENSITY   0.0004
 
#define NBTRIES   10
 
#define BENCH(X)
 

Typedefs

typedef Matrix< Scalar, Dynamic, 1 > VectorX
 

Functions

template<int Backend>
void doEigen (const char *name, const EigenSparseMatrix &sm1, const VectorX &b, VectorX &x, int flags=0)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ BENCH

#define BENCH (   X)
Value:
timer.reset(); \
for (int _j = 0; _j < NBTRIES; ++_j) { \
timer.start(); \
for (int _k = 0; _k < REPEAT; ++_k) { \
X \
} \
timer.stop(); \
}
#define REPEAT
Definition: sparse_lu.cpp:20
#define NBTRIES
Definition: sparse_lu.cpp:30

◆ DENSITY

#define DENSITY   0.01

◆ EIGEN_SUPERLU_SUPPORT

#define EIGEN_SUPERLU_SUPPORT

◆ EIGEN_UMFPACK_SUPPORT

#define EIGEN_UMFPACK_SUPPORT

◆ MINDENSITY

#define MINDENSITY   0.0004

◆ NBTRIES

#define NBTRIES   10

◆ NOGMM

#define NOGMM

◆ NOMTL

#define NOMTL

◆ REPEAT

#define REPEAT   1

◆ SIZE

#define SIZE   10

Typedef Documentation

◆ VectorX

typedef Matrix<Scalar, Dynamic, 1> VectorX

Function Documentation

◆ doEigen()

template<int Backend>
void doEigen ( const char name,
const EigenSparseMatrix sm1,
const VectorX b,
VectorX x,
int  flags = 0 
)
48  {
49  std::cout << name << "..." << std::flush;
51  timer.start();
53  timer.stop();
54  if (lu.succeeded())
55  std::cout << ":\t" << timer.value() << endl;
56  else {
57  std::cout << ":\t FAILED" << endl;
58  return;
59  }
60 
61  bool ok;
62  timer.reset();
63  timer.start();
64  ok = lu.solve(b, &x);
65  timer.stop();
66  if (ok)
67  std::cout << " solve:\t" << timer.value() << endl;
68  else
69  std::cout << " solve:\t"
70  << " FAILED" << endl;
71 
72  // std::cout << x.transpose() << "\n";
73 }
Scalar * b
Definition: benchVecAdd.cpp:17
Definition: BenchTimer.h:55
Sparse supernodal LU factorization for general matrices.
Definition: SparseLU.h:151
cout<< "Here is the matrix m:"<< endl<< m<< endl;Eigen::FullPivLU< Matrix5x3 > lu(m)
list x
Definition: plotDoE.py:28
string name
Definition: plotDoE.py:33
double timer
Definition: oomph_metis_from_parmetis_3.1.1/struct.h:210

References b, lu(), plotDoE::name, and plotDoE::x.

◆ main()

int main ( int argc  ,
char argv[] 
)
75  {
76  int rows = SIZE;
77  int cols = SIZE;
78  float density = DENSITY;
80 
81  VectorX b = VectorX::Random(cols);
82  VectorX x = VectorX::Random(cols);
83 
84  bool densedone = false;
85 
86  // for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
87  // float density = 0.5;
88  {
90  fillMatrix(density, rows, cols, sm1);
91 
92 // dense matrices
93 #ifdef DENSEMATRIX
94  if (!densedone) {
95  densedone = true;
96  std::cout << "Eigen Dense\t" << density * 100 << "%\n";
98  eiToDense(sm1, m1);
99 
101  timer.start();
103  timer.stop();
104  std::cout << "Eigen/dense:\t" << timer.value() << endl;
105 
106  timer.reset();
107  timer.start();
108  lu.solve(b, &x);
109  timer.stop();
110  std::cout << " solve:\t" << timer.value() << endl;
111  // std::cout << b.transpose() << "\n";
112  // std::cout << x.transpose() << "\n";
113  }
114 #endif
115 
116 #ifdef EIGEN_UMFPACK_SUPPORT
117  x.setZero();
118  doEigen<Eigen::UmfPack>("Eigen/UmfPack (auto)", sm1, b, x, 0);
119 #endif
120 
121 #ifdef EIGEN_SUPERLU_SUPPORT
122  x.setZero();
123  doEigen<Eigen::SuperLU>("Eigen/SuperLU (nat)", sm1, b, x, Eigen::NaturalOrdering);
124  // doEigen<Eigen::SuperLU>("Eigen/SuperLU (MD AT+A)", sm1, b, x, Eigen::MinimumDegree_AT_PLUS_A);
125  // doEigen<Eigen::SuperLU>("Eigen/SuperLU (MD ATA)", sm1, b, x, Eigen::MinimumDegree_ATA);
126  doEigen<Eigen::SuperLU>("Eigen/SuperLU (COLAMD)", sm1, b, x, Eigen::ColApproxMinimumDegree);
127 #endif
128  }
129 
130  return 0;
131 }
void eiToDense(const EigenSparseMatrix &src, DenseMatrix &dst)
Definition: BenchSparseUtil.h:54
void fillMatrix(float density, int rows, int cols, EigenSparseMatrix &dst)
Definition: BenchSparseUtil.h:27
Matrix3d m1
Definition: IOFormat.cpp:2
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
LU decomposition of a matrix with complete pivoting, and related features.
Definition: FullPivLU.h:63
Definition: Ordering.h:89
density
Definition: UniformPSDSelfTest.py:19
#define SIZE
Definition: sparse_lu.cpp:12
#define DENSITY
Definition: sparse_lu.cpp:16

References b, cols, UniformPSDSelfTest::density, DENSITY, eiToDense(), fillMatrix(), lu(), m1, rows, SIZE, and plotDoE::x.