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