// 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 "Eigen/SparseCore" #include #include #include #include #include #include #include #include #include #include #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 0 #define EIGEN_SUPERLU 1 #define EIGEN_PASTIX 2 #define EIGEN_PARDISO 3 #define EIGEN_BICGSTAB 4 #define EIGEN_BICGSTAB_ILUT 5 #define EIGEN_GMRES 6 #define EIGEN_GMRES_ILUT 7 #define EIGEN_SIMPLICIAL_LDLT 8 #define EIGEN_CHOLMOD_LDLT 9 #define EIGEN_PASTIX_LDLT 10 #define EIGEN_PARDISO_LDLT 11 #define EIGEN_SIMPLICIAL_LLT 12 #define EIGEN_CHOLMOD_SUPERNODAL_LLT 13 #define EIGEN_CHOLMOD_SIMPLICIAL_LLT 14 #define EIGEN_PASTIX_LLT 15 #define EIGEN_PARDISO_LLT 16 #define EIGEN_CG 17 #define EIGEN_CG_PRECOND 18 #define EIGEN_ALL_SOLVERS 19 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"; // Write the root XML element out << "\n \n" ; // 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"; } 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 << "