Commit 33885ddd authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Merge branch 'mhfem' into develop

* mhfem:
  Added umfpack report functions in case of errors
  Added tnlUmfpackWrapper{,_impl}.h to CMakeLists.txt
  Added tnlUmfpackWrapper class
  Fixed passing of the verbose flag to the solver monitor
  Added timer for preconditioner update
  Fixed bug in GMRES solver
  Fixed constant in tnlCuda::getMaxGridSize

 Conflicts:
	src/solvers/linear/krylov/tnlGMRESSolver_impl.h
	src/solvers/pde/tnlSemiImplicitTimeStepper.h
	src/solvers/pde/tnlSemiImplicitTimeStepper_impl.h
	src/solvers/tnlBuildConfigTags.h
	src/solvers/tnlSolverStarter_impl.h
parents a306cbb8 72cedd39
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ __host__ __device__
inline int tnlCuda::getMaxGridSize()
{
   // TODO: make it preprocessor macro constant defined in tnlConfig
   return 65536;
   return 65535;
};

#ifdef HAVE_CUDA
+9 −0
Original line number Diff line number Diff line
@@ -21,6 +21,11 @@
#include <matrices/tnlSparseMatrix.h>
#include <core/vectors/tnlVector.h>

#ifdef HAVE_UMFPACK
    template< typename Matrix, typename Preconditioner >
    class tnlUmfpackWrapper;
#endif

template< typename Real >
class tnlCusparseCSRMatrix;

@@ -209,6 +214,10 @@ class tnlCSRMatrix : public tnlSparseMatrix< Real, Device, Index >
   typedef tnlCSRMatrixDeviceDependentCode< DeviceType > DeviceDependentCode;
   friend class tnlCSRMatrixDeviceDependentCode< DeviceType >;
   friend class tnlCusparseCSRMatrix< RealType >;
#ifdef HAVE_UMFPACK
    template< typename Matrix, typename Preconditioner >
    friend class tnlUmfpackWrapper;
#endif

};

+3 −1
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@ ADD_SUBDIRECTORY( stationary )

SET( headers tnlLinearResidueGetter.h
             tnlLinearResidueGetter_impl.h 
             tnlUmfpackWrapper.h
             tnlUmfpackWrapper_impl.h
   )

SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/solvers/linear )
+2 −6
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ bool tnlGMRESSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
   this->setResidue( beta / normb );

   tnlSharedVector< RealType, DeviceType, IndexType > vi, vk;
   while( this->nextIteration() )
   while( this->checkNextIteration() )
   {
      const IndexType m = restarting;
      for( IndexType i = 0; i < m + 1; i ++ )
@@ -250,11 +250,7 @@ bool tnlGMRESSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
                             sn[ i ] );

         this->setResidue( fabs( s[ i + 1 ] ) / normb );
         // The nextIteration() method should not be called here, because it increments
         // the iteration counter. The condition below is slightly different than in
         // nextIteration(), because it first increments and then compares.
         if( this->getIterations() >= this->getMinIterations() && this->getResidue() < this->getConvergenceResidue() )
         {
         if( ! this->checkNextIteration() ) {
            update( i, m, _H, _s, _v, x );
            this->refreshSolverMonitor( true );
            return this->checkConvergence();
+122 −0
Original line number Diff line number Diff line
#pragma once

#ifdef HAVE_UMFPACK

#include <umfpack.h>

#include <core/tnlObject.h>
#include <config/tnlConfigDescription.h>
#include <matrices/tnlCSRMatrix.h>
#include <solvers/preconditioners/tnlDummyPreconditioner.h>
#include <solvers/tnlIterativeSolver.h>
#include <solvers/linear/tnlLinearResidueGetter.h>


template< typename Matrix >
struct is_csr_matrix
{
    static const bool value = false;
};

template< typename Real, typename Device, typename Index >
struct is_csr_matrix< tnlCSRMatrix< Real, Device, Index > >
{
    static const bool value = true;
};


template< typename Matrix,
          typename Preconditioner = tnlDummyPreconditioner< typename Matrix :: RealType,
                                                            typename Matrix :: DeviceType,
                                                            typename Matrix :: IndexType> >
class tnlUmfpackWrapper
    : public tnlObject,
      // just to ensure the same interface as other linear solvers
      public tnlIterativeSolver< typename Matrix::RealType,
                                 typename Matrix::IndexType >
{
public:
    typedef typename Matrix :: RealType RealType;
    typedef typename Matrix :: IndexType IndexType;
    typedef typename Matrix :: DeviceType DeviceType;
    typedef Matrix MatrixType;
    typedef Preconditioner PreconditionerType;

    tnlUmfpackWrapper()
    {
        if( ! is_csr_matrix< Matrix >::value )
            cerr << "The tnlUmfpackWrapper solver is available only for CSR matrices." << endl;
        if( std::is_same< typename Matrix::DeviceType, tnlCuda >::value )
            cerr << "The tnlUmfpackWrapper solver is not available on CUDA." << endl;
        if( ! std::is_same< RealType, double >::value )
            cerr << "The tnlUmfpackWrapper solver is available only for double precision." << endl;
        if( ! std::is_same< IndexType, int >::value )
            cerr << "The tnlUmfpackWrapper solver is available only for 'int' index type." << endl;
    }

    static void configSetup( tnlConfigDescription& config,
                             const tnlString& prefix = "" )
    {};

    bool setup( const tnlParameterContainer& parameters,
               const tnlString& prefix = "" )
    {
        return false;
    };

    void setMatrix( const MatrixType& matrix )
    {};

    void setPreconditioner( const Preconditioner& preconditioner )
    {};

    template< typename Vector,
              typename ResidueGetter = tnlLinearResidueGetter< MatrixType, Vector > >
    bool solve( const Vector& b, Vector& x )
    {
        return false;
    };

};


template< typename Preconditioner >
class tnlUmfpackWrapper< tnlCSRMatrix< double, tnlHost, int >, Preconditioner >
    : public tnlObject,
      // just to ensure the same interface as other linear solvers
      public tnlIterativeSolver< double, int >
{
public:
    typedef double RealType;
    typedef int IndexType;
    typedef tnlHost DeviceType;
    typedef tnlCSRMatrix< double, tnlHost, int > MatrixType;
    typedef Preconditioner PreconditionerType;

    tnlUmfpackWrapper();

    tnlString getType() const;

    static void configSetup( tnlConfigDescription& config,
                             const tnlString& prefix = "" );

    bool setup( const tnlParameterContainer& parameters,
               const tnlString& prefix = "" );

    void setMatrix( const MatrixType& matrix );

    void setPreconditioner( const Preconditioner& preconditioner );

    template< typename Vector,
              typename ResidueGetter = tnlLinearResidueGetter< MatrixType, Vector > >
    bool solve( const Vector& b, Vector& x );

protected:
   const MatrixType* matrix;

   const PreconditionerType* preconditioner;
};

#include "tnlUmfpackWrapper_impl.h"

#endif
Loading