Disabled external gits

This commit is contained in:
2022-04-07 18:46:57 +02:00
parent 88cb3426ad
commit 15e7120d6d
5316 changed files with 4563444 additions and 6 deletions

View File

@@ -0,0 +1,85 @@
set(BLAS_FOUND TRUE)
set(LAPACK_FOUND TRUE)
set(BLAS_LIBRARIES eigen_blas_static)
set(LAPACK_LIBRARIES eigen_lapack_static)
set(SPARSE_LIBS "")
# find_library(PARDISO_LIBRARIES pardiso412-GNU450-X86-64)
# if(PARDISO_LIBRARIES)
# add_definitions("-DEIGEN_PARDISO_SUPPORT")
# set(SPARSE_LIBS ${SPARSE_LIBS} ${PARDISO_LIBRARIES})
# endif(PARDISO_LIBRARIES)
find_package(Cholmod)
if(CHOLMOD_FOUND AND BLAS_FOUND AND LAPACK_FOUND)
add_definitions("-DEIGEN_CHOLMOD_SUPPORT")
include_directories(${CHOLMOD_INCLUDES})
set(SPARSE_LIBS ${SPARSE_LIBS} ${CHOLMOD_LIBRARIES} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
set(CHOLMOD_ALL_LIBS ${CHOLMOD_LIBRARIES} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
endif()
find_package(Umfpack)
if(UMFPACK_FOUND AND BLAS_FOUND)
add_definitions("-DEIGEN_UMFPACK_SUPPORT")
include_directories(${UMFPACK_INCLUDES})
set(SPARSE_LIBS ${SPARSE_LIBS} ${UMFPACK_LIBRARIES} ${BLAS_LIBRARIES})
set(UMFPACK_ALL_LIBS ${UMFPACK_LIBRARIES} ${BLAS_LIBRARIES})
endif()
find_package(SuperLU 4.0)
if(SUPERLU_FOUND AND BLAS_FOUND)
add_definitions("-DEIGEN_SUPERLU_SUPPORT")
include_directories(${SUPERLU_INCLUDES})
set(SPARSE_LIBS ${SPARSE_LIBS} ${SUPERLU_LIBRARIES} ${BLAS_LIBRARIES})
set(SUPERLU_ALL_LIBS ${SUPERLU_LIBRARIES} ${BLAS_LIBRARIES})
endif()
find_package(PASTIX QUIET COMPONENTS METIS SCOTCH)
# check that the PASTIX found is a version without MPI
find_path(PASTIX_pastix_nompi.h_INCLUDE_DIRS
NAMES pastix_nompi.h
HINTS ${PASTIX_INCLUDE_DIRS}
)
if (NOT PASTIX_pastix_nompi.h_INCLUDE_DIRS)
message(STATUS "A version of Pastix has been found but pastix_nompi.h does not exist in the include directory."
" Because Eigen tests require a version without MPI, we disable the Pastix backend.")
endif()
if(PASTIX_FOUND AND PASTIX_pastix_nompi.h_INCLUDE_DIRS AND BLAS_FOUND)
add_definitions("-DEIGEN_PASTIX_SUPPORT")
include_directories(${PASTIX_INCLUDE_DIRS_DEP})
if(SCOTCH_FOUND)
include_directories(${SCOTCH_INCLUDE_DIRS})
set(PASTIX_LIBRARIES ${PASTIX_LIBRARIES} ${SCOTCH_LIBRARIES})
elseif(METIS_FOUND)
include_directories(${METIS_INCLUDE_DIRS})
set(PASTIX_LIBRARIES ${PASTIX_LIBRARIES} ${METIS_LIBRARIES})
endif(SCOTCH_FOUND)
set(SPARSE_LIBS ${SPARSE_LIBS} ${PASTIX_LIBRARIES_DEP} ${ORDERING_LIBRARIES})
set(PASTIX_ALL_LIBS ${PASTIX_LIBRARIES_DEP})
endif()
if(METIS_FOUND)
include_directories(${METIS_INCLUDE_DIRS})
set (SPARSE_LIBS ${SPARSE_LIBS} ${METIS_LIBRARIES})
add_definitions("-DEIGEN_METIS_SUPPORT")
endif(METIS_FOUND)
find_library(RT_LIBRARY rt)
if(RT_LIBRARY)
set(SPARSE_LIBS ${SPARSE_LIBS} ${RT_LIBRARY})
endif(RT_LIBRARY)
add_executable(spbenchsolver spbenchsolver.cpp)
target_link_libraries (spbenchsolver ${SPARSE_LIBS})
add_executable(spsolver sp_solver.cpp)
target_link_libraries (spsolver ${SPARSE_LIBS})
add_executable(test_sparseLU test_sparseLU.cpp)
target_link_libraries (test_sparseLU ${SPARSE_LIBS})

View File

@@ -0,0 +1,125 @@
// Small bench routine for Eigen available in Eigen
// (C) Desire NUENTSA WAKAM, INRIA
#include <iostream>
#include <fstream>
#include <iomanip>
#include <Eigen/Jacobi>
#include <Eigen/Householder>
#include <Eigen/IterativeLinearSolvers>
#include <Eigen/LU>
#include <unsupported/Eigen/SparseExtra>
//#include <Eigen/SparseLU>
#include <Eigen/SuperLUSupport>
// #include <unsupported/Eigen/src/IterativeSolvers/Scaling.h>
#include <bench/BenchTimer.h>
#include <unsupported/Eigen/IterativeSolvers>
using namespace std;
using namespace Eigen;
int main(int argc, char **args)
{
SparseMatrix<double, ColMajor> A;
typedef SparseMatrix<double, ColMajor>::Index Index;
typedef Matrix<double, Dynamic, Dynamic> DenseMatrix;
typedef Matrix<double, Dynamic, 1> DenseRhs;
VectorXd b, x, tmp;
BenchTimer timer,totaltime;
//SparseLU<SparseMatrix<double, ColMajor> > solver;
// SuperLU<SparseMatrix<double, ColMajor> > solver;
ConjugateGradient<SparseMatrix<double, ColMajor>, Lower,IncompleteCholesky<double,Lower> > solver;
ifstream matrix_file;
string line;
int n;
// Set parameters
// solver.iparm(IPARM_THREAD_NBR) = 4;
/* Fill the matrix with sparse matrix stored in Matrix-Market coordinate column-oriented format */
if (argc < 2) assert(false && "please, give the matrix market file ");
timer.start();
totaltime.start();
loadMarket(A, args[1]);
cout << "End charging matrix " << endl;
bool iscomplex=false, isvector=false;
int sym;
getMarketHeader(args[1], sym, iscomplex, isvector);
if (iscomplex) { cout<< " Not for complex matrices \n"; return -1; }
if (isvector) { cout << "The provided file is not a matrix file\n"; return -1;}
if (sym != 0) { // symmetric matrices, only the lower part is stored
SparseMatrix<double, ColMajor> temp;
temp = A;
A = temp.selfadjointView<Lower>();
}
timer.stop();
n = A.cols();
// ====== TESTS FOR SPARSE TUTORIAL ======
// cout<< "OuterSize " << A.outerSize() << " inner " << A.innerSize() << endl;
// SparseMatrix<double, RowMajor> mat1(A);
// SparseMatrix<double, RowMajor> mat2;
// cout << " norm of A " << mat1.norm() << endl; ;
// PermutationMatrix<Dynamic, Dynamic, int> perm(n);
// perm.resize(n,1);
// perm.indices().setLinSpaced(n, 0, n-1);
// mat2 = perm * mat1;
// mat.subrows();
// mat2.resize(n,n);
// mat2.reserve(10);
// mat2.setConstant();
// std::cout<< "NORM " << mat1.squaredNorm()<< endl;
cout<< "Time to load the matrix " << timer.value() <<endl;
/* Fill the right hand side */
// solver.set_restart(374);
if (argc > 2)
loadMarketVector(b, args[2]);
else
{
b.resize(n);
tmp.resize(n);
// tmp.setRandom();
for (int i = 0; i < n; i++) tmp(i) = i;
b = A * tmp ;
}
// Scaling<SparseMatrix<double> > scal;
// scal.computeRef(A);
// b = scal.LeftScaling().cwiseProduct(b);
/* Compute the factorization */
cout<< "Starting the factorization "<< endl;
timer.reset();
timer.start();
cout<< "Size of Input Matrix "<< b.size()<<"\n\n";
cout<< "Rows and columns "<< A.rows() <<" " <<A.cols() <<"\n";
solver.compute(A);
// solver.analyzePattern(A);
// solver.factorize(A);
if (solver.info() != Success) {
std::cout<< "The solver failed \n";
return -1;
}
timer.stop();
float time_comp = timer.value();
cout <<" Compute Time " << time_comp<< endl;
timer.reset();
timer.start();
x = solver.solve(b);
// x = scal.RightScaling().cwiseProduct(x);
timer.stop();
float time_solve = timer.value();
cout<< " Time to solve " << time_solve << endl;
/* Check the accuracy */
VectorXd tmp2 = b - A*x;
double tempNorm = tmp2.norm()/b.norm();
cout << "Relative norm of the computed solution : " << tempNorm <<"\n";
// cout << "Iterations : " << solver.iterations() << "\n";
totaltime.stop();
cout << "Total time " << totaltime.value() << "\n";
// std::cout<<x.transpose()<<"\n";
return 0;
}

View File

@@ -0,0 +1,31 @@
<!ELEMENT BENCH (AVAILSOLVER+,LINEARSYSTEM+)>
<!ELEMENT AVAILSOLVER (SOLVER+)>
<!ELEMENT SOLVER (TYPE,PACKAGE)>
<!ELEMENT TYPE (#PCDATA)> <!-- One of LU, LLT, LDLT, ITER -->
<!ELEMENT PACKAGE (#PCDATA)> <!-- Derived from a library -->
<!ELEMENT LINEARSYSTEM (MATRIX,SOLVER_STAT+,BEST_SOLVER,GLOBAL_PARAMS*)>
<!ELEMENT MATRIX (NAME,SIZE,ENTRIES,PATTERN?,SYMMETRY,POSDEF?,ARITHMETIC,RHS*)>
<!ELEMENT NAME (#PCDATA)>
<!ELEMENT SIZE (#PCDATA)>
<!ELEMENT ENTRIES (#PCDATA)> <!-- The number of nonzeros elements -->
<!ELEMENT PATTERN (#PCDATA)> <!-- Is structural pattern symmetric or not -->
<!ELEMENT SYMMETRY (#PCDATA)> <!-- symmmetry with numerical values -->
<!ELEMENT POSDEF (#PCDATA)> <!-- Is the matrix positive definite or not -->
<!ELEMENT ARITHMETIC (#PCDATA)>
<!ELEMENT RHS (SOURCE)> <!-- A matrix can have one or more right hand side associated. -->
<!ELEMENT SOURCE (#PCDATA)> <!-- Source of the right hand side, either generated or provided -->
<!ELEMENT SOLVER_STAT (PARAMS*,TIME,ERROR,ITER?)>
<!ELEMENT PARAMS (#PCDATA)>
<!ELEMENT TIME (COMPUTE,SOLVE,TOTAL)>
<!ELEMENT COMPUTE (#PCDATA)> <!-- Time to analyze,to factorize, or to setup the preconditioner-->
<!ELEMENT SOLVE (#PCDATA)> <!-- Time to solve with all the available rhs -->
<!ELEMENT TOTAL (#PCDATA)>
<!ELEMENT ERROR (#PCDATA)> <!-- Either the relative error or the relative residual norm -->
<!ELEMENT ITER (#PCDATA)> <!-- Number of iterations -->
<!ELEMENT BEST_SOLVER CDATA> <!-- Id of the best solver -->
<!ELEMENT GLOBAL_PARAMS (#PCDATA)> <!-- Parameters shared by all solvers -->
<!ATTLIST SOLVER ID CDATA #REQUIRED>
<!ATTLIST SOLVER_STAT ID CDATA #REQUIRED>
<!ATTLIST BEST_SOLVER ID CDATA #REQUIRED>
<!ATTLIST RHS ID CDATA #IMPLIED>

View File

@@ -0,0 +1,87 @@
#include <bench/spbench/spbenchsolver.h>
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<< " 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";
cout<< " If a matrix is SPD, the matrix should be named as MatrixName_SPD.mtx \n";
cout<< " If a true solution exists, it should be named as MatrixName_x.mtx; \n" ;
cout<< " it will be used to compute the norm of the error relative to the computed solutions\n\n";
cout<< " OPTIONS : \n";
cout<< " -h or --help \n print this help and return\n\n";
cout<< " -d matrixdir \n Use matrixdir as the matrix folder instead of the one specified in the environment variable EIGEN_MATRIXDIR\n\n";
cout<< " -o outputfile.xml \n Output the statistics to a xml file \n\n";
cout<< " --eps <RelErr> Sets the relative tolerance for iterative solvers (default 1e-08) \n\n";
cout<< " --maxits <MaxIts> Sets the maximum number of iterations (default 1000) \n\n";
}
int main(int argc, char ** args)
{
bool help = ( get_options(argc, args, "-h") || get_options(argc, args, "--help") );
if(help) {
bench_printhelp();
return 0;
}
// Get the location of the test matrices
string matrix_dir;
if (!get_options(argc, args, "-d", &matrix_dir))
{
if(getenv("EIGEN_MATRIXDIR") == NULL){
std::cerr << "Please, specify the location of the matrices with -d mat_folder or the environment variable EIGEN_MATRIXDIR \n";
std::cerr << " Run with --help to see the list of all the available options \n";
return -1;
}
matrix_dir = getenv("EIGEN_MATRIXDIR");
}
std::ofstream statbuf;
string statFile ;
// Get the file to write the statistics
bool statFileExists = get_options(argc, args, "-o", &statFile);
if(statFileExists)
{
statbuf.open(statFile.c_str(), std::ios::out);
if(statbuf.good()){
statFileExists = true;
printStatheader(statbuf);
statbuf.close();
}
else
std::cerr << "Unable to open the provided file for writting... \n";
}
// Get the maximum number of iterations and the tolerance
int maxiters = 1000;
double tol = 1e-08;
string inval;
if (get_options(argc, args, "--eps", &inval))
tol = atof(inval.c_str());
if(get_options(argc, args, "--maxits", &inval))
maxiters = atoi(inval.c_str());
string current_dir;
// Test the real-arithmetics matrices
Browse_Matrices<double>(matrix_dir, statFileExists, statFile,maxiters, tol);
// Test the complex-arithmetics matrices
Browse_Matrices<std::complex<double> >(matrix_dir, statFileExists, statFile, maxiters, tol);
if(statFileExists)
{
statbuf.open(statFile.c_str(), std::ios::app);
statbuf << "</BENCH> \n";
cout << "\n Output written in " << statFile << " ...\n";
statbuf.close();
}
return 0;
}

View File

@@ -0,0 +1,554 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
//
// 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 <iostream>
#include <fstream>
#include <Eigen/SparseCore>
#include <bench/BenchTimer.h>
#include <cstdlib>
#include <string>
#include <Eigen/Cholesky>
#include <Eigen/Jacobi>
#include <Eigen/Householder>
#include <Eigen/IterativeLinearSolvers>
#include <unsupported/Eigen/IterativeSolvers>
#include <Eigen/LU>
#include <unsupported/Eigen/SparseExtra>
#include <Eigen/SparseLU>
#include "spbenchstyle.h"
#ifdef EIGEN_METIS_SUPPORT
#include <Eigen/MetisSupport>
#endif
#ifdef EIGEN_CHOLMOD_SUPPORT
#include <Eigen/CholmodSupport>
#endif
#ifdef EIGEN_UMFPACK_SUPPORT
#include <Eigen/UmfPackSupport>
#endif
#ifdef EIGEN_PARDISO_SUPPORT
#include <Eigen/PardisoSupport>
#endif
#ifdef EIGEN_SUPERLU_SUPPORT
#include <Eigen/SuperLUSupport>
#endif
#ifdef EIGEN_PASTIX_SUPPORT
#include <Eigen/PaStiXSupport>
#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<typename T> inline typename NumTraits<T>::Real test_precision() { return NumTraits<T>::dummy_precision(); }
template<> inline float test_precision<float>() { return 1e-3f; }
template<> inline double test_precision<double>() { return 1e-6; }
template<> inline float test_precision<std::complex<float> >() { return test_precision<float>(); }
template<> inline double test_precision<std::complex<double> >() { return test_precision<double>(); }
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 << "<?xml version='1.0' encoding='UTF-8'?> \n";
out << "<?xml-stylesheet type='text/xsl' href='#stylesheet' ?> \n";
out << "<!DOCTYPE BENCH [\n<!ATTLIST xsl:stylesheet\n id\t ID #REQUIRED>\n]>";
out << "\n\n<!-- Generated by the Eigen library -->\n";
out << "\n<BENCH> \n" ; //root XML element
// Print the xsl style section
printBenchStyle(out);
// List all available solvers
out << " <AVAILSOLVER> \n";
#ifdef EIGEN_UMFPACK_SUPPORT
out <<" <SOLVER ID='" << EIGEN_UMFPACK << "'>\n";
out << " <TYPE> LU </TYPE> \n";
out << " <PACKAGE> UMFPACK </PACKAGE> \n";
out << " </SOLVER> \n";
#endif
#ifdef EIGEN_SUPERLU_SUPPORT
out <<" <SOLVER ID='" << EIGEN_SUPERLU << "'>\n";
out << " <TYPE> LU </TYPE> \n";
out << " <PACKAGE> SUPERLU </PACKAGE> \n";
out << " </SOLVER> \n";
#endif
#ifdef EIGEN_CHOLMOD_SUPPORT
out <<" <SOLVER ID='" << EIGEN_CHOLMOD_SIMPLICIAL_LLT << "'>\n";
out << " <TYPE> LLT SP</TYPE> \n";
out << " <PACKAGE> CHOLMOD </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_CHOLMOD_SUPERNODAL_LLT << "'>\n";
out << " <TYPE> LLT</TYPE> \n";
out << " <PACKAGE> CHOLMOD </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_CHOLMOD_LDLT << "'>\n";
out << " <TYPE> LDLT </TYPE> \n";
out << " <PACKAGE> CHOLMOD </PACKAGE> \n";
out << " </SOLVER> \n";
#endif
#ifdef EIGEN_PARDISO_SUPPORT
out <<" <SOLVER ID='" << EIGEN_PARDISO << "'>\n";
out << " <TYPE> LU </TYPE> \n";
out << " <PACKAGE> PARDISO </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_PARDISO_LLT << "'>\n";
out << " <TYPE> LLT </TYPE> \n";
out << " <PACKAGE> PARDISO </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_PARDISO_LDLT << "'>\n";
out << " <TYPE> LDLT </TYPE> \n";
out << " <PACKAGE> PARDISO </PACKAGE> \n";
out << " </SOLVER> \n";
#endif
#ifdef EIGEN_PASTIX_SUPPORT
out <<" <SOLVER ID='" << EIGEN_PASTIX << "'>\n";
out << " <TYPE> LU </TYPE> \n";
out << " <PACKAGE> PASTIX </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_PASTIX_LLT << "'>\n";
out << " <TYPE> LLT </TYPE> \n";
out << " <PACKAGE> PASTIX </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_PASTIX_LDLT << "'>\n";
out << " <TYPE> LDLT </TYPE> \n";
out << " <PACKAGE> PASTIX </PACKAGE> \n";
out << " </SOLVER> \n";
#endif
out <<" <SOLVER ID='" << EIGEN_BICGSTAB << "'>\n";
out << " <TYPE> BICGSTAB </TYPE> \n";
out << " <PACKAGE> EIGEN </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_BICGSTAB_ILUT << "'>\n";
out << " <TYPE> BICGSTAB_ILUT </TYPE> \n";
out << " <PACKAGE> EIGEN </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_GMRES_ILUT << "'>\n";
out << " <TYPE> GMRES_ILUT </TYPE> \n";
out << " <PACKAGE> EIGEN </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_SIMPLICIAL_LDLT << "'>\n";
out << " <TYPE> LDLT </TYPE> \n";
out << " <PACKAGE> EIGEN </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_SIMPLICIAL_LLT << "'>\n";
out << " <TYPE> LLT </TYPE> \n";
out << " <PACKAGE> EIGEN </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_CG << "'>\n";
out << " <TYPE> CG </TYPE> \n";
out << " <PACKAGE> EIGEN </PACKAGE> \n";
out << " </SOLVER> \n";
out <<" <SOLVER ID='" << EIGEN_SPARSELU_COLAMD << "'>\n";
out << " <TYPE> LU_COLAMD </TYPE> \n";
out << " <PACKAGE> EIGEN </PACKAGE> \n";
out << " </SOLVER> \n";
#ifdef EIGEN_METIS_SUPPORT
out <<" <SOLVER ID='" << EIGEN_SPARSELU_METIS << "'>\n";
out << " <TYPE> LU_METIS </TYPE> \n";
out << " <PACKAGE> EIGEN </PACKAGE> \n";
out << " </SOLVER> \n";
#endif
out << " </AVAILSOLVER> \n";
}
template<typename Solver, typename Scalar>
void call_solver(Solver &solver, const int solver_id, const typename Solver::MatrixType& A, const Matrix<Scalar, Dynamic, 1>& b, const Matrix<Scalar, Dynamic, 1>& refX,std::ofstream& statbuf)
{
double total_time;
double compute_time;
double solve_time;
double rel_error;
Matrix<Scalar, Dynamic, 1> 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 << " <TIME>\n";
statbuf << " <COMPUTE> " << timer.value() << "</COMPUTE>\n";
std::cout<< "COMPUTE TIME : " << timer.value() <<std::endl;
timer.reset();
timer.start();
x = solver.solve(b);
if (solver.info() == NumericalIssue)
{
std::cerr << "Solver failed ... \n";
return;
}
timer.stop();
solve_time = timer.value();
statbuf << " <SOLVE> " << timer.value() << "</SOLVE>\n";
std::cout<< "SOLVE TIME : " << timer.value() <<std::endl;
total_time = solve_time + compute_time;
statbuf << " <TOTAL> " << total_time << "</TOTAL>\n";
std::cout<< "TOTAL TIME : " << total_time <<std::endl;
statbuf << " </TIME>\n";
// Verify the relative error
if(refX.size() != 0)
rel_error = (refX - x).norm()/refX.norm();
else
{
// Compute the relative residual norm
Matrix<Scalar, Dynamic, 1> temp;
temp = A * x;
rel_error = (b-temp).norm()/b.norm();
}
statbuf << " <ERROR> " << rel_error << "</ERROR>\n";
std::cout<< "REL. ERROR : " << rel_error << "\n\n" ;
if ( rel_error <= RelErr )
{
// check the best time if convergence
if(!best_time_val || (best_time_val > total_time))
{
best_time_val = total_time;
best_time_id = solver_id;
}
}
}
template<typename Solver, typename Scalar>
void call_directsolver(Solver& solver, const int solver_id, const typename Solver::MatrixType& A, const Matrix<Scalar, Dynamic, 1>& b, const Matrix<Scalar, Dynamic, 1>& refX, std::string& statFile)
{
std::ofstream statbuf(statFile.c_str(), std::ios::app);
statbuf << " <SOLVER_STAT ID='" << solver_id <<"'>\n";
call_solver(solver, solver_id, A, b, refX,statbuf);
statbuf << " </SOLVER_STAT>\n";
statbuf.close();
}
template<typename Solver, typename Scalar>
void call_itersolver(Solver &solver, const int solver_id, const typename Solver::MatrixType& A, const Matrix<Scalar, Dynamic, 1>& b, const Matrix<Scalar, Dynamic, 1>& refX, std::string& statFile)
{
solver.setTolerance(RelErr);
solver.setMaxIterations(MaximumIters);
std::ofstream statbuf(statFile.c_str(), std::ios::app);
statbuf << " <SOLVER_STAT ID='" << solver_id <<"'>\n";
call_solver(solver, solver_id, A, b, refX,statbuf);
statbuf << " <ITER> "<< solver.iterations() << "</ITER>\n";
statbuf << " </SOLVER_STAT>\n";
std::cout << "ITERATIONS : " << solver.iterations() <<"\n\n\n";
}
template <typename Scalar>
void SelectSolvers(const SparseMatrix<Scalar>&A, unsigned int sym, Matrix<Scalar, Dynamic, 1>& b, const Matrix<Scalar, Dynamic, 1>& refX, std::string& statFile)
{
typedef SparseMatrix<Scalar, ColMajor> SpMat;
// First, deal with Nonsymmetric and symmetric matrices
best_time_id = 0;
best_time_val = 0.0;
//UMFPACK
#ifdef EIGEN_UMFPACK_SUPPORT
{
cout << "Solving with UMFPACK LU ... \n";
UmfPackLU<SpMat> solver;
call_directsolver(solver, EIGEN_UMFPACK, A, b, refX,statFile);
}
#endif
//SuperLU
#ifdef EIGEN_SUPERLU_SUPPORT
{
cout << "\nSolving with SUPERLU ... \n";
SuperLU<SpMat> solver;
call_directsolver(solver, EIGEN_SUPERLU, A, b, refX,statFile);
}
#endif
// PaStix LU
#ifdef EIGEN_PASTIX_SUPPORT
{
cout << "\nSolving with PASTIX LU ... \n";
PastixLU<SpMat> solver;
call_directsolver(solver, EIGEN_PASTIX, A, b, refX,statFile) ;
}
#endif
//PARDISO LU
#ifdef EIGEN_PARDISO_SUPPORT
{
cout << "\nSolving with PARDISO LU ... \n";
PardisoLU<SpMat> solver;
call_directsolver(solver, EIGEN_PARDISO, A, b, refX,statFile);
}
#endif
// Eigen SparseLU METIS
cout << "\n Solving with Sparse LU AND COLAMD ... \n";
SparseLU<SpMat, COLAMDOrdering<int> > solver;
call_directsolver(solver, EIGEN_SPARSELU_COLAMD, A, b, refX, statFile);
// Eigen SparseLU METIS
#ifdef EIGEN_METIS_SUPPORT
{
cout << "\n Solving with Sparse LU AND METIS ... \n";
SparseLU<SpMat, MetisOrdering<int> > solver;
call_directsolver(solver, EIGEN_SPARSELU_METIS, A, b, refX, statFile);
}
#endif
//BiCGSTAB
{
cout << "\nSolving with BiCGSTAB ... \n";
BiCGSTAB<SpMat> solver;
call_itersolver(solver, EIGEN_BICGSTAB, A, b, refX,statFile);
}
//BiCGSTAB+ILUT
{
cout << "\nSolving with BiCGSTAB and ILUT ... \n";
BiCGSTAB<SpMat, IncompleteLUT<Scalar> > solver;
call_itersolver(solver, EIGEN_BICGSTAB_ILUT, A, b, refX,statFile);
}
//GMRES
// {
// cout << "\nSolving with GMRES ... \n";
// GMRES<SpMat> solver;
// call_itersolver(solver, EIGEN_GMRES, A, b, refX,statFile);
// }
//GMRES+ILUT
{
cout << "\nSolving with GMRES and ILUT ... \n";
GMRES<SpMat, IncompleteLUT<Scalar> > solver;
call_itersolver(solver, EIGEN_GMRES_ILUT, A, b, refX,statFile);
}
// Hermitian and not necessarily positive-definites
if (sym != NonSymmetric)
{
// Internal Cholesky
{
cout << "\nSolving with Simplicial LDLT ... \n";
SimplicialLDLT<SpMat, Lower> solver;
call_directsolver(solver, EIGEN_SIMPLICIAL_LDLT, A, b, refX,statFile);
}
// CHOLMOD
#ifdef EIGEN_CHOLMOD_SUPPORT
{
cout << "\nSolving with CHOLMOD LDLT ... \n";
CholmodDecomposition<SpMat, Lower> solver;
solver.setMode(CholmodLDLt);
call_directsolver(solver,EIGEN_CHOLMOD_LDLT, A, b, refX,statFile);
}
#endif
//PASTIX LLT
#ifdef EIGEN_PASTIX_SUPPORT
{
cout << "\nSolving with PASTIX LDLT ... \n";
PastixLDLT<SpMat, Lower> solver;
call_directsolver(solver,EIGEN_PASTIX_LDLT, A, b, refX,statFile);
}
#endif
//PARDISO LLT
#ifdef EIGEN_PARDISO_SUPPORT
{
cout << "\nSolving with PARDISO LDLT ... \n";
PardisoLDLT<SpMat, Lower> solver;
call_directsolver(solver,EIGEN_PARDISO_LDLT, A, b, refX,statFile);
}
#endif
}
// Now, symmetric POSITIVE DEFINITE matrices
if (sym == SPD)
{
//Internal Sparse Cholesky
{
cout << "\nSolving with SIMPLICIAL LLT ... \n";
SimplicialLLT<SpMat, Lower> solver;
call_directsolver(solver,EIGEN_SIMPLICIAL_LLT, A, b, refX,statFile);
}
// CHOLMOD
#ifdef EIGEN_CHOLMOD_SUPPORT
{
// CholMOD SuperNodal LLT
cout << "\nSolving with CHOLMOD LLT (Supernodal)... \n";
CholmodDecomposition<SpMat, Lower> solver;
solver.setMode(CholmodSupernodalLLt);
call_directsolver(solver,EIGEN_CHOLMOD_SUPERNODAL_LLT, A, b, refX,statFile);
// CholMod Simplicial LLT
cout << "\nSolving with CHOLMOD LLT (Simplicial) ... \n";
solver.setMode(CholmodSimplicialLLt);
call_directsolver(solver,EIGEN_CHOLMOD_SIMPLICIAL_LLT, A, b, refX,statFile);
}
#endif
//PASTIX LLT
#ifdef EIGEN_PASTIX_SUPPORT
{
cout << "\nSolving with PASTIX LLT ... \n";
PastixLLT<SpMat, Lower> solver;
call_directsolver(solver,EIGEN_PASTIX_LLT, A, b, refX,statFile);
}
#endif
//PARDISO LLT
#ifdef EIGEN_PARDISO_SUPPORT
{
cout << "\nSolving with PARDISO LLT ... \n";
PardisoLLT<SpMat, Lower> solver;
call_directsolver(solver,EIGEN_PARDISO_LLT, A, b, refX,statFile);
}
#endif
// Internal CG
{
cout << "\nSolving with CG ... \n";
ConjugateGradient<SpMat, Lower> solver;
call_itersolver(solver,EIGEN_CG, A, b, refX,statFile);
}
//CG+IdentityPreconditioner
// {
// cout << "\nSolving with CG and IdentityPreconditioner ... \n";
// ConjugateGradient<SpMat, Lower, IdentityPreconditioner> solver;
// call_itersolver(solver,EIGEN_CG_PRECOND, A, b, refX,statFile);
// }
} // End SPD matrices
}
/* Browse all the matrices available in the specified folder
* and solve the associated linear system.
* The results of each solve are printed in the standard output
* and optionally in the provided html file
*/
template <typename Scalar>
void Browse_Matrices(const string folder, bool statFileExists, std::string& statFile, int maxiters, double tol)
{
MaximumIters = maxiters; // Maximum number of iterations, global variable
RelErr = tol; //Relative residual error as stopping criterion for iterative solvers
MatrixMarketIterator<Scalar> it(folder);
for ( ; it; ++it)
{
//print the infos for this linear system
if(statFileExists)
{
std::ofstream statbuf(statFile.c_str(), std::ios::app);
statbuf << "<LINEARSYSTEM> \n";
statbuf << " <MATRIX> \n";
statbuf << " <NAME> " << it.matname() << " </NAME>\n";
statbuf << " <SIZE> " << it.matrix().rows() << " </SIZE>\n";
statbuf << " <ENTRIES> " << it.matrix().nonZeros() << "</ENTRIES>\n";
if (it.sym()!=NonSymmetric)
{
statbuf << " <SYMMETRY> Symmetric </SYMMETRY>\n" ;
if (it.sym() == SPD)
statbuf << " <POSDEF> YES </POSDEF>\n";
else
statbuf << " <POSDEF> NO </POSDEF>\n";
}
else
{
statbuf << " <SYMMETRY> NonSymmetric </SYMMETRY>\n" ;
statbuf << " <POSDEF> NO </POSDEF>\n";
}
statbuf << " </MATRIX> \n";
statbuf.close();
}
cout<< "\n\n===================================================== \n";
cout<< " ====== SOLVING WITH MATRIX " << it.matname() << " ====\n";
cout<< " =================================================== \n\n";
Matrix<Scalar, Dynamic, 1> refX;
if(it.hasrefX()) refX = it.refX();
// Call all suitable solvers for this linear system
SelectSolvers<Scalar>(it.matrix(), it.sym(), it.rhs(), refX, statFile);
if(statFileExists)
{
std::ofstream statbuf(statFile.c_str(), std::ios::app);
statbuf << " <BEST_SOLVER ID='"<< best_time_id
<< "'></BEST_SOLVER>\n";
statbuf << " </LINEARSYSTEM> \n";
statbuf.close();
}
}
}
bool get_options(int argc, char **args, string option, string* value=0)
{
int idx = 1, found=false;
while (idx<argc && !found){
if (option.compare(args[idx]) == 0){
found = true;
if(value) *value = args[idx+1];
}
idx+=2;
}
return found;
}

View File

@@ -0,0 +1,95 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
//
// 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/.
#ifndef SPBENCHSTYLE_H
#define SPBENCHSTYLE_H
void printBenchStyle(std::ofstream& out)
{
out << "<xsl:stylesheet id='stylesheet' version='1.0' \
xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >\n \
<xsl:template match='xsl:stylesheet' />\n \
<xsl:template match='/'> <!-- Root of the document -->\n \
<html>\n \
<head> \n \
<style type='text/css'> \n \
td { white-space: nowrap;}\n \
</style>\n \
</head>\n \
<body>";
out<<"<table border='1' width='100%' height='100%'>\n \
<TR> <!-- Write the table header -->\n \
<TH>Matrix</TH> <TH>N</TH> <TH> NNZ</TH> <TH> Sym</TH> <TH> SPD</TH> <TH> </TH>\n \
<xsl:for-each select='BENCH/AVAILSOLVER/SOLVER'>\n \
<xsl:sort select='@ID' data-type='number'/>\n \
<TH>\n \
<xsl:value-of select='TYPE' />\n \
<xsl:text></xsl:text>\n \
<xsl:value-of select='PACKAGE' />\n \
<xsl:text></xsl:text>\n \
</TH>\n \
</xsl:for-each>\n \
</TR>";
out<<" <xsl:for-each select='BENCH/LINEARSYSTEM'>\n \
<TR> <!-- print statistics for one linear system-->\n \
<TH rowspan='4'> <xsl:value-of select='MATRIX/NAME' /> </TH>\n \
<TD rowspan='4'> <xsl:value-of select='MATRIX/SIZE' /> </TD>\n \
<TD rowspan='4'> <xsl:value-of select='MATRIX/ENTRIES' /> </TD>\n \
<TD rowspan='4'> <xsl:value-of select='MATRIX/SYMMETRY' /> </TD>\n \
<TD rowspan='4'> <xsl:value-of select='MATRIX/POSDEF' /> </TD>\n \
<TH> Compute Time </TH>\n \
<xsl:for-each select='SOLVER_STAT'>\n \
<xsl:sort select='@ID' data-type='number'/>\n \
<TD> <xsl:value-of select='TIME/COMPUTE' /> </TD>\n \
</xsl:for-each>\n \
</TR>";
out<<" <TR>\n \
<TH> Solve Time </TH>\n \
<xsl:for-each select='SOLVER_STAT'>\n \
<xsl:sort select='@ID' data-type='number'/>\n \
<TD> <xsl:value-of select='TIME/SOLVE' /> </TD>\n \
</xsl:for-each>\n \
</TR>\n \
<TR>\n \
<TH> Total Time </TH>\n \
<xsl:for-each select='SOLVER_STAT'>\n \
<xsl:sort select='@ID' data-type='number'/>\n \
<xsl:choose>\n \
<xsl:when test='@ID=../BEST_SOLVER/@ID'>\n \
<TD style='background-color:red'> <xsl:value-of select='TIME/TOTAL' /> </TD>\n \
</xsl:when>\n \
<xsl:otherwise>\n \
<TD> <xsl:value-of select='TIME/TOTAL' /></TD>\n \
</xsl:otherwise>\n \
</xsl:choose>\n \
</xsl:for-each>\n \
</TR>";
out<<" <TR>\n \
<TH> Error </TH>\n \
<xsl:for-each select='SOLVER_STAT'>\n \
<xsl:sort select='@ID' data-type='number'/>\n \
<TD> <xsl:value-of select='ERROR' />\n \
<xsl:if test='ITER'>\n \
<xsl:text>(</xsl:text>\n \
<xsl:value-of select='ITER' />\n \
<xsl:text>)</xsl:text>\n \
</xsl:if> </TD>\n \
</xsl:for-each>\n \
</TR>\n \
</xsl:for-each>\n \
</table>\n \
</body>\n \
</html>\n \
</xsl:template>\n \
</xsl:stylesheet>\n\n";
}
#endif

View File

@@ -0,0 +1,93 @@
// Small bench routine for Eigen available in Eigen
// (C) Desire NUENTSA WAKAM, INRIA
#include <iostream>
#include <fstream>
#include <iomanip>
#include <unsupported/Eigen/SparseExtra>
#include <Eigen/SparseLU>
#include <bench/BenchTimer.h>
#ifdef EIGEN_METIS_SUPPORT
#include <Eigen/MetisSupport>
#endif
using namespace std;
using namespace Eigen;
int main(int argc, char **args)
{
// typedef complex<double> scalar;
typedef double scalar;
SparseMatrix<scalar, ColMajor> A;
typedef SparseMatrix<scalar, ColMajor>::Index Index;
typedef Matrix<scalar, Dynamic, Dynamic> DenseMatrix;
typedef Matrix<scalar, Dynamic, 1> DenseRhs;
Matrix<scalar, Dynamic, 1> b, x, tmp;
// SparseLU<SparseMatrix<scalar, ColMajor>, AMDOrdering<int> > solver;
// #ifdef EIGEN_METIS_SUPPORT
// SparseLU<SparseMatrix<scalar, ColMajor>, MetisOrdering<int> > solver;
// std::cout<< "ORDERING : METIS\n";
// #else
SparseLU<SparseMatrix<scalar, ColMajor>, COLAMDOrdering<int> > solver;
std::cout<< "ORDERING : COLAMD\n";
// #endif
ifstream matrix_file;
string line;
int n;
BenchTimer timer;
// Set parameters
/* Fill the matrix with sparse matrix stored in Matrix-Market coordinate column-oriented format */
if (argc < 2) assert(false && "please, give the matrix market file ");
loadMarket(A, args[1]);
cout << "End charging matrix " << endl;
bool iscomplex=false, isvector=false;
int sym;
getMarketHeader(args[1], sym, iscomplex, isvector);
// if (iscomplex) { cout<< " Not for complex matrices \n"; return -1; }
if (isvector) { cout << "The provided file is not a matrix file\n"; return -1;}
if (sym != 0) { // symmetric matrices, only the lower part is stored
SparseMatrix<scalar, ColMajor> temp;
temp = A;
A = temp.selfadjointView<Lower>();
}
n = A.cols();
/* Fill the right hand side */
if (argc > 2)
loadMarketVector(b, args[2]);
else
{
b.resize(n);
tmp.resize(n);
// tmp.setRandom();
for (int i = 0; i < n; i++) tmp(i) = i;
b = A * tmp ;
}
/* Compute the factorization */
// solver.isSymmetric(true);
timer.start();
// solver.compute(A);
solver.analyzePattern(A);
timer.stop();
cout << "Time to analyze " << timer.value() << std::endl;
timer.reset();
timer.start();
solver.factorize(A);
timer.stop();
cout << "Factorize Time " << timer.value() << std::endl;
timer.reset();
timer.start();
x = solver.solve(b);
timer.stop();
cout << "solve time " << timer.value() << std::endl;
/* Check the accuracy */
Matrix<scalar, Dynamic, 1> tmp2 = b - A*x;
scalar tempNorm = tmp2.norm()/b.norm();
cout << "Relative norm of the computed solution : " << tempNorm <<"\n";
cout << "Number of nonzeros in the factor : " << solver.nnzL() + solver.nnzU() << std::endl;
return 0;
}