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

Programing GPU.

parent 7c0da9d5
Loading
Loading
Loading
Loading
+15 −15
Original line number Diff line number Diff line
@@ -89,7 +89,6 @@ bool tnlArray< Element, Device, Index > :: setSize( const Index size )
      this -> size = 0;
      return false;
   }
   //( this -> data ) ++;
   return true;
};

@@ -122,6 +121,7 @@ template< typename Element,
void tnlArray< Element, Device, Index > :: reset()
{
   this->size = 0;
   tnlArrayOperations< Device >::freeMemory( this->data );
   this->data = 0;
};

+1 −5
Original line number Diff line number Diff line
@@ -100,9 +100,6 @@ void tnlString :: setString( const char* c, int prefix_cut_off, int sufix_cut_of
   }
   int c_len = ( int ) strlen( c );
   int _length = Max( 0, c_len - prefix_cut_off - sufix_cut_off );
   //assert( _length );
   //dbgExpr( _length );
   //dbgExpr( string );

   if( length < _length || length == 0 )
   {
@@ -110,8 +107,7 @@ void tnlString :: setString( const char* c, int prefix_cut_off, int sufix_cut_of
      length = STRING_PAGE * ( _length / STRING_PAGE + 1 );
      string = new char[ length ];
   }
   assert( string );
   //dbgExpr( length );
   tnlAssert( string, );
   memcpy( string, c + Min( c_len, prefix_cut_off ), sizeof( char ) * ( _length ) );
   string[ _length ] = 0;
}
+0 −30
Original line number Diff line number Diff line
@@ -119,36 +119,6 @@ void tnlCSRMatrix< Real, Device, Index >::reset()
   this->rowPointers.reset();
}

template< typename Real,
          typename Device,
          typename Index >
   template< typename Real2,
             typename Device2,
             typename Index2 >
bool tnlCSRMatrix< Real, Device, Index >::operator == ( const tnlCSRMatrix< Real2, Device2, Index2 >& matrix ) const
{
   tnlAssert( this->getRows() == matrix.getRows() &&
              this->getColumns() == matrix.getColumns(),
              cerr << "this->getRows() = " << this->getRows()
                   << " matrix.getRows() = " << matrix.getRows()
                   << " this->getColumns() = " << this->getColumns()
                   << " matrix.getColumns() = " << matrix.getColumns()
                   << " this->getName() = " << this->getName()
                   << " matrix.getName() = " << matrix.getName() );
   // TODO: implement this
}

template< typename Real,
          typename Device,
          typename Index >
   template< typename Real2,
             typename Device2,
             typename Index2 >
bool tnlCSRMatrix< Real, Device, Index >::operator != ( const tnlCSRMatrix< Real2, Device2, Index2 >& matrix ) const
{
   return ! ( ( *this ) == matrix );
}

template< typename Real,
          typename Device,
          typename Index >
+20 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ bool tnlMatrixReader< Matrix >::readMtxFile( std::istream& file,
      return false;
   }

   if( ! computeRowLengthsFromMtxFile( file, rowLengths, symmetricMatrix, verbose ) )
   if( ! computeRowLengthsFromMtxFile( file, rowLengths, columns, rows, symmetricMatrix, verbose ) )
      return false;

   if( ! matrix.setRowLengths( rowLengths ) )
@@ -253,6 +253,8 @@ bool tnlMatrixReader< Matrix >::readMtxHeader( std::istream& file,
template< typename Matrix >
bool tnlMatrixReader< Matrix >::computeRowLengthsFromMtxFile( std::istream& file,
                                                              tnlVector< int, tnlHost, int >& rowLengths,
                                                              const int columns,
                                                              const int rows,
                                                              bool symmetricMatrix,
                                                              bool verbose )
{
@@ -276,11 +278,28 @@ bool tnlMatrixReader< Matrix >::computeRowLengthsFromMtxFile( std::istream& file
      if( ! parseMtxLineWithElement( line, row, column, value ) )
         return false;
      numberOfElements++;
      if( column > columns || row > rows )
      {
         cerr << "There is an element at position " << row << ", " << column << " out of the matrix dimensions " << rows << " x " << columns << "." << endl;
         return false;
      }
      if( verbose )
         cout << " Counting the matrix elements ... " << numberOfElements / 1000 << " thousands      \r" << flush;
      rowLengths[ row - 1 ]++;
      if( rowLengths[ row - 1 ] >= columns )
      {
         cerr << "There are more elements than the matrix columns at the row " << row << "." << endl;
         return false;
      }
      if( symmetricMatrix && row != column )
      {
         rowLengths[ column - 1 ]++;
         if( rowLengths[ column - 1 ] >= columns )
         {
            cerr << "There are more elements than the matrix columns at the row " << column << " ." << endl;
            return false;
         }
      }
   }
   file.clear();
   long int fileSize = file.tellg();
+51 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#define TNLMATRIX_IMPL_H_

#include <matrices/tnlMatrix.h>
#include <core/tnlAssert.h>

template< typename Real,
          typename Device,
@@ -94,6 +95,31 @@ void tnlMatrix< Real, Device, Index >::reset()
   this->columns = 0;
}

template< typename Real,
          typename Device,
          typename Index >
   template< typename Matrix >
bool tnlMatrix< Real, Device, Index >::copyFrom( const Matrix& matrix,
                                                 const RowLengthsVector& rowLengths )
{
   /*tnlStaticAssert( DeviceType::DeviceType == tnlHostDevice, );
   tnlStaticAssert( DeviceType::DeviceType == Matrix:DeviceType::DeviceType, );*/

   this->setLike( matrix );
   if( ! this->setRowLengths( rowLengths ) )
      return false;
   tnlVector< RealType, tnlHost, IndexType > values;
   tnlVector< IndexType, tnlHost, IndexType > columns;
   if( ! values.setSize( this->getColumns() ) ||
       ! columns.setSize( this->getColumns() ) )
      return false;
   for( IndexType row = 0; row < this->getRows(); row++ )
   {
      matrix.getRow( row, columns.getData(), values.getData() );
      this->setRow( row, columns.getData(), values.getData(), rowLengths.getElement( row ) );
   }
}

template< typename Real,
          typename Device,
          typename Index >
@@ -122,6 +148,31 @@ tnlMatrix< Real, Device, Index >& tnlMatrix< Real, Device, Index >::operator = (
   }
}

template< typename Real,
          typename Device,
          typename Index >
   template< typename Matrix >
bool tnlMatrix< Real, Device, Index >::operator == ( const Matrix& matrix ) const
{
   if( this->getRows() != matrix.getRows() ||
       this->getColumns() != matrix.getColumns() )
      return false;
   for( IndexType row = 0; row < this->getRows(); row++ )
      for( IndexType column = 0; column < this->getColumns(); column++ )
         if( this->getElement( row, column ) != matrix.getElement( row, column ) )
            return false;
   return true;
}

template< typename Real,
          typename Device,
          typename Index >
   template< typename Matrix >
bool tnlMatrix< Real, Device, Index >::operator != ( const Matrix& matrix ) const
{
   return ! operator == ( matrix );
}

template< typename Real,
          typename Device,
          typename Index >
Loading