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

Refactoring SpMV benchmarks.

parent 3dcabfe4
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
2011-05-15  Tomas Oberhuber  <tomas.oberhuber@fjfi.cvut.cz>

	* tests/cusp-test.h: Removed.
	* tests/tnlSpmvBenchmark.h: New file.
	* tests/tnlSpmvBenchmarkCSRMatrix.h: New file.
	* tests/tnlSpmvBenchmarkHybridMatrix.h: New file.
	* tests/tnlSpmvBenchmarkRgCSRMatrix.h: New file.
	* src/core/tnlLongVectorCUDA.h: Adding operator =, denying copy constructors
	* src/core/tnlLongVectorHost.h: Adding operator =, denying copy constructors 
	* src/matrix/tnlCSRMatrix.h: Adding reorderRows
	* src/matrix/tnlMatrix.h: Adding sortRowsDecreasignly
	* src/matrix/tnlRgCSRMatrix.h:  
	* tests/Makefile.am:  
	* tests/matrix-formats-test.h: 
	* tests/run-sparse-matrix-benchmark: Adding debug
	* tests/sparse-matrix-benchmark.cpp (main): 
	* tests/sparse-matrix-benchmark.h: refactoring
	* tests/unit-tests/Makefile.am:  
	* tests/unit-tests/matrix/tnlRgCSRMatrixTester.h (triDiagonalMatrixTest): 
	(diagonalMatrixTest): 

2011-03-09  Tomas Oberhuber  <tomas.oberhuber@fjfi.cvut.cz>

	* configure.ac: 
+10 −2
Original line number Diff line number Diff line
@@ -49,6 +49,14 @@ class tnlLongVector< Real, tnlCuda, Index > : public tnlLongVectorBase< Real >
   //! We do not allow constructor without parameters.
   tnlLongVector(){};

   /****
    * We do not allow copy constructors as well to avoid having two
    * vectors with the same name.
    */
   tnlLongVector( const tnlLongVector< Real, tnlHost, Index >& v ){};

   tnlLongVector( const tnlLongVector< Real, tnlCuda, Index >& v ){};

   public:

   //! Basic constructor
@@ -349,7 +357,7 @@ bool tnlLongVector< Real, tnlCuda, Index > :: setSize( Index _size )
   }
   return true;
#else
   cerr << "I am sorry but CUDA support is missing on this system " << __FILE__ << " line " << __LINE__ << "." << endl;
   //cerr << "I am sorry but CUDA support is missing on this system " << __FILE__ << " line " << __LINE__ << "." << endl;
   return false;
#endif
};
@@ -744,7 +752,7 @@ tnlLongVector< Real, tnlCuda, Index > :: ~tnlLongVector()
      }
   }
#else
   cerr << "I am sorry but CUDA support is missing on this system " << __FILE__ << " line " << __LINE__ << "." << endl;
   //cerr << "I am sorry but CUDA support is missing on this system " << __FILE__ << " line " << __LINE__ << "." << endl;
#endif
};

+14 −2
Original line number Diff line number Diff line
@@ -29,6 +29,14 @@ template< typename Real, typename Index > class tnlLongVector< Real, tnlHost, In
   //! We do not allow constructor without parameters.
   tnlLongVector(){};

   /****
    * We do not allow copy constructors as well to avoid having two
    * vectors with the same name.
    */
   tnlLongVector( const tnlLongVector< Real, tnlHost, Index >& v ){};

   tnlLongVector( const tnlLongVector< Real, tnlCuda, Index >& v ){};

   public:

   //! Basic constructor with given size
@@ -259,8 +267,12 @@ void tnlLongVector< Real, tnlHost, Index > :: swap( tnlLongVector< Real, tnlHost
                   << "The first one is " << this -> getName() << " with size " << this -> getSize()
                   << " while the second one is " << v. getName() << " with size " << v. getSize() << "." );

   std :: swap( this -> data, v. data );
   std :: swap( this -> shared_data, v. shared_data );
   Real* auxData = this -> data;
   this -> data = v. data;
   v. data = auxData;
   bool auxShared = this -> shared_data;
   this -> shared_data = v. shared_data;
   v. shared_data = auxShared;
};

template< typename Real, typename Index >
+66 −5
Original line number Diff line number Diff line
@@ -61,6 +61,8 @@ class tnlCSRMatrix : public tnlMatrix< Real, Device, Index >
   //! Sets the number of row and columns.
   bool setSize( Index new_size );

   bool setLike( const tnlCSRMatrix< Real, Device, Index >& matrix );

   //! Allocate memory for the nonzero elements.
   bool setNonzeroElements( Index elements );

@@ -111,6 +113,9 @@ class tnlCSRMatrix : public tnlMatrix< Real, Device, Index >

   Real getRowL1Norm( Index row ) const;

   bool reorderRows( const tnlLongVector< Index, Device, Index >& rowPermutation,
                     const tnlCSRMatrix< Real, Device, Index >& csrMatrix );

   void multiplyRow( Index row, const Real& value );

   bool read( istream& str, int verbose = 0 );
@@ -125,6 +130,8 @@ class tnlCSRMatrix : public tnlMatrix< Real, Device, Index >

   bool load( const tnlString& fileName );

   tnlCSRMatrix< Real, Device, Index >& operator = ( const tnlCSRMatrix< Real, Device, Index >& csrMatrix );

   //! Prints out the matrix structure
   void printOut( ostream& str,
		            const Index lines = 0 ) const;
@@ -190,6 +197,7 @@ class tnlCSRMatrix : public tnlMatrix< Real, Device, Index >
   Index last_nonzero_element;

   friend class tnlRgCSRMatrix< Real, tnlHost, Index >;
   friend class tnlRgCSRMatrix< Real, tnlCuda, Index >;
   friend class tnlAdaptiveRgCSRMatrix< Real, tnlHost, Index >;
   friend class tnlFastCSRMatrix< Real, tnlHost, Index >;
   friend class tnlEllpackMatrix< Real, tnlHost, Index >;
@@ -198,9 +206,9 @@ class tnlCSRMatrix : public tnlMatrix< Real, Device, Index >
template< typename Real, tnlDevice Device, typename Index >
tnlCSRMatrix< Real, Device, Index > :: tnlCSRMatrix( const tnlString& name )
   : tnlMatrix< Real, Device, Index >( name ),
     nonzero_elements( "tnlCSRMatrix< Real, Device, Index > :: nonzero-elements" ),
     columns( "tnlCSRMatrix< Real, Device, Index > :: columns" ),
     row_offsets( "tnlCSRMatrix< Real, Device, Index > :: row_offsets" ),
     nonzero_elements( name + " : nonzero-elements" ),
     columns( name + " : columns" ),
     row_offsets( name + " : row_offsets" ),
     last_nonzero_element( 0 )
{
};
@@ -232,6 +240,19 @@ bool tnlCSRMatrix< Real, Device, Index > :: setSize( Index new_size )
   return true;
};

template< typename Real, tnlDevice Device, typename Index >
bool tnlCSRMatrix< Real, Device, Index > :: setLike( const tnlCSRMatrix< Real, Device, Index >& matrix )
{
   this -> size = matrix. getSize();
   if( ! nonzero_elements. setLike( matrix. nonzero_elements ) ||
       ! columns. setLike( matrix. columns ) ||
       ! row_offsets. setLike( matrix. row_offsets ) )
      return false;
   row_offsets. setValue( 0 );
   last_nonzero_element = 0;
   return true;
}

template< typename Real, tnlDevice Device, typename Index >
bool tnlCSRMatrix< Real, Device, Index > :: setNonzeroElements( Index elements )
{
@@ -589,6 +610,29 @@ void tnlCSRMatrix< Real, Device, Index > :: multiplyRow( Index row, const Real&
      els[ i ] *= value;
};

template< typename Real, tnlDevice Device, typename Index >
bool tnlCSRMatrix< Real, Device, Index > :: reorderRows( const tnlLongVector< Index, Device, Index >& rowPermutation,
                                                         const tnlCSRMatrix< Real, Device, Index >& inputCsrMatrix )
{
   last_nonzero_element = 0;
   if( ! this -> setLike( inputCsrMatrix ) )
   {
      cerr << "I am not able to allocate new memory for matrix reordering." << endl;
      return false;
   }
   for( Index i = 0; i < this -> getSize(); i ++ )
   {
      row_offsets[ i ] = last_nonzero_element;
      Index row = rowPermutation[ i ];
      Index j = inputCsrMatrix. row_offsets[ row ];
      while( j < inputCsrMatrix. row_offsets[ row + 1 ] )
      {
         nonzero_elements[ last_nonzero_element ] = inputCsrMatrix. nonzero_elements[ j ];
         columns[ last_nonzero_element ++ ] = inputCsrMatrix. columns[ j ++ ];
      }
   }
   return true;
}

template< typename Real, tnlDevice Device, typename Index >
bool tnlCSRMatrix< Real, Device, Index > :: save( tnlFile& file ) const
@@ -626,6 +670,23 @@ bool tnlCSRMatrix< Real, Device, Index > :: load( const tnlString& fileName )
   return tnlObject :: load( fileName );
}

template< typename Real, tnlDevice Device, typename Index >
tnlCSRMatrix< Real, Device, Index >& tnlCSRMatrix< Real, Device, Index > :: operator = ( const tnlCSRMatrix< Real, Device, Index >& csrMatrix )
{
   if( ! nonzero_elements. setSize( csrMatrix. nonzero_elements. getSize() ) ||
       ! columns. setSize( csrMatrix. columns. getSize() ) ||
       ! row_offsets. setSize( csrMatrix. row_offsets. getSize() ) )
   {
      cerr << "I am unable to allocate memory for new matrix!" << endl;
      abort();
   }
   nonzero_elements = csrMatrix. nonzero_elements;
   columns = csrMatrix. columns;
   row_offsets = csrMatrix. row_offsets;
   tnlMatrix< Real, Device, Index > :: operator = ( csrMatrix );
   return * this;
}

template< typename Real, tnlDevice Device, typename Index >
void tnlCSRMatrix< Real, Device, Index > :: printOut( ostream& str,
		                                        const Index lines ) const
+29 −14
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ class tnlMatrix : public tnlObject

   virtual Index getArtificialZeroElements() const;

   bool setRowsReordering( const tnlLongVector< Index, Device, Index >& reorderingPermutation );
   //bool setRowsReordering( const tnlLongVector< Index, Device, Index >& reorderingPermutation );

   virtual Real getElement( Index row, Index column ) const = 0;

@@ -109,11 +109,13 @@ class tnlMatrix : public tnlObject

   bool load( const tnlString& fileName );

   tnlMatrix< Real, Device, Index >& operator = ( const tnlMatrix< Real, Device, Index >& matrix );

   /*!
    * Computes permutation of the rows such that the rows would be
    * ordered decreasingly by the number of the non-zero elements.
    */
   bool reorderDecreasingly( const tnlLongVector< Index, Device, Index >& permutation );
   bool sortRowsDecreasingly( tnlLongVector< Index, Device, Index >& permutation );

   virtual bool read( istream& str,
		                int verbose = 0 );
@@ -134,7 +136,7 @@ class tnlMatrix : public tnlObject

   Index size;

   tnlLongVector< Index, Device, Index > rowsReorderingPermutation;
   //tnlLongVector< Index, Device, Index > rowsReorderingPermutation;
};

template< typename Real, tnlDevice Device, typename Index >
@@ -142,8 +144,8 @@ ostream& operator << ( ostream& o_str, const tnlMatrix< Real, Device, Index >& A

template< typename Real, tnlDevice Device, typename Index >
tnlMatrix< Real, Device, Index > :: tnlMatrix( const tnlString& name )
: tnlObject( name ),
  rowsReorderingPermutation( "tnlMatrix::rowsReorderingPermutation" )
: tnlObject( name )
  //rowsReorderingPermutation( "tnlMatrix::rowsReorderingPermutation" )
{
};

@@ -162,14 +164,14 @@ Index tnlMatrix< Real, Device, Index > :: getNonzeroElementsInRow( const Index&
    */
}

template< typename Real, tnlDevice Device, typename Index >
/*template< typename Real, tnlDevice Device, typename Index >
bool tnlMatrix< Real, Device, Index > :: setRowsReordering( const tnlLongVector< Index, Device, Index >& reorderingPermutation )
{
   if( ! rowsReorderingPermutation. setSize( reorderingPermutation. getSize() ) )
      return false;
   rowsReorderingPermutation = reorderingPermutation;
   return true;
};
};*/

template< typename Real, tnlDevice Device, typename Index >
bool tnlMatrix< Real, Device, Index > :: performSORIteration( const Real& omega,
@@ -235,6 +237,18 @@ bool tnlMatrix< Real, Device, Index > :: load( const tnlString& fileName )
   return tnlObject :: load( fileName );
}

template< typename Real, tnlDevice Device, typename Index >
tnlMatrix< Real, Device, Index >& tnlMatrix< Real, Device, Index > ::  operator = ( const tnlMatrix< Real, Device, Index >& matrix )
{
   this -> size = matrix. getSize();
   /*if( ! rowsReorderingPermutation. setSize( matrix. rowsReorderingPermutation. getSize() ) )
   {
      cerr << "I am not able to allocat the row permutation vector for the new matrix." << endl;
      abort();
   }
   rowsReorderingPermutation = matrix. rowsReorderingPermutation;*/
}

template< typename Real, tnlDevice Device, typename Index >
bool tnlMatrix< Real, Device, Index > :: checkMtxHeader( const tnlString& header,
		                                   bool& symmetric )
@@ -366,30 +380,31 @@ bool tnlMatrix< Real, Device, Index > :: read( istream& file,
}

template< typename Real, tnlDevice Device, typename Index >
bool tnlMatrix< Real, Device, Index > :: reorderDecreasingly( const tnlLongVector< Index, Device, Index >& permutation )
bool tnlMatrix< Real, Device, Index > :: sortRowsDecreasingly( tnlLongVector< Index, Device, Index >& permutation )
{
   /*
   /****
    * We use bucketsort to sort the rows by the number of the non-zero elements.
    */
   if( ! permutation. setSize( this -> getSize() ) )
      return false;
   permutation. setValue( 0 );

   /*
   /****
    * The permutation vector is now used to compute the buckets
    */
   for( Index i = 0; i < this -> getSize(); i ++ )
      permutation[ this -> getNonzeroElementsInRow( i ) ] ++;

   tnlLongVector< Index, tnlHost, Index > buckets( "tnlMatrix::reorderDecreasingly:buckets" );
   buckets. setSize( this -> getSize() );
   buckets. setValue( 0 );

   buckets[ 0 ] = 0;
   for( Index i = 1; i < this -> getSize; i ++ )
      buckets[ i ] = buckets[ i - 1 ] + permutation[ i ];

   for( Index i = 1; i < this -> getSize(); i ++ )
      permutation[ buckets[ this -> getNonzeroElementsInRow( i ) ] ++ ] = i;
      buckets[ i ] = buckets[ i - 1 ] + permutation[ this -> getSize() - i ];

   for( Index i = 0; i < this -> getSize(); i ++ )
      permutation[ buckets[ this -> getSize() - this -> getNonzeroElementsInRow( i ) - 1 ] ++ ] = i;
}

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