From 44861dcbfeee041223c4aac1ee075e92fa4daa01 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 18 Sep 2016 12:42:15 +0200 Subject: update --- eigen/bench/spbench/test_sparseLU.cpp | 93 +++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 eigen/bench/spbench/test_sparseLU.cpp (limited to 'eigen/bench/spbench/test_sparseLU.cpp') diff --git a/eigen/bench/spbench/test_sparseLU.cpp b/eigen/bench/spbench/test_sparseLU.cpp new file mode 100644 index 0000000..f8ecbe6 --- /dev/null +++ b/eigen/bench/spbench/test_sparseLU.cpp @@ -0,0 +1,93 @@ +// Small bench routine for Eigen available in Eigen +// (C) Desire NUENTSA WAKAM, INRIA + +#include +#include +#include +#include +#include +#include +#ifdef EIGEN_METIS_SUPPORT +#include +#endif + +using namespace std; +using namespace Eigen; + +int main(int argc, char **args) +{ +// typedef complex scalar; + typedef double scalar; + SparseMatrix A; + typedef SparseMatrix::Index Index; + typedef Matrix DenseMatrix; + typedef Matrix DenseRhs; + Matrix b, x, tmp; +// SparseLU, AMDOrdering > solver; +// #ifdef EIGEN_METIS_SUPPORT +// SparseLU, MetisOrdering > solver; +// std::cout<< "ORDERING : METIS\n"; +// #else + SparseLU, COLAMDOrdering > solver; + std::cout<< "ORDERING : COLAMD\n"; +// #endif + + ifstream matrix_file; + string line; + int n; + BenchTimer timer; + + // Set parameters + /* Fill the matrix with sparse matrix stored in Matrix-Market coordinate column-oriented format */ + if (argc < 2) assert(false && "please, give the matrix market file "); + loadMarket(A, args[1]); + cout << "End charging matrix " << endl; + bool iscomplex=false, isvector=false; + int sym; + getMarketHeader(args[1], sym, iscomplex, isvector); +// if (iscomplex) { cout<< " Not for complex matrices \n"; return -1; } + if (isvector) { cout << "The provided file is not a matrix file\n"; return -1;} + if (sym != 0) { // symmetric matrices, only the lower part is stored + SparseMatrix temp; + temp = A; + A = temp.selfadjointView(); + } + n = A.cols(); + /* Fill the right hand side */ + + if (argc > 2) + loadMarketVector(b, args[2]); + else + { + b.resize(n); + tmp.resize(n); +// tmp.setRandom(); + for (int i = 0; i < n; i++) tmp(i) = i; + b = A * tmp ; + } + + /* Compute the factorization */ +// solver.isSymmetric(true); + timer.start(); +// solver.compute(A); + solver.analyzePattern(A); + timer.stop(); + cout << "Time to analyze " << timer.value() << std::endl; + timer.reset(); + timer.start(); + solver.factorize(A); + timer.stop(); + cout << "Factorize Time " << timer.value() << std::endl; + timer.reset(); + timer.start(); + x = solver.solve(b); + timer.stop(); + cout << "solve time " << timer.value() << std::endl; + /* Check the accuracy */ + Matrix tmp2 = b - A*x; + scalar tempNorm = tmp2.norm()/b.norm(); + cout << "Relative norm of the computed solution : " << tempNorm <<"\n"; + cout << "Number of nonzeros in the factor : " << solver.nnzL() + solver.nnzU() << std::endl; + + return 0; +} \ No newline at end of file -- cgit v1.2.3