From 6221b196d399e138b7c80ec4853884821af2a3bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 13:51:05 +0200 Subject: [PATCH 01/30] Fixed methods save/load in Mesh --- .../DistributedMeshes/DistributedGridIO.h | 14 ++---- src/TNL/Meshes/DummyMesh.h | 10 ++-- src/TNL/Meshes/MeshDetails/MeshEntity_impl.h | 18 +++---- .../MeshLayers/BoundaryTags/Layer.h | 37 +++----------- .../MeshLayers/BoundaryTags/LayerFamily.h | 23 +++------ .../MeshDetails/MeshLayers/StorageLayer.h | 49 +++++-------------- .../MeshLayers/SubentityStorageLayer.h | 41 +++------------- .../MeshLayers/SuperentityStorageLayer.h | 41 +++------------- src/TNL/Meshes/MeshEntity.h | 8 +-- 9 files changed, 62 insertions(+), 179 deletions(-) diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGridIO.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO.h index 49d7467e1..38a7c04f0 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGridIO.h +++ b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO.h @@ -40,21 +40,17 @@ class DistributedGridIO< MeshFunctionType, Dummy > bool save(const String& fileName, MeshFunctionType &meshFunction) { return true; - }; + } bool load(const String& fileName, MeshFunctionType &meshFunction) { return true; - }; + } }; - - - - -} -} -} +} // namespace DistributedMeshes +} // namespace Meshes +} // namespace TNL //not clean logic of includes... #include diff --git a/src/TNL/Meshes/DummyMesh.h b/src/TNL/Meshes/DummyMesh.h index 4bff7ce17..96cd7e3a4 100644 --- a/src/TNL/Meshes/DummyMesh.h +++ b/src/TNL/Meshes/DummyMesh.h @@ -11,6 +11,7 @@ #pragma once #include +#include #include namespace TNL { @@ -42,14 +43,13 @@ public: const GridFunction& f2, const typename GridFunction::RealType& p ) const { return 0.0; } - bool save( File& file ) const { return true; } + void save( File& file ) const {} - //! Method for restoring the object from a file - bool load( File& file ) { return true; } + void load( File& file ) {} - bool save( const String& fileName ) const { return true; } + void save( const String& fileName ) const {} - bool load( const String& fileName ) { return true; } + void load( const String& fileName ) {} bool writeMesh( const String& fileName, const String& format ) const { return true; } diff --git a/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h b/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h index 8a21168de..8bdd40570 100644 --- a/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h +++ b/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h @@ -100,23 +100,21 @@ getTypeVirtual() const template< typename MeshConfig, typename Device, typename EntityTopology > -bool +void MeshEntity< MeshConfig, Device, EntityTopology >:: save( File& file ) const { // no I/O for subentities and superentities - not loaded anyway - return true; } template< typename MeshConfig, typename Device, typename EntityTopology > -bool +void MeshEntity< MeshConfig, Device, EntityTopology >:: load( File& file ) { // no I/O for subentities and superentities - Mesh::load has to rebind pointers - return true; } template< typename MeshConfig, @@ -258,25 +256,21 @@ getTypeVirtual() const } template< typename MeshConfig, typename Device > -bool +void MeshEntity< MeshConfig, Device, Topologies::Vertex >:: save( File& file ) const { // no I/O for superentities - not loaded anyway - if( ! point.save( file ) ) - return false; - return true; + point.save( file ); } template< typename MeshConfig, typename Device > -bool +void MeshEntity< MeshConfig, Device, Topologies::Vertex >:: load( File& file ) { // no I/O for superentities - Mesh::load has to rebind pointers - if( ! point.load( file ) ) - return false; - return true; + point.load( file ); } template< typename MeshConfig, typename Device > diff --git a/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h b/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h index 99a0e6126..ebbee9fdd 100644 --- a/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h +++ b/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h @@ -168,33 +168,15 @@ public: return interiorIndices[ i ]; } - bool save( File& file ) const + void save( File& file ) const { - try - { - boundaryTags.save( file ); - } - catch(...) - { - std::cerr << "Failed to save the boundary tags of the entities with dimension " << DimensionTag::value << "." << std::endl; - return false; - } - return true; + boundaryTags.save( file ); } - bool load( File& file ) + void load( File& file ) { - try - { - boundaryTags.load( file ); - } - catch(...) - { - std::cerr << "Failed to load the boundary tags of the entities with dimension " << DimensionTag::value << "." << std::endl; - return false; - } + boundaryTags.load( file ); updateBoundaryIndices( DimensionTag() ); - return true; } void print( std::ostream& str ) const @@ -257,16 +239,9 @@ protected: void getInteriorEntitiesCount( DimensionTag ) const {} void getInteriorEntityIndex( DimensionTag, const GlobalIndexType& i ) const {} - bool save( File& file ) const - { - return true; - } + void save( File& file ) const {} + void load( File& file ) {} - bool load( File& file ) - { - return true; - } - void print( std::ostream& str ) const {} bool operator==( const Layer& layer ) const diff --git a/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/LayerFamily.h b/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/LayerFamily.h index 44f6cdc44..d78ba1c52 100644 --- a/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/LayerFamily.h +++ b/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/LayerFamily.h @@ -77,16 +77,16 @@ protected: } - bool save( File& file ) const + void save( File& file ) const { - return LayerType::save( file ) && - BaseType::save( file ); + LayerType::save( file ); + BaseType::save( file ); } - bool load( File& file ) + void load( File& file ) { - return LayerType::load( file ) && - BaseType::load( file ); + LayerType::load( file ); + BaseType::load( file ); } void print( std::ostream& str ) const @@ -124,16 +124,9 @@ protected: template< typename Device_ > LayerInheritor& operator=( const LayerInheritor< MeshConfig, Device_, DimensionTag< MeshConfig::meshDimension + 1 > >& other ) { return *this; } - bool save( File& file ) const - { - return true; - } + void save( File& file ) const {} + void load( File& file ) {} - bool load( File& file ) - { - return true; - } - void print( std::ostream& str ) const {} bool operator==( const LayerInheritor& layer ) const diff --git a/src/TNL/Meshes/MeshDetails/MeshLayers/StorageLayer.h b/src/TNL/Meshes/MeshDetails/MeshLayers/StorageLayer.h index a9d25d843..618934ce5 100644 --- a/src/TNL/Meshes/MeshDetails/MeshLayers/StorageLayer.h +++ b/src/TNL/Meshes/MeshDetails/MeshLayers/StorageLayer.h @@ -139,38 +139,20 @@ public: return *this; } - bool save( File& file ) const + void save( File& file ) const { - try - { - SubentityStorageBaseType::save( file ); - SuperentityStorageBaseType::save( file ); - this->entities.save( file ); - BaseType::save( file ); - } - catch(...) - { - std::cerr << "Saving of the mesh entities with dimension " << DimensionTag::value << " failed." << std::endl; - return false; - } - return true; + SubentityStorageBaseType::save( file ); + SuperentityStorageBaseType::save( file ); + this->entities.save( file ); + BaseType::save( file ); } - bool load( File& file ) + void load( File& file ) { - try - { - SubentityStorageBaseType::load( file ); - SuperentityStorageBaseType::load( file ); - this->entities.load( file ); - BaseType::load( file ); - } - catch(...) - { - std::cerr << "Loading of the mesh entities with dimension " << DimensionTag::value << " failed." << std::endl; - return false; - } - return true; + SubentityStorageBaseType::load( file ); + SuperentityStorageBaseType::load( file ); + this->entities.load( file ); + BaseType::load( file ); } void print( std::ostream& str ) const @@ -276,15 +258,8 @@ protected: void getEntitiesCount() const {} void getEntity() const {} - bool save( File& file ) const - { - return true; - } - - bool load( File& file ) - { - return true; - } + void save( File& file ) const {} + void load( File& file ) {} void print( std::ostream& str ) const {} diff --git a/src/TNL/Meshes/MeshDetails/MeshLayers/SubentityStorageLayer.h b/src/TNL/Meshes/MeshDetails/MeshLayers/SubentityStorageLayer.h index cd4d9edf0..a598289e5 100644 --- a/src/TNL/Meshes/MeshDetails/MeshLayers/SubentityStorageLayer.h +++ b/src/TNL/Meshes/MeshDetails/MeshLayers/SubentityStorageLayer.h @@ -105,34 +105,16 @@ protected: } - bool save( File& file ) const + void save( File& file ) const { - try - { - BaseType::save( file ); - this->storageNetwork.save( file ); - } - catch(...) - { - std::cerr << "Saving of the entity subentities layer with " << SubdimensionTag::value << " dimension failed." << std::endl; - return false; - } - return true; + BaseType::save( file ); + this->storageNetwork.save( file ); } - bool load( File& file ) + void load( File& file ) { - try - { - BaseType::load( file ); - this->storageNetwork.load( file ); - } - catch(...) - { - std::cerr << "Loading of the entity subentities layer with " << SubdimensionTag::value << " dimension failed." << std::endl; - return false; - } - return true; + BaseType::load( file ); + this->storageNetwork.load( file ); } void print( std::ostream& str ) const @@ -219,16 +201,9 @@ protected: return true; } - bool save( File& file ) const - { - return true; - } + void save( File& file ) const {} + void load( File& file ) {} - bool load( File& file ) - { - return true; - } - void getSubentityStorageNetwork( SubdimensionTag ) {} }; diff --git a/src/TNL/Meshes/MeshDetails/MeshLayers/SuperentityStorageLayer.h b/src/TNL/Meshes/MeshDetails/MeshLayers/SuperentityStorageLayer.h index 7e49a3155..9cc1c5535 100644 --- a/src/TNL/Meshes/MeshDetails/MeshLayers/SuperentityStorageLayer.h +++ b/src/TNL/Meshes/MeshDetails/MeshLayers/SuperentityStorageLayer.h @@ -107,34 +107,16 @@ protected: } - bool save( File& file ) const + void save( File& file ) const { - try - { - BaseType::save( file ); - this->storageNetwork.save( file ); - } - catch(...) - { - std::cerr << "Saving of the entity superentities layer with " << SuperdimensionTag::value << " dimension failed." << std::endl; - return false; - } - return true; + BaseType::save( file ); + this->storageNetwork.save( file ); } - bool load( File& file ) + void load( File& file ) { - try - { - BaseType::load( file ); - this->storageNetwork.load( file ); - } - catch(...) - { - std::cerr << "Loading of the entity superentities layer with " << SuperdimensionTag::value << " dimension failed." << std::endl; - return false; - } - return true; + BaseType::load( file ); + this->storageNetwork.load( file ); } void print( std::ostream& str ) const @@ -212,16 +194,9 @@ protected: return true; } - bool save( File& file ) const - { - return true; - } + void save( File& file ) const {} + void load( File& file ) {} - bool load( File& file ) - { - return true; - } - void getSuperentityStorageNetwork( SuperdimensionTag ) {} }; diff --git a/src/TNL/Meshes/MeshEntity.h b/src/TNL/Meshes/MeshEntity.h index 7c9768680..6e0970ade 100644 --- a/src/TNL/Meshes/MeshEntity.h +++ b/src/TNL/Meshes/MeshEntity.h @@ -76,9 +76,9 @@ class MeshEntity String getTypeVirtual() const; - bool save( File& file ) const; + void save( File& file ) const; - bool load( File& file ); + void load( File& file ); void print( std::ostream& str ) const; @@ -170,9 +170,9 @@ class MeshEntity< MeshConfig, Device, Topologies::Vertex > String getTypeVirtual() const; - bool save( File& file ) const; + void save( File& file ) const; - bool load( File& file ); + void load( File& file ); void print( std::ostream& str ) const; -- GitLab From 296bf503616e608890d4f49ad27c69beb20ce2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 14:51:54 +0200 Subject: [PATCH 02/30] Improved ArrayViewTest --- src/UnitTests/Containers/ArrayViewTest.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/UnitTests/Containers/ArrayViewTest.h b/src/UnitTests/Containers/ArrayViewTest.h index 061a2f5ef..ac86cc354 100644 --- a/src/UnitTests/Containers/ArrayViewTest.h +++ b/src/UnitTests/Containers/ArrayViewTest.h @@ -171,10 +171,13 @@ TYPED_TEST( ArrayViewTest, constructors ) // test initialization by const reference const ArrayType& b = a; ConstViewType b_view = b.getConstView(); + EXPECT_EQ( b_view.getData(), b.getData() ); ConstViewType const_a_view = a.getConstView(); + EXPECT_EQ( const_a_view.getData(), a.getData() ); // test initialization of const view by non-const view ConstViewType const_b_view( b_view ); + EXPECT_EQ( const_b_view.getData(), b_view.getData() ); } TYPED_TEST( ArrayViewTest, bind ) -- GitLab From 5b6e8c9cd05ccdee4671b8777d9db651d84acd82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 14:51:32 +0200 Subject: [PATCH 03/30] Marked binding constructors and methods in Array as deprecated --- src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h | 5 ++--- src/TNL/Containers/Array.h | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h b/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h index 62e371172..b297854ea 100644 --- a/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h +++ b/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h @@ -266,9 +266,8 @@ struct SpmvBenchmark distributedMatrix.vectorProduct( distributedVector, distributedY ); const int rank = CommunicatorType::GetRank( distributedMatrix.getCommunicationGroup() ); const int nproc = CommunicatorType::GetSize( distributedMatrix.getCommunicationGroup() ); - VectorType subY( y, - Partitioner::getOffset( matrix.getRows(), rank, nproc ), - Partitioner::getSizeForRank( matrix.getRows(), rank, nproc ) ); + typename VectorType::ViewType subY( &y[ Partitioner::getOffset( matrix.getRows(), rank, nproc ) ], + Partitioner::getSizeForRank( matrix.getRows(), rank, nproc ) ); TNL_ASSERT_EQ( distributedY.getLocalVectorView(), subY, "WRONG RESULT !!!" ); #endif } diff --git a/src/TNL/Containers/Array.h b/src/TNL/Containers/Array.h index fd6a1ac4e..96545ab32 100644 --- a/src/TNL/Containers/Array.h +++ b/src/TNL/Containers/Array.h @@ -98,6 +98,7 @@ class Array : public Object * \param data Pointer to data. * \param size Number of array elements. */ + [[deprecated("Binding functionality of Array is deprecated, ArrayView should be used instead.")]] Array( Value* data, const IndexType& size ); @@ -118,6 +119,7 @@ class Array : public Object * \param begin is the first index which should be bound. * \param size is number of array elements that should be bound. */ + [[deprecated("Binding functionality of Array is deprecated, ArrayView should be used instead.")]] Array( Array& array, const IndexType& begin = 0, const IndexType& size = 0 ); @@ -223,6 +225,7 @@ class Array : public Object * \param _data Pointer to new data. * \param _size Size of new _data. Number of elements. */ + [[deprecated("Binding functionality of Array is deprecated, ArrayView should be used instead.")]] void bind( Value* _data, const Index _size ); @@ -240,6 +243,7 @@ class Array : public Object * \param size Size of new array. Number of elements. */ template< typename ArrayT > + [[deprecated("Binding functionality of Array is deprecated, ArrayView should be used instead.")]] void bind( const ArrayT& array, const IndexType& begin = 0, const IndexType& size = 0 ); @@ -256,6 +260,7 @@ class Array : public Object * \param array Reference to a static array. */ template< int Size > + [[deprecated("Binding functionality of Array is deprecated, ArrayView should be used instead.")]] void bind( StaticArray< Size, Value >& array ); /** -- GitLab From d8cdf0318bd33e8953294968d8ed704f008bbc12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 15:46:01 +0200 Subject: [PATCH 04/30] Removed binding stuff from ArrayTest, other improvements --- src/UnitTests/Containers/ArrayTest.h | 145 ++--------------------- src/UnitTests/Containers/ArrayViewTest.h | 20 ++-- 2 files changed, 18 insertions(+), 147 deletions(-) diff --git a/src/UnitTests/Containers/ArrayTest.h b/src/UnitTests/Containers/ArrayTest.h index 3790b35dc..573c79f36 100644 --- a/src/UnitTests/Containers/ArrayTest.h +++ b/src/UnitTests/Containers/ArrayTest.h @@ -152,25 +152,9 @@ TYPED_TEST( ArrayTest, constructors ) ArrayType v( 10 ); EXPECT_EQ( v.getSize(), 10 ); - if( std::is_same< typename ArrayType::DeviceType, Devices::Host >::value ) { - typename ArrayType::ValueType data[ 10 ]; - ArrayType w( data, 10 ); - EXPECT_EQ( w.getData(), data ); - - ArrayType z1( w ); - //EXPECT_EQ( z1.getData(), data ); - EXPECT_EQ( z1.getSize(), 10 ); - - ArrayType z2( w, 1 ); - EXPECT_EQ( z2.getData(), data + 1 ); - EXPECT_EQ( z2.getSize(), 9 ); - - ArrayType z3( w, 2, 3 ); - EXPECT_EQ( z3.getData(), data + 2 ); - EXPECT_EQ( z3.getSize(), 3 ); - } - + // deep copy ArrayType w( v ); + EXPECT_NE( w.getData(), v.getData() ); EXPECT_EQ( w.getSize(), v.getSize() ); for( int i = 0; i < 10; i++ ) EXPECT_EQ( v.getElement( i ), w.getElement( i ) ); @@ -206,15 +190,6 @@ TYPED_TEST( ArrayTest, setSize ) u.setSize( i ); EXPECT_EQ( u.getSize(), i ); } - - ArrayType v( u ); - EXPECT_EQ( v.getSize(), 10 ); - //EXPECT_EQ( v.getData(), u.getData() ); - v.setSize( 11 ); - EXPECT_EQ( u.getSize(), 10 ); - EXPECT_EQ( v.getSize(), 11 ); - EXPECT_NE( v.getData(), u.getData() ); - } TYPED_TEST( ArrayTest, empty ) @@ -240,45 +215,6 @@ TYPED_TEST( ArrayTest, setLike ) EXPECT_NE( v.getData(), u.getData() ); } -TYPED_TEST( ArrayTest, bind ) -{ - using ArrayType = typename TestFixture::ArrayType; - - ArrayType u( 10 ), v; - v.bind( u ); - EXPECT_EQ( v.getSize(), u.getSize() ); - EXPECT_EQ( v.getData(), u.getData() ); - - // bind array with offset and size - ArrayType w; - w.bind( u, 2, 3 ); - EXPECT_EQ( w.getSize(), 3 ); - EXPECT_EQ( w.getData(), u.getData() + 2 ); - - // setting values - u.setValue( 27 ); - EXPECT_EQ( u.getElement( 0 ), 27 ); - v.setValue( 50 ); - EXPECT_EQ( u.getElement( 0 ), 50 ); - u.reset(); - EXPECT_EQ( u.getSize(), 0 ); - EXPECT_EQ( v.getElement( 0 ), 50 ); - - if( std::is_same< typename ArrayType::DeviceType, Devices::Host >::value ) { - typename ArrayType::ValueType data[ 10 ] = { 1, 2, 3, 4, 5, 6, 7, 8, 10 }; - u.bind( data, 10 ); - EXPECT_EQ( u.getData(), data ); - EXPECT_EQ( u.getSize(), 10 ); - EXPECT_EQ( u.getElement( 1 ), 2 ); - v.bind( u ); - EXPECT_EQ( v.getElement( 1 ), 2 ); - u.reset(); - v.setElement( 1, 3 ); - v.reset(); - EXPECT_EQ( data[ 1 ], 3 ); - } -} - TYPED_TEST( ArrayTest, swap ) { using ArrayType = typename TestFixture::ArrayType; @@ -470,9 +406,9 @@ TYPED_TEST( ArrayTest, assignmentOperator ) u_host.setElement( i, i ); } - v = 72; //.setValue( 0 ); + v = 42; for( int i = 0; i < 10; i++ ) - EXPECT_EQ( v.getElement( i ), 72 ); + EXPECT_EQ( v.getElement( i ), 42 ); v = u; EXPECT_EQ( u, v ); @@ -557,7 +493,7 @@ TYPED_TEST( ArrayTest, boundLoad ) { using ArrayType = typename TestFixture::ArrayType; - ArrayType u, v, w; + ArrayType v, w; v.setSize( 100 ); for( int i = 0; i < 100; i ++ ) v.setElement( i, 3.14147 ); @@ -567,82 +503,23 @@ TYPED_TEST( ArrayTest, boundLoad ) file.close(); w.setSize( 100 ); - u.bind( w ); + auto u = w.getView(); file.open( "test-file.tnl", File::Mode::In ); - u.boundLoad( file ); + u.load( file ); EXPECT_EQ( u, v ); EXPECT_EQ( u.getData(), w.getData() ); - u.setSize( 50 ); + ArrayType z( 50 ); file.open( "test-file.tnl", File::Mode::In ); - bool catched( false ); - try - { - u.boundLoad( file ); - } - catch(...) - { - catched = true; - } - EXPECT_TRUE( catched ); + EXPECT_ANY_THROW( z.boundLoad( file ) ); - u.reset(); + v.reset(); file.open( "test-file.tnl", File::Mode::In ); - u.boundLoad( file ); + EXPECT_NO_THROW( v.boundLoad( file ) ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); } -TYPED_TEST( ArrayTest, referenceCountingConstructors ) -{ - using ArrayType = typename TestFixture::ArrayType; - - // copies of a dynamic array - ArrayType u( 10 ); - ArrayType v( u ); - ArrayType w( v ); - //EXPECT_EQ( v.getData(), u.getData() ); - //EXPECT_EQ( w.getData(), u.getData() ); - - // copies of a static array - if( std::is_same< typename ArrayType::DeviceType, Devices::Host >::value ) { - typename ArrayType::ValueType data[ 10 ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - ArrayType u( data, 10 ); - ArrayType v( u ); - ArrayType w( v ); - EXPECT_EQ( u.getData(), data ); - //EXPECT_EQ( v.getData(), data ); - //EXPECT_EQ( w.getData(), data ); - } -} - -TYPED_TEST( ArrayTest, referenceCountingBind ) -{ - using ArrayType = typename TestFixture::ArrayType; - - // copies of a dynamic array - ArrayType u( 10 ); - ArrayType v; - v.bind( u ); - ArrayType w; - w.bind( v ); - EXPECT_EQ( v.getData(), u.getData() ); - EXPECT_EQ( w.getData(), u.getData() ); - - // copies of a static array - if( std::is_same< typename ArrayType::DeviceType, Devices::Host >::value ) { - typename ArrayType::ValueType data[ 10 ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - ArrayType u( data, 10 ); - ArrayType v; - v.bind( u ); - ArrayType w; - w.bind( v ); - EXPECT_EQ( u.getData(), data ); - EXPECT_EQ( v.getData(), data ); - EXPECT_EQ( w.getData(), data ); - } -} - // TODO: test all __cuda_callable__ methods from a CUDA kernel #endif // HAVE_GTEST diff --git a/src/UnitTests/Containers/ArrayViewTest.h b/src/UnitTests/Containers/ArrayViewTest.h index ac86cc354..28d8b512b 100644 --- a/src/UnitTests/Containers/ArrayViewTest.h +++ b/src/UnitTests/Containers/ArrayViewTest.h @@ -200,19 +200,13 @@ TYPED_TEST( ArrayViewTest, bind ) EXPECT_EQ( a.getSize(), 0 ); EXPECT_EQ( v.getSize(), 10 ); - if( std::is_same< typename ArrayType::DeviceType, Devices::Host >::value ) { - typename ArrayType::ValueType data[ 10 ] = { 1, 2, 3, 4, 5, 6, 7, 8, 10 }; - a.bind( data, 10 ); - EXPECT_EQ( a.getData(), data ); - EXPECT_EQ( a.getSize(), 10 ); - EXPECT_EQ( a.getElement( 1 ), 2 ); - v.bind( a ); - EXPECT_EQ( v.getElement( 1 ), 2 ); - a.reset(); - v.setElement( 1, 3 ); - v.reset(); - EXPECT_EQ( data[ 1 ], 3 ); - } + ArrayType b = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + EXPECT_EQ( b.getSize(), 10 ); + EXPECT_EQ( b.getElement( 1 ), 2 ); + v.bind( b ); + EXPECT_EQ( v.getElement( 1 ), 2 ); + v.setElement( 1, 3 ); + EXPECT_EQ( b.getElement( 1 ), 3 ); } TYPED_TEST( ArrayViewTest, swap ) -- GitLab From f9190a81c1659ba43b8059d100101c46d20d30d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 19:37:43 +0200 Subject: [PATCH 05/30] Removed getSerializationType() methods from Vector - they should be saved as Array --- src/TNL/Containers/Vector.h | 6 ------ src/TNL/Containers/Vector.hpp | 20 -------------------- src/TNL/Containers/VectorView.h | 6 ------ src/Tools/tnl-diff.h | 9 ++++++--- src/Tools/tnl-init.h | 3 +-- src/Tools/tnl-view.h | 16 ++++++++++------ 6 files changed, 17 insertions(+), 43 deletions(-) diff --git a/src/TNL/Containers/Vector.h b/src/TNL/Containers/Vector.h index 30e399312..afdcad9ce 100644 --- a/src/TNL/Containers/Vector.h +++ b/src/TNL/Containers/Vector.h @@ -51,12 +51,6 @@ public: /** \brief Returns type of vector Real value, Device type and the type of Index. */ virtual String getTypeVirtual() const; - /** \brief Returns (host) type of vector Real value, Device type and the type of Index. */ - static String getSerializationType(); - - /** \brief Returns (host) type of vector Real value, Device type and the type of Index. */ - virtual String getSerializationTypeVirtual() const; - /** * \brief Returns a modifiable view of the vector. */ diff --git a/src/TNL/Containers/Vector.hpp b/src/TNL/Containers/Vector.hpp index 5f15d9bae..8dea03963 100644 --- a/src/TNL/Containers/Vector.hpp +++ b/src/TNL/Containers/Vector.hpp @@ -39,26 +39,6 @@ getTypeVirtual() const return this->getType(); } -template< typename Real, - typename Device, - typename Index > -String -Vector< Real, Device, Index >:: -getSerializationType() -{ - return HostType::getType(); -} - -template< typename Real, - typename Device, - typename Index > -String -Vector< Real, Device, Index >:: -getSerializationTypeVirtual() const -{ - return this->getSerializationType(); -} - template< typename Real, typename Device, typename Index > diff --git a/src/TNL/Containers/VectorView.h b/src/TNL/Containers/VectorView.h index 1e5f07048..0bf4ac044 100644 --- a/src/TNL/Containers/VectorView.h +++ b/src/TNL/Containers/VectorView.h @@ -17,12 +17,6 @@ namespace TNL { namespace Containers { -template< typename Real, typename Device, typename Index > -class Vector; - -template< int Size, typename Real > -class StaticVector; - template< typename Real = double, typename Device = Devices::Host, typename Index = int > diff --git a/src/Tools/tnl-diff.h b/src/Tools/tnl-diff.h index 5443f953a..3fc71893b 100644 --- a/src/Tools/tnl-diff.h +++ b/src/Tools/tnl-diff.h @@ -436,7 +436,8 @@ bool computeDifference( const MeshPointer& meshPointer, const String& objectType { if( objectType == "Functions::MeshFunction" ) return computeDifferenceOfMeshFunctions< MeshPointer, Value, Real, Index >( meshPointer, parameters ); - if( objectType == "Containers::Vector" ) + if( objectType == "Containers::Array" || + objectType == "Containers::Vector" ) // TODO: remove deprecated names (Vector is saved as Array) return computeDifferenceOfVectors< MeshPointer, Value, Real, Index >( meshPointer, parameters ); std::cerr << "Unknown object type " << objectType << "." << std::endl; return false; @@ -450,7 +451,8 @@ bool setIndexType( const MeshPointer& meshPointer, const Config::ParameterContainer& parameters ) { String indexType; - if( parsedObjectType[ 0 ] == "Containers::Vector" ) + if( parsedObjectType[ 0 ] == "Containers::Array" || + parsedObjectType[ 0 ] == "Containers::Vector" ) // TODO: remove deprecated names (Vector is saved as Array) indexType = parsedObjectType[ 3 ]; if( parsedObjectType[ 0 ] == "Functions::MeshFunction" ) @@ -525,7 +527,8 @@ bool setValueType( const MeshPointer& meshPointer, if( parsedObjectType[ 0 ] == "Functions::MeshFunction" ) elementType = parsedObjectType[ 3 ]; - if( parsedObjectType[ 0 ] == "Containers::Vector" ) + if( parsedObjectType[ 0 ] == "Containers::Array" || + parsedObjectType[ 0 ] == "Containers::Vector" ) // TODO: remove deprecated names (Vector is saved as Array) elementType = parsedObjectType[ 1 ]; diff --git a/src/Tools/tnl-init.h b/src/Tools/tnl-init.h index a393a7a7c..a1c0eb5fa 100644 --- a/src/Tools/tnl-init.h +++ b/src/Tools/tnl-init.h @@ -263,8 +263,7 @@ bool resolveMesh( const std::vector< String >& parsedMeshType, const Config::ParameterContainer& parameters ) { std::cout << "+ -> Setting mesh type to " << parsedMeshType[ 0 ] << " ... " << std::endl; - if( parsedMeshType[ 0 ] == "Meshes::Grid" || - parsedMeshType[ 0 ] == "tnlGrid" ) // TODO: remove deprecated type name + if( parsedMeshType[ 0 ] == "Meshes::Grid" ) { typedef Meshes::Grid< Dimension, RealType, Devices::Host, IndexType > MeshType; return resolveRealType< MeshType >( parameters ); diff --git a/src/Tools/tnl-view.h b/src/Tools/tnl-view.h index 64c09e32b..9f2bc02b2 100644 --- a/src/Tools/tnl-view.h +++ b/src/Tools/tnl-view.h @@ -250,7 +250,8 @@ bool convertObject( const MeshPointer& meshPointer, std::cout << " writing to " << outputFileName << " ... " << std::flush; - if( parsedObjectType[ 0 ] == "Containers::Vector" ) + if( parsedObjectType[ 0 ] == "Containers::Array" || + parsedObjectType[ 0 ] == "Containers::Vector" ) // TODO: remove deprecated names (Vector is saved as Array) { using MeshType = typename MeshPointer::ObjectType; // FIXME: why is MeshType::GlobalIndexType not the same as Index? @@ -271,7 +272,8 @@ bool setDimension( const MeshPointer& meshPointer, const Config::ParameterContainer& parameters ) { int dimensions( 0 ); - if( parsedObjectType[ 0 ] == "Containers::Vector" ) + if( parsedObjectType[ 0 ] == "Containers::Array" || + parsedObjectType[ 0 ] == "Containers::Vector" ) // TODO: remove deprecated names (Vector is saved as Array) dimensions = 1; switch( dimensions ) { @@ -293,7 +295,8 @@ bool setIndexType( const MeshPointer& meshPointer, const Config::ParameterContainer& parameters ) { String indexType; - if( parsedObjectType[ 0 ] == "Containers::Vector" ) + if( parsedObjectType[ 0 ] == "Containers::Array" || + parsedObjectType[ 0 ] == "Containers::Vector" ) // TODO: remove deprecated names (Vector is saved as Array) indexType = parsedObjectType[ 3 ]; if( indexType == "int" ) @@ -363,8 +366,8 @@ bool setValueType( const MeshPointer& meshPointer, { String elementType; - // TODO: Fix this even for arrays - if( parsedObjectType[ 0 ] == "Containers::Vector" ) + if( parsedObjectType[ 0 ] == "Containers::Array" || + parsedObjectType[ 0 ] == "Containers::Vector" ) // TODO: remove deprecated names (Vector is saved as Array) elementType = parsedObjectType[ 1 ]; if( elementType == "float" ) @@ -459,7 +462,8 @@ struct FilesProcessor error = true; continue; } - if( parsedObjectType[ 0 ] == "Containers::Vector" ) + if( parsedObjectType[ 0 ] == "Containers::Array" || + parsedObjectType[ 0 ] == "Containers::Vector" ) // TODO: remove deprecated names (Vector is saved as Array) setValueType< MeshPointer >( meshPointer, inputFiles[ i ], parsedObjectType, parameters ); if( parsedObjectType[ 0 ] == "Functions::MeshFunction" ) setMeshFunction< MeshPointer >( meshPointer, inputFiles[ i ], parsedObjectType, parameters ); -- GitLab From 833011ade5140f1e3dd9141f29e985af9a67ede0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 19:40:39 +0200 Subject: [PATCH 06/30] Commented out unused variables in HeatEquationBenchmarkProblem --- .../HeatEquation/HeatEquationBenchmarkProblem_impl.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Benchmarks/HeatEquation/HeatEquationBenchmarkProblem_impl.h b/src/Benchmarks/HeatEquation/HeatEquationBenchmarkProblem_impl.h index 2bfd1e71c..14f1fd8a9 100644 --- a/src/Benchmarks/HeatEquation/HeatEquationBenchmarkProblem_impl.h +++ b/src/Benchmarks/HeatEquation/HeatEquationBenchmarkProblem_impl.h @@ -598,12 +598,14 @@ getExplicitUpdate( const RealType& time, userData.real_u = uDofs->getData(); userData.real_fu = fuDofs->getData(); #endif + /* const IndexType gridXSize = mesh->getDimensions().x(); const IndexType gridYSize = mesh->getDimensions().y(); dim3 cudaBlockSize( 16, 16 ); dim3 cudaGridSize( gridXSize / 16 + ( gridXSize % 16 != 0 ), gridYSize / 16 + ( gridYSize % 16 != 0 ) ); - + */ + TNL::Devices::Cuda::synchronizeDevice(); int cudaErr; Meshes::Traverser< MeshType, Cell > meshTraverser; -- GitLab From 2719f4fda3e67e60d1fd8c735a020e5f3eb38d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 19:45:46 +0200 Subject: [PATCH 07/30] Commented out unused computed value in HeatEquation benchmark's ExplicitUpdater --- src/Benchmarks/HeatEquation/Tuning/ExplicitUpdater.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Benchmarks/HeatEquation/Tuning/ExplicitUpdater.h b/src/Benchmarks/HeatEquation/Tuning/ExplicitUpdater.h index 62f0c55c9..e492d8761 100644 --- a/src/Benchmarks/HeatEquation/Tuning/ExplicitUpdater.h +++ b/src/Benchmarks/HeatEquation/Tuning/ExplicitUpdater.h @@ -187,7 +187,8 @@ class ExplicitUpdater typedef Functions::FunctionAdapter< MeshType, RightHandSide > FunctionAdapter; ( *userData.fu )( entity ) = ( *userData.differentialOperator )( *userData.u, entity, userData.time ); - + FunctionAdapter::getValue( *userData.rightHandSide, entity, userData.time ); + // TODO: fix the right hand side here !!! +// + FunctionAdapter::getValue( *userData.rightHandSide, entity, userData.time ); } @@ -200,6 +201,7 @@ class ExplicitUpdater typedef Functions::FunctionAdapter< MeshType, RightHandSide > FunctionAdapter; userData.real_fu[ entityIndex ] = ( *userData.differentialOperator )( mesh, userData.real_u, entityIndex, coordinates, userData.time ); + // TODO: fix the right hand side here !!! // + 0.0; } -- GitLab From 369b3838021309786f20bcd36051a4e76ad79415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 19:51:29 +0200 Subject: [PATCH 08/30] Fixed catching exceptions by reference Fixes #29 --- src/Benchmarks/SpMV/tnl-benchmark-spmv.h | 2 +- src/Tools/tnl-diff.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Benchmarks/SpMV/tnl-benchmark-spmv.h b/src/Benchmarks/SpMV/tnl-benchmark-spmv.h index ad3c8d61c..c707018ad 100644 --- a/src/Benchmarks/SpMV/tnl-benchmark-spmv.h +++ b/src/Benchmarks/SpMV/tnl-benchmark-spmv.h @@ -316,7 +316,7 @@ bool setupBenchmark( const Config::ParameterContainer& parameters ) return false; } } - catch( std::bad_alloc ) + catch( const std::bad_alloc& ) { std::cerr << "Not enough memory to read the matrix." << std::endl; logFile << std::endl; diff --git a/src/Tools/tnl-diff.h b/src/Tools/tnl-diff.h index 3fc71893b..914e4e086 100644 --- a/src/Tools/tnl-diff.h +++ b/src/Tools/tnl-diff.h @@ -583,7 +583,7 @@ bool processFiles( const Config::ParameterContainer& parameters ) { objectType = getObjectType( inputFiles[ 0 ] ); } - catch( std::ios_base::failure exception ) + catch( const std::ios_base::failure& exception ) { std::cerr << "Cannot open file " << inputFiles[ 0 ] << std::endl; } -- GitLab From 73ae99f7dd65cc3d50c790336d62711349ed4f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 19:55:16 +0200 Subject: [PATCH 09/30] Used VectorView for binding instead of Vector in mesh BoundaryTags layer --- src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h b/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h index ebbee9fdd..cc4b66602 100644 --- a/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h +++ b/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h @@ -12,7 +12,7 @@ #include #include -#include +#include #include "Traits.h" @@ -97,7 +97,7 @@ public: void updateBoundaryIndices( DimensionTag ) { // Array does not have sum(), Vector of bools does not fit due to arithmetics - Containers::Vector< typename BoundaryTagsArray::ValueType, typename BoundaryTagsArray::DeviceType, typename BoundaryTagsArray::IndexType > _boundaryTagsVector; + Containers::VectorView< typename BoundaryTagsArray::ValueType, typename BoundaryTagsArray::DeviceType, typename BoundaryTagsArray::IndexType > _boundaryTagsVector; _boundaryTagsVector.bind( boundaryTags.getData(), boundaryTags.getSize() ); const GlobalIndexType boundaryEntities = _boundaryTagsVector.template sum< GlobalIndexType >(); boundaryIndices.setSize( boundaryEntities ); -- GitLab From 8aa006fa9daf122b5f42caaf4a9e4930a0cc4a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 20:04:14 +0200 Subject: [PATCH 10/30] Removed binding from StaticArrayTest --- src/UnitTests/Containers/StaticArrayTest.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/UnitTests/Containers/StaticArrayTest.cpp b/src/UnitTests/Containers/StaticArrayTest.cpp index a418b9d06..16817100f 100644 --- a/src/UnitTests/Containers/StaticArrayTest.cpp +++ b/src/UnitTests/Containers/StaticArrayTest.cpp @@ -280,22 +280,6 @@ TYPED_TEST( StaticArrayTest, streamOperator ) std::stringstream testStream; testStream << u; } - -TYPED_TEST( StaticArrayTest, BindToArray ) -{ - using ArrayType = typename TestFixture::ArrayType; - using ValueType = typename TestFixture::ValueType; - constexpr int Size = ArrayType::size; - - ArrayType a; - for( int i = 0; i < Size; i++ ) - a[ i ] = i+1; - - Array< ValueType, Devices::Host > sharedArray; - sharedArray.bind( a ); - for( int i = 0; i < Size; i++ ) - EXPECT_EQ( a[ i ], sharedArray[ i ] ); -} #endif // HAVE_GTEST -- GitLab From b357ff4ebfa0539de85dd7ecc8ac51e6b39d3c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 20:22:08 +0200 Subject: [PATCH 11/30] Fixes in ArrayOperations --- .../Algorithms/ArrayOperationsCuda.hpp | 14 +++++----- .../Algorithms/ArrayOperationsHost.hpp | 28 ++++++++++++------- .../Algorithms/VectorOperationsHost_impl.h | 4 +-- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/TNL/Containers/Algorithms/ArrayOperationsCuda.hpp b/src/TNL/Containers/Algorithms/ArrayOperationsCuda.hpp index 0badc8d79..739e5149b 100644 --- a/src/TNL/Containers/Algorithms/ArrayOperationsCuda.hpp +++ b/src/TNL/Containers/Algorithms/ArrayOperationsCuda.hpp @@ -33,7 +33,7 @@ allocateMemory( Element*& data, #ifdef HAVE_CUDA TNL_CHECK_CUDA_DEVICE; if( cudaMalloc( ( void** ) &data, - ( size_t ) size * sizeof( Element ) ) != cudaSuccess ) + ( std::size_t ) size * sizeof( Element ) ) != cudaSuccess ) { data = 0; throw Exceptions::CudaBadAlloc(); @@ -182,12 +182,12 @@ copySTLList( DestinationElement* destination, const std::size_t copy_buffer_size = std::min( Devices::Cuda::TransferBufferSize / (std::size_t) sizeof( DestinationElement ), ( std::size_t ) size ); using BaseType = typename std::remove_cv< DestinationElement >::type; std::unique_ptr< BaseType[] > copy_buffer{ new BaseType[ copy_buffer_size ] }; - size_t copiedElements = 0; + std::size_t copiedElements = 0; auto it = source.begin(); while( copiedElements < size ) { const auto copySize = std::min( size - copiedElements, copy_buffer_size ); - for( size_t i = 0; i < copySize; i++ ) + for( std::size_t i = 0; i < copySize; i++ ) copy_buffer[ i ] = static_cast< DestinationElement >( * it ++ ); ArrayOperations< Devices::Cuda, Devices::Host >::copyMemory( &destination[ copiedElements ], ©_buffer[ 0 ], copySize ); copiedElements += copySize; @@ -220,7 +220,7 @@ containsValue( const Element* data, const Element& value ) { TNL_ASSERT_TRUE( data, "Attempted to check data through a nullptr." ); - TNL_ASSERT_GE( size, 0, "" ); + TNL_ASSERT_GE( size, (Index) 0, "" ); if( size == 0 ) return false; auto fetch = [=] __cuda_callable__ ( Index i ) -> bool { return ( data[ i ] == value ); }; @@ -315,7 +315,7 @@ compareMemory( const Element1* destination, */ TNL_ASSERT_TRUE( destination, "Attempted to compare data through a nullptr." ); TNL_ASSERT_TRUE( source, "Attempted to compare data through a nullptr." ); - TNL_ASSERT_GE( size, 0, "Array size must be non-negative." ); + TNL_ASSERT_GE( size, (Index) 0, "Array size must be non-negative." ); #ifdef HAVE_CUDA std::unique_ptr< Element2[] > host_buffer{ new Element2[ Devices::Cuda::getGPUTransferBufferSize() ] }; Index compared( 0 ); @@ -352,7 +352,7 @@ copyMemory( DestinationElement* destination, { TNL_ASSERT_TRUE( destination, "Attempted to copy data to a nullptr." ); TNL_ASSERT_TRUE( source, "Attempted to copy data from a nullptr." ); - TNL_ASSERT_GE( size, 0, "Array size must be non-negative." ); + TNL_ASSERT_GE( size, (Index) 0, "Array size must be non-negative." ); #ifdef HAVE_CUDA if( std::is_same< DestinationElement, SourceElement >::value ) { @@ -400,7 +400,7 @@ compareMemory( const Element1* hostData, { TNL_ASSERT_TRUE( hostData, "Attempted to compare data through a nullptr." ); TNL_ASSERT_TRUE( deviceData, "Attempted to compare data through a nullptr." ); - TNL_ASSERT_GE( size, 0, "Array size must be non-negative." ); + TNL_ASSERT_GE( size, (Index) 0, "Array size must be non-negative." ); return ArrayOperations< Devices::Host, Devices::Cuda >::compareMemory( deviceData, hostData, size ); } diff --git a/src/TNL/Containers/Algorithms/ArrayOperationsHost.hpp b/src/TNL/Containers/Algorithms/ArrayOperationsHost.hpp index ff24b237d..2b6e45115 100644 --- a/src/TNL/Containers/Algorithms/ArrayOperationsHost.hpp +++ b/src/TNL/Containers/Algorithms/ArrayOperationsHost.hpp @@ -18,9 +18,11 @@ #include namespace TNL { -namespace Containers { +namespace Containers { namespace Algorithms { +static constexpr int OpenMPArrayOperationsThreshold = 512; // TODO: check this threshold + template< typename Element, typename Index > void ArrayOperations< Devices::Host >:: @@ -67,7 +69,10 @@ setMemory( Element* data, const Element& value, const Index size ) { - for( Index i = 0; i < size; i ++ ) + #ifdef HAVE_OPENMP + #pragma omp parallel for if( Devices::Host::isOMPEnabled() && size > OpenMPArrayOperationsThreshold ) + #endif + for( Index i = 0; i < size; i++ ) data[ i ] = value; } @@ -86,7 +91,7 @@ copyMemory( DestinationElement* destination, { // GCC 8.1 complains that we bypass a non-trivial copy-constructor // (in C++17 we could use constexpr if to avoid compiling this branch in that case) - #if defined(__GNUC__) && ( __GNUC__ > 8 || ( __GNUC__ == 8 && __GNUC_MINOR__ > 0 ) ) && !defined(__clang__) && !defined(__NVCC__) + #if defined(__GNUC__) && ( __GNUC__ > 8 || ( __GNUC__ == 8 && __GNUC_MINOR__ > 0 ) ) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wclass-memaccess" #endif @@ -96,8 +101,11 @@ copyMemory( DestinationElement* destination, #endif } else - for( Index i = 0; i < size; i ++ ) - destination[ i ] = ( DestinationElement ) source[ i ]; + #ifdef HAVE_OPENMP + #pragma omp parallel for if( Devices::Host::isOMPEnabled() && size > OpenMPArrayOperationsThreshold ) + #endif + for( Index i = 0; i < size; i++ ) + destination[ i ] = source[ i ]; } template< typename DestinationElement, @@ -107,9 +115,9 @@ ArrayOperations< Devices::Host >:: copySTLList( DestinationElement* destination, const std::list< SourceElement >& source ) { - size_t i = 0; + std::size_t i = 0; for( const SourceElement& e : source ) - destination[ i ++ ] = static_cast< DestinationElement >( e ); + destination[ i++ ] = e; } @@ -132,7 +140,7 @@ compareMemory( const DestinationElement* destination, return false; } else - for( Index i = 0; i < size; i ++ ) + for( Index i = 0; i < size; i++ ) if( ! ( destination[ i ] == source[ i ] ) ) return false; return true; @@ -149,7 +157,7 @@ containsValue( const Element* data, TNL_ASSERT_TRUE( data, "Attempted to check data through a nullptr." ); TNL_ASSERT_GE( size, 0, "" ); - for( Index i = 0; i < size; i ++ ) + for( Index i = 0; i < size; i++ ) if( data[ i ] == value ) return true; return false; @@ -168,7 +176,7 @@ containsOnlyValue( const Element* data, if( size == 0 ) return false; - for( Index i = 0; i < size; i ++ ) + for( Index i = 0; i < size; i++ ) if( ! ( data[ i ] == value ) ) return false; return true; diff --git a/src/TNL/Containers/Algorithms/VectorOperationsHost_impl.h b/src/TNL/Containers/Algorithms/VectorOperationsHost_impl.h index 7b1bba80c..47a03c636 100644 --- a/src/TNL/Containers/Algorithms/VectorOperationsHost_impl.h +++ b/src/TNL/Containers/Algorithms/VectorOperationsHost_impl.h @@ -17,8 +17,8 @@ namespace TNL { namespace Containers { namespace Algorithms { -static const int OpenMPVectorOperationsThreshold = 512; // TODO: check this threshold -static const int PrefetchDistance = 128; +static constexpr int OpenMPVectorOperationsThreshold = 512; // TODO: check this threshold +static constexpr int PrefetchDistance = 128; template< typename Vector > void -- GitLab From 7431697ce2756f02e4dc57f1f968e6afa69b899f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 21:03:43 +0200 Subject: [PATCH 12/30] Fixed overloading between Array's copy-constructor and templated binding constructor --- src/TNL/Containers/Array.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TNL/Containers/Array.h b/src/TNL/Containers/Array.h index 96545ab32..2bf88373c 100644 --- a/src/TNL/Containers/Array.h +++ b/src/TNL/Containers/Array.h @@ -121,7 +121,7 @@ class Array : public Object */ [[deprecated("Binding functionality of Array is deprecated, ArrayView should be used instead.")]] Array( Array& array, - const IndexType& begin = 0, + const IndexType& begin, const IndexType& size = 0 ); /** -- GitLab From 386e96470b95bc2d136ee9bfda38ce68cffccb5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 22:07:52 +0200 Subject: [PATCH 13/30] Fixed Array's move-assignment operator --- src/TNL/Containers/Array.h | 2 +- src/TNL/Containers/Array.hpp | 19 ++----------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/TNL/Containers/Array.h b/src/TNL/Containers/Array.h index 2bf88373c..3c99605a3 100644 --- a/src/TNL/Containers/Array.h +++ b/src/TNL/Containers/Array.h @@ -129,7 +129,7 @@ class Array : public Object * * @param array is an array to be moved */ - Array( Array&& array ); + Array( Array&& array ) = default; /** * \brief Initialize the array from initializer list, i.e. { ... } diff --git a/src/TNL/Containers/Array.hpp b/src/TNL/Containers/Array.hpp index a3107fbc4..f5a49214f 100644 --- a/src/TNL/Containers/Array.hpp +++ b/src/TNL/Containers/Array.hpp @@ -109,23 +109,6 @@ Array( Array< Value, Device, Index >& array, } } -template< typename Value, - typename Device, - typename Index > -Array< Value, Device, Index >:: -Array( Array< Value, Device, Index >&& array ) -{ - this->size = array.size; - this->data = array.data; - this->allocationPointer = array.allocationPointer; - this->referenceCounter = array.referenceCounter; - - array.size = 0; - array.data = nullptr; - array.allocationPointer = nullptr; - array.referenceCounter = nullptr; -} - template< typename Value, typename Device, typename Index > @@ -528,6 +511,8 @@ Array< Value, Device, Index >& Array< Value, Device, Index >:: operator=( Array< Value, Device, Index >&& array ) { + reset(); + this->size = array.size; this->data = array.data; this->allocationPointer = array.allocationPointer; -- GitLab From 84af6166e61cc94fccd0b11dc6c20b2afec81396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 21:17:50 +0200 Subject: [PATCH 14/30] Fixed array binding in the Hamilton-Jacobi solver - using ArrayView instead of Array --- .../tnlDirectEikonalMethodsBase.h | 34 +++++++++---------- .../tnlDirectEikonalMethodsBase_impl.h | 18 +++++----- .../tnlFastSweepingMethod2D_impl.h | 26 +++++++------- .../tnlFastSweepingMethod3D_impl.h | 14 ++++---- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlDirectEikonalMethodsBase.h b/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlDirectEikonalMethodsBase.h index 76d98a2de..24a388554 100644 --- a/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlDirectEikonalMethodsBase.h +++ b/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlDirectEikonalMethodsBase.h @@ -80,12 +80,12 @@ class tnlDirectEikonalMethodsBase< Meshes::Grid< 2, Real, Device, Index > > const Real velocity = 1.0 ); template< int sizeSArray > - void updateBlocks( InterfaceMapType interfaceMap, - MeshFunctionType aux, - MeshFunctionType helpFunc, - ArrayContainer BlockIterHost, int numThreadsPerBlock/*, Real **sArray*/ ); + void updateBlocks( const InterfaceMapType& interfaceMap, + MeshFunctionType& aux, + MeshFunctionType& helpFunc, + ArrayContainer& BlockIterHost, int numThreadsPerBlock/*, Real **sArray*/ ); - void getNeighbours( ArrayContainer BlockIterHost, int numBlockX, int numBlockY ); + void getNeighbours( ArrayContainer& BlockIterHost, int numBlockX, int numBlockY ); }; template< typename Real, @@ -114,12 +114,12 @@ class tnlDirectEikonalMethodsBase< Meshes::Grid< 3, Real, Device, Index > > const RealType velocity = 1.0); template< int sizeSArray > - void updateBlocks( const InterfaceMapType interfaceMap, - const MeshFunctionType aux, + void updateBlocks( const InterfaceMapType& interfaceMap, + const MeshFunctionType& aux, MeshFunctionType& helpFunc, - ArrayContainer BlockIterHost, int numThreadsPerBlock/*, Real **sArray*/ ); + ArrayContainer& BlockIterHost, int numThreadsPerBlock/*, Real **sArray*/ ); - void getNeighbours( ArrayContainer BlockIterHost, int numBlockX, int numBlockY, int numBlockZ ); + void getNeighbours( ArrayContainer& BlockIterHost, int numBlockX, int numBlockY, int numBlockZ ); template< int sizeSArray > __cuda_callable__ bool updateCell3D( volatile Real *sArray, @@ -147,15 +147,15 @@ __global__ void CudaUpdateCellCaller( tnlDirectEikonalMethodsBase< Meshes::Grid< const Functions::MeshFunction< Meshes::Grid< 2, Real, Device, Index >, 2, bool >& interfaceMap, const Functions::MeshFunction< Meshes::Grid< 2, Real, Device, Index > >& aux, Functions::MeshFunction< Meshes::Grid< 2, Real, Device, Index > >& helpFunc, - TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterDevice, int oddEvenBlock =0); + TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterDevice, int oddEvenBlock =0); template < typename Index > -__global__ void CudaParallelReduc( TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterDevice, - TNL::Containers::Array< int, Devices::Cuda, Index > dBlock, int nBlocks ); +__global__ void CudaParallelReduc( TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterDevice, + TNL::Containers::ArrayView< int, Devices::Cuda, Index > dBlock, int nBlocks ); template < typename Index > -__global__ void GetNeighbours( TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterDevice, - TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterPom, int numBlockX, int numBlockY ); +__global__ void GetNeighbours( TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterDevice, + TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterPom, int numBlockX, int numBlockY ); template < typename Real, typename Device, typename Index > __global__ void CudaInitCaller( const Functions::MeshFunction< Meshes::Grid< 2, Real, Device, Index > >& input, @@ -172,11 +172,11 @@ __global__ void CudaUpdateCellCaller( tnlDirectEikonalMethodsBase< Meshes::Grid< const Functions::MeshFunction< Meshes::Grid< 3, Real, Device, Index >, 3, bool >& interfaceMap, const Functions::MeshFunction< Meshes::Grid< 3, Real, Device, Index > >& aux, Functions::MeshFunction< Meshes::Grid< 3, Real, Device, Index > >& helpFunc, - TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterDevice ); + TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterDevice ); template < typename Index > -__global__ void GetNeighbours3D( TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterDevice, - TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterPom, +__global__ void GetNeighbours3D( TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterDevice, + TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterPom, int numBlockX, int numBlockY, int numBlockZ ); #endif diff --git a/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlDirectEikonalMethodsBase_impl.h b/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlDirectEikonalMethodsBase_impl.h index 786c6a488..26444bcfa 100644 --- a/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlDirectEikonalMethodsBase_impl.h +++ b/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlDirectEikonalMethodsBase_impl.h @@ -96,10 +96,10 @@ template< typename Real, template< int sizeSArray > void tnlDirectEikonalMethodsBase< Meshes::Grid< 2, Real, Device, Index > >:: -updateBlocks( InterfaceMapType interfaceMap, - MeshFunctionType aux, - MeshFunctionType helpFunc, - ArrayContainer BlockIterHost, int numThreadsPerBlock/*, Real **sArray*/ ) +updateBlocks( const InterfaceMapType& interfaceMap, + MeshFunctionType& aux, + MeshFunctionType& helpFunc, + ArrayContainer& BlockIterHost, int numThreadsPerBlock/*, Real **sArray*/ ) { #pragma omp parallel for schedule( dynamic ) for( IndexType i = 0; i < BlockIterHost.getSize(); i++ ) @@ -270,10 +270,10 @@ template< typename Real, template< int sizeSArray > void tnlDirectEikonalMethodsBase< Meshes::Grid< 3, Real, Device, Index > >:: -updateBlocks( const InterfaceMapType interfaceMap, - const MeshFunctionType aux, +updateBlocks( const InterfaceMapType& interfaceMap, + const MeshFunctionType& aux, MeshFunctionType& helpFunc, - ArrayContainer BlockIterHost, int numThreadsPerBlock/*, Real **sArray*/ ) + ArrayContainer& BlockIterHost, int numThreadsPerBlock/*, Real **sArray*/ ) { //#pragma omp parallel for schedule( dynamic ) for( IndexType i = 0; i < BlockIterHost.getSize(); i++ ) @@ -594,7 +594,7 @@ template< typename Real, typename Index > void tnlDirectEikonalMethodsBase< Meshes::Grid< 3, Real, Device, Index > >:: -getNeighbours( ArrayContainer BlockIterHost, int numBlockX, int numBlockY, int numBlockZ ) +getNeighbours( ArrayContainer& BlockIterHost, int numBlockX, int numBlockY, int numBlockZ ) { int* BlockIterPom; BlockIterPom = new int [ numBlockX * numBlockY * numBlockZ ]; @@ -634,7 +634,7 @@ template< typename Real, typename Index > void tnlDirectEikonalMethodsBase< Meshes::Grid< 2, Real, Device, Index > >:: -getNeighbours( ArrayContainer BlockIterHost, int numBlockX, int numBlockY ) +getNeighbours( ArrayContainer& BlockIterHost, int numBlockX, int numBlockY ) { int* BlockIterPom; BlockIterPom = new int [numBlockX * numBlockY]; diff --git a/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlFastSweepingMethod2D_impl.h b/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlFastSweepingMethod2D_impl.h index 001f4c69a..8fff00449 100644 --- a/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlFastSweepingMethod2D_impl.h +++ b/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlFastSweepingMethod2D_impl.h @@ -378,7 +378,7 @@ solve( const MeshPointer& mesh, auxPtr.template getData< Device>(), helpFunc.template modifyData< Device>(), BlockIterDevice, - oddEvenBlock ); + oddEvenBlock.getView() ); cudaDeviceSynchronize(); TNL_CHECK_CUDA_DEVICE; auxPtr = helpFunc; @@ -390,17 +390,17 @@ solve( const MeshPointer& mesh, auxPtr.template getData< Device>(), helpFunc.template modifyData< Device>(), BlockIterDevice, - oddEvenBlock ); + oddEvenBlock.getView() ); cudaDeviceSynchronize(); TNL_CHECK_CUDA_DEVICE; auxPtr = helpFunc; oddEvenBlock= (oddEvenBlock == 0) ? 1: 0; - CudaParallelReduc<<< nBlocks , 1024 >>>( BlockIterDevice, dBlock, ( numBlocksX * numBlocksY ) ); + CudaParallelReduc<<< nBlocks , 1024 >>>( BlockIterDevice.getView(), dBlock.getView(), ( numBlocksX * numBlocksY ) ); cudaDeviceSynchronize(); TNL_CHECK_CUDA_DEVICE; - CudaParallelReduc<<< 1, nBlocks >>>( dBlock, dBlock, nBlocks ); + CudaParallelReduc<<< 1, nBlocks >>>( dBlock.getView(), dBlock.getView(), nBlocks ); cudaDeviceSynchronize(); TNL_CHECK_CUDA_DEVICE; @@ -422,7 +422,7 @@ solve( const MeshPointer& mesh, interfaceMapPtr.template getData< Device >(), auxPtr.template modifyData< Device>(), helpFunc.template modifyData< Device>(), - BlockIterDevice ); + BlockIterDevice.getView() ); cudaDeviceSynchronize(); TNL_CHECK_CUDA_DEVICE; @@ -437,7 +437,7 @@ solve( const MeshPointer& mesh, //} //std::cout << std::endl; - GetNeighbours<<< nBlocksNeigh, 1024 >>>( BlockIterDevice, BlockIterPom, numBlocksX, numBlocksY ); + GetNeighbours<<< nBlocksNeigh, 1024 >>>( BlockIterDevice.getView(), BlockIterPom.getView(), numBlocksX, numBlocksY ); cudaDeviceSynchronize(); TNL_CHECK_CUDA_DEVICE; BlockIterDevice = BlockIterPom; @@ -447,10 +447,10 @@ solve( const MeshPointer& mesh, //TNL::swap( auxPtr, helpFunc ); - CudaParallelReduc<<< nBlocks , 1024 >>>( BlockIterDevice, dBlock, ( numBlocksX * numBlocksY ) ); + CudaParallelReduc<<< nBlocks , 1024 >>>( BlockIterDevice.getView(), dBlock.getView(), ( numBlocksX * numBlocksY ) ); TNL_CHECK_CUDA_DEVICE; - CudaParallelReduc<<< 1, nBlocks >>>( dBlock, dBlock, nBlocks ); + CudaParallelReduc<<< 1, nBlocks >>>( dBlock.getView(), dBlock.getView(), nBlocks ); TNL_CHECK_CUDA_DEVICE; @@ -489,8 +489,8 @@ solve( const MeshPointer& mesh, template < typename Index > -__global__ void GetNeighbours( TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterDevice, - TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterPom, int numBlockX, int numBlockY ) +__global__ void GetNeighbours( TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterDevice, + TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterPom, int numBlockX, int numBlockY ) { int i = blockIdx.x * 1024 + threadIdx.x; @@ -515,8 +515,8 @@ __global__ void GetNeighbours( TNL::Containers::Array< int, Devices::Cuda, Index } template < typename Index > -__global__ void CudaParallelReduc( TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterDevice, - TNL::Containers::Array< int, Devices::Cuda, Index > dBlock, int nBlocks ) +__global__ void CudaParallelReduc( TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterDevice, + TNL::Containers::ArrayView< int, Devices::Cuda, Index > dBlock, int nBlocks ) { int i = threadIdx.x; int blId = blockIdx.x; @@ -588,7 +588,7 @@ __global__ void CudaUpdateCellCaller( tnlDirectEikonalMethodsBase< Meshes::Grid< const Functions::MeshFunction< Meshes::Grid< 2, Real, Device, Index >, 2, bool >& interfaceMap, const Functions::MeshFunction< Meshes::Grid< 2, Real, Device, Index > >& aux, Functions::MeshFunction< Meshes::Grid< 2, Real, Device, Index > >& helpFunc, - TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterDevice, int oddEvenBlock ) + TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterDevice, int oddEvenBlock ) { int thri = threadIdx.x; int thrj = threadIdx.y; int i = threadIdx.x + blockDim.x*blockIdx.x; diff --git a/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlFastSweepingMethod3D_impl.h b/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlFastSweepingMethod3D_impl.h index 5af33cf29..2a1183bc2 100644 --- a/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlFastSweepingMethod3D_impl.h +++ b/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlFastSweepingMethod3D_impl.h @@ -383,20 +383,20 @@ solve( const MeshPointer& mesh, interfaceMapPtr.template getData< Device >(), auxPtr.template getData< Device>(), helpFunc.template modifyData< Device>(), - BlockIterDevice ); + BlockIterDevice.getView() ); cudaDeviceSynchronize(); TNL_CHECK_CUDA_DEVICE; - GetNeighbours3D<<< nBlocksNeigh, 1024 >>>( BlockIterDevice, BlockIterPom, numBlocksX, numBlocksY, numBlocksZ ); + GetNeighbours3D<<< nBlocksNeigh, 1024 >>>( BlockIterDevice.getView(), BlockIterPom.getView(), numBlocksX, numBlocksY, numBlocksZ ); cudaDeviceSynchronize(); TNL_CHECK_CUDA_DEVICE; BlockIterDevice = BlockIterPom; - CudaParallelReduc<<< nBlocks , 512 >>>( BlockIterDevice, dBlock, ( numBlocksX * numBlocksY * numBlocksZ ) ); + CudaParallelReduc<<< nBlocks , 512 >>>( BlockIterDevice.getView(), dBlock.getView(), ( numBlocksX * numBlocksY * numBlocksZ ) ); cudaDeviceSynchronize(); TNL_CHECK_CUDA_DEVICE; - CudaParallelReduc<<< 1, nBlocks >>>( dBlock, dBlock, nBlocks ); + CudaParallelReduc<<< 1, nBlocks >>>( dBlock.getView(), dBlock.getView(), nBlocks ); cudaDeviceSynchronize(); TNL_CHECK_CUDA_DEVICE; cudaMemcpy(&BlockIterD, &dBlock[0], sizeof( int ), cudaMemcpyDeviceToHost); @@ -426,8 +426,8 @@ solve( const MeshPointer& mesh, #ifdef HAVE_CUDA template < typename Index > -__global__ void GetNeighbours3D( TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterDevice, - TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterPom, +__global__ void GetNeighbours3D( TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterDevice, + TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterPom, int numBlockX, int numBlockY, int numBlockZ ) { int i = blockIdx.x * 1024 + threadIdx.x; @@ -462,7 +462,7 @@ __global__ void CudaUpdateCellCaller( tnlDirectEikonalMethodsBase< Meshes::Grid< const Functions::MeshFunction< Meshes::Grid< 3, Real, Device, Index >, 3, bool >& interfaceMap, const Functions::MeshFunction< Meshes::Grid< 3, Real, Device, Index > >& aux, Functions::MeshFunction< Meshes::Grid< 3, Real, Device, Index > >& helpFunc, - TNL::Containers::Array< int, Devices::Cuda, Index > BlockIterDevice ) + TNL::Containers::ArrayView< int, Devices::Cuda, Index > BlockIterDevice ) { int thri = threadIdx.x; int thrj = threadIdx.y; int thrk = threadIdx.z; int blIdx = blockIdx.x; int blIdy = blockIdx.y; int blIdz = blockIdx.z; -- GitLab From bd407ceab41f91fd63aeae7b917fea0036657a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 11 Apr 2019 22:44:08 +0200 Subject: [PATCH 15/30] Removed useless ThisType aliases --- src/TNL/Containers/StaticVector.h | 12 ++---- src/TNL/Functions/BoundaryMeshFunction.h | 1 - src/TNL/Functions/MeshFunction.h | 13 +++---- src/TNL/Functions/MeshFunction_impl.h | 22 +++++------ src/TNL/Functions/VectorField.h | 7 ++-- src/TNL/Matrices/AdEllpack.h | 1 - src/TNL/Matrices/BiEllpack.h | 1 - src/TNL/Matrices/BiEllpackSymmetric.h | 1 - src/TNL/Matrices/COOMatrix.h | 1 - src/TNL/Matrices/CSR.h | 1 - src/TNL/Matrices/ChunkedEllpack.h | 1 - src/TNL/Matrices/Dense.h | 1 - src/TNL/Matrices/Dense_impl.h | 4 +- src/TNL/Matrices/Ellpack.h | 1 - src/TNL/Matrices/EllpackSymmetric.h | 1 - src/TNL/Matrices/EllpackSymmetricGraph.h | 1 - src/TNL/Matrices/Multidiagonal.h | 1 - src/TNL/Matrices/SlicedEllpack.h | 1 - src/TNL/Matrices/SlicedEllpackSymmetric.h | 1 - .../Matrices/SlicedEllpackSymmetricGraph.h | 1 - src/TNL/Matrices/Tridiagonal.h | 1 - src/TNL/Matrices/Tridiagonal_impl.h | 2 +- src/TNL/Meshes/DummyMesh.h | 1 - src/TNL/Meshes/GridDetails/Grid1D.h | 5 +-- src/TNL/Meshes/GridDetails/Grid1D_impl.h | 4 +- src/TNL/Meshes/GridDetails/Grid2D.h | 5 +-- src/TNL/Meshes/GridDetails/Grid2D_impl.h | 4 +- src/TNL/Meshes/GridDetails/Grid3D.h | 5 +-- src/TNL/Meshes/GridDetails/Grid3D_impl.h | 4 +- src/TNL/Meshes/GridDetails/GridEntity_impl.h | 12 +++--- .../NeighborGridEntityGetter1D_impl.h | 3 +- .../NeighborGridEntityGetter2D_impl.h | 6 +-- .../NeighborGridEntityGetter3D_impl.h | 7 ++-- src/TNL/Meshes/GridEntity.h | 21 +++++----- src/TNL/Operators/FunctionInverseOperator.h | 4 +- src/TNL/Operators/NeumannBoundaryConditions.h | 3 -- src/TNL/Pointers/DevicePointer.h | 39 +++++++++---------- src/TNL/Pointers/SharedPointerCuda.h | 30 +++++++------- src/TNL/Pointers/SharedPointerHost.h | 17 ++++---- src/TNL/Pointers/SharedPointerMic.h | 15 ++++--- src/TNL/Pointers/UniquePointer.h | 15 +++---- 41 files changed, 114 insertions(+), 162 deletions(-) diff --git a/src/TNL/Containers/StaticVector.h b/src/TNL/Containers/StaticVector.h index c8b7bb9b4..6b7c941f2 100644 --- a/src/TNL/Containers/StaticVector.h +++ b/src/TNL/Containers/StaticVector.h @@ -27,7 +27,6 @@ class StaticVector : public StaticArray< Size, Real > { public: typedef Real RealType; - typedef StaticVector< Size, Real > ThisType; enum { size = Size }; /** @@ -210,7 +209,7 @@ class StaticVector : public StaticArray< Size, Real > * \brief Returns static vector with all elements in absolute value. */ __cuda_callable__ - ThisType abs() const; + StaticVector abs() const; /** * \brief Returns the length of this vector in p-dimensional vector space. @@ -246,7 +245,6 @@ class StaticVector< 1, Real > : public StaticArray< 1, Real > { public: typedef Real RealType; - typedef StaticVector< 1, Real > ThisType; enum { size = 1 }; /** \brief See StaticVector::StaticVector().*/ @@ -328,7 +326,7 @@ class StaticVector< 1, Real > : public StaticArray< 1, Real > /** \brief See StaticVector::abs() const.*/ __cuda_callable__ - ThisType abs() const; + StaticVector abs() const; /** \brief See StaticVector::lpNorm( const Real& p ) const.*/ __cuda_callable__ @@ -360,7 +358,6 @@ class StaticVector< 2, Real > : public StaticArray< 2, Real > { public: typedef Real RealType; - typedef StaticVector< 2, Real > ThisType; enum { size = 2 }; /** \brief See StaticVector::StaticVector().*/ @@ -451,7 +448,7 @@ class StaticVector< 2, Real > : public StaticArray< 2, Real > /** \brief See StaticVector::abs() const.*/ __cuda_callable__ - ThisType abs() const; + StaticVector abs() const; /** \brief See StaticVector::lpNorm( const Real& p ) const.*/ __cuda_callable__ @@ -483,7 +480,6 @@ class StaticVector< 3, Real > : public StaticArray< 3, Real > { public: typedef Real RealType; - typedef StaticVector< 3, Real > ThisType; enum { size = 3 }; /** \brief See StaticVector::StaticVector().*/ @@ -575,7 +571,7 @@ class StaticVector< 3, Real > : public StaticArray< 3, Real > /** \brief See StaticVector::abs() const.*/ __cuda_callable__ - ThisType abs() const; + StaticVector abs() const; /** \brief See StaticVector::lpNorm( const Real& p ) const.*/ __cuda_callable__ diff --git a/src/TNL/Functions/BoundaryMeshFunction.h b/src/TNL/Functions/BoundaryMeshFunction.h index b91b87bbb..c09e52543 100644 --- a/src/TNL/Functions/BoundaryMeshFunction.h +++ b/src/TNL/Functions/BoundaryMeshFunction.h @@ -30,7 +30,6 @@ class BoundaryMeshFunction : public: using BaseType = MeshFunction< Mesh, MeshEntityDimension, Real >; - using ThisType = BoundaryMeshFunction< Mesh, MeshEntityDimension, Real >; using typename BaseType::MeshType; using typename BaseType::DeviceType; using typename BaseType::IndexType; diff --git a/src/TNL/Functions/MeshFunction.h b/src/TNL/Functions/MeshFunction.h index 1850f4fb2..a59a8aecf 100644 --- a/src/TNL/Functions/MeshFunction.h +++ b/src/TNL/Functions/MeshFunction.h @@ -39,9 +39,8 @@ class MeshFunction : using MeshPointer = Pointers::SharedPointer< MeshType >; using RealType = Real; using VectorType = Containers::Vector< RealType, DeviceType, IndexType >; - using ThisType = Functions::MeshFunction< MeshType, MeshEntityDimension, RealType >; using DistributedMeshType = Meshes::DistributedMeshes::DistributedMesh; - using DistributedMeshSynchronizerType = Meshes::DistributedMeshes::DistributedMeshSynchronizer; + using DistributedMeshSynchronizerType = Meshes::DistributedMeshes::DistributedMeshSynchronizer; static constexpr int getEntitiesDimension() { return MeshEntityDimension; } @@ -51,7 +50,7 @@ class MeshFunction : MeshFunction( const MeshPointer& meshPointer ); - MeshFunction( const ThisType& meshFunction ); + MeshFunction( const MeshFunction& meshFunction ); template< typename Vector > MeshFunction( const MeshPointer& meshPointer, @@ -78,7 +77,7 @@ class MeshFunction : const Config::ParameterContainer& parameters, const String& prefix = "" ); - void bind( ThisType& meshFunction ); + void bind( MeshFunction& meshFunction ); template< typename Vector > void bind( const Vector& data, @@ -135,13 +134,13 @@ class MeshFunction : const RealType& operator[]( const IndexType& meshEntityIndex ) const; template< typename Function > - ThisType& operator = ( const Function& f ); + MeshFunction& operator = ( const Function& f ); template< typename Function > - ThisType& operator -= ( const Function& f ); + MeshFunction& operator -= ( const Function& f ); template< typename Function > - ThisType& operator += ( const Function& f ); + MeshFunction& operator += ( const Function& f ); RealType getLpNorm( const RealType& p ) const; diff --git a/src/TNL/Functions/MeshFunction_impl.h b/src/TNL/Functions/MeshFunction_impl.h index 107503ca4..207165dfe 100644 --- a/src/TNL/Functions/MeshFunction_impl.h +++ b/src/TNL/Functions/MeshFunction_impl.h @@ -47,7 +47,7 @@ template< typename Mesh, int MeshEntityDimension, typename Real > MeshFunction< Mesh, MeshEntityDimension, Real >:: -MeshFunction( const ThisType& meshFunction ) +MeshFunction( const MeshFunction& meshFunction ) { setupSynchronizer(meshFunction.meshPointer->getDistributedMesh()); @@ -181,7 +181,7 @@ template< typename Mesh, typename Real > void MeshFunction< Mesh, MeshEntityDimension, Real >:: -bind( ThisType& meshFunction ) +bind( MeshFunction& meshFunction ) { setupSynchronizer(meshFunction.meshPointer->getDistributedMesh()); @@ -411,9 +411,9 @@ MeshFunction< Mesh, MeshEntityDimension, Real >& MeshFunction< Mesh, MeshEntityDimension, Real >:: operator = ( const Function& f ) { - Pointers::DevicePointer< ThisType > thisDevicePtr( *this ); + Pointers::DevicePointer< MeshFunction > thisDevicePtr( *this ); Pointers::DevicePointer< typename std::add_const< Function >::type > fDevicePtr( f ); - MeshFunctionEvaluator< ThisType, Function >::evaluate( thisDevicePtr, fDevicePtr ); + MeshFunctionEvaluator< MeshFunction, Function >::evaluate( thisDevicePtr, fDevicePtr ); return *this; } @@ -425,9 +425,9 @@ MeshFunction< Mesh, MeshEntityDimension, Real >& MeshFunction< Mesh, MeshEntityDimension, Real >:: operator += ( const Function& f ) { - Pointers::DevicePointer< ThisType > thisDevicePtr( *this ); + Pointers::DevicePointer< MeshFunction > thisDevicePtr( *this ); Pointers::DevicePointer< typename std::add_const< Function >::type > fDevicePtr( f ); - MeshFunctionEvaluator< ThisType, Function >::evaluate( thisDevicePtr, fDevicePtr, ( RealType ) 1.0, ( RealType ) 1.0 ); + MeshFunctionEvaluator< MeshFunction, Function >::evaluate( thisDevicePtr, fDevicePtr, ( RealType ) 1.0, ( RealType ) 1.0 ); return *this; } @@ -439,9 +439,9 @@ MeshFunction< Mesh, MeshEntityDimension, Real >& MeshFunction< Mesh, MeshEntityDimension, Real >:: operator -= ( const Function& f ) { - Pointers::DevicePointer< ThisType > thisDevicePtr( *this ); + Pointers::DevicePointer< MeshFunction > thisDevicePtr( *this ); Pointers::DevicePointer< typename std::add_const< Function >::type > fDevicePtr( f ); - MeshFunctionEvaluator< ThisType, Function >::evaluate( thisDevicePtr, fDevicePtr, ( RealType ) 1.0, ( RealType ) -1.0 ); + MeshFunctionEvaluator< MeshFunction, Function >::evaluate( thisDevicePtr, fDevicePtr, ( RealType ) 1.0, ( RealType ) -1.0 ); return *this; } @@ -452,7 +452,7 @@ Real MeshFunction< Mesh, MeshEntityDimension, Real >:: getLpNorm( const RealType& p ) const { - return MeshFunctionNormGetter< ThisType >::getNorm( *this, p ); + return MeshFunctionNormGetter< MeshFunction >::getNorm( *this, p ); } template< typename Mesh, @@ -520,9 +520,9 @@ write( const String& fileName, return false; } if( format == "vtk" ) - return MeshFunctionVTKWriter< ThisType >::write( *this, file, scale ); + return MeshFunctionVTKWriter< MeshFunction >::write( *this, file, scale ); else if( format == "gnuplot" ) - return MeshFunctionGnuplotWriter< ThisType >::write( *this, file, scale ); + return MeshFunctionGnuplotWriter< MeshFunction >::write( *this, file, scale ); else { std::cerr << "Unknown output format: " << format << std::endl; return false; diff --git a/src/TNL/Functions/VectorField.h b/src/TNL/Functions/VectorField.h index c7d5bf553..87d86d62b 100644 --- a/src/TNL/Functions/VectorField.h +++ b/src/TNL/Functions/VectorField.h @@ -89,7 +89,6 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > typedef Pointers::SharedPointer< FunctionType > FunctionPointer; typedef typename MeshType::DeviceType DeviceType; typedef typename MeshType::GlobalIndexType IndexType; - typedef VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, RealType > > ThisType; typedef Containers::StaticVector< Size, RealType > VectorType; static constexpr int getEntitiesDimension() { return FunctionType::getEntitiesDimension(); } @@ -177,7 +176,7 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > return Size * FunctionType::getDofs( meshPointer ); } - void bind( ThisType& vectorField ) + void bind( VectorField& vectorField ) { for( int i = 0; i < Size; i ++ ) { @@ -303,9 +302,9 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > return false; } if( format == "vtk" ) - return VectorFieldVTKWriter< ThisType >::write( *this, file, scale ); + return VectorFieldVTKWriter< VectorField >::write( *this, file, scale ); else if( format == "gnuplot" ) - return VectorFieldGnuplotWriter< ThisType >::write( *this, file, scale ); + return VectorFieldGnuplotWriter< VectorField >::write( *this, file, scale ); else { std::cerr << "Unknown output format: " << format << std::endl; return false; diff --git a/src/TNL/Matrices/AdEllpack.h b/src/TNL/Matrices/AdEllpack.h index bfe70b6cb..dd6618d5e 100644 --- a/src/TNL/Matrices/AdEllpack.h +++ b/src/TNL/Matrices/AdEllpack.h @@ -84,7 +84,6 @@ public: typedef Index IndexType; typedef typename Sparse< RealType, DeviceType, IndexType >::CompressedRowLengthsVector CompressedRowLengthsVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; - typedef AdEllpack< Real, Device, Index > ThisType; typedef AdEllpack< Real, Devices::Host, Index > HostType; typedef AdEllpack< Real, Devices::Cuda, Index > CudaType; diff --git a/src/TNL/Matrices/BiEllpack.h b/src/TNL/Matrices/BiEllpack.h index 93bfeabaa..08bb53666 100644 --- a/src/TNL/Matrices/BiEllpack.h +++ b/src/TNL/Matrices/BiEllpack.h @@ -39,7 +39,6 @@ public: typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; typedef typename Sparse< RealType, DeviceType, IndexType >::ValuesVector ValuesVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ColumnIndexesVector ColumnIndexesVector; - typedef BiEllpack< Real, Device, Index > ThisType; typedef BiEllpack< Real, Devices::Host, Index > HostType; typedef BiEllpack< Real, Devices::Cuda, Index > CudaType; diff --git a/src/TNL/Matrices/BiEllpackSymmetric.h b/src/TNL/Matrices/BiEllpackSymmetric.h index 5e72d9b64..0d2ae9f1e 100644 --- a/src/TNL/Matrices/BiEllpackSymmetric.h +++ b/src/TNL/Matrices/BiEllpackSymmetric.h @@ -30,7 +30,6 @@ public: typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; typedef typename Sparse< RealType, DeviceType, IndexType >::ValuesVector ValuesVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ColumnIndexesVector ColumnIndexesVector; - typedef BiEllpackSymmetric< Real, Device, Index > ThisType; typedef BiEllpackSymmetric< Real, Devices::Host, Index > HostType; typedef BiEllpackSymmetric< Real, Devices::Cuda, Index > CudaType; diff --git a/src/TNL/Matrices/COOMatrix.h b/src/TNL/Matrices/COOMatrix.h index e67351ab9..accf7c205 100644 --- a/src/TNL/Matrices/COOMatrix.h +++ b/src/TNL/Matrices/COOMatrix.h @@ -35,7 +35,6 @@ public: typedef Index IndexType; typedef typename Sparse< RealType, DeviceType, IndexType >:: CompressedRowLengthsVector CompressedRowLengthsVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; - typedef COOMatrix< Real, Device, Index > ThisType; typedef COOMatrix< Real, Devices::Host, Index > HostType; typedef COOMatrix< Real, Devices::Cuda, Index > CudaType; diff --git a/src/TNL/Matrices/CSR.h b/src/TNL/Matrices/CSR.h index 4f42c1bac..70eae6f4b 100644 --- a/src/TNL/Matrices/CSR.h +++ b/src/TNL/Matrices/CSR.h @@ -49,7 +49,6 @@ public: using IndexType = Index; typedef typename Sparse< RealType, DeviceType, IndexType >:: CompressedRowLengthsVector CompressedRowLengthsVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; - typedef CSR< Real, Device, Index > ThisType; typedef CSR< Real, Devices::Host, Index > HostType; typedef CSR< Real, Devices::Cuda, Index > CudaType; typedef Sparse< Real, Device, Index > BaseType; diff --git a/src/TNL/Matrices/ChunkedEllpack.h b/src/TNL/Matrices/ChunkedEllpack.h index 928dcd8d1..a6f06e797 100644 --- a/src/TNL/Matrices/ChunkedEllpack.h +++ b/src/TNL/Matrices/ChunkedEllpack.h @@ -78,7 +78,6 @@ public: typedef tnlChunkedEllpackSliceInfo< IndexType > ChunkedEllpackSliceInfo; typedef typename Sparse< RealType, DeviceType, IndexType >:: CompressedRowLengthsVector CompressedRowLengthsVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; - typedef ChunkedEllpack< Real, Device, Index > ThisType; typedef ChunkedEllpack< Real, Devices::Host, Index > HostType; typedef ChunkedEllpack< Real, Devices::Cuda, Index > CudaType; typedef Sparse< Real, Device, Index > BaseType; diff --git a/src/TNL/Matrices/Dense.h b/src/TNL/Matrices/Dense.h index e9601a9fa..8c21e33b0 100644 --- a/src/TNL/Matrices/Dense.h +++ b/src/TNL/Matrices/Dense.h @@ -41,7 +41,6 @@ public: typedef Index IndexType; typedef typename Matrix< Real, Device, Index >::CompressedRowLengthsVector CompressedRowLengthsVector; typedef typename Matrix< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; - typedef Dense< Real, Device, Index > ThisType; typedef Dense< Real, Devices::Host, Index > HostType; typedef Dense< Real, Devices::Cuda, Index > CudaType; typedef Matrix< Real, Device, Index > BaseType; diff --git a/src/TNL/Matrices/Dense_impl.h b/src/TNL/Matrices/Dense_impl.h index 3844751d4..2a73d03bf 100644 --- a/src/TNL/Matrices/Dense_impl.h +++ b/src/TNL/Matrices/Dense_impl.h @@ -612,7 +612,7 @@ void Dense< Real, Device, Index >::getMatrixProduct( const Matrix1& matrix1, cudaGridSize.x = columnTiles % Devices::Cuda::getMaxGridSize(); if( gridIdx_y == rowGrids - 1 ) cudaGridSize.y = rowTiles % Devices::Cuda::getMaxGridSize(); - ThisType* this_kernel = Devices::Cuda::passToDevice( *this ); + Dense* this_kernel = Devices::Cuda::passToDevice( *this ); Matrix1* matrix1_kernel = Devices::Cuda::passToDevice( matrix1 ); Matrix2* matrix2_kernel = Devices::Cuda::passToDevice( matrix2 ); DenseMatrixProductKernel< Real, @@ -828,7 +828,7 @@ void Dense< Real, Device, Index >::getTransposition( const Matrix& matrix, const IndexType columnGrids = roundUpDivision( columnTiles, Devices::Cuda::getMaxGridSize() ); const IndexType sharedMemorySize = tileDim*tileDim + tileDim*tileDim/Devices::Cuda::getNumberOfSharedMemoryBanks(); - ThisType* this_device = Devices::Cuda::passToDevice( *this ); + Dense* this_device = Devices::Cuda::passToDevice( *this ); Matrix* matrix_device = Devices::Cuda::passToDevice( matrix ); for( IndexType gridIdx_x = 0; gridIdx_x < columnGrids; gridIdx_x++ ) diff --git a/src/TNL/Matrices/Ellpack.h b/src/TNL/Matrices/Ellpack.h index 100685e7b..e2479fd54 100644 --- a/src/TNL/Matrices/Ellpack.h +++ b/src/TNL/Matrices/Ellpack.h @@ -39,7 +39,6 @@ public: typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; typedef typename Sparse< RealType, DeviceType, IndexType >::ValuesVector ValuesVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ColumnIndexesVector ColumnIndexesVector; - typedef Ellpack< Real, Device, Index > ThisType; typedef Ellpack< Real, Devices::Host, Index > HostType; typedef Ellpack< Real, Devices::Cuda, Index > CudaType; typedef Sparse< Real, Device, Index > BaseType; diff --git a/src/TNL/Matrices/EllpackSymmetric.h b/src/TNL/Matrices/EllpackSymmetric.h index b150bc4d9..323772551 100644 --- a/src/TNL/Matrices/EllpackSymmetric.h +++ b/src/TNL/Matrices/EllpackSymmetric.h @@ -31,7 +31,6 @@ class EllpackSymmetric : public Sparse< Real, Device, Index > typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; typedef typename Sparse< RealType, DeviceType, IndexType >::ValuesVector ValuesVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ColumnIndexesVector ColumnIndexesVector; - typedef EllpackSymmetric< Real, Device, Index > ThisType; typedef EllpackSymmetric< Real, Devices::Host, Index > HostType; typedef EllpackSymmetric< Real, Devices::Cuda, Index > CudaType; diff --git a/src/TNL/Matrices/EllpackSymmetricGraph.h b/src/TNL/Matrices/EllpackSymmetricGraph.h index 85c7e49b0..4c56a8716 100644 --- a/src/TNL/Matrices/EllpackSymmetricGraph.h +++ b/src/TNL/Matrices/EllpackSymmetricGraph.h @@ -31,7 +31,6 @@ class EllpackSymmetricGraph : public Sparse< Real, Device, Index > typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; typedef typename Sparse< RealType, DeviceType, IndexType >::ValuesVector ValuesVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ColumnIndexesVector ColumnIndexesVector; - typedef EllpackSymmetricGraph< Real, Device, Index > ThisType; typedef EllpackSymmetricGraph< Real, Devices::Host, Index > HostType; typedef EllpackSymmetricGraph< Real, Devices::Cuda, Index > CudaType; diff --git a/src/TNL/Matrices/Multidiagonal.h b/src/TNL/Matrices/Multidiagonal.h index 969a1e0aa..0496a25a3 100644 --- a/src/TNL/Matrices/Multidiagonal.h +++ b/src/TNL/Matrices/Multidiagonal.h @@ -38,7 +38,6 @@ public: typedef Index IndexType; typedef typename Matrix< Real, Device, Index >::CompressedRowLengthsVector CompressedRowLengthsVector; typedef typename Matrix< Real, Device, Index >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; - typedef Multidiagonal< Real, Device, Index > ThisType; typedef Multidiagonal< Real, Devices::Host, Index > HostType; typedef Multidiagonal< Real, Devices::Cuda, Index > CudaType; typedef Matrix< Real, Device, Index > BaseType; diff --git a/src/TNL/Matrices/SlicedEllpack.h b/src/TNL/Matrices/SlicedEllpack.h index b7302e559..2b207c32b 100644 --- a/src/TNL/Matrices/SlicedEllpack.h +++ b/src/TNL/Matrices/SlicedEllpack.h @@ -68,7 +68,6 @@ public: typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; typedef typename Sparse< RealType, DeviceType, IndexType >::ValuesVector ValuesVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ColumnIndexesVector ColumnIndexesVector; - typedef SlicedEllpack< Real, Device, Index, SliceSize > ThisType; typedef SlicedEllpack< Real, Devices::Host, Index, SliceSize > HostType; typedef SlicedEllpack< Real, Devices::Cuda, Index, SliceSize > CudaType; typedef Sparse< Real, Device, Index > BaseType; diff --git a/src/TNL/Matrices/SlicedEllpackSymmetric.h b/src/TNL/Matrices/SlicedEllpackSymmetric.h index 550df75c4..9e7694de4 100644 --- a/src/TNL/Matrices/SlicedEllpackSymmetric.h +++ b/src/TNL/Matrices/SlicedEllpackSymmetric.h @@ -49,7 +49,6 @@ class SlicedEllpackSymmetric : public Sparse< Real, Device, Index > typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; typedef typename Sparse< RealType, DeviceType, IndexType >::ValuesVector ValuesVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ColumnIndexesVector ColumnIndexesVector; - typedef SlicedEllpackSymmetric< Real, Device, Index > ThisType; typedef SlicedEllpackSymmetric< Real, Devices::Host, Index > HostType; typedef SlicedEllpackSymmetric< Real, Devices::Cuda, Index > CudaType; diff --git a/src/TNL/Matrices/SlicedEllpackSymmetricGraph.h b/src/TNL/Matrices/SlicedEllpackSymmetricGraph.h index 762b0a21e..12019b79d 100644 --- a/src/TNL/Matrices/SlicedEllpackSymmetricGraph.h +++ b/src/TNL/Matrices/SlicedEllpackSymmetricGraph.h @@ -49,7 +49,6 @@ class SlicedEllpackSymmetricGraph : public Sparse< Real, Device, Index > typedef typename Sparse< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; typedef typename Sparse< RealType, DeviceType, IndexType >::ValuesVector ValuesVector; typedef typename Sparse< RealType, DeviceType, IndexType >::ColumnIndexesVector ColumnIndexesVector; - typedef SlicedEllpackSymmetricGraph< Real, Device, Index > ThisType; typedef SlicedEllpackSymmetricGraph< Real, Devices::Host, Index > HostType; typedef SlicedEllpackSymmetricGraph< Real, Devices::Cuda, Index > CudaType; diff --git a/src/TNL/Matrices/Tridiagonal.h b/src/TNL/Matrices/Tridiagonal.h index 153c3bdbc..327d68b9d 100644 --- a/src/TNL/Matrices/Tridiagonal.h +++ b/src/TNL/Matrices/Tridiagonal.h @@ -40,7 +40,6 @@ public: typedef Index IndexType; typedef typename Matrix< Real, Device, Index >::CompressedRowLengthsVector CompressedRowLengthsVector; typedef typename Matrix< Real, Device, Index >::ConstCompressedRowLengthsVectorView ConstCompressedRowLengthsVectorView; - typedef Tridiagonal< Real, Device, Index > ThisType; typedef Tridiagonal< Real, Devices::Host, Index > HostType; typedef Tridiagonal< Real, Devices::Cuda, Index > CudaType; typedef Matrix< Real, Device, Index > BaseType; diff --git a/src/TNL/Matrices/Tridiagonal_impl.h b/src/TNL/Matrices/Tridiagonal_impl.h index faee48154..157145e14 100644 --- a/src/TNL/Matrices/Tridiagonal_impl.h +++ b/src/TNL/Matrices/Tridiagonal_impl.h @@ -509,7 +509,7 @@ void Tridiagonal< Real, Device, Index >::getTransposition( const Tridiagonal< Re if( std::is_same< Device, Devices::Cuda >::value ) { #ifdef HAVE_CUDA - ThisType* kernel_this = Devices::Cuda::passToDevice( *this ); + Tridiagonal* kernel_this = Devices::Cuda::passToDevice( *this ); typedef Tridiagonal< Real2, Device, Index2 > InMatrixType; InMatrixType* kernel_inMatrix = Devices::Cuda::passToDevice( matrix ); dim3 cudaBlockSize( 256 ), cudaGridSize( Devices::Cuda::getMaxGridSize() ); diff --git a/src/TNL/Meshes/DummyMesh.h b/src/TNL/Meshes/DummyMesh.h index 96cd7e3a4..04a49ed01 100644 --- a/src/TNL/Meshes/DummyMesh.h +++ b/src/TNL/Meshes/DummyMesh.h @@ -26,7 +26,6 @@ public: typedef Real RealType; typedef Device DeviceType; typedef Index IndexType; - typedef DummyMesh< Real, Device, Index > ThisType; constexpr static int getMeshDimension() { return 1; } diff --git a/src/TNL/Meshes/GridDetails/Grid1D.h b/src/TNL/Meshes/GridDetails/Grid1D.h index e4986c9fa..9c4b17246 100644 --- a/src/TNL/Meshes/GridDetails/Grid1D.h +++ b/src/TNL/Meshes/GridDetails/Grid1D.h @@ -36,9 +36,8 @@ class Grid< 1, Real, Device, Index > : public Object typedef Containers::StaticVector< 1, Index > CoordinatesType; typedef Grid< 1, Real, Devices::Host, Index > HostType; typedef Grid< 1, Real, Devices::Cuda, Index > CudaType; - typedef Grid< 1, Real, Device, Index > ThisType; - typedef DistributedMeshes::DistributedMesh DistributedMeshType; + typedef DistributedMeshes::DistributedMesh DistributedMeshType; // TODO: deprecated and to be removed (GlobalIndexType shall be used instead) typedef Index IndexType; @@ -50,7 +49,7 @@ class Grid< 1, Real, Device, Index > : public Object template< int EntityDimension, typename Config = GridEntityCrossStencilStorage< 1 > > - using EntityType = GridEntity< ThisType, EntityDimension, Config >; + using EntityType = GridEntity< Grid, EntityDimension, Config >; typedef EntityType< getMeshDimension(), GridEntityCrossStencilStorage< 1 > > Cell; typedef EntityType< 0 > Face; diff --git a/src/TNL/Meshes/GridDetails/Grid1D_impl.h b/src/TNL/Meshes/GridDetails/Grid1D_impl.h index 5f3e919c6..7519561f3 100644 --- a/src/TNL/Meshes/GridDetails/Grid1D_impl.h +++ b/src/TNL/Meshes/GridDetails/Grid1D_impl.h @@ -231,7 +231,7 @@ getEntity( const IndexType& entityIndex ) const static_assert( Entity::getEntityDimension() <= 1 && Entity::getEntityDimension() >= 0, "Wrong grid entity dimensions." ); - return GridEntityGetter< ThisType, Entity >::getEntity( *this, entityIndex ); + return GridEntityGetter< Grid, Entity >::getEntity( *this, entityIndex ); } template< typename Real, @@ -246,7 +246,7 @@ getEntityIndex( const Entity& entity ) const static_assert( Entity::getEntityDimension() <= 1 && Entity::getEntityDimension() >= 0, "Wrong grid entity dimensions." ); - return GridEntityGetter< ThisType, Entity >::getEntityIndex( *this, entity ); + return GridEntityGetter< Grid, Entity >::getEntityIndex( *this, entity ); } template< typename Real, diff --git a/src/TNL/Meshes/GridDetails/Grid2D.h b/src/TNL/Meshes/GridDetails/Grid2D.h index 59ad153e2..ddb752e16 100644 --- a/src/TNL/Meshes/GridDetails/Grid2D.h +++ b/src/TNL/Meshes/GridDetails/Grid2D.h @@ -36,9 +36,8 @@ class Grid< 2, Real, Device, Index > : public Object typedef Containers::StaticVector< 2, Index > CoordinatesType; typedef Grid< 2, Real, Devices::Host, Index > HostType; typedef Grid< 2, Real, Devices::Cuda, Index > CudaType; - typedef Grid< 2, Real, Device, Index > ThisType; - typedef DistributedMeshes::DistributedMesh DistributedMeshType; + typedef DistributedMeshes::DistributedMesh DistributedMeshType; // TODO: deprecated and to be removed (GlobalIndexType shall be used instead) typedef Index IndexType; @@ -47,7 +46,7 @@ class Grid< 2, Real, Device, Index > : public Object template< int EntityDimension, typename Config = GridEntityCrossStencilStorage< 1 > > - using EntityType = GridEntity< ThisType, EntityDimension, Config >; + using EntityType = GridEntity< Grid, EntityDimension, Config >; typedef EntityType< getMeshDimension(), GridEntityCrossStencilStorage< 1 > > Cell; typedef EntityType< getMeshDimension() - 1 > Face; diff --git a/src/TNL/Meshes/GridDetails/Grid2D_impl.h b/src/TNL/Meshes/GridDetails/Grid2D_impl.h index 42f2601b6..78a339b5b 100644 --- a/src/TNL/Meshes/GridDetails/Grid2D_impl.h +++ b/src/TNL/Meshes/GridDetails/Grid2D_impl.h @@ -288,7 +288,7 @@ getEntity( const IndexType& entityIndex ) const static_assert( Entity::getEntityDimension() <= 2 && Entity::getEntityDimension() >= 0, "Wrong grid entity dimensions." ); - return GridEntityGetter< ThisType, Entity >::getEntity( *this, entityIndex ); + return GridEntityGetter< Grid, Entity >::getEntity( *this, entityIndex ); } template< typename Real, @@ -303,7 +303,7 @@ getEntityIndex( const Entity& entity ) const static_assert( Entity::getEntityDimension() <= 2 && Entity::getEntityDimension() >= 0, "Wrong grid entity dimensions." ); - return GridEntityGetter< ThisType, Entity >::getEntityIndex( *this, entity ); + return GridEntityGetter< Grid, Entity >::getEntityIndex( *this, entity ); } template< typename Real, diff --git a/src/TNL/Meshes/GridDetails/Grid3D.h b/src/TNL/Meshes/GridDetails/Grid3D.h index 232c36805..71b80cb6c 100644 --- a/src/TNL/Meshes/GridDetails/Grid3D.h +++ b/src/TNL/Meshes/GridDetails/Grid3D.h @@ -35,9 +35,8 @@ class Grid< 3, Real, Device, Index > : public Object typedef Containers::StaticVector< 3, Index > CoordinatesType; typedef Grid< 3, Real, Devices::Host, Index > HostType; typedef Grid< 3, Real, Devices::Cuda, Index > CudaType; - typedef Grid< 3, Real, Device, Index > ThisType; - typedef DistributedMeshes::DistributedMesh DistributedMeshType; + typedef DistributedMeshes::DistributedMesh DistributedMeshType; // TODO: deprecated and to be removed (GlobalIndexType shall be used instead) typedef Index IndexType; @@ -46,7 +45,7 @@ class Grid< 3, Real, Device, Index > : public Object template< int EntityDimension, typename Config = GridEntityCrossStencilStorage< 1 > > - using EntityType = GridEntity< ThisType, EntityDimension, Config >; + using EntityType = GridEntity< Grid, EntityDimension, Config >; typedef EntityType< getMeshDimension(), GridEntityCrossStencilStorage< 1 > > Cell; typedef EntityType< getMeshDimension() - 1 > Face; diff --git a/src/TNL/Meshes/GridDetails/Grid3D_impl.h b/src/TNL/Meshes/GridDetails/Grid3D_impl.h index 4908ad707..dbd5fcf47 100644 --- a/src/TNL/Meshes/GridDetails/Grid3D_impl.h +++ b/src/TNL/Meshes/GridDetails/Grid3D_impl.h @@ -359,7 +359,7 @@ getEntity( const IndexType& entityIndex ) const static_assert( Entity::getEntityDimension() <= 3 && Entity::getEntityDimension() >= 0, "Wrong grid entity dimensions." ); - return GridEntityGetter< ThisType, Entity >::getEntity( *this, entityIndex ); + return GridEntityGetter< Grid, Entity >::getEntity( *this, entityIndex ); } template< typename Real, @@ -374,7 +374,7 @@ getEntityIndex( const Entity& entity ) const static_assert( Entity::getEntityDimension() <= 3 && Entity::getEntityDimension() >= 0, "Wrong grid entity dimensions." ); - return GridEntityGetter< ThisType, Entity >::getEntityIndex( *this, entity ); + return GridEntityGetter< Grid, Entity >::getEntityIndex( *this, entity ); } template< typename Real, diff --git a/src/TNL/Meshes/GridDetails/GridEntity_impl.h b/src/TNL/Meshes/GridDetails/GridEntity_impl.h index 7c3820f6b..fb5548f35 100644 --- a/src/TNL/Meshes/GridDetails/GridEntity_impl.h +++ b/src/TNL/Meshes/GridDetails/GridEntity_impl.h @@ -231,7 +231,7 @@ bool GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, EntityDimension, Config >:: isBoundaryEntity() const { - return BoundaryGridEntityChecker< ThisType >::isBoundaryEntity( *this ); + return BoundaryGridEntityChecker< GridEntity >::isBoundaryEntity( *this ); } template< int Dimension, @@ -245,7 +245,7 @@ typename Meshes::Grid< Dimension, Real, Device, Index >::PointType GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, EntityDimension, Config >:: getCenter() const { - return GridEntityCenterGetter< ThisType >::getEntityCenter( *this ); + return GridEntityCenterGetter< GridEntity >::getEntityCenter( *this ); } template< int Dimension, @@ -443,7 +443,7 @@ bool GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, Dimension, Config >:: isBoundaryEntity() const { - return BoundaryGridEntityChecker< ThisType >::isBoundaryEntity( *this ); + return BoundaryGridEntityChecker< GridEntity >::isBoundaryEntity( *this ); } template< int Dimension, @@ -456,7 +456,7 @@ typename Meshes::Grid< Dimension, Real, Device, Index >::PointType GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, Dimension, Config >:: getCenter() const { - return GridEntityCenterGetter< ThisType >::getEntityCenter( *this ); + return GridEntityCenterGetter< GridEntity >::getEntityCenter( *this ); } template< int Dimension, @@ -659,7 +659,7 @@ bool GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, 0, Config >:: isBoundaryEntity() const { - return BoundaryGridEntityChecker< ThisType >::isBoundaryEntity( *this ); + return BoundaryGridEntityChecker< GridEntity >::isBoundaryEntity( *this ); } template< int Dimension, @@ -672,7 +672,7 @@ typename Meshes::Grid< Dimension, Real, Device, Index >::PointType GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, 0, Config >:: getCenter() const { - return GridEntityCenterGetter< ThisType >::getEntityCenter( *this ); + return GridEntityCenterGetter< GridEntity >::getEntityCenter( *this ); } template< int Dimension, diff --git a/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter1D_impl.h b/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter1D_impl.h index 04f61c51d..737d38c26 100644 --- a/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter1D_impl.h +++ b/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter1D_impl.h @@ -117,7 +117,6 @@ class NeighborGridEntityGetter< typedef Index IndexType; typedef typename GridType::CoordinatesType CoordinatesType; typedef GridEntityGetter< GridType, NeighborGridEntityType > GridEntityGetterType; - typedef NeighborGridEntityGetter< GridEntityType, 1, StencilStorage > ThisType; static constexpr int stencilSize = Config::getStencilSize(); @@ -167,7 +166,7 @@ class NeighborGridEntityGetter< public: __cuda_callable__ - static void exec( ThisType& neighborEntityGetter, const IndexType& entityIndex ) + static void exec( NeighborGridEntityGetter& neighborEntityGetter, const IndexType& entityIndex ) { neighborEntityGetter.stencil[ index + stencilSize ] = entityIndex + index; } diff --git a/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter2D_impl.h b/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter2D_impl.h index b377dc7ae..5332eed97 100644 --- a/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter2D_impl.h +++ b/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter2D_impl.h @@ -120,8 +120,6 @@ class NeighborGridEntityGetter< typedef typename GridType::CoordinatesType CoordinatesType; typedef GridEntityGetter< GridType, NeighborGridEntityType > GridEntityGetterType; typedef GridEntityStencilStorageTag< GridEntityCrossStencil > StencilStorage; - typedef NeighborGridEntityGetter< GridEntityType, 2, StencilStorage > ThisType; - static constexpr int stencilSize = Config::getStencilSize(); @@ -177,7 +175,7 @@ class NeighborGridEntityGetter< public: __cuda_callable__ - static void exec( ThisType& neighborEntityGetter, const IndexType& entityIndex ) + static void exec( NeighborGridEntityGetter& neighborEntityGetter, const IndexType& entityIndex ) { neighborEntityGetter.stencilX[ index + stencilSize ] = entityIndex + index; } @@ -189,7 +187,7 @@ class NeighborGridEntityGetter< public: __cuda_callable__ - static void exec( ThisType& neighborEntityGetter, const IndexType& entityIndex ) + static void exec( NeighborGridEntityGetter& neighborEntityGetter, const IndexType& entityIndex ) { neighborEntityGetter.stencilY[ index + stencilSize ] = entityIndex + index * neighborEntityGetter.entity.getMesh().getDimensions().x(); diff --git a/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter3D_impl.h b/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter3D_impl.h index 0c8b49aa1..78955a6c0 100644 --- a/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter3D_impl.h +++ b/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter3D_impl.h @@ -124,7 +124,6 @@ class NeighborGridEntityGetter< typedef typename GridType::CoordinatesType CoordinatesType; typedef GridEntityGetter< GridType, NeighborGridEntityType > GridEntityGetterType; typedef GridEntityStencilStorageTag< GridEntityCrossStencil > StencilStorage; - typedef NeighborGridEntityGetter< GridEntityType, 3, StencilStorage > ThisType; static constexpr int stencilSize = Config::getStencilSize(); @@ -187,7 +186,7 @@ class NeighborGridEntityGetter< public: __cuda_callable__ - static void exec( ThisType& neighborEntityGetter, const IndexType& entityIndex ) + static void exec( NeighborGridEntityGetter& neighborEntityGetter, const IndexType& entityIndex ) { neighborEntityGetter.stencilX[ index + stencilSize ] = entityIndex + index; } @@ -199,7 +198,7 @@ class NeighborGridEntityGetter< public: __cuda_callable__ - static void exec( ThisType& neighborEntityGetter, const IndexType& entityIndex ) + static void exec( NeighborGridEntityGetter& neighborEntityGetter, const IndexType& entityIndex ) { neighborEntityGetter.stencilY[ index + stencilSize ] = entityIndex + index * neighborEntityGetter.entity.getMesh().getDimensions().x(); @@ -212,7 +211,7 @@ class NeighborGridEntityGetter< public: __cuda_callable__ - static void exec( ThisType& neighborEntityGetter, const IndexType& entityIndex ) + static void exec( NeighborGridEntityGetter& neighborEntityGetter, const IndexType& entityIndex ) { neighborEntityGetter.stencilZ[ index + stencilSize ] = entityIndex + index * neighborEntityGetter.entity.getMesh().cellZNeighborsStep; diff --git a/src/TNL/Meshes/GridEntity.h b/src/TNL/Meshes/GridEntity.h index abad0a57d..80041a753 100644 --- a/src/TNL/Meshes/GridEntity.h +++ b/src/TNL/Meshes/GridEntity.h @@ -57,10 +57,9 @@ class GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, EntityDimensio typedef Containers::StaticVector< getMeshDimension(), IndexType > EntityOrientationType; typedef Containers::StaticVector< getMeshDimension(), IndexType > EntityBasisType; - typedef GridEntity< GridType, EntityDimension, Config > ThisType; typedef typename GridType::PointType PointType; - typedef NeighborGridEntitiesStorage< ThisType, Config > NeighborGridEntitiesStorageType; + typedef NeighborGridEntitiesStorage< GridEntity, Config > NeighborGridEntitiesStorageType; template< int NeighborEntityDimension = getEntityDimension() > using NeighborEntities = @@ -146,9 +145,9 @@ class GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, EntityDimensio //__cuda_callable__ inline //GridEntity(); - friend class BoundaryGridEntityChecker< ThisType >; + friend class BoundaryGridEntityChecker< GridEntity >; - friend class GridEntityCenterGetter< ThisType >; + friend class GridEntityCenterGetter< GridEntity >; }; /**** @@ -178,8 +177,7 @@ class GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, Dimension, Con typedef Containers::StaticVector< getMeshDimension(), IndexType > EntityOrientationType; typedef Containers::StaticVector< getMeshDimension(), IndexType > EntityBasisType; - typedef GridEntity< GridType, Dimension, Config > ThisType; - typedef NeighborGridEntitiesStorage< ThisType, Config > NeighborGridEntitiesStorageType; + typedef NeighborGridEntitiesStorage< GridEntity, Config > NeighborGridEntitiesStorageType; template< int NeighborEntityDimension = getEntityDimension() > using NeighborEntities = @@ -265,9 +263,9 @@ class GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, Dimension, Con //__cuda_callable__ inline //GridEntity(); - friend class BoundaryGridEntityChecker< ThisType >; + friend class BoundaryGridEntityChecker< GridEntity >; - friend class GridEntityCenterGetter< ThisType >; + friend class GridEntityCenterGetter< GridEntity >; }; /**** @@ -296,8 +294,7 @@ class GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, 0, Config > typedef Containers::StaticVector< getMeshDimension(), IndexType > EntityOrientationType; typedef Containers::StaticVector< getMeshDimension(), IndexType > EntityBasisType; - typedef GridEntity< GridType, 0, Config > ThisType; - typedef NeighborGridEntitiesStorage< ThisType, Config > NeighborGridEntitiesStorageType; + typedef NeighborGridEntitiesStorage< GridEntity, Config > NeighborGridEntitiesStorageType; template< int NeighborEntityDimension = getEntityDimension() > using NeighborEntities = @@ -385,9 +382,9 @@ class GridEntity< Meshes::Grid< Dimension, Real, Device, Index >, 0, Config > NeighborGridEntitiesStorageType neighborEntitiesStorage; - friend class BoundaryGridEntityChecker< ThisType >; + friend class BoundaryGridEntityChecker< GridEntity >; - friend class GridEntityCenterGetter< ThisType >; + friend class GridEntityCenterGetter< GridEntity >; }; } // namespace Meshes diff --git a/src/TNL/Operators/FunctionInverseOperator.h b/src/TNL/Operators/FunctionInverseOperator.h index f202d870c..1265f3b70 100644 --- a/src/TNL/Operators/FunctionInverseOperator.h +++ b/src/TNL/Operators/FunctionInverseOperator.h @@ -31,9 +31,7 @@ class FunctionInverseOperator typedef OperatorT OperatorType; typedef typename OperatorType::RealType RealType; typedef typename OperatorType::IndexType IndexType; - typedef FunctionInverseOperator< OperatorT > ThisType; - typedef ThisType ExactOperatorType; - + typedef FunctionInverseOperator ExactOperatorType; FunctionInverseOperator( const OperatorType& operator_ ) : operator_( operator_ ) {}; diff --git a/src/TNL/Operators/NeumannBoundaryConditions.h b/src/TNL/Operators/NeumannBoundaryConditions.h index 15cfbe85c..a46545cd1 100644 --- a/src/TNL/Operators/NeumannBoundaryConditions.h +++ b/src/TNL/Operators/NeumannBoundaryConditions.h @@ -110,7 +110,6 @@ class NeumannBoundaryConditions< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; typedef Containers::StaticVector< 1, RealType > PointType; typedef typename MeshType::CoordinatesType CoordinatesType; - typedef NeumannBoundaryConditions< MeshType, Function, Real, Index > ThisType; typedef NeumannBoundaryConditionsBase< Function > BaseType; template< typename EntityType, @@ -203,7 +202,6 @@ class NeumannBoundaryConditions< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; typedef Containers::StaticVector< 2, RealType > PointType; typedef typename MeshType::CoordinatesType CoordinatesType; - typedef NeumannBoundaryConditions< MeshType, Function, Real, Index > ThisType; typedef NeumannBoundaryConditionsBase< Function > BaseType; @@ -323,7 +321,6 @@ class NeumannBoundaryConditions< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; typedef Containers::StaticVector< 3, RealType > PointType; typedef typename MeshType::CoordinatesType CoordinatesType; - typedef NeumannBoundaryConditions< MeshType, Function, Real, Index > ThisType; typedef NeumannBoundaryConditionsBase< Function > BaseType; template< typename EntityType, diff --git a/src/TNL/Pointers/DevicePointer.h b/src/TNL/Pointers/DevicePointer.h index 26ff692e4..867f18fcb 100644 --- a/src/TNL/Pointers/DevicePointer.h +++ b/src/TNL/Pointers/DevicePointer.h @@ -56,7 +56,6 @@ class DevicePointer< Object, Devices::Host > : public SmartPointer typedef Object ObjectType; typedef Devices::Host DeviceType; - typedef DevicePointer< Object, Devices::Host > ThisType; explicit DevicePointer( ObjectType& obj ) : pointer( nullptr ) @@ -65,7 +64,7 @@ class DevicePointer< Object, Devices::Host > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - DevicePointer( const ThisType& pointer ) + DevicePointer( const DevicePointer& pointer ) : pointer( pointer.pointer ) { } @@ -79,7 +78,7 @@ class DevicePointer< Object, Devices::Host > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - DevicePointer( ThisType&& pointer ) + DevicePointer( DevicePointer&& pointer ) : pointer( pointer.pointer ) { pointer.pointer = nullptr; @@ -141,7 +140,7 @@ class DevicePointer< Object, Devices::Host > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( const ThisType& ptr ) + const DevicePointer& operator=( const DevicePointer& ptr ) { this->pointer = ptr.pointer; return *this; @@ -150,14 +149,14 @@ class DevicePointer< Object, Devices::Host > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( const DevicePointer< Object_, DeviceType >& ptr ) + const DevicePointer& operator=( const DevicePointer< Object_, DeviceType >& ptr ) { this->pointer = ptr.pointer; return *this; } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( ThisType&& ptr ) + const DevicePointer& operator=( DevicePointer&& ptr ) { this->pointer = ptr.pointer; ptr.pointer = nullptr; @@ -167,7 +166,7 @@ class DevicePointer< Object, Devices::Host > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( DevicePointer< Object_, DeviceType >&& ptr ) + const DevicePointer& operator=( DevicePointer< Object_, DeviceType >&& ptr ) { this->pointer = ptr.pointer; ptr.pointer = nullptr; @@ -212,7 +211,6 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer typedef Object ObjectType; typedef Devices::Cuda DeviceType; - typedef DevicePointer< Object, Devices::Cuda > ThisType; explicit DevicePointer( ObjectType& obj ) : pointer( nullptr ), @@ -223,7 +221,7 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - DevicePointer( const ThisType& pointer ) + DevicePointer( const DevicePointer& pointer ) : pointer( pointer.pointer ), pd( (PointerData*) pointer.pd ), cuda_pointer( pointer.cuda_pointer ) @@ -243,7 +241,7 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - DevicePointer( ThisType&& pointer ) + DevicePointer( DevicePointer&& pointer ) : pointer( pointer.pointer ), pd( (PointerData*) pointer.pd ), cuda_pointer( pointer.cuda_pointer ) @@ -332,7 +330,7 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( const ThisType& ptr ) + const DevicePointer& operator=( const DevicePointer& ptr ) { this->free(); this->pointer = ptr.pointer; @@ -345,7 +343,7 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( const DevicePointer< Object_, DeviceType >& ptr ) + const DevicePointer& operator=( const DevicePointer< Object_, DeviceType >& ptr ) { this->free(); this->pointer = ptr.pointer; @@ -356,7 +354,7 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( ThisType&& ptr ) + const DevicePointer& operator=( DevicePointer&& ptr ) { this->free(); this->pointer = ptr.pointer; @@ -371,7 +369,7 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( DevicePointer< Object_, DeviceType >&& ptr ) + const DevicePointer& operator=( DevicePointer< Object_, DeviceType >&& ptr ) { this->free(); this->pointer = ptr.pointer; @@ -496,7 +494,6 @@ class DevicePointer< Object, Devices::MIC > : public SmartPointer typedef Object ObjectType; typedef Devices::MIC DeviceType; - typedef DevicePointer< Object, Devices::MIC > ThisType; explicit DevicePointer( ObjectType& obj ) : pointer( nullptr ), @@ -507,7 +504,7 @@ class DevicePointer< Object, Devices::MIC > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - DevicePointer( const ThisType& pointer ) + DevicePointer( const DevicePointer& pointer ) : pointer( pointer.pointer ), pd( (PointerData*) pointer.pd ), mic_pointer( pointer.mic_pointer ) @@ -527,7 +524,7 @@ class DevicePointer< Object, Devices::MIC > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - DevicePointer( ThisType&& pointer ) + DevicePointer( DevicePointer&& pointer ) : pointer( pointer.pointer ), pd( (PointerData*) pointer.pd ), mic_pointer( pointer.mic_pointer ) @@ -609,7 +606,7 @@ class DevicePointer< Object, Devices::MIC > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( const ThisType& ptr ) + const DevicePointer& operator=( const DevicePointer& ptr ) { this->free(); this->pointer = ptr.pointer; @@ -622,7 +619,7 @@ class DevicePointer< Object, Devices::MIC > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( const DevicePointer< Object_, DeviceType >& ptr ) + const DevicePointer& operator=( const DevicePointer< Object_, DeviceType >& ptr ) { this->free(); this->pointer = ptr.pointer; @@ -633,7 +630,7 @@ class DevicePointer< Object, Devices::MIC > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( ThisType&& ptr ) + const DevicePointer& operator=( DevicePointer&& ptr ) { this->free(); this->pointer = ptr.pointer; @@ -648,7 +645,7 @@ class DevicePointer< Object, Devices::MIC > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( DevicePointer< Object_, DeviceType >&& ptr ) + const DevicePointer& operator=( DevicePointer< Object_, DeviceType >&& ptr ) { this->free(); this->pointer = ptr.pointer; diff --git a/src/TNL/Pointers/SharedPointerCuda.h b/src/TNL/Pointers/SharedPointerCuda.h index 42e46b257..2cf1b297f 100644 --- a/src/TNL/Pointers/SharedPointerCuda.h +++ b/src/TNL/Pointers/SharedPointerCuda.h @@ -68,7 +68,6 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer using ObjectType = Object; using DeviceType = Devices::Cuda; - using ThisType = SharedPointer< Object, Devices::Cuda >; SharedPointer( std::nullptr_t ) : pd( nullptr ) @@ -85,7 +84,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - SharedPointer( const ThisType& pointer ) + SharedPointer( const SharedPointer& pointer ) : pd( (PointerData*) pointer.pd ) { this->pd->counter += 1; @@ -101,7 +100,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - SharedPointer( ThisType&& pointer ) + SharedPointer( SharedPointer&& pointer ) : pd( (PointerData*) pointer.pd ) { pointer.pd = nullptr; @@ -194,7 +193,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( const ThisType& ptr ) + const SharedPointer& operator=( const SharedPointer& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -206,7 +205,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( const SharedPointer< Object_, DeviceType >& ptr ) + const SharedPointer& operator=( const SharedPointer< Object_, DeviceType >& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -216,7 +215,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( ThisType&& ptr ) + const SharedPointer& operator=( SharedPointer&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -227,7 +226,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( SharedPointer< Object_, DeviceType >&& ptr ) + const SharedPointer& operator=( SharedPointer< Object_, DeviceType >&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -245,7 +244,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer this->free(); } - void swap( ThisType& ptr2 ) + void swap( SharedPointer& ptr2 ) { std::swap( this->pd, ptr2.pd ); } @@ -322,7 +321,6 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer using ObjectType = Object; using DeviceType = Devices::Cuda; - using ThisType = SharedPointer< Object, Devices::Cuda >; SharedPointer( std::nullptr_t ) : pd( nullptr ), @@ -338,7 +336,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - SharedPointer( const ThisType& pointer ) + SharedPointer( const SharedPointer& pointer ) : pd( (PointerData*) pointer.pd ), cuda_pointer( pointer.cuda_pointer ) { @@ -356,7 +354,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - SharedPointer( ThisType&& pointer ) + SharedPointer( SharedPointer&& pointer ) : pd( (PointerData*) pointer.pd ), cuda_pointer( pointer.cuda_pointer ) { @@ -472,7 +470,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( const ThisType& ptr ) + const SharedPointer& operator=( const SharedPointer& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -488,7 +486,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( const SharedPointer< Object_, DeviceType >& ptr ) + const SharedPointer& operator=( const SharedPointer< Object_, DeviceType >& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -502,7 +500,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( ThisType&& ptr ) + const SharedPointer& operator=( SharedPointer&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -518,7 +516,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( SharedPointer< Object_, DeviceType >&& ptr ) + const SharedPointer& operator=( SharedPointer< Object_, DeviceType >&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -559,7 +557,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer this->free(); } - void swap( ThisType& ptr2 ) + void swap( SharedPointer& ptr2 ) { std::swap( this->pd, ptr2.pd ); std::swap( this->cuda_pointer, ptr2.cuda_pointer ); diff --git a/src/TNL/Pointers/SharedPointerHost.h b/src/TNL/Pointers/SharedPointerHost.h index f6c45cf71..48d83c938 100644 --- a/src/TNL/Pointers/SharedPointerHost.h +++ b/src/TNL/Pointers/SharedPointerHost.h @@ -44,7 +44,6 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer using ObjectType = Object; using DeviceType = Devices::Host; - using ThisType = SharedPointer< Object, Devices::Host >; SharedPointer( std::nullptr_t ) : pd( nullptr ) @@ -61,7 +60,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - SharedPointer( const ThisType& pointer ) + SharedPointer( const SharedPointer& pointer ) : pd( (PointerData*) pointer.pd ) { this->pd->counter += 1; @@ -77,7 +76,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - SharedPointer( ThisType&& pointer ) + SharedPointer( SharedPointer&& pointer ) : pd( (PointerData*) pointer.pd ) { pointer.pd = nullptr; @@ -170,7 +169,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( const ThisType& ptr ) + const SharedPointer& operator=( const SharedPointer& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -182,7 +181,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( const SharedPointer< Object_, DeviceType >& ptr ) + const SharedPointer& operator=( const SharedPointer< Object_, DeviceType >& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -192,7 +191,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( ThisType&& ptr ) + const SharedPointer& operator=( SharedPointer&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -203,7 +202,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( SharedPointer< Object_, DeviceType >&& ptr ) + const SharedPointer& operator=( SharedPointer< Object_, DeviceType >&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -221,11 +220,11 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer this->free(); } - void swap( ThisType& ptr2 ) + void swap( SharedPointer& ptr2 ) { std::swap( this->pd, ptr2.pd ); } - + ~SharedPointer() { this->free(); diff --git a/src/TNL/Pointers/SharedPointerMic.h b/src/TNL/Pointers/SharedPointerMic.h index 3acea10bc..0e19e78b2 100644 --- a/src/TNL/Pointers/SharedPointerMic.h +++ b/src/TNL/Pointers/SharedPointerMic.h @@ -45,7 +45,6 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer using ObjectType = Object; using DeviceType = Devices::MIC; - using ThisType = SharedPointer< Object, Devices::MIC >; SharedPointer( std::nullptr_t ) : pd( nullptr ), @@ -61,7 +60,7 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - SharedPointer( const ThisType& pointer ) + SharedPointer( const SharedPointer& pointer ) : pd( (PointerData*) pointer.pd ), mic_pointer( pointer.mic_pointer ) { @@ -79,7 +78,7 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer } // this is needed only to avoid the default compiler-generated constructor - SharedPointer( ThisType&& pointer ) + SharedPointer( SharedPointer&& pointer ) : pd( (PointerData*) pointer.pd ), mic_pointer( pointer.mic_pointer ) { @@ -188,7 +187,7 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( const ThisType& ptr ) + const SharedPointer& operator=( const SharedPointer& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -204,7 +203,7 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( const SharedPointer< Object_, DeviceType >& ptr ) + const SharedPointer& operator=( const SharedPointer< Object_, DeviceType >& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -218,7 +217,7 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer } // this is needed only to avoid the default compiler-generated operator - const ThisType& operator=( ThisType&& ptr ) + const SharedPointer& operator=( SharedPointer&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -234,7 +233,7 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer // conditional operator for non-const -> const data template< typename Object_, typename = typename Enabler< Object_ >::type > - const ThisType& operator=( SharedPointer< Object_, DeviceType >&& ptr ) + const SharedPointer& operator=( SharedPointer< Object_, DeviceType >&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; @@ -272,7 +271,7 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer this->free(); } - void swap( ThisType& ptr2 ) + void swap( SharedPointer& ptr2 ) { std::swap( this->pd, ptr2.pd ); std::swap( this->mic_pointer, ptr2.mic_pointer ); diff --git a/src/TNL/Pointers/UniquePointer.h b/src/TNL/Pointers/UniquePointer.h index 279f45356..c8efd5afe 100644 --- a/src/TNL/Pointers/UniquePointer.h +++ b/src/TNL/Pointers/UniquePointer.h @@ -35,7 +35,6 @@ class UniquePointer< Object, Devices::Host > : public SmartPointer typedef Object ObjectType; typedef Devices::Host DeviceType; - typedef UniquePointer< Object, Devices::Host > ThisType; UniquePointer( std::nullptr_t ) : pointer( nullptr ) @@ -97,7 +96,7 @@ class UniquePointer< Object, Devices::Host > : public SmartPointer return *( this->pointer ); } - const ThisType& operator=( ThisType& ptr ) + const UniquePointer& operator=( UniquePointer& ptr ) { if( this->pointer ) delete this->pointer; @@ -106,7 +105,7 @@ class UniquePointer< Object, Devices::Host > : public SmartPointer return *this; } - const ThisType& operator=( ThisType&& ptr ) + const UniquePointer& operator=( UniquePointer&& ptr ) { return this->operator=( ptr ); } @@ -135,7 +134,6 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer typedef Object ObjectType; typedef Devices::Cuda DeviceType; - typedef UniquePointer< Object, Devices::Cuda > ThisType; UniquePointer( std::nullptr_t ) : pd( nullptr ), @@ -215,7 +213,7 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer return *( this->cuda_pointer ); } - const ThisType& operator=( ThisType& ptr ) + const UniquePointer& operator=( UniquePointer& ptr ) { this->free(); this->pd = ptr.pd; @@ -225,7 +223,7 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer return *this; } - const ThisType& operator=( ThisType&& ptr ) + const UniquePointer& operator=( UniquePointer&& ptr ) { return this->operator=( ptr ); } @@ -320,7 +318,6 @@ class UniquePointer< Object, Devices::MIC > : public SmartPointer typedef Object ObjectType; typedef Devices::MIC DeviceType; - typedef UniquePointer< Object, Devices::MIC > ThisType; UniquePointer( std::nullptr_t ) : pd( nullptr ), @@ -393,7 +390,7 @@ class UniquePointer< Object, Devices::MIC > : public SmartPointer return *( this->mic_pointer ); } - const ThisType& operator=( ThisType& ptr ) + const UniquePointer& operator=( UniquePointer& ptr ) { this->free(); this->pd = ptr.pd; @@ -403,7 +400,7 @@ class UniquePointer< Object, Devices::MIC > : public SmartPointer return *this; } - const ThisType& operator=( ThisType&& ptr ) + const UniquePointer& operator=( UniquePointer&& ptr ) { return this->operator=( ptr ); } -- GitLab From 803bb734d3e463df8037699bf00d9198ef3e01e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 12 Apr 2019 12:59:07 +0200 Subject: [PATCH 16/30] Added missing ASSERT_NO_THROW macros to tests --- src/TNL/Object.hpp | 2 - src/UnitTests/Containers/ArrayTest.h | 24 ++++----- src/UnitTests/Containers/StaticArrayTest.cpp | 12 ++--- src/UnitTests/FileTest.h | 52 +++++++++---------- src/UnitTests/Matrices/DenseMatrixTest.h | 4 +- src/UnitTests/Matrices/SparseMatrixTest.hpp | 6 +-- src/UnitTests/Meshes/MeshTest.h | 12 ++--- src/UnitTests/ObjectTest.cpp | 22 ++++---- src/UnitTests/SaveAndLoadMeshfunctionTest.cpp | 24 ++++----- src/UnitTests/StringTest.cpp | 10 ++-- 10 files changed, 83 insertions(+), 85 deletions(-) diff --git a/src/TNL/Object.hpp b/src/TNL/Object.hpp index 1e83f036f..92d33626d 100644 --- a/src/TNL/Object.hpp +++ b/src/TNL/Object.hpp @@ -166,6 +166,4 @@ inline void loadHeader( File& file, String& type ) file >> type; } - - } // namespace TNL diff --git a/src/UnitTests/Containers/ArrayTest.h b/src/UnitTests/Containers/ArrayTest.h index 573c79f36..62bf493cb 100644 --- a/src/UnitTests/Containers/ArrayTest.h +++ b/src/UnitTests/Containers/ArrayTest.h @@ -479,11 +479,11 @@ TYPED_TEST( ArrayTest, SaveAndLoad ) for( int i = 0; i < 100; i ++ ) v.setElement( i, 3.14147 ); File file; - file.open( "test-file.tnl", File::Mode::Out ); - v.save( file ); - file.close(); - file.open( "test-file.tnl", File::Mode::In ); - u.load( file ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( v.save( file ) ); + ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( u.load( file ) ); EXPECT_EQ( u, v ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); @@ -498,23 +498,23 @@ TYPED_TEST( ArrayTest, boundLoad ) for( int i = 0; i < 100; i ++ ) v.setElement( i, 3.14147 ); File file; - file.open( "test-file.tnl", File::Mode::Out ); - v.save( file ); - file.close(); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( v.save( file ) ); + ASSERT_NO_THROW( file.close() ); w.setSize( 100 ); auto u = w.getView(); - file.open( "test-file.tnl", File::Mode::In ); - u.load( file ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( u.load( file ) ); EXPECT_EQ( u, v ); EXPECT_EQ( u.getData(), w.getData() ); ArrayType z( 50 ); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); EXPECT_ANY_THROW( z.boundLoad( file ) ); v.reset(); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); EXPECT_NO_THROW( v.boundLoad( file ) ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); diff --git a/src/UnitTests/Containers/StaticArrayTest.cpp b/src/UnitTests/Containers/StaticArrayTest.cpp index 16817100f..1297933e7 100644 --- a/src/UnitTests/Containers/StaticArrayTest.cpp +++ b/src/UnitTests/Containers/StaticArrayTest.cpp @@ -246,12 +246,12 @@ TYPED_TEST( StaticArrayTest, SaveAndLoad ) ArrayType u1( 7 ), u2; File file; - file.open( "tnl-static-array-test.tnl", File::Mode::Out ); - u1.save( file ); - file.close(); - file.open( "tnl-static-array-test.tnl", File::Mode::In ); - u2.load( file ); - file.close(); + ASSERT_NO_THROW( file.open( "tnl-static-array-test.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( u1.save( file ) ); + ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( file.open( "tnl-static-array-test.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( u2.load( file ) ); + ASSERT_NO_THROW( file.close() ); EXPECT_EQ( u1, u2 ); diff --git a/src/UnitTests/FileTest.h b/src/UnitTests/FileTest.h index 39671ba66..4a69fcb20 100644 --- a/src/UnitTests/FileTest.h +++ b/src/UnitTests/FileTest.h @@ -24,23 +24,23 @@ TEST( FileTest, OpenInvalid ) TEST( FileTest, WriteAndRead ) { File file; - file.open( String( "test-file.tnl" ), File::Mode::Out ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::Out ) ); int intData( 5 ); double doubleData[ 3 ] = { 1.0, 2.0, 3.0 }; const double constDoubleData = 3.14; - file.save( &intData ); - file.save( doubleData, 3 ); - file.save( &constDoubleData ); - file.close(); + ASSERT_NO_THROW( file.save( &intData ) ); + ASSERT_NO_THROW( file.save( doubleData, 3 ) ); + ASSERT_NO_THROW( file.save( &constDoubleData ) ); + ASSERT_NO_THROW( file.close() ); - file.open( String( "test-file.tnl" ), File::Mode::In ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::In ) ); int newIntData; double newDoubleData[ 3 ]; double newConstDoubleData; - file.load( &newIntData, 1 ); - file.load( newDoubleData, 3 ); - file.load( &newConstDoubleData, 1 ); + ASSERT_NO_THROW( file.load( &newIntData, 1 ) ); + ASSERT_NO_THROW( file.load( newDoubleData, 3 ) ); + ASSERT_NO_THROW( file.load( &newConstDoubleData, 1 ) ); EXPECT_EQ( newIntData, intData ); for( int i = 0; i < 3; i ++ ) @@ -58,17 +58,17 @@ TEST( FileTest, WriteAndReadWithConversion ) float floatData[ 3 ]; int intData[ 3 ]; File file; - file.open( "test-file.tnl", File::Mode::Out | File::Mode::Truncate ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out | File::Mode::Truncate ) ); file.save< double, float, Devices::Host >( doubleData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); file.load< float, float, Devices::Host >( floatData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); file.load< int, float, Devices::Host >( intData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); EXPECT_NEAR( floatData[ 0 ], 3.14159, 0.0001 ); EXPECT_NEAR( floatData[ 1 ], 2.71828, 0.0001 ); @@ -108,14 +108,14 @@ TEST( FileTest, WriteAndReadCUDA ) cudaMemcpyHostToDevice ); File file; - file.open( String( "test-file.tnl" ), File::Mode::Out ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::Out ) ); file.save< int, int, Devices::Cuda >( cudaIntData ); file.save< float, float, Devices::Cuda >( cudaFloatData, 3 ); file.save< const double, double, Devices::Cuda >( cudaConstDoubleData ); - file.close(); + ASSERT_NO_THROW( file.close() ); - file.open( String( "test-file.tnl" ), File::Mode::In ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::In ) ); int newIntData; float newFloatData[ 3 ]; double newDoubleData; @@ -147,7 +147,7 @@ TEST( FileTest, WriteAndReadCUDA ) EXPECT_EQ( newDoubleData, constDoubleData ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); -}; +} TEST( FileTest, WriteAndReadCUDAWithConversion ) { @@ -169,17 +169,17 @@ TEST( FileTest, WriteAndReadCUDAWithConversion ) cudaMemcpyHostToDevice ); File file; - file.open( String( "cuda-test-file.tnl" ), File::Mode::Out | File::Mode::Truncate ); + ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), File::Mode::Out | File::Mode::Truncate ) ); file.save< double, float, Devices::Cuda >( cudaConstDoubleData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); - file.open( String( "cuda-test-file.tnl" ), File::Mode::In ); + ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), File::Mode::In ) ); file.load< float, float, Devices::Cuda >( cudaFloatData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); - file.open( String( "cuda-test-file.tnl" ), File::Mode::In ); + ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), File::Mode::In ) ); file.load< int, float, Devices::Cuda >( cudaIntData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); cudaMemcpy( floatData, cudaFloatData, @@ -200,7 +200,7 @@ TEST( FileTest, WriteAndReadCUDAWithConversion ) EXPECT_EQ( intData[ 2 ], 1 ); EXPECT_EQ( std::remove( "cuda-test-file.tnl" ), 0 ); -}; +} #endif #endif diff --git a/src/UnitTests/Matrices/DenseMatrixTest.h b/src/UnitTests/Matrices/DenseMatrixTest.h index c67386e81..ea4b6174d 100644 --- a/src/UnitTests/Matrices/DenseMatrixTest.h +++ b/src/UnitTests/Matrices/DenseMatrixTest.h @@ -1281,13 +1281,13 @@ void test_SaveAndLoad() for( IndexType j = 0; j < cols; j++ ) savedMatrix.setElement( i, j, value++ ); - savedMatrix.save( "denseMatrixFile" ); + ASSERT_NO_THROW( savedMatrix.save( "denseMatrixFile" ) ); Matrix loadedMatrix; loadedMatrix.reset(); loadedMatrix.setDimensions( rows, cols ); - loadedMatrix.load( "denseMatrixFile" ); + ASSERT_NO_THROW( loadedMatrix.load( "denseMatrixFile" ) ); EXPECT_EQ( savedMatrix.getElement( 0, 0 ), loadedMatrix.getElement( 0, 0 ) ); EXPECT_EQ( savedMatrix.getElement( 0, 1 ), loadedMatrix.getElement( 0, 1 ) ); diff --git a/src/UnitTests/Matrices/SparseMatrixTest.hpp b/src/UnitTests/Matrices/SparseMatrixTest.hpp index 8c3858641..28883ae76 100644 --- a/src/UnitTests/Matrices/SparseMatrixTest.hpp +++ b/src/UnitTests/Matrices/SparseMatrixTest.hpp @@ -799,7 +799,7 @@ void test_SaveAndLoad() for( IndexType i = 1; i < m_cols; i++ ) // 3rd row savedMatrix.setElement( 3, i, value++ ); - savedMatrix.save( "sparseMatrixFile" ); + ASSERT_NO_THROW( savedMatrix.save( "sparseMatrixFile" ) ); Matrix loadedMatrix; loadedMatrix.reset(); @@ -810,7 +810,7 @@ void test_SaveAndLoad() loadedMatrix.setCompressedRowLengths( rowLengths2 ); - loadedMatrix.load( "sparseMatrixFile" ); + ASSERT_NO_THROW( loadedMatrix.load( "sparseMatrixFile" ) ); EXPECT_EQ( savedMatrix.getElement( 0, 0 ), loadedMatrix.getElement( 0, 0 ) ); @@ -923,4 +923,4 @@ void test_Print() EXPECT_EQ( printed.str(), couted.str() ); } -#endif \ No newline at end of file +#endif diff --git a/src/UnitTests/Meshes/MeshTest.h b/src/UnitTests/Meshes/MeshTest.h index 65ec8c353..9d450a293 100644 --- a/src/UnitTests/Meshes/MeshTest.h +++ b/src/UnitTests/Meshes/MeshTest.h @@ -107,13 +107,13 @@ void testMeshOnCuda( const Mesh& mesh ) EXPECT_EQ( mesh2, mesh ); // test load from file to CUDA - mesh.save( "mesh.tnl" ); - dmesh1.load( "mesh.tnl" ); + ASSERT_NO_THROW( mesh.save( "mesh.tnl" ) ); + ASSERT_NO_THROW( dmesh1.load( "mesh.tnl" ) ); EXPECT_EQ( dmesh1, mesh ); // test save into file from CUDA - dmesh1.save( "mesh.tnl" ); - mesh2.load( "mesh.tnl" ); + ASSERT_NO_THROW( dmesh1.save( "mesh.tnl" ) ); + ASSERT_NO_THROW( mesh2.load( "mesh.tnl" ) ); EXPECT_EQ( mesh2, mesh ); EXPECT_EQ( std::remove( "mesh.tnl" ), 0 ); @@ -154,8 +154,8 @@ template< typename Mesh > void testFinishedMesh( const Mesh& mesh ) { Mesh mesh2; - mesh.save( "mesh.tnl" ); - mesh2.load( "mesh.tnl" ); + ASSERT_NO_THROW( mesh.save( "mesh.tnl" ) ); + ASSERT_NO_THROW( mesh2.load( "mesh.tnl" ) ); EXPECT_EQ( std::remove( "mesh.tnl" ), 0 ); ASSERT_EQ( mesh, mesh2 ); compareStringRepresentation( mesh, mesh2 ); diff --git a/src/UnitTests/ObjectTest.cpp b/src/UnitTests/ObjectTest.cpp index ac0281afa..8de417507 100644 --- a/src/UnitTests/ObjectTest.cpp +++ b/src/UnitTests/ObjectTest.cpp @@ -24,11 +24,11 @@ TEST( ObjectTest, SaveAndLoadTest ) { Object testObject; File file; - file.open( "test-file.tnl", File::Mode::Out ); - testObject.save( file ); - file.close(); - file.open( "test-file.tnl", File::Mode::In ); - testObject.load( file ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( testObject.save( file ) ); + ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( testObject.load( file ) ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); } @@ -80,13 +80,13 @@ TEST( HeaderTest, SaveAndLoadTest ) { Object testObject; File file; - file.open( "test-file.tnl", File::Mode::Out ); - saveHeader( file, "TYPE" ); - file.close(); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( saveHeader( file, "TYPE" ) ); + ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); String type; - loadHeader( file, type ); - + ASSERT_NO_THROW( loadHeader( file, type ) ); + EXPECT_EQ( type, "TYPE" ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); diff --git a/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp b/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp index e7079e894..9e4b1eaf3 100644 --- a/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp +++ b/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp @@ -8,7 +8,7 @@ #include -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include #include "Functions/Functions.h" @@ -36,21 +36,21 @@ class TestSaveAndLoadMeshfunction typedef MeshFunction MeshFunctionType; typedef Vector DofType; typedef typename MeshType::Cell Cell; - typedef typename MeshType::IndexType IndexType; - typedef typename MeshType::PointType PointType; - + typedef typename MeshType::IndexType IndexType; + typedef typename MeshType::PointType PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; typedef LinearFunction LinearFunctionType; Pointers::SharedPointer< LinearFunctionType, Host > linearFunctionPtr; - MeshFunctionEvaluator< MeshFunctionType, LinearFunctionType > linearFunctionEvaluator; + MeshFunctionEvaluator< MeshFunctionType, LinearFunctionType > linearFunctionEvaluator; PointType localOrigin; localOrigin.setValue(-0.5); PointType localProportions; localProportions.setValue(10); - + Pointers::SharedPointer localGridptr; localGridptr->setDimensions(localProportions); localGridptr->setDomain(localOrigin,localProportions); @@ -62,9 +62,9 @@ class TestSaveAndLoadMeshfunction linearFunctionEvaluator.evaluateAllEntities(localMeshFunctionptr , linearFunctionPtr); File file; - file.open( String( FILENAME), File::Mode::Out ); - localMeshFunctionptr->save(file); - file.close(); + ASSERT_NO_THROW( file.open( String( FILENAME), File::Mode::Out ) ); + ASSERT_NO_THROW( localMeshFunctionptr->save(file) ); + ASSERT_NO_THROW( file.close() ); //load other meshfunction on same localgrid from created file Pointers::SharedPointer loadGridptr; @@ -80,9 +80,9 @@ class TestSaveAndLoadMeshfunction loadDof[i]=-1; } - file.open( String( FILENAME ), File::Mode::In ); - loadMeshFunctionptr->boundLoad(file); - file.close(); + ASSERT_NO_THROW( file.open( String( FILENAME ), File::Mode::In ) ); + ASSERT_NO_THROW( loadMeshFunctionptr->boundLoad(file) ); + ASSERT_NO_THROW( file.close() ); for(int i=0;i #endif @@ -19,7 +19,7 @@ using namespace TNL; -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST TEST( StringTest, BasicConstructor ) { String str; @@ -306,10 +306,10 @@ TEST( StringTest, SaveLoad ) { String str1( "testing-string" ); File file; - file.open( "test-file.tnl", File::Mode::Out ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); ASSERT_NO_THROW( file << str1 ); - file.close(); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); String str2; ASSERT_NO_THROW( file >> str2 ); EXPECT_EQ( str1, str2 ); -- GitLab From 22ccb366e847ce61d7d1e0e136957312f07b173d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 12 Apr 2019 14:06:54 +0200 Subject: [PATCH 17/30] Tests: split main functions into separate headers --- src/UnitTests/AssertCudaTest.cu | 11 +-- src/UnitTests/AssertTest.cpp | 11 +-- .../Containers/ArrayOperationsTest.h | 11 +-- src/UnitTests/Containers/ArrayTest.h | 11 +-- src/UnitTests/Containers/ArrayViewTest.h | 11 +-- .../Containers/DistributedArrayTest.h | 62 +--------------- .../Containers/DistributedVectorTest.h | 62 +--------------- src/UnitTests/Containers/ListTest.cpp | 11 +-- .../Containers/Multimaps/MultimapTest.cpp | 12 +--- .../Multimaps/StaticMultimapTest.cpp | 12 +--- src/UnitTests/Containers/MultireductionTest.h | 11 +-- src/UnitTests/Containers/StaticArrayTest.cpp | 11 +-- src/UnitTests/Containers/StaticVectorTest.cpp | 11 +-- src/UnitTests/Containers/VectorTest.h | 11 +-- src/UnitTests/FileNameTest.cpp | 13 +--- src/UnitTests/FileTest.h | 11 +-- .../Functions/BoundaryMeshFunctionTest.h | 15 +--- src/UnitTests/Functions/MeshFunctionTest.h | 16 +---- src/UnitTests/Matrices/DenseMatrixTest.h | 12 +--- .../Matrices/DistributedMatrixTest.h | 62 +--------------- src/UnitTests/Matrices/SparseMatrixCopyTest.h | 11 +-- src/UnitTests/Matrices/SparseMatrixTest.h | 11 +-- .../Matrices/SparseMatrixTest_AdEllpack.h | 11 +-- .../Matrices/SparseMatrixTest_BiEllpack.h | 11 +-- src/UnitTests/Matrices/SparseMatrixTest_CSR.h | 11 +-- .../SparseMatrixTest_ChunkedEllpack.h | 11 +-- .../Matrices/SparseMatrixTest_Ellpack.h | 11 +-- .../Matrices/SparseMatrixTest_SlicedEllpack.h | 11 +-- src/UnitTests/Meshes/BoundaryTagsTest.cpp | 11 +-- .../DistributedMeshes/CopyEntitiesTest.cpp | 12 +--- .../CutDistributedGridTest.cpp | 69 +----------------- .../CutDistributedMeshFunctionTest.cpp | 69 +----------------- .../DistributedMeshes/CutMeshFunctionTest.cpp | 11 +-- .../DistributedMeshes/DirectionsTest.cpp | 13 +--- .../DistributedGridIOTestBase.h | 67 +---------------- .../DistributedGridIO_MPIIOTestBase.h | 66 +---------------- .../DistributedGridTest_1D.cpp | 66 +---------------- .../DistributedGridTest_2D.cpp | 68 +----------------- .../DistributedGridTest_3D.cpp | 70 +----------------- .../DistributedVectorFieldIO_MPIIOTest.cpp | 71 +------------------ src/UnitTests/Meshes/MeshEntityTest.cpp | 11 +-- src/UnitTests/Meshes/MeshOrderingTest.cpp | 11 +-- src/UnitTests/Meshes/MeshOrderingTest.cu | 11 +-- src/UnitTests/Meshes/MeshTest.cpp | 11 +-- src/UnitTests/Meshes/MeshTest.cu | 11 +-- src/UnitTests/ObjectTest.cpp | 14 +--- .../Pointers/SharedPointerCudaTest.cu | 39 ++++------ .../Pointers/SharedPointerHostTest.cpp | 24 ++----- src/UnitTests/Pointers/UniquePointerTest.cpp | 15 +--- src/UnitTests/SaveAndLoadMeshfunctionTest.cpp | 14 +--- src/UnitTests/StringTest.cpp | 13 +--- src/UnitTests/TimerTest.cpp | 18 +---- src/UnitTests/main.h | 15 ++++ src/UnitTests/main_mpi.h | 66 +++++++++++++++++ 54 files changed, 162 insertions(+), 1179 deletions(-) create mode 100644 src/UnitTests/main.h create mode 100644 src/UnitTests/main_mpi.h diff --git a/src/UnitTests/AssertCudaTest.cu b/src/UnitTests/AssertCudaTest.cu index cfd4e846b..9d4865eb9 100644 --- a/src/UnitTests/AssertCudaTest.cu +++ b/src/UnitTests/AssertCudaTest.cu @@ -108,13 +108,4 @@ WRAP_ASSERT( test28, TNL_ASSERT_FALSE( data_full, "non-nullptr is false" );, fal #endif #endif -#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "main.h" diff --git a/src/UnitTests/AssertTest.cpp b/src/UnitTests/AssertTest.cpp index ea20f7957..88bbcf4be 100644 --- a/src/UnitTests/AssertTest.cpp +++ b/src/UnitTests/AssertTest.cpp @@ -68,13 +68,4 @@ TEST( AssertTest, basicTest ) } #endif -#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "main.h" diff --git a/src/UnitTests/Containers/ArrayOperationsTest.h b/src/UnitTests/Containers/ArrayOperationsTest.h index 23b8fcd4e..4c1b6b9c2 100644 --- a/src/UnitTests/Containers/ArrayOperationsTest.h +++ b/src/UnitTests/Containers/ArrayOperationsTest.h @@ -442,13 +442,4 @@ TYPED_TEST( ArrayOperationsTest, containsOnlyValue_cuda ) #endif // HAVE_GTEST -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Containers/ArrayTest.h b/src/UnitTests/Containers/ArrayTest.h index 62bf493cb..dc054e1a8 100644 --- a/src/UnitTests/Containers/ArrayTest.h +++ b/src/UnitTests/Containers/ArrayTest.h @@ -525,13 +525,4 @@ TYPED_TEST( ArrayTest, boundLoad ) #endif // HAVE_GTEST -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Containers/ArrayViewTest.h b/src/UnitTests/Containers/ArrayViewTest.h index 28d8b512b..914d5a581 100644 --- a/src/UnitTests/Containers/ArrayViewTest.h +++ b/src/UnitTests/Containers/ArrayViewTest.h @@ -545,13 +545,4 @@ TYPED_TEST( ArrayViewTest, assignmentOperatorWithDifferentType ) #endif // HAVE_GTEST -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Containers/DistributedArrayTest.h b/src/UnitTests/Containers/DistributedArrayTest.h index 381539af6..03d94ccbe 100644 --- a/src/UnitTests/Containers/DistributedArrayTest.h +++ b/src/UnitTests/Containers/DistributedArrayTest.h @@ -11,7 +11,6 @@ #include #include -#include #include #include @@ -288,63 +287,4 @@ TYPED_TEST( DistributedArrayTest, boolOperator ) #endif // HAVE_GTEST - -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -using CommunicatorType = Communicators::MpiCommunicator; - -#include - -class MinimalistBufferedPrinter -: public ::testing::EmptyTestEventListener -{ -private: - std::stringstream sout; - -public: - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) - { - sout << test_info.test_case_name() << "." << test_info.name() << " Start." << std::endl; - } - - // Called after a failed assertion or a SUCCEED() invocation. - virtual void OnTestPartResult(const ::testing::TestPartResult& test_part_result) - { - sout << (test_part_result.failed() ? "====Failure=== " : "===Success=== ") - << test_part_result.file_name() << " " - << test_part_result.line_number() <listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main_mpi.h" diff --git a/src/UnitTests/Containers/DistributedVectorTest.h b/src/UnitTests/Containers/DistributedVectorTest.h index 870446d15..3b52055f4 100644 --- a/src/UnitTests/Containers/DistributedVectorTest.h +++ b/src/UnitTests/Containers/DistributedVectorTest.h @@ -44,7 +44,6 @@ void setNegativeLinearSequence( Vector& deviceVector ) #include #include -#include #include #include #include @@ -349,63 +348,4 @@ TYPED_TEST( DistributedVectorTest, addVectors ) #endif // HAVE_GTEST - -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -using CommunicatorType = Communicators::MpiCommunicator; - -#include - -class MinimalistBufferedPrinter -: public ::testing::EmptyTestEventListener -{ -private: - std::stringstream sout; - -public: - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) - { - sout << test_info.test_case_name() << "." << test_info.name() << " Start." << std::endl; - } - - // Called after a failed assertion or a SUCCEED() invocation. - virtual void OnTestPartResult(const ::testing::TestPartResult& test_part_result) - { - sout << (test_part_result.failed() ? "====Failure=== " : "===Success=== ") - << test_part_result.file_name() << " " - << test_part_result.line_number() <listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main_mpi.h" diff --git a/src/UnitTests/Containers/ListTest.cpp b/src/UnitTests/Containers/ListTest.cpp index 32e65c223..8330e5268 100644 --- a/src/UnitTests/Containers/ListTest.cpp +++ b/src/UnitTests/Containers/ListTest.cpp @@ -143,13 +143,4 @@ TYPED_TEST( ListTest, operations ) #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Containers/Multimaps/MultimapTest.cpp b/src/UnitTests/Containers/Multimaps/MultimapTest.cpp index 4612c1dd3..1ba445e2c 100644 --- a/src/UnitTests/Containers/Multimaps/MultimapTest.cpp +++ b/src/UnitTests/Containers/Multimaps/MultimapTest.cpp @@ -7,7 +7,7 @@ using IndexType = int; using Device = Devices::Host; using LocalIndexType = short; -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include TEST( MultimapTest, TestTypedefs ) @@ -147,12 +147,4 @@ TEST( MultimapTest, TestSaveAndLoad ) } #endif -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - return EXIT_FAILURE; -#endif -} +#include "../../main.h" diff --git a/src/UnitTests/Containers/Multimaps/StaticMultimapTest.cpp b/src/UnitTests/Containers/Multimaps/StaticMultimapTest.cpp index 3602f53ca..d4ad0bcf7 100644 --- a/src/UnitTests/Containers/Multimaps/StaticMultimapTest.cpp +++ b/src/UnitTests/Containers/Multimaps/StaticMultimapTest.cpp @@ -7,7 +7,7 @@ using IndexType = int; using Device = Devices::Host; using LocalIndexType = short; -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include TEST( MultimapTest, TestTypedefs ) @@ -95,12 +95,4 @@ TEST( MultimapTest, TestSaveAndLoad ) } #endif -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - return EXIT_FAILURE; -#endif -} +#include "../../main.h" diff --git a/src/UnitTests/Containers/MultireductionTest.h b/src/UnitTests/Containers/MultireductionTest.h index d0aa7bd84..0487e916b 100644 --- a/src/UnitTests/Containers/MultireductionTest.h +++ b/src/UnitTests/Containers/MultireductionTest.h @@ -120,13 +120,4 @@ TYPED_TEST( MultireductionTest, scalarProduct ) #endif // HAVE_GTEST -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Containers/StaticArrayTest.cpp b/src/UnitTests/Containers/StaticArrayTest.cpp index 1297933e7..f1f6b208d 100644 --- a/src/UnitTests/Containers/StaticArrayTest.cpp +++ b/src/UnitTests/Containers/StaticArrayTest.cpp @@ -283,13 +283,4 @@ TYPED_TEST( StaticArrayTest, streamOperator ) #endif // HAVE_GTEST -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Containers/StaticVectorTest.cpp b/src/UnitTests/Containers/StaticVectorTest.cpp index e34db3f33..3f39c5045 100644 --- a/src/UnitTests/Containers/StaticVectorTest.cpp +++ b/src/UnitTests/Containers/StaticVectorTest.cpp @@ -191,13 +191,4 @@ TYPED_TEST( StaticVectorTest, lpNorm ) #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Containers/VectorTest.h b/src/UnitTests/Containers/VectorTest.h index 5f8424516..c223a7afd 100644 --- a/src/UnitTests/Containers/VectorTest.h +++ b/src/UnitTests/Containers/VectorTest.h @@ -791,13 +791,4 @@ TEST( VectorSpecialCasesTest, defaultConstructors ) #endif // HAVE_GTEST -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/FileNameTest.cpp b/src/UnitTests/FileNameTest.cpp index 5a69a1f28..b731db6a0 100644 --- a/src/UnitTests/FileNameTest.cpp +++ b/src/UnitTests/FileNameTest.cpp @@ -75,15 +75,4 @@ TEST( FileNameTest, AllTogether ) } #endif - -#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} - +#include "main.h" diff --git a/src/UnitTests/FileTest.h b/src/UnitTests/FileTest.h index 4a69fcb20..1e0db34f4 100644 --- a/src/UnitTests/FileTest.h +++ b/src/UnitTests/FileTest.h @@ -205,13 +205,4 @@ TEST( FileTest, WriteAndReadCUDAWithConversion ) #endif #endif -#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "main.h" diff --git a/src/UnitTests/Functions/BoundaryMeshFunctionTest.h b/src/UnitTests/Functions/BoundaryMeshFunctionTest.h index bab8bf5af..d3e0a48f5 100644 --- a/src/UnitTests/Functions/BoundaryMeshFunctionTest.h +++ b/src/UnitTests/Functions/BoundaryMeshFunctionTest.h @@ -10,9 +10,7 @@ #pragma once -#include "../GtestMissingError.h" - -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include #include #include @@ -22,16 +20,7 @@ TEST( BoundaryMeshFunctionTest, BasicConstructor ) using Grid = TNL::Meshes::Grid< 2 >; TNL::Functions::BoundaryMeshFunction< Grid > boundaryMesh; } - #endif -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Functions/MeshFunctionTest.h b/src/UnitTests/Functions/MeshFunctionTest.h index b60daf091..8c8b77c09 100644 --- a/src/UnitTests/Functions/MeshFunctionTest.h +++ b/src/UnitTests/Functions/MeshFunctionTest.h @@ -10,9 +10,7 @@ #pragma once -#include "../GtestMissingError.h" - -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include #include #include @@ -35,7 +33,7 @@ TEST( MeshFunctionTest, OstreamOperatorTest ) grid->setDimensions( CoordinatesType( 3, 3 ) ); MeshFunctionType meshFunction( grid ); meshFunction.getData().setValue( 1.0 ); - + const char* str = "[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]"; std::stringstream string_stream1, string_stream2( str ); string_stream1 << meshFunction; @@ -46,12 +44,4 @@ TEST( MeshFunctionTest, OstreamOperatorTest ) #endif -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Matrices/DenseMatrixTest.h b/src/UnitTests/Matrices/DenseMatrixTest.h index ea4b6174d..f1661c997 100644 --- a/src/UnitTests/Matrices/DenseMatrixTest.h +++ b/src/UnitTests/Matrices/DenseMatrixTest.h @@ -1651,14 +1651,4 @@ TEST( DenseMatrixTest, Dense_performSORIterationTest_Cuda ) #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} - +#include "../main.h" diff --git a/src/UnitTests/Matrices/DistributedMatrixTest.h b/src/UnitTests/Matrices/DistributedMatrixTest.h index 2400b7a9e..a2170dd1e 100644 --- a/src/UnitTests/Matrices/DistributedMatrixTest.h +++ b/src/UnitTests/Matrices/DistributedMatrixTest.h @@ -41,7 +41,6 @@ void setMatrix( Matrix& matrix, const RowLengths& rowLengths ) #include #include -#include #include #include #include @@ -237,63 +236,4 @@ TYPED_TEST( DistributedMatrixTest, vectorProduct_distributedInput ) #endif // HAVE_GTEST - -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -using CommunicatorType = Communicators::MpiCommunicator; - -#include - -class MinimalistBufferedPrinter -: public ::testing::EmptyTestEventListener -{ -private: - std::stringstream sout; - -public: - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) - { - sout << test_info.test_case_name() << "." << test_info.name() << " Start." << std::endl; - } - - // Called after a failed assertion or a SUCCEED() invocation. - virtual void OnTestPartResult(const ::testing::TestPartResult& test_part_result) - { - sout << (test_part_result.failed() ? "====Failure=== " : "===Success=== ") - << test_part_result.file_name() << " " - << test_part_result.line_number() <listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main_mpi.h" diff --git a/src/UnitTests/Matrices/SparseMatrixCopyTest.h b/src/UnitTests/Matrices/SparseMatrixCopyTest.h index 2885bac09..a38f29497 100644 --- a/src/UnitTests/Matrices/SparseMatrixCopyTest.h +++ b/src/UnitTests/Matrices/SparseMatrixCopyTest.h @@ -551,13 +551,4 @@ TEST( SparseMatrixCopyTest, SlicedEllpack_to_Ellpack_cuda ) #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest.h b/src/UnitTests/Matrices/SparseMatrixTest.h index 78121bdf2..c3716c116 100644 --- a/src/UnitTests/Matrices/SparseMatrixTest.h +++ b/src/UnitTests/Matrices/SparseMatrixTest.h @@ -50,13 +50,4 @@ TEST( SparseMatrixTest, CSR_perforSORIterationTest_Cuda ) #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.h b/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.h index 24b4db1b2..f6ab325b0 100644 --- a/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.h +++ b/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.h @@ -139,13 +139,4 @@ TYPED_TEST( AdEllpackMatrixTest, printTest ) #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.h b/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.h index a18e7cc52..c3dd6abb4 100644 --- a/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.h +++ b/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.h @@ -138,13 +138,4 @@ TYPED_TEST( BiEllpackMatrixTest, printTest ) #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_CSR.h b/src/UnitTests/Matrices/SparseMatrixTest_CSR.h index 2eaecc76e..9707f6b84 100644 --- a/src/UnitTests/Matrices/SparseMatrixTest_CSR.h +++ b/src/UnitTests/Matrices/SparseMatrixTest_CSR.h @@ -136,13 +136,4 @@ TYPED_TEST( CSRMatrixTest, printTest ) #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.h b/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.h index 99ad9f0b4..1845255d3 100644 --- a/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.h +++ b/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.h @@ -141,13 +141,4 @@ TYPED_TEST( ChunkedEllpackMatrixTest, printTest ) #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.h b/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.h index c6ecd72b3..f20208b7c 100644 --- a/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.h +++ b/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.h @@ -136,13 +136,4 @@ TYPED_TEST( EllpackMatrixTest, printTest ) #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.h b/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.h index 0fc1f59e2..534184771 100644 --- a/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.h +++ b/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.h @@ -136,13 +136,4 @@ TYPED_TEST( SlicedEllpackMatrixTest, printTest ) #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Meshes/BoundaryTagsTest.cpp b/src/UnitTests/Meshes/BoundaryTagsTest.cpp index 274ef974b..c83e40752 100644 --- a/src/UnitTests/Meshes/BoundaryTagsTest.cpp +++ b/src/UnitTests/Meshes/BoundaryTagsTest.cpp @@ -1,11 +1,2 @@ #include "BoundaryTagsTest.h" - -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - return EXIT_FAILURE; -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Meshes/DistributedMeshes/CopyEntitiesTest.cpp b/src/UnitTests/Meshes/DistributedMeshes/CopyEntitiesTest.cpp index 383f8328b..1f6ddf2c7 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/CopyEntitiesTest.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/CopyEntitiesTest.cpp @@ -224,14 +224,4 @@ TEST( CopyEntitiesTest, 3D ) #endif -#include "../../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} - +#include "../../main.h" diff --git a/src/UnitTests/Meshes/DistributedMeshes/CutDistributedGridTest.cpp b/src/UnitTests/Meshes/DistributedMeshes/CutDistributedGridTest.cpp index 587ec807e..54071032c 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/CutDistributedGridTest.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/CutDistributedGridTest.cpp @@ -4,7 +4,6 @@ #ifdef HAVE_MPI #include -#include #include #include @@ -356,74 +355,8 @@ TEST(CutDistributedGirdTest_3D, IsNotDistributed_2D) EXPECT_FALSE(cutDistributedGrid.isDistributed()) << "Řez by nemÄ›l být distribuovaný"; } } - - - -#else -TEST(NoMPI, NoTest) -{ - ASSERT_TRUE(true) << ":-("; -} #endif #endif - -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -#include - - class MinimalistBufferedPrinter : public ::testing::EmptyTestEventListener { - - private: - std::stringstream sout; - - public: - - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) { - sout<< test_info.test_case_name() <<"." << test_info.name() << " Start." <listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - - throw GtestMissingError(); -#endif -} - +#include "../../main_mpi.h" diff --git a/src/UnitTests/Meshes/DistributedMeshes/CutDistributedMeshFunctionTest.cpp b/src/UnitTests/Meshes/DistributedMeshes/CutDistributedMeshFunctionTest.cpp index caaf3f613..7a19611da 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/CutDistributedMeshFunctionTest.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/CutDistributedMeshFunctionTest.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -639,74 +638,8 @@ TEST(CutDistributedMeshFunction, 3D_2_Save) } } - - - -#else -TEST(NoMPI, NoTest) -{ - ASSERT_TRUE(true) << ":-("; -} -#endif - -#endif - - -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -#include - - class MinimalistBufferedPrinter : public ::testing::EmptyTestEventListener { - - private: - std::stringstream sout; - - public: - - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) { - sout<< test_info.test_case_name() <<"." << test_info.name() << " Start." <listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - - throw GtestMissingError(); #endif -} +#include "../../main_mpi.h" diff --git a/src/UnitTests/Meshes/DistributedMeshes/CutMeshFunctionTest.cpp b/src/UnitTests/Meshes/DistributedMeshes/CutMeshFunctionTest.cpp index ce78b8568..854cdbda1 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/CutMeshFunctionTest.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/CutMeshFunctionTest.cpp @@ -213,13 +213,4 @@ TEST(CutMeshFunction, 3D_2) #endif -#include "../../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../../main.h" diff --git a/src/UnitTests/Meshes/DistributedMeshes/DirectionsTest.cpp b/src/UnitTests/Meshes/DistributedMeshes/DirectionsTest.cpp index b772ecda0..bc1f94f8a 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DirectionsTest.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/DirectionsTest.cpp @@ -120,15 +120,4 @@ TEST(XYZ, 3D ) #endif -#include "../../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - int result= RUN_ALL_TESTS(); - return result; -#else - - throw GtestMissingError(); -#endif -} +#include "../../main.h" diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTestBase.h b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTestBase.h index 537bcd923..cd4a155ef 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTestBase.h +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTestBase.h @@ -12,7 +12,6 @@ #ifdef HAVE_MPI #include "DistributedGridIOTest.h" -#include TEST( DistributedGridIO, Save_1D ) { @@ -74,74 +73,10 @@ TEST( DistributedGridIO, Load_3D_GPU ) { TestDistributedGridIO<3,Cuda>::TestLoad(); } - -#endif - -#else -TEST(NoMPI, NoTest) -{ - ASSERT_TRUE(true) << ":-("; -} #endif #endif -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -#include - - class MinimalistBufferedPrinter : public ::testing::EmptyTestEventListener { - - private: - std::stringstream sout; - - public: - - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) { - sout<< test_info.test_case_name() <<"." << test_info.name() << " Start." <listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - CommunicatorType::setRedirection( false ); - CommunicatorType::setupRedirection(); - #endif - return RUN_ALL_TESTS(); -#else - - throw GtestMissingError(); -#endif -} +#include "../../main_mpi.h" diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIO_MPIIOTestBase.h b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIO_MPIIOTestBase.h index 4e3603a7a..f84de9065 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIO_MPIIOTestBase.h +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIO_MPIIOTestBase.h @@ -10,7 +10,6 @@ #ifdef HAVE_MPI #include "DistributedGridIO_MPIIOTest.h" -#include TEST( DistributedGridMPIIO, Save_1D ) { @@ -74,71 +73,8 @@ TEST( DistributedGridMPIIO, Load_3D ) } #endif -#else -TEST(NoMPI, NoTest) -{ - ASSERT_TRUE(true) << ":-("; -} -#endif - #endif -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -#include - - class MinimalistBufferedPrinter : public ::testing::EmptyTestEventListener { - - private: - std::stringstream sout; - - public: - - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) { - sout<< test_info.test_case_name() <<"." << test_info.name() << " Start." <listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - CommunicatorType::setRedirection( false ); - CommunicatorType::setupRedirection(); - #endif - return RUN_ALL_TESTS(); -#else - - throw GtestMissingError(); -#endif -} +#include "../../main_mpi.h" diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_1D.cpp b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_1D.cpp index 43af00161..1a5dcb819 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_1D.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_1D.cpp @@ -13,7 +13,6 @@ #ifdef HAVE_MPI #include -#include #include #include #include @@ -378,71 +377,8 @@ TEST_F(DistributedGridTest_1D, SynchronizePeriodicBoundariesLinearTest ) if( rank == nproc - 1 ) EXPECT_EQ( meshFunctionPtr->getValue(entity2), 0 ) << "Linear function Overlap error on right Edge."; } - -#else -TEST(NoMPI, NoTest) -{ - ASSERT_TRUE(true) << ":-("; -} #endif #endif - -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -#include - - class MinimalistBufferedPrinter : public ::testing::EmptyTestEventListener { - - private: - std::stringstream sout; - - public: - - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) { - sout<< test_info.test_case_name() <<"." << test_info.name() << " Start." <listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - - throw GtestMissingError(); -#endif -} +#include "../../main_mpi.h" diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_2D.cpp b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_2D.cpp index f5a0056de..2aaeaa06b 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_2D.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_2D.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include "../../Functions/Functions.h" @@ -1017,73 +1016,8 @@ TEST_F(DistributedGridTest_2D, SynchronizerNeighborPeriodicBoundariesWithInActiv } } */ - -#else -TEST(NoMPI, NoTest) -{ - ASSERT_TRUE(true) << ":-("; -} #endif #endif - -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -#include - - class MinimalistBufferedPrinter : public ::testing::EmptyTestEventListener { - - private: - std::stringstream sout; - - public: - - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) { - sout<< test_info.test_case_name() <<"." << test_info.name() << " Start." <listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - - throw GtestMissingError(); -#endif -} - - +#include "../../main_mpi.h" diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_3D.cpp b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_3D.cpp index f92ef08d7..823c30db9 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_3D.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_3D.cpp @@ -4,7 +4,6 @@ #ifdef HAVE_MPI #include -#include #include #include #include @@ -720,75 +719,8 @@ TEST_F(DistributedGirdTest_3D, SynchronizerNeighborTest) } */ - -#else -TEST(NoMPI, NoTest) -{ - ASSERT_TRUE(true) << ":-("; -} -#endif - -#endif - - -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -#include - - class MinimalistBufferedPrinter : public ::testing::EmptyTestEventListener { - - private: - std::stringstream sout; - - public: - - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) { - sout<< test_info.test_case_name() <<"." << test_info.name() << " Start." <listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - - throw GtestMissingError(); #endif -} - - - +#include "../../main_mpi.h" diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedVectorFieldIO_MPIIOTest.cpp b/src/UnitTests/Meshes/DistributedMeshes/DistributedVectorFieldIO_MPIIOTest.cpp index 67098fc5d..0a5ab3e37 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedVectorFieldIO_MPIIOTest.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedVectorFieldIO_MPIIOTest.cpp @@ -1,12 +1,8 @@ - - - #ifdef HAVE_GTEST #include #ifdef HAVE_MPI #include -#include #include "DistributedVectorFieldIO_MPIIOTestBase.h" using namespace TNL::Communicators; @@ -43,73 +39,8 @@ TEST( DistributedVectorFieldIO_MPIIO, Load_3D ) { TestDistributedVectorFieldMPIIO<3,2,Host>::TestLoad(); } - - -#else -TEST(NoMPI, NoTest) -{ - ASSERT_TRUE(true) << ":-("; -} #endif #endif -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -#include - - class MinimalistBufferedPrinter : public ::testing::EmptyTestEventListener { - - private: - std::stringstream sout; - - public: - - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) { - sout<< test_info.test_case_name() <<"." << test_info.name() << " Start." <listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - CommunicatorType::setRedirection( false ); - CommunicatorType::setupRedirection(); - #endif - return RUN_ALL_TESTS(); -#else - - throw GtestMissingError(); -#endif -} +#include "../../main_mpi.h" diff --git a/src/UnitTests/Meshes/MeshEntityTest.cpp b/src/UnitTests/Meshes/MeshEntityTest.cpp index e3f87a32b..66b6da128 100644 --- a/src/UnitTests/Meshes/MeshEntityTest.cpp +++ b/src/UnitTests/Meshes/MeshEntityTest.cpp @@ -1,11 +1,2 @@ #include "MeshEntityTest.h" - -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - return EXIT_FAILURE; -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Meshes/MeshOrderingTest.cpp b/src/UnitTests/Meshes/MeshOrderingTest.cpp index fc03c92cc..ff02fe8a2 100644 --- a/src/UnitTests/Meshes/MeshOrderingTest.cpp +++ b/src/UnitTests/Meshes/MeshOrderingTest.cpp @@ -1,11 +1,2 @@ #include "MeshOrderingTest.h" - -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - return EXIT_FAILURE; -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Meshes/MeshOrderingTest.cu b/src/UnitTests/Meshes/MeshOrderingTest.cu index fc03c92cc..ff02fe8a2 100644 --- a/src/UnitTests/Meshes/MeshOrderingTest.cu +++ b/src/UnitTests/Meshes/MeshOrderingTest.cu @@ -1,11 +1,2 @@ #include "MeshOrderingTest.h" - -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - return EXIT_FAILURE; -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Meshes/MeshTest.cpp b/src/UnitTests/Meshes/MeshTest.cpp index 93004f18d..d0ee1e52f 100644 --- a/src/UnitTests/Meshes/MeshTest.cpp +++ b/src/UnitTests/Meshes/MeshTest.cpp @@ -1,11 +1,2 @@ #include "MeshTest.h" - -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - return EXIT_FAILURE; -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Meshes/MeshTest.cu b/src/UnitTests/Meshes/MeshTest.cu index 93004f18d..d0ee1e52f 100644 --- a/src/UnitTests/Meshes/MeshTest.cu +++ b/src/UnitTests/Meshes/MeshTest.cu @@ -1,11 +1,2 @@ #include "MeshTest.h" - -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - return EXIT_FAILURE; -#endif -} +#include "../main.h" diff --git a/src/UnitTests/ObjectTest.cpp b/src/UnitTests/ObjectTest.cpp index 8de417507..be30000b2 100644 --- a/src/UnitTests/ObjectTest.cpp +++ b/src/UnitTests/ObjectTest.cpp @@ -91,18 +91,6 @@ TEST( HeaderTest, SaveAndLoadTest ) EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); } - - #endif - -#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "main.h" diff --git a/src/UnitTests/Pointers/SharedPointerCudaTest.cu b/src/UnitTests/Pointers/SharedPointerCudaTest.cu index 813054c14..c0d76b2cc 100644 --- a/src/UnitTests/Pointers/SharedPointerCudaTest.cu +++ b/src/UnitTests/Pointers/SharedPointerCudaTest.cu @@ -14,12 +14,11 @@ #include #include -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include #endif #include -#include "../GtestMissingError.h" using namespace TNL; @@ -50,18 +49,18 @@ TEST( SharedPointerCudaTest, getDataTest ) #ifdef HAVE_CUDA typedef TNL::Containers::StaticArray< 2, int > TestType; Pointers::SharedPointer< TestType, Devices::Cuda > ptr1( 1, 2 ); - + #ifdef HAVE_CUDA_UNIFIED_MEMORY ASSERT_EQ( ptr1->x(), 1 ); ASSERT_EQ( ptr1->y(), 2 ); #else - + Devices::Cuda::synchronizeDevice(); - + TestType aux; - + cudaMemcpy( ( void*) &aux, &ptr1.getData< Devices::Cuda >(), sizeof( TestType ), cudaMemcpyDeviceToHost ); - + ASSERT_EQ( aux[ 0 ], 1 ); ASSERT_EQ( aux[ 1 ], 2 ); #endif // HAVE_CUDA_UNIFIED_MEMORY @@ -85,7 +84,7 @@ TEST( SharedPointerCudaTest, getDataArrayTest ) #ifdef HAVE_CUDA typedef TNL::Containers::Array< int, Devices::Cuda > TestType; Pointers::SharedPointer< TestType > ptr; - + ptr->setSize( 2 ); ptr->setElement( 0, 1 ); ptr->setElement( 1, 2 ); @@ -97,10 +96,10 @@ TEST( SharedPointerCudaTest, getDataArrayTest ) copyArrayKernel<<< 1, 2 >>>( &ptr.getData< Devices::Cuda >(), testArray_device ); testArray_host = new int [ 2 ]; cudaMemcpy( testArray_host, testArray_device, 2 * sizeof( int ), cudaMemcpyDeviceToHost ); - + ASSERT_EQ( testArray_host[ 0 ], 1 ); ASSERT_EQ( testArray_host[ 1 ], 2 ); - + delete[] testArray_host; cudaFree( testArray_device ); @@ -112,10 +111,10 @@ TEST( SharedPointerCudaTest, nullptrAssignement ) #ifdef HAVE_CUDA using TestType = Pointers::SharedPointer< double, Devices::Cuda >; TestType p1( 5 ), p2( nullptr ); - + // This should not crash p1 = p2; - + ASSERT_FALSE( p1 ); ASSERT_FALSE( p2 ); #endif @@ -126,23 +125,15 @@ TEST( SharedPointerCudaTest, swap ) #ifdef HAVE_CUDA using TestType = Pointers::SharedPointer< double, Devices::Cuda >; TestType p1( 1 ), p2( 2 ); - + p1.swap( p2 ); - + ASSERT_EQ( *p1, 2 ); ASSERT_EQ( *p2, 1 ); #endif } - #endif -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} + +#include "../main.h" diff --git a/src/UnitTests/Pointers/SharedPointerHostTest.cpp b/src/UnitTests/Pointers/SharedPointerHostTest.cpp index b7d441f70..53501e774 100644 --- a/src/UnitTests/Pointers/SharedPointerHostTest.cpp +++ b/src/UnitTests/Pointers/SharedPointerHostTest.cpp @@ -13,13 +13,13 @@ #include #include -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include #endif using namespace TNL; -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST TEST( SharedPointerHostTest, ConstructorTest ) { typedef TNL::Containers::StaticArray< 2, int > TestType; @@ -43,10 +43,10 @@ TEST( SharedPointerCudaTest, nullptrAssignement ) { using TestType = Pointers::SharedPointer< double, Devices::Host >; TestType p1( 5 ), p2( nullptr ); - + // This should not crash p1 = p2; - + ASSERT_FALSE( p1 ); ASSERT_FALSE( p2 ); } @@ -55,22 +55,12 @@ TEST( SharedPointerCudaTest, swap ) { using TestType = Pointers::SharedPointer< double, Devices::Host >; TestType p1( 1 ), p2( 2 ); - + p1.swap( p2 ); - + ASSERT_EQ( *p1, 2 ); ASSERT_EQ( *p2, 1 ); } - #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/Pointers/UniquePointerTest.cpp b/src/UnitTests/Pointers/UniquePointerTest.cpp index 2fba352f5..447358017 100644 --- a/src/UnitTests/Pointers/UniquePointerTest.cpp +++ b/src/UnitTests/Pointers/UniquePointerTest.cpp @@ -13,14 +13,14 @@ #include #include -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include #endif using namespace TNL; using namespace TNL::Pointers; -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST TEST( UniquePointerTest, ConstructorTest ) { typedef TNL::Containers::StaticArray< 2, int > TestType; @@ -41,13 +41,4 @@ TEST( UniquePointerTest, ConstructorTest ) }; #endif -#include "../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../main.h" diff --git a/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp b/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp index 9e4b1eaf3..1596fbcfb 100644 --- a/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp +++ b/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp @@ -108,18 +108,6 @@ TEST( CopyEntitiesTest, 3D ) { TestSaveAndLoadMeshfunction<3>::Test(); } - - #endif -#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} - +#include "main.h" diff --git a/src/UnitTests/StringTest.cpp b/src/UnitTests/StringTest.cpp index 755cb6419..099bc4d6c 100644 --- a/src/UnitTests/StringTest.cpp +++ b/src/UnitTests/StringTest.cpp @@ -316,17 +316,6 @@ TEST( StringTest, SaveLoad ) EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); }; - -#endif - -#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); #endif -} +#include "main.h" diff --git a/src/UnitTests/TimerTest.cpp b/src/UnitTests/TimerTest.cpp index 6c20c4abb..dd46f30f3 100644 --- a/src/UnitTests/TimerTest.cpp +++ b/src/UnitTests/TimerTest.cpp @@ -10,7 +10,7 @@ // Implemented by Nina Dzugasova -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include #endif @@ -18,7 +18,7 @@ using namespace TNL; -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST TEST( TimerTest, Constructor ) { Timer time; @@ -34,16 +34,4 @@ TEST( TimerTest, Constructor ) } #endif - -#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} - - +#include "main.h" diff --git a/src/UnitTests/main.h b/src/UnitTests/main.h new file mode 100644 index 000000000..87da37fa8 --- /dev/null +++ b/src/UnitTests/main.h @@ -0,0 +1,15 @@ +#ifdef HAVE_GTEST +#include +#else +#include "GtestMissingError.h" +#endif + +int main( int argc, char* argv[] ) +{ +#ifdef HAVE_GTEST + ::testing::InitGoogleTest( &argc, argv ); + return RUN_ALL_TESTS(); +#else + throw GtestMissingError(); +#endif +} diff --git a/src/UnitTests/main_mpi.h b/src/UnitTests/main_mpi.h new file mode 100644 index 000000000..3c7c39a86 --- /dev/null +++ b/src/UnitTests/main_mpi.h @@ -0,0 +1,66 @@ +#ifdef HAVE_GTEST +#include +#else +#include "GtestMissingError.h" +#endif + +#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) +#include +#include +using CommunicatorType = Communicators::MpiCommunicator; + +#include + +class MinimalistBufferedPrinter +: public ::testing::EmptyTestEventListener +{ +private: + std::stringstream sout; + +public: + // Called before a test starts. + virtual void OnTestStart(const ::testing::TestInfo& test_info) + { + sout << test_info.test_case_name() << "." << test_info.name() << " Start." << std::endl; + } + + // Called after a failed assertion or a SUCCEED() invocation. + virtual void OnTestPartResult(const ::testing::TestPartResult& test_part_result) + { + sout << (test_part_result.failed() ? "====Failure=== " : "===Success=== ") + << test_part_result.file_name() << " " + << test_part_result.line_number() <listeners(); + + delete listeners.Release(listeners.default_result_printer()); + listeners.Append(new MinimalistBufferedPrinter); + + Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); + #endif + return RUN_ALL_TESTS(); +#else + throw GtestMissingError(); +#endif +} -- GitLab From 5dce2ff7f1265768a71f4b7eac26f63943357e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 12 Apr 2019 15:25:52 +0200 Subject: [PATCH 18/30] Added NotImplementedError exception --- src/TNL/Communicators/MPITypeResolver.h | 6 +- .../Algorithms/ArrayOperationsMIC.hpp | 9 +- .../Algorithms/CudaMultireductionKernel.h | 4 +- .../Algorithms/CudaReductionKernel.h | 134 +++++++++--------- .../Algorithms/Multireduction_impl.h | 6 +- .../Containers/DistributedVectorView_impl.h | 11 +- src/TNL/Containers/DistributedVector_impl.h | 11 +- src/TNL/Exceptions/NotImplementedError.h | 29 ++++ src/TNL/File.hpp | 11 +- src/TNL/Functions/Analytic/VectorNorm.h | 6 - src/TNL/Functions/MeshFunctionGnuplotWriter.h | 5 +- src/TNL/Functions/MeshFunctionNormGetter.h | 4 +- src/TNL/Functions/TestFunction_impl.h | 7 +- src/TNL/Matrices/CSR_impl.h | 12 +- src/TNL/Matrices/ChunkedEllpack_impl.h | 8 +- src/TNL/Matrices/Dense_impl.h | 4 +- src/TNL/Matrices/EllpackSymmetric_impl.h | 5 +- src/TNL/Matrices/Ellpack_impl.h | 5 +- src/TNL/Matrices/Multidiagonal_impl.h | 6 +- .../SlicedEllpackSymmetricGraph_impl.h | 5 +- .../Matrices/SlicedEllpackSymmetric_impl.h | 5 +- src/TNL/Matrices/SlicedEllpack_impl.h | 15 +- src/TNL/Matrices/SparseRow_impl.h | 6 +- src/TNL/Matrices/Sparse_impl.h | 3 +- src/TNL/Matrices/Tridiagonal_impl.h | 6 +- .../DistributedMeshSynchronizer.h | 15 +- .../Meshes/GridDetails/GridTraverser_1D.hpp | 3 +- .../Meshes/GridDetails/GridTraverser_3D.hpp | 3 +- src/TNL/Meshes/Readers/VTKReader.h | 7 +- src/TNL/Meshes/Writers/AsymptoteWriter.h | 7 +- src/TNL/Solvers/Linear/Preconditioners/ILU0.h | 9 +- .../Linear/Preconditioners/Preconditioner.h | 2 +- 32 files changed, 200 insertions(+), 169 deletions(-) create mode 100644 src/TNL/Exceptions/NotImplementedError.h diff --git a/src/TNL/Communicators/MPITypeResolver.h b/src/TNL/Communicators/MPITypeResolver.h index 2d0b45e2b..371616322 100644 --- a/src/TNL/Communicators/MPITypeResolver.h +++ b/src/TNL/Communicators/MPITypeResolver.h @@ -19,6 +19,11 @@ struct MPITypeResolver { static inline MPI_Datatype getType() { + static_assert( sizeof(Type) == sizeof(char) || + sizeof(Type) == sizeof(int) || + sizeof(Type) == sizeof(short int) || + sizeof(Type) == sizeof(long int), + "Fatal Error - Unknown MPI Type"); switch( sizeof( Type ) ) { case sizeof( char ): @@ -30,7 +35,6 @@ struct MPITypeResolver case sizeof( long int ): return MPI_LONG; } - TNL_ASSERT_TRUE(false, "Fatal Error - Unknown MPI Type"); }; }; diff --git a/src/TNL/Containers/Algorithms/ArrayOperationsMIC.hpp b/src/TNL/Containers/Algorithms/ArrayOperationsMIC.hpp index b41e09f0b..b0f09fb02 100644 --- a/src/TNL/Containers/Algorithms/ArrayOperationsMIC.hpp +++ b/src/TNL/Containers/Algorithms/ArrayOperationsMIC.hpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace TNL { namespace Containers { @@ -146,7 +147,7 @@ ArrayOperations< Devices::MIC >:: copySTLList( DestinationElement* destination, const std::list< SourceElement >& source ) { - TNL_ASSERT( false, std::cerr << "TODO" ); + throw Exceptions::NotImplementedError(); } template< typename Element1, @@ -212,8 +213,7 @@ containsValue( const Element* data, TNL_ASSERT_TRUE( data, "Attempted to check data through a nullptr." ); TNL_ASSERT_GE( size, 0, "" ); #ifdef HAVE_MIC - TNL_ASSERT( false, ); - return false; + throw Exceptions::NotImplementedError(); #else throw Exceptions::MICSupportMissing(); #endif @@ -230,8 +230,7 @@ containsOnlyValue( const Element* data, TNL_ASSERT_TRUE( data, "Attempted to check data through a nullptr." ); TNL_ASSERT_GE( size, 0, "" ); #ifdef HAVE_MIC - TNL_ASSERT( false, ); - return false; + throw Exceptions::NotImplementedError(); #else throw Exceptions::MICSupportMissing(); #endif diff --git a/src/TNL/Containers/Algorithms/CudaMultireductionKernel.h b/src/TNL/Containers/Algorithms/CudaMultireductionKernel.h index c779a7e12..2074d5941 100644 --- a/src/TNL/Containers/Algorithms/CudaMultireductionKernel.h +++ b/src/TNL/Containers/Algorithms/CudaMultireductionKernel.h @@ -302,9 +302,9 @@ CudaMultireductionKernelLauncher( Operation& operation, <<< gridSize, blockSize, shmem >>>( operation, n, size, input1, ldInput1, input2, output); break; case 1: - TNL_ASSERT( false, std::cerr << "blockSize should not be 1." << std::endl ); + throw std::logic_error( "blockSize should not be 1." ); default: - TNL_ASSERT( false, std::cerr << "Block size is " << blockSize.x << " which is none of 1, 2, 4, 8, 16, 32, 64, 128, 256 or 512." << std::endl ); + throw std::logic_error( "Block size is " + std::to_string(blockSize.x) + " which is none of 1, 2, 4, 8, 16, 32, 64, 128, 256 or 512." ); } TNL_CHECK_CUDA_DEVICE; diff --git a/src/TNL/Containers/Algorithms/CudaReductionKernel.h b/src/TNL/Containers/Algorithms/CudaReductionKernel.h index 8701b8b7d..59603d0f3 100644 --- a/src/TNL/Containers/Algorithms/CudaReductionKernel.h +++ b/src/TNL/Containers/Algorithms/CudaReductionKernel.h @@ -273,73 +273,73 @@ struct CudaReductionKernelLauncher ? 2 * blockSize.x * sizeof( ResultType ) : blockSize.x * sizeof( ResultType ); - /*** - * Depending on the blockSize we generate appropriate template instance. - */ - switch( blockSize.x ) - { - case 512: - CudaReductionKernel< 512 > - <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); - break; - case 256: - cudaFuncSetCacheConfig(CudaReductionKernel< 256, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); - - CudaReductionKernel< 256 > - <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); - break; - case 128: - cudaFuncSetCacheConfig(CudaReductionKernel< 128, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); - - CudaReductionKernel< 128 > - <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); - break; - case 64: - cudaFuncSetCacheConfig(CudaReductionKernel< 64, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); - - CudaReductionKernel< 64 > - <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); - break; - case 32: - cudaFuncSetCacheConfig(CudaReductionKernel< 32, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); - - CudaReductionKernel< 32 > - <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); - break; - case 16: - cudaFuncSetCacheConfig(CudaReductionKernel< 16, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); - - CudaReductionKernel< 16 > - <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); - break; - case 8: - cudaFuncSetCacheConfig(CudaReductionKernel< 8, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); - - CudaReductionKernel< 8 > - <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); - break; - case 4: - cudaFuncSetCacheConfig(CudaReductionKernel< 4, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); - - CudaReductionKernel< 4 > - <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); - break; - case 2: - cudaFuncSetCacheConfig(CudaReductionKernel< 2, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); - - CudaReductionKernel< 2 > - <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); - break; - case 1: - TNL_ASSERT( false, std::cerr << "blockSize should not be 1." << std::endl ); - default: - TNL_ASSERT( false, std::cerr << "Block size is " << blockSize. x << " which is none of 1, 2, 4, 8, 16, 32, 64, 128, 256 or 512." ); - } - TNL_CHECK_CUDA_DEVICE; - - //// - // return the size of the output array on the CUDA device - return gridSize.x; + /*** + * Depending on the blockSize we generate appropriate template instance. + */ + switch( blockSize.x ) + { + case 512: + CudaReductionKernel< 512 > + <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); + break; + case 256: + cudaFuncSetCacheConfig(CudaReductionKernel< 256, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); + + CudaReductionKernel< 256 > + <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); + break; + case 128: + cudaFuncSetCacheConfig(CudaReductionKernel< 128, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); + + CudaReductionKernel< 128 > + <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); + break; + case 64: + cudaFuncSetCacheConfig(CudaReductionKernel< 64, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); + + CudaReductionKernel< 64 > + <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); + break; + case 32: + cudaFuncSetCacheConfig(CudaReductionKernel< 32, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); + + CudaReductionKernel< 32 > + <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); + break; + case 16: + cudaFuncSetCacheConfig(CudaReductionKernel< 16, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); + + CudaReductionKernel< 16 > + <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); + break; + case 8: + cudaFuncSetCacheConfig(CudaReductionKernel< 8, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); + + CudaReductionKernel< 8 > + <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); + break; + case 4: + cudaFuncSetCacheConfig(CudaReductionKernel< 4, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); + + CudaReductionKernel< 4 > + <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); + break; + case 2: + cudaFuncSetCacheConfig(CudaReductionKernel< 2, Result, DataFetcher, Reduction, VolatileReduction, Index >, cudaFuncCachePreferShared); + + CudaReductionKernel< 2 > + <<< gridSize, blockSize, shmem >>>( zero, dataFetcher, reduction, volatileReduction, size, output); + break; + case 1: + throw std::logic_error( "blockSize should not be 1." ); + default: + throw std::logic_error( "Block size is " + std::to_string(blockSize.x) + " which is none of 1, 2, 4, 8, 16, 32, 64, 128, 256 or 512." ); + } + TNL_CHECK_CUDA_DEVICE; + + //// + // return the size of the output array on the CUDA device + return gridSize.x; } const int activeDevice; diff --git a/src/TNL/Containers/Algorithms/Multireduction_impl.h b/src/TNL/Containers/Algorithms/Multireduction_impl.h index 580136363..a4c5ff26e 100644 --- a/src/TNL/Containers/Algorithms/Multireduction_impl.h +++ b/src/TNL/Containers/Algorithms/Multireduction_impl.h @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -318,10 +319,7 @@ reduce( Operation& operation, const typename Operation::DataType2* input2, typename Operation::ResultType* result ) { - TNL_ASSERT( n > 0, ); - TNL_ASSERT( size <= ldInput1, ); - - throw std::runtime_error("Not Implemented yet Multireduction< Devices::MIC >::reduce"); + throw Exceptions::NotImplementedError("Multireduction is not implemented for MIC."); } } // namespace Algorithms diff --git a/src/TNL/Containers/DistributedVectorView_impl.h b/src/TNL/Containers/DistributedVectorView_impl.h index 0639b2f8e..cc7df30cb 100644 --- a/src/TNL/Containers/DistributedVectorView_impl.h +++ b/src/TNL/Containers/DistributedVectorView_impl.h @@ -12,10 +12,9 @@ #pragma once -#include // std::runtime_error - #include "DistributedVectorView.h" #include +#include namespace TNL { namespace Containers { @@ -543,7 +542,7 @@ void DistributedVectorView< Real, Device, Index, Communicator >:: computePrefixSum() { - throw std::runtime_error("Distributed prefix sum is not implemented yet."); + throw Exceptions::NotImplementedError("Distributed prefix sum is not implemented yet."); } template< typename Real, @@ -554,7 +553,7 @@ void DistributedVectorView< Real, Device, Index, Communicator >:: computePrefixSum( IndexType begin, IndexType end ) { - throw std::runtime_error("Distributed prefix sum is not implemented yet."); + throw Exceptions::NotImplementedError("Distributed prefix sum is not implemented yet."); } template< typename Real, @@ -565,7 +564,7 @@ void DistributedVectorView< Real, Device, Index, Communicator >:: computeExclusivePrefixSum() { - throw std::runtime_error("Distributed prefix sum is not implemented yet."); + throw Exceptions::NotImplementedError("Distributed prefix sum is not implemented yet."); } template< typename Real, @@ -576,7 +575,7 @@ void DistributedVectorView< Real, Device, Index, Communicator >:: computeExclusivePrefixSum( IndexType begin, IndexType end ) { - throw std::runtime_error("Distributed prefix sum is not implemented yet."); + throw Exceptions::NotImplementedError("Distributed prefix sum is not implemented yet."); } } // namespace Containers diff --git a/src/TNL/Containers/DistributedVector_impl.h b/src/TNL/Containers/DistributedVector_impl.h index 239239ead..a2c7cf538 100644 --- a/src/TNL/Containers/DistributedVector_impl.h +++ b/src/TNL/Containers/DistributedVector_impl.h @@ -12,10 +12,9 @@ #pragma once -#include // std::runtime_error - #include "DistributedVector.h" #include +#include namespace TNL { namespace Containers { @@ -572,7 +571,7 @@ void DistributedVector< Real, Device, Index, Communicator >:: computePrefixSum() { - throw std::runtime_error("Distributed prefix sum is not implemented yet."); + throw Exceptions::NotImplementedError("Distributed prefix sum is not implemented yet."); } template< typename Real, @@ -583,7 +582,7 @@ void DistributedVector< Real, Device, Index, Communicator >:: computePrefixSum( IndexType begin, IndexType end ) { - throw std::runtime_error("Distributed prefix sum is not implemented yet."); + throw Exceptions::NotImplementedError("Distributed prefix sum is not implemented yet."); } template< typename Real, @@ -594,7 +593,7 @@ void DistributedVector< Real, Device, Index, Communicator >:: computeExclusivePrefixSum() { - throw std::runtime_error("Distributed prefix sum is not implemented yet."); + throw Exceptions::NotImplementedError("Distributed prefix sum is not implemented yet."); } template< typename Real, @@ -605,7 +604,7 @@ void DistributedVector< Real, Device, Index, Communicator >:: computeExclusivePrefixSum( IndexType begin, IndexType end ) { - throw std::runtime_error("Distributed prefix sum is not implemented yet."); + throw Exceptions::NotImplementedError("Distributed prefix sum is not implemented yet."); } } // namespace Containers diff --git a/src/TNL/Exceptions/NotImplementedError.h b/src/TNL/Exceptions/NotImplementedError.h new file mode 100644 index 000000000..9f0fb97b2 --- /dev/null +++ b/src/TNL/Exceptions/NotImplementedError.h @@ -0,0 +1,29 @@ +/*************************************************************************** + NotImplementedError.h - description + ------------------- + begin : Apr 12, 2019 + copyright : (C) 2019 by Tomas Oberhuber et al. + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +// Implemented by: Jakub Klinkovsky + +#pragma once + +#include + +namespace TNL { +namespace Exceptions { + +struct NotImplementedError + : public std::runtime_error +{ + NotImplementedError( std::string msg = "Something is not implemented." ) + : std::runtime_error( msg ) + {} +}; + +} // namespace Exceptions +} // namespace TNL diff --git a/src/TNL/File.hpp b/src/TNL/File.hpp index df1181af7..4b6e1cb42 100644 --- a/src/TNL/File.hpp +++ b/src/TNL/File.hpp @@ -21,6 +21,7 @@ #include #include #include +#include namespace TNL { @@ -207,10 +208,7 @@ void File::load_impl( Type* buffer, std::streamsize elements ) free( host_buffer ); } else - { - std::cerr << "Type conversion during loading is not implemented for MIC." << std::endl; - abort(); - } + throw Exceptions::NotImplementedError("Type conversion during loading is not implemented for MIC."); #else throw Exceptions::MICSupportMissing(); #endif @@ -345,10 +343,7 @@ void File::save_impl( const Type* buffer, std::streamsize elements ) } } else - { - std::cerr << "Type conversion during saving is not implemented for MIC." << std::endl; - abort(); - } + throw Exceptions::NotImplementedError("Type conversion during saving is not implemented for MIC."); #else throw Exceptions::MICSupportMissing(); #endif diff --git a/src/TNL/Functions/Analytic/VectorNorm.h b/src/TNL/Functions/Analytic/VectorNorm.h index c543cb2d8..a9d292c5f 100644 --- a/src/TNL/Functions/Analytic/VectorNorm.h +++ b/src/TNL/Functions/Analytic/VectorNorm.h @@ -285,9 +285,3 @@ std::ostream& operator << ( std::ostream& str, const VectorNorm< Dimensions, Rea } // namespace Analytic } // namespace Functions } // namespace TNL - - - - - - diff --git a/src/TNL/Functions/MeshFunctionGnuplotWriter.h b/src/TNL/Functions/MeshFunctionGnuplotWriter.h index 11470965e..d747e84a7 100644 --- a/src/TNL/Functions/MeshFunctionGnuplotWriter.h +++ b/src/TNL/Functions/MeshFunctionGnuplotWriter.h @@ -11,6 +11,7 @@ #pragma once #include +#include namespace TNL { @@ -47,7 +48,7 @@ class MeshFunctionGnuplotWriterBase { static int get( const TNL::Meshes::MeshEntity< MeshConfig, Device, Topology >& entity ) { - throw "not implemented"; + throw Exceptions::NotImplementedError(); } }; @@ -56,7 +57,7 @@ class MeshFunctionGnuplotWriterBase { static int get( const TNL::Meshes::MeshEntity< MeshConfig, Device, Topology >& entity ) { - throw "not implemented"; + throw Exceptions::NotImplementedError(); } }; }; diff --git a/src/TNL/Functions/MeshFunctionNormGetter.h b/src/TNL/Functions/MeshFunctionNormGetter.h index 50e39c6de..7f00b6a6c 100644 --- a/src/TNL/Functions/MeshFunctionNormGetter.h +++ b/src/TNL/Functions/MeshFunctionNormGetter.h @@ -10,6 +10,8 @@ #pragma once +#include + namespace TNL { namespace Functions { @@ -134,7 +136,7 @@ class MeshFunctionNormGetter< MeshFunction< Meshes::Grid< Dimension, MeshReal, D } if( EntityDimension > 0 ) { - TNL_ASSERT_TRUE( false, "Not implemented yet." ); + throw Exceptions::NotImplementedError("Not implemented yet."); } if( p == 1.0 ) diff --git a/src/TNL/Functions/TestFunction_impl.h b/src/TNL/Functions/TestFunction_impl.h index f1776783c..e2bdce1f1 100644 --- a/src/TNL/Functions/TestFunction_impl.h +++ b/src/TNL/Functions/TestFunction_impl.h @@ -37,6 +37,8 @@ #include #include +#include + #include "TestFunction.h" namespace TNL { @@ -406,7 +408,7 @@ operator = ( const TestFunction& function ) this->copyFunction< SinWaveSDF< FunctionDimension, Real > >( function.function ); break; default: - TNL_ASSERT( false, ); + throw std::invalid_argument( "Unknown function type." ); break; } } @@ -890,8 +892,7 @@ copyFunction( const void* function ) } if( std::is_same< Device, Devices::Cuda >::value ) { - TNL_ASSERT( false, ); - abort(); + throw Exceptions::NotImplementedError( "Assignment operator is not implemented for CUDA." ); } } diff --git a/src/TNL/Matrices/CSR_impl.h b/src/TNL/Matrices/CSR_impl.h index 5fe617b54..7437c9302 100644 --- a/src/TNL/Matrices/CSR_impl.h +++ b/src/TNL/Matrices/CSR_impl.h @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef HAVE_CUSPARSE #include @@ -137,8 +138,7 @@ template< typename Real, Index CSR< Real, Device, Index >::getNonZeroRowLength( const IndexType row ) const { // TODO: Fix/Implement - TNL_ASSERT( false, std::cerr << "TODO: Fix/Implement" ); - return 0; + throw Exceptions::NotImplementedError( "CSR::getNonZeroRowLength is not implemented." ); // if( std::is_same< DeviceType, Devices::Host >::value ) // { // ConstMatrixRow matrixRow = this->getRow( row ); @@ -529,7 +529,7 @@ void CSR< Real, Device, Index >::addMatrix( const CSR< Real2, Device, Index2 >& const RealType& matrixMultiplicator, const RealType& thisMatrixMultiplicator ) { - TNL_ASSERT( false, std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "CSR::addMatrix is not implemented." ); // TODO: implement } @@ -541,7 +541,7 @@ template< typename Real, void CSR< Real, Device, Index >::getTransposition( const CSR< Real2, Device, Index2 >& matrix, const RealType& matrixMultiplicator ) { - TNL_ASSERT( false, std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "CSR::getTransposition is not implemented." ); // TODO: implement } @@ -847,8 +847,8 @@ class CSRDeviceDependentCode< Devices::MIC > const InVector& inVector, OutVector& outVector ) { - std::cout <<"Not Implemented YET tnlCSRMatrixDeviceDependentCode for MIC" <* matrixPtr = &matrix; const InVector* inVectorPtr = &inVector; diff --git a/src/TNL/Matrices/ChunkedEllpack_impl.h b/src/TNL/Matrices/ChunkedEllpack_impl.h index e3a686264..f3df045c4 100644 --- a/src/TNL/Matrices/ChunkedEllpack_impl.h +++ b/src/TNL/Matrices/ChunkedEllpack_impl.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace TNL { namespace Matrices { @@ -1185,7 +1186,7 @@ void ChunkedEllpack< Real, Device, Index >::addMatrix( const ChunkedEllpack< Rea const RealType& matrixMultiplicator, const RealType& thisMatrixMultiplicator ) { - TNL_ASSERT( false, std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "ChunkedEllpack::addMatrix is not implemented." ); // TODO: implement } @@ -1197,7 +1198,7 @@ template< typename Real, void ChunkedEllpack< Real, Device, Index >::getTransposition( const ChunkedEllpack< Real2, Device, Index2 >& matrix, const RealType& matrixMultiplicator ) { - TNL_ASSERT( false, std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "ChunkedEllpack::getTransposition is not implemented." ); // TODO: implement } @@ -1276,8 +1277,7 @@ ChunkedEllpack< Real, Device, Index >::operator=( const ChunkedEllpack< Real2, D this->setLike( matrix ); - std::cerr << "Cross-device assignment for the ChunkedEllpack format is not implemented yet." << std::endl; - throw 1; + throw Exceptions::NotImplementedError("Cross-device assignment for the ChunkedEllpack format is not implemented yet."); } diff --git a/src/TNL/Matrices/Dense_impl.h b/src/TNL/Matrices/Dense_impl.h index 2a73d03bf..a1702f0af 100644 --- a/src/TNL/Matrices/Dense_impl.h +++ b/src/TNL/Matrices/Dense_impl.h @@ -12,6 +12,7 @@ #include #include +#include namespace TNL { namespace Matrices { @@ -928,8 +929,7 @@ Dense< Real, Device, Index >::operator=( const Dense< Real2, Device2, Index2 >& this->setLike( matrix ); - std::cerr << "Cross-device assignment for the Dense format is not implemented yet." << std::endl; - throw 1; + throw Exceptions::NotImplementedError("Cross-device assignment for the Dense format is not implemented yet."); } diff --git a/src/TNL/Matrices/EllpackSymmetric_impl.h b/src/TNL/Matrices/EllpackSymmetric_impl.h index fed7f7669..ace203c56 100644 --- a/src/TNL/Matrices/EllpackSymmetric_impl.h +++ b/src/TNL/Matrices/EllpackSymmetric_impl.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace TNL { namespace Matrices { @@ -480,7 +481,7 @@ void EllpackSymmetric< Real, Device, Index > :: addMatrix( const EllpackSymmetri const RealType& matrixMultiplicator, const RealType& thisMatrixMultiplicator ) { - TNL_ASSERT( false,std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "EllpackSymmetric::addMatrix is not implemented." ); // TODO: implement } @@ -492,7 +493,7 @@ template< typename Real, void EllpackSymmetric< Real, Device, Index >::getTransposition( const EllpackSymmetric< Real2, Device, Index2 >& matrix, const RealType& matrixMultiplicator ) { - TNL_ASSERT( false,std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "EllpackSymmetric::getTransposition is not implemented." ); // TODO: implement } diff --git a/src/TNL/Matrices/Ellpack_impl.h b/src/TNL/Matrices/Ellpack_impl.h index 6c06fdd98..5a4e4b4d7 100644 --- a/src/TNL/Matrices/Ellpack_impl.h +++ b/src/TNL/Matrices/Ellpack_impl.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace TNL { namespace Matrices { @@ -533,7 +534,7 @@ void Ellpack< Real, Device, Index > :: addMatrix( const Ellpack< Real2, Device, const RealType& matrixMultiplicator, const RealType& thisMatrixMultiplicator ) { - TNL_ASSERT( false, std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "Ellpack::addMatrix is not implemented." ); // TODO: implement } @@ -545,7 +546,7 @@ template< typename Real, void Ellpack< Real, Device, Index >::getTransposition( const Ellpack< Real2, Device, Index2 >& matrix, const RealType& matrixMultiplicator ) { - TNL_ASSERT( false, std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "Ellpack::getTransposition is not implemented." ); // TODO: implement } diff --git a/src/TNL/Matrices/Multidiagonal_impl.h b/src/TNL/Matrices/Multidiagonal_impl.h index 860b3717c..38ffc13c3 100644 --- a/src/TNL/Matrices/Multidiagonal_impl.h +++ b/src/TNL/Matrices/Multidiagonal_impl.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace TNL { namespace Matrices { @@ -545,7 +546,7 @@ void Multidiagonal< Real, Device, Index > :: addMatrix( const Multidiagonal< Rea const RealType& matrixMultiplicator, const RealType& thisMatrixMultiplicator ) { - TNL_ASSERT( false, std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "Multidiagonal::addMatrix is not implemented." ); } template< typename Real, @@ -642,8 +643,7 @@ Multidiagonal< Real, Device, Index >::operator=( const Multidiagonal< Real2, Dev this->setLike( matrix ); - std::cerr << "Cross-device assignment for the Multidiagonal format is not implemented yet." << std::endl; - throw 1; + throw Exceptions::NotImplementedError("Cross-device assignment for the Multidiagonal format is not implemented yet."); } diff --git a/src/TNL/Matrices/SlicedEllpackSymmetricGraph_impl.h b/src/TNL/Matrices/SlicedEllpackSymmetricGraph_impl.h index dcd7ca3dc..c7611ee83 100644 --- a/src/TNL/Matrices/SlicedEllpackSymmetricGraph_impl.h +++ b/src/TNL/Matrices/SlicedEllpackSymmetricGraph_impl.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace TNL { namespace Matrices { @@ -510,7 +511,7 @@ void SlicedEllpackSymmetricGraph< Real, Device, Index, SliceSize >::addMatrix( c const RealType& matrixMultiplicator, const RealType& thisMatrixMultiplicator ) { - TNL_ASSERT( false,std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "SlicedEllpackSymmetricGraph::addMatrix is not implemented." ); // TODO: implement } @@ -523,7 +524,7 @@ template< typename Real, void SlicedEllpackSymmetricGraph< Real, Device, Index, SliceSize >::getTransposition( const SlicedEllpackSymmetricGraph< Real2, Device, Index2 >& matrix, const RealType& matrixMultiplicator ) { - TNL_ASSERT( false,std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "SlicedEllpackSymmetricGraph::getTransposition is not implemented." ); // TODO: implement } diff --git a/src/TNL/Matrices/SlicedEllpackSymmetric_impl.h b/src/TNL/Matrices/SlicedEllpackSymmetric_impl.h index 3a8e3cab4..579ca666d 100644 --- a/src/TNL/Matrices/SlicedEllpackSymmetric_impl.h +++ b/src/TNL/Matrices/SlicedEllpackSymmetric_impl.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace TNL { namespace Matrices { @@ -559,7 +560,7 @@ void SlicedEllpackSymmetric< Real, Device, Index, SliceSize >::addMatrix( const const RealType& matrixMultiplicator, const RealType& thisMatrixMultiplicator ) { - TNL_ASSERT( false,std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "SlicedEllpackSymmetric::addMatrix is not implemented." ); // TODO: implement } @@ -572,7 +573,7 @@ template< typename Real, void SlicedEllpackSymmetric< Real, Device, Index, SliceSize >::getTransposition( const SlicedEllpackSymmetric< Real2, Device, Index2 >& matrix, const RealType& matrixMultiplicator ) { - TNL_ASSERT( false,std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "SlicedEllpackSymmetric::getTransposition is not implemented." ); // TODO: implement } diff --git a/src/TNL/Matrices/SlicedEllpack_impl.h b/src/TNL/Matrices/SlicedEllpack_impl.h index 8e20c970e..31ac08dc8 100644 --- a/src/TNL/Matrices/SlicedEllpack_impl.h +++ b/src/TNL/Matrices/SlicedEllpack_impl.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace TNL { namespace Matrices { @@ -551,7 +552,7 @@ void SlicedEllpack< Real, Device, Index, SliceSize >::addMatrix( const SlicedEll const RealType& matrixMultiplicator, const RealType& thisMatrixMultiplicator ) { - TNL_ASSERT( false, std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "SlicedEllpack::addMatrix is not implemented." ); // TODO: implement } @@ -564,7 +565,7 @@ template< typename Real, void SlicedEllpack< Real, Device, Index, SliceSize >::getTransposition( const SlicedEllpack< Real2, Device, Index2 >& matrix, const RealType& matrixMultiplicator ) { - TNL_ASSERT( false, std::cerr << "TODO: implement" ); + throw Exceptions::NotImplementedError( "SlicedEllpack::getTransposition is not implemented." ); // TODO: implement } @@ -693,7 +694,7 @@ SlicedEllpack< Real, Device, Index, SliceSize >::operator=( const SlicedEllpack< } if( std::is_same< Device, Devices::MIC >::value ) { - throw std::runtime_error("Not Implemented yet for MIC"); + throw Exceptions::NotImplementedError("Cross-device assignment for the SlicedEllpack format is not implemented for MIC."); } return *this; @@ -1079,7 +1080,7 @@ class SlicedEllpackDeviceDependentCode< Devices::MIC > Index& rowEnd, Index& step ) { - throw std::runtime_error("Not Implemented yet SlicedEllpackDeviceDependentCode< Devices::MIC >::initRowTraverse"); + throw Exceptions::NotImplementedError("Not Implemented yet SlicedEllpackDeviceDependentCode< Devices::MIC >::initRowTraverse"); } template< typename Real, @@ -1092,7 +1093,7 @@ class SlicedEllpackDeviceDependentCode< Devices::MIC > Index& rowEnd, Index& step ) { - throw std::runtime_error("Not Implemented yet SlicedEllpackDeviceDependentCode< Devices::MIC >::initRowTraverseFast"); + throw Exceptions::NotImplementedError("Not Implemented yet SlicedEllpackDeviceDependentCode< Devices::MIC >::initRowTraverseFast"); } template< typename Real, @@ -1101,7 +1102,7 @@ class SlicedEllpackDeviceDependentCode< Devices::MIC > static bool computeMaximalRowLengthInSlices( SlicedEllpack< Real, Device, Index, SliceSize >& matrix, typename SlicedEllpack< Real, Device, Index >::ConstCompressedRowLengthsVectorView rowLengths ) { - throw std::runtime_error("Not Implemented yet SlicedEllpackDeviceDependentCode< Devices::MIC >::computeMaximalRowLengthInSlices"); + throw Exceptions::NotImplementedError("Not Implemented yet SlicedEllpackDeviceDependentCode< Devices::MIC >::computeMaximalRowLengthInSlices"); } template< typename Real, @@ -1113,7 +1114,7 @@ class SlicedEllpackDeviceDependentCode< Devices::MIC > const InVector& inVector, OutVector& outVector ) { - throw std::runtime_error("Not Implemented yet SlicedEllpackDeviceDependentCode< Devices::MIC >::vectorProduct"); + throw Exceptions::NotImplementedError("Not Implemented yet SlicedEllpackDeviceDependentCode< Devices::MIC >::vectorProduct"); } }; diff --git a/src/TNL/Matrices/SparseRow_impl.h b/src/TNL/Matrices/SparseRow_impl.h index 6c86b9d51..bc2705f2c 100644 --- a/src/TNL/Matrices/SparseRow_impl.h +++ b/src/TNL/Matrices/SparseRow_impl.h @@ -12,6 +12,7 @@ #include #include +#include // Following includes are here to enable usage of std::vector and std::cout. To avoid having to include Device type (HOW would this be done anyway) #include @@ -118,7 +119,7 @@ __global__ void getNonZeroRowLengthCudaKernel( const MatrixRow row, Index* result ) { // TODO: Fix/Implement - TNL_ASSERT( false, std::cerr << "TODO: Fix/Implement" ); + throw Exceptions::NotImplementedError( "TODO: Fix/Implement" ); // int threadId = blockIdx.x * blockDim.x + threadIdx.x; // if( threadId == 0 ) // { @@ -134,8 +135,7 @@ SparseRow< Real, Index >:: getNonZeroElementsCount() const { // TODO: Fix/Implement - TNL_ASSERT( false, std::cerr << "TODO: Fix/Implement" ); - return 0; + throw Exceptions::NotImplementedError( "TODO: Fix/Implement" ); // using NonConstIndex = typename std::remove_const< Index >::type; // // NonConstIndex elementCount ( 0 ); diff --git a/src/TNL/Matrices/Sparse_impl.h b/src/TNL/Matrices/Sparse_impl.h index 13b7ee7a9..6731ea1f4 100644 --- a/src/TNL/Matrices/Sparse_impl.h +++ b/src/TNL/Matrices/Sparse_impl.h @@ -11,6 +11,7 @@ #pragma once #include "Sparse.h" +#include namespace TNL { namespace Matrices { @@ -126,7 +127,7 @@ template< typename Real, typename Index > void Sparse< Real, Device, Index >::printStructure( std::ostream& str ) const { - TNL_ASSERT_TRUE( false, "Not implemented yet." ); + throw Exceptions::NotImplementedError("Sparse::printStructure is not implemented yet."); } } // namespace Matrices diff --git a/src/TNL/Matrices/Tridiagonal_impl.h b/src/TNL/Matrices/Tridiagonal_impl.h index 157145e14..9485998f3 100644 --- a/src/TNL/Matrices/Tridiagonal_impl.h +++ b/src/TNL/Matrices/Tridiagonal_impl.h @@ -12,6 +12,7 @@ #include #include +#include namespace TNL { namespace Matrices { @@ -402,7 +403,7 @@ const typename Tridiagonal< Real, Device, Index >::MatrixRow Tridiagonal< Real, Device, Index >:: getRow( const IndexType rowIndex ) const { - TNL_ASSERT( false, ); + throw Exceptions::NotImplementedError(); } @@ -578,8 +579,7 @@ Tridiagonal< Real, Device, Index >::operator=( const Tridiagonal< Real2, Device2 this->setLike( matrix ); - std::cerr << "Cross-device assignment for the Tridiagonal format is not implemented yet." << std::endl; - throw 1; + throw Exceptions::NotImplementedError("Cross-device assignment for the Tridiagonal format is not implemented yet."); } diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedMeshSynchronizer.h b/src/TNL/Meshes/DistributedMeshes/DistributedMeshSynchronizer.h index 03fff7fa1..4703b2050 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedMeshSynchronizer.h +++ b/src/TNL/Meshes/DistributedMeshes/DistributedMeshSynchronizer.h @@ -10,24 +10,25 @@ #pragma once +#include + namespace TNL { -namespace Meshes { +namespace Meshes { namespace DistributedMeshes { -template +template class DistributedMeshSynchronizer { public: - + // FIXME: clang does not like this (incomplete type error) // typedef typename MeshFunctionType::DistributedMeshType DistributedMeshType; - + template< typename DistributedMeshType > void setDistributedGrid( DistributedMeshType *distributedGrid ) { - TNL_ASSERT_TRUE( false, "Distribution of this type of mesh is NOT implemented" ); - } - + throw Exceptions::NotImplementedError("Distributed version of this mesh type is not implemented."); + } }; } // namespace DistributedMeshes diff --git a/src/TNL/Meshes/GridDetails/GridTraverser_1D.hpp b/src/TNL/Meshes/GridDetails/GridTraverser_1D.hpp index 42ba1b636..59989bb2a 100644 --- a/src/TNL/Meshes/GridDetails/GridTraverser_1D.hpp +++ b/src/TNL/Meshes/GridDetails/GridTraverser_1D.hpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace TNL { namespace Meshes { @@ -275,7 +276,7 @@ processEntities( GridTraverserMode mode, const int& stream ) { - std::cout << "Not Implemented yet Grid Traverser <1, Real, Device::MIC>" << std::endl; + throw Exceptions::NotImplementedError("Not Implemented yet Grid Traverser <1, Real, Device::MIC>"); /* auto& pool = CudaStreamPool::getInstance(); const cudaStream_t& s = pool.getStream( stream ); diff --git a/src/TNL/Meshes/GridDetails/GridTraverser_3D.hpp b/src/TNL/Meshes/GridDetails/GridTraverser_3D.hpp index 9259da9bf..5a3cd568f 100644 --- a/src/TNL/Meshes/GridDetails/GridTraverser_3D.hpp +++ b/src/TNL/Meshes/GridDetails/GridTraverser_3D.hpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace TNL { namespace Meshes { @@ -512,7 +513,7 @@ processEntities( const int& stream, const GridEntityParameters&... gridEntityParameters ) { - std::cout << "Not Implemented yet Grid Traverser <3, Real, Device::MIC>" << std::endl; + throw Exceptions::NotImplementedError("Not Implemented yet Grid Traverser <3, Real, Device::MIC>"); /* HAVE_CUDA dim3 cudaBlockSize( 8, 8, 8 ); diff --git a/src/TNL/Meshes/Readers/VTKReader.h b/src/TNL/Meshes/Readers/VTKReader.h index 7b52df0bc..b4b986537 100644 --- a/src/TNL/Meshes/Readers/VTKReader.h +++ b/src/TNL/Meshes/Readers/VTKReader.h @@ -17,6 +17,7 @@ #include #include +#include namespace TNL { namespace Meshes { @@ -46,8 +47,7 @@ public: // TODO: implement binary parsing if( dataType == "BINARY" ) { - std::cerr << "VTKReader: parsing of BINARY data is not implemented yet." << std::endl; - return false; + throw Exceptions::NotImplementedError("VTKReader: parsing of BINARY data is not implemented yet."); } std::string line, aux; @@ -176,8 +176,7 @@ public: // TODO: implement binary parsing if( dataType == "BINARY" ) { - std::cerr << "VTKReader: parsing of BINARY data is not implemented yet." << std::endl; - return false; + throw Exceptions::NotImplementedError("VTKReader: parsing of BINARY data is not implemented yet."); } std::string line, aux; diff --git a/src/TNL/Meshes/Writers/AsymptoteWriter.h b/src/TNL/Meshes/Writers/AsymptoteWriter.h index 96d138b96..62a9f073d 100644 --- a/src/TNL/Meshes/Writers/AsymptoteWriter.h +++ b/src/TNL/Meshes/Writers/AsymptoteWriter.h @@ -11,6 +11,7 @@ #pragma once #include +#include namespace TNL { namespace Meshes { @@ -24,13 +25,13 @@ class AsymptoteWriter public: static void writeAllEntities( const Mesh& mesh, std::ostream& str ) { - throw "not implemented"; + throw Exceptions::NotImplementedError(); } template< int EntityDimension = Mesh::getMeshDimension() > static void writeEntities( const Mesh& mesh, std::ostream& str ) { - throw "not implemented"; + throw Exceptions::NotImplementedError(); } }; @@ -154,7 +155,7 @@ public: template< int EntityDimension = Mesh::getMeshDimension() > static void writeEntities( const Mesh& mesh, std::ostream& str ) { - throw "not implemented"; + throw Exceptions::NotImplementedError(); } }; diff --git a/src/TNL/Solvers/Linear/Preconditioners/ILU0.h b/src/TNL/Solvers/Linear/Preconditioners/ILU0.h index f5f971543..1fc2fa3fa 100644 --- a/src/TNL/Solvers/Linear/Preconditioners/ILU0.h +++ b/src/TNL/Solvers/Linear/Preconditioners/ILU0.h @@ -17,6 +17,7 @@ #include #include #include +#include #if defined(HAVE_CUDA) && defined(HAVE_CUSPARSE) #include @@ -189,12 +190,12 @@ public: virtual void update( const MatrixPointer& matrixPointer ) override { - throw std::runtime_error("ILU0 is not implemented yet for CUDA and distributed matrices."); + throw Exceptions::NotImplementedError("ILU0 is not implemented yet for CUDA and distributed matrices."); } virtual void solve( ConstVectorViewType b, VectorViewType x ) const override { - throw std::runtime_error("ILU0 is not implemented yet for CUDA and distributed matrices."); + throw Exceptions::NotImplementedError("ILU0 is not implemented yet for CUDA and distributed matrices."); } }; @@ -212,12 +213,12 @@ public: virtual void update( const MatrixPointer& matrixPointer ) override { - throw std::runtime_error("Not Iplemented yet for MIC"); + throw Exceptions::NotImplementedError("Not Iplemented yet for MIC"); } virtual void solve( ConstVectorViewType b, VectorViewType x ) const override { - throw std::runtime_error("Not Iplemented yet for MIC"); + throw Exceptions::NotImplementedError("Not Iplemented yet for MIC"); } }; diff --git a/src/TNL/Solvers/Linear/Preconditioners/Preconditioner.h b/src/TNL/Solvers/Linear/Preconditioners/Preconditioner.h index 1bef28b9e..6934d1e55 100644 --- a/src/TNL/Solvers/Linear/Preconditioners/Preconditioner.h +++ b/src/TNL/Solvers/Linear/Preconditioners/Preconditioner.h @@ -52,7 +52,7 @@ public: virtual void solve( ConstVectorViewType b, VectorViewType x ) const { - TNL_ASSERT_TRUE( false, "The solve() method of a dummy preconditioner should not be called." ); + throw std::logic_error("The solve() method of a dummy preconditioner should not be called."); } String getType() const -- GitLab From 27b28734f1b33c533611361a1c308a045581167a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Mon, 24 Dec 2018 20:49:44 +0100 Subject: [PATCH 19/30] Switch to C++14 --- CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 208b4789a..07fc0aa77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,8 +62,8 @@ endif() # check if the compiler is good enough if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # GCC 5.0 is the first release with full C++11 support (due to libstdc++) - # https://gcc.gnu.org/gcc-5/changes.html + # GCC 5.0 is the first release with full C++11 support (due to libstdc++) as + # well as full C++14 support: https://gcc.gnu.org/gcc-5/changes.html if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0") message(FATAL_ERROR "Insufficient GCC version") endif() @@ -74,8 +74,13 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") endif() endif() +# set C++ standard +set( CMAKE_CXX_STANDARD 14 ) +set( CMAKE_CXX_STANDARD_REQUIRED ON ) +set( CMAKE_CXX_EXTENSIONS OFF ) + # set Debug/Release options -set( CMAKE_CXX_FLAGS "-std=c++11 -pthread -Wall -Wno-unused-local-typedefs -Wno-unused-variable" ) +set( CMAKE_CXX_FLAGS "-pthread -Wall -Wno-unused-local-typedefs -Wno-unused-variable" ) set( CMAKE_CXX_FLAGS_DEBUG "-g" ) set( CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -mtune=native -DNDEBUG" ) #set( CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -mtune=native -DNDEBUG -ftree-vectorizer-verbose=1 -ftree-vectorize -fopt-info-vec-missed -funroll-loops" ) -- GitLab From 00602293001707b93b66fc5244209cd91bbc9d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Tue, 25 Dec 2018 12:16:54 +0100 Subject: [PATCH 20/30] Require CUDA >= 9.0 due to C++14 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07fc0aa77..a21c4333e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,7 +152,7 @@ endif() # Check for CUDA # if( ${WITH_CUDA} ) - find_package( CUDA ) + find_package( CUDA 9.0 ) if( CUDA_FOUND ) set( BUILD_CUDA TRUE) set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF) -- GitLab From ab68ce891ea69c40b13c6d37637708edd5ab7400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 3 Jan 2019 17:22:16 +0100 Subject: [PATCH 21/30] Require cmake 3.12.2 due to CUDA 10 compatibility --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a21c4333e..7d0f8ca5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,9 @@ # ############################################################################### -cmake_minimum_required( VERSION 3.5.1 ) +# cmake 3.12.2 is required due to compatibility with CUDA 10 +# (see the issue reported here: https://github.com/clab/dynet/issues/1457 ) +cmake_minimum_required( VERSION 3.12.2 ) project( tnl ) -- GitLab From 0e22fa732b09f799337b6b6850131415dff41a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 12 Apr 2019 16:25:40 +0200 Subject: [PATCH 22/30] C++14 simplifications --- src/TNL/Containers/Array.h | 2 +- src/TNL/Containers/ArrayView.h | 4 ++-- src/TNL/Containers/DistributedArray.h | 6 ++---- src/TNL/Containers/DistributedArrayView.h | 4 ++-- src/TNL/Containers/DistributedVector.h | 4 ++-- src/TNL/Containers/DistributedVectorView.h | 4 ++-- src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.h | 2 +- src/TNL/Containers/Vector.h | 2 +- src/TNL/Containers/VectorView.h | 2 +- src/TNL/Functions/MeshFunction_impl.h | 6 +++--- src/TNL/Matrices/DistributedMatrix.h | 2 +- src/TNL/Matrices/ThreePartVector.h | 2 +- src/TNL/Solvers/Linear/LinearSolver.h | 6 +++--- src/TNL/Solvers/Linear/Preconditioners/Diagonal.h | 2 +- src/TNL/Solvers/Linear/Preconditioners/Preconditioner.h | 4 ++-- src/TNL/Solvers/Linear/Traits.h | 6 +++--- 16 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/TNL/Containers/Array.h b/src/TNL/Containers/Array.h index 3c99605a3..caeb88dd0 100644 --- a/src/TNL/Containers/Array.h +++ b/src/TNL/Containers/Array.h @@ -70,7 +70,7 @@ class Array : public Object using HostType = Containers::Array< Value, Devices::Host, Index >; using CudaType = Containers::Array< Value, Devices::Cuda, Index >; using ViewType = ArrayView< Value, Device, Index >; - using ConstViewType = ArrayView< typename std::add_const< Value >::type, Device, Index >; + using ConstViewType = ArrayView< std::add_const_t< Value >, Device, Index >; /** * \brief Basic constructor. diff --git a/src/TNL/Containers/ArrayView.h b/src/TNL/Containers/ArrayView.h index 91de01dac..40e6792af 100644 --- a/src/TNL/Containers/ArrayView.h +++ b/src/TNL/Containers/ArrayView.h @@ -12,7 +12,7 @@ #pragma once -#include // std::add_const +#include // std::add_const_t #include #include @@ -72,7 +72,7 @@ public: using HostType = ArrayView< Value, Devices::Host, Index >; using CudaType = ArrayView< Value, Devices::Cuda, Index >; using ViewType = ArrayView< Value, Device, Index >; - using ConstViewType = ArrayView< typename std::add_const< Value >::type, Device, Index >; + using ConstViewType = ArrayView< std::add_const_t< Value >, Device, Index >; /** * \brief Returns type of array view in C++ style. diff --git a/src/TNL/Containers/DistributedArray.h b/src/TNL/Containers/DistributedArray.h index f624100cb..edae7ccd0 100644 --- a/src/TNL/Containers/DistributedArray.h +++ b/src/TNL/Containers/DistributedArray.h @@ -12,8 +12,6 @@ #pragma once -#include // std::add_const - #include #include @@ -36,11 +34,11 @@ public: using LocalRangeType = Subrange< Index >; using LocalArrayType = Containers::Array< Value, Device, Index >; using LocalArrayViewType = Containers::ArrayView< Value, Device, Index >; - using ConstLocalArrayViewType = Containers::ArrayView< typename std::add_const< Value >::type, Device, Index >; + using ConstLocalArrayViewType = Containers::ArrayView< std::add_const_t< Value >, Device, Index >; using HostType = DistributedArray< Value, Devices::Host, Index, Communicator >; using CudaType = DistributedArray< Value, Devices::Cuda, Index, Communicator >; using ViewType = DistributedArrayView< Value, Device, Index, Communicator >; - using ConstViewType = DistributedArrayView< typename std::add_const< Value >::type, Device, Index, Communicator >; + using ConstViewType = DistributedArrayView< std::add_const_t< Value >, Device, Index, Communicator >; DistributedArray() = default; diff --git a/src/TNL/Containers/DistributedArrayView.h b/src/TNL/Containers/DistributedArrayView.h index 6995cf03e..4b099548b 100644 --- a/src/TNL/Containers/DistributedArrayView.h +++ b/src/TNL/Containers/DistributedArrayView.h @@ -33,11 +33,11 @@ public: using IndexType = Index; using LocalRangeType = Subrange< Index >; using LocalArrayViewType = Containers::ArrayView< Value, Device, Index >; - using ConstLocalArrayViewType = Containers::ArrayView< typename std::add_const< Value >::type, Device, Index >; + using ConstLocalArrayViewType = Containers::ArrayView< std::add_const_t< Value >, Device, Index >; using HostType = DistributedArrayView< Value, Devices::Host, Index, Communicator >; using CudaType = DistributedArrayView< Value, Devices::Cuda, Index, Communicator >; using ViewType = DistributedArrayView< Value, Device, Index, Communicator >; - using ConstViewType = DistributedArrayView< typename std::add_const< Value >::type, Device, Index, Communicator >; + using ConstViewType = DistributedArrayView< std::add_const_t< Value >, Device, Index, Communicator >; // Initialization by raw data __cuda_callable__ diff --git a/src/TNL/Containers/DistributedVector.h b/src/TNL/Containers/DistributedVector.h index 3e110b127..0607a1b16 100644 --- a/src/TNL/Containers/DistributedVector.h +++ b/src/TNL/Containers/DistributedVector.h @@ -33,11 +33,11 @@ public: using CommunicatorType = Communicator; using IndexType = Index; using LocalVectorViewType = Containers::VectorView< Real, Device, Index >; - using ConstLocalVectorViewType = Containers::VectorView< typename std::add_const< Real >::type, Device, Index >; + using ConstLocalVectorViewType = Containers::VectorView< std::add_const_t< Real >, Device, Index >; using HostType = DistributedVector< Real, Devices::Host, Index, Communicator >; using CudaType = DistributedVector< Real, Devices::Cuda, Index, Communicator >; using ViewType = DistributedVectorView< Real, Device, Index, Communicator >; - using ConstViewType = DistributedVectorView< typename std::add_const< Real >::type, Device, Index, Communicator >; + using ConstViewType = DistributedVectorView< std::add_const_t< Real >, Device, Index, Communicator >; // inherit all constructors and assignment operators from Array using BaseType::DistributedArray; diff --git a/src/TNL/Containers/DistributedVectorView.h b/src/TNL/Containers/DistributedVectorView.h index 7fc3778b4..5c0376e8d 100644 --- a/src/TNL/Containers/DistributedVectorView.h +++ b/src/TNL/Containers/DistributedVectorView.h @@ -34,11 +34,11 @@ public: using CommunicatorType = Communicator; using IndexType = Index; using LocalVectorViewType = Containers::VectorView< Real, Device, Index >; - using ConstLocalVectorViewType = Containers::VectorView< typename std::add_const< Real >::type, Device, Index >; + using ConstLocalVectorViewType = Containers::VectorView< std::add_const_t< Real >, Device, Index >; using HostType = DistributedVectorView< Real, Devices::Host, Index, Communicator >; using CudaType = DistributedVectorView< Real, Devices::Cuda, Index, Communicator >; using ViewType = DistributedVectorView< Real, Device, Index, Communicator >; - using ConstViewType = DistributedVectorView< typename std::add_const< Real >::type, Device, Index, Communicator >; + using ConstViewType = DistributedVectorView< std::add_const_t< Real >, Device, Index, Communicator >; // inherit all constructors and assignment operators from ArrayView using BaseType::DistributedArrayView; diff --git a/src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.h b/src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.h index 42addccd1..be86f31fa 100644 --- a/src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.h +++ b/src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.h @@ -89,7 +89,7 @@ class EllpackIndexMultimapValues protected: using ValuesCountType = typename std::conditional< std::is_const< IndexType >::value, - typename std::add_const< LocalIndexType >::type, + std::add_const_t< LocalIndexType >, LocalIndexType >::type; __cuda_callable__ diff --git a/src/TNL/Containers/Vector.h b/src/TNL/Containers/Vector.h index afdcad9ce..f9e1c68b3 100644 --- a/src/TNL/Containers/Vector.h +++ b/src/TNL/Containers/Vector.h @@ -39,7 +39,7 @@ public: using HostType = Vector< Real, TNL::Devices::Host, Index >; using CudaType = Vector< Real, TNL::Devices::Cuda, Index >; using ViewType = VectorView< Real, Device, Index >; - using ConstViewType = VectorView< typename std::add_const< Real >::type, Device, Index >; + using ConstViewType = VectorView< std::add_const_t< Real >, Device, Index >; /** Constructors and assignment operators are inherited from the class \ref Array. */ using Array< Real, Device, Index >::Array; diff --git a/src/TNL/Containers/VectorView.h b/src/TNL/Containers/VectorView.h index 0bf4ac044..1ae79565b 100644 --- a/src/TNL/Containers/VectorView.h +++ b/src/TNL/Containers/VectorView.h @@ -32,7 +32,7 @@ public: using HostType = VectorView< Real, Devices::Host, Index >; using CudaType = VectorView< Real, Devices::Cuda, Index >; using ViewType = VectorView< Real, Device, Index >; - using ConstViewType = VectorView< typename std::add_const< Real >::type, Device, Index >; + using ConstViewType = VectorView< std::add_const_t< Real >, Device, Index >; // inherit all ArrayView's constructors #ifndef __NVCC__ diff --git a/src/TNL/Functions/MeshFunction_impl.h b/src/TNL/Functions/MeshFunction_impl.h index 207165dfe..2c6f7a178 100644 --- a/src/TNL/Functions/MeshFunction_impl.h +++ b/src/TNL/Functions/MeshFunction_impl.h @@ -412,7 +412,7 @@ MeshFunction< Mesh, MeshEntityDimension, Real >:: operator = ( const Function& f ) { Pointers::DevicePointer< MeshFunction > thisDevicePtr( *this ); - Pointers::DevicePointer< typename std::add_const< Function >::type > fDevicePtr( f ); + Pointers::DevicePointer< std::add_const_t< Function > > fDevicePtr( f ); MeshFunctionEvaluator< MeshFunction, Function >::evaluate( thisDevicePtr, fDevicePtr ); return *this; } @@ -426,7 +426,7 @@ MeshFunction< Mesh, MeshEntityDimension, Real >:: operator += ( const Function& f ) { Pointers::DevicePointer< MeshFunction > thisDevicePtr( *this ); - Pointers::DevicePointer< typename std::add_const< Function >::type > fDevicePtr( f ); + Pointers::DevicePointer< std::add_const_t< Function > > fDevicePtr( f ); MeshFunctionEvaluator< MeshFunction, Function >::evaluate( thisDevicePtr, fDevicePtr, ( RealType ) 1.0, ( RealType ) 1.0 ); return *this; } @@ -440,7 +440,7 @@ MeshFunction< Mesh, MeshEntityDimension, Real >:: operator -= ( const Function& f ) { Pointers::DevicePointer< MeshFunction > thisDevicePtr( *this ); - Pointers::DevicePointer< typename std::add_const< Function >::type > fDevicePtr( f ); + Pointers::DevicePointer< std::add_const_t< Function > > fDevicePtr( f ); MeshFunctionEvaluator< MeshFunction, Function >::evaluate( thisDevicePtr, fDevicePtr, ( RealType ) 1.0, ( RealType ) -1.0 ); return *this; } diff --git a/src/TNL/Matrices/DistributedMatrix.h b/src/TNL/Matrices/DistributedMatrix.h index 776af7597..dd76804cf 100644 --- a/src/TNL/Matrices/DistributedMatrix.h +++ b/src/TNL/Matrices/DistributedMatrix.h @@ -61,7 +61,7 @@ public: using CompressedRowLengthsVector = Containers::DistributedVector< IndexType, DeviceType, IndexType, CommunicatorType >; using MatrixRow = Matrices::SparseRow< RealType, IndexType >; - using ConstMatrixRow = Matrices::SparseRow< typename std::add_const< RealType >::type, typename std::add_const< IndexType >::type >; + using ConstMatrixRow = Matrices::SparseRow< std::add_const_t< RealType >, std::add_const_t< IndexType > >; DistributedMatrix() = default; diff --git a/src/TNL/Matrices/ThreePartVector.h b/src/TNL/Matrices/ThreePartVector.h index 6afc2dd11..f57e3e116 100644 --- a/src/TNL/Matrices/ThreePartVector.h +++ b/src/TNL/Matrices/ThreePartVector.h @@ -90,7 +90,7 @@ template< typename Real, typename Index = int > class ThreePartVector { - using ConstReal = typename std::add_const< Real >::type; + using ConstReal = std::add_const_t< Real >; public: using RealType = Real; using DeviceType = Device; diff --git a/src/TNL/Solvers/Linear/LinearSolver.h b/src/TNL/Solvers/Linear/LinearSolver.h index e75d74b26..89158608f 100644 --- a/src/TNL/Solvers/Linear/LinearSolver.h +++ b/src/TNL/Solvers/Linear/LinearSolver.h @@ -12,7 +12,7 @@ #pragma once -#include // std::add_const +#include // std::add_const_t #include // std::shared_ptr #include @@ -39,9 +39,9 @@ public: using VectorViewType = typename Traits< Matrix >::VectorViewType; using ConstVectorViewType = typename Traits< Matrix >::ConstVectorViewType; using MatrixType = Matrix; - using MatrixPointer = Pointers::SharedPointer< typename std::add_const< MatrixType >::type >; + using MatrixPointer = Pointers::SharedPointer< std::add_const_t< MatrixType > >; using PreconditionerType = Preconditioners::Preconditioner< MatrixType >; - using PreconditionerPointer = std::shared_ptr< typename std::add_const< PreconditionerType >::type >; + using PreconditionerPointer = std::shared_ptr< std::add_const_t< PreconditionerType > >; static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ) diff --git a/src/TNL/Solvers/Linear/Preconditioners/Diagonal.h b/src/TNL/Solvers/Linear/Preconditioners/Diagonal.h index 71aa1ff1d..308423728 100644 --- a/src/TNL/Solvers/Linear/Preconditioners/Diagonal.h +++ b/src/TNL/Solvers/Linear/Preconditioners/Diagonal.h @@ -61,7 +61,7 @@ public: using typename Preconditioner< MatrixType >::MatrixPointer; using VectorType = Containers::Vector< RealType, DeviceType, IndexType >; using LocalVectorViewType = Containers::VectorView< RealType, DeviceType, IndexType >; - using ConstLocalVectorViewType = Containers::VectorView< typename std::add_const< RealType >::type, DeviceType, IndexType >; + using ConstLocalVectorViewType = Containers::VectorView< std::add_const_t< RealType >, DeviceType, IndexType >; virtual void update( const MatrixPointer& matrixPointer ) override; diff --git a/src/TNL/Solvers/Linear/Preconditioners/Preconditioner.h b/src/TNL/Solvers/Linear/Preconditioners/Preconditioner.h index 6934d1e55..2e70be2b1 100644 --- a/src/TNL/Solvers/Linear/Preconditioners/Preconditioner.h +++ b/src/TNL/Solvers/Linear/Preconditioners/Preconditioner.h @@ -10,7 +10,7 @@ #pragma once -#include // std::add_const +#include // std::add_const_t #include #include @@ -35,7 +35,7 @@ public: using VectorViewType = typename Traits< Matrix >::VectorViewType; using ConstVectorViewType = typename Traits< Matrix >::ConstVectorViewType; using MatrixType = Matrix; - using MatrixPointer = Pointers::SharedPointer< typename std::add_const< MatrixType >::type >; + using MatrixPointer = Pointers::SharedPointer< std::add_const_t< MatrixType > >; static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ) diff --git a/src/TNL/Solvers/Linear/Traits.h b/src/TNL/Solvers/Linear/Traits.h index f05ad2f50..4130ec430 100644 --- a/src/TNL/Solvers/Linear/Traits.h +++ b/src/TNL/Solvers/Linear/Traits.h @@ -37,7 +37,7 @@ struct Traits typename Matrix::DeviceType, typename Matrix::IndexType >; using ConstVectorViewType = Containers::VectorView - < typename std::add_const< typename Matrix::RealType >::type, + < std::add_const_t< typename Matrix::RealType >, typename Matrix::DeviceType, typename Matrix::IndexType >; @@ -70,7 +70,7 @@ struct Traits< Matrices::DistributedMatrix< Matrix, Communicator > > typename Matrix::IndexType, Communicator >; using ConstVectorViewType = Containers::DistributedVectorView - < typename std::add_const< typename Matrix::RealType >::type, + < std::add_const_t< typename Matrix::RealType >, typename Matrix::DeviceType, typename Matrix::IndexType, Communicator >; @@ -84,7 +84,7 @@ struct Traits< Matrices::DistributedMatrix< Matrix, Communicator > > typename Matrix::DeviceType, typename Matrix::IndexType >; using ConstLocalVectorViewType = Containers::VectorView - < typename std::add_const< typename Matrix::RealType >::type, + < std::add_const_t< typename Matrix::RealType >, typename Matrix::DeviceType, typename Matrix::IndexType >; -- GitLab From d57680eb4b1568dddc582396407b8caf993d64b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 12 Apr 2019 17:22:48 +0200 Subject: [PATCH 23/30] Revision of ArrayViewExample --- src/Examples/Containers/ArrayViewExample.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Examples/Containers/ArrayViewExample.cpp b/src/Examples/Containers/ArrayViewExample.cpp index 087dc19c6..9eb6aa712 100644 --- a/src/Examples/Containers/ArrayViewExample.cpp +++ b/src/Examples/Containers/ArrayViewExample.cpp @@ -1,11 +1,8 @@ #include -#include -#include #include #include using namespace TNL; -using namespace std; /*** * The following works for any device (CPU, GPU ...). @@ -18,18 +15,19 @@ void arrayViewExample() using IndexType = typename ArrayType::IndexType; using ViewType = Containers::ArrayView< int, Device >; ArrayType _a1( size ), _a2( size ); - ViewType a1( _a1 ), a2( _a2 ); + ViewType a1 = _a1.getView(); + ViewType a2 = _a2.getView(); /*** * You may initiate the array view using setElement */ - for( int i = 0; i< size; i++ ) + for( int i = 0; i < size; i++ ) a1.setElement( i, i ); /*** * You may also assign value to all array view elements ... */ - a2 = 0.0; + a2 = 0; /*** * Simple array view values checks can be done as follows ... @@ -45,8 +43,8 @@ void arrayViewExample() * More efficient way of array view elements manipulation is with the lambda functions */ ArrayType _a3( size ); - ViewType a3( _a3 ); - auto f1 = [] __cuda_callable__ ( IndexType i ) -> int { return 2 * i;}; + ViewType a3 = _a3.getView(); + auto f1 = [] __cuda_callable__ ( IndexType i ) -> int { return 2 * i; }; a3.evaluate( f1 ); for( int i = 0; i < size; i++ ) @@ -63,6 +61,7 @@ void arrayViewExample() */ a1.save( "a1.tnl" ); a2.load( "a1.tnl" ); + std::remove( "a1.tnl" ); if( a2 != a1 ) std::cerr << "Something is wrong!!!" << std::endl; -- GitLab From d02a0482c567c70a07036d99a2505fe8361e7f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 12 Apr 2019 17:24:07 +0200 Subject: [PATCH 24/30] Disabled building documentation on the CI --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9670a1ed7..e0228789c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,6 +21,7 @@ stages: WITH_MPI: "no" WITH_TESTS: "yes" WITH_COVERAGE: "no" + WITH_DOC: "no" # these are built only in the "full" config WITH_BENCHMARKS: "no" WITH_EXAMPLES: "no" @@ -55,6 +56,7 @@ stages: -DWITH_CUDA_ARCH=${WITH_CUDA_ARCH} -DWITH_MIC=${WITH_MIC} -DWITH_TESTS=${WITH_TESTS} + -DWITH_DOC=${WITH_DOC} -DWITH_COVERAGE=${WITH_COVERAGE} -DWITH_BENCHMARKS=${WITH_BENCHMARKS} -DWITH_EXAMPLES=${WITH_EXAMPLES} -- GitLab From 7f445c6a96078fc0f9b44f4de8c5d52bb2cea5c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 12 Apr 2019 19:07:00 +0200 Subject: [PATCH 25/30] Removed File::Mode enum --- src/Examples/FileExample.cpp | 5 ++-- src/Examples/FileExampleCuda.cu | 4 +-- src/Examples/FileExampleSaveAndLoad.cpp | 8 ++--- src/Examples/StringExample.cpp | 4 +-- src/TNL/Containers/ArrayView.hpp | 4 +-- src/TNL/File.h | 20 ++++--------- src/TNL/File.hpp | 29 ++++--------------- .../DistributedGridIO_MeshFunction.h | 6 ++-- src/TNL/Object.hpp | 8 ++--- src/UnitTests/Containers/ArrayTest.h | 12 ++++---- src/UnitTests/Containers/StaticArrayTest.cpp | 4 +-- src/UnitTests/FileTest.h | 22 +++++++------- .../CutDistributedMeshFunctionTest.cpp | 4 +-- .../DistributedMeshes/DistributedGridIOTest.h | 4 +-- .../DistributedGridIO_MPIIOTest.h | 4 +-- .../DistributedVectorFieldIO_MPIIOTestBase.h | 6 ++-- src/UnitTests/ObjectTest.cpp | 8 ++--- src/UnitTests/SaveAndLoadMeshfunctionTest.cpp | 4 +-- src/UnitTests/StringTest.cpp | 4 +-- 19 files changed, 64 insertions(+), 96 deletions(-) diff --git a/src/Examples/FileExample.cpp b/src/Examples/FileExample.cpp index 5239fc214..d8905d5ef 100644 --- a/src/Examples/FileExample.cpp +++ b/src/Examples/FileExample.cpp @@ -9,16 +9,15 @@ int main() { File file; - file.open( String("new-file.tnl"), File::Mode::Out ); + file.open( String("new-file.tnl"), std::ios_base::out ); String title("'string to file'"); file << title; file.close(); - file.open( String("new-file.tnl"), File::Mode::In ); + file.open( String("new-file.tnl"), std::ios_base::in ); String restoredString; file >> restoredString; file.close(); cout << "restored string = " << restoredString <( doubleArray, size ); file.close(); @@ -30,7 +30,7 @@ int main() /*** * Read array from the file to device */ - file.open( "test-file.tnl", File::Mode::In ); + file.open( "test-file.tnl", std::ios_base::in ); file.load< double, double, Devices::Cuda >( deviceArray, size ); file.close(); diff --git a/src/Examples/FileExampleSaveAndLoad.cpp b/src/Examples/FileExampleSaveAndLoad.cpp index 59718ed3f..00e353218 100644 --- a/src/Examples/FileExampleSaveAndLoad.cpp +++ b/src/Examples/FileExampleSaveAndLoad.cpp @@ -17,21 +17,21 @@ int main() * Save the array of doubles as floats. */ File file; - file.open( "test-file.tnl", File::Mode::Out | File::Mode::Truncate ); + file.open( "test-file.tnl", std::ios_base::out | std::ios_base::trunc ); file.save< double, float, Devices::Host >( doubleArray, size ); file.close(); /*** * Load the array of floats from the file. */ - file.open( "test-file.tnl", File::Mode::In ); + file.open( "test-file.tnl", std::ios_base::in ); file.load< float, float, Devices::Host >( floatArray, size ); file.close(); /*** * Load the array of floats from the file and convert them to integers. */ - file.open( "test-file.tnl", File::Mode::In ); + file.open( "test-file.tnl", std::ios_base::in ); file.load< int, float, Devices::Host >( intArray, size ); file.close(); @@ -44,5 +44,3 @@ int main() << floatArray[ i ] << " -- " << intArray[ i ] << std::endl; } - - diff --git a/src/Examples/StringExample.cpp b/src/Examples/StringExample.cpp index 19ed24bd1..609e2a269 100644 --- a/src/Examples/StringExample.cpp +++ b/src/Examples/StringExample.cpp @@ -47,11 +47,11 @@ int main( int argc, char* argv[] ) cout << "string1 is not empty" << endl; File myFile; - myFile.open( "string_save.out", File::Mode::Out ); + myFile.open( "string_save.out", std::ios_base::out ); myFile << string1; myFile.close(); - myFile.open( "string_save.out", File::Mode::In ); + myFile.open( "string_save.out", std::ios_base::in ); myFile >> string3; cout << "string 3 after loading = " << string3 << endl; } diff --git a/src/TNL/Containers/ArrayView.hpp b/src/TNL/Containers/ArrayView.hpp index a32c2c5f0..6b2f9fae0 100644 --- a/src/TNL/Containers/ArrayView.hpp +++ b/src/TNL/Containers/ArrayView.hpp @@ -379,7 +379,7 @@ ArrayView< Value, Device, Index >:: save( const String& fileName ) const { File file; - file.open( fileName, File::Mode::Out ); + file.open( fileName, std::ios_base::out ); this->save( file ); } @@ -391,7 +391,7 @@ ArrayView< Value, Device, Index >:: load( const String& fileName ) { File file; - file.open( fileName, File::Mode::In ); + file.open( fileName, std::ios_base::in ); this->load( file ); } diff --git a/src/TNL/File.h b/src/TNL/File.h index 120d7342d..6463e2cc4 100644 --- a/src/TNL/File.h +++ b/src/TNL/File.h @@ -32,18 +32,6 @@ class File { public: - /** - * This enum defines mode for opening files. - */ - enum class Mode - { - In = 1, ///< Open for input. - Out = 2, ///< Open for output. - Append = 4, ///< Output operations are appended at the end of file. - AtEnd = 8, ///< Set the initial position at the end. - Truncate = 16 ///< If the file is opened for ouptput, its previous content is deleted. - }; - /** * \brief Basic constructor. */ @@ -52,15 +40,17 @@ class File /** * \brief Open given file. * - * Opens file with given \e fileName in some \e mode from \ref File::Mode. + * Opens file with given \e fileName in some \e mode from \ref std::ios_base::openmode. + * Note that the file is always opened in binary mode, i.e. \ref std::ios_base::binary + * is always added to \e mode. * * Throws \ref std::ios_base::failure on failure. * * \param fileName String which indicates file name. - * \param mode Indicates in what mode the file will be opened - see. \ref File::Mode. + * \param mode Indicates in what mode the file will be opened - see \ref std::ios_base::openmode. */ void open( const String& fileName, - Mode mode = static_cast< Mode >( static_cast< int >( Mode::In ) | static_cast< int >( Mode::Out ) ) ); + std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out ); /** * \brief Closes the file. diff --git a/src/TNL/File.hpp b/src/TNL/File.hpp index 4b6e1cb42..a764d7242 100644 --- a/src/TNL/File.hpp +++ b/src/TNL/File.hpp @@ -25,34 +25,25 @@ namespace TNL { -inline File::Mode operator|( File::Mode m1, File::Mode m2 ); - -inline bool operator&( File::Mode m1, File::Mode m2 ); - -inline void File::open( const String& fileName, Mode mode ) +inline void File::open( const String& fileName, std::ios_base::openmode mode ) { // enable exceptions file.exceptions( std::fstream::failbit | std::fstream::badbit | std::fstream::eofbit ); close(); - auto ios_mode = std::ios::binary; - if( mode & Mode::In ) ios_mode |= std::ios::in; - if( mode & Mode::Out ) ios_mode |= std::ios::out; - if( mode & Mode::Append ) ios_mode |= std::ios::app; - if( mode & Mode::AtEnd ) ios_mode |= std::ios::ate; - if( mode & Mode::Truncate ) ios_mode |= std::ios::trunc; + mode |= std::ios::binary; try { - file.open( fileName.getString(), ios_mode ); + file.open( fileName.getString(), mode ); } catch( std::ios_base::failure& ) { std::stringstream msg; msg << "Unable to open file " << fileName << " "; - if( mode & Mode::In ) + if( mode & std::ios_base::in ) msg << " for reading."; - if( mode & Mode::Out ) + if( mode & std::ios_base::out ) msg << " for writing."; throw std::ios_base::failure( msg.str() ); @@ -408,14 +399,4 @@ inline File& operator>>( File& file, std::string& str ) return file; } -inline File::Mode operator|( File::Mode m1, File::Mode m2 ) -{ - return static_cast< File::Mode >( static_cast< int >( m1 ) | static_cast< int >( m2 ) ); -} - -inline bool operator&( File::Mode m1, File::Mode m2 ) -{ - return static_cast< bool >( static_cast< int >( m1 ) & static_cast< int >( m2 ) ); -} - } // namespace TNL diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h index b9d3c5e24..1a1caeded 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h +++ b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h @@ -65,7 +65,7 @@ class DistributedGridIO< newMesh->setOrigin(origin+TNL::Containers::Scale(spaceSteps,localBegin)); File meshFile; - meshFile.open( fileName+String("-mesh-")+distrGrid->printProcessCoords()+String(".tnl"),File::Mode::Out ); + meshFile.open( fileName+String("-mesh-")+distrGrid->printProcessCoords()+String(".tnl"), std::ios_base::out ); newMesh->save( meshFile ); meshFile.close(); @@ -80,7 +80,7 @@ class DistributedGridIO< CopyEntitiesHelper::Copy(meshFunction,newMeshFunction,localBegin,zeroCoord,localSize); File file; - file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::Out ); + file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), std::ios_base::out ); newMeshFunction.save(file); file.close(); @@ -119,7 +119,7 @@ class DistributedGridIO< zeroCoord.setValue(0); File file; - file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::In ); + file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), std::ios_base::in ); newMeshFunction.boundLoad(file); file.close(); CopyEntitiesHelper::Copy(newMeshFunction,meshFunction,zeroCoord,localBegin,localSize); diff --git a/src/TNL/Object.hpp b/src/TNL/Object.hpp index 92d33626d..6af83feee 100644 --- a/src/TNL/Object.hpp +++ b/src/TNL/Object.hpp @@ -63,21 +63,21 @@ inline void Object::boundLoad( File& file ) inline void Object::save( const String& fileName ) const { File file; - file.open( fileName, File::Mode::Out ); + file.open( fileName, std::ios_base::out ); this->save( file ); } inline void Object::load( const String& fileName ) { File file; - file.open( fileName, File::Mode::In ); + file.open( fileName, std::ios_base::in ); this->load( file ); } inline void Object::boundLoad( const String& fileName ) { File file; - file.open( fileName, File::Mode::In ); + file.open( fileName, std::ios_base::in ); this->boundLoad( file ); } @@ -95,7 +95,7 @@ inline String getObjectType( File& file ) inline String getObjectType( const String& fileName ) { File binaryFile; - binaryFile.open( fileName, File::Mode::In ); + binaryFile.open( fileName, std::ios_base::in ); return getObjectType( binaryFile ); } diff --git a/src/UnitTests/Containers/ArrayTest.h b/src/UnitTests/Containers/ArrayTest.h index dc054e1a8..2d4283221 100644 --- a/src/UnitTests/Containers/ArrayTest.h +++ b/src/UnitTests/Containers/ArrayTest.h @@ -479,10 +479,10 @@ TYPED_TEST( ArrayTest, SaveAndLoad ) for( int i = 0; i < 100; i ++ ) v.setElement( i, 3.14147 ); File file; - ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::out ) ); ASSERT_NO_THROW( v.save( file ) ); ASSERT_NO_THROW( file.close() ); - ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); ASSERT_NO_THROW( u.load( file ) ); EXPECT_EQ( u, v ); @@ -498,23 +498,23 @@ TYPED_TEST( ArrayTest, boundLoad ) for( int i = 0; i < 100; i ++ ) v.setElement( i, 3.14147 ); File file; - ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::out ) ); ASSERT_NO_THROW( v.save( file ) ); ASSERT_NO_THROW( file.close() ); w.setSize( 100 ); auto u = w.getView(); - ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); ASSERT_NO_THROW( u.load( file ) ); EXPECT_EQ( u, v ); EXPECT_EQ( u.getData(), w.getData() ); ArrayType z( 50 ); - ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); EXPECT_ANY_THROW( z.boundLoad( file ) ); v.reset(); - ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); EXPECT_NO_THROW( v.boundLoad( file ) ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); diff --git a/src/UnitTests/Containers/StaticArrayTest.cpp b/src/UnitTests/Containers/StaticArrayTest.cpp index f1f6b208d..3cb37e07c 100644 --- a/src/UnitTests/Containers/StaticArrayTest.cpp +++ b/src/UnitTests/Containers/StaticArrayTest.cpp @@ -246,10 +246,10 @@ TYPED_TEST( StaticArrayTest, SaveAndLoad ) ArrayType u1( 7 ), u2; File file; - ASSERT_NO_THROW( file.open( "tnl-static-array-test.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( file.open( "tnl-static-array-test.tnl", std::ios_base::out ) ); ASSERT_NO_THROW( u1.save( file ) ); ASSERT_NO_THROW( file.close() ); - ASSERT_NO_THROW( file.open( "tnl-static-array-test.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( file.open( "tnl-static-array-test.tnl", std::ios_base::in ) ); ASSERT_NO_THROW( u2.load( file ) ); ASSERT_NO_THROW( file.close() ); diff --git a/src/UnitTests/FileTest.h b/src/UnitTests/FileTest.h index 1e0db34f4..b767dd0c3 100644 --- a/src/UnitTests/FileTest.h +++ b/src/UnitTests/FileTest.h @@ -18,13 +18,13 @@ using namespace TNL; TEST( FileTest, OpenInvalid ) { File file; - EXPECT_THROW( file.open( "invalid-file.tnl", File::Mode::In ), std::ios_base::failure ); + EXPECT_THROW( file.open( "invalid-file.tnl", std::ios_base::in ), std::ios_base::failure ); } TEST( FileTest, WriteAndRead ) { File file; - ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::Out ) ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), std::ios_base::out ) ); int intData( 5 ); double doubleData[ 3 ] = { 1.0, 2.0, 3.0 }; @@ -34,7 +34,7 @@ TEST( FileTest, WriteAndRead ) ASSERT_NO_THROW( file.save( &constDoubleData ) ); ASSERT_NO_THROW( file.close() ); - ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::In ) ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), std::ios_base::in ) ); int newIntData; double newDoubleData[ 3 ]; double newConstDoubleData; @@ -58,15 +58,15 @@ TEST( FileTest, WriteAndReadWithConversion ) float floatData[ 3 ]; int intData[ 3 ]; File file; - ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out | File::Mode::Truncate ) ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::out | std::ios_base::trunc ) ); file.save< double, float, Devices::Host >( doubleData, 3 ); ASSERT_NO_THROW( file.close() ); - ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); file.load< float, float, Devices::Host >( floatData, 3 ); ASSERT_NO_THROW( file.close() ); - ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); file.load< int, float, Devices::Host >( intData, 3 ); ASSERT_NO_THROW( file.close() ); @@ -108,14 +108,14 @@ TEST( FileTest, WriteAndReadCUDA ) cudaMemcpyHostToDevice ); File file; - ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::Out ) ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), std::ios_base::out ) ); file.save< int, int, Devices::Cuda >( cudaIntData ); file.save< float, float, Devices::Cuda >( cudaFloatData, 3 ); file.save< const double, double, Devices::Cuda >( cudaConstDoubleData ); ASSERT_NO_THROW( file.close() ); - ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::In ) ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), std::ios_base::in ) ); int newIntData; float newFloatData[ 3 ]; double newDoubleData; @@ -169,15 +169,15 @@ TEST( FileTest, WriteAndReadCUDAWithConversion ) cudaMemcpyHostToDevice ); File file; - ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), File::Mode::Out | File::Mode::Truncate ) ); + ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), std::ios_base::out | std::ios_base::trunc ) ); file.save< double, float, Devices::Cuda >( cudaConstDoubleData, 3 ); ASSERT_NO_THROW( file.close() ); - ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), File::Mode::In ) ); + ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), std::ios_base::in ) ); file.load< float, float, Devices::Cuda >( cudaFloatData, 3 ); ASSERT_NO_THROW( file.close() ); - ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), File::Mode::In ) ); + ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), std::ios_base::in ) ); file.load< int, float, Devices::Cuda >( cudaIntData, 3 ); ASSERT_NO_THROW( file.close() ); diff --git a/src/UnitTests/Meshes/DistributedMeshes/CutDistributedMeshFunctionTest.cpp b/src/UnitTests/Meshes/DistributedMeshes/CutDistributedMeshFunctionTest.cpp index 7a19611da..456cd01f6 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/CutDistributedMeshFunctionTest.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/CutDistributedMeshFunctionTest.cpp @@ -591,7 +591,7 @@ TEST(CutDistributedMeshFunction, 3D_2_Save) if(CommunicatorType::GetRank(*group)==0) { File meshFile; - meshFile.open( FileName+String("-mesh.tnl"),File::Mode::Out); + meshFile.open( FileName+String("-mesh.tnl"),std::ios_base::out); cutDistributedGrid.getGlobalGrid().save( meshFile ); meshFile.close(); } @@ -611,7 +611,7 @@ TEST(CutDistributedMeshFunction, 3D_2_Save) loadMeshFunctionptr.bind(globalCutGrid,loaddof); File file; - file.open( FileName, File::Mode::In ); + file.open( FileName, std::ios_base::in ); loadMeshFunctionptr.boundLoad(file); file.close(); diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTest.h b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTest.h index 09be099c5..e0b2e14ea 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTest.h +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTest.h @@ -276,7 +276,7 @@ class TestDistributedGridIO String localFileName= fileName+String("-")+distributedGrid.printProcessCoords()+String(".tnl"); File file; - file.open(localFileName, File::Mode::In ); + file.open(localFileName, std::ios_base::in ); loadMeshFunctionptr->boundLoad(file); file.close(); @@ -336,7 +336,7 @@ class TestDistributedGridIO String fileName=String("test-file-distributedgrid-io-load.tnl"); String localFileName=fileName+String("-")+distributedGrid.printProcessCoords()+String(".tnl"); File file; - file.open( localFileName, File::Mode::Out ); + file.open( localFileName, std::ios_base::out ); localMeshFunctionptr->save(file); file.close(); diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIO_MPIIOTest.h b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIO_MPIIOTest.h index b19c8641f..477b28c2e 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIO_MPIIOTest.h +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIO_MPIIOTest.h @@ -100,7 +100,7 @@ class TestDistributedGridMPIIO{ loadDof.setValue(-1); File file; - file.open( FileName, File::Mode::In ); + file.open( FileName, std::ios_base::in ); loadMeshFunctionptr->boundLoad(file); file.close(); @@ -148,7 +148,7 @@ class TestDistributedGridMPIIO{ linearFunctionEvaluator.evaluateAllEntities(saveMeshFunctionptr , linearFunctionPtr); File file; - file.open( FileName, File::Mode::Out ); + file.open( FileName, std::ios_base::out ); saveMeshFunctionptr->save(file); file.close(); } diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedVectorFieldIO_MPIIOTestBase.h b/src/UnitTests/Meshes/DistributedMeshes/DistributedVectorFieldIO_MPIIOTestBase.h index 055faa812..f3eb66731 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedVectorFieldIO_MPIIOTestBase.h +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedVectorFieldIO_MPIIOTestBase.h @@ -80,7 +80,7 @@ class TestDistributedVectorFieldMPIIO{ String FileName=String("/tmp/test-file.tnl"); DistributedGridIO ::save(FileName, vectorField ); /*File file; - file.open( FileName, File::Mode::Out ); + file.open( FileName, std::ios_base::out ); vectorField.save(file); file.close(); */ @@ -102,7 +102,7 @@ class TestDistributedVectorFieldMPIIO{ loadDof.setValue(-1); File file; - file.open( FileName, File::Mode::In ); + file.open( FileName, std::ios_base::in ); loadvct.boundLoad(file); for(int i=0;isave(file) ); ASSERT_NO_THROW( file.close() ); @@ -80,7 +80,7 @@ class TestSaveAndLoadMeshfunction loadDof[i]=-1; } - ASSERT_NO_THROW( file.open( String( FILENAME ), File::Mode::In ) ); + ASSERT_NO_THROW( file.open( String( FILENAME ), std::ios_base::in ) ); ASSERT_NO_THROW( loadMeshFunctionptr->boundLoad(file) ); ASSERT_NO_THROW( file.close() ); diff --git a/src/UnitTests/StringTest.cpp b/src/UnitTests/StringTest.cpp index 099bc4d6c..d2588f5ed 100644 --- a/src/UnitTests/StringTest.cpp +++ b/src/UnitTests/StringTest.cpp @@ -306,10 +306,10 @@ TEST( StringTest, SaveLoad ) { String str1( "testing-string" ); File file; - ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::out ) ); ASSERT_NO_THROW( file << str1 ); ASSERT_NO_THROW( file.close() ); - ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); String str2; ASSERT_NO_THROW( file >> str2 ); EXPECT_EQ( str1, str2 ); -- GitLab From 9aa442c48a9c1ca05e61f1852dc94b65831f81ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 12 Apr 2019 19:33:57 +0200 Subject: [PATCH 26/30] Removed superfluous exceptions for file loading/saving Exceptions are meant to categorize errors, so there should not be many different exceptions and they should not be specific for a small number of objects/functions. Let's make all save/load methods throw only 2 exceptions: FileSerializationError and FileDeserializationError. --- src/TNL/Containers/Array.hpp | 8 +-- src/TNL/Containers/ArrayView.hpp | 6 +-- src/TNL/Exceptions/ArrayWrongSize.h | 32 ------------ src/TNL/Exceptions/FileDeserializationError.h | 4 +- src/TNL/Exceptions/FileSerializationError.h | 4 +- src/TNL/Exceptions/MeshFunctionDataMismatch.h | 32 ------------ src/TNL/Exceptions/NotTNLFile.h | 31 ----------- .../Exceptions/ObjectTypeDetectionFailure.h | 31 ----------- src/TNL/Exceptions/ObjectTypeMismatch.h | 32 ------------ src/TNL/File.hpp | 8 +-- src/TNL/Functions/MeshFunction.h | 2 +- src/TNL/Functions/MeshFunction_impl.h | 7 +-- src/TNL/Meshes/Readers/TNLReader.h | 12 +---- src/TNL/Object.h | 52 ++++++++++++------- src/TNL/Object.hpp | 8 ++- src/Tools/tnl-diff.cpp | 11 +--- src/Tools/tnl-lattice-init.h | 33 ++---------- 17 files changed, 61 insertions(+), 252 deletions(-) delete mode 100644 src/TNL/Exceptions/ArrayWrongSize.h delete mode 100644 src/TNL/Exceptions/MeshFunctionDataMismatch.h delete mode 100644 src/TNL/Exceptions/NotTNLFile.h delete mode 100644 src/TNL/Exceptions/ObjectTypeDetectionFailure.h delete mode 100644 src/TNL/Exceptions/ObjectTypeMismatch.h diff --git a/src/TNL/Containers/Array.hpp b/src/TNL/Containers/Array.hpp index f5a49214f..34fb38e62 100644 --- a/src/TNL/Containers/Array.hpp +++ b/src/TNL/Containers/Array.hpp @@ -11,6 +11,7 @@ #pragma once #include +#include #include #include @@ -18,7 +19,6 @@ #include #include #include -#include #include "Array.h" @@ -673,7 +673,7 @@ load( File& file ) Index _size; file.load( &_size ); if( _size < 0 ) - throw Exceptions::ArrayWrongSize( _size, "positive" ); + throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) ); setSize( _size ); if( _size ) Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); @@ -690,11 +690,11 @@ boundLoad( File& file ) Index _size; file.load( &_size ); if( _size < 0 ) - throw Exceptions::ArrayWrongSize( _size, "Positive is expected," ); + throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) ); if( this->getSize() != 0 ) { if( this->getSize() != _size ) - throw Exceptions::ArrayWrongSize( _size, convertToString( this->getSize() ) + " is expected." ); + throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) + " (expected " + std::to_string( this->getSize() ) + ")." ); } else setSize( _size ); if( _size ) diff --git a/src/TNL/Containers/ArrayView.hpp b/src/TNL/Containers/ArrayView.hpp index 6b2f9fae0..cca4ceef5 100644 --- a/src/TNL/Containers/ArrayView.hpp +++ b/src/TNL/Containers/ArrayView.hpp @@ -11,13 +11,13 @@ #pragma once #include +#include #include #include #include #include #include -#include #include "ArrayView.h" @@ -363,11 +363,11 @@ load( File& file ) String type; loadHeader( file, type ); if( type != SerializationType::getType() ) - throw Exceptions::ObjectTypeMismatch( SerializationType::getType(), type ); + throw Exceptions::FileDeserializationError( file.getFileName(), "invalid object type: " + type + " (expected " + SerializationType::getType() + ")." ); Index _size; file.load( &_size ); if( _size != this->getSize() ) - throw Exceptions::ArrayWrongSize( _size, convertToString( this->getSize() ) ); + throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) + " (expected " + std::to_string( this->getSize() ) + ")." ); Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); } diff --git a/src/TNL/Exceptions/ArrayWrongSize.h b/src/TNL/Exceptions/ArrayWrongSize.h deleted file mode 100644 index 8181b3c55..000000000 --- a/src/TNL/Exceptions/ArrayWrongSize.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - ArrayWrongSize.h - description - ------------------- - begin : Mar 8, 2019 - copyright : (C) 2019 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -// Implemented by: Tomas Oberhuber - -#pragma once - -#include -#include -#include - -namespace TNL { -namespace Exceptions { - -class ArrayWrongSize - : public std::runtime_error -{ -public: - ArrayWrongSize( std::size_t size, const String& mesg = "" ) - : std::runtime_error( "Wrong array size " + convertToString( size ) + ". " + mesg ) - {} -}; - -} // namespace Exceptions -} // namespace TNL diff --git a/src/TNL/Exceptions/FileDeserializationError.h b/src/TNL/Exceptions/FileDeserializationError.h index d6c02cbf2..9ba647c6f 100644 --- a/src/TNL/Exceptions/FileDeserializationError.h +++ b/src/TNL/Exceptions/FileDeserializationError.h @@ -22,8 +22,8 @@ class FileDeserializationError : public std::runtime_error { public: - FileDeserializationError( const std::string& objectType, const std::string& fileName ) - : std::runtime_error( "Failed to deserialize object of type '" + objectType + "' from file '" + fileName + "'." ) + FileDeserializationError( const std::string& fileName, const std::string& details ) + : std::runtime_error( "Failed to deserialize an object from the file '" + fileName + "': " + details ) {} }; diff --git a/src/TNL/Exceptions/FileSerializationError.h b/src/TNL/Exceptions/FileSerializationError.h index 6336efa54..77320f000 100644 --- a/src/TNL/Exceptions/FileSerializationError.h +++ b/src/TNL/Exceptions/FileSerializationError.h @@ -22,8 +22,8 @@ class FileSerializationError : public std::runtime_error { public: - FileSerializationError( const std::string& objectType, const std::string& fileName ) - : std::runtime_error( "Failed to serialize object of type '" + objectType + "' into file '" + fileName + "'." ) + FileSerializationError( const std::string& fileName, const std::string& details ) + : std::runtime_error( "Failed to serialize an object into the file '" + fileName + "': " + details ) {} }; diff --git a/src/TNL/Exceptions/MeshFunctionDataMismatch.h b/src/TNL/Exceptions/MeshFunctionDataMismatch.h deleted file mode 100644 index 6106db872..000000000 --- a/src/TNL/Exceptions/MeshFunctionDataMismatch.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - MeshFunctionDataMismatch.h - description - ------------------- - begin : Mar 8, 2019 - copyright : (C) 2019 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -// Implemented by: Tomas Oberhuber - -#pragma once - -#include -#include -#include - -namespace TNL { -namespace Exceptions { - -class MeshFunctionDataMismatch - : public std::runtime_error -{ -public: - MeshFunctionDataMismatch( std::size_t size, const String& mesg = "" ) - : std::runtime_error( "Mesh function data size " + convertToString( size ) + " mismatch." + mesg ) - {} -}; - -} // namespace Exceptions -} // namespace TNL diff --git a/src/TNL/Exceptions/NotTNLFile.h b/src/TNL/Exceptions/NotTNLFile.h deleted file mode 100644 index ce2d756a5..000000000 --- a/src/TNL/Exceptions/NotTNLFile.h +++ /dev/null @@ -1,31 +0,0 @@ -/*************************************************************************** - NotTNLFile.h - description - ------------------- - begin : Mar 4, 2019 - copyright : (C) 2019 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -// Implemented by: Tomas Oberhuber - -#pragma once - -#include -#include - -namespace TNL { -namespace Exceptions { - -class NotTNLFile - : public std::runtime_error -{ -public: - NotTNLFile() - : std::runtime_error( "Wrong magic number found in a binary file. It is not TNL compatible file." ) - {} -}; - -} // namespace Exceptions -} // namespace TNL diff --git a/src/TNL/Exceptions/ObjectTypeDetectionFailure.h b/src/TNL/Exceptions/ObjectTypeDetectionFailure.h deleted file mode 100644 index 6381c2fd7..000000000 --- a/src/TNL/Exceptions/ObjectTypeDetectionFailure.h +++ /dev/null @@ -1,31 +0,0 @@ -/*************************************************************************** - ObjectTypeDetectionFailure.h - description - ------------------- - begin : Mar 4, 2019 - copyright : (C) 2019 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -// Implemented by: Tomas Oberhuber - -#pragma once - -#include -#include - -namespace TNL { -namespace Exceptions { - -class ObjectTypeDetectionFailure - : public std::runtime_error -{ -public: - ObjectTypeDetectionFailure( const String& fileName, const String& objectType ) - : std::runtime_error( "Failed to detect " + objectType + " in file " + fileName + "." ) - {} -}; - -} // namespace Exceptions -} // namespace TNL diff --git a/src/TNL/Exceptions/ObjectTypeMismatch.h b/src/TNL/Exceptions/ObjectTypeMismatch.h deleted file mode 100644 index 9b48fd0ea..000000000 --- a/src/TNL/Exceptions/ObjectTypeMismatch.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - ObjectTypeMismatch.h - description - ------------------- - begin : Mar 8, 2019 - copyright : (C) 2019 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -// Implemented by: Tomas Oberhuber - -#pragma once - -#include -#include -#include - -namespace TNL { -namespace Exceptions { - -class ObjectTypeMismatch - : public std::runtime_error -{ -public: - ObjectTypeMismatch( const String& expected, const String& detected ) - : std::runtime_error( "Object type mismatch. Expected object type is " + expected + " but " + detected + " was detcted." ) - {} -}; - -} // namespace Exceptions -} // namespace TNL diff --git a/src/TNL/File.hpp b/src/TNL/File.hpp index a764d7242..f010129ce 100644 --- a/src/TNL/File.hpp +++ b/src/TNL/File.hpp @@ -358,7 +358,7 @@ inline File& operator<<( File& file, const std::string& str ) } catch(...) { - throw Exceptions::FileSerializationError( getType< int >(), file.getFileName() ); + throw Exceptions::FileSerializationError( file.getFileName(), "unable to write string length." ); } try { @@ -366,7 +366,7 @@ inline File& operator<<( File& file, const std::string& str ) } catch(...) { - throw Exceptions::FileSerializationError( "String", file.getFileName() ); + throw Exceptions::FileSerializationError( file.getFileName(), "unable to write a C-string." ); } return file; } @@ -381,7 +381,7 @@ inline File& operator>>( File& file, std::string& str ) } catch(...) { - throw Exceptions::FileDeserializationError( getType< int >(), file.getFileName() ); + throw Exceptions::FileDeserializationError( file.getFileName(), "unable to read string length." ); } char buffer[ length ]; if( length ) @@ -392,7 +392,7 @@ inline File& operator>>( File& file, std::string& str ) } catch(...) { - throw Exceptions::FileDeserializationError( "String", file.getFileName() ); + throw Exceptions::FileDeserializationError( file.getFileName(), "unable to read a C-string." ); } } str.assign( buffer, length ); diff --git a/src/TNL/Functions/MeshFunction.h b/src/TNL/Functions/MeshFunction.h index a59a8aecf..9e6f6f571 100644 --- a/src/TNL/Functions/MeshFunction.h +++ b/src/TNL/Functions/MeshFunction.h @@ -10,7 +10,7 @@ #pragma once -#include +#include #include #include #include diff --git a/src/TNL/Functions/MeshFunction_impl.h b/src/TNL/Functions/MeshFunction_impl.h index 2c6f7a178..40844062b 100644 --- a/src/TNL/Functions/MeshFunction_impl.h +++ b/src/TNL/Functions/MeshFunction_impl.h @@ -15,7 +15,6 @@ #include #include #include -#include #pragma once @@ -169,9 +168,7 @@ setup( const MeshPointer& meshPointer, } else { - std::cerr << "Missing parameter " << prefix << "file." << std::endl; - throw(0); - return false; + throw std::runtime_error( "Missing parameter " + prefix + "file." ); } return true; } @@ -489,7 +486,7 @@ load( File& file ) this->data.load( file ); const IndexType meshSize = this->getMesh().template getEntitiesCount< typename MeshType::template EntityType< MeshEntityDimension > >(); if( this->data.getSize() != meshSize ) - throw Exceptions::MeshFunctionDataMismatch( this->data.getSize(), " Does not fit with mesh size " + convertToString( meshSize ) + "." ); + throw Exceptions::FileDeserializationError( file.getFileName(), "mesh function data size does not match the mesh size (expected " + std::to_string(meshSize) + ", got " + std::to_string(this->data.getSize()) + ")." ); } template< typename Mesh, diff --git a/src/TNL/Meshes/Readers/TNLReader.h b/src/TNL/Meshes/Readers/TNLReader.h index 6100a5119..88869ffc1 100644 --- a/src/TNL/Meshes/Readers/TNLReader.h +++ b/src/TNL/Meshes/Readers/TNLReader.h @@ -12,7 +12,6 @@ #include #include -#include #include namespace TNL { @@ -28,16 +27,7 @@ public: this->reset(); this->fileName = fileName; - String objectType; - try - { - objectType = getObjectType( fileName ); - } - catch( ... ) - { - throw Exceptions::ObjectTypeDetectionFailure( fileName, "mesh" ); - } - + const String objectType = getObjectType( fileName ); const std::vector< String > parsedMeshType = parseObjectType( objectType ); if( ! parsedMeshType.size() ) { std::cerr << "Unable to parse the mesh type " << meshType << "." << std::endl; diff --git a/src/TNL/Object.h b/src/TNL/Object.h index 92ed9fef7..4dd6d658e 100644 --- a/src/TNL/Object.h +++ b/src/TNL/Object.h @@ -24,19 +24,19 @@ namespace TNL { /** * \brief Basic class for majority of TNL objects like matrices, meshes, grids, solvers, etc.. * - * Objects like numerical meshes, matrices large vectors etc. are inherited by - * this class. This class introduces virtual method \ref getType which is + * Objects like numerical meshes, matrices large vectors etc. are inherited by + * this class. This class introduces virtual method \ref getType which is * supposed to tell the object type in a C++ style. - * - * Since the virtual destructor is not defined as \ref __cuda_callable__, + * + * Since the virtual destructor is not defined as \ref __cuda_callable__, * objects inherited from Object should not be created in CUDA kernels. - * + * * In addition to methods of this class, see the following related functions: - * + * * \ref getObjectType - * + * * \ref parseObjectType - * + * */ class Object { @@ -47,7 +47,7 @@ class Object * * Returns the type in C++ style - for example the returned value * may look as \c "Array< double, Devices::Cuda, int >". - * + * * \par Example * \include ObjectExample_getType.cpp * \par Output @@ -57,7 +57,7 @@ class Object /*** * \brief Virtual type getter. - * + * * Returns the type in C++ style - for example the returned value * may look as \c "Array< double, Devices::Cuda, int >". * See example at \ref Object::getType. @@ -68,7 +68,7 @@ class Object * \brief Static serialization type getter. * * Objects in TNL are saved as in a device independent manner. This method - * is supposed to return the object type but with the device type replaced + * is supposed to return the object type but with the device type replaced * by Devices::Host. For example \c Array< double, Devices::Cuda > is * saved as \c Array< double, Devices::Host >. * See example at \ref Object::getType. @@ -77,9 +77,9 @@ class Object /*** * \brief Virtual serialization type getter. - * + * * Objects in TNL are saved as in a device independent manner. This method - * is supposed to return the object type but with the device type replaced + * is supposed to return the object type but with the device type replaced * by Devices::Host. For example \c Array< double, Devices::Cuda > is * saved as \c Array< double, Devices::Host >. * See example at \ref Object::getType. @@ -89,6 +89,8 @@ class Object /** * \brief Method for saving the object to a file as a binary data. * + * Throws \ref Exceptions::FileSerializationError if the object cannot be saved. + * * \param file Name of file object. */ virtual void save( File& file ) const; @@ -96,6 +98,8 @@ class Object /** * \brief Method for restoring the object from a file. * + * Throws \ref Exceptions::FileDeserializationError if the object cannot be loaded. + * * \param file Name of file object. */ virtual void load( File& file ); @@ -103,6 +107,8 @@ class Object /** * \brief Method for restoring the object from a file. * + * Throws \ref Exceptions::FileDeserializationError if the object cannot be loaded. + * * \param file Name of file object. */ virtual void boundLoad( File& file ); @@ -110,6 +116,8 @@ class Object /** * \brief Method for saving the object to a file as a binary data. * + * Throws \ref Exceptions::FileSerializationError if the object cannot be saved. + * * \param fileName String defining the name of a file. */ void save( const String& fileName ) const; @@ -117,6 +125,8 @@ class Object /** * \brief Method for restoring the object from a file. * + * Throws \ref Exceptions::FileDeserializationError if the object cannot be loaded. + * * \param fileName String defining the name of a file. */ void load( const String& fileName ); @@ -124,13 +134,15 @@ class Object /** * \brief Method for restoring the object from a file. * + * Throws \ref Exceptions::FileDeserializationError if the object cannot be loaded. + * * \param fileName String defining the name of a file. */ void boundLoad( const String& fileName ); - + /** * \brief Destructor. - * + * * Since it is not defined as \ref __cuda_callable__, objects inherited * from Object should not be created in CUDA kernels. */ @@ -141,7 +153,9 @@ class Object /** * \brief Extracts object type from a binary file. - * + * + * Throws \ref Exceptions::FileDeserializationError if the object type cannot be detected. + * * @param file is file where the object is stored * @return string with the object type */ @@ -149,7 +163,9 @@ String getObjectType( File& file ); /** * \brief Does the same as \ref getObjectType but with a \e fileName parameter instead of file. - * + * + * Throws \ref Exceptions::FileDeserializationError if the object type cannot be detected. + * * @param fileName name of a file where the object is stored * @return string with the object type */ @@ -157,7 +173,7 @@ String getObjectType( const String& fileName ); /** * \brief Parses the object type - * + * * @param objectType is a string with the object type to be parsed. * @return vector of strings where the first one is the object type and the next * strings are the template parameters. diff --git a/src/TNL/Object.hpp b/src/TNL/Object.hpp index 6af83feee..f2bad7cf3 100644 --- a/src/TNL/Object.hpp +++ b/src/TNL/Object.hpp @@ -15,8 +15,6 @@ #include #include -#include -#include namespace TNL { @@ -52,7 +50,7 @@ inline void Object::load( File& file ) { String objectType = getObjectType( file ); if( objectType != this->getSerializationTypeVirtual() ) - throw Exceptions::ObjectTypeMismatch( this->getSerializationTypeVirtual(), objectType ); + throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + this->getSerializationTypeVirtual() + ", found " + objectType + ")." ); } inline void Object::boundLoad( File& file ) @@ -87,7 +85,7 @@ inline String getObjectType( File& file ) String type; file.load( mn, strlen( magic_number ) ); if( strncmp( mn, magic_number, 5 ) != 0 ) - throw Exceptions::NotTNLFile(); + throw Exceptions::FileDeserializationError( file.getFileName(), "wrong magic number - file is not in a TNL-compatible format." ); file >> type; return type; } @@ -162,7 +160,7 @@ inline void loadHeader( File& file, String& type ) char mn[ 10 ]; file.load( mn, strlen( magic_number ) ); if( strncmp( mn, magic_number, 5 ) != 0 ) - throw Exceptions::NotTNLFile(); + throw Exceptions::FileDeserializationError( file.getFileName(), "wrong magic number - file is not in a TNL-compatible format." ); file >> type; } diff --git a/src/Tools/tnl-diff.cpp b/src/Tools/tnl-diff.cpp index 1d681a6df..9fbb851ff 100644 --- a/src/Tools/tnl-diff.cpp +++ b/src/Tools/tnl-diff.cpp @@ -9,7 +9,6 @@ /* See Copyright Notice in tnl/Copyright */ #include "tnl-diff.h" -#include #include #include @@ -50,15 +49,7 @@ int main( int argc, char* argv[] ) return EXIT_FAILURE; return EXIT_SUCCESS; }*/ - String meshType; - try - { - meshType = getObjectType( meshFile ); - } - catch(...) - { - throw Exceptions::ObjectTypeDetectionFailure( meshFile, "mesh" ); - } + const String meshType = getObjectType( meshFile ); std::cout << meshType << " detected in " << meshFile << " file." << std::endl; const std::vector< String > parsedMeshType = parseObjectType( meshType ); if( ! parsedMeshType.size() ) diff --git a/src/Tools/tnl-lattice-init.h b/src/Tools/tnl-lattice-init.h index 557bf5359..a50edcd59 100644 --- a/src/Tools/tnl-lattice-init.h +++ b/src/Tools/tnl-lattice-init.h @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -233,15 +232,7 @@ template< typename ProfileMesh, typename Real, typename Mesh > bool resolveProfileReal( const Config::ParameterContainer& parameters ) { String profileFile = parameters. getParameter< String >( "profile-file" ); - String meshFunctionType; - try - { - meshFunctionType = getObjectType( profileFile ); - } - catch(...) - { - throw Exceptions::ObjectTypeDetectionFailure( profileFile, "mesh" ); - } + const String meshFunctionType = getObjectType( profileFile ); //std::cout << meshFunctionType << " detected in " << profileFile << " file." << std::endl; const std::vector< String > parsedMeshFunctionType = parseObjectType( meshFunctionType ); if( ! parsedMeshFunctionType.size() ) @@ -292,15 +283,7 @@ template< typename ProfileMesh, typename Real > bool resolveMesh( const Config::ParameterContainer& parameters ) { String meshFile = parameters.getParameter< String >( "mesh" ); - String meshType; - try - { - meshType = getObjectType( meshFile ); - } - catch(...) - { - throw Exceptions::ObjectTypeDetectionFailure( meshFile, "mesh" ); - } + const String meshType = getObjectType( meshFile ); std::cout << meshType << " detected in " << meshFile << " file." << std::endl; const std::vector< String > parsedMeshType = parseObjectType( meshType ); if( ! parsedMeshType.size() ) @@ -390,15 +373,7 @@ bool resolveProfileMeshRealType( const std::vector< String >& parsedMeshType, bool resolveProfileMeshType( const Config::ParameterContainer& parameters ) { String meshFile = parameters. getParameter< String >( "profile-mesh" ); - String meshType; - try - { - meshType = getObjectType( meshFile ); - } - catch(...) - { - throw Exceptions::ObjectTypeDetectionFailure( meshFile, "mesh" ); - } + const String meshType = getObjectType( meshFile ); std::cout << meshType << " detected in " << meshFile << " file." << std::endl; const std::vector< String > parsedMeshType = parseObjectType( meshType ); if( ! parsedMeshType.size() ) @@ -406,7 +381,7 @@ bool resolveProfileMeshType( const Config::ParameterContainer& parameters ) std::cerr << "Unable to parse the mesh type " << meshType << "." << std::endl; return EXIT_FAILURE; } - + int dimensions = atoi( parsedMeshType[ 1 ].getString() ); if( dimensions != 2 ) { -- GitLab From 67d4cba342d524feeb8e863ee8360eaf194d0e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 12 Apr 2019 22:19:58 +0200 Subject: [PATCH 27/30] Refactoring ArrayIO --- src/TNL/Containers/Algorithms/ArrayIO.h | 75 ++++++++++++++++--------- src/TNL/Containers/Array.hpp | 9 +-- src/TNL/Containers/ArrayView.hpp | 3 +- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/TNL/Containers/Algorithms/ArrayIO.h b/src/TNL/Containers/Algorithms/ArrayIO.h index 77e82355f..a97fc755f 100644 --- a/src/TNL/Containers/Algorithms/ArrayIO.h +++ b/src/TNL/Containers/Algorithms/ArrayIO.h @@ -23,66 +23,85 @@ template< typename Value, typename Device, typename Index, bool Elementwise = std::is_base_of< Object, Value >::value > -class ArrayIO +struct ArrayIO {}; template< typename Value, typename Device, typename Index > -class ArrayIO< Value, Device, Index, true > +struct ArrayIO< Value, Device, Index, true > { public: - static bool save( File& file, + static void save( File& file, const Value* data, const Index elements ) { - for( Index i = 0; i < elements; i++ ) - if( ! data[ i ].save( file ) ) - { - std::cerr << "I was not able to save " << i << "-th of " << elements << " elements." << std::endl; - return false; - } - return true; + Index i; + try + { + for( i = 0; i < elements; i++ ) + data[ i ].save( file ); + } + catch(...) + { + throw Exceptions::FileSerializationError( file.getFileName(), "unable to write the " + std::to_string(i) + "-th array element of " + std::to_string(elements) + " into the file." ); + } } - static bool load( File& file, + static void load( File& file, Value* data, const Index elements ) { - for( Index i = 0; i < elements; i++ ) - if( ! data[ i ].load( file ) ) - { - std::cerr << "I was not able to load " << i << "-th of " << elements << " elements." << std::endl; - return false; - } - return true; + Index i = 0; + try + { + for( i = 0; i < elements; i++ ) + data[ i ].load( file ); + } + catch(...) + { + throw Exceptions::FileDeserializationError( file.getFileName(), "unable to read the " + std::to_string(i) + "-th array element of " + std::to_string(elements) + " from the file." ); + } } }; template< typename Value, typename Device, typename Index > -class ArrayIO< Value, Device, Index, false > +struct ArrayIO< Value, Device, Index, false > { - public: - - static bool save( File& file, + static void save( File& file, const Value* data, const Index elements ) { - file.save< Value, Value, Device >( data, elements ); - return true; + if( elements == 0 ) + return; + try + { + file.save< Value, Value, Device >( data, elements ); + } + catch(...) + { + throw Exceptions::FileSerializationError( file.getFileName(), "unable to write " + std::to_string(elements) + " array elements into the file." ); + } } - static bool load( File& file, + static void load( File& file, Value* data, const Index elements ) { - file.load< Value, Value, Device >( data, elements ); - return true; + if( elements == 0 ) + return; + try + { + file.load< Value, Value, Device >( data, elements ); + } + catch(...) + { + throw Exceptions::FileDeserializationError( file.getFileName(), "unable to read " + std::to_string(elements) + " array elements from the file." ); + } } - }; } // namespace Algorithms diff --git a/src/TNL/Containers/Array.hpp b/src/TNL/Containers/Array.hpp index 34fb38e62..d0cbf3965 100644 --- a/src/TNL/Containers/Array.hpp +++ b/src/TNL/Containers/Array.hpp @@ -658,8 +658,7 @@ void Array< Value, Device, Index >::save( File& file ) const { Object::save( file ); file.save( &this->size ); - if( this->size != 0 ) - Algorithms::ArrayIO< Value, Device, Index >::save( file, this->data, this->size ); + Algorithms::ArrayIO< Value, Device, Index >::save( file, this->data, this->size ); } template< typename Value, @@ -675,8 +674,7 @@ load( File& file ) if( _size < 0 ) throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) ); setSize( _size ); - if( _size ) - Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); + Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); } template< typename Value, @@ -697,8 +695,7 @@ boundLoad( File& file ) throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) + " (expected " + std::to_string( this->getSize() ) + ")." ); } else setSize( _size ); - if( _size ) - Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); + Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); } template< typename Value, diff --git a/src/TNL/Containers/ArrayView.hpp b/src/TNL/Containers/ArrayView.hpp index cca4ceef5..030f29e64 100644 --- a/src/TNL/Containers/ArrayView.hpp +++ b/src/TNL/Containers/ArrayView.hpp @@ -349,8 +349,7 @@ void ArrayView< Value, Device, Index >::save( File& file ) const { saveHeader( file, SerializationType::getType() ); file.save( &this->size ); - if( this->size != 0 ) - Algorithms::ArrayIO< Value, Device, Index >::save( file, this->data, this->size ); + Algorithms::ArrayIO< Value, Device, Index >::save( file, this->data, this->size ); } template< typename Value, -- GitLab From 3b27d05ae13eeca0b7beeb17040d7ff60c3e1bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 12 Apr 2019 23:39:58 +0200 Subject: [PATCH 28/30] Removed boundLoad from Array and Object - needed only in MeshFunction and VectorField --- src/Python/pytnl/tnl/Object.cpp | 1 - src/TNL/Containers/Array.h | 14 -------------- src/TNL/Containers/Array.hpp | 21 --------------------- src/TNL/Containers/DistributedArray.h | 3 +-- src/TNL/Functions/MeshFunction.h | 4 ++-- src/TNL/Functions/MeshFunction_impl.h | 14 +++++++++++++- src/TNL/Functions/VectorField.h | 13 +++++++++---- src/TNL/Matrices/DistributedMatrix.h | 1 - src/TNL/Object.h | 18 ------------------ src/TNL/Object.hpp | 12 ------------ src/UnitTests/Containers/ArrayTest.h | 8 ++------ 11 files changed, 27 insertions(+), 82 deletions(-) diff --git a/src/Python/pytnl/tnl/Object.cpp b/src/Python/pytnl/tnl/Object.cpp index 56b0f54e5..8c7569f2b 100644 --- a/src/Python/pytnl/tnl/Object.cpp +++ b/src/Python/pytnl/tnl/Object.cpp @@ -12,7 +12,6 @@ void export_Object( py::module & m ) // TODO: make it abstract class in Python .def("save", (void (TNL::Object::*)(const TNL::String &) const) &TNL::Object::save) .def("load", (void (TNL::Object::*)(const TNL::String &)) &TNL::Object::load) - .def("boundLoad", (void (TNL::Object::*)(const TNL::String &)) &TNL::Object::boundLoad) // FIXME: why does it not work? // .def("save", py::overload_cast(&TNL::Object::save, py::const_)) // .def("load", py::overload_cast(&TNL::Object::load)) diff --git a/src/TNL/Containers/Array.h b/src/TNL/Containers/Array.h index caeb88dd0..0c0e6c0cc 100644 --- a/src/TNL/Containers/Array.h +++ b/src/TNL/Containers/Array.h @@ -537,24 +537,10 @@ class Array : public Object */ void load( File& file ); - /** - * \brief This method loads data without reallocation. - * - * This is useful for loading data into shared arrays. - * If the array was not initialize yet, common load is - * performed. Otherwise, the array size must fit with - * the size of array being loaded. - * - * This method is deprecated - use ArrayView instead. - */ - void boundLoad( File& file ); - using Object::save; using Object::load; - using Object::boundLoad; - /** \brief Basic destructor. */ ~Array(); diff --git a/src/TNL/Containers/Array.hpp b/src/TNL/Containers/Array.hpp index d0cbf3965..cde3b782e 100644 --- a/src/TNL/Containers/Array.hpp +++ b/src/TNL/Containers/Array.hpp @@ -677,27 +677,6 @@ load( File& file ) Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); } -template< typename Value, - typename Device, - typename Index > -void -Array< Value, Device, Index >:: -boundLoad( File& file ) -{ - Object::load( file ); - Index _size; - file.load( &_size ); - if( _size < 0 ) - throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) ); - if( this->getSize() != 0 ) - { - if( this->getSize() != _size ) - throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) + " (expected " + std::to_string( this->getSize() ) + ")." ); - } - else setSize( _size ); - Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); -} - template< typename Value, typename Device, typename Index > diff --git a/src/TNL/Containers/DistributedArray.h b/src/TNL/Containers/DistributedArray.h index edae7ccd0..db160a1ef 100644 --- a/src/TNL/Containers/DistributedArray.h +++ b/src/TNL/Containers/DistributedArray.h @@ -138,7 +138,7 @@ public: // Returns true iff non-zero size is set operator bool() const; - // TODO: serialization (save, load, boundLoad) + // TODO: serialization (save, load) protected: LocalRangeType localRange; @@ -150,7 +150,6 @@ private: // TODO: disabled until they are implemented using Object::save; using Object::load; - using Object::boundLoad; }; } // namespace Containers diff --git a/src/TNL/Functions/MeshFunction.h b/src/TNL/Functions/MeshFunction.h index 9e6f6f571..c9eb66ac5 100644 --- a/src/TNL/Functions/MeshFunction.h +++ b/src/TNL/Functions/MeshFunction.h @@ -152,6 +152,8 @@ class MeshFunction : void boundLoad( File& file ); + void boundLoad( const String& fileName ); + bool write( const String& fileName, const String& format = "vtk", const double& scale = 1.0 ) const; @@ -160,8 +162,6 @@ class MeshFunction : using Object::load; - using Object::boundLoad; - DistributedMeshSynchronizerType& getSynchronizer() { return this->synchronizer; diff --git a/src/TNL/Functions/MeshFunction_impl.h b/src/TNL/Functions/MeshFunction_impl.h index 40844062b..d0efb9f38 100644 --- a/src/TNL/Functions/MeshFunction_impl.h +++ b/src/TNL/Functions/MeshFunction_impl.h @@ -497,7 +497,19 @@ MeshFunction< Mesh, MeshEntityDimension, Real >:: boundLoad( File& file ) { Object::load( file ); - this->data.boundLoad( file ); + this->data.getView().load( file ); +} + +template< typename Mesh, + int MeshEntityDimension, + typename Real > +void +MeshFunction< Mesh, MeshEntityDimension, Real >:: +boundLoad( const String& fileName ) +{ + File file; + file.open( fileName, std::ios_base::in ); + this->boundLoad( file ); } template< typename Mesh, diff --git a/src/TNL/Functions/VectorField.h b/src/TNL/Functions/VectorField.h index 87d86d62b..4db601c9f 100644 --- a/src/TNL/Functions/VectorField.h +++ b/src/TNL/Functions/VectorField.h @@ -282,14 +282,21 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > for( int i = 0; i < Size; i++ ) vectorField[ i ]->load( file ); } - + void boundLoad( File& file ) { Object::load( file ); for( int i = 0; i < Size; i++ ) vectorField[ i ]->boundLoad( file ); } - + + void boundLoad( const String& fileName ) + { + File file; + file.open( fileName, std::ios_base::in ); + this->boundLoad( file ); + } + bool write( const String& fileName, const String& format = "vtk", const double& scale = 1.0 ) const @@ -316,8 +323,6 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > using Object::load; - using Object::boundLoad; - protected: Containers::StaticArray< Size, FunctionPointer > vectorField; diff --git a/src/TNL/Matrices/DistributedMatrix.h b/src/TNL/Matrices/DistributedMatrix.h index dd76804cf..c200663dc 100644 --- a/src/TNL/Matrices/DistributedMatrix.h +++ b/src/TNL/Matrices/DistributedMatrix.h @@ -177,7 +177,6 @@ private: // TODO: disabled until they are implemented using Object::save; using Object::load; - using Object::boundLoad; }; } // namespace Matrices diff --git a/src/TNL/Object.h b/src/TNL/Object.h index 4dd6d658e..8e7e567a9 100644 --- a/src/TNL/Object.h +++ b/src/TNL/Object.h @@ -104,15 +104,6 @@ class Object */ virtual void load( File& file ); - /** - * \brief Method for restoring the object from a file. - * - * Throws \ref Exceptions::FileDeserializationError if the object cannot be loaded. - * - * \param file Name of file object. - */ - virtual void boundLoad( File& file ); - /** * \brief Method for saving the object to a file as a binary data. * @@ -131,15 +122,6 @@ class Object */ void load( const String& fileName ); - /** - * \brief Method for restoring the object from a file. - * - * Throws \ref Exceptions::FileDeserializationError if the object cannot be loaded. - * - * \param fileName String defining the name of a file. - */ - void boundLoad( const String& fileName ); - /** * \brief Destructor. * diff --git a/src/TNL/Object.hpp b/src/TNL/Object.hpp index f2bad7cf3..697e738fd 100644 --- a/src/TNL/Object.hpp +++ b/src/TNL/Object.hpp @@ -53,11 +53,6 @@ inline void Object::load( File& file ) throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + this->getSerializationTypeVirtual() + ", found " + objectType + ")." ); } -inline void Object::boundLoad( File& file ) -{ - this->load( file ); -} - inline void Object::save( const String& fileName ) const { File file; @@ -72,13 +67,6 @@ inline void Object::load( const String& fileName ) this->load( file ); } -inline void Object::boundLoad( const String& fileName ) -{ - File file; - file.open( fileName, std::ios_base::in ); - this->boundLoad( file ); -} - inline String getObjectType( File& file ) { char mn[ 10 ]; diff --git a/src/UnitTests/Containers/ArrayTest.h b/src/UnitTests/Containers/ArrayTest.h index 2d4283221..527f6e9e1 100644 --- a/src/UnitTests/Containers/ArrayTest.h +++ b/src/UnitTests/Containers/ArrayTest.h @@ -489,7 +489,7 @@ TYPED_TEST( ArrayTest, SaveAndLoad ) EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); } -TYPED_TEST( ArrayTest, boundLoad ) +TYPED_TEST( ArrayTest, LoadViaView ) { using ArrayType = typename TestFixture::ArrayType; @@ -511,11 +511,7 @@ TYPED_TEST( ArrayTest, boundLoad ) ArrayType z( 50 ); ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); - EXPECT_ANY_THROW( z.boundLoad( file ) ); - - v.reset(); - ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); - EXPECT_NO_THROW( v.boundLoad( file ) ); + EXPECT_ANY_THROW( z.getView().load( file ) ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); } -- GitLab From f354eea77e23582c2304e2329bed9eb572cebd38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 13 Apr 2019 12:28:13 +0200 Subject: [PATCH 29/30] Replaced save and load methods on Array and ArrayView with operator<< and operator>> --- .../DistSpMV/tnl-benchmark-distributed-spmv.h | 2 +- .../tnl-benchmark-linear-solvers.h | 4 +- src/Examples/Containers/ArrayExample.cpp | 12 ++- src/Examples/Containers/ArrayViewExample.cpp | 7 +- src/Python/pytnl/tnl/Array.h | 3 +- src/TNL/Containers/Array.h | 42 ++++---- src/TNL/Containers/Array.hpp | 77 +++++++++------ src/TNL/Containers/ArrayView.h | 56 +++++------ src/TNL/Containers/ArrayView.hpp | 98 +++++++++---------- .../Multimaps/EllpackIndexMultimap_impl.h | 6 +- .../StaticEllpackIndexMultimap_impl.h | 4 +- src/TNL/File.h | 17 ++++ src/TNL/File.hpp | 5 + src/TNL/Functions/MeshFunction_impl.h | 11 +-- src/TNL/Matrices/AdEllpack_impl.h | 10 +- src/TNL/Matrices/BiEllpackSymmetric_impl.h | 6 +- src/TNL/Matrices/BiEllpack_impl.h | 6 +- src/TNL/Matrices/COOMatrix.h | 8 +- src/TNL/Matrices/COOMatrix_impl.h | 24 ++--- src/TNL/Matrices/CSR_impl.h | 4 +- src/TNL/Matrices/ChunkedEllpack_impl.h | 10 +- src/TNL/Matrices/Matrix_impl.h | 4 +- src/TNL/Matrices/Multidiagonal_impl.h | 6 +- .../SlicedEllpackSymmetricGraph_impl.h | 6 +- .../Matrices/SlicedEllpackSymmetric_impl.h | 6 +- src/TNL/Matrices/SlicedEllpack_impl.h | 6 +- src/TNL/Matrices/Sparse_impl.h | 6 +- src/TNL/Matrices/Tridiagonal.h | 8 +- src/TNL/Matrices/Tridiagonal_impl.h | 30 ++---- .../MeshLayers/BoundaryTags/Layer.h | 4 +- .../MeshDetails/MeshLayers/StorageLayer.h | 4 +- src/TNL/Object.h | 12 ++- src/TNL/Object.hpp | 13 +-- src/TNL/Problems/PDEProblem_impl.h | 4 +- src/TNL/Solvers/ODE/Merson_impl.h | 12 +-- src/Tools/tnl-dicom-reader.cpp | 2 +- src/Tools/tnl-diff.h | 14 +-- src/Tools/tnl-image-converter.cpp | 2 +- src/Tools/tnl-view.h | 2 +- src/UnitTests/Containers/ArrayTest.h | 19 ++-- src/UnitTests/ObjectTest.cpp | 9 +- 41 files changed, 281 insertions(+), 300 deletions(-) diff --git a/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h b/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h index b297854ea..e1689d0db 100644 --- a/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h +++ b/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h @@ -164,7 +164,7 @@ struct SpmvBenchmark MatrixType matrix; VectorType vector; matrix.load( parameters.getParameter< String >( "input-matrix" ) ); - vector.load( parameters.getParameter< String >( "input-vector" ) ); + File( parameters.getParameter< String >( "input-vector" ), std::ios_base::in ) >> vector; typename MatrixType::CompressedRowLengthsVector rowLengths; matrix.getCompressedRowLengths( rowLengths ); diff --git a/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h b/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h index 2926e6bb1..1dd341d43 100644 --- a/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h +++ b/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h @@ -333,8 +333,8 @@ struct LinearSolversBenchmark SharedPointer< MatrixType > matrixPointer; VectorType x0, b; matrixPointer->load( parameters.getParameter< String >( "input-matrix" ) ); - x0.load( parameters.getParameter< String >( "input-dof" ) ); - b.load( parameters.getParameter< String >( "input-rhs" ) ); + File( parameters.getParameter< String >( "input-dof" ), std::ios_base::in ) >> x0; + File( parameters.getParameter< String >( "input-rhs" ), std::ios_base::in ) >> b; typename MatrixType::CompressedRowLengthsVector rowLengths; matrixPointer->getCompressedRowLengths( rowLengths ); diff --git a/src/Examples/Containers/ArrayExample.cpp b/src/Examples/Containers/ArrayExample.cpp index 9dcfd7cbd..4d6ca48e5 100644 --- a/src/Examples/Containers/ArrayExample.cpp +++ b/src/Examples/Containers/ArrayExample.cpp @@ -20,14 +20,14 @@ void arrayExample() /*** * You may initiate the array using setElement */ - for( int i = 0; i< size; i++ ) + for( int i = 0; i < size; i++ ) a1.setElement( i, i ); std::cout << "a1 = " << a1 << std::endl; /*** * You may also assign value to all array elements ... */ - a2 = 0.0; + a2 = 0; std::cout << "a2 = " << a2 << std::endl; /*** @@ -56,10 +56,12 @@ void arrayExample() a1.swap( a2 ); /*** - * Of course, you may save it to file and load again + * You may save it to file and load again */ - a1.save( "a1.tnl" ); - a2.load( "a1.tnl" ); + File( "a1.tnl", std::ios_base::out ) << a1; + File( "a1.tnl", std::ios_base::in ) >> a2; + + std::remove( "a1.tnl" ); if( a2 != a1 ) std::cerr << "Something is wrong!!!" << std::endl; diff --git a/src/Examples/Containers/ArrayViewExample.cpp b/src/Examples/Containers/ArrayViewExample.cpp index 9eb6aa712..3790073eb 100644 --- a/src/Examples/Containers/ArrayViewExample.cpp +++ b/src/Examples/Containers/ArrayViewExample.cpp @@ -57,10 +57,11 @@ void arrayViewExample() a1.swap( a3 ); /*** - * Of course, you may save it to file and load again + * You may save it to file and load again */ - a1.save( "a1.tnl" ); - a2.load( "a1.tnl" ); + File( "a1.tnl", std::ios_base::out ) << a1; + File( "a1.tnl", std::ios_base::in ) >> a2; + std::remove( "a1.tnl" ); if( a2 != a1 ) diff --git a/src/Python/pytnl/tnl/Array.h b/src/Python/pytnl/tnl/Array.h index c90ac44ad..acebce3d2 100644 --- a/src/Python/pytnl/tnl/Array.h +++ b/src/Python/pytnl/tnl/Array.h @@ -11,7 +11,8 @@ namespace py = pybind11; template< typename ArrayType > void export_Array(py::module & m, const char* name) { - auto array = py::class_(m, name, py::buffer_protocol()) +// auto array = py::class_(m, name, py::buffer_protocol()) + auto array = py::class_(m, name, py::buffer_protocol()) .def(py::init<>()) .def(py::init()) .def_static("getType", &ArrayType::getType) diff --git a/src/TNL/Containers/Array.h b/src/TNL/Containers/Array.h index 0c0e6c0cc..434299443 100644 --- a/src/TNL/Containers/Array.h +++ b/src/TNL/Containers/Array.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include namespace TNL { @@ -60,7 +60,7 @@ template< int, typename > class StaticArray; template< typename Value, typename Device = Devices::Host, typename Index = int > -class Array : public Object +class Array { public: @@ -523,24 +523,6 @@ class Array : public Object __cuda_callable__ bool empty() const; - /** - * \brief Method for saving the object to a \e file as a binary data. - * - * \param file Reference to a file. - */ - void save( File& file ) const; - - /** - * Method for loading the object from a file as a binary data. - * - * \param file Reference to a file. - */ - void load( File& file ); - - using Object::save; - - using Object::load; - /** \brief Basic destructor. */ ~Array(); @@ -576,7 +558,25 @@ class Array : public Object }; template< typename Value, typename Device, typename Index > -std::ostream& operator<<( std::ostream& str, const Array< Value, Device, Index >& v ); +std::ostream& operator<<( std::ostream& str, const Array< Value, Device, Index >& array ); + +/** + * \brief Serialization of arrays into binary files. + */ +template< typename Value, typename Device, typename Index > +File& operator<<( File& file, const Array< Value, Device, Index >& array ); + +template< typename Value, typename Device, typename Index > +File& operator<<( File&& file, const Array< Value, Device, Index >& array ); + +/** + * \brief Deserialization of arrays from binary files. + */ +template< typename Value, typename Device, typename Index > +File& operator>>( File& file, Array< Value, Device, Index >& array ); + +template< typename Value, typename Device, typename Index > +File& operator>>( File&& file, Array< Value, Device, Index >& array ); } // namespace Containers } // namespace TNL diff --git a/src/TNL/Containers/Array.hpp b/src/TNL/Containers/Array.hpp index cde3b782e..8224a213f 100644 --- a/src/TNL/Containers/Array.hpp +++ b/src/TNL/Containers/Array.hpp @@ -651,32 +651,6 @@ empty() const return ( data == nullptr ); } -template< typename Value, - typename Device, - typename Index > -void Array< Value, Device, Index >::save( File& file ) const -{ - Object::save( file ); - file.save( &this->size ); - Algorithms::ArrayIO< Value, Device, Index >::save( file, this->data, this->size ); -} - -template< typename Value, - typename Device, - typename Index > -void -Array< Value, Device, Index >:: -load( File& file ) -{ - Object::load( file ); - Index _size; - file.load( &_size ); - if( _size < 0 ) - throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) ); - setSize( _size ); - Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); -} - template< typename Value, typename Device, typename Index > @@ -687,18 +661,59 @@ Array< Value, Device, Index >:: } template< typename Value, typename Device, typename Index > -std::ostream& operator<<( std::ostream& str, const Array< Value, Device, Index >& v ) +std::ostream& operator<<( std::ostream& str, const Array< Value, Device, Index >& array ) { str << "[ "; - if( v.getSize() > 0 ) + if( array.getSize() > 0 ) { - str << v.getElement( 0 ); - for( Index i = 1; i < v.getSize(); i++ ) - str << ", " << v.getElement( i ); + str << array.getElement( 0 ); + for( Index i = 1; i < array.getSize(); i++ ) + str << ", " << array.getElement( i ); } str << " ]"; return str; } +// Serialization of arrays into binary files. +template< typename Value, typename Device, typename Index > +File& operator<<( File& file, const Array< Value, Device, Index >& array ) +{ + saveObjectType( file, array.getSerializationType() ); + const Index size = array.getSize(); + file.save( &size ); + Algorithms::ArrayIO< Value, Device, Index >::save( file, array.getData(), array.getSize() ); + return file; +} + +template< typename Value, typename Device, typename Index > +File& operator<<( File&& file, const Array< Value, Device, Index >& array ) +{ + File& f = file; + return f << array; +} + +// Deserialization of arrays from binary files. +template< typename Value, typename Device, typename Index > +File& operator>>( File& file, Array< Value, Device, Index >& array ) +{ + const String type = getObjectType( file ); + if( type != array.getSerializationType() ) + throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + array.getSerializationType() + ", found " + type + ")." ); + Index _size; + file.load( &_size ); + if( _size < 0 ) + throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) ); + array.setSize( _size ); + Algorithms::ArrayIO< Value, Device, Index >::load( file, array.getData(), array.getSize() ); + return file; +} + +template< typename Value, typename Device, typename Index > +File& operator>>( File&& file, Array< Value, Device, Index >& array ) +{ + File& f = file; + return f >> array; +} + } // namespace Containers } // namespace TNL diff --git a/src/TNL/Containers/ArrayView.h b/src/TNL/Containers/ArrayView.h index 40e6792af..04084c316 100644 --- a/src/TNL/Containers/ArrayView.h +++ b/src/TNL/Containers/ArrayView.h @@ -81,6 +81,13 @@ public: */ static String getType(); + /** + * \brief Returns type of array view for serialization. + * + * \return String with serialization array type. + */ + static String getSerializationType(); + /** * \brief Basic constructor for empty ArrayView. * @@ -414,35 +421,6 @@ public: __cuda_callable__ bool empty() const; - /** - * \brief Method for saving the object to a \e file as a binary data. - * - * \param file Reference to a file. - */ - void save( File& file ) const; - - /** - * Method for loading the object from a file as a binary data. - * - * \param file Reference to a file. - */ - void load( File& file ); - - /** - * \brief Method for saving the array view to a file as a binary data. - * - * \param fileName String defining the name of a file. - */ - void save( const String& fileName ) const; - - /** - * \brief Method for restoring the array view from a file. - * - * \param fileName String defining the name of a file. - */ - void load( const String& fileName ); - - protected: //! Pointer to allocated data Value* data = nullptr; @@ -452,7 +430,25 @@ protected: }; template< typename Value, typename Device, typename Index > -std::ostream& operator<<( std::ostream& str, const ArrayView< Value, Device, Index >& v ); +std::ostream& operator<<( std::ostream& str, const ArrayView< Value, Device, Index >& view ); + +/** + * \brief Serialization of array views into binary files. + */ +template< typename Value, typename Device, typename Index > +File& operator<<( File& file, const ArrayView< Value, Device, Index > view ); + +template< typename Value, typename Device, typename Index > +File& operator<<( File&& file, const ArrayView< Value, Device, Index > view ); + +/** + * \brief Deserialization of array views from binary files. + */ +template< typename Value, typename Device, typename Index > +File& operator>>( File& file, ArrayView< Value, Device, Index > view ); + +template< typename Value, typename Device, typename Index > +File& operator>>( File&& file, ArrayView< Value, Device, Index > view ); } // namespace Containers } // namespace TNL diff --git a/src/TNL/Containers/ArrayView.hpp b/src/TNL/Containers/ArrayView.hpp index 030f29e64..83cc81db2 100644 --- a/src/TNL/Containers/ArrayView.hpp +++ b/src/TNL/Containers/ArrayView.hpp @@ -37,6 +37,16 @@ getType() TNL::getType< Index >() + " >"; } +template< typename Value, + typename Device, + typename Index > +String +ArrayView< Value, Device, Index >:: +getSerializationType() +{ + return SerializationType::getSerializationType(); +} + // explicit initialization by raw data pointer and size template< typename Value, typename Device, @@ -342,70 +352,58 @@ empty() const return ( data == nullptr ); } -template< typename Value, - typename Device, - typename Index > -void ArrayView< Value, Device, Index >::save( File& file ) const +template< typename Value, typename Device, typename Index > +std::ostream& operator<<( std::ostream& str, const ArrayView< Value, Device, Index >& view ) { - saveHeader( file, SerializationType::getType() ); - file.save( &this->size ); - Algorithms::ArrayIO< Value, Device, Index >::save( file, this->data, this->size ); + str << "[ "; + if( view.getSize() > 0 ) + { + str << view.getElement( 0 ); + for( Index i = 1; i < view.getSize(); i++ ) + str << ", " << view.getElement( i ); + } + str << " ]"; + return str; } -template< typename Value, - typename Device, - typename Index > -void -ArrayView< Value, Device, Index >:: -load( File& file ) +// Serialization of array views into binary files. +template< typename Value, typename Device, typename Index > +File& operator<<( File& file, const ArrayView< Value, Device, Index > view ) { - String type; - loadHeader( file, type ); - if( type != SerializationType::getType() ) - throw Exceptions::FileDeserializationError( file.getFileName(), "invalid object type: " + type + " (expected " + SerializationType::getType() + ")." ); - Index _size; - file.load( &_size ); - if( _size != this->getSize() ) - throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) + " (expected " + std::to_string( this->getSize() ) + ")." ); - Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); + saveObjectType( file, view.getSerializationType() ); + const Index size = view.getSize(); + file.save( &size ); + Algorithms::ArrayIO< Value, Device, Index >::save( file, view.getData(), view.getSize() ); + return file; } -template< typename Value, - typename Device, - typename Index > -void -ArrayView< Value, Device, Index >:: -save( const String& fileName ) const +template< typename Value, typename Device, typename Index > +File& operator<<( File&& file, const ArrayView< Value, Device, Index > view ) { - File file; - file.open( fileName, std::ios_base::out ); - this->save( file ); + File& f = file; + return f << view; } -template< typename Value, - typename Device, - typename Index > -void -ArrayView< Value, Device, Index >:: -load( const String& fileName ) +// Deserialization of array views from binary files. +template< typename Value, typename Device, typename Index > +File& operator>>( File& file, ArrayView< Value, Device, Index > view ) { - File file; - file.open( fileName, std::ios_base::in ); - this->load( file ); + const String type = getObjectType( file ); + if( type != view.getSerializationType() ) + throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + view.getSerializationType() + ", found " + type + ")." ); + Index _size; + file.load( &_size ); + if( _size != view.getSize() ) + throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) + " (expected " + std::to_string( view.getSize() ) + ")." ); + Algorithms::ArrayIO< Value, Device, Index >::load( file, view.getData(), view.getSize() ); + return file; } template< typename Value, typename Device, typename Index > -std::ostream& operator<<( std::ostream& str, const ArrayView< Value, Device, Index >& v ) +File& operator>>( File&& file, ArrayView< Value, Device, Index > view ) { - str << "[ "; - if( v.getSize() > 0 ) - { - str << v.getElement( 0 ); - for( Index i = 1; i < v.getSize(); i++ ) - str << ", " << v.getElement( i ); - } - str << " ]"; - return str; + File& f = file; + return f >> view; } } // namespace Containers diff --git a/src/TNL/Containers/Multimaps/EllpackIndexMultimap_impl.h b/src/TNL/Containers/Multimaps/EllpackIndexMultimap_impl.h index 2d145d377..bf0b37970 100644 --- a/src/TNL/Containers/Multimaps/EllpackIndexMultimap_impl.h +++ b/src/TNL/Containers/Multimaps/EllpackIndexMultimap_impl.h @@ -245,8 +245,7 @@ save( File& file ) const Object::save( file ); file.save( &this->keysRange ); file.save( &this->maxValuesCount ); - this->values.save( file ); - this->valuesCounts.save( file ); + file << this->values << this->valuesCounts; } template< typename Index, @@ -260,8 +259,7 @@ load( File& file ) Object::load( file ); file.load( &this->keysRange ); file.load( &this->maxValuesCount ); - this->values.load( file ); - this->valuesCounts.load( file ); + file >> this->values >> this->valuesCounts; } template< typename Index, diff --git a/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap_impl.h b/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap_impl.h index 95cb75d5d..c8dcd637e 100644 --- a/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap_impl.h +++ b/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap_impl.h @@ -203,7 +203,7 @@ save( File& file ) const { Object::save( file ); file.save( &this->keysRange ); - this->values.save( file ); + file << this->values; } template< int ValuesCount, @@ -217,7 +217,7 @@ load( File& file ) { Object::load( file ); file.load( &this->keysRange ); - this->values.load( file ); + file >> this->values; } template< int ValuesCount, diff --git a/src/TNL/File.h b/src/TNL/File.h index 6463e2cc4..1aa5615e5 100644 --- a/src/TNL/File.h +++ b/src/TNL/File.h @@ -37,6 +37,22 @@ class File */ File() = default; + File( const File& ) = delete; + + File( File&& ) = default; + + File& operator=( const File& ) = delete; + + File& operator=( File&& ) = default; + + /** + * \brief Constructor which opens given file. + * + * All parameters are passed to the \ref open method. + */ + File( const String& fileName, + std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out ); + /** * \brief Open given file. * @@ -197,6 +213,7 @@ File& operator<<( File& file, const std::string& str ); * \brief Deserialization of strings. */ File& operator>>( File& file, std::string& str ); + } // namespace TNL #include diff --git a/src/TNL/File.hpp b/src/TNL/File.hpp index f010129ce..f4edd2b96 100644 --- a/src/TNL/File.hpp +++ b/src/TNL/File.hpp @@ -25,6 +25,11 @@ namespace TNL { +inline File::File( const String& fileName, std::ios_base::openmode mode ) +{ + open( fileName, mode ); +} + inline void File::open( const String& fileName, std::ios_base::openmode mode ) { // enable exceptions diff --git a/src/TNL/Functions/MeshFunction_impl.h b/src/TNL/Functions/MeshFunction_impl.h index d0efb9f38..0ac98b7b2 100644 --- a/src/TNL/Functions/MeshFunction_impl.h +++ b/src/TNL/Functions/MeshFunction_impl.h @@ -19,7 +19,7 @@ #pragma once namespace TNL { - namespace Functions { +namespace Functions { template< typename Mesh, int MeshEntityDimension, @@ -472,7 +472,7 @@ save( File& file ) const TNL_ASSERT_EQ( this->data.getSize(), this->getMesh().template getEntitiesCount< typename MeshType::template EntityType< MeshEntityDimension > >(), "Size of the mesh function data does not match the mesh." ); Object::save( file ); - this->data.save( file ); + file << this->data; } template< typename Mesh, @@ -483,7 +483,7 @@ MeshFunction< Mesh, MeshEntityDimension, Real >:: load( File& file ) { Object::load( file ); - this->data.load( file ); + file >> this->data; const IndexType meshSize = this->getMesh().template getEntitiesCount< typename MeshType::template EntityType< MeshEntityDimension > >(); if( this->data.getSize() != meshSize ) throw Exceptions::FileDeserializationError( file.getFileName(), "mesh function data size does not match the mesh size (expected " + std::to_string(meshSize) + ", got " + std::to_string(this->data.getSize()) + ")." ); @@ -497,7 +497,7 @@ MeshFunction< Mesh, MeshEntityDimension, Real >:: boundLoad( File& file ) { Object::load( file ); - this->data.getView().load( file ); + file >> this->data.getView(); } template< typename Mesh, @@ -577,6 +577,5 @@ operator << ( std::ostream& str, const MeshFunction< Mesh, MeshEntityDimension, return str; } - } // namespace Functions +} // namespace Functions } // namespace TNL - diff --git a/src/TNL/Matrices/AdEllpack_impl.h b/src/TNL/Matrices/AdEllpack_impl.h index 0838bf09b..12d7336b8 100644 --- a/src/TNL/Matrices/AdEllpack_impl.h +++ b/src/TNL/Matrices/AdEllpack_impl.h @@ -612,10 +612,7 @@ template< typename Real, void AdEllpack< Real, Device, Index >::save( File& file ) const { Sparse< Real, Device, Index >::save( file ); - this->offset.save( file ); - this->rowOffset.save( file ); - this->localLoad.save( file ); - this->reduceMap.save( file ); + file << this->offset << this->rowOffset << this->localLoad << this->reduceMap; } template< typename Real, @@ -624,10 +621,7 @@ template< typename Real, void AdEllpack< Real, Device, Index >::load( File& file ) { Sparse< Real, Device, Index >::load( file ); - this->offset.load( file ); - this->rowOffset.load( file ); - this->localLoad.load( file ); - this->reduceMap.load( file ); + file >> this->offset >> this->rowOffset >> this->localLoad >> this->reduceMap; } template< typename Real, diff --git a/src/TNL/Matrices/BiEllpackSymmetric_impl.h b/src/TNL/Matrices/BiEllpackSymmetric_impl.h index 69d32a472..d4c755a23 100644 --- a/src/TNL/Matrices/BiEllpackSymmetric_impl.h +++ b/src/TNL/Matrices/BiEllpackSymmetric_impl.h @@ -680,8 +680,7 @@ template< typename Real, void BiEllpackSymmetric< Real, Device, Index, StripSize >::save( File& file ) const { Sparse< Real, Device, Index >::save( file ); - this->groupPointers.save( file ); - this->rowPermArray.save( file ); + file << this->groupPointers << this->rowPermArray; } template< typename Real, @@ -691,8 +690,7 @@ template< typename Real, void BiEllpackSymmetric< Real, Device, Index, StripSize >::load( File& file ) { Sparse< Real, Device, Index >::load( file ); - this->groupPointers.load( file ); - this->rowPermArray.load( file ); + file >> this->groupPointers >> this->rowPermArray; } template< typename Real, diff --git a/src/TNL/Matrices/BiEllpack_impl.h b/src/TNL/Matrices/BiEllpack_impl.h index 31dbd2bb3..8608a0d99 100644 --- a/src/TNL/Matrices/BiEllpack_impl.h +++ b/src/TNL/Matrices/BiEllpack_impl.h @@ -684,8 +684,7 @@ template< typename Real, void BiEllpack< Real, Device, Index, StripSize >::save( File& file ) const { Sparse< Real, Device, Index >::save( file ); - this->groupPointers.save( file ); - this->rowPermArray.save( file ); + file << this->groupPointers << this->rowPermArray; } template< typename Real, @@ -695,8 +694,7 @@ template< typename Real, void BiEllpack< Real, Device, Index, StripSize >::load( File& file ) { Sparse< Real, Device, Index >::load( file ); - this->groupPointers.load( file ); - this->rowPermArray.load( file ); + file >> this->groupPointers >> this->rowPermArray; } template< typename Real, diff --git a/src/TNL/Matrices/COOMatrix.h b/src/TNL/Matrices/COOMatrix.h index accf7c205..e5a4a0fd9 100644 --- a/src/TNL/Matrices/COOMatrix.h +++ b/src/TNL/Matrices/COOMatrix.h @@ -102,13 +102,13 @@ public: typename Vector::RealType rowVectorProduct(const IndexType row, const Vector& inVector) const; - bool save(File& file) const; + void save(File& file) const; - bool load(File& file); + void load(File& file); - bool save(const String& fileName) const; + void save(const String& fileName) const; - bool load(const String& fileName); + void load(const String& fileName); // TODO: nejsem si jisty jestli dela to co ma void print(std::ostream& str) const; diff --git a/src/TNL/Matrices/COOMatrix_impl.h b/src/TNL/Matrices/COOMatrix_impl.h index 054396341..090ccd118 100644 --- a/src/TNL/Matrices/COOMatrix_impl.h +++ b/src/TNL/Matrices/COOMatrix_impl.h @@ -321,39 +321,35 @@ typename Vector::RealType COOMatrix< Real, Device, Index >::rowVectorProduct(con template< typename Real, typename Device, typename Index > -bool COOMatrix< Real, Device, Index >::save(File& file) const +void COOMatrix< Real, Device, Index >::save(File& file) const { - if (!Sparse< Real, Device, Index >::save(file) || - !this->rowIndexes.save(file)) - return false; - return true; + Sparse< Real, Device, Index >::save(file); + file << this->rowIndexes; } template< typename Real, typename Device, typename Index > -bool COOMatrix< Real, Device, Index >::load(File& file) +void COOMatrix< Real, Device, Index >::load(File& file) { - if (!Sparse< Real, Device, Index >::load(file) || - !this->rowIndexes.load(file)) - return false; - return true; + Sparse< Real, Device, Index >::load(file); + file >> this->rowIndexes; } template< typename Real, typename Device, typename Index > -bool COOMatrix< Real, Device, Index >::save(const String& fileName) const +void COOMatrix< Real, Device, Index >::save(const String& fileName) const { - return Object::save(fileName); + Object::save(fileName); } template< typename Real, typename Device, typename Index > -bool COOMatrix< Real, Device, Index >::load(const String& fileName) +void COOMatrix< Real, Device, Index >::load(const String& fileName) { - return Object::load(fileName); + Object::load(fileName); } template< typename Real, diff --git a/src/TNL/Matrices/CSR_impl.h b/src/TNL/Matrices/CSR_impl.h index 7437c9302..3af550a7a 100644 --- a/src/TNL/Matrices/CSR_impl.h +++ b/src/TNL/Matrices/CSR_impl.h @@ -618,7 +618,7 @@ template< typename Real, void CSR< Real, Device, Index >::save( File& file ) const { Sparse< Real, Device, Index >::save( file ); - this->rowPointers.save( file ); + file << this->rowPointers; } template< typename Real, @@ -627,7 +627,7 @@ template< typename Real, void CSR< Real, Device, Index >::load( File& file ) { Sparse< Real, Device, Index >::load( file ); - this->rowPointers.load( file ); + file >> this->rowPointers; } template< typename Real, diff --git a/src/TNL/Matrices/ChunkedEllpack_impl.h b/src/TNL/Matrices/ChunkedEllpack_impl.h index f3df045c4..a1aae9d97 100644 --- a/src/TNL/Matrices/ChunkedEllpack_impl.h +++ b/src/TNL/Matrices/ChunkedEllpack_impl.h @@ -1287,10 +1287,7 @@ template< typename Real, void ChunkedEllpack< Real, Device, Index >::save( File& file ) const { Sparse< Real, Device, Index >::save( file ); - this->rowToChunkMapping.save( file ); - this->rowToSliceMapping.save( file ); - this->rowPointers.save( file ); - this->slices.save( file ); + file << this->rowToChunkMapping << this->rowToSliceMapping << this->rowPointers << this->slices; } template< typename Real, @@ -1299,10 +1296,7 @@ template< typename Real, void ChunkedEllpack< Real, Device, Index >::load( File& file ) { Sparse< Real, Device, Index >::load( file ); - this->rowToChunkMapping.load( file ); - this->rowToSliceMapping.load( file ); - this->rowPointers.load( file ); - this->slices.load( file ); + file >> this->rowToChunkMapping >> this->rowToSliceMapping >> this->rowPointers >> this->slices; } template< typename Real, diff --git a/src/TNL/Matrices/Matrix_impl.h b/src/TNL/Matrices/Matrix_impl.h index 815e0e7d8..7472760c2 100644 --- a/src/TNL/Matrices/Matrix_impl.h +++ b/src/TNL/Matrices/Matrix_impl.h @@ -147,7 +147,7 @@ void Matrix< Real, Device, Index >::save( File& file ) const Object::save( file ); file.save( &this->rows ); file.save( &this->columns ); - this->values.save( file ); + file << this->values; } template< typename Real, @@ -158,7 +158,7 @@ void Matrix< Real, Device, Index >::load( File& file ) Object::load( file ); file.load( &this->rows ); file.load( &this->columns ); - this->values.load( file ); + file >> this->values; } template< typename Real, diff --git a/src/TNL/Matrices/Multidiagonal_impl.h b/src/TNL/Matrices/Multidiagonal_impl.h index 38ffc13c3..065e7780d 100644 --- a/src/TNL/Matrices/Multidiagonal_impl.h +++ b/src/TNL/Matrices/Multidiagonal_impl.h @@ -653,8 +653,7 @@ template< typename Real, void Multidiagonal< Real, Device, Index >::save( File& file ) const { Matrix< Real, Device, Index >::save( file ); - this->values.save( file ); - this->diagonalsShift.save( file ); + file << this->values << this->diagonalsShift; } template< typename Real, @@ -663,8 +662,7 @@ template< typename Real, void Multidiagonal< Real, Device, Index >::load( File& file ) { Matrix< Real, Device, Index >::load( file ); - this->values.load( file ); - this->diagonalsShift.load( file ); + file >> this->values >> this->diagonalsShift; } template< typename Real, diff --git a/src/TNL/Matrices/SlicedEllpackSymmetricGraph_impl.h b/src/TNL/Matrices/SlicedEllpackSymmetricGraph_impl.h index c7611ee83..f96cc4d68 100644 --- a/src/TNL/Matrices/SlicedEllpackSymmetricGraph_impl.h +++ b/src/TNL/Matrices/SlicedEllpackSymmetricGraph_impl.h @@ -577,8 +577,7 @@ template< typename Real, void SlicedEllpackSymmetricGraph< Real, Device, Index, SliceSize >::save( File& file ) const { Sparse< Real, Device, Index >::save( file ); - this->slicePointers.save( file ); - this->sliceRowLengths.save( file ); + file << this->slicePointers << this->sliceRowLengths; } template< typename Real, @@ -588,8 +587,7 @@ template< typename Real, void SlicedEllpackSymmetricGraph< Real, Device, Index, SliceSize >::load( File& file ) { Sparse< Real, Device, Index >::load( file ); - this->slicePointers.load( file ); - this->sliceRowLengths.load( file ); + file >> this->slicePointers >> this->sliceRowLengths; } template< typename Real, diff --git a/src/TNL/Matrices/SlicedEllpackSymmetric_impl.h b/src/TNL/Matrices/SlicedEllpackSymmetric_impl.h index 579ca666d..7089a45ad 100644 --- a/src/TNL/Matrices/SlicedEllpackSymmetric_impl.h +++ b/src/TNL/Matrices/SlicedEllpackSymmetric_impl.h @@ -626,8 +626,7 @@ template< typename Real, void SlicedEllpackSymmetric< Real, Device, Index, SliceSize >::save( File& file ) const { Sparse< Real, Device, Index >::save( file ); - this->slicePointers.save( file ); - this->sliceRowLengths.save( file ); + file << this->slicePointers << this->sliceRowLengths; } template< typename Real, @@ -637,8 +636,7 @@ template< typename Real, void SlicedEllpackSymmetric< Real, Device, Index, SliceSize >::load( File& file ) { Sparse< Real, Device, Index >::load( file ); - this->slicePointers.load( file ); - this->sliceRowLengths.load( file ); + file >> this->slicePointers >> this->sliceRowLengths; } template< typename Real, diff --git a/src/TNL/Matrices/SlicedEllpack_impl.h b/src/TNL/Matrices/SlicedEllpack_impl.h index 31ac08dc8..afb0781ad 100644 --- a/src/TNL/Matrices/SlicedEllpack_impl.h +++ b/src/TNL/Matrices/SlicedEllpack_impl.h @@ -708,8 +708,7 @@ template< typename Real, void SlicedEllpack< Real, Device, Index, SliceSize >::save( File& file ) const { Sparse< Real, Device, Index >::save( file ); - this->slicePointers.save( file ); - this->sliceCompressedRowLengths.save( file ); + file << this->slicePointers << this->sliceCompressedRowLengths; } template< typename Real, @@ -719,8 +718,7 @@ template< typename Real, void SlicedEllpack< Real, Device, Index, SliceSize >::load( File& file ) { Sparse< Real, Device, Index >::load( file ); - this->slicePointers.load( file ); - this->sliceCompressedRowLengths.load( file ); + file >> this->slicePointers >> this->sliceCompressedRowLengths; } template< typename Real, diff --git a/src/TNL/Matrices/Sparse_impl.h b/src/TNL/Matrices/Sparse_impl.h index 6731ea1f4..18bc4ea71 100644 --- a/src/TNL/Matrices/Sparse_impl.h +++ b/src/TNL/Matrices/Sparse_impl.h @@ -92,8 +92,7 @@ template< typename Real, void Sparse< Real, Device, Index >::save( File& file ) const { Matrix< Real, Device, Index >::save( file ); - this->values.save( file ); - this->columnIndexes.save( file ); + file << this->values << this->columnIndexes; } template< typename Real, @@ -102,8 +101,7 @@ template< typename Real, void Sparse< Real, Device, Index >::load( File& file ) { Matrix< Real, Device, Index >::load( file ); - this->values.load( file ); - this->columnIndexes.load( file ); + file >> this->values >> this->columnIndexes; } template< typename Real, diff --git a/src/TNL/Matrices/Tridiagonal.h b/src/TNL/Matrices/Tridiagonal.h index 327d68b9d..7f58bd9c4 100644 --- a/src/TNL/Matrices/Tridiagonal.h +++ b/src/TNL/Matrices/Tridiagonal.h @@ -182,13 +182,13 @@ public: typename = typename Enabler< Device2 >::type > Tridiagonal& operator=( const Tridiagonal< Real2, Device2, Index2 >& matrix ); - bool save( File& file ) const; + void save( File& file ) const; - bool load( File& file ); + void load( File& file ); - bool save( const String& fileName ) const; + void save( const String& fileName ) const; - bool load( const String& fileName ); + void load( const String& fileName ); void print( std::ostream& str ) const; diff --git a/src/TNL/Matrices/Tridiagonal_impl.h b/src/TNL/Matrices/Tridiagonal_impl.h index 9485998f3..8aabbf0fe 100644 --- a/src/TNL/Matrices/Tridiagonal_impl.h +++ b/src/TNL/Matrices/Tridiagonal_impl.h @@ -586,45 +586,35 @@ Tridiagonal< Real, Device, Index >::operator=( const Tridiagonal< Real2, Device2 template< typename Real, typename Device, typename Index > -bool Tridiagonal< Real, Device, Index >::save( File& file ) const +void Tridiagonal< Real, Device, Index >::save( File& file ) const { - if( ! Matrix< Real, Device, Index >::save( file ) || - ! this->values.save( file ) ) - { - std::cerr << "Unable to save a tridiagonal matrix." << std::endl; - return false; - } - return true; + Matrix< Real, Device, Index >::save( file ); + file << this->values; } template< typename Real, typename Device, typename Index > -bool Tridiagonal< Real, Device, Index >::load( File& file ) +void Tridiagonal< Real, Device, Index >::load( File& file ) { - if( ! Matrix< Real, Device, Index >::load( file ) || - ! this->values.load( file ) ) - { - std::cerr << "Unable to save a tridiagonal matrix." << std::endl; - return false; - } - return true; + Matrix< Real, Device, Index >::load( file ); + file >> this->values; } template< typename Real, typename Device, typename Index > -bool Tridiagonal< Real, Device, Index >::save( const String& fileName ) const +void Tridiagonal< Real, Device, Index >::save( const String& fileName ) const { - return Object::save( fileName ); + Object::save( fileName ); } template< typename Real, typename Device, typename Index > -bool Tridiagonal< Real, Device, Index >::load( const String& fileName ) +void Tridiagonal< Real, Device, Index >::load( const String& fileName ) { - return Object::load( fileName ); + Object::load( fileName ); } template< typename Real, diff --git a/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h b/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h index cc4b66602..f3d3a378c 100644 --- a/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h +++ b/src/TNL/Meshes/MeshDetails/MeshLayers/BoundaryTags/Layer.h @@ -170,12 +170,12 @@ public: void save( File& file ) const { - boundaryTags.save( file ); + file << boundaryTags; } void load( File& file ) { - boundaryTags.load( file ); + file >> boundaryTags; updateBoundaryIndices( DimensionTag() ); } diff --git a/src/TNL/Meshes/MeshDetails/MeshLayers/StorageLayer.h b/src/TNL/Meshes/MeshDetails/MeshLayers/StorageLayer.h index 618934ce5..86c19eeb2 100644 --- a/src/TNL/Meshes/MeshDetails/MeshLayers/StorageLayer.h +++ b/src/TNL/Meshes/MeshDetails/MeshLayers/StorageLayer.h @@ -143,7 +143,7 @@ public: { SubentityStorageBaseType::save( file ); SuperentityStorageBaseType::save( file ); - this->entities.save( file ); + file << this->entities; BaseType::save( file ); } @@ -151,7 +151,7 @@ public: { SubentityStorageBaseType::load( file ); SuperentityStorageBaseType::load( file ); - this->entities.load( file ); + file >> this->entities; BaseType::load( file ); } diff --git a/src/TNL/Object.h b/src/TNL/Object.h index 8e7e567a9..24ced9a5c 100644 --- a/src/TNL/Object.h +++ b/src/TNL/Object.h @@ -168,9 +168,15 @@ String getObjectType( const String& fileName ); std::vector< String > parseObjectType( const String& objectType ); -inline void saveHeader( File& file, const String& type ); - -inline void loadHeader( File& file, String& type ); +/** + * \brief Saves object type into a binary file. + * + * Throws \ref Exceptions::FileDeserializationError if the object type cannot be detected. + * + * @param file is the file where the object will be saved + * @param type is the object type to be saved + */ +void saveObjectType( File& file, const String& type ); } // namespace TNL diff --git a/src/TNL/Object.hpp b/src/TNL/Object.hpp index 697e738fd..eeec8bf98 100644 --- a/src/TNL/Object.hpp +++ b/src/TNL/Object.hpp @@ -48,7 +48,7 @@ inline void Object::save( File& file ) const inline void Object::load( File& file ) { - String objectType = getObjectType( file ); + const String objectType = getObjectType( file ); if( objectType != this->getSerializationTypeVirtual() ) throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + this->getSerializationTypeVirtual() + ", found " + objectType + ")." ); } @@ -137,19 +137,10 @@ parseObjectType( const String& objectType ) return parsedObjectType; } -inline void saveHeader( File& file, const String& type ) +inline void saveObjectType( File& file, const String& type ) { file.save( magic_number, strlen( magic_number ) ); file << type; } -inline void loadHeader( File& file, String& type ) -{ - char mn[ 10 ]; - file.load( mn, strlen( magic_number ) ); - if( strncmp( mn, magic_number, 5 ) != 0 ) - throw Exceptions::FileDeserializationError( file.getFileName(), "wrong magic number - file is not in a TNL-compatible format." ); - file >> type; -} - } // namespace TNL diff --git a/src/TNL/Problems/PDEProblem_impl.h b/src/TNL/Problems/PDEProblem_impl.h index 1e5260527..151f1e2ac 100644 --- a/src/TNL/Problems/PDEProblem_impl.h +++ b/src/TNL/Problems/PDEProblem_impl.h @@ -193,8 +193,8 @@ saveFailedLinearSystem( const Matrix& matrix, const DofVectorType& rhs ) const { matrix.save( "failed-matrix.tnl" ); - dofs.save( "failed-dof.vec.tnl" ); - rhs.save( "failed-rhs.vec.tnl" ); + File( "failed-dof.vec.tnl", std::ios_base::out ) << dofs; + File( "failed-rhs.vec.tnl", std::ios_base::out ) << rhs; std::cerr << "The linear system has been saved to failed-{matrix,dof.vec,rhs.vec}.tnl" << std::endl; } diff --git a/src/TNL/Solvers/ODE/Merson_impl.h b/src/TNL/Solvers/ODE/Merson_impl.h index 3323f4b74..0b73f234d 100644 --- a/src/TNL/Solvers/ODE/Merson_impl.h +++ b/src/TNL/Solvers/ODE/Merson_impl.h @@ -489,12 +489,12 @@ template< typename Problem > void Merson< Problem >::writeGrids( const DofVectorPointer& u ) { std::cout << "Writing Merson solver grids ..."; - u->save( "Merson-u.tnl" ); - k1->save( "Merson-k1.tnl" ); - k2->save( "Merson-k2.tnl" ); - k3->save( "Merson-k3.tnl" ); - k4->save( "Merson-k4.tnl" ); - k5->save( "Merson-k5.tnl" ); + File( "Merson-u.tnl", std::ios_base::out ) << *u; + File( "Merson-k1.tnl", std::ios_base::out ) << *k1; + File( "Merson-k2.tnl", std::ios_base::out ) << *k2; + File( "Merson-k3.tnl", std::ios_base::out ) << *k3; + File( "Merson-k4.tnl", std::ios_base::out ) << *k4; + File( "Merson-k5.tnl", std::ios_base::out ) << *k5; std::cout << " done. PRESS A KEY." << std::endl; getchar(); } diff --git a/src/Tools/tnl-dicom-reader.cpp b/src/Tools/tnl-dicom-reader.cpp index 55a66b7a6..f6931e5f4 100644 --- a/src/Tools/tnl-dicom-reader.cpp +++ b/src/Tools/tnl-dicom-reader.cpp @@ -72,7 +72,7 @@ bool processDicomSeries( const Config::ParameterContainer& parameters ) fileName.setExtension( "tnl" ); fileName.setIndex( imageIdx ); std::cout << "Writing file " << fileName.getFileName() << " ... " << std::endl; - vector.save( fileName.getFileName() ); + File( fileName.getFileName(), std::ios_base::out ) << vector; } } return true; diff --git a/src/Tools/tnl-diff.h b/src/Tools/tnl-diff.h index 914e4e086..5aa8b3537 100644 --- a/src/Tools/tnl-diff.h +++ b/src/Tools/tnl-diff.h @@ -363,8 +363,8 @@ bool computeDifferenceOfVectors( const MeshPointer& meshPointer, const Config::P } if( verbose ) std::cout << "Processing files " << inputFiles[ i ] << " and " << inputFiles[ i + 1 ] << "... \r" << std::flush; - v1.load( inputFiles[ i ] ); - v2.load( inputFiles[ i + 1 ] ); + File( inputFiles[ i ], std::ios_base::in ) >> v1; + File( inputFiles[ i + 1 ], std::ios_base::in ) >> v2; outputFile << std::setw( 6 ) << i/2 * snapshotPeriod << " "; i++; } @@ -374,11 +374,11 @@ bool computeDifferenceOfVectors( const MeshPointer& meshPointer, const Config::P { if( verbose ) std::cout << "Reading the file " << inputFiles[ 0 ] << "... \r" << std::flush; - v1.load( inputFiles[ 0 ] ); + File( inputFiles[ 0 ], std::ios_base::in ) >> v1; } if( verbose ) std::cout << "Processing the files " << inputFiles[ 0 ] << " and " << inputFiles[ i ] << "... \r" << std::flush; - v2.load( inputFiles[ i ] ); + File( inputFiles[ i ], std::ios_base::in ) >> v2; outputFile << std::setw( 6 ) << ( i - 1 ) * snapshotPeriod << " "; } if( mode == "halves" ) @@ -388,8 +388,8 @@ bool computeDifferenceOfVectors( const MeshPointer& meshPointer, const Config::P i = half; if( verbose ) std::cout << "Processing files " << inputFiles[ i - half ] << " and " << inputFiles[ i ] << "... \r" << std::flush; - v1.load( inputFiles[ i - half ] ); - v2.load( inputFiles[ i ] ); + File( inputFiles[ i - half ], std::ios_base::in ) >> v1; + File( inputFiles[ i ], std::ios_base::in ) >> v2; //if( snapshotPeriod != 0.0 ) outputFile << std::setw( 6 ) << ( i - half ) * snapshotPeriod << " "; } @@ -421,7 +421,7 @@ bool computeDifferenceOfVectors( const MeshPointer& meshPointer, const Config::P diff.setLike( v1 ); diff = v1; diff -= v2; - diff.save( differenceFileName ); + File( differenceFileName, std::ios_base::out ) << diff; } } outputFile.close(); diff --git a/src/Tools/tnl-image-converter.cpp b/src/Tools/tnl-image-converter.cpp index 8a7fccf50..493ff503c 100644 --- a/src/Tools/tnl-image-converter.cpp +++ b/src/Tools/tnl-image-converter.cpp @@ -160,7 +160,7 @@ bool processFiles( const Config::ParameterContainer& parameters ) std::cout << "Processing file " << fileName << "... "; try { - vector.load( fileName ); + File( fileName, std::ios_base::in ) >> vector; } catch(...) { diff --git a/src/Tools/tnl-view.h b/src/Tools/tnl-view.h index 9f2bc02b2..e75878fde 100644 --- a/src/Tools/tnl-view.h +++ b/src/Tools/tnl-view.h @@ -257,7 +257,7 @@ bool convertObject( const MeshPointer& meshPointer, // FIXME: why is MeshType::GlobalIndexType not the same as Index? // Containers::Vector< Value, Devices::Host, Index > vector; Containers::Vector< Value, Devices::Host, typename MeshType::GlobalIndexType > vector; - vector.load( inputFileName ); + File( inputFileName, std::ios_base::in ) >> vector; Functions::MeshFunction< MeshType, MeshType::getMeshDimension(), Value > mf; mf.bind( meshPointer, vector ); mf.write( outputFileName, outputFormat ); diff --git a/src/UnitTests/Containers/ArrayTest.h b/src/UnitTests/Containers/ArrayTest.h index 527f6e9e1..65b8c8b1d 100644 --- a/src/UnitTests/Containers/ArrayTest.h +++ b/src/UnitTests/Containers/ArrayTest.h @@ -478,12 +478,8 @@ TYPED_TEST( ArrayTest, SaveAndLoad ) v.setSize( 100 ); for( int i = 0; i < 100; i ++ ) v.setElement( i, 3.14147 ); - File file; - ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::out ) ); - ASSERT_NO_THROW( v.save( file ) ); - ASSERT_NO_THROW( file.close() ); - ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); - ASSERT_NO_THROW( u.load( file ) ); + ASSERT_NO_THROW( File( "test-file.tnl", std::ios_base::out ) << v ); + ASSERT_NO_THROW( File( "test-file.tnl", std::ios_base::in ) >> u ); EXPECT_EQ( u, v ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); @@ -497,21 +493,18 @@ TYPED_TEST( ArrayTest, LoadViaView ) v.setSize( 100 ); for( int i = 0; i < 100; i ++ ) v.setElement( i, 3.14147 ); - File file; - ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::out ) ); - ASSERT_NO_THROW( v.save( file ) ); - ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( File( "test-file.tnl", std::ios_base::out ) << v ); w.setSize( 100 ); auto u = w.getView(); - ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); - ASSERT_NO_THROW( u.load( file ) ); + ASSERT_NO_THROW( File( "test-file.tnl", std::ios_base::in ) >> u ); EXPECT_EQ( u, v ); EXPECT_EQ( u.getData(), w.getData() ); ArrayType z( 50 ); + File file; ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); - EXPECT_ANY_THROW( z.getView().load( file ) ); + EXPECT_THROW( file >> z.getView(), Exceptions::FileDeserializationError ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); } diff --git a/src/UnitTests/ObjectTest.cpp b/src/UnitTests/ObjectTest.cpp index cb6c9c8ad..9758e25b4 100644 --- a/src/UnitTests/ObjectTest.cpp +++ b/src/UnitTests/ObjectTest.cpp @@ -13,13 +13,13 @@ #include #include -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include #endif using namespace TNL; -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST TEST( ObjectTest, SaveAndLoadTest ) { Object testObject; @@ -81,12 +81,11 @@ TEST( HeaderTest, SaveAndLoadTest ) Object testObject; File file; ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::out ) ); - ASSERT_NO_THROW( saveHeader( file, "TYPE" ) ); + ASSERT_NO_THROW( saveObjectType( file, "TYPE" ) ); ASSERT_NO_THROW( file.close() ); ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); String type; - ASSERT_NO_THROW( loadHeader( file, type ) ); - + ASSERT_NO_THROW( type = getObjectType( file ) ); EXPECT_EQ( type, "TYPE" ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); -- GitLab From bd1d51b36bffefad5bccedc0c1cb9e77c5378f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 13 Apr 2019 13:00:13 +0200 Subject: [PATCH 30/30] Removed Object from classes which don't really need it --- src/TNL/Containers/DistributedArray.h | 6 ------ src/TNL/Matrices/DistributedMatrix.h | 6 ------ src/TNL/Solvers/ODE/ExplicitSolver.h | 1 - src/TNL/Solvers/PDE/PDESolver.h | 3 +-- src/TNL/Solvers/PDE/TimeIndependentPDESolver.h | 5 +---- src/TNL/Solvers/SolverInitiator.h | 6 ++---- 6 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/TNL/Containers/DistributedArray.h b/src/TNL/Containers/DistributedArray.h index db160a1ef..bfaef291c 100644 --- a/src/TNL/Containers/DistributedArray.h +++ b/src/TNL/Containers/DistributedArray.h @@ -23,7 +23,6 @@ template< typename Value, typename Index = int, typename Communicator = Communicators::MpiCommunicator > class DistributedArray -: public Object { using CommunicationGroup = typename Communicator::CommunicationGroup; public: @@ -145,11 +144,6 @@ protected: IndexType globalSize = 0; CommunicationGroup group = Communicator::NullGroup; LocalArrayType localData; - -private: - // TODO: disabled until they are implemented - using Object::save; - using Object::load; }; } // namespace Containers diff --git a/src/TNL/Matrices/DistributedMatrix.h b/src/TNL/Matrices/DistributedMatrix.h index c200663dc..72586dbb3 100644 --- a/src/TNL/Matrices/DistributedMatrix.h +++ b/src/TNL/Matrices/DistributedMatrix.h @@ -44,7 +44,6 @@ struct has_communicator< T, typename enable_if_type< typename T::CommunicatorTyp template< typename Matrix, typename Communicator = Communicators::MpiCommunicator > class DistributedMatrix -: public Object { using CommunicationGroup = typename Communicator::CommunicationGroup; public: @@ -172,11 +171,6 @@ protected: Matrix localMatrix; DistributedSpMV< Matrix, Communicator > spmv; - -private: - // TODO: disabled until they are implemented - using Object::save; - using Object::load; }; } // namespace Matrices diff --git a/src/TNL/Solvers/ODE/ExplicitSolver.h b/src/TNL/Solvers/ODE/ExplicitSolver.h index c1431c0fb..f2c710770 100644 --- a/src/TNL/Solvers/ODE/ExplicitSolver.h +++ b/src/TNL/Solvers/ODE/ExplicitSolver.h @@ -12,7 +12,6 @@ #include #include -#include #include #include #include diff --git a/src/TNL/Solvers/PDE/PDESolver.h b/src/TNL/Solvers/PDE/PDESolver.h index 4b06ef210..b9bbcd5e2 100644 --- a/src/TNL/Solvers/PDE/PDESolver.h +++ b/src/TNL/Solvers/PDE/PDESolver.h @@ -10,7 +10,6 @@ #pragma once -#include #include #include #include @@ -23,7 +22,7 @@ namespace PDE { template< typename Real, typename Index > -class PDESolver : public Object +class PDESolver { public: using RealType = Real; diff --git a/src/TNL/Solvers/PDE/TimeIndependentPDESolver.h b/src/TNL/Solvers/PDE/TimeIndependentPDESolver.h index e4a5f9778..bdab1a541 100644 --- a/src/TNL/Solvers/PDE/TimeIndependentPDESolver.h +++ b/src/TNL/Solvers/PDE/TimeIndependentPDESolver.h @@ -17,13 +17,12 @@ #pragma once -#include #include #include #include #include #include - +#include namespace TNL { namespace Solvers { @@ -78,10 +77,8 @@ class TimeIndependentPDESolver : public PDESolver< typename Problem::RealType, ProblemType* problem; }; - } // namespace PDE } // namespace Solvers } // namespace TNL #include - diff --git a/src/TNL/Solvers/SolverInitiator.h b/src/TNL/Solvers/SolverInitiator.h index 31fad1ee8..0ba4dc55a 100644 --- a/src/TNL/Solvers/SolverInitiator.h +++ b/src/TNL/Solvers/SolverInitiator.h @@ -10,17 +10,15 @@ #pragma once -#include #include #include namespace TNL { -namespace Solvers { +namespace Solvers { template< template< typename Real, typename Device, typename Index, typename MeshType, typename ConfigTag, typename SolverStarter , typename CommunicatorType > class ProblemSetter, typename ConfigTag > - -class SolverInitiator : public Object +class SolverInitiator { public: -- GitLab