// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2012 Désiré Nuentsa-Wakam // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "spbenchstyle.h" #ifdef EIGEN_METIS_SUPPORT #include #endif #ifdef EIGEN_CHOLMOD_SUPPORT #include #endif #ifdef EIGEN_UMFPACK_SUPPORT #include #endif #ifdef EIGEN_PARDISO_SUPPORT #include #endif #ifdef EIGEN_SUPERLU_SUPPORT #include #endif #ifdef EIGEN_PASTIX_SUPPORT #include #endif // CONSTANTS #define EIGEN_UMFPACK 10 #define EIGEN_SUPERLU 20 #define EIGEN_PASTIX 30 #define EIGEN_PARDISO 40 #define EIGEN_SPARSELU_COLAMD 50 #define EIGEN_SPARSELU_METIS 51 #define EIGEN_BICGSTAB 60 #define EIGEN_BICGSTAB_ILUT 61 #define EIGEN_GMRES 70 #define EIGEN_GMRES_ILUT 71 #define EIGEN_SIMPLICIAL_LDLT 80 #define EIGEN_CHOLMOD_LDLT 90 #define EIGEN_PASTIX_LDLT 100 #define EIGEN_PARDISO_LDLT 110 #define EIGEN_SIMPLICIAL_LLT 120 #define EIGEN_CHOLMOD_SUPERNODAL_LLT 130 #define EIGEN_CHOLMOD_SIMPLICIAL_LLT 140 #define EIGEN_PASTIX_LLT 150 #define EIGEN_PARDISO_LLT 160 #define EIGEN_CG 170 #define EIGEN_CG_PRECOND 180 using namespace Eigen; using namespace std; // 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; } template<> inline double test_precision() { return 1e-6; } template<> inline float test_precision >() { return test_precision(); } template<> inline double test_precision >() { return test_precision(); } void printStatheader(std::ofstream& out) { // 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\n"; out << "\n \n" ; //root XML element // Print the xsl style section printBenchStyle(out); // List all available solvers out << " \n"; #ifdef EIGEN_UMFPACK_SUPPORT out <<" \n"; out << " LU \n"; out << " UMFPACK \n"; out << " \n"; #endif #ifdef EIGEN_SUPERLU_SUPPORT out <<" \n"; out << " LU \n"; out << " SUPERLU \n"; out << " \n"; #endif #ifdef EIGEN_CHOLMOD_SUPPORT 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 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 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 << " 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"; out << " LU_COLAMD \n"; out << " EIGEN \n"; out << " \n"; #ifdef EIGEN_METIS_SUPPORT out <<" \n"; out << " LU_METIS \n"; out << " EIGEN \n"; out << " \n"; #endif out << " \n"; } template void call_solver(Solver &solver, const int solver_id, const typename Solver::MatrixType& A, const Matrix& b, const Matrix& refX,std::ofstream& statbuf) { double total_time; double compute_time; double solve_time; double rel_error; Matrix x; BenchTimer timer; timer.reset(); timer.start(); solver.compute(A); if (solver.info() != Success) { std::cerr << "Solver failed ... \n"; return; } timer.stop(); compute_time = timer.value(); statbuf << "