& refX, std::string& statFile)
{
- Stats stat;
solver.setTolerance(RelErr);
solver.setMaxIterations(MaximumIters);
- stat = call_solver(solver, A, b, refX);
- stat.iterations = solver.iterations();
- return stat;
-}
-
-inline void printStatItem(Stats *stat, int solver_id, int& best_time_id, double& best_time_val)
-{
- stat[solver_id].isavail = 1;
-
- if (stat[solver_id].info == NumericalIssue)
- {
- cout << " SOLVER FAILED ... Probably a numerical issue \n";
- return;
- }
- if (stat[solver_id].info == NoConvergence){
- cout << "REL. ERROR " << stat[solver_id].rel_error;
- if(stat[solver_id].isIterative == 1)
- cout << " (" << stat[solver_id].iterations << ") \n";
- return;
- }
-
- // Record the best CPU time
- if (!best_time_val)
- {
- best_time_val = stat[solver_id].total_time;
- best_time_id = solver_id;
- }
- else if (stat[solver_id].total_time < best_time_val)
- {
- best_time_val = stat[solver_id].total_time;
- best_time_id = solver_id;
- }
- // Print statistics to standard output
- if (stat[solver_id].info == Success){
- cout<< "COMPUTE TIME : " << stat[solver_id].compute_time<< " \n";
- cout<< "SOLVE TIME : " << stat[solver_id].solve_time<< " \n";
- cout<< "TOTAL TIME : " << stat[solver_id].total_time<< " \n";
- cout << "REL. ERROR : " << stat[solver_id].rel_error ;
- if(stat[solver_id].isIterative == 1) {
- cout << " (" << stat[solver_id].iterations << ") ";
- }
- cout << std::endl;
- }
-
-}
-
-
-/* Print the results from all solvers corresponding to a particular matrix
- * The best CPU time is printed in bold
- */
-inline void printHtmlStatLine(Stats *stat, int best_time_id, string& statline)
-{
-
- string markup;
- ostringstream compute,solve,total,error;
- for (int i = 0; i < EIGEN_ALL_SOLVERS; i++)
- {
- if (stat[i].isavail == 0) continue;
- if(i == best_time_id)
- markup = "";
- else
- markup = " | ";
-
- if (stat[i].info == Success){
- compute << markup << stat[i].compute_time;
- solve << markup << stat[i].solve_time;
- total << markup << stat[i].total_time;
- error << " | " << stat[i].rel_error;
- if(stat[i].isIterative == 1) {
- error << " (" << stat[i].iterations << ") ";
- }
- }
- else {
- compute << " | -" ;
- solve << " | -" ;
- total << " | -" ;
- if(stat[i].info == NoConvergence){
- error << " | "<< stat[i].rel_error ;
- if(stat[i].isIterative == 1)
- error << " (" << stat[i].iterations << ") ";
- }
- else error << " | - ";
- }
- }
-
- statline = " | Compute Time " + compute.str() + "\n"
- + " | Solve Time " + solve.str() + "\n"
- + " |
---|
Total Time " + total.str() + "\n"
- +" |
---|
Error(Iter)" + error.str() + "\n";
+ std::ofstream statbuf(statFile.c_str(), std::ios::app);
+ statbuf << " \n";
+ call_solver(solver, solver_id, A, b, refX,statbuf);
+ statbuf << " "<< solver.iterations() << "\n";
+ statbuf << " \n";
+ std::cout << "ITERATIONS : " << solver.iterations() <<"\n\n\n";
}
+
template
-int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix& b, const Matrix& refX, Stats *stat)
+void SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix& b, const Matrix& refX, std::string& statFile)
{
typedef SparseMatrix SpMat;
// First, deal with Nonsymmetric and symmetric matrices
- int best_time_id = 0;
- double best_time_val = 0.0;
+ best_time_id = 0;
+ best_time_val = 0.0;
//UMFPACK
#ifdef EIGEN_UMFPACK_SUPPORT
{
cout << "Solving with UMFPACK LU ... \n";
UmfPackLU solver;
- stat[EIGEN_UMFPACK] = call_directsolver(solver, A, b, refX);
- printStatItem(stat, EIGEN_UMFPACK, best_time_id, best_time_val);
+ call_directsolver(solver, EIGEN_UMFPACK, A, b, refX,statFile);
}
#endif
//SuperLU
@@ -304,8 +302,8 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
- stat[EIGEN_SUPERLU] = call_directsolver(solver, A, b, refX);
- printStatItem(stat, EIGEN_SUPERLU, best_time_id, best_time_val);
+ call_directsolver(solver, EIGEN_SUPERLU, A, b, refX,statFile);
+ printStatItem(stat, best_time_id, best_time_val);
}
#endif
@@ -314,8 +312,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
- stat[EIGEN_PASTIX] = call_directsolver(solver, A, b, refX) ;
- printStatItem(stat, EIGEN_PASTIX, best_time_id, best_time_val);
+ call_directsolver(solver, EIGEN_PASTIX, A, b, refX,statFile) ;
}
#endif
@@ -324,8 +321,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
- stat[EIGEN_PARDISO] = call_directsolver(solver, A, b, refX);
- printStatItem(stat, EIGEN_PARDISO, best_time_id, best_time_val);
+ call_directsolver(solver, EIGEN_PARDISO, A, b, refX,statFile);
}
#endif
@@ -335,17 +331,13 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
- stat[EIGEN_BICGSTAB] = call_itersolver(solver, A, b, refX);
- stat[EIGEN_BICGSTAB].isIterative = 1;
- printStatItem(stat, EIGEN_BICGSTAB, best_time_id, best_time_val);
+ call_itersolver(solver, EIGEN_BICGSTAB, A, b, refX,statFile);
}
//BiCGSTAB+ILUT
{
cout << "\nSolving with BiCGSTAB and ILUT ... \n";
BiCGSTAB > solver;
- stat[EIGEN_BICGSTAB_ILUT] = call_itersolver(solver, A, b, refX);
- stat[EIGEN_BICGSTAB_ILUT].isIterative = 1;
- printStatItem(stat, EIGEN_BICGSTAB_ILUT, best_time_id, best_time_val);
+ call_itersolver(solver, EIGEN_BICGSTAB_ILUT, A, b, refX,statFile);
}
@@ -353,17 +345,13 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
-// stat[EIGEN_GMRES] = call_itersolver(solver, A, b, refX);
-// stat[EIGEN_GMRES].isIterative = 1;
-// printStatItem(stat, EIGEN_GMRES, best_time_id, best_time_val);
+// call_itersolver(solver, EIGEN_GMRES, A, b, refX,statFile);
// }
//GMRES+ILUT
{
cout << "\nSolving with GMRES and ILUT ... \n";
GMRES > solver;
- stat[EIGEN_GMRES_ILUT] = call_itersolver(solver, A, b, refX);
- stat[EIGEN_GMRES_ILUT].isIterative = 1;
- printStatItem(stat, EIGEN_GMRES_ILUT, best_time_id, best_time_val);
+ call_itersolver(solver, EIGEN_GMRES_ILUT, A, b, refX,statFile);
}
// Hermitian and not necessarily positive-definites
@@ -373,8 +361,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
- stat[EIGEN_SIMPLICIAL_LDLT] = call_directsolver(solver, A, b, refX);
- printStatItem(stat, EIGEN_SIMPLICIAL_LDLT, best_time_id, best_time_val);
+ call_directsolver(solver, EIGEN_SIMPLICIAL_LDLT, A, b, refX,statFile);
}
// CHOLMOD
@@ -383,8 +370,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
solver.setMode(CholmodLDLt);
- stat[EIGEN_CHOLMOD_LDLT] = call_directsolver(solver, A, b, refX);
- printStatItem(stat,EIGEN_CHOLMOD_LDLT, best_time_id, best_time_val);
+ call_directsolver(solver,EIGEN_CHOLMOD_LDLT, A, b, refX,statFile);
}
#endif
@@ -393,8 +379,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
- stat[EIGEN_PASTIX_LDLT] = call_directsolver(solver, A, b, refX);
- printStatItem(stat,EIGEN_PASTIX_LDLT, best_time_id, best_time_val);
+ call_directsolver(solver,EIGEN_PASTIX_LDLT, A, b, refX,statFile);
}
#endif
@@ -403,8 +388,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
- stat[EIGEN_PARDISO_LDLT] = call_directsolver(solver, A, b, refX);
- printStatItem(stat,EIGEN_PARDISO_LDLT, best_time_id, best_time_val);
+ call_directsolver(solver,EIGEN_PARDISO_LDLT, A, b, refX,statFile);
}
#endif
}
@@ -417,8 +401,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
- stat[EIGEN_SIMPLICIAL_LLT] = call_directsolver(solver, A, b, refX);
- printStatItem(stat,EIGEN_SIMPLICIAL_LLT, best_time_id, best_time_val);
+ call_directsolver(solver,EIGEN_SIMPLICIAL_LLT, A, b, refX,statFile);
}
// CHOLMOD
@@ -428,13 +411,11 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
solver.setMode(CholmodSupernodalLLt);
- stat[EIGEN_CHOLMOD_SUPERNODAL_LLT] = call_directsolver(solver, A, b, refX);
- printStatItem(stat,EIGEN_CHOLMOD_SUPERNODAL_LLT, best_time_id, best_time_val);
+ call_directsolver(solver,EIGEN_CHOLMOD_SUPERNODAL_LLT, A, b, refX,statFile);
// CholMod Simplicial LLT
cout << "\nSolving with CHOLMOD LLT (Simplicial) ... \n";
solver.setMode(CholmodSimplicialLLt);
- stat[EIGEN_CHOLMOD_SIMPLICIAL_LLT] = call_directsolver(solver, A, b, refX);
- printStatItem(stat,EIGEN_CHOLMOD_SIMPLICIAL_LLT, best_time_id, best_time_val);
+ call_directsolver(solver,EIGEN_CHOLMOD_SIMPLICIAL_LLT, A, b, refX,statFile);
}
#endif
@@ -443,8 +424,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
- stat[EIGEN_PASTIX_LLT] = call_directsolver(solver, A, b, refX);
- printStatItem(stat,EIGEN_PASTIX_LLT, best_time_id, best_time_val);
+ call_directsolver(solver,EIGEN_PASTIX_LLT, A, b, refX,statFile);
}
#endif
@@ -453,8 +433,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
- stat[EIGEN_PARDISO_LLT] = call_directsolver(solver, A, b, refX);
- printStatItem(stat,EIGEN_PARDISO_LLT, best_time_id, best_time_val);
+ call_directsolver(solver,EIGEN_PARDISO_LLT, A, b, refX,statFile);
}
#endif
@@ -462,21 +441,16 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver;
- stat[EIGEN_CG] = call_itersolver(solver, A, b, refX);
- stat[EIGEN_CG].isIterative = 1;
- printStatItem(stat,EIGEN_CG, best_time_id, best_time_val);
+ call_itersolver(solver,EIGEN_CG, A, b, refX,statFile);
}
//CG+IdentityPreconditioner
// {
// cout << "\nSolving with CG and IdentityPreconditioner ... \n";
// ConjugateGradient solver;
-// stat[EIGEN_CG_PRECOND] = call_itersolver(solver, A, b, refX);
-// stat[EIGEN_CG_PRECOND].isIterative = 1;
-// printStatItem(stat,EIGEN_CG_PRECOND, best_time_id, best_time_val);
+// call_itersolver(solver,EIGEN_CG_PRECOND, A, b, refX,statFile);
+// printStatItem(stat, best_time_id, best_time_val);
// }
} // End SPD matrices
-
- return best_time_id;
}
/* Browse all the matrices available in the specified folder
@@ -490,30 +464,49 @@ void Browse_Matrices(const string folder, bool statFileExists, std::string& stat
MaximumIters = maxiters; // Maximum number of iterations, global variable
RelErr = tol; //Relative residual error as stopping criterion for iterative solvers
MatrixMarketIterator it(folder);
- Stats stat[EIGEN_ALL_SOLVERS];
for ( ; it; ++it)
- {
- for (int i = 0; i < EIGEN_ALL_SOLVERS; i++)
+ {
+ //print the infos for this linear system
+ if(statFileExists)
{
- stat[i].isavail = 0;
- stat[i].isIterative = 0;
+ std::ofstream statbuf(statFile.c_str(), std::ios::app);
+ statbuf << " \n";
+ statbuf << " \n";
+ statbuf << " " << it.matname() << " \n";
+ statbuf << " " << it.matrix().rows() << " \n";
+ statbuf << " " << it.matrix().nonZeros() << "\n";
+ if (it.sym()!=NonSymmetric)
+ {
+ statbuf << " Symmetric \n" ;
+ if (it.sym() == SPD)
+ statbuf << " YES \n";
+ else
+ statbuf << " NO \n";
+
+ }
+ else
+ {
+ statbuf << " NonSymmetric \n" ;
+ statbuf << " NO \n";
+ }
+ statbuf << " \n";
+ statbuf.close();
}
- int best_time_id;
cout<< "\n\n===================================================== \n";
cout<< " ====== SOLVING WITH MATRIX " << it.matname() << " ====\n";
cout<< " =================================================== \n\n";
Matrix refX;
if(it.hasrefX()) refX = it.refX();
- best_time_id = SelectSolvers(it.matrix(), it.sym(), it.rhs(), refX, &stat[0]);
+ // Call all suitable solvers for this linear system
+ SelectSolvers(it.matrix(), it.sym(), it.rhs(), refX, statFile);
if(statFileExists)
{
- string statline;
- printHtmlStatLine(&stat[0], best_time_id, statline);
std::ofstream statbuf(statFile.c_str(), std::ios::app);
- statbuf << "" << it.matname() << " | "
- << it.matrix().rows() << " | " << it.matrix().nonZeros()<< " "<< statline ;
+ statbuf << " \n";
+ statbuf << " \n";
statbuf.close();
}
}
diff --git a/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h b/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h
index 4716b68e7..bf13cf21f 100644
--- a/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h
+++ b/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h
@@ -184,9 +184,20 @@ class MatrixMarketIterator
// if (S_ISDIR(st_buf.st_mode)) continue;
// Determine from the header if it is a matrix or a right hand side
- bool isvector,iscomplex;
+ bool isvector,iscomplex=false;
if(!getMarketHeader(curfile,m_sym,iscomplex,isvector)) continue;
if(isvector) continue;
+ if (!iscomplex)
+ {
+ if(internal::is_same >::value || internal::is_same >::value)
+ continue;
+ }
+ if (iscomplex)
+ {
+ if(internal::is_same::value || internal::is_same::value)
+ continue;
+ }
+
// Get the matrix name
std::string filename = m_curs_id->d_name;
|
---|
|
---|