From 5a68640d3ba8d308c3096cb55024acd2268dff38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com> Date: Mon, 23 Dec 2019 16:15:02 +0100 Subject: [PATCH] Fixed sparse matrix assignment operator. --- src/TNL/Containers/Segments/SlicedEllpackView.hpp | 2 +- src/TNL/Matrices/SparseMatrix.h | 2 +- src/TNL/Matrices/SparseMatrix.hpp | 8 +++++++- src/UnitTests/Matrices/SparseMatrixCopyTest.h | 1 - 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/TNL/Containers/Segments/SlicedEllpackView.hpp b/src/TNL/Containers/Segments/SlicedEllpackView.hpp index f2e03bd38a..66cfce1952 100644 --- a/src/TNL/Containers/Segments/SlicedEllpackView.hpp +++ b/src/TNL/Containers/Segments/SlicedEllpackView.hpp @@ -171,7 +171,7 @@ getGlobalIndex( const Index segmentIdx, const Index localIdx ) const } else { -#ifdef __CUDA__ARCH__ +#ifdef __CUDA_ARCH__ sliceOffset = this->sliceOffsets[ sliceIdx ]; segmentSize = this->sliceSegmentSizes[ sliceIdx ]; #else diff --git a/src/TNL/Matrices/SparseMatrix.h b/src/TNL/Matrices/SparseMatrix.h index 44ded93a65..a5effce936 100644 --- a/src/TNL/Matrices/SparseMatrix.h +++ b/src/TNL/Matrices/SparseMatrix.h @@ -34,7 +34,7 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator > using IndexType = Index; using RealAllocatorType = RealAllocator; using IndexAllocatorType = IndexAllocator; - using RowsCapacitiesType = Containers::Vector< IndexType, DeviceType, IndexType >; + using RowsCapacitiesType = Containers::Vector< IndexType, DeviceType, IndexType, IndexAllocatorType >; using RowsCapacitiesView = Containers::VectorView< IndexType, DeviceType, IndexType >; using ConstRowsCapacitiesView = typename RowsCapacitiesView::ConstViewType; using ValuesVectorType = typename Matrix< Real, Device, Index, RealAllocator >::ValuesVector; diff --git a/src/TNL/Matrices/SparseMatrix.hpp b/src/TNL/Matrices/SparseMatrix.hpp index 964e9eb221..75f505f5f4 100644 --- a/src/TNL/Matrices/SparseMatrix.hpp +++ b/src/TNL/Matrices/SparseMatrix.hpp @@ -739,8 +739,9 @@ operator=( const SparseMatrix< Real2, Segments2, Device2, Index2, RealAllocator2 } else { + //std::cerr << "Matrix = " << std::endl << matrix << std::endl; const IndexType maxRowLength = max( rowLengths ); - const IndexType bufferRowsCount( 128 ); + const IndexType bufferRowsCount( 8 ); const size_t bufferSize = bufferRowsCount * maxRowLength; Containers::Vector< Real2, Device2, Index2, RealAllocator2 > matrixValuesBuffer( bufferSize ); Containers::Vector< Index2, Device2, Index2, IndexAllocator2 > matrixColumnsBuffer( bufferSize ); @@ -757,6 +758,7 @@ operator=( const SparseMatrix< Real2, Segments2, Device2, Index2, RealAllocator2 { const IndexType lastRow = min( baseRow + bufferRowsCount, rowsCount ); thisColumnsBuffer = paddingIndex; + matrixColumnsBuffer_view = paddingIndex; //// // Copy matrix elements into buffer @@ -765,12 +767,15 @@ operator=( const SparseMatrix< Real2, Segments2, Device2, Index2, RealAllocator2 if( column != paddingIndex ) { const IndexType bufferIdx = ( rowIdx - baseRow ) * maxRowLength + localIdx; + //printf( ">>>RowIdx = %d GlobalIdx = %d column = %d bufferIdx = %d \n", rowIdx, globalIdx, column, bufferIdx ); matrixValuesBuffer_view[ bufferIdx ] = matrix_values_view[ globalIdx ]; matrixColumnsBuffer_view[ bufferIdx ] = column; } }; matrix.forRows( baseRow, lastRow, f1 ); + //std::cerr << "Values = " << matrixValuesBuffer_view << std::endl; + //std::cerr << "Columns = " << matrixColumnsBuffer_view << std::endl; //// // Copy the source matrix buffer to this matrix buffer thisValuesBuffer_view = matrixValuesBuffer_view; @@ -790,6 +795,7 @@ operator=( const SparseMatrix< Real2, Segments2, Device2, Index2, RealAllocator2 this->forRows( baseRow, lastRow, f2 ); baseRow += bufferRowsCount; } + //std::cerr << "This matrix = " << std::endl << *this << std::endl; } } diff --git a/src/UnitTests/Matrices/SparseMatrixCopyTest.h b/src/UnitTests/Matrices/SparseMatrixCopyTest.h index 684a6a8713..e3fb505d30 100644 --- a/src/UnitTests/Matrices/SparseMatrixCopyTest.h +++ b/src/UnitTests/Matrices/SparseMatrixCopyTest.h @@ -438,7 +438,6 @@ void testConversion() } } - TEST( SparseMatrixCopyTest, CSR_HostToHost ) { testCopyAssignment< CSR_host, CSR_host >(); -- GitLab