diff --git a/src/implementation/matrices/tnlCOOMatrix_impl.h b/src/implementation/matrices/tnlCOOMatrix_impl.h index a9cbdc15e4d5e270e854c02a22ca8ddda085faae..8dd8b9b5b5d6352ef2491689ac114a6429e9570f 100644 --- a/src/implementation/matrices/tnlCOOMatrix_impl.h +++ b/src/implementation/matrices/tnlCOOMatrix_impl.h @@ -11,7 +11,8 @@ template< typename Real, typename Index > tnlCOOMatrix< Real, Device, Index >::tnlCOOMatrix() :cudaWarpSize( 32 ), - numberOfUsedValues( 0 ) + numberOfUsedValues( 0 ), + appendMode( true ) { }; @@ -89,8 +90,14 @@ template< typename Real, typename Index > void tnlCOOMatrix< Real, Device, Index >::getRowLengths(tnlVector< IndexType, DeviceType, IndexType >& rowLengthsVector) const { + IndexType rowLength; for(IndexType row = 0; row < this->getRows(); row++) - rowLengthsVector.setElement(row, this->getRowLength(row)); + rowLengthsVector.setElement(row, 0); + for(IndexType elementPtr = 0; elementPtr < this->values.getSize(); elementPtr++) + { + rowLength = rowLengthsVector.getElement(this->rowIndexes.getElement(elementPtr)); + rowLengthsVector.setElement(this->rowIndexes.getElement(elementPtr), rowLength++); + } } template< typename Real, @@ -110,9 +117,12 @@ template< typename Real, typename Index > bool tnlCOOMatrix< Real, Device, Index >::setElement( const IndexType row, const IndexType column, - const RealType& value) + const RealType& value ) { - return this->addElement( row, column, value, 1.0); + if( this->appendMode ) + return this->addElement( row, column, value, 1.0 ); + else + return this->appendElement( row, column, value ); } template< typename Real, @@ -129,6 +139,8 @@ bool tnlCOOMatrix< Real, Device, Index >::addElement( const IndexType row, << " column = " << column << " this->rows = " << this->rows << " this->columns = " << this->columns ); + if( appendMode ) + return this->appendElement( row, column, value ); IndexType endPtr = this->getNumberOfUsedValues(); for(IndexType elementPtr = 0; elementPtr < endPtr; elementPtr++) @@ -150,6 +162,25 @@ bool tnlCOOMatrix< Real, Device, Index >::addElement( const IndexType row, return false; } +template< typename Real, + typename Device, + typename Index > +bool tnlCOOMatrix< Real, Device, Index >::appendElement( const IndexType row, + const IndexType column, + const RealType& value ) +{ + if( !this->getNumberOfUsedValues < this->values.getSize() ) + return false; + else + { + this->rowIndexes.setElement( this->getNumberOfUsedValues(), row ); + this->columnIndexes.setElement( this->getNumberOfUsedValues(), column ); + this->values.setElement( this->getNumberOfUsedValues(), value ); + this->numberOfUsedValues++; + } + return true; +} + template< typename Real, typename Device, typename Index > @@ -236,6 +267,8 @@ template< typename InVector, void tnlCOOMatrix< Real, Device, Index >::vectorProductHost(const InVector& inVector, OutVector& outVector) const { + for(IndexType row = 0; row < this->getRows(); row++) + outVector[ row ] = 0; for(IndexType i = 0; i < this->values.getSize(); i++) outVector[ this->rowIndexes.getElement(i) ] = this->values.getElement(i)*inVector[ this->columnIndexes.getElement(i) ]; } diff --git a/src/matrices/tnlCOOMatrix.h b/src/matrices/tnlCOOMatrix.h index c2426c50c289a8838489eac4884936ad30c4f95d..ceba85aeb5d194c56a81123462c5b2cab42401a4 100644 --- a/src/matrices/tnlCOOMatrix.h +++ b/src/matrices/tnlCOOMatrix.h @@ -1,5 +1,7 @@ /* u addElement by nejspis melo byt realokovani pole jinak se asi prvek, ktery * na danem miste nebyl pridat neda, leda by se puvodne naalokovalo pole o neco vetsi + * + * u getRowLengths dat jeden cyklus co projede vsechny prvky a nastavi rovnou cele pole */ #ifndef TNLCOOMATRIX_H_ #define TNLCOOMATRIX_H_ @@ -51,6 +53,10 @@ public: const RealType& value, const RealType& thisElementMultiplicator = 1.0); + bool appendElement( const IndexType row, + const IndexType column, + const RealType& value); + bool setRow(const IndexType row, const IndexType* columns, const RealType* values, @@ -106,6 +112,8 @@ private: IndexType numberOfUsedValues; int cudaWarpSize; + + bool appendMode; }; #include <implementation/matrices/tnlCOOMatrix_impl.h> diff --git a/tests/benchmarks/tnlCusparseCSRMatrix.h b/tests/benchmarks/tnlCusparseCSRMatrix.h index 81d0bc4f63fc37a2d1f8b7ee84ee0b732c3f909e..5f572322c5bc6484692b3f7ddb939ead9e7c616a 100644 --- a/tests/benchmarks/tnlCusparseCSRMatrix.h +++ b/tests/benchmarks/tnlCusparseCSRMatrix.h @@ -110,18 +110,19 @@ class tnlCusparseCSRMatrix< double > : public tnlCusparseCSRMatrixBase< double > { tnlAssert( matrix, ); #ifdef HAVE_CUDA - /*cusparseDcsrmv( *( this->cusparseHandle ), + cusparseDcsrmv( *( this->cusparseHandle ), CUSPARSE_OPERATION_NON_TRANSPOSE, this->matrix->getRows(), this->matrix->getColumns(), this->matrix->values.getSize(), + 1.0, this->matrixDescriptor, this->matrix->values.getData(), this->matrix->rowPointers.getData(), this->matrix->columnIndexes.getData(), inVector.getData(), 1.0, - outVector.getData() );*/ + outVector.getData() ); #endif } }; @@ -138,18 +139,19 @@ class tnlCusparseCSRMatrix< float > : public tnlCusparseCSRMatrixBase< float > { tnlAssert( matrix, ); #ifdef HAVE_CUDA - /*cusparseScsrmv( *( this->cusparseHandle ), + cusparseScsrmv( *( this->cusparseHandle ), CUSPARSE_OPERATION_NON_TRANSPOSE, this->matrix->getRows(), this->matrix->getColumns(), - this->matrix->values.getSize(), + this->matrix->values.getSize(), + 1.0, this->matrixDescriptor, this->matrix->values.getData(), this->matrix->rowPointers.getData(), this->matrix->columnIndexes.getData(), inVector.getData(), 0, - outVector.getData() );*/ + outVector.getData() ); #endif } };