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

Implementing Chunked Ellpack format.

parent 9c4e176d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -4,7 +4,8 @@ SET( headers tnlDenseMatrix_impl.h
             tnlEllpackMatrix_impl.h
             tnlSlicedEllpackMatrix_impl.h
             tnlChunkedEllpackMatrix_impl.h
             tnlCSRMatrix_impl.h )
             tnlCSRMatrix_impl.h
             tnlMatrixReader_impl.h )

SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/implementation/matrices )
set( common_SOURCES
+5 −5
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ bool tnlCSRMatrix< Real, Device, Index >::setElement( const IndexType row,
                                                                           const IndexType column,
                                                                           const Real& value )
{
   return this->addToElement( row, column, value, 0.0 );
   return this->addElement( row, column, value, 0.0 );
}

template< typename Real,
@@ -205,7 +205,7 @@ Real tnlCSRMatrix< Real, Device, Index >::getElement( const IndexType row,
template< typename Real,
          typename Device,
          typename Index >
bool tnlCSRMatrix< Real, Device, Index >::addToElement( const IndexType row,
bool tnlCSRMatrix< Real, Device, Index >::addElement( const IndexType row,
                                                      const IndexType column,
                                                      const RealType& value,
                                                      const RealType& thisElementMultiplicator )
+29 −22
Original line number Diff line number Diff line
@@ -32,6 +32,12 @@ tnlChunkedEllpackMatrix< Real, Device, Index >::tnlChunkedEllpackMatrix()
  chunksInSlice( 256 ),
  desiredChunkSize( 16 )
{
   values.setName( "tnlChunkedEllpackMatrix::values" );
   columnIndexes.setName( "tnlChunkedEllpackMatrix::columnIndexes" );
   chunksToRowsMapping.setName( "tnlChunkedEllpackMatrix::chunksToRowsMapping" );
   slicesToRowsMapping.setName( "tnlChunkedEllpackMatrix::slicesToRowsMapping" );
   rowPointers.setName( "tnlChunkedEllpackMatrix::rowPointers" );
   slices.setName( "tnlChunkedEllpackMatrix::slices" );
};

template< typename Real,
@@ -106,12 +112,11 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index >::setRowLengths( const Vector
       * number of elements in a slice.
       */
      allocatedElementsInSlice += rowLengths[ row ];
      if( allocatedElementsInSlice < desiredElementsInSlice )
      {
         row++;
      sliceSize++;
      row++;
      if( allocatedElementsInSlice < desiredElementsInSlice )
         if( row < this->rows && sliceSize < chunksInSlice ) continue;
      }
      tnlAssert( sliceSize >0, );

      /****
       * Now, compute the number of chunks per each row.
@@ -127,16 +132,13 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index >::setRowLengths( const Vector
         this->chunksToRowsMapping.setElement( i, 1 );
      while( freeChunks )
      {
         IndexType allocatedChunks( 0 );
         for( IndexType i = sliceBegin; i < sliceEnd; i++ )
         for( IndexType i = sliceBegin; i < sliceEnd && freeChunks > 0; i++ )
         {
            RealType rowRatio( 0.0 );
            if( allocatedElementsInSlice != 0 )
               rowRatio = ( RealType ) rowLengths[ i ] / ( RealType ) allocatedElementsInSlice;
            allocatedChunks += this->chunksToRowsMapping[ i ] = freeChunks * rowRatio;
            freeChunks -= this->chunksToRowsMapping[ i ] = ceil( freeChunks * rowRatio );
         }
         freeChunks -= allocatedChunks;
         tnlAssert( allocatedChunks != 0, );
         tnlAssert( freeChunks >= 0, );
      }

@@ -174,7 +176,6 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index >::setRowLengths( const Vector
      /****
       * Proceed to the next row
       */
      row++;
      sliceSize = 0;
      if( row < this->rows ) continue;
      else break;
@@ -187,7 +188,6 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index >::setRowLengths( const Vector
       ! this->columnIndexes.setSize( elementsToAllocation ) )
      return false;
   this->columnIndexes.setValue( this->columns );
   //this->numberOfSlices = sliceIndex;
   return true;
}

@@ -199,6 +199,8 @@ template< typename Real,
             typename Index2 >
bool tnlChunkedEllpackMatrix< Real, Device, Index >::setLike( const tnlChunkedEllpackMatrix< Real2, Device2, Index2 >& matrix )
{
   this->chunksInSlice = matrix.chunksInSlice;
   this->desiredChunkSize = matrix.desiredChunkSize;
   if( ! this->setDimensions( matrix.getRows(), matrix.getColumns() ) ||
       ! this->values.setLike( matrix.values ) ||
       ! this->columnIndexes.setLike( matrix.columnIndexes ) ||
@@ -314,7 +316,7 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index >::setElement( const IndexType
                                                                           const IndexType column,
                                                                           const Real& value )
{
   return this->addToElement( row, column, value, 0.0 );
   return this->addElement( row, column, value, 0.0 );
}

template< typename Real,
@@ -324,7 +326,8 @@ Real tnlChunkedEllpackMatrix< Real, Device, Index >::getElement( const IndexType
                                                                 const IndexType column ) const
{
   const IndexType& sliceIndex = slicesToRowsMapping[ row ];
   const IndexType& chunkSize = slices[ sliceIndex ].chunkSize;
   tnlAssert( sliceIndex < this->rows, );
   const IndexType& chunkSize = slices.getElement( sliceIndex ).chunkSize;
   IndexType elementPtr = rowPointers[ row ];
   const IndexType rowEnd = rowPointers[ row + 1 ];
   while( elementPtr < rowEnd && this->columnIndexes[ elementPtr ] < column )
@@ -337,7 +340,7 @@ Real tnlChunkedEllpackMatrix< Real, Device, Index >::getElement( const IndexType
template< typename Real,
          typename Device,
          typename Index >
bool tnlChunkedEllpackMatrix< Real, Device, Index >::addToElement( const IndexType row,
bool tnlChunkedEllpackMatrix< Real, Device, Index >::addElement( const IndexType row,
                                                                 const IndexType column,
                                                                 const RealType& value,
                                                                 const RealType& thisElementMultiplicator )
@@ -350,7 +353,8 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index >::addToElement( const IndexTy
                   << " this->columns = " << this-> columns );

   const IndexType& sliceIndex = slicesToRowsMapping[ row ];
   const IndexType& chunkSize = slices[ sliceIndex ].chunkSize;
   tnlAssert( sliceIndex < this->rows, );
   const IndexType& chunkSize = slices.getElement( sliceIndex ).chunkSize;
   IndexType elementPtr = rowPointers[ row ];
   const IndexType rowEnd = rowPointers[ row + 1 ];

@@ -396,7 +400,8 @@ typename Vector::RealType tnlChunkedEllpackMatrix< Real, Device, Index >::rowVec
            cerr << " row = " << row << " this->rows = " << this->rows );

   const IndexType& sliceIndex = slicesToRowsMapping[ row ];
   const IndexType& chunkSize = slices[ sliceIndex ].chunkSize;
   tnlAssert( sliceIndex < this->rows, );
   const IndexType& chunkSize = slices.getElement( sliceIndex ).chunkSize;
   IndexType elementPtr = rowPointers[ row ];
   const IndexType rowEnd = rowPointers[ row + 1 ];

@@ -463,7 +468,8 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index >::performSORIteration( const
   RealType sum( 0.0 );

   const IndexType& sliceIndex = slicesToRowsMapping[ row ];
   const IndexType& chunkSize = slices[ sliceIndex ].chunkSize;
   tnlAssert( sliceIndex < this->rows, );
   const IndexType& chunkSize = slices.getElement( sliceIndex ).chunkSize;
   IndexType elementPtr = rowPointers[ row ];
   const IndexType rowEnd = rowPointers[ row + 1 ];
   IndexType column;
@@ -543,7 +549,8 @@ void tnlChunkedEllpackMatrix< Real, Device, Index >::print( ostream& str ) const
      str <<"Row: " << row << " -> ";

      const IndexType& sliceIndex = slicesToRowsMapping[ row ];
      const IndexType& chunkSize = slices[ sliceIndex ].chunkSize;
      tnlAssert( sliceIndex < this->rows, );
      const IndexType& chunkSize = slices.getElement( sliceIndex ).chunkSize;
      IndexType elementPtr = rowPointers[ row ];
      const IndexType rowEnd = rowPointers[ row + 1 ];

+41 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#ifndef TNLDENSEMATRIX_IMPL_H_
#define TNLDENSEMATRIX_IMPL_H_

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

template< typename Real,
@@ -83,7 +84,7 @@ Index tnlDenseMatrix< Real, Device, Index >::getColumns() const
template< typename Real,
          typename Device,
          typename Index >
bool tnlDenseMatrix< Real, Device, Index >::addToElement( const IndexType row,
bool tnlDenseMatrix< Real, Device, Index >::addElement( const IndexType row,
                                                        const IndexType column,
                                                        const RealType& value,
                                                        const RealType& thisElementMultiplicator )
@@ -95,6 +96,42 @@ bool tnlDenseMatrix< Real, Device, Index >::addToElement( const IndexType row,
         thisElementMultiplicator * this->operator()( row, column ) + value;
}

template< typename Real,
          typename Device,
          typename Index >
bool tnlDenseMatrix< Real, Device, Index >::setRow( const IndexType row,
                                                    const IndexType* columns,
                                                    const RealType* values,
                                                    const IndexType elements )
{
   tnlAssert( elements <= this->getDimensions().y(),
            cerr << " elements = " << elements
                 << " this->columns = " << this->getDimensions().y()
                 << " this->getName() = " << this->getName() );
   for( IndexType i = 0; i < elements; i++ )
      this->operator()( row, columns[ i ] ) = values[ i ];
   return true;
}

template< typename Real,
          typename Device,
          typename Index >
bool tnlDenseMatrix< Real, Device, Index >::addRow( const IndexType row,
                                                    const IndexType* columns,
                                                    const RealType* values,
                                                    const IndexType elements,
                                                    const RealType thisRowMultiplicator )
{
   tnlAssert( elements <= this->columns,
            cerr << " elements = " << elements
                 << " this->columns = " << this->columns
                 << " this->getName() = " << this->getName() );
   for( IndexType i = 0; i < elements; i++ )
      this->operator[]( row, columns[ i ] ) =
               thisRowMultiplicator * this->operator[]( row, columns[ i ] ) + values[ i ];
   return true;
}

template< typename Real,
          typename Device,
          typename Index >
+5 −5
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ bool tnlEllpackMatrix< Real, Device, Index > :: setElement( const IndexType row,
                                                            const IndexType column,
                                                            const Real& value )
{
   return this->addToElement( row, column, value, 0.0 );
   return this->addElement( row, column, value, 0.0 );
}

template< typename Real,
@@ -205,7 +205,7 @@ Real tnlEllpackMatrix< Real, Device, Index >::getElement( const IndexType row,
template< typename Real,
          typename Device,
          typename Index >
bool tnlEllpackMatrix< Real, Device, Index > :: addToElement( const IndexType row,
bool tnlEllpackMatrix< Real, Device, Index > :: addElement( const IndexType row,
                                                            const IndexType column,
                                                            const RealType& value,
                                                            const RealType& thisElementMultiplicator )
Loading