13 #include <Eigen/SparseCore> 17 #include <Eigen/Cholesky> 18 #include <Eigen/Jacobi> 19 #include <Eigen/Householder> 20 #include <Eigen/IterativeLinearSolvers> 21 #include <unsupported/Eigen/IterativeSolvers> 23 #include <unsupported/Eigen/SparseExtra> 24 #include <Eigen/SparseLU> 28 #ifdef EIGEN_METIS_SUPPORT 29 #include <Eigen/MetisSupport> 32 #ifdef EIGEN_CHOLMOD_SUPPORT 33 #include <Eigen/CholmodSupport> 36 #ifdef EIGEN_UMFPACK_SUPPORT 37 #include <Eigen/UmfPackSupport> 40 #ifdef EIGEN_KLU_SUPPORT 41 #include <Eigen/KLUSupport> 44 #ifdef EIGEN_PARDISO_SUPPORT 45 #include <Eigen/PardisoSupport> 48 #ifdef EIGEN_SUPERLU_SUPPORT 49 #include <Eigen/SuperLUSupport> 52 #ifdef EIGEN_PASTIX_SUPPORT 53 #include <Eigen/PaStiXSupport> 57 #define EIGEN_UMFPACK 10 59 #define EIGEN_SUPERLU 20 60 #define EIGEN_PASTIX 30 61 #define EIGEN_PARDISO 40 62 #define EIGEN_SPARSELU_COLAMD 50 63 #define EIGEN_SPARSELU_METIS 51 64 #define EIGEN_BICGSTAB 60 65 #define EIGEN_BICGSTAB_ILUT 61 66 #define EIGEN_GMRES 70 67 #define EIGEN_GMRES_ILUT 71 68 #define EIGEN_SIMPLICIAL_LDLT 80 69 #define EIGEN_CHOLMOD_LDLT 90 70 #define EIGEN_PASTIX_LDLT 100 71 #define EIGEN_PARDISO_LDLT 110 72 #define EIGEN_SIMPLICIAL_LLT 120 73 #define EIGEN_CHOLMOD_SUPERNODAL_LLT 130 74 #define EIGEN_CHOLMOD_SIMPLICIAL_LLT 140 75 #define EIGEN_PASTIX_LLT 150 76 #define EIGEN_PARDISO_LLT 160 78 #define EIGEN_CG_PRECOND 180 80 using namespace Eigen;
101 out <<
"<?xml version='1.0' encoding='UTF-8'?> \n";
102 out <<
"<?xml-stylesheet type='text/xsl' href='#stylesheet' ?> \n";
103 out <<
"<!DOCTYPE BENCH [\n<!ATTLIST xsl:stylesheet\n id\t ID #REQUIRED>\n]>";
104 out <<
"\n\n<!-- Generated by the Eigen library -->\n";
106 out <<
"\n<BENCH> \n" ;
110 out <<
" <AVAILSOLVER> \n";
111 #ifdef EIGEN_UMFPACK_SUPPORT 113 out <<
" <TYPE> LU </TYPE> \n";
114 out <<
" <PACKAGE> UMFPACK </PACKAGE> \n";
115 out <<
" </SOLVER> \n";
117 #ifdef EIGEN_KLU_SUPPORT 118 out <<
" <SOLVER ID='" <<
EIGEN_KLU <<
"'>\n";
119 out <<
" <TYPE> LU </TYPE> \n";
120 out <<
" <PACKAGE> KLU </PACKAGE> \n";
121 out <<
" </SOLVER> \n";
123 #ifdef EIGEN_SUPERLU_SUPPORT 125 out <<
" <TYPE> LU </TYPE> \n";
126 out <<
" <PACKAGE> SUPERLU </PACKAGE> \n";
127 out <<
" </SOLVER> \n";
129 #ifdef EIGEN_CHOLMOD_SUPPORT 131 out <<
" <TYPE> LLT SP</TYPE> \n";
132 out <<
" <PACKAGE> CHOLMOD </PACKAGE> \n";
133 out <<
" </SOLVER> \n";
136 out <<
" <TYPE> LLT</TYPE> \n";
137 out <<
" <PACKAGE> CHOLMOD </PACKAGE> \n";
138 out <<
" </SOLVER> \n";
141 out <<
" <TYPE> LDLT </TYPE> \n";
142 out <<
" <PACKAGE> CHOLMOD </PACKAGE> \n";
143 out <<
" </SOLVER> \n";
145 #ifdef EIGEN_PARDISO_SUPPORT 147 out <<
" <TYPE> LU </TYPE> \n";
148 out <<
" <PACKAGE> PARDISO </PACKAGE> \n";
149 out <<
" </SOLVER> \n";
152 out <<
" <TYPE> LLT </TYPE> \n";
153 out <<
" <PACKAGE> PARDISO </PACKAGE> \n";
154 out <<
" </SOLVER> \n";
157 out <<
" <TYPE> LDLT </TYPE> \n";
158 out <<
" <PACKAGE> PARDISO </PACKAGE> \n";
159 out <<
" </SOLVER> \n";
161 #ifdef EIGEN_PASTIX_SUPPORT 163 out <<
" <TYPE> LU </TYPE> \n";
164 out <<
" <PACKAGE> PASTIX </PACKAGE> \n";
165 out <<
" </SOLVER> \n";
168 out <<
" <TYPE> LLT </TYPE> \n";
169 out <<
" <PACKAGE> PASTIX </PACKAGE> \n";
170 out <<
" </SOLVER> \n";
173 out <<
" <TYPE> LDLT </TYPE> \n";
174 out <<
" <PACKAGE> PASTIX </PACKAGE> \n";
175 out <<
" </SOLVER> \n";
179 out <<
" <TYPE> BICGSTAB </TYPE> \n";
180 out <<
" <PACKAGE> EIGEN </PACKAGE> \n";
181 out <<
" </SOLVER> \n";
184 out <<
" <TYPE> BICGSTAB_ILUT </TYPE> \n";
185 out <<
" <PACKAGE> EIGEN </PACKAGE> \n";
186 out <<
" </SOLVER> \n";
189 out <<
" <TYPE> GMRES_ILUT </TYPE> \n";
190 out <<
" <PACKAGE> EIGEN </PACKAGE> \n";
191 out <<
" </SOLVER> \n";
194 out <<
" <TYPE> LDLT </TYPE> \n";
195 out <<
" <PACKAGE> EIGEN </PACKAGE> \n";
196 out <<
" </SOLVER> \n";
199 out <<
" <TYPE> LLT </TYPE> \n";
200 out <<
" <PACKAGE> EIGEN </PACKAGE> \n";
201 out <<
" </SOLVER> \n";
203 out <<
" <SOLVER ID='" <<
EIGEN_CG <<
"'>\n";
204 out <<
" <TYPE> CG </TYPE> \n";
205 out <<
" <PACKAGE> EIGEN </PACKAGE> \n";
206 out <<
" </SOLVER> \n";
209 out <<
" <TYPE> LU_COLAMD </TYPE> \n";
210 out <<
" <PACKAGE> EIGEN </PACKAGE> \n";
211 out <<
" </SOLVER> \n";
213 #ifdef EIGEN_METIS_SUPPORT 215 out <<
" <TYPE> LU_METIS </TYPE> \n";
216 out <<
" <PACKAGE> EIGEN </PACKAGE> \n";
217 out <<
" </SOLVER> \n";
219 out <<
" </AVAILSOLVER> \n";
224 template<
typename Solver,
typename Scalar>
239 std::cerr <<
"Solver failed ... \n";
243 compute_time = timer.
value();
244 statbuf <<
" <TIME>\n";
245 statbuf <<
" <COMPUTE> " << timer.
value() <<
"</COMPUTE>\n";
246 std::cout<<
"COMPUTE TIME : " << timer.
value() <<std::endl;
253 std::cerr <<
"Solver failed ... \n";
257 solve_time = timer.
value();
258 statbuf <<
" <SOLVE> " << timer.
value() <<
"</SOLVE>\n";
259 std::cout<<
"SOLVE TIME : " << timer.
value() <<std::endl;
261 total_time = solve_time + compute_time;
262 statbuf <<
" <TOTAL> " << total_time <<
"</TOTAL>\n";
263 std::cout<<
"TOTAL TIME : " << total_time <<std::endl;
264 statbuf <<
" </TIME>\n";
268 rel_error = (refX - x).norm()/refX.norm();
274 rel_error = (b-temp).norm()/b.norm();
276 statbuf <<
" <ERROR> " << rel_error <<
"</ERROR>\n";
277 std::cout<<
"REL. ERROR : " << rel_error <<
"\n\n" ;
278 if ( rel_error <=
RelErr )
289 template<
typename Solver,
typename Scalar>
292 std::ofstream statbuf(statFile.c_str(), std::ios::app);
293 statbuf <<
" <SOLVER_STAT ID='" << solver_id <<
"'>\n";
294 call_solver(solver, solver_id, A, b, refX,statbuf);
295 statbuf <<
" </SOLVER_STAT>\n";
299 template<
typename Solver,
typename Scalar>
302 solver.setTolerance(
RelErr);
305 std::ofstream statbuf(statFile.c_str(), std::ios::app);
306 statbuf <<
" <SOLVER_STAT ID='" << solver_id <<
"'>\n";
307 call_solver(solver, solver_id, A, b, refX,statbuf);
308 statbuf <<
" <ITER> "<< solver.iterations() <<
"</ITER>\n";
309 statbuf <<
" </SOLVER_STAT>\n";
310 std::cout <<
"ITERATIONS : " << solver.iterations() <<
"\n\n\n";
315 template <
typename Scalar>
323 #ifdef EIGEN_UMFPACK_SUPPORT 325 cout <<
"Solving with UMFPACK LU ... \n";
331 #ifdef EIGEN_KLU_SUPPORT 333 cout <<
"Solving with KLU LU ... \n";
339 #ifdef EIGEN_SUPERLU_SUPPORT 341 cout <<
"\nSolving with SUPERLU ... \n";
348 #ifdef EIGEN_PASTIX_SUPPORT 350 cout <<
"\nSolving with PASTIX LU ... \n";
357 #ifdef EIGEN_PARDISO_SUPPORT 359 cout <<
"\nSolving with PARDISO LU ... \n";
366 cout <<
"\n Solving with Sparse LU AND COLAMD ... \n";
370 #ifdef EIGEN_METIS_SUPPORT 372 cout <<
"\n Solving with Sparse LU AND METIS ... \n";
380 cout <<
"\nSolving with BiCGSTAB ... \n";
386 cout <<
"\nSolving with BiCGSTAB and ILUT ... \n";
400 cout <<
"\nSolving with GMRES and ILUT ... \n";
410 cout <<
"\nSolving with Simplicial LDLT ... \n";
416 #ifdef EIGEN_CHOLMOD_SUPPORT 418 cout <<
"\nSolving with CHOLMOD LDLT ... \n";
426 #ifdef EIGEN_PASTIX_SUPPORT 428 cout <<
"\nSolving with PASTIX LDLT ... \n";
435 #ifdef EIGEN_PARDISO_SUPPORT 437 cout <<
"\nSolving with PARDISO LDLT ... \n";
450 cout <<
"\nSolving with SIMPLICIAL LLT ... \n";
456 #ifdef EIGEN_CHOLMOD_SUPPORT 459 cout <<
"\nSolving with CHOLMOD LLT (Supernodal)... \n";
464 cout <<
"\nSolving with CHOLMOD LLT (Simplicial) ... \n";
471 #ifdef EIGEN_PASTIX_SUPPORT 473 cout <<
"\nSolving with PASTIX LLT ... \n";
480 #ifdef EIGEN_PARDISO_SUPPORT 482 cout <<
"\nSolving with PARDISO LLT ... \n";
490 cout <<
"\nSolving with CG ... \n";
508 template <
typename Scalar>
509 void Browse_Matrices(
const string folder,
bool statFileExists, std::string& statFile,
int maxiters,
double tol)
519 std::ofstream statbuf(statFile.c_str(), std::ios::app);
520 statbuf <<
"<LINEARSYSTEM> \n";
521 statbuf <<
" <MATRIX> \n";
522 statbuf <<
" <NAME> " << it.
matname() <<
" </NAME>\n";
523 statbuf <<
" <SIZE> " << it.
matrix().
rows() <<
" </SIZE>\n";
524 statbuf <<
" <ENTRIES> " << it.
matrix().
nonZeros() <<
"</ENTRIES>\n";
527 statbuf <<
" <SYMMETRY> Symmetric </SYMMETRY>\n" ;
529 statbuf <<
" <POSDEF> YES </POSDEF>\n";
531 statbuf <<
" <POSDEF> NO </POSDEF>\n";
536 statbuf <<
" <SYMMETRY> NonSymmetric </SYMMETRY>\n" ;
537 statbuf <<
" <POSDEF> NO </POSDEF>\n";
539 statbuf <<
" </MATRIX> \n";
543 cout<<
"\n\n===================================================== \n";
544 cout<<
" ====== SOLVING WITH MATRIX " << it.
matname() <<
" ====\n";
545 cout<<
" =================================================== \n\n";
549 SelectSolvers<Scalar>(it.
matrix(), it.
sym(), it.
rhs(), refX, statFile);
553 std::ofstream statbuf(statFile.c_str(), std::ios::app);
555 <<
"'></BEST_SOLVER>\n";
556 statbuf <<
" </LINEARSYSTEM> \n";
564 int idx = 1, found=
false;
565 while (idx<argc && !found){
566 if (option.compare(args[idx]) == 0){
#define EIGEN_SIMPLICIAL_LDLT
void setMode(CholmodMode mode)
void printStatheader(std::ofstream &out)
void SelectSolvers(const SparseMatrix< Scalar > &A, unsigned int sym, Matrix< Scalar, Dynamic, 1 > &b, const Matrix< Scalar, Dynamic, 1 > &refX, std::string &statFile)
A sparse LU factorization and solver based on UmfPack.
double test_precision< double >()
void Browse_Matrices(const string folder, bool statFileExists, std::string &statFile, int maxiters, double tol)
#define EIGEN_CHOLMOD_LDLT
#define EIGEN_BICGSTAB_ILUT
A sparse direct LU factorization and solver based on the SuperLU library.
std::ofstream out("Result.txt")
bool get_options(int argc, char **args, string option, string *value=0)
void printBenchStyle(std::ofstream &out)
double value(int TIMER=CPU_TIMER) const
Namespace containing all symbols from the Eigen library.
A conjugate gradient solver for sparse (or dense) self-adjoint problems.
BiCGSTAB< SparseMatrix< double > > solver
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
void call_itersolver(Solver &solver, const int solver_id, const typename Solver::MatrixType &A, const Matrix< Scalar, Dynamic, 1 > &b, const Matrix< Scalar, Dynamic, 1 > &refX, std::string &statFile)
A direct sparse LDLT Cholesky factorizations without square root.
Sparse supernodal LU factorization for general matrices.
#define EIGEN_SPARSELU_METIS
A sparse direct Cholesky (LLT) factorization and solver based on the PARDISO library.
float test_precision< float >()
#define EIGEN_PARDISO_LLT
A sparse direct supernodal Cholesky (LLT) factorization and solver based on the PaStiX library...
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Iterator to browse matrices from a specified folder.
A sparse direct LU factorization and solver based on the PARDISO library.
A general Cholesky factorization and solver based on Cholmod.
Eigen::SparseMatrix< double > SpMat
#define EIGEN_SIMPLICIAL_LLT
NumTraits< T >::Real test_precision()
A GMRES solver for sparse square problems.
#define EIGEN_CHOLMOD_SIMPLICIAL_LLT
A sparse direct Cholesky (LDLT) factorization and solver based on the PARDISO library.
Interface to the PaStix solver.
#define EIGEN_SPARSELU_COLAMD
A sparse direct supernodal Cholesky (LLT) factorization and solver based on the PaStiX library...
A bi conjugate gradient stabilized solver for sparse square problems.
#define EIGEN_PASTIX_LDLT
A direct sparse LLT Cholesky factorizations.
#define EIGEN_CHOLMOD_SUPERNODAL_LLT
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
#define EIGEN_PARDISO_LDLT
void call_directsolver(Solver &solver, const int solver_id, const typename Solver::MatrixType &A, const Matrix< Scalar, Dynamic, 1 > &b, const Matrix< Scalar, Dynamic, 1 > &refX, std::string &statFile)
void call_solver(Solver &solver, const int solver_id, const typename Solver::MatrixType &A, const Matrix< Scalar, Dynamic, 1 > &b, const Matrix< Scalar, Dynamic, 1 > &refX, std::ofstream &statbuf)