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.

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