blob: 4acd0039cee4c0af59e5c794b79d9443458ec283 [file] [log] [blame]
Narayan Kamathc981c482012-11-02 10:59:05 +00001#include <bench/spbench/spbenchsolver.h>
2
3void 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";
Narayan Kamathc981c482012-11-02 10:59:05 +00008 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";
Carlos Hernandez7faaa9f2014-08-05 17:53:32 -070017 cout<< " -o outputfile.xml \n Output the statistics to a xml file \n\n";
Narayan Kamathc981c482012-11-02 10:59:05 +000018 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}
22int main(int argc, char ** args)
23{
24
25 bool help = ( get_options(argc, args, "-h") || get_options(argc, args, "--help") );
26 if(help) {
27 bench_printhelp();
28 return 0;
29 }
30
31 // Get the location of the test matrices
32 string matrix_dir;
33 if (!get_options(argc, args, "-d", &matrix_dir))
34 {
35 if(getenv("EIGEN_MATRIXDIR") == NULL){
36 std::cerr << "Please, specify the location of the matrices with -d mat_folder or the environment variable EIGEN_MATRIXDIR \n";
37 std::cerr << " Run with --help to see the list of all the available options \n";
38 return -1;
39 }
40 matrix_dir = getenv("EIGEN_MATRIXDIR");
41 }
42
43 std::ofstream statbuf;
44 string statFile ;
45
46 // Get the file to write the statistics
47 bool statFileExists = get_options(argc, args, "-o", &statFile);
48 if(statFileExists)
49 {
50 statbuf.open(statFile.c_str(), std::ios::out);
51 if(statbuf.good()){
52 statFileExists = true;
53 printStatheader(statbuf);
54 statbuf.close();
55 }
56 else
57 std::cerr << "Unable to open the provided file for writting... \n";
58 }
59
60 // Get the maximum number of iterations and the tolerance
61 int maxiters = 1000;
62 double tol = 1e-08;
63 string inval;
64 if (get_options(argc, args, "--eps", &inval))
65 tol = atof(inval.c_str());
66 if(get_options(argc, args, "--maxits", &inval))
67 maxiters = atoi(inval.c_str());
68
69 string current_dir;
Carlos Hernandez7faaa9f2014-08-05 17:53:32 -070070 // Test the real-arithmetics matrices
71 Browse_Matrices<double>(matrix_dir, statFileExists, statFile,maxiters, tol);
Narayan Kamathc981c482012-11-02 10:59:05 +000072
Carlos Hernandez7faaa9f2014-08-05 17:53:32 -070073 // Test the complex-arithmetics matrices
74 Browse_Matrices<std::complex<double> >(matrix_dir, statFileExists, statFile, maxiters, tol);
Narayan Kamathc981c482012-11-02 10:59:05 +000075
76 if(statFileExists)
77 {
78 statbuf.open(statFile.c_str(), std::ios::app);
Carlos Hernandez7faaa9f2014-08-05 17:53:32 -070079 statbuf << "</BENCH> \n";
Narayan Kamathc981c482012-11-02 10:59:05 +000080 cout << "\n Output written in " << statFile << " ...\n";
81 statbuf.close();
82 }
83
84 return 0;
85}
86
87