mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-24 02:29:33 +08:00
Add common options to the benchmark interface
This commit is contained in:
parent
5cbe6a5fbf
commit
1b9097644d
@ -16,6 +16,8 @@ void bench_printhelp()
|
|||||||
cout<< " -h or --help \n print this help and return\n\n";
|
cout<< " -h or --help \n print this help and return\n\n";
|
||||||
cout<< " -d matrixdir \n Use matrixdir as the matrix folder instead of the one specified in the environment variable EIGEN_MATRIXDIR\n\n";
|
cout<< " -d matrixdir \n Use matrixdir as the matrix folder instead of the one specified in the environment variable EIGEN_MATRIXDIR\n\n";
|
||||||
cout<< " -o outputfile.html \n Output the statistics to a html file \n\n";
|
cout<< " -o outputfile.html \n Output the statistics to a html file \n\n";
|
||||||
|
cout<< " --eps <RelErr> Sets the relative tolerance for iterative solvers (default 1e-08)
|
||||||
|
cout<< " --maxits <MaxIts> Sets the maximum number of iterations (default 1000)
|
||||||
|
|
||||||
}
|
}
|
||||||
int main(int argc, char ** args)
|
int main(int argc, char ** args)
|
||||||
@ -56,14 +58,23 @@ int main(int argc, char ** args)
|
|||||||
std::cerr << "Unable to open the provided file for writting... \n";
|
std::cerr << "Unable to open the provided file for writting... \n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the maximum number of iterations and the tolerance
|
||||||
|
int maxiters = 1000;
|
||||||
|
double tol = 1e-08;
|
||||||
|
string inval;
|
||||||
|
if (get_options(argc, args, "--eps", &inval))
|
||||||
|
tol = atof(inval.c_str());
|
||||||
|
if(get_options(argc, args, "--maxits", &inval))
|
||||||
|
maxiters = atoi(inval.c_str());
|
||||||
|
|
||||||
string current_dir;
|
string current_dir;
|
||||||
// Test the matrices in %EIGEN_MATRIXDIR/real
|
// Test the matrices in %EIGEN_MATRIXDIR/real
|
||||||
current_dir = matrix_dir + "/real";
|
current_dir = matrix_dir + "/real";
|
||||||
Browse_Matrices<double>(current_dir, statFileExists, statFile);
|
Browse_Matrices<double>(current_dir, statFileExists, statFile,maxiters, tol);
|
||||||
|
|
||||||
// Test the matrices in %EIGEN_MATRIXDIR/complex
|
// Test the matrices in %EIGEN_MATRIXDIR/complex
|
||||||
current_dir = matrix_dir + "/complex";
|
current_dir = matrix_dir + "/complex";
|
||||||
Browse_Matrices<std::complex<double> >(current_dir, statFileExists, statFile);
|
Browse_Matrices<std::complex<double> >(current_dir, statFileExists, statFile, maxiters, tol);
|
||||||
|
|
||||||
if(statFileExists)
|
if(statFileExists)
|
||||||
{
|
{
|
||||||
|
@ -94,6 +94,10 @@ struct Stats{
|
|||||||
int isIterative;
|
int isIterative;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Global variables for input parameters
|
||||||
|
int MaximumIters; // Maximum number of iterations
|
||||||
|
double RelErr; // Relative error of the computed solution
|
||||||
|
|
||||||
template<typename T> inline typename NumTraits<T>::Real test_precision() { return NumTraits<T>::dummy_precision(); }
|
template<typename T> inline typename NumTraits<T>::Real test_precision() { return NumTraits<T>::dummy_precision(); }
|
||||||
template<> inline float test_precision<float>() { return 1e-3f; }
|
template<> inline float test_precision<float>() { return 1e-3f; }
|
||||||
template<> inline double test_precision<double>() { return 1e-6; }
|
template<> inline double test_precision<double>() { return 1e-6; }
|
||||||
@ -175,7 +179,7 @@ Stats call_solver(Solver &solver, const typename Solver::MatrixType& A, const Ma
|
|||||||
temp = A * x;
|
temp = A * x;
|
||||||
stat.rel_error = (b-temp).norm()/b.norm();
|
stat.rel_error = (b-temp).norm()/b.norm();
|
||||||
}
|
}
|
||||||
if ( stat.rel_error > test_precision<Scalar>() )
|
if ( stat.rel_error > RelErr )
|
||||||
{
|
{
|
||||||
stat.info = NoConvergence;
|
stat.info = NoConvergence;
|
||||||
return stat;
|
return stat;
|
||||||
@ -199,7 +203,9 @@ template<typename Solver, typename Scalar>
|
|||||||
Stats call_itersolver(Solver &solver, const typename Solver::MatrixType& A, const Matrix<Scalar, Dynamic, 1>& b, const Matrix<Scalar, Dynamic, 1>& refX)
|
Stats call_itersolver(Solver &solver, const typename Solver::MatrixType& A, const Matrix<Scalar, Dynamic, 1>& b, const Matrix<Scalar, Dynamic, 1>& refX)
|
||||||
{
|
{
|
||||||
Stats stat;
|
Stats stat;
|
||||||
solver.setTolerance(1e-10);
|
solver.setTolerance(RelErr);
|
||||||
|
solver.setMaxIterations(MaximumIters);
|
||||||
|
|
||||||
stat = call_solver(solver, A, b, refX);
|
stat = call_solver(solver, A, b, refX);
|
||||||
stat.iterations = solver.iterations();
|
stat.iterations = solver.iterations();
|
||||||
return stat;
|
return stat;
|
||||||
@ -375,8 +381,8 @@ int SelectSolvers(const SparseMatrix<Scalar>&A, unsigned int sym, Matrix<Scalar,
|
|||||||
printStatItem(stat, EIGEN_GMRES_ILUT, best_time_id, best_time_val);
|
printStatItem(stat, EIGEN_GMRES_ILUT, best_time_id, best_time_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Symmetric and not necessarily positive-definites
|
// Hermitian and not necessarily positive-definites
|
||||||
if ( (sym == Symmetric) || (sym == SPD) )
|
if (sym != NonSymmetric)
|
||||||
{
|
{
|
||||||
// Internal Cholesky
|
// Internal Cholesky
|
||||||
{
|
{
|
||||||
@ -494,8 +500,10 @@ int SelectSolvers(const SparseMatrix<Scalar>&A, unsigned int sym, Matrix<Scalar,
|
|||||||
* and optionally in the provided html file
|
* and optionally in the provided html file
|
||||||
*/
|
*/
|
||||||
template <typename Scalar>
|
template <typename Scalar>
|
||||||
void Browse_Matrices(const string folder, bool statFileExists, std::string& statFile)
|
void Browse_Matrices(const string folder, bool statFileExists, std::string& statFile, int maxiters, double tol)
|
||||||
{
|
{
|
||||||
|
MaximumIters = maxiters; // Maximum number of iterations, global variable
|
||||||
|
RelErr = tol; //Relative residual error as stopping criterion for iterative solvers
|
||||||
MatrixMarketIterator<Scalar> it(folder);
|
MatrixMarketIterator<Scalar> it(folder);
|
||||||
Stats stat[EIGEN_ALL_SOLVERS];
|
Stats stat[EIGEN_ALL_SOLVERS];
|
||||||
for ( ; it; ++it)
|
for ( ; it; ++it)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user