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

Fixed issues reported in compiler warnings

- base class with non-virtual destructor causes undefined behaviour
- missing return statements at the end of non-void functions
- missing const before char* function argument
- reordered initialization of class members
- misleading indentation after for statement
- fixed use of uninitialized variables
- fixed unsequenced modification and access to variables (the C++
  standard does not define the evaluation order of operands, so
  expressions with side-effects such as j++ cause undefined behaviour)
parent 06c2b3e5
No related branches found
No related tags found
No related merge requests found
Showing
with 48 additions and 35 deletions
......@@ -41,7 +41,9 @@ struct ConfigEntryBase
virtual bool hasEnumValues() const { return false; };
virtual void printEnumValues() const{};
virtual void printEnumValues() const {};
virtual ~ConfigEntryBase() {};
};
} // namespace Config
......
......@@ -230,7 +230,10 @@ bool ArrayOperations< Devices::Host, Devices::Cuda >::copyMemory( DestinationEle
}
Index j( 0 );
while( j < Devices::Cuda::getGPUTransferBufferSize() && i + j < size )
destination[ i + j ] = buffer[ j++ ];
{
destination[ i + j ] = buffer[ j ];
j++;
}
i += j;
}
delete[] buffer;
......@@ -332,7 +335,10 @@ bool ArrayOperations< Devices::Cuda, Devices::Host >::copyMemory( DestinationEle
{
Index j( 0 );
while( j < Devices::Cuda::getGPUTransferBufferSize() && i + j < size )
buffer[ j ] = source[ i + j++ ];
{
buffer[ j ] = source[ i + j ];
j++;
}
if( cudaMemcpy( &destination[ i ],
buffer,
j * sizeof( DestinationElement ),
......
......@@ -69,6 +69,7 @@ readHeader()
this->components = this->decinfo.num_components;
//this->color_space = this->cinfo.jpeg_color_space;
//cout << this->height << " x " << this->width << " : " << this->components << " " << this->color_space << std::endl;
return true;
#else
std::cerr << "TNL was not compiled with support of JPEG. You may still use PGM format." << std::endl;
return false;
......@@ -192,6 +193,7 @@ writeHeader( const Meshes::Grid< 2, Real, Device, Index >& grid )
this->cinfo.in_color_space = JCS_GRAYSCALE;
jpeg_set_defaults( &this->cinfo );
jpeg_start_compress( &this->cinfo, true );
return true;
#else
//cerr << "TNL was not compiled with support of JPEG. You may still use PGM format." << std::endl;
return false;
......
......@@ -265,7 +265,7 @@ writeHeader( const Meshes::Grid< 2, Real, Device, Index >& grid )
PNG_FILTER_TYPE_DEFAULT );
png_init_io( this->png_ptr, this->file );
png_write_info( png_ptr, info_ptr );
return true;
#else
std::cerr << "TNL was not compiled with support of PNG. You may still use PGM format." << std::endl;
return false;
......
......@@ -222,7 +222,7 @@ bool CSR< Real, Device, Index >::addElement( const IndexType row,
IndexType elementPtr = this->rowPointers.getElement( row );
const IndexType rowEnd = this->rowPointers.getElement( row + 1 );
IndexType col;
IndexType col = 0;
while( elementPtr < rowEnd &&
( col = this->columnIndexes.getElement( elementPtr ) ) < column &&
col != this->getPaddingIndex() ) elementPtr++;
......
......@@ -435,7 +435,7 @@ bool ChunkedEllpack< Real, Device, Index >::addElementToChunkFast( const IndexTy
elementPtr,
chunkEnd,
step );
IndexType col;
IndexType col = 0;
while( elementPtr < chunkEnd &&
( col = this->columnIndexes[ elementPtr ] ) < column &&
col != this->getPaddingIndex() )
......@@ -532,7 +532,7 @@ bool ChunkedEllpack< Real, Device, Index >::addElementToChunk( const IndexType s
elementPtr,
chunkEnd,
step );
IndexType col;
IndexType col = 0;
while( elementPtr < chunkEnd &&
( col = this->columnIndexes.getElement( elementPtr ) ) < column &&
col != this->getPaddingIndex() )
......@@ -1044,7 +1044,7 @@ typename Vector::RealType ChunkedEllpack< Real, Device, Index >::chunkVectorProd
elementPtr,
chunkEnd,
step );
IndexType i( 0 ), col;
IndexType i( 0 ), col( 0 );
typename Vector::RealType result( 0.0 );
while( i < chunkSize && ( col = this->columnIndexes[ elementPtr ] ) != this->getPaddingIndex() )
{
......
......@@ -158,7 +158,7 @@ template< typename Real,
typename Index >
Index Multidiagonal< Real, Device, Index > :: getNumberOfNonzeroMatrixElements() const
{
IndexType nonzeroElements;
IndexType nonzeroElements = 0;
for( IndexType i = 0; i < this->values.getSize(); i++ )
if( this->values.getElement( i ) != 0 )
nonzeroElements++;
......
......@@ -193,7 +193,7 @@ bool SlicedEllpack< Real, Device, Index, SliceSize >::addElementFast( const Inde
Index elementPtr, rowEnd, step;
DeviceDependentCode::initRowTraverseFast( *this, row, elementPtr, rowEnd, step );
IndexType col;
IndexType col = 0;
while( elementPtr < rowEnd &&
( col = this->columnIndexes[ elementPtr ] ) < column &&
col != this->getPaddingIndex() ) elementPtr += step;
......@@ -241,7 +241,7 @@ bool SlicedEllpack< Real, Device, Index, SliceSize >::addElement( const IndexTyp
Index elementPtr, rowEnd, step;
DeviceDependentCode::initRowTraverse( *this, row, elementPtr, rowEnd, step );
IndexType col;
IndexType col = 0;
while( elementPtr < rowEnd &&
( col = this->columnIndexes.getElement( elementPtr ) ) < column &&
col != this->getPaddingIndex() ) elementPtr += step;
......@@ -379,7 +379,7 @@ Real SlicedEllpack< Real, Device, Index, SliceSize >::getElementFast( const Inde
Index elementPtr, rowEnd, step;
DeviceDependentCode::initRowTraverseFast( *this, row, elementPtr, rowEnd, step );
IndexType col;
IndexType col = 0;
while( elementPtr < rowEnd &&
( col = this->columnIndexes[ elementPtr ] ) < column &&
col != this->getPaddingIndex() )
......@@ -400,7 +400,7 @@ Real SlicedEllpack< Real, Device, Index, SliceSize >::getElement( const IndexTyp
Index elementPtr, rowEnd, step;
DeviceDependentCode::initRowTraverse( *this, row, elementPtr, rowEnd, step );
IndexType col;
IndexType col = 0;
while( elementPtr < rowEnd &&
( col = this->columnIndexes.getElement( elementPtr ) ) < column &&
col != this->getPaddingIndex() )
......
......@@ -129,7 +129,7 @@ template< typename Real,
typename Index >
Index Tridiagonal< Real, Device, Index > :: getNumberOfNonzeroMatrixElements() const
{
IndexType nonzeroElements;
IndexType nonzeroElements = 0;
for( IndexType i = 0; i < this->values.getSize(); i++ )
if( this->values.getElement( i ) != 0 )
nonzeroElements++;
......@@ -631,13 +631,13 @@ class TridiagonalDeviceDependentCode< Devices::Host >
if( row == 0 )
return vector[ 0 ] * values[ 0 ] +
vector[ 1 ] * values[ 1 ];
Index i = 3 * row - 1;
Index i = 3 * row;
if( row == rows - 1 )
return vector[ row - 1 ] * values[ i++ ] +
return vector[ row - 1 ] * values[ i - 1 ] +
vector[ row ] * values[ i ];
return vector[ row - 1 ] * values[ i++ ] +
vector[ row ] * values[ i++ ] +
vector[ row + 1 ] * values[ i ];
return vector[ row - 1 ] * values[ i - 1 ] +
vector[ row ] * values[ i ] +
vector[ row + 1 ] * values[ i + 1 ];
}
template< typename Real,
......
......@@ -34,7 +34,7 @@ class GridEntityMeasureGetter< Meshes::Grid< Dimensions, Real, Device, Index >,
template< typename EntityType >
__cuda_callable__ inline
static const Real& getMeasure( const GridType& grid,
static const Real getMeasure( const GridType& grid,
const EntityType& entity )
{
return 0.0;
......
......@@ -105,7 +105,7 @@ class MeshBuilder
for( GlobalIndexType i = 0; i < this->points.getSize(); i++ )
if (! this->pointsSet[ i ] )
return false;
return true;
return true;
}
PointArrayType points;
......
......@@ -35,7 +35,7 @@ class MeshEntityReferenceOrientation
}
}
static String getType(){};
static String getType(){ return "MeshEntityReferenceOrientation"; };
EntityOrientation createOrientation( const SeedType& seed ) const
{
......
......@@ -72,8 +72,7 @@ class MeshWriterVTKLegacy
outputFile << std::setprecision( 6 );
outputFile << std::fixed;
if( ! writeMesh( outputFile, mesh, verbose ) )
return false;
return writeMesh( outputFile, mesh, verbose );
}
template< typename MeshType >
......
......@@ -74,7 +74,7 @@ class MeshEntityInitializer
//using SuperentityBaseType::setNumberOfSuperentities;
static String getType() {};
static String getType() { return "MeshEntityInitializer"; };
MeshEntityInitializer() : entity(0), entityIndex( -1 ) {}
......@@ -111,7 +111,7 @@ class MeshEntityInitializer< MeshConfig, MeshVertexTopology >
typedef typename MeshTraits< MeshConfig >::PointType PointType;
typedef MeshInitializer< MeshConfig > InitializerType;
static String getType() {};
static String getType() { return "MeshEntityInitializer"; };
static void setVertexPoint( VertexType& vertex,
const PointType& point,
......
......@@ -337,6 +337,7 @@ class MeshInitializerLayer< MeshConfig,
using BaseType::findEntitySeedIndex;
GlobalIndexType findEntitySeedIndex( const SeedType& seed ) const
{
// FIXME: index may be uninitialized (when seedsIndexedSet.find returns false)
GlobalIndexType index;
this->seedsIndexedSet.find( seed, index );
return index;
......
......@@ -18,9 +18,9 @@ template< typename Problem >
ExplicitSolver< Problem >::
ExplicitSolver()
: time( 0.0 ),
stopTime( 0.0 ),
tau( 0.0 ),
maxTau( DBL_MAX ),
stopTime( 0.0 ),
solver_comm( MPI_COMM_WORLD ),
verbosity( 0 ),
timer( &defaultTimer ),
......
......@@ -27,6 +27,8 @@ class ExplicitUpdaterTraverserUserData
{
public:
const Real time;
const DifferentialOperator* differentialOperator;
const BoundaryConditions* boundaryConditions;
......@@ -35,8 +37,6 @@ class ExplicitUpdaterTraverserUserData
MeshFunction *u, *fu;
const Real time;
ExplicitUpdaterTraverserUserData( const Real& time,
const DifferentialOperator* differentialOperator,
const BoundaryConditions* boundaryConditions,
......
......@@ -142,7 +142,7 @@ bool Timer::writeLog( Logger& logger, int logLevel )
logger.writeParameter< double >( "Real time:", this->getRealTime(), logLevel );
logger.writeParameter< double >( "CPU time:", this->getCPUTime(), logLevel );
logger.writeParameter< unsigned long long int >( "CPU Cycles:", this->getCPUCycles(), logLevel );
return true;
}
} // namespace TNL
......@@ -210,7 +210,7 @@ __global__ void updateKernel( Real* u,
template< typename Real, typename Index >
bool writeFunction(
char* fileName,
const char* fileName,
const Real* data,
const Index xSize,
const Index ySize,
......@@ -232,6 +232,7 @@ bool writeFunction(
file << i * hx - originX << " " << j * hy - originY << " " << data[ j * xSize + i ] << endl;
file << endl;
}
return true;
}
template< typename Real, typename Index >
......
......@@ -173,11 +173,13 @@ benchmarkSpmvSynthetic( Benchmark & benchmark,
const int & size,
const int & elementsPerRow )
{
bool result = true;
// TODO: benchmark all formats from tnl-benchmark-spmv (different parameters of the base formats)
benchmarkSpMV< Real, Matrices::CSR >( benchmark, loops, size, elementsPerRow );
benchmarkSpMV< Real, Matrices::Ellpack >( benchmark, loops, size, elementsPerRow );
benchmarkSpMV< Real, SlicedEllpack >( benchmark, loops, size, elementsPerRow );
benchmarkSpMV< Real, Matrices::ChunkedEllpack >( benchmark, loops, size, elementsPerRow );
result |= benchmarkSpMV< Real, Matrices::CSR >( benchmark, loops, size, elementsPerRow );
result |= benchmarkSpMV< Real, Matrices::Ellpack >( benchmark, loops, size, elementsPerRow );
result |= benchmarkSpMV< Real, SlicedEllpack >( benchmark, loops, size, elementsPerRow );
result |= benchmarkSpMV< Real, Matrices::ChunkedEllpack >( benchmark, loops, size, elementsPerRow );
return result;
}
} // namespace benchmarks
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment