Skip to content
Snippets Groups Projects
Commit c3480c11 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Per-row counts of valid values in ellpack multimap are stored in separate vector

parent 3360d606
No related branches found
No related tags found
No related merge requests found
...@@ -61,6 +61,7 @@ class EllpackIndexMultimap ...@@ -61,6 +61,7 @@ class EllpackIndexMultimap
protected: protected:
Containers::Vector< IndexType, DeviceType, IndexType > values; Containers::Vector< IndexType, DeviceType, IndexType > values;
Containers::Vector< LocalIndexType, DeviceType, IndexType > valuesCounts;
IndexType keysRange; IndexType keysRange;
LocalIndexType maxValuesCount; LocalIndexType maxValuesCount;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#pragma once #pragma once
#include <type_traits>
#include <ostream> #include <ostream>
namespace TNL { namespace TNL {
...@@ -59,18 +60,25 @@ class EllpackIndexMultimapValues ...@@ -59,18 +60,25 @@ class EllpackIndexMultimapValues
bool operator==( const ThisType& other ) const; bool operator==( const ThisType& other ) const;
bool operator!=( const ThisType& other ) const;
void print( std::ostream& str ) const; void print( std::ostream& str ) const;
protected: protected:
using ValuesCountType = typename std::conditional< std::is_const< IndexType >::value,
typename std::add_const< LocalIndexType >::type,
LocalIndexType >::type;
EllpackIndexMultimapValues( IndexType* values, EllpackIndexMultimapValues( IndexType* values,
ValuesCountType* valuesCounts,
const IndexType& input, const IndexType& input,
const LocalIndexType& allocatedSize ); const LocalIndexType& allocatedSize );
IndexType* values; IndexType* values;
// TODO: step is unused ValuesCountType* valuesCount;
// LocalIndexType step;
// TODO: this is useless for a const-accessor (without setSize etc.)
LocalIndexType allocatedSize; LocalIndexType allocatedSize;
friend EllpackIndexMultimap< IndexType, DeviceType, LocalIndexType >; friend EllpackIndexMultimap< IndexType, DeviceType, LocalIndexType >;
......
...@@ -21,7 +21,7 @@ template< typename Index, ...@@ -21,7 +21,7 @@ template< typename Index,
typename LocalIndex > typename LocalIndex >
EllpackIndexMultimapValues< Index, Device, LocalIndex >:: EllpackIndexMultimapValues< Index, Device, LocalIndex >::
EllpackIndexMultimapValues() EllpackIndexMultimapValues()
: values( nullptr ), allocatedSize( 0 ) : values( nullptr ), valuesCount( nullptr ), allocatedSize( 0 )
{ {
} }
...@@ -30,9 +30,10 @@ template< typename Index, ...@@ -30,9 +30,10 @@ template< typename Index,
typename LocalIndex > typename LocalIndex >
EllpackIndexMultimapValues< Index, Device, LocalIndex >:: EllpackIndexMultimapValues< Index, Device, LocalIndex >::
EllpackIndexMultimapValues( ThisType&& other ) EllpackIndexMultimapValues( ThisType&& other )
: values( other.values ), allocatedSize( other.allocatedSize ) : values( other.values ), valuesCount( other.valuesCount ), allocatedSize( other.allocatedSize )
{ {
other.values = nullptr; other.values = nullptr;
other.valuesCount = nullptr;
other.allocatedSize = 0; other.allocatedSize = 0;
} }
...@@ -59,8 +60,10 @@ EllpackIndexMultimapValues< Index, Device, LocalIndex >:: ...@@ -59,8 +60,10 @@ EllpackIndexMultimapValues< Index, Device, LocalIndex >::
operator=( ThisType&& other ) operator=( ThisType&& other )
{ {
this->values = other.values; this->values = other.values;
this->valuesCount = other.valuesCount;
this->allocatedSize = other.allocatedSize; this->allocatedSize = other.allocatedSize;
other.values = nullptr; other.values = nullptr;
other.valuesCount = nullptr;
other.allocatedSize = 0; other.allocatedSize = 0;
return *this; return *this;
} }
...@@ -73,6 +76,7 @@ EllpackIndexMultimapValues< Index, Device, LocalIndex >:: ...@@ -73,6 +76,7 @@ EllpackIndexMultimapValues< Index, Device, LocalIndex >::
bind( const ThisType& other ) bind( const ThisType& other )
{ {
this->values = other.values; this->values = other.values;
this->valuesCount = other.valuesCount;
this->allocatedSize = other.allocatedSize; this->allocatedSize = other.allocatedSize;
} }
...@@ -81,11 +85,14 @@ template< typename Index, ...@@ -81,11 +85,14 @@ template< typename Index,
typename LocalIndex > typename LocalIndex >
EllpackIndexMultimapValues< Index, Device, LocalIndex >:: EllpackIndexMultimapValues< Index, Device, LocalIndex >::
EllpackIndexMultimapValues( IndexType* values, EllpackIndexMultimapValues( IndexType* values,
ValuesCountType* valuesCounts,
const IndexType& input, const IndexType& input,
const LocalIndexType& allocatedSize ) const LocalIndexType& allocatedSize )
{ {
this->values = &values[ input * ( allocatedSize + 1 ) ]; this->values = &values[ input * allocatedSize ];
this->valuesCount = &valuesCounts[ input ];
this->allocatedSize = allocatedSize; this->allocatedSize = allocatedSize;
Assert( *(this->valuesCount) <= allocatedSize, );
} }
template< typename Index, template< typename Index,
...@@ -95,9 +102,9 @@ bool ...@@ -95,9 +102,9 @@ bool
EllpackIndexMultimapValues< Index, Device, LocalIndex >:: EllpackIndexMultimapValues< Index, Device, LocalIndex >::
setSize( const LocalIndexType& size ) setSize( const LocalIndexType& size )
{ {
if( ! this->values || size > this->allocatedSize ) if( ! this->valuesCount || size > this->allocatedSize )
return false; return false;
this->values[ this->allocatedSize ] = size; *valuesCount = size;
return true; return true;
} }
...@@ -108,9 +115,9 @@ LocalIndex ...@@ -108,9 +115,9 @@ LocalIndex
EllpackIndexMultimapValues< Index, Device, LocalIndex >:: EllpackIndexMultimapValues< Index, Device, LocalIndex >::
getSize() const getSize() const
{ {
if( ! this->values ) if( ! valuesCount )
return 0; return 0;
return this->values[ this->allocatedSize ]; return *valuesCount;
} }
template< typename Index, template< typename Index,
...@@ -195,6 +202,16 @@ operator==( const ThisType& other ) const ...@@ -195,6 +202,16 @@ operator==( const ThisType& other ) const
return true; return true;
} }
template< typename Index,
typename Device,
typename LocalIndex >
bool
EllpackIndexMultimapValues< Index, Device, LocalIndex >::
operator!=( const ThisType& other ) const
{
return ! ( *this == other );
}
template< typename Index, template< typename Index,
typename Device, typename Device,
typename LocalIndex > typename LocalIndex >
......
...@@ -79,11 +79,11 @@ allocate( const LocalIndexType& maxValuesCount ) ...@@ -79,11 +79,11 @@ allocate( const LocalIndexType& maxValuesCount )
{ {
Assert( maxValuesCount >= 0, ); Assert( maxValuesCount >= 0, );
this->maxValuesCount = maxValuesCount; this->maxValuesCount = maxValuesCount;
if( ! this->values.setSize( this->keysRange * ( this->maxValuesCount + 1 ) ) ) if( ! this->values.setSize( this->keysRange * this->maxValuesCount ) )
return false; return false;
// TODO: maybe the local sizes should be stored differently? if( ! this->valuesCounts.setSize( this->keysRange ) )
for( IndexType i = 0; i < this->keysRange; i++ ) return false;
this->getValues( i ).setSize( maxValuesCount ); this->valuesCounts.setValue( maxValuesCount );
return true; return true;
} }
...@@ -101,11 +101,11 @@ allocate( const ValuesAllocationVectorType& valuesCounts ) ...@@ -101,11 +101,11 @@ allocate( const ValuesAllocationVectorType& valuesCounts )
Assert( this->maxValuesCount >= 0, Assert( this->maxValuesCount >= 0,
std::cerr << "this->maxValuesCount = " << this->maxValuesCount << std::endl; ); std::cerr << "this->maxValuesCount = " << this->maxValuesCount << std::endl; );
if( ! this->values.setSize( this->keysRange * ( this->maxValuesCount + 1 ) ) ) if( ! this->values.setSize( this->keysRange * this->maxValuesCount ) )
return false; return false;
// TODO: maybe the local sizes should be stored differently? if( ! this->valuesCounts.setSize( this->keysRange ) )
for( IndexType i = 0; i < this->keysRange; i++ ) return false;
this->getValues( i ).setSize( valuesCounts[ i ] ); this->valuesCounts = valuesCounts;
return true; return true;
} }
...@@ -116,7 +116,7 @@ typename EllpackIndexMultimap< Index, Device, LocalIndex >::ValuesAccessorType ...@@ -116,7 +116,7 @@ typename EllpackIndexMultimap< Index, Device, LocalIndex >::ValuesAccessorType
EllpackIndexMultimap< Index, Device, LocalIndex >:: EllpackIndexMultimap< Index, Device, LocalIndex >::
getValues( const IndexType& inputIndex ) getValues( const IndexType& inputIndex )
{ {
return ValuesAccessorType( this->values.getData(), inputIndex, this->maxValuesCount ); return ValuesAccessorType( this->values.getData(), this->valuesCounts.getData(), inputIndex, this->maxValuesCount );
} }
template< typename Index, template< typename Index,
...@@ -126,7 +126,7 @@ typename EllpackIndexMultimap< Index, Device, LocalIndex >::ConstValuesAccessorT ...@@ -126,7 +126,7 @@ typename EllpackIndexMultimap< Index, Device, LocalIndex >::ConstValuesAccessorT
EllpackIndexMultimap< Index, Device, LocalIndex >:: EllpackIndexMultimap< Index, Device, LocalIndex >::
getValues( const IndexType& inputIndex ) const getValues( const IndexType& inputIndex ) const
{ {
return ConstValuesAccessorType( this->values.getData(), inputIndex, this->maxValuesCount ); return ConstValuesAccessorType( this->values.getData(), this->valuesCounts.getData(), inputIndex, this->maxValuesCount );
} }
template< typename Index, template< typename Index,
...@@ -136,9 +136,15 @@ bool ...@@ -136,9 +136,15 @@ bool
EllpackIndexMultimap< Index, Device, LocalIndex >:: EllpackIndexMultimap< Index, Device, LocalIndex >::
operator==( const EllpackIndexMultimap< Index, Device, LocalIndex >& other ) const operator==( const EllpackIndexMultimap< Index, Device, LocalIndex >& other ) const
{ {
return ( this->keysRange == other.keysRange && if( ! ( this->keysRange == other.keysRange &&
this->maxValuesCount == other.maxValuesCount && this->maxValuesCount == other.maxValuesCount &&
this->values == other.values ); this->valuesCounts == other.valuesCounts ) )
return false;
// compare values for each key separately - the sizes may vary
for( IndexType i = 0; i < this->keysRange; i++ )
if( this->getValues( i ) != other.getValues( i ) )
return false;
return true;
} }
template< typename Index, template< typename Index,
...@@ -156,6 +162,8 @@ save( File& file ) const ...@@ -156,6 +162,8 @@ save( File& file ) const
return false; return false;
if( ! this->values.save( file ) ) if( ! this->values.save( file ) )
return false; return false;
if( ! this->valuesCounts.save( file ) )
return false;
return true; return true;
} }
...@@ -174,6 +182,8 @@ load( File& file ) ...@@ -174,6 +182,8 @@ load( File& file )
return false; return false;
if( ! this->values.load( file ) ) if( ! this->values.load( file ) )
return false; return false;
if( ! this->valuesCounts.load( file ) )
return false;
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment