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

Optimizing slow Legacy CSR unit test.

parent dca1b1ca
Loading
Loading
Loading
Loading
+42 −44
Original line number Diff line number Diff line
@@ -1393,45 +1393,36 @@ void test_VectorProductCSRAdaptive()
   using IndexType = typename Matrix::IndexType;
   using VectorType = TNL::Containers::Vector< RealType, DeviceType, IndexType >;


   Matrix m;
   m.reset();
   IndexType m_rows = 100;
   IndexType m_cols = 100;
   //----------------- Test CSR Stream part ------------------
   Matrix m;
   m.setDimensions( m_rows, m_cols );
   typename Matrix::CompressedRowLengthsVector rowLengths(
   typename Matrix::CompressedRowLengthsVector rowLengths( 100, 100 );

   if( std::is_same< DeviceType, TNL::Devices::Cuda >::value )
   {
         100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
         100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
         100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
         100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
         100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
         100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
         100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
         100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
         100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
         100, 100, 100, 100, 100, 100, 100, 100, 100, 100
      typedef typename Matrix::Self< RealType, TNL::Devices::Host, IndexType > HostMatrixType;
      typename HostMatrixType::CompressedRowLengthsVector rowLengths( 100, 100 );
      HostMatrixType hostMatrix;
      hostMatrix.setDimensions( m_rows, m_cols );
      hostMatrix.setCompressedRowLengths( rowLengths );
      for (int i = 0; i < m_rows; ++i)
         for (int j = 0; j < m_cols; ++j) 
            hostMatrix.setElement( i, j, i + 1 );
      m = hostMatrix;
   }
   );

   else
   {
      m.setCompressedRowLengths( rowLengths );

      for (int i = 0; i < m_rows; ++i)
         for (int j = 0; j < m_cols; ++j) 
            m.setElement( i, j, i + 1 );
   }


   VectorType inVector;
   inVector.setSize( m_rows );
   for( IndexType i = 0; i < inVector.getSize(); ++i )        
      inVector.setElement( i, 1 );

   VectorType outVector;  
   outVector.setSize( m_rows );
   for( IndexType i = 0; i < outVector.getSize(); ++i )
      outVector.setElement( i, 0 );
   
   VectorType inVector( m_rows, 1.0 );
   VectorType outVector( m_rows, 0.0 );
   m.vectorProduct( inVector, outVector);

   for (int i = 0; i < m_rows; ++i)
@@ -1447,20 +1438,27 @@ void test_VectorProductCSRAdaptive()
   m.setDimensions( m_rows, m_cols );
   typename Matrix::CompressedRowLengthsVector rowLengths2({m_cols});

   if( std::is_same< DeviceType, TNL::Devices::Cuda >::value )
   {
      typedef typename Matrix::Self< RealType, TNL::Devices::Host, IndexType > HostMatrixType;
      typename HostMatrixType::CompressedRowLengthsVector rowLengths( {m_cols} );
      HostMatrixType hostMatrix;
      hostMatrix.setDimensions( m_rows, m_cols );
      hostMatrix.setCompressedRowLengths( rowLengths );
      for( int i = 0; i < m_cols; ++i )
         hostMatrix.setElement( 0, i, i );
      m = hostMatrix;
   }
   else
   {
      m.setCompressedRowLengths( rowLengths2 );

      for (int i = 0; i < m_cols; ++i) 
         m.setElement( 0, i, i );
   }

   VectorType inVector2;
   inVector2.setSize( m_cols );
   for( IndexType i = 0; i < inVector2.getSize(); i++ )
      inVector2.setElement( i, 2 );
   VectorType inVector2( m_cols, 2.0 );

   VectorType outVector2;
   outVector2.setSize( m_rows );
   for( IndexType i = 0; i < outVector2.getSize(); ++i )
      outVector2.setElement( i, 0 );
   VectorType outVector2( m_rows, 0.0 );

   m.vectorProduct(inVector2, outVector2);
   EXPECT_EQ( outVector2.getElement( 0 ), 8997000 );