test_sparseLU.cpp File Reference
#include <iostream>
#include <fstream>
#include <iomanip>
#include <unsupported/Eigen/SparseExtra>
#include <Eigen/SparseLU>
#include <bench/BenchTimer.h>

Functions

int main (int argc, char **args)
 

Function Documentation

◆ main()

int main ( int argc  ,
char **  args 
)
17  {
18  // typedef complex<double> scalar;
19  typedef double scalar;
23  typedef Matrix<scalar, Dynamic, 1> DenseRhs;
25  // SparseLU<SparseMatrix<scalar, ColMajor>, AMDOrdering<int> > solver;
26  // #ifdef EIGEN_METIS_SUPPORT
27  // SparseLU<SparseMatrix<scalar, ColMajor>, MetisOrdering<int> > solver;
28  // std::cout<< "ORDERING : METIS\n";
29  // #else
31  std::cout << "ORDERING : COLAMD\n";
32  // #endif
33 
34  ifstream matrix_file;
35  string line;
36  int n;
38 
39  // Set parameters
40  /* Fill the matrix with sparse matrix stored in Matrix-Market coordinate column-oriented format */
41  if (argc < 2) assert(false && "please, give the matrix market file ");
42  loadMarket(A, args[1]);
43  cout << "End charging matrix " << endl;
44  bool iscomplex = false, isvector = false;
45  int sym;
46  getMarketHeader(args[1], sym, iscomplex, isvector);
47  // if (iscomplex) { cout<< " Not for complex matrices \n"; return -1; }
48  if (isvector) {
49  cout << "The provided file is not a matrix file\n";
50  return -1;
51  }
52  if (sym != 0) { // symmetric matrices, only the lower part is stored
54  temp = A;
55  A = temp.selfadjointView<Lower>();
56  }
57  n = A.cols();
58  /* Fill the right hand side */
59 
60  if (argc > 2)
61  loadMarketVector(b, args[2]);
62  else {
63  b.resize(n);
64  tmp.resize(n);
65  // tmp.setRandom();
66  for (int i = 0; i < n; i++) tmp(i) = i;
67  b = A * tmp;
68  }
69 
70  /* Compute the factorization */
71  // solver.isSymmetric(true);
72  timer.start();
73  // solver.compute(A);
74  solver.analyzePattern(A);
75  timer.stop();
76  cout << "Time to analyze " << timer.value() << std::endl;
77  timer.reset();
78  timer.start();
79  solver.factorize(A);
80  timer.stop();
81  cout << "Factorize Time " << timer.value() << std::endl;
82  timer.reset();
83  timer.start();
84  x = solver.solve(b);
85  timer.stop();
86  cout << "solve time " << timer.value() << std::endl;
87  /* Check the accuracy */
88  Matrix<scalar, Dynamic, 1> tmp2 = b - A * x;
89  scalar tempNorm = tmp2.norm() / b.norm();
90  cout << "Relative norm of the computed solution : " << tempNorm << "\n";
91  cout << "Number of nonzeros in the factor : " << solver.nnzL() + solver.nnzU() << std::endl;
92 
93  return 0;
94 }
Matrix< Scalar, Dynamic, Dynamic > DenseMatrix
Definition: BenchSparseUtil.h:23
BiCGSTAB< SparseMatrix< double > > solver
Definition: BiCGSTAB_simple.cpp:5
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
#define assert(e,...)
Definition: Logger.h:744
Scalar * b
Definition: benchVecAdd.cpp:17
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Definition: BenchTimer.h:55
Definition: Ordering.h:109
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:192
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:294
Sparse supernodal LU factorization for general matrices.
Definition: SparseLU.h:151
ConstSelfAdjointViewReturnType< UpLo >::Type selfadjointView() const
A versatible sparse matrix representation.
Definition: SparseMatrix.h:121
@ Lower
Definition: Constants.h:211
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
bool loadMarketVector(VectorType &vec, const std::string &filename)
Same functionality as loadMarketDense, deprecated.
Definition: MarketIO.h:284
bool loadMarket(SparseMatrixType &mat, const std::string &filename)
Loads a sparse matrix from a matrixmarket format file.
Definition: MarketIO.h:156
bool getMarketHeader(const std::string &filename, int &sym, bool &iscomplex, bool &isdense)
Reads the header of a matrixmarket file and determines the properties of a matrix.
Definition: MarketIO.h:122
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
line
Definition: calibrate.py:103
args
Definition: compute_granudrum_aor.py:143
list x
Definition: plotDoE.py:28
double timer
Definition: oomph_metis_from_parmetis_3.1.1/struct.h:210

References compute_granudrum_aor::args, assert, b, Eigen::PlainObjectBase< Derived >::cols(), Eigen::getMarketHeader(), i, calibrate::line, Eigen::loadMarket(), Eigen::loadMarketVector(), Eigen::Lower, n, Eigen::PlainObjectBase< Derived >::resize(), Eigen::SparseMatrixBase< Derived >::selfadjointView(), solver, tmp, and plotDoE::x.