Commit 061b5040 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Refactoring the shared vector.

parent 4f37054a
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -25,9 +25,8 @@
#include <core/tnlString.h>
#include <core/mfilename.h>
#include <core/mfuncs.h>
#include <core/tnlSharedVector.h>
#include <core/vectors/tnlSharedVector.h>
#include <solvers/ode/tnlMersonSolver.h>
#include <legacy/mesh/tnlGridOld.h>


#ifdef HAVE_CUDA
+16 −35
Original line number Diff line number Diff line
@@ -86,49 +86,30 @@ class tnlSharedVector : public tnlSharedArray< Real, Device, Index >
   template< typename Vector >
   Real scalarProduct( const Vector& v );

   //! Computes SAXPY operation (Y = Scalar Alpha X Pus Y ).
   //! Computes Y = alpha * X + Y.
   template< typename Vector >
   void saxpy( const Real& alpha,
   void alphaXPlusY( const Real& alpha,
                     const Vector& x );

   //! Computes SAXMY operation (Y = Scalar Alpha X Minus Y ).
   /*!**
    * It is not a standart BLAS function but is useful for GMRES solver.
    */
   //! Computes Y = alpha * X + beta * Y.
   template< typename Vector >
   void saxmy( const Real& alpha,
               const Vector& x );

   //! Computes Y = Scalar Alpha X Plus Scalar Beta Y
   /*!**
    * It is not standard BLAS function as well.
    */
   template< typename Vector >
   void saxpsby( const Real& alpha,
   void alphaXPlusBetaY( const Real& alpha,
                         const Vector& x,
                         const Real& beta );

   //! Computes Y = Scalar Alpha X Plus Scalar Beta Z
   /*!**
    * It is not standard BLAS function as well.
    */
   //! Computes Y = alpha * X + beta * Z
   template< typename Vector >
   void saxpsbz( const Real& alpha,
   void alphaXPlusBetaZ( const Real& alpha,
                         const Vector& x,
                         const Real& beta,
                         const Vector& z );

   //! Computes Y = Scalar Alpha X Plus Scalar Beta Z Plus Y
   /*!**
    * It is not standard BLAS function as well.
    */
   template< typename Vector >
   void saxpsbzpy( const Real& alpha,
   void alphaXPlusBetaZPlusY( const Real& alpha,
                              const Vector& x,
                              const Real& beta,
                              const Vector& z );


};

#include <implementation/core/vectors/tnlSharedVector_impl.h>
+16 −30
Original line number Diff line number Diff line
@@ -234,12 +234,11 @@ Real tnlSharedVector< Real, Device, Index > :: scalarProduct( const Vector& v )
   return tnlVectorOperations< Device > :: getScalarProduct( *this, v );
}


template< typename Real,
          typename Device,
          typename Index >
template< typename Vector >
void tnlSharedVector< Real, Device, Index > :: saxpy( const Real& alpha,
void tnlSharedVector< Real, Device, Index > :: alphaXPlusY( const Real& alpha,
                                                            const Vector& x )
{
   tnlVectorOperations< Device > :: alphaXPlusY( *this, x, alpha );
@@ -249,48 +248,35 @@ template< typename Real,
          typename Device,
          typename Index >
   template< typename Vector >
void tnlSharedVector< Real, Device, Index > :: saxmy( const Real& alpha,
                                                      const Vector& x )
{
   tnlVectorOperations< Device > :: vectorSaxmy( *this, x, alpha );
}


template< typename Real,
          typename Device,
          typename Index >
   template< typename Vector >
void tnlSharedVector< Real, Device, Index > :: saxpsby( const Real& alpha,
void tnlSharedVector< Real, Device, Index > :: alphaXPlusBetaY( const Real& alpha,
                                                                const Vector& x,
                                                                const Real& beta )
{
   tnlVectorOperations< Device > :: vectorSaxpsby( *this, x, alpha, beta );
   tnlVectorOperations< Device > :: alphaXPlusBetaY( *this, x, alpha, beta );
}

template< typename Real,
          typename Device,
          typename Index >
   template< typename Vector >
void tnlSharedVector< Real, Device, Index > :: saxpsbz( const Real& alpha,
void tnlSharedVector< Real, Device, Index > :: alphaXPlusBetaZ( const Real& alpha,
                                                                const Vector& x,
                                                                const Real& beta,
                                                                const Vector& z )
{
   tnlVectorOperations< Device > :: vectorSaxpsbz( *this, x, alpha, z, beta );
   tnlVectorOperations< Device > :: alphaXPlusBetaZ( *this, x, alpha, z, beta );
}

template< typename Real,
          typename Device,
          typename Index >
   template< typename Vector >
void tnlSharedVector< Real, Device, Index > :: saxpsbzpy( const Real& alpha,
void tnlSharedVector< Real, Device, Index > :: alphaXPlusBetaZPlusY( const Real& alpha,
                                                                     const Vector& x,
                                                                     const Real& beta,
                                                                     const Vector& z )
{
   tnlVectorOperations< Device > :: vectorSaxpsbz( *this, x, alpha, z, beta );
   tnlVectorOperations< Device > :: alphaXPlusBetaZPlusY( *this, x, alpha, z, beta );
}



#endif /* TNLSHAREDVECTOR_H_IMPLEMENTATION */
+0 −1
Original line number Diff line number Diff line
@@ -232,7 +232,6 @@ Real tnlVector< Real, Device, Index > :: scalarProduct( const Vector& v )
   return tnlVectorOperations< Device > :: getScalarProduct( *this, v );
}


template< typename Real,
          typename Device,
          typename Index >
+5 −5
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ bool tnlGMRESSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
    */
   if( preconditioner )
   {
      this->preconditioner->Solve( b, M_tmp );
      this->preconditioner->solve( b, _M_tmp );
      for( i = 0; i < _size; i ++ )
         normb += M_tmp[ i ] * M_tmp[ i ];

@@ -112,7 +112,7 @@ bool tnlGMRESSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
      for( i = 0; i < size; i ++ )
         M_tmp[ i ] = b[ i ] - M_tmp[ i ];

      this->preconditioner->Solve( M_tmp, r );
      this->preconditioner->solve( _M_tmp, _r );
      for( i = 0; i < size; i ++ )
         beta += r[ i ] * r[ i ];
   }
@@ -149,7 +149,7 @@ bool tnlGMRESSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
       * v_0 = r / | r | =  1.0 / beta * r
       */
      vi. bind( _v. getData(), size );
      vi. saxpy( ( RealType ) 1.0 / beta, _r );
      vi. alphaXPlusY( ( RealType ) 1.0 / beta, _r );

      _s. setValue( ( RealType ) 0.0 );
      _s[ 0 ] = beta;
@@ -166,7 +166,7 @@ bool tnlGMRESSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
         if( preconditioner )
         {
            matrix -> vectorProduct( vi, _M_tmp );
            this->preconditioner->Solve( M_tmp, w );
            this->preconditioner->solve( _M_tmp, _w );
         }
         else
             matrix -> vectorProduct( vi, _w );
@@ -195,7 +195,7 @@ bool tnlGMRESSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
          * v_{i+1} = w / |w|
          */
         vi. bind( &( _v. getData()[ ( i + 1 ) * size ] ), size );
         vi. saxpy( ( RealType ) 1.0 / normw, _w );
         vi. alphaXPlusY( ( RealType ) 1.0 / normw, _w );


         //dbgCout( "Applying rotations" );
Loading