Loading src/implementation/matrices/tnlEllpackSymMatrix_impl.h +13 −5 Original line number Diff line number Diff line Loading @@ -76,8 +76,8 @@ bool tnlEllpackSymMatrix< Real, Device, Index >::setRowLengths( const RowLengths { tnlAssert( this->getRows() > 0, ); tnlAssert( this->getColumns() > 0, ); tnlAssert( this->rowLengths > 0, cerr << "this->rowLengths = " << this->rowLengths ); //tnlAssert( this->rowLengths > 0, // cerr << "this->rowLengths = " << this->rowLengths ); this->rowLengths = this->maxRowLength = rowLengths.max(); return allocateElements(); } Loading Loading @@ -394,6 +394,9 @@ template< typename Real, Real tnlEllpackSymMatrix< Real, Device, Index >::getElementFast( const IndexType row, const IndexType column ) const { if( row < column ) return this->getElementFast( column, row ); typedef tnlEllpackSymMatrixDeviceDependentCode< DeviceType > DDCType; IndexType elementPtr = DDCType::getRowBegin( *this, row ); const IndexType rowEnd = DDCType::getRowEnd( *this, row ); Loading @@ -413,6 +416,9 @@ template< typename Real, Real tnlEllpackSymMatrix< Real, Device, Index >::getElement( const IndexType row, const IndexType column ) const { if( row < column ) return this->getElement( column, row ); typedef tnlEllpackSymMatrixDeviceDependentCode< DeviceType > DDCType; IndexType elementPtr = DDCType::getRowBegin( *this, row ); const IndexType rowEnd = DDCType::getRowEnd( *this, row ); Loading Loading @@ -642,7 +648,8 @@ class tnlEllpackSymMatrixDeviceDependentCode< tnlHost > static Index getRowEnd( const tnlEllpackSymMatrix< Real, Device, Index >& matrix, const Index row ) { return ( row + 1 ) * matrix.rowLengths; //return row * matrix.rowLengths + row + 1; return min(row * matrix.rowLengths + row + 1, ( row + 1 ) * matrix.rowLengths ); } template< typename Real, Loading Loading @@ -734,7 +741,7 @@ void tnlEllpackSymMatrix< Real, Device, Index >::spmvCuda( const InVector& inVec const IndexType column = this->columnIndexes.getElemnt( i ); outVector[ rowId ] += this->values.getElement( i ) * inVector[ column ]; if( rowId != column ) outVector[ column ] += this->values.getElement( i ) * inVector[ row ]; outVector[ column ].add( this->values.getElement( i ) * inVector[ row ] ); i += step; } }; Loading Loading @@ -784,7 +791,8 @@ class tnlEllpackSymMatrixDeviceDependentCode< tnlCuda > static Index getRowEnd( const tnlEllpackSymMatrix< Real, Device, Index >& matrix, const Index row ) { return row + getElementStep( matrix ) * matrix.rowLengths; // TODO: fix this: return row + getElementStep( matrix ) * matrix.rowLengths; return min( row + getElementStep( matrix ) * matrix.rowLengths, row + ( row + 1 ) * getElementStep( matrix ) ); } template< typename Real, Loading tests/long-time-unit-tests/matrix-formats-test.h +16 −9 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ void setupConfig( tnlConfigDescription& config ) template< typename Matrix > bool testMatrix( const tnlParameterContainer& parameters, bool sym ) bool testMatrix( bool sym, const tnlParameterContainer& parameters ) { Matrix matrix; typedef typename Matrix::RealType RealType; Loading @@ -74,6 +74,12 @@ bool testMatrix( const tnlParameterContainer& parameters, bool sym ) return false; //if( ! tnlMatrixReader< Matrix >::verifyMtxFile( file, matrix, verbose ) ) // return false; //for( int i = 0; i < matrix.getRows(); i++ ) // for( int j = 0; j < matrix.getColumns(); j++ ) // { // cout << "Row " << i << ", column " << j << ", value " << matrix.getElement( i, j ) << endl; // } if( parameters.GetParameter< bool >( "hard-test" ) ) { typedef tnlDenseMatrix< RealType, DeviceType, IndexType > DenseMatrix; Loading Loading @@ -113,6 +119,7 @@ bool testMatrix( const tnlParameterContainer& parameters, bool sym ) b.setSize( matrix.getRows() ); for( IndexType i = 0; i < x.getSize(); i++ ) { b.setValue( 0 ); x.setValue( 0 ); x.setElement( i, 1.0 ); matrix.vectorProduct( x, b ); Loading Loading @@ -149,49 +156,49 @@ int main( int argc, char* argv[] ) const tnlString& matrixFormat = parameters.GetParameter< tnlString >( "matrix-format" ); if( matrixFormat == "dense" ) { if( !testMatrix< tnlDenseMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlDenseMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "ellpack" ) { if( !testMatrix< tnlEllpackMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlEllpackMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "ellpack-sym" ) { if( !testMatrix< tnlEllpackSymMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlEllpackSymMatrix< double, tnlHost, int > >( true, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "sliced-ellpack" ) { if( !testMatrix< tnlSlicedEllpackMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlSlicedEllpackMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "chunked-ellpack" ) { if( !testMatrix< tnlChunkedEllpackMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlChunkedEllpackMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "csr" ) { if( !testMatrix< tnlCSRMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlCSRMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "bi-ell" ) { if( !testMatrix< tnlBiEllpackMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlBiEllpackMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "bi-ell-sym" ) { if( !testMatrix< tnlBiEllpackSymMatrix< double, tnlHost, int > >( parameters, true ) ) if( !testMatrix< tnlBiEllpackSymMatrix< double, tnlHost, int > >( true, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } Loading Loading
src/implementation/matrices/tnlEllpackSymMatrix_impl.h +13 −5 Original line number Diff line number Diff line Loading @@ -76,8 +76,8 @@ bool tnlEllpackSymMatrix< Real, Device, Index >::setRowLengths( const RowLengths { tnlAssert( this->getRows() > 0, ); tnlAssert( this->getColumns() > 0, ); tnlAssert( this->rowLengths > 0, cerr << "this->rowLengths = " << this->rowLengths ); //tnlAssert( this->rowLengths > 0, // cerr << "this->rowLengths = " << this->rowLengths ); this->rowLengths = this->maxRowLength = rowLengths.max(); return allocateElements(); } Loading Loading @@ -394,6 +394,9 @@ template< typename Real, Real tnlEllpackSymMatrix< Real, Device, Index >::getElementFast( const IndexType row, const IndexType column ) const { if( row < column ) return this->getElementFast( column, row ); typedef tnlEllpackSymMatrixDeviceDependentCode< DeviceType > DDCType; IndexType elementPtr = DDCType::getRowBegin( *this, row ); const IndexType rowEnd = DDCType::getRowEnd( *this, row ); Loading @@ -413,6 +416,9 @@ template< typename Real, Real tnlEllpackSymMatrix< Real, Device, Index >::getElement( const IndexType row, const IndexType column ) const { if( row < column ) return this->getElement( column, row ); typedef tnlEllpackSymMatrixDeviceDependentCode< DeviceType > DDCType; IndexType elementPtr = DDCType::getRowBegin( *this, row ); const IndexType rowEnd = DDCType::getRowEnd( *this, row ); Loading Loading @@ -642,7 +648,8 @@ class tnlEllpackSymMatrixDeviceDependentCode< tnlHost > static Index getRowEnd( const tnlEllpackSymMatrix< Real, Device, Index >& matrix, const Index row ) { return ( row + 1 ) * matrix.rowLengths; //return row * matrix.rowLengths + row + 1; return min(row * matrix.rowLengths + row + 1, ( row + 1 ) * matrix.rowLengths ); } template< typename Real, Loading Loading @@ -734,7 +741,7 @@ void tnlEllpackSymMatrix< Real, Device, Index >::spmvCuda( const InVector& inVec const IndexType column = this->columnIndexes.getElemnt( i ); outVector[ rowId ] += this->values.getElement( i ) * inVector[ column ]; if( rowId != column ) outVector[ column ] += this->values.getElement( i ) * inVector[ row ]; outVector[ column ].add( this->values.getElement( i ) * inVector[ row ] ); i += step; } }; Loading Loading @@ -784,7 +791,8 @@ class tnlEllpackSymMatrixDeviceDependentCode< tnlCuda > static Index getRowEnd( const tnlEllpackSymMatrix< Real, Device, Index >& matrix, const Index row ) { return row + getElementStep( matrix ) * matrix.rowLengths; // TODO: fix this: return row + getElementStep( matrix ) * matrix.rowLengths; return min( row + getElementStep( matrix ) * matrix.rowLengths, row + ( row + 1 ) * getElementStep( matrix ) ); } template< typename Real, Loading
tests/long-time-unit-tests/matrix-formats-test.h +16 −9 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ void setupConfig( tnlConfigDescription& config ) template< typename Matrix > bool testMatrix( const tnlParameterContainer& parameters, bool sym ) bool testMatrix( bool sym, const tnlParameterContainer& parameters ) { Matrix matrix; typedef typename Matrix::RealType RealType; Loading @@ -74,6 +74,12 @@ bool testMatrix( const tnlParameterContainer& parameters, bool sym ) return false; //if( ! tnlMatrixReader< Matrix >::verifyMtxFile( file, matrix, verbose ) ) // return false; //for( int i = 0; i < matrix.getRows(); i++ ) // for( int j = 0; j < matrix.getColumns(); j++ ) // { // cout << "Row " << i << ", column " << j << ", value " << matrix.getElement( i, j ) << endl; // } if( parameters.GetParameter< bool >( "hard-test" ) ) { typedef tnlDenseMatrix< RealType, DeviceType, IndexType > DenseMatrix; Loading Loading @@ -113,6 +119,7 @@ bool testMatrix( const tnlParameterContainer& parameters, bool sym ) b.setSize( matrix.getRows() ); for( IndexType i = 0; i < x.getSize(); i++ ) { b.setValue( 0 ); x.setValue( 0 ); x.setElement( i, 1.0 ); matrix.vectorProduct( x, b ); Loading Loading @@ -149,49 +156,49 @@ int main( int argc, char* argv[] ) const tnlString& matrixFormat = parameters.GetParameter< tnlString >( "matrix-format" ); if( matrixFormat == "dense" ) { if( !testMatrix< tnlDenseMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlDenseMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "ellpack" ) { if( !testMatrix< tnlEllpackMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlEllpackMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "ellpack-sym" ) { if( !testMatrix< tnlEllpackSymMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlEllpackSymMatrix< double, tnlHost, int > >( true, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "sliced-ellpack" ) { if( !testMatrix< tnlSlicedEllpackMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlSlicedEllpackMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "chunked-ellpack" ) { if( !testMatrix< tnlChunkedEllpackMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlChunkedEllpackMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "csr" ) { if( !testMatrix< tnlCSRMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlCSRMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "bi-ell" ) { if( !testMatrix< tnlBiEllpackMatrix< double, tnlHost, int > >( parameters, false ) ) if( !testMatrix< tnlBiEllpackMatrix< double, tnlHost, int > >( false, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } if( matrixFormat == "bi-ell-sym" ) { if( !testMatrix< tnlBiEllpackSymMatrix< double, tnlHost, int > >( parameters, true ) ) if( !testMatrix< tnlBiEllpackSymMatrix< double, tnlHost, int > >( true, parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; } Loading