From fe9956defee58dd43b83736ebb80189eff498e19 Mon Sep 17 00:00:00 2001 From: "Desire NUENTSA W." Date: Mon, 27 Aug 2012 22:52:43 +0200 Subject: Read real and complex bench matrices from a unique folder Output and display bench results using XML and XSLT --- bench/spbench/spbench.dtd | 31 ++++ bench/spbench/spbench.xsl | 83 +++++++++ bench/spbench/spbenchsolver.cpp | 13 +- bench/spbench/spbenchsolver.h | 401 ++++++++++++++++++++-------------------- 4 files changed, 316 insertions(+), 212 deletions(-) create mode 100644 bench/spbench/spbench.dtd create mode 100644 bench/spbench/spbench.xsl (limited to 'bench/spbench') diff --git a/bench/spbench/spbench.dtd b/bench/spbench/spbench.dtd new file mode 100644 index 000000000..0fb51b89a --- /dev/null +++ b/bench/spbench/spbench.dtd @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bench/spbench/spbench.xsl b/bench/spbench/spbench.xsl new file mode 100644 index 000000000..7727542f8 --- /dev/null +++ b/bench/spbench/spbench.xsl @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Matrix N NNZ Sym SPD + + + + +
Compute Time
Solve Time
Total Time
Error + + ( + + ) +
+ + +
+ +
\ No newline at end of file diff --git a/bench/spbench/spbenchsolver.cpp b/bench/spbench/spbenchsolver.cpp index 830542ff1..ff0ce4c7d 100644 --- a/bench/spbench/spbenchsolver.cpp +++ b/bench/spbench/spbenchsolver.cpp @@ -5,7 +5,6 @@ void bench_printhelp() cout<< " \nbenchsolver : performs a benchmark of all the solvers available in Eigen \n\n"; cout<< " MATRIX FOLDER : \n"; cout<< " The matrices for the benchmark should be collected in a folder specified with an environment variable EIGEN_MATRIXDIR \n"; - cout<< " This folder should contain the subfolders real/ and complex/ : \n"; cout<< " The matrices are stored using the matrix market coordinate format \n"; cout<< " The matrix and associated right-hand side (rhs) files are named respectively \n"; cout<< " as MatrixName.mtx and MatrixName_b.mtx. If the rhs does not exist, a random one is generated. \n"; @@ -68,18 +67,16 @@ int main(int argc, char ** args) maxiters = atoi(inval.c_str()); string current_dir; - // Test the matrices in %EIGEN_MATRIXDIR/real - current_dir = matrix_dir + "/real"; - Browse_Matrices(current_dir, statFileExists, statFile,maxiters, tol); + // Test the real-arithmetics matrices + Browse_Matrices(matrix_dir, statFileExists, statFile,maxiters, tol); - // Test the matrices in %EIGEN_MATRIXDIR/complex - current_dir = matrix_dir + "/complex"; - Browse_Matrices >(current_dir, statFileExists, statFile, maxiters, tol); + // Test the complex-arithmetics matrices + Browse_Matrices >(matrix_dir, statFileExists, statFile, maxiters, tol); if(statFileExists) { statbuf.open(statFile.c_str(), std::ios::app); - statbuf << " \n"; + statbuf << " \n"; cout << "\n Output written in " << statFile << " ...\n"; statbuf.close(); } diff --git a/bench/spbench/spbenchsolver.h b/bench/spbench/spbenchsolver.h index 609c7c39d..99f05aabc 100644 --- a/bench/spbench/spbenchsolver.h +++ b/bench/spbench/spbenchsolver.h @@ -67,21 +67,12 @@ using namespace Eigen; using namespace std; -struct Stats{ - ComputationInfo info; - double total_time; - double compute_time; - double solve_time; - double rel_error; - int memory_used; - int iterations; - int isavail; - int isIterative; -}; // Global variables for input parameters int MaximumIters; // Maximum number of iterations double RelErr; // Relative error of the computed solution +double best_time_val; // Current best time overall solvers +int best_time_id; // id of the best solver for the current system template inline typename NumTraits::Real test_precision() { return NumTraits::dummy_precision(); } template<> inline float test_precision() { return 1e-3f; } @@ -91,41 +82,123 @@ template<> inline double test_precision >() { return test_p void printStatheader(std::ofstream& out) { - int LUcnt = 0; - string LUlist =" ", LLTlist = " LLT", LDLTlist = " LDLT "; + // Print XML header + // NOTE It would have been much easier to write these XML documents using external libraries like tinyXML or Xerces-C++. + + out << " \n"; + out << " \n"; + out << " \n"; + out << "\n\n"; + + // Write the root XML element + out << "\n \n" ; + // List all available solvers + out << " \n"; #ifdef EIGEN_UMFPACK_SUPPORT - LUlist += " UMFPACK "; LUcnt++; + out <<" \n"; + out << " LU \n"; + out << " UMFPACK \n"; + out << " \n"; #endif #ifdef EIGEN_SUPERLU_SUPPORT - LUlist += " SUPERLU "; LUcnt++; + out <<" \n"; + out << " LU \n"; + out << " SUPERLU \n"; + out << " \n"; #endif #ifdef EIGEN_CHOLMOD_SUPPORT - LLTlist += " CHOLMOD SP LLT CHOLMOD LLT"; - LDLTlist += "CHOLMOD LDLT"; + out <<" \n"; + out << " LLT SP \n"; + out << " CHOLMOD \n"; + out << " \n"; + + out <<" \n"; + out << " LLT \n"; + out << " CHOLMOD \n"; + out << " \n"; + + out <<" \n"; + out << " LDLT \n"; + out << " CHOLMOD \n"; + out << " \n"; #endif #ifdef EIGEN_PARDISO_SUPPORT - LUlist += " PARDISO LU"; LUcnt++; - LLTlist += " PARDISO LLT"; - LDLTlist += " PARDISO LDLT"; + out <<" \n"; + out << " LU \n"; + out << " PARDISO \n"; + out << " \n"; + + out <<" \n"; + out << " LLT \n"; + out << " PARDISO \n"; + out << " \n"; + + out <<" \n"; + out << " LDLT \n"; + out << " PARDISO \n"; + out << " \n"; #endif #ifdef EIGEN_PASTIX_SUPPORT - LUlist += " PASTIX LU"; LUcnt++; - LLTlist += " PASTIX LLT"; - LDLTlist += " PASTIX LDLT"; + out <<" \n"; + out << " LU \n"; + out << " PASTIX \n"; + out << " \n"; + + out <<" \n"; + out << " LLT \n"; + out << " PASTIX \n"; + out << " \n"; + + out <<" \n"; + out << " LDLT \n"; + out << " PASTIX \n"; + out << " \n"; #endif - out << "\n "; - out << "
Matrix N NNZ "; - if (LUcnt) out << LUlist; - out << " BiCGSTAB BiCGSTAB+ILUT"<< "GMRES+ILUT" < CG "<< std::endl; + out <<" \n"; + out << " BICGSTAB \n"; + out << " EIGEN \n"; + out << " \n"; + + out <<" \n"; + out << " BICGSTAB_ILUT \n"; + out << " EIGEN \n"; + out << " \n"; + + out <<" \n"; + out << " GMRES_ILUT \n"; + out << " EIGEN \n"; + out << " \n"; + + out <<" \n"; + out << " LDLT \n"; + out << " EIGEN \n"; + out << " \n"; + + out <<" \n"; + out << " LLT \n"; + out << " EIGEN \n"; + out << " \n"; + + out <<" \n"; + out << " CG \n"; + out << " EIGEN \n"; + out << " \n"; + + out << " \n"; + } template -Stats call_solver(Solver &solver, const typename Solver::MatrixType& A, const Matrix& b, const Matrix& refX) +void call_solver(Solver &solver, const int solver_id, const typename Solver::MatrixType& A, const Matrix& b, const Matrix& refX,std::ofstream& statbuf) { - Stats stat; + + double total_time; + double compute_time; + double solve_time; + double rel_error; Matrix x; BenchTimer timer; timer.reset(); @@ -133,170 +206,95 @@ Stats call_solver(Solver &solver, const typename Solver::MatrixType& A, const Ma solver.compute(A); if (solver.info() != Success) { - stat.info = NumericalIssue; std::cerr << "Solver failed ... \n"; - return stat; + return; } - timer.stop(); - stat.compute_time = timer.value(); - + timer.stop(); + compute_time = timer.value(); + statbuf << " "; - else - markup = ""; - - if (stat[i].info == Success){ - compute << markup << stat[i].compute_time; - solve << markup << stat[i].solve_time; - total << markup << stat[i].total_time; - error << " " << stat[i].rel_error; - if(stat[i].isIterative == 1) { - error << " (" << stat[i].iterations << ") "; - } - } - else { - compute << " -" ; - solve << " -" ; - total << " -" ; - if(stat[i].info == NoConvergence){ - error << " "<< stat[i].rel_error ; - if(stat[i].isIterative == 1) - error << " (" << stat[i].iterations << ") "; - } - else error << " - "; - } - } - - statline = "Compute Time " + compute.str() + "\n" - + "
Solve Time " + solve.str() + "\n" - + "
Total Time " + total.str() + "\n" - +"
Error(Iter)" + error.str() + "\n"; - -} - template -int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix& b, const Matrix& refX, Stats *stat) +void SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix& b, const Matrix& refX, std::string& statFile) { typedef SparseMatrix SpMat; // First, deal with Nonsymmetric and symmetric matrices - int best_time_id = 0; - double best_time_val = 0.0; + best_time_id = 0; + best_time_val = 0.0; //UMFPACK #ifdef EIGEN_UMFPACK_SUPPORT { cout << "Solving with UMFPACK LU ... \n"; UmfPackLU solver; - stat[EIGEN_UMFPACK] = call_directsolver(solver, A, b, refX); - printStatItem(stat, EIGEN_UMFPACK, best_time_id, best_time_val); + call_directsolver(solver, EIGEN_UMFPACK, A, b, refX,statFile); } #endif //SuperLU @@ -304,8 +302,8 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; - stat[EIGEN_SUPERLU] = call_directsolver(solver, A, b, refX); - printStatItem(stat, EIGEN_SUPERLU, best_time_id, best_time_val); + call_directsolver(solver, EIGEN_SUPERLU, A, b, refX,statFile); + printStatItem(stat, best_time_id, best_time_val); } #endif @@ -314,8 +312,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; - stat[EIGEN_PASTIX] = call_directsolver(solver, A, b, refX) ; - printStatItem(stat, EIGEN_PASTIX, best_time_id, best_time_val); + call_directsolver(solver, EIGEN_PASTIX, A, b, refX,statFile) ; } #endif @@ -324,8 +321,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; - stat[EIGEN_PARDISO] = call_directsolver(solver, A, b, refX); - printStatItem(stat, EIGEN_PARDISO, best_time_id, best_time_val); + call_directsolver(solver, EIGEN_PARDISO, A, b, refX,statFile); } #endif @@ -335,17 +331,13 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; - stat[EIGEN_BICGSTAB] = call_itersolver(solver, A, b, refX); - stat[EIGEN_BICGSTAB].isIterative = 1; - printStatItem(stat, EIGEN_BICGSTAB, best_time_id, best_time_val); + call_itersolver(solver, EIGEN_BICGSTAB, A, b, refX,statFile); } //BiCGSTAB+ILUT { cout << "\nSolving with BiCGSTAB and ILUT ... \n"; BiCGSTAB > solver; - stat[EIGEN_BICGSTAB_ILUT] = call_itersolver(solver, A, b, refX); - stat[EIGEN_BICGSTAB_ILUT].isIterative = 1; - printStatItem(stat, EIGEN_BICGSTAB_ILUT, best_time_id, best_time_val); + call_itersolver(solver, EIGEN_BICGSTAB_ILUT, A, b, refX,statFile); } @@ -353,17 +345,13 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; -// stat[EIGEN_GMRES] = call_itersolver(solver, A, b, refX); -// stat[EIGEN_GMRES].isIterative = 1; -// printStatItem(stat, EIGEN_GMRES, best_time_id, best_time_val); +// call_itersolver(solver, EIGEN_GMRES, A, b, refX,statFile); // } //GMRES+ILUT { cout << "\nSolving with GMRES and ILUT ... \n"; GMRES > solver; - stat[EIGEN_GMRES_ILUT] = call_itersolver(solver, A, b, refX); - stat[EIGEN_GMRES_ILUT].isIterative = 1; - printStatItem(stat, EIGEN_GMRES_ILUT, best_time_id, best_time_val); + call_itersolver(solver, EIGEN_GMRES_ILUT, A, b, refX,statFile); } // Hermitian and not necessarily positive-definites @@ -373,8 +361,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; - stat[EIGEN_SIMPLICIAL_LDLT] = call_directsolver(solver, A, b, refX); - printStatItem(stat, EIGEN_SIMPLICIAL_LDLT, best_time_id, best_time_val); + call_directsolver(solver, EIGEN_SIMPLICIAL_LDLT, A, b, refX,statFile); } // CHOLMOD @@ -383,8 +370,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; solver.setMode(CholmodLDLt); - stat[EIGEN_CHOLMOD_LDLT] = call_directsolver(solver, A, b, refX); - printStatItem(stat,EIGEN_CHOLMOD_LDLT, best_time_id, best_time_val); + call_directsolver(solver,EIGEN_CHOLMOD_LDLT, A, b, refX,statFile); } #endif @@ -393,8 +379,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; - stat[EIGEN_PASTIX_LDLT] = call_directsolver(solver, A, b, refX); - printStatItem(stat,EIGEN_PASTIX_LDLT, best_time_id, best_time_val); + call_directsolver(solver,EIGEN_PASTIX_LDLT, A, b, refX,statFile); } #endif @@ -403,8 +388,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; - stat[EIGEN_PARDISO_LDLT] = call_directsolver(solver, A, b, refX); - printStatItem(stat,EIGEN_PARDISO_LDLT, best_time_id, best_time_val); + call_directsolver(solver,EIGEN_PARDISO_LDLT, A, b, refX,statFile); } #endif } @@ -417,8 +401,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; - stat[EIGEN_SIMPLICIAL_LLT] = call_directsolver(solver, A, b, refX); - printStatItem(stat,EIGEN_SIMPLICIAL_LLT, best_time_id, best_time_val); + call_directsolver(solver,EIGEN_SIMPLICIAL_LLT, A, b, refX,statFile); } // CHOLMOD @@ -428,13 +411,11 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; solver.setMode(CholmodSupernodalLLt); - stat[EIGEN_CHOLMOD_SUPERNODAL_LLT] = call_directsolver(solver, A, b, refX); - printStatItem(stat,EIGEN_CHOLMOD_SUPERNODAL_LLT, best_time_id, best_time_val); + call_directsolver(solver,EIGEN_CHOLMOD_SUPERNODAL_LLT, A, b, refX,statFile); // CholMod Simplicial LLT cout << "\nSolving with CHOLMOD LLT (Simplicial) ... \n"; solver.setMode(CholmodSimplicialLLt); - stat[EIGEN_CHOLMOD_SIMPLICIAL_LLT] = call_directsolver(solver, A, b, refX); - printStatItem(stat,EIGEN_CHOLMOD_SIMPLICIAL_LLT, best_time_id, best_time_val); + call_directsolver(solver,EIGEN_CHOLMOD_SIMPLICIAL_LLT, A, b, refX,statFile); } #endif @@ -443,8 +424,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; - stat[EIGEN_PASTIX_LLT] = call_directsolver(solver, A, b, refX); - printStatItem(stat,EIGEN_PASTIX_LLT, best_time_id, best_time_val); + call_directsolver(solver,EIGEN_PASTIX_LLT, A, b, refX,statFile); } #endif @@ -453,8 +433,7 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; - stat[EIGEN_PARDISO_LLT] = call_directsolver(solver, A, b, refX); - printStatItem(stat,EIGEN_PARDISO_LLT, best_time_id, best_time_val); + call_directsolver(solver,EIGEN_PARDISO_LLT, A, b, refX,statFile); } #endif @@ -462,21 +441,16 @@ int SelectSolvers(const SparseMatrix&A, unsigned int sym, Matrix solver; - stat[EIGEN_CG] = call_itersolver(solver, A, b, refX); - stat[EIGEN_CG].isIterative = 1; - printStatItem(stat,EIGEN_CG, best_time_id, best_time_val); + call_itersolver(solver,EIGEN_CG, A, b, refX,statFile); } //CG+IdentityPreconditioner // { // cout << "\nSolving with CG and IdentityPreconditioner ... \n"; // ConjugateGradient solver; -// stat[EIGEN_CG_PRECOND] = call_itersolver(solver, A, b, refX); -// stat[EIGEN_CG_PRECOND].isIterative = 1; -// printStatItem(stat,EIGEN_CG_PRECOND, best_time_id, best_time_val); +// call_itersolver(solver,EIGEN_CG_PRECOND, A, b, refX,statFile); +// printStatItem(stat, best_time_id, best_time_val); // } } // End SPD matrices - - return best_time_id; } /* Browse all the matrices available in the specified folder @@ -490,30 +464,49 @@ void Browse_Matrices(const string folder, bool statFileExists, std::string& stat MaximumIters = maxiters; // Maximum number of iterations, global variable RelErr = tol; //Relative residual error as stopping criterion for iterative solvers MatrixMarketIterator it(folder); - Stats stat[EIGEN_ALL_SOLVERS]; for ( ; it; ++it) - { - for (int i = 0; i < EIGEN_ALL_SOLVERS; i++) + { + //print the infos for this linear system + if(statFileExists) { - stat[i].isavail = 0; - stat[i].isIterative = 0; + std::ofstream statbuf(statFile.c_str(), std::ios::app); + statbuf << " \n"; + statbuf << " \n"; + statbuf << " " << it.matname() << " \n"; + statbuf << " " << it.matrix().rows() << " \n"; + statbuf << " " << it.matrix().nonZeros() << "\n"; + if (it.sym()!=NonSymmetric) + { + statbuf << " Symmetric \n" ; + if (it.sym() == SPD) + statbuf << " YES \n"; + else + statbuf << " NO \n"; + + } + else + { + statbuf << " NonSymmetric \n" ; + statbuf << " NO \n"; + } + statbuf << " \n"; + statbuf.close(); } - int best_time_id; cout<< "\n\n===================================================== \n"; cout<< " ====== SOLVING WITH MATRIX " << it.matname() << " ====\n"; cout<< " =================================================== \n\n"; Matrix refX; if(it.hasrefX()) refX = it.refX(); - best_time_id = SelectSolvers(it.matrix(), it.sym(), it.rhs(), refX, &stat[0]); + // Call all suitable solvers for this linear system + SelectSolvers(it.matrix(), it.sym(), it.rhs(), refX, statFile); if(statFileExists) { - string statline; - printHtmlStatLine(&stat[0], best_time_id, statline); std::ofstream statbuf(statFile.c_str(), std::ios::app); - statbuf << "
" << it.matname() << " " - << it.matrix().rows() << " " << it.matrix().nonZeros()<< " "<< statline ; + statbuf << " \n"; + statbuf << " \n"; statbuf.close(); } } -- cgit v1.2.3