| |
| |
|
|
| #include <iostream> |
| #include <fstream> |
| #include <iomanip> |
| #include <Eigen/Jacobi> |
| #include <Eigen/Householder> |
| #include <Eigen/IterativeLinearSolvers> |
| #include <Eigen/LU> |
| #include <unsupported/Eigen/SparseExtra> |
| |
| #include <Eigen/SuperLUSupport> |
| |
| #include <bench/BenchTimer.h> |
| #include <unsupported/Eigen/IterativeSolvers> |
| using namespace std; |
| using namespace Eigen; |
|
|
| int main(int argc, char **args) |
| { |
| SparseMatrix<double, ColMajor> A; |
| typedef SparseMatrix<double, ColMajor>::Index Index; |
| typedef Matrix<double, Dynamic, Dynamic> DenseMatrix; |
| typedef Matrix<double, Dynamic, 1> DenseRhs; |
| VectorXd b, x, tmp; |
| BenchTimer timer,totaltime; |
| |
| |
| ConjugateGradient<SparseMatrix<double, ColMajor>, Lower,IncompleteCholesky<double,Lower> > solver; |
| ifstream matrix_file; |
| string line; |
| int n; |
| |
| |
| |
| if (argc < 2) assert(false && "please, give the matrix market file "); |
| |
| timer.start(); |
| totaltime.start(); |
| 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) { |
| SparseMatrix<double, ColMajor> temp; |
| temp = A; |
| A = temp.selfadjointView<Lower>(); |
| } |
| timer.stop(); |
| |
| n = A.cols(); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| cout<< "Time to load the matrix " << timer.value() <<endl; |
| |
|
|
| |
| if (argc > 2) |
| loadMarketVector(b, args[2]); |
| else |
| { |
| b.resize(n); |
| tmp.resize(n); |
| |
| for (int i = 0; i < n; i++) tmp(i) = i; |
| b = A * tmp ; |
| } |
| |
| |
| |
|
|
| |
| cout<< "Starting the factorization "<< endl; |
| timer.reset(); |
| timer.start(); |
| cout<< "Size of Input Matrix "<< b.size()<<"\n\n"; |
| cout<< "Rows and columns "<< A.rows() <<" " <<A.cols() <<"\n"; |
| solver.compute(A); |
| |
| |
| if (solver.info() != Success) { |
| std::cout<< "The solver failed \n"; |
| return -1; |
| } |
| timer.stop(); |
| float time_comp = timer.value(); |
| cout <<" Compute Time " << time_comp<< endl; |
| |
| timer.reset(); |
| timer.start(); |
| x = solver.solve(b); |
| |
| timer.stop(); |
| float time_solve = timer.value(); |
| cout<< " Time to solve " << time_solve << endl; |
| |
| |
| VectorXd tmp2 = b - A*x; |
| double tempNorm = tmp2.norm()/b.norm(); |
| cout << "Relative norm of the computed solution : " << tempNorm <<"\n"; |
| |
| |
| totaltime.stop(); |
| cout << "Total time " << totaltime.value() << "\n"; |
| |
| |
| return 0; |
| } |