Commit 3c945fad authored by Tomáš Oberhuber's avatar Tomáš Oberhuber

Fixing BiEllpack.

parent f6ace3fc
......@@ -211,7 +211,7 @@ computeColumnSizes( const SizesHolder& segmentsSizes )
if( strip == numberOfStrips - 1 )
{
IndexType segmentsCount = size - firstSegment;
while( !( segmentsCount > TNL::pow( 2, getLogWarpSize() - 1 - emptyGroups ) ) )
while( segmentsCount <= TNL::pow( 2, getLogWarpSize() - 1 - emptyGroups ) - 1 )
emptyGroups++;
for( IndexType group = groupBegin; group < groupBegin + emptyGroups; group++ )
groupPointersView[ group ] = 0;
......@@ -290,7 +290,7 @@ template< typename Device,
void BiEllpack< Device, Index, IndexAllocator, Organization, WarpSize >::
verifyRowLengths( const SizesHolder& segmentsSizes )
{
bool ok = true;
std::cerr << "segmentsSizes = " << segmentsSizes << std::endl;
for( IndexType segmentIdx = 0; segmentIdx < this->getSize(); segmentIdx++ )
{
const IndexType strip = segmentIdx / getWarpSize();
......@@ -303,6 +303,7 @@ verifyRowLengths( const SizesHolder& segmentsSizes )
const IndexType groupsCount = details::BiEllpack< Index, Device, Organization, WarpSize >::getActiveGroupsCount( this->rowPermArray.getConstView(), segmentIdx );
for( IndexType group = 0; group < groupsCount; group++ )
{
std::cerr << "groupIdx = " << group << " groupLength = " << this->getGroupLength( strip, group ) << std::endl;
for( IndexType i = 0; i < this->getGroupLength( strip, group ); i++ )
{
IndexType biElementPtr = elementPtr;
......@@ -315,10 +316,8 @@ verifyRowLengths( const SizesHolder& segmentsSizes )
}
}
if( segmentsSizes.getElement( segmentIdx ) > rowLength )
ok = false;
throw( std::logic_error( "Segments capacities verification failed." ) );
}
if( ! ok )
throw( std::logic_error( "Segments capacities verification failed." ) );
}
template< typename Device,
......@@ -349,7 +348,7 @@ setSegmentsSizes( const SizesHolder& segmentsSizes )
this->groupPointers.template scan< Algorithms::ScanType::Exclusive >();
this->verifyRowPerm( segmentsSizes );
this->verifyRowLengths( segmentsSizes );
//this->verifyRowLengths( segmentsSizes ); // TODO: I am not sure what this test is doing.
this->storageSize = getWarpSize() * this->groupPointers.getElement( strips * ( getLogWarpSize() + 1 ) );
}
else
......
......@@ -1235,7 +1235,6 @@ void test_VectorProduct()
EXPECT_EQ( outVector_4.getElement( 6 ), 280 );
EXPECT_EQ( outVector_4.getElement( 7 ), 330 );
/*
* Sets up the following 8x8 sparse matrix:
*
......@@ -1308,6 +1307,55 @@ void test_VectorProduct()
EXPECT_EQ( outVector_5.getElement( 5 ), 224 );
EXPECT_EQ( outVector_5.getElement( 6 ), 352 );
EXPECT_EQ( outVector_5.getElement( 7 ), 520 );
/////
// Large test
if( ( std::is_same< IndexType, int >::value || std::is_same< IndexType, long int >::value ) &&
std::is_same< RealType, double >::value )
{
const IndexType size( 35 );
//for( int size = 1; size < 1000; size++ )
{
//std::cerr << " size = " << size << std::endl;
// Test with large diagonal matrix
Matrix m1( size, size );
TNL::Containers::Vector< IndexType, DeviceType, IndexType > rowCapacities( size );
rowCapacities.evaluate( [] __cuda_callable__ ( IndexType i ) { return 1; } );
m1.setRowCapacities( rowCapacities );
auto f1 = [=] __cuda_callable__ ( IndexType row, IndexType localIdx, IndexType& column, RealType& value, bool& compute ) {
if( localIdx == 0 )
{
value = row + 1;
column = row;
}
};
m1.forAllRows( f1 );
TNL::Containers::Vector< double, DeviceType, IndexType > in( size, 1.0 ), out( size, 0.0 );
m1.vectorProduct( in, out );
//std::cerr << out << std::endl;
for( IndexType i = 0; i < size; i++ )
EXPECT_EQ( out.getElement( i ), i + 1 );
// Test with large triangular matrix
Matrix m2( size, size );
rowCapacities.evaluate( [] __cuda_callable__ ( IndexType i ) { return i + 1; } );
m2.setRowCapacities( rowCapacities );
auto f2 = [=] __cuda_callable__ ( IndexType row, IndexType localIdx, IndexType& column, RealType& value, bool& compute ) {
if( localIdx <= row )
{
value = row -localIdx + 1;
column = localIdx;
}
};
m2.forAllRows( f2 );
out = 0.0;
m2.vectorProduct( in, out );
//std::cerr << out << std::endl;
for( IndexType i = 0; i < size; i++ )
EXPECT_EQ( out.getElement( i ), ( i + 1 ) * ( i + 2 ) / 2 );
}
}
}
template< typename Matrix >
......
......@@ -30,7 +30,7 @@ using ColumnMajorBiEllpack = TNL::Algorithms::Segments::BiEllpack< Device, Index
// types for which MatrixTest is instantiated
using MatrixTypes = ::testing::Types
<
TNL::Matrices::SparseMatrix< int, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >,
TNL::Matrices::SparseMatrix< double, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >,
TNL::Matrices::SparseMatrix< int, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, RowMajorBiEllpack >,
TNL::Matrices::SparseMatrix< long, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, RowMajorBiEllpack >,
TNL::Matrices::SparseMatrix< float, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, RowMajorBiEllpack >,
......@@ -40,15 +40,15 @@ using MatrixTypes = ::testing::Types
TNL::Matrices::SparseMatrix< float, TNL::Devices::Host, long, TNL::Matrices::GeneralMatrix, RowMajorBiEllpack >,
TNL::Matrices::SparseMatrix< double, TNL::Devices::Host, long, TNL::Matrices::GeneralMatrix, RowMajorBiEllpack >
#ifdef HAVE_CUDA
,TNL::Matrices::SparseMatrix< int, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >,
,TNL::Matrices::SparseMatrix< double, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, RowMajorBiEllpack >,
TNL::Matrices::SparseMatrix< int, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >,
TNL::Matrices::SparseMatrix< long, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >,
TNL::Matrices::SparseMatrix< float, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >,
TNL::Matrices::SparseMatrix< double, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >,
TNL::Matrices::SparseMatrix< int, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >,
TNL::Matrices::SparseMatrix< long, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >,
TNL::Matrices::SparseMatrix< float, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >,
TNL::Matrices::SparseMatrix< double, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >,
TNL::Matrices::SparseMatrix< int, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, RowMajorBiEllpack >,
TNL::Matrices::SparseMatrix< double, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, ColumnMajorBiEllpack >
#endif
>;
......
......@@ -52,4 +52,5 @@ using MatrixTypes = ::testing::Types
#endif
#include "SparseMatrixTest.h"
#include "../main.h"
......@@ -53,4 +53,5 @@ using MatrixTypes = ::testing::Types
#endif
#include "SparseMatrixTest.h"
#include "../main.h"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment