You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.4 KiB

  1. #include <bench/spbench/spbenchsolver.h>
  2. void bench_printhelp()
  3. {
  4. cout<< " \nbenchsolver : performs a benchmark of all the solvers available in Eigen \n\n";
  5. cout<< " MATRIX FOLDER : \n";
  6. cout<< " The matrices for the benchmark should be collected in a folder specified with an environment variable EIGEN_MATRIXDIR \n";
  7. cout<< " This folder should contain the subfolders real/ and complex/ : \n";
  8. cout<< " The matrices are stored using the matrix market coordinate format \n";
  9. cout<< " The matrix and associated right-hand side (rhs) files are named respectively \n";
  10. cout<< " as MatrixName.mtx and MatrixName_b.mtx. If the rhs does not exist, a random one is generated. \n";
  11. cout<< " If a matrix is SPD, the matrix should be named as MatrixName_SPD.mtx \n";
  12. cout<< " If a true solution exists, it should be named as MatrixName_x.mtx; \n" ;
  13. cout<< " it will be used to compute the norm of the error relative to the computed solutions\n\n";
  14. cout<< " OPTIONS : \n";
  15. cout<< " -h or --help \n print this help and return\n\n";
  16. cout<< " -d matrixdir \n Use matrixdir as the matrix folder instead of the one specified in the environment variable EIGEN_MATRIXDIR\n\n";
  17. cout<< " -o outputfile.html \n Output the statistics to a html file \n\n";
  18. cout<< " --eps <RelErr> Sets the relative tolerance for iterative solvers (default 1e-08) \n\n";
  19. cout<< " --maxits <MaxIts> Sets the maximum number of iterations (default 1000) \n\n";
  20. }
  21. int main(int argc, char ** args)
  22. {
  23. bool help = ( get_options(argc, args, "-h") || get_options(argc, args, "--help") );
  24. if(help) {
  25. bench_printhelp();
  26. return 0;
  27. }
  28. // Get the location of the test matrices
  29. string matrix_dir;
  30. if (!get_options(argc, args, "-d", &matrix_dir))
  31. {
  32. if(getenv("EIGEN_MATRIXDIR") == NULL){
  33. std::cerr << "Please, specify the location of the matrices with -d mat_folder or the environment variable EIGEN_MATRIXDIR \n";
  34. std::cerr << " Run with --help to see the list of all the available options \n";
  35. return -1;
  36. }
  37. matrix_dir = getenv("EIGEN_MATRIXDIR");
  38. }
  39. std::ofstream statbuf;
  40. string statFile ;
  41. // Get the file to write the statistics
  42. bool statFileExists = get_options(argc, args, "-o", &statFile);
  43. if(statFileExists)
  44. {
  45. statbuf.open(statFile.c_str(), std::ios::out);
  46. if(statbuf.good()){
  47. statFileExists = true;
  48. printStatheader(statbuf);
  49. statbuf.close();
  50. }
  51. else
  52. std::cerr << "Unable to open the provided file for writting... \n";
  53. }
  54. // Get the maximum number of iterations and the tolerance
  55. int maxiters = 1000;
  56. double tol = 1e-08;
  57. string inval;
  58. if (get_options(argc, args, "--eps", &inval))
  59. tol = atof(inval.c_str());
  60. if(get_options(argc, args, "--maxits", &inval))
  61. maxiters = atoi(inval.c_str());
  62. string current_dir;
  63. // Test the matrices in %EIGEN_MATRIXDIR/real
  64. current_dir = matrix_dir + "/real";
  65. Browse_Matrices<double>(current_dir, statFileExists, statFile,maxiters, tol);
  66. // Test the matrices in %EIGEN_MATRIXDIR/complex
  67. current_dir = matrix_dir + "/complex";
  68. Browse_Matrices<std::complex<double> >(current_dir, statFileExists, statFile, maxiters, tol);
  69. if(statFileExists)
  70. {
  71. statbuf.open(statFile.c_str(), std::ios::app);
  72. statbuf << "</TABLE> \n";
  73. cout << "\n Output written in " << statFile << " ...\n";
  74. statbuf.close();
  75. }
  76. return 0;
  77. }