diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9670a1ed73767ac132db7268e6169e9da17038fe..e0228789c668cf6d87d1affe31786cc85e5ea437 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} diff --git a/CMakeLists.txt b/CMakeLists.txt index 208b4789ae887047bdd22394efca62b025ddc4f8..7d0f8ca5a8aa6188293edd33d8b5c72b3e0fc0c3 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 ) @@ -62,8 +64,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 +76,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" ) @@ -147,7 +154,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) diff --git a/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h b/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h index 62e37117247bbe1d24398ed8b40159010213b182..e1689d0dbc2bbc073f30f8f9f62f2644e0a0a810 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 ); @@ -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/Benchmarks/HeatEquation/HeatEquationBenchmarkProblem_impl.h b/src/Benchmarks/HeatEquation/HeatEquationBenchmarkProblem_impl.h index 2bfd1e71cf58bea53963d33c24c5baf601939cc9..14f1fd8a9e0a38a6aa335aacdbe886a155225811 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; diff --git a/src/Benchmarks/HeatEquation/Tuning/ExplicitUpdater.h b/src/Benchmarks/HeatEquation/Tuning/ExplicitUpdater.h index 62f0c55c903a83eb5749d73a6e36ea59cdeef8a9..e492d87619563fe948363d24849b947d6d8308e2 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; } diff --git a/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h b/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h index 2926e6bb149131cb01592532027c1d2b66fc8968..1dd341d43621662b2cd8a74cbfaa38ae126e4b39 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/Benchmarks/SpMV/tnl-benchmark-spmv.h b/src/Benchmarks/SpMV/tnl-benchmark-spmv.h index ad3c8d61c0ef09f084bf4b5ba392224ab2786ea3..c707018ad7e8da62e47249315eb80da37280bbbb 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/Examples/Containers/ArrayExample.cpp b/src/Examples/Containers/ArrayExample.cpp index 9dcfd7cbddc9ad4920ce024b3e2044b3a248efcf..4d6ca48e5865c340f26660a9c6305e627c880ec7 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 087dc19c6abf28d117eb0e05c048aab012e54bc3..3790073eb44773a23c7dc07f634b2962ec6352db 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++ ) @@ -59,10 +57,12 @@ 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 ) std::cerr << "Something is wrong!!!" << std::endl; diff --git a/src/Examples/FileExample.cpp b/src/Examples/FileExample.cpp index 5239fc2144d6795a5dd1df79af47129bf314a8a6..d8905d5ef65b54d827542bdaaaf507a282ff8bb1 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 59718ed3ff1bbb845d1a333a078f0139d8a23ff5..00e353218b241e60659d78ad829ee78704b7641f 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 19ed24bd11d67e7b4b7d98de9c9f93c758bcbaa2..609e2a26981362a663f2a92e6a82c6f86a94e41c 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/Python/pytnl/tnl/Array.h b/src/Python/pytnl/tnl/Array.h index c90ac44ad0c5911e9cd1d64ef3f2141892e17ecd..acebce3d22701f68b2a8beb831292fb997ed0a56 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/Python/pytnl/tnl/Object.cpp b/src/Python/pytnl/tnl/Object.cpp index 56b0f54e523df5201a3a14261d3ab712f1ea11da..8c7569f2b3d80b75b954b6642afdb132dbc0b48a 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/Communicators/MPITypeResolver.h b/src/TNL/Communicators/MPITypeResolver.h index 2d0b45e2b3fcc4a1385a261c18d4bb987f86e2e4..371616322494f52aff5a0ed5b1975f071ba90d6f 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/ArrayIO.h b/src/TNL/Containers/Algorithms/ArrayIO.h index 77e82355f82d414dc77224633ed5bc79a6f4fb08..a97fc755fd6184ac8d7868c878768d827d7e4339 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/Algorithms/ArrayOperationsCuda.hpp b/src/TNL/Containers/Algorithms/ArrayOperationsCuda.hpp index 0badc8d799c5d5e81a10393c1ceb987ab3fc8e1e..739e5149bf2d56cc9d4088470cf98983c180177b 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 ff24b237deaa074b7e3a46602606957fbb0fc629..2b6e4511547bd21509d661dfebc26a5229154c00 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/ArrayOperationsMIC.hpp b/src/TNL/Containers/Algorithms/ArrayOperationsMIC.hpp index b41e09f0bee1bfee02d2587b0cb865a8d4f78e91..b0f09fb026fcdb2f0124cba6657b24c269c8c96a 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 c779a7e12a92b582da90964bf6bb1d96ec853b1e..2074d5941a667ba0c0124cd592d8ed655152ceb6 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 8701b8b7df3ade43bbf9f6cd195142915226d110..59603d0f37712155a8c9be83ea777a4ca910b25b 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 5801363632c51239a3a483fcee0e9c1bc888c92f..a4c5ff26e49df3b289ab3c4e15e86225901ed99c 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/Algorithms/VectorOperationsHost_impl.h b/src/TNL/Containers/Algorithms/VectorOperationsHost_impl.h index 7b1bba80c4cd619275bda20d537c5646ec154a0b..47a03c6369ab8ac5fd8e7ac3324ba8dba27b820e 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 diff --git a/src/TNL/Containers/Array.h b/src/TNL/Containers/Array.h index fd6a1ac4e53ce92fda6552332539601245a2c093..43429944305ae66e00564d4dd99226265d95b368 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: @@ -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. @@ -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,8 +119,9 @@ 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& begin, const IndexType& size = 0 ); /** @@ -127,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. { ... } @@ -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 ); /** @@ -518,38 +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 ); - - /** - * \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(); @@ -585,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 a3107fbc42fcbe57330d8511621b82ecd0f008f0..8224a213f70c99a90dc9170c32f6aa1087eafcf8 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" @@ -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; @@ -669,74 +654,65 @@ empty() const template< typename Value, typename Device, typename Index > -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 ); -} - -template< typename Value, - typename Device, - typename Index > -void Array< Value, Device, Index >:: -load( File& file ) +~Array() { - Object::load( file ); - Index _size; - file.load( &_size ); - if( _size < 0 ) - throw Exceptions::ArrayWrongSize( _size, "positive" ); - setSize( _size ); - if( _size ) - Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); + this->releaseData(); } -template< typename Value, - typename Device, - typename Index > -void -Array< Value, Device, Index >:: -boundLoad( File& file ) +template< typename Value, typename Device, typename Index > +std::ostream& operator<<( std::ostream& str, const Array< Value, Device, Index >& array ) { - Object::load( file ); - Index _size; - file.load( &_size ); - if( _size < 0 ) - throw Exceptions::ArrayWrongSize( _size, "Positive is expected," ); - if( this->getSize() != 0 ) + str << "[ "; + if( array.getSize() > 0 ) { - if( this->getSize() != _size ) - throw Exceptions::ArrayWrongSize( _size, convertToString( this->getSize() ) + " is expected." ); + str << array.getElement( 0 ); + for( Index i = 1; i < array.getSize(); i++ ) + str << ", " << array.getElement( i ); } - else setSize( _size ); - if( _size ) - Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size ); + str << " ]"; + return str; } -template< typename Value, - typename Device, - typename Index > -Array< Value, Device, Index >:: -~Array() +// Serialization of arrays into binary files. +template< typename Value, typename Device, typename Index > +File& operator<<( File& file, const Array< Value, Device, Index >& array ) { - this->releaseData(); + 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 > -std::ostream& operator<<( std::ostream& str, const Array< Value, Device, Index >& v ) +File& operator<<( File&& file, const Array< Value, Device, Index >& array ) { - 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 << 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 diff --git a/src/TNL/Containers/ArrayView.h b/src/TNL/Containers/ArrayView.h index 91de01dac18b7dd1a0178c0ae19b4cb449ec822a..04084c3163596e957865f4189ab8ea0059c1dbe7 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. @@ -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 a32c2c5f07659e368ced1832bf68835126aed868..83cc81db2de1132eecb945d49299b481cd5e4a8b 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" @@ -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,71 +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 ); - if( this->size != 0 ) - 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::ObjectTypeMismatch( SerializationType::getType(), type ); - Index _size; - file.load( &_size ); - if( _size != this->getSize() ) - throw Exceptions::ArrayWrongSize( _size, convertToString( 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, File::Mode::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, File::Mode::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/DistributedArray.h b/src/TNL/Containers/DistributedArray.h index f624100cb6e8b6ad2a3c09d34f871e9994df440c..bfaef291ce1e65f96c1b35e8463e401049043d4a 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 @@ -25,7 +23,6 @@ template< typename Value, typename Index = int, typename Communicator = Communicators::MpiCommunicator > class DistributedArray -: public Object { using CommunicationGroup = typename Communicator::CommunicationGroup; public: @@ -36,11 +33,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; @@ -140,19 +137,13 @@ public: // Returns true iff non-zero size is set operator bool() const; - // TODO: serialization (save, load, boundLoad) + // TODO: serialization (save, load) protected: LocalRangeType localRange; IndexType globalSize = 0; CommunicationGroup group = Communicator::NullGroup; LocalArrayType localData; - -private: - // TODO: disabled until they are implemented - using Object::save; - using Object::load; - using Object::boundLoad; }; } // namespace Containers diff --git a/src/TNL/Containers/DistributedArrayView.h b/src/TNL/Containers/DistributedArrayView.h index 6995cf03e494fda563f0e0a386a494a8afc892c3..4b099548b5792ae660c521d228be7f2e426524a4 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 3e110b1270e0609d6b5a140e83cb61dd58ea9829..0607a1b16a60f980acc7dd2b484a358199632543 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 7fc3778b4dd162ce789f140315c433523bfcf695..5c0376e8dbcfe22422bed49ce4ea5f2dc9d31bd8 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/DistributedVectorView_impl.h b/src/TNL/Containers/DistributedVectorView_impl.h index 0639b2f8e1a68105b48bbca43def645d622f1580..cc7df30cb47d818d6adc60e7b9ddd4ec17c69573 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 239239ead7f2b5b5f4b066a11d81648f389a77ae..a2c7cf538373e83ab56f9b70ad46e0012b392f76 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/Containers/Multimaps/EllpackIndexMultimapValues.h b/src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.h index 42addccd1d540deb783eb38e63900e291ada7156..be86f31fac38464ea6e1e0c60fc4f07646325917 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/Multimaps/EllpackIndexMultimap_impl.h b/src/TNL/Containers/Multimaps/EllpackIndexMultimap_impl.h index 2d145d377245ae8e0c92560aeaf9d8389bda2bd4..bf0b3797057cff3ad46699c58674780e36015d06 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 95cb75d5db4069319c9bbd7bcbc138e102285ec5..c8dcd637eeb05fe3d763606a40c16c2e7dd6833e 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/Containers/StaticVector.h b/src/TNL/Containers/StaticVector.h index c8b7bb9b448d7fd4036750dd53681dd0c0188038..6b7c941f23e49798f8fc5dd0b1041e5f0ced8c75 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/Containers/Vector.h b/src/TNL/Containers/Vector.h index 30e399312afc584d5f053de6d8792e4bd0064d13..f9e1c68b31cade956b90b9b2933b93e213617626 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; @@ -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 5f15d9bae5fc6d0527943f8b4245b6f94379fec3..8dea03963762b0bc2fc239f1425a5613b8eeae32 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 1e5f070486052b6e52bc01da6d5ce5ff88d3edab..1ae79565b086fd3a847d692bfa1bd9aaec487e9a 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 > @@ -38,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/Exceptions/ArrayWrongSize.h b/src/TNL/Exceptions/ArrayWrongSize.h deleted file mode 100644 index 8181b3c557e176ab530d8b5f33a8c53896e09a73..0000000000000000000000000000000000000000 --- 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 d6c02cbf20dc9db9c4c39821834d8a7ce8de935b..9ba647c6f5fc0ba2949a94aa9987e8ad981d1bf8 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 6336efa5498cd751863af11ac563bf0dcf6f9c1a..77320f000dd6c261f0b6c3d9663401ec687de4fb 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 6106db872a3eacb5edbc73290f192a2e1e40d392..0000000000000000000000000000000000000000 --- 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/NotImplementedError.h similarity index 64% rename from src/TNL/Exceptions/NotTNLFile.h rename to src/TNL/Exceptions/NotImplementedError.h index ce2d756a533133a068254ad2428fc49c243dd4b5..9f0fb97b276492fa7cbc127836ccc8aa37dfcbc7 100644 --- a/src/TNL/Exceptions/NotTNLFile.h +++ b/src/TNL/Exceptions/NotImplementedError.h @@ -1,29 +1,27 @@ /*************************************************************************** - NotTNLFile.h - description + NotImplementedError.h - description ------------------- - begin : Mar 4, 2019 + 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: Tomas Oberhuber +// Implemented by: Jakub Klinkovsky #pragma once -#include #include namespace TNL { namespace Exceptions { -class NotTNLFile +struct NotImplementedError : public std::runtime_error { -public: - NotTNLFile() - : std::runtime_error( "Wrong magic number found in a binary file. It is not TNL compatible file." ) + NotImplementedError( std::string msg = "Something is not implemented." ) + : std::runtime_error( msg ) {} }; diff --git a/src/TNL/Exceptions/ObjectTypeDetectionFailure.h b/src/TNL/Exceptions/ObjectTypeDetectionFailure.h deleted file mode 100644 index 6381c2fd73f36287b7585f1f067aad5af0deeb41..0000000000000000000000000000000000000000 --- 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 9b48fd0ea3a0fcfcb12d804bc41485a9f342e261..0000000000000000000000000000000000000000 --- 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/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlDirectEikonalMethodsBase.h b/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/tnlDirectEikonalMethodsBase.h index 76d98a2de79882b1a5c2b89b6c73dc30b34e59b8..24a3885540e091047cd2580468ff24d3f1da38d6 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 786c6a48862d6107904107d9b75ab4802d05557f..26444bcfa591d702fbf7fdb325db0fd846c31fa1 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 001f4c69a45e98b245b8e470f489db65c84956bf..8fff00449546090617dbed1dafcea8f6c430aa6a 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 5af33cf29605ce983d75b61846ceeafeada7fde0..2a1183bc2007c1c4c6498c1027b7cdc7ef3a3e1d 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; diff --git a/src/TNL/File.h b/src/TNL/File.h index 120d7342dd2d3151c864e3c68daf864a81679e37..1aa5615e5cbbf8f36d2c9ac3d98bdbc3ba4ada03 100644 --- a/src/TNL/File.h +++ b/src/TNL/File.h @@ -32,35 +32,41 @@ 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. */ 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. * - * 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. @@ -207,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 df1181af7e1a13238418d23562c7377982f347d1..f4edd2b9638e0331da973bdf16de06568d4b7c23 100644 --- a/src/TNL/File.hpp +++ b/src/TNL/File.hpp @@ -21,37 +21,34 @@ #include #include #include +#include namespace TNL { -inline File::Mode operator|( File::Mode m1, File::Mode m2 ); - -inline bool operator&( File::Mode m1, File::Mode m2 ); +inline File::File( const String& fileName, std::ios_base::openmode mode ) +{ + open( fileName, mode ); +} -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() ); @@ -207,10 +204,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 +339,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 @@ -372,7 +363,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 { @@ -380,7 +371,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; } @@ -395,7 +386,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 ) @@ -406,21 +397,11 @@ 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 ); 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/Functions/Analytic/VectorNorm.h b/src/TNL/Functions/Analytic/VectorNorm.h index c543cb2d849485a53b4b6cbb5465f96bb14f715f..a9d292c5f625a22e15115fe6a69d1f5903525a91 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/BoundaryMeshFunction.h b/src/TNL/Functions/BoundaryMeshFunction.h index b91b87bbbea693e13187272d6a7ff10a8c509b99..c09e52543c3401355316d6df0f6b539cca2d9fb1 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 1850f4fb200ab43c3360385fe7ac9d321ed6d88f..c9eb66ac53e60a23f895fa62a0098b68bde943f8 100644 --- a/src/TNL/Functions/MeshFunction.h +++ b/src/TNL/Functions/MeshFunction.h @@ -10,7 +10,7 @@ #pragma once -#include +#include #include #include #include @@ -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; @@ -153,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; @@ -161,8 +162,6 @@ class MeshFunction : using Object::load; - using Object::boundLoad; - DistributedMeshSynchronizerType& getSynchronizer() { return this->synchronizer; diff --git a/src/TNL/Functions/MeshFunctionGnuplotWriter.h b/src/TNL/Functions/MeshFunctionGnuplotWriter.h index 11470965ee6fe4a90dd7db3784c132824ea966c4..d747e84a75d6c75d4029b49761ad17efdaf72368 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 50e39c6de767fa79828d7e4bc9c488356c1d5be6..7f00b6a6c008b6f56d24c13461d6d733719c82d9 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/MeshFunction_impl.h b/src/TNL/Functions/MeshFunction_impl.h index 107503ca4c97e5c59db73bfdae7f6f95f2922a63..0ac98b7b270725d92f8ab7b21acedfb7a41e0ad1 100644 --- a/src/TNL/Functions/MeshFunction_impl.h +++ b/src/TNL/Functions/MeshFunction_impl.h @@ -15,12 +15,11 @@ #include #include #include -#include #pragma once namespace TNL { - namespace Functions { +namespace Functions { template< typename Mesh, int MeshEntityDimension, @@ -47,7 +46,7 @@ template< typename Mesh, int MeshEntityDimension, typename Real > MeshFunction< Mesh, MeshEntityDimension, Real >:: -MeshFunction( const ThisType& meshFunction ) +MeshFunction( const MeshFunction& meshFunction ) { setupSynchronizer(meshFunction.meshPointer->getDistributedMesh()); @@ -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; } @@ -181,7 +178,7 @@ template< typename Mesh, typename Real > void MeshFunction< Mesh, MeshEntityDimension, Real >:: -bind( ThisType& meshFunction ) +bind( MeshFunction& meshFunction ) { setupSynchronizer(meshFunction.meshPointer->getDistributedMesh()); @@ -411,9 +408,9 @@ MeshFunction< Mesh, MeshEntityDimension, Real >& MeshFunction< Mesh, MeshEntityDimension, Real >:: operator = ( const Function& f ) { - Pointers::DevicePointer< ThisType > thisDevicePtr( *this ); - Pointers::DevicePointer< typename std::add_const< Function >::type > fDevicePtr( f ); - MeshFunctionEvaluator< ThisType, Function >::evaluate( thisDevicePtr, fDevicePtr ); + Pointers::DevicePointer< MeshFunction > thisDevicePtr( *this ); + Pointers::DevicePointer< std::add_const_t< Function > > fDevicePtr( f ); + MeshFunctionEvaluator< MeshFunction, Function >::evaluate( thisDevicePtr, fDevicePtr ); return *this; } @@ -425,9 +422,9 @@ MeshFunction< Mesh, MeshEntityDimension, Real >& MeshFunction< Mesh, MeshEntityDimension, Real >:: operator += ( const Function& f ) { - Pointers::DevicePointer< ThisType > thisDevicePtr( *this ); - Pointers::DevicePointer< typename std::add_const< Function >::type > fDevicePtr( f ); - MeshFunctionEvaluator< ThisType, Function >::evaluate( thisDevicePtr, fDevicePtr, ( RealType ) 1.0, ( RealType ) 1.0 ); + Pointers::DevicePointer< MeshFunction > thisDevicePtr( *this ); + Pointers::DevicePointer< std::add_const_t< Function > > fDevicePtr( f ); + MeshFunctionEvaluator< MeshFunction, Function >::evaluate( thisDevicePtr, fDevicePtr, ( RealType ) 1.0, ( RealType ) 1.0 ); return *this; } @@ -439,9 +436,9 @@ MeshFunction< Mesh, MeshEntityDimension, Real >& MeshFunction< Mesh, MeshEntityDimension, Real >:: operator -= ( const Function& f ) { - Pointers::DevicePointer< ThisType > thisDevicePtr( *this ); - Pointers::DevicePointer< typename std::add_const< Function >::type > fDevicePtr( f ); - MeshFunctionEvaluator< ThisType, Function >::evaluate( thisDevicePtr, fDevicePtr, ( RealType ) 1.0, ( RealType ) -1.0 ); + Pointers::DevicePointer< MeshFunction > thisDevicePtr( *this ); + Pointers::DevicePointer< std::add_const_t< Function > > fDevicePtr( f ); + MeshFunctionEvaluator< MeshFunction, Function >::evaluate( thisDevicePtr, fDevicePtr, ( RealType ) 1.0, ( RealType ) -1.0 ); return *this; } @@ -452,7 +449,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, @@ -475,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, @@ -486,10 +483,10 @@ 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::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, @@ -500,7 +497,19 @@ MeshFunction< Mesh, MeshEntityDimension, Real >:: boundLoad( File& file ) { Object::load( file ); - this->data.boundLoad( file ); + file >> this->data.getView(); +} + +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, @@ -520,9 +529,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; @@ -568,6 +577,5 @@ operator << ( std::ostream& str, const MeshFunction< Mesh, MeshEntityDimension, return str; } - } // namespace Functions +} // namespace Functions } // namespace TNL - diff --git a/src/TNL/Functions/TestFunction_impl.h b/src/TNL/Functions/TestFunction_impl.h index f1776783c5da14a127d78cb84c5fba817db4bfcf..e2bdce1f1c4a72848e82f10d9c270099121c28b7 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/Functions/VectorField.h b/src/TNL/Functions/VectorField.h index c7d5bf553ac01cf55a63c0cff75d5d0a323d5d3b..4db601c9f4ccd9c003c46f41a112501953a73a76 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 ++ ) { @@ -283,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 @@ -303,9 +309,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; @@ -317,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/AdEllpack.h b/src/TNL/Matrices/AdEllpack.h index bfe70b6cbba6f1c98558f7b59a21e98713d9fc6f..dd6618d5e40e481e453c46b29b0988a067046b76 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/AdEllpack_impl.h b/src/TNL/Matrices/AdEllpack_impl.h index 0838bf09b7861f60a99415c20cbb5503cc028ae7..12d7336b8f7ea3b46ace0df151475df354537ced 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/BiEllpack.h b/src/TNL/Matrices/BiEllpack.h index 93bfeabaa5814269c4329c70b7555cfc963b2c12..08bb5366671ebbf6abb208d213027914a765ad2e 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 5e72d9b641480d70426d2fd75e186ff9a1aca851..0d2ae9f1e64d42a13d6849e185048b974a9ac61b 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/BiEllpackSymmetric_impl.h b/src/TNL/Matrices/BiEllpackSymmetric_impl.h index 69d32a4722dfeadfcb9182262508b28014ce4a1b..d4c755a236fa9833dbed19d7f70223cc6c7a0608 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 31dbd2bb3f8f5fb178ade2eff590873fe27d6a18..8608a0d99613f7f5c95ad71a63afdcb2fd389144 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 e67351ab9092c3ea3c504781b4409f4053601caa..e5a4a0fd94634a627cfb0080e0700896f2c98f5c 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; @@ -103,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 05439634140745c82bfb23f2df2c0042e7b3741a..090ccd1180349e41e02093ed740aef79b049b14c 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.h b/src/TNL/Matrices/CSR.h index 4f42c1bacdc64da76e189a344e655bd8b44d63e6..70eae6f4b30eba6e6acdf8772df712c5a9e0bf38 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/CSR_impl.h b/src/TNL/Matrices/CSR_impl.h index 5fe617b5430ca870a3857f5a1545e1a038163c7c..3af550a7a4a7ee007fc90ebdc12a31ed35d65785 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 } @@ -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, @@ -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.h b/src/TNL/Matrices/ChunkedEllpack.h index 928dcd8d1f6ad7303d913400f269a0b85aa22e61..a6f06e79745d02f308604fd2bcba46fbeeed497c 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/ChunkedEllpack_impl.h b/src/TNL/Matrices/ChunkedEllpack_impl.h index e3a686264dd3defe5921708fbc5373bc19b0b5ef..a1aae9d97a9e5e8cc69b293399fa56e206e5dd75 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."); } @@ -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/Dense.h b/src/TNL/Matrices/Dense.h index e9601a9face2e7a754c25a1b8a397aae79da1a27..8c21e33b0f02300c7223ce420125f91bc064699d 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 3844751d4638561b883d666d507fbf4ed444de71..a1702f0af55683ee3b718eac567c8f0bd70c944b 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 { @@ -612,7 +613,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 +829,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++ ) @@ -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/DistributedMatrix.h b/src/TNL/Matrices/DistributedMatrix.h index 776af759735af9931103a36c2951a5b5e31ac279..72586dbb3814b95d08cf746c4e32d5704185db2f 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: @@ -61,7 +60,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; @@ -172,12 +171,6 @@ protected: Matrix localMatrix; DistributedSpMV< Matrix, Communicator > spmv; - -private: - // TODO: disabled until they are implemented - using Object::save; - using Object::load; - using Object::boundLoad; }; } // namespace Matrices diff --git a/src/TNL/Matrices/Ellpack.h b/src/TNL/Matrices/Ellpack.h index 100685e7b3fc43cc566d589cc64ed8e82c7df940..e2479fd54349a93424a1d2e67a6fc42a1d0a6eff 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 b150bc4d9b9a6f0b764192ea0c2b6df2d458558a..323772551aac67668cca60ea69fa6651f24dbe1c 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 85c7e49b0c46b5dde10b31f6c52d18a28360d7ed..4c56a8716b5b9ba1612a52750063a42120223682 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/EllpackSymmetric_impl.h b/src/TNL/Matrices/EllpackSymmetric_impl.h index fed7f7669c4f33abdadf4b91f30f8ec5e14b1e23..ace203c565eec321f54596be572e137e24126d87 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 6c06fdd98beb4bba90bc0a16ddffacc998458ee2..5a4e4b4d7512af51fc42cd28bf10e11da86c1b19 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/Matrix_impl.h b/src/TNL/Matrices/Matrix_impl.h index 815e0e7d82c8406369665e947d4fa9de414fba89..7472760c23ec6d8df8a4295457cd6773e4ac80df 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.h b/src/TNL/Matrices/Multidiagonal.h index 969a1e0aaaeac9412979a9626d08ed173b0b82fa..0496a25a343f336690b7b0d00e699e209aabcd28 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/Multidiagonal_impl.h b/src/TNL/Matrices/Multidiagonal_impl.h index 860b3717ca94a1a38d7b48f2dcb4d9060ccfd11c..065e7780dcde13ea02404de3a5a42447ca4d4ae4 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."); } @@ -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/SlicedEllpack.h b/src/TNL/Matrices/SlicedEllpack.h index b7302e55973eb699c80a2ed07cbdaae6cfa8d099..2b207c32b1208c133b60803a7196197055d430b9 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 550df75c43529ce909902389302221a8a0e8869c..9e7694de47649259e597f13582c6b77fbc6a47ae 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 762b0a21e3383ed3c551ee8409e23e8da18d56f4..12019b79d6f2acd5c95c53d2dda4abc7da655a61 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/SlicedEllpackSymmetricGraph_impl.h b/src/TNL/Matrices/SlicedEllpackSymmetricGraph_impl.h index dcd7ca3dc079c249ef45f2b0874faa622b1f329b..f96cc4d68b4248bbded80b91ab91c2e5ec4aec2f 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 } @@ -576,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, @@ -587,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 3a8e3cab4b8e874462c7f7695bab1b3693d4f8d4..7089a45ad70ec80c1b464e38800ebbbb7753c5f9 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 } @@ -625,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, @@ -636,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 8e20c970e95611849d528d2f7d910c2a254a0f9e..afb0781add8826a5b472dfdcc981d67656cc9d6b 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; @@ -707,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, @@ -718,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, @@ -1079,7 +1078,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 +1091,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 +1100,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 +1112,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 6c86b9d5176e6b9a52a8a4177907e134b39a3394..bc2705f2cb22e209ebec7a97e8aa89994c3c061a 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 13b7ee7a933c936f75d41b58f9e83a5467dce1e6..18bc4ea71e4519ac07e35e305b6948c293b3888c 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 { @@ -91,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, @@ -101,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, @@ -126,7 +125,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/ThreePartVector.h b/src/TNL/Matrices/ThreePartVector.h index 6afc2dd114150da67084ffd9b4394c3c81574ab0..f57e3e116a13e6f01d128284422a08f1c719c27c 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/Matrices/Tridiagonal.h b/src/TNL/Matrices/Tridiagonal.h index 153c3bdbc4b6235022a44bb297d09c7fe5cbc458..7f58bd9c492fa59c454b2226f301c83b89e74dbf 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; @@ -183,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 faee4815491672b467fec15774f9a7cacd5efa6c..8aabbf0fef9082abc18632c20728e98462d5c103 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(); } @@ -509,7 +510,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() ); @@ -578,53 +579,42 @@ 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."); } 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/DistributedMeshes/DistributedGridIO.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO.h index 49d7467e1f4cd701a5dedc8d7adb3b98fb39138b..38a7c04f0b5e1d3a86fe7cb30740dba2a242908d 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/DistributedMeshes/DistributedGridIO_MeshFunction.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h index b9d3c5e24e7ad2c99a888c30e361711029bcb601..1a1caeded8c7fcf30e5cce904777e7b6ec0da1ab 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/Meshes/DistributedMeshes/DistributedMeshSynchronizer.h b/src/TNL/Meshes/DistributedMeshes/DistributedMeshSynchronizer.h index 03fff7fa190238a8167ebc169f089271d998888b..4703b205059443d0ffa32349cb8026b7fd27995c 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/DummyMesh.h b/src/TNL/Meshes/DummyMesh.h index 4bff7ce1773978c95a9d16fa2edda1d0760ee7bd..04a49ed0118ac8d7d2bcf8534b6634d3ff3a49da 100644 --- a/src/TNL/Meshes/DummyMesh.h +++ b/src/TNL/Meshes/DummyMesh.h @@ -11,6 +11,7 @@ #pragma once #include +#include #include namespace TNL { @@ -25,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; } @@ -42,14 +42,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/GridDetails/Grid1D.h b/src/TNL/Meshes/GridDetails/Grid1D.h index e4986c9fa140cf2f185204c2bdde16b41a01a999..9c4b1724607c455a540f08c4f546272ee22a1318 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 5f3e919c662ee40d0c9f6ca0c830b1824c7f305e..7519561f3febd96b57d39aa1b7d2a42182359ede 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 59ad153e229973033bd8c7b8c4501fa6992167f8..ddb752e166041339943c566cb10d3d3261e43d5f 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 42f2601b67facfde7bd52a7bf62c5fea5ea4c618..78a339b5b24c7ea3d5446cbf7ba3b9d8e269c478 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 232c3680549a7956e9275e5a477fa43fc63370a6..71b80cb6c0dc50e7326ea2e92a40d11c18c258a7 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 4908ad7074df5d828049ff41339147a00b2a8551..dbd5fcf47e71fd6c2dbb0ba271eb1656773a9a80 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 7c3820f6b6bdda78ea29437c7d10ebc41a172afc..fb5548f359b6b9b478447b5fc76ae9aed41cf2ce 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/GridTraverser_1D.hpp b/src/TNL/Meshes/GridDetails/GridTraverser_1D.hpp index 42ba1b636a0a7626097f32d8283c88798de4d65e..59989bb2a14a85443c2f9616c583ab945b727116 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 9259da9bf436231dad96a4ec74d40e4ecf4b7932..5a3cd568f93bcb20f40682e55959eadf50b5c67f 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/GridDetails/NeighborGridEntityGetter1D_impl.h b/src/TNL/Meshes/GridDetails/NeighborGridEntityGetter1D_impl.h index 04f61c51d20ed508924b89a05e1aeb86b8c4c967..737d38c261882245338439d8e13fe25f8303f2ee 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 b377dc7aeded56007905f3f8f399b50fb927be67..5332eed97a3468270316f58f94bb228fa960a3cb 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 0c8b49aa1a8ff393a357f45516b4691aa8217197..78955a6c0a55318f925212751b33fc408571359c 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 abad0a57d52695df4c1b34f476e2e99c523bb6ff..80041a7539d6c852fb4ce59e8c2ed98224897191 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/Meshes/MeshDetails/MeshEntity_impl.h b/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h index 8a21168de1496d497c248d7cd8fb05c9787066e4..8bdd40570ab492484a2784791e1061a6f6fed6b5 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 99a0e612667ed157f153d5a120ecd497cdc70110..f3d3a378cae2e57c7a4faf10731bc1a1488c81d8 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 ); @@ -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; + file << boundaryTags; } - 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; - } + file >> boundaryTags; 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 44f6cdc445d00a7f6ae49587500e20b950121873..d78ba1c523378e46e45e4792ee51759bb1f20541 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 a9d25d8438316f34782cb8d4cf14c97573dd0b96..86c19eeb2873aedc1d35fb1a27560ec1d3d20eff 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 ); + file << this->entities; + 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 ); + file >> this->entities; + 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 cd4d9edf00c6da911b5bf172094dcc04df6d9aaf..a598289e5dd1457917734470192c6a3bf2cf9ae7 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 7e49a3155cc389d08655387874977e038db2cfa6..9cc1c5535b5d7aaedc89208532794b111b7a75fb 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 7c97686808d3f670f51b0d0fdc9c9f3cd63a0049..6e0970ade32564f03aa16380f86164c109a79cb7 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; diff --git a/src/TNL/Meshes/Readers/TNLReader.h b/src/TNL/Meshes/Readers/TNLReader.h index 6100a5119474fde61ad49c450def2a77ff84f53e..88869ffc1281d5231943180b9e3a8b610ff65326 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/Meshes/Readers/VTKReader.h b/src/TNL/Meshes/Readers/VTKReader.h index 7b52df0bc92401a1187c17feb0636a4cfe305789..b4b986537981dfba159db4daa5f89fed505beeb3 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 96d138b9678ef9d884551ae9e1d1859d0c48a7b1..62a9f073dbd8880072e0d92f4c073286a0e423cf 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/Object.h b/src/TNL/Object.h index 92ed9fef7821cd3bb295d7b5eeace72e3f1a50bf..24ced9a5c2ee9ac97f8d2a7a86e51e88085d13a4 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,20 +98,17 @@ class Object /** * \brief Method for restoring the object from a file. * - * \param file Name of file 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 ); + virtual void load( File& file ); /** * \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,20 +116,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 load( const String& fileName ); - /** - * \brief Method for restoring the object from a file. - * - * \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 +135,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 +145,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 +155,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. @@ -170,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 1e83f036f123cff75fafe63bbcb6b9cc3fba50db..eeec8bf9840b2da7a72db00c49fd64ea660fcc6d 100644 --- a/src/TNL/Object.hpp +++ b/src/TNL/Object.hpp @@ -15,8 +15,6 @@ #include #include -#include -#include namespace TNL { @@ -50,44 +48,32 @@ 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::ObjectTypeMismatch( this->getSerializationTypeVirtual(), objectType ); -} - -inline void Object::boundLoad( File& file ) -{ - this->load( file ); + throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + this->getSerializationTypeVirtual() + ", found " + objectType + ")." ); } 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 ); - this->boundLoad( file ); -} - inline String getObjectType( File& file ) { char mn[ 10 ]; 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; } @@ -95,7 +81,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 ); } @@ -151,21 +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::NotTNLFile(); - file >> type; -} - - - } // namespace TNL diff --git a/src/TNL/Operators/FunctionInverseOperator.h b/src/TNL/Operators/FunctionInverseOperator.h index f202d870cf79e1888fc3a9daf7701b94bfb928c8..1265f3b70bdc7b5c5264289e1a39b71aa0801533 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 15cfbe85c68e8e986e8d50dc8f1c83c24c36fb7b..a46545cd176a7b6f4daecd61ed953c7b4fd22409 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 26ff692e4d0e36d9d6783fc91d4fb620ad832d5a..867f18fcbf0bb4c2aaee8e621616c5fe0e6417dc 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 42e46b257f9eb309f458f28ff3e46e591b03091b..2cf1b297f8f1dbdbbb95d7bf3630df8e48242988 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 f6c45cf710e6901c9a5f23ec4b02de295d48d62f..48d83c93890a12ef2b4d0dfb7a466490578f24b9 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 3acea10bc8eb14a8753fce3a598e62011a06edb7..0e19e78b21eb48d8d2c83df35332ad6f888e9a93 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 279f4535629ea144234040ef55570133a4dbeba8..c8efd5afe38d47b07904be5e93d5de6f5fe53aec 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 ); } diff --git a/src/TNL/Problems/PDEProblem_impl.h b/src/TNL/Problems/PDEProblem_impl.h index 1e5260527132b01e67993a62e177e3588d57dda2..151f1e2ac553e212d2f7adf64c99c73fbad1bf3a 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/Linear/LinearSolver.h b/src/TNL/Solvers/Linear/LinearSolver.h index e75d74b268adb8a4370b6fcf16451b98e0413b29..89158608f2847b924fcea79a5137f217f616023c 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 71aa1ff1d35d67addf3ebbb3fc9404f26fd67b98..308423728af9069fc768a1ee374f28483f70a77b 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/ILU0.h b/src/TNL/Solvers/Linear/Preconditioners/ILU0.h index f5f9715436f218aea85a0da3b6a249a61e27db6c..1fc2fa3fa69f964cb3486d6ee16dcf43fc8d3b9f 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 1bef28b9ec10c0174c564c0445a75c4080cb3614..2e70be2b1b044ee45585ef689d443db1d1e8a8c1 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 = "" ) @@ -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 diff --git a/src/TNL/Solvers/Linear/Traits.h b/src/TNL/Solvers/Linear/Traits.h index f05ad2f5067ebc0a9200e617c9a2811f59987eb9..4130ec430053b8fd28867c4d247c7d8760dc2a05 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 >; diff --git a/src/TNL/Solvers/ODE/ExplicitSolver.h b/src/TNL/Solvers/ODE/ExplicitSolver.h index c1431c0fb8a31f58985c5817ff327c1360756b6a..f2c7107700f4b7af860b65f445f71d8b9807be25 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/ODE/Merson_impl.h b/src/TNL/Solvers/ODE/Merson_impl.h index 3323f4b742373738602d8a671fb2245cb10707d4..0b73f234d52ec3a50e6e187c16ad2b797d966e92 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/TNL/Solvers/PDE/PDESolver.h b/src/TNL/Solvers/PDE/PDESolver.h index 4b06ef2103350bb18fce6dd664568f7053266760..b9bbcd5e2e3ba89d0a424611ea3547008f5f9632 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 e4a5f9778d3bf14b2a42df0819a3b71de028547b..bdab1a541e5e2476953d6499c1e2be7dcd8525f4 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 31fad1ee81184d585c1476db02665652c17e6685..0ba4dc55a9bbad7354dfe296cecb2c10074da3ff 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: diff --git a/src/Tools/tnl-dicom-reader.cpp b/src/Tools/tnl-dicom-reader.cpp index 55a66b7a6c85ac86888beb9c700e50e8cccc0e19..f6931e5f47f21b7ce404e6bc90c384b2aeb749d7 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.cpp b/src/Tools/tnl-diff.cpp index 1d681a6df133001011cf01c7bc0ba8a4ea671859..9fbb851ffcd17f4cb4e7f2a3d15399cc9cf87dcf 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-diff.h b/src/Tools/tnl-diff.h index 5443f953ac1163b649d5b4afa4cf12121183e709..5aa8b3537b7d5d80def78a27e620e68cae2259e9 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(); @@ -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 ]; @@ -580,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; } diff --git a/src/Tools/tnl-image-converter.cpp b/src/Tools/tnl-image-converter.cpp index 8a7fccf5009f9c101b3f2ad85c983635aa96101d..493ff503c8fd035681cadb608cecd5161429d110 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-init.h b/src/Tools/tnl-init.h index a393a7a7cf25523dfbf40034cd5833da5ebb4716..a1c0eb5faaada36f00666ac761bc62aa82d3bdb6 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-lattice-init.h b/src/Tools/tnl-lattice-init.h index 557bf53594f158016373d1e915bc484a5c16546c..a50edcd59a4265c989cbc807a81b70b57567fc3e 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 ) { diff --git a/src/Tools/tnl-view.h b/src/Tools/tnl-view.h index 64c09e32bb8263de055f443c60ab1627d4424839..e75878fdee246cfff6cda3a4acbde0b0f2daa067 100644 --- a/src/Tools/tnl-view.h +++ b/src/Tools/tnl-view.h @@ -250,13 +250,14 @@ 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? // 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 ); @@ -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 ); diff --git a/src/UnitTests/AssertCudaTest.cu b/src/UnitTests/AssertCudaTest.cu index cfd4e846b718edf2481e49cec45023a7ef757a81..9d4865eb9c8ba3b7aaa6f8bf5506fabe17be4483 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 ea20f7957a3fb4103b482d6a7650f4d3902de191..88bbcf4bee40cc82099281f4026285bc0d3fb238 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 23b8fcd4ebfef2dfd36b75582cd2b14652988abd..4c1b6b9c2ced4d380e93f1056cafab50b0335b64 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 3790b35dc9935e1dba49676b0b0ff1ba0245e82c..65b8c8b1d49fd049340d4a13e037331a3ae18179 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 ); @@ -542,119 +478,40 @@ TYPED_TEST( ArrayTest, SaveAndLoad ) v.setSize( 100 ); 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( "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 ); } -TYPED_TEST( ArrayTest, boundLoad ) +TYPED_TEST( ArrayTest, LoadViaView ) { 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 ); - File file; - file.open( "test-file.tnl", File::Mode::Out ); - v.save( file ); - file.close(); + ASSERT_NO_THROW( File( "test-file.tnl", std::ios_base::out ) << v ); w.setSize( 100 ); - u.bind( w ); - file.open( "test-file.tnl", File::Mode::In ); - u.boundLoad( file ); + auto u = w.getView(); + ASSERT_NO_THROW( File( "test-file.tnl", std::ios_base::in ) >> u ); EXPECT_EQ( u, v ); EXPECT_EQ( u.getData(), w.getData() ); - u.setSize( 50 ); - file.open( "test-file.tnl", File::Mode::In ); - bool catched( false ); - try - { - u.boundLoad( file ); - } - catch(...) - { - catched = true; - } - EXPECT_TRUE( catched ); - - u.reset(); - file.open( "test-file.tnl", File::Mode::In ); - u.boundLoad( file ); + ArrayType z( 50 ); + File file; + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); + EXPECT_THROW( file >> z.getView(), Exceptions::FileDeserializationError ); 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 -#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 061a2f5effcf45680c43d6645bdbbc383775bb76..914d5a581251d1d3d1a2c94df35f8c13b052bbc6 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 ) @@ -197,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 ) @@ -548,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 381539af6b72ec44ce6f62497e2b1530d8edc9f9..03d94ccbe3693d9e1a9c1f0221101de7f1d01698 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 870446d15a39a0543f4a33f9b05b5f679d15272f..3b52055f44a3519d9ced4bea873f08ced14b5005 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 32e65c22318a4059c981e9fb38bd93de22a2e5da..8330e5268a3ddc6adfa6a20db1137595c542fd83 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 4612c1dd3709efcc470fee9b70e0d3a359b6a693..1ba445e2c62a0c2968a321b16d1b2780cc22f553 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 3602f53ca83708f874bd5a4492ec751800b4876f..d4ad0bcf732be391633ae78651dfa83707ffd3c0 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 d0aa7bd84d536480581d2bdc9023b81fe174680d..0487e916b8080bec0ead292ddb95725d8f84533a 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 a418b9d06ce026fcb0584e3a71150fe332d1729b..3cb37e07c2e8096a016d006c3a2862b68845717d 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", 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", std::ios_base::in ) ); + ASSERT_NO_THROW( u2.load( file ) ); + ASSERT_NO_THROW( file.close() ); EXPECT_EQ( u1, u2 ); @@ -280,32 +280,7 @@ 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 -#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 e34db3f33833dc3254e13bc0b2c650a2613abd22..3f39c5045289420671402e27afaf90ac34f64aeb 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 5f84245165145e32a784e6c9792ec2f33361e21d..c223a7afd064264d627ce0d29d9265ef9f054cb0 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 5a69a1f2882d18f7a19928e70bd93c8586ecaefc..b731db6a08e535084483b7bb3a68567bdcbe105f 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 39671ba661ca77add041345206c9fd2926ce2879..b767dd0c3db8020a742133e8ab85dd08c53849d3 100644 --- a/src/UnitTests/FileTest.h +++ b/src/UnitTests/FileTest.h @@ -18,29 +18,29 @@ 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; - 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 }; 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" ), std::ios_base::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", std::ios_base::out | std::ios_base::trunc ) ); 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", std::ios_base::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", std::ios_base::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" ), 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 ); - 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" ), std::ios_base::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" ), std::ios_base::out | std::ios_base::trunc ) ); 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" ), std::ios_base::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" ), std::ios_base::in ) ); file.load< int, float, Devices::Cuda >( cudaIntData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); cudaMemcpy( floatData, cudaFloatData, @@ -200,18 +200,9 @@ TEST( FileTest, WriteAndReadCUDAWithConversion ) EXPECT_EQ( intData[ 2 ], 1 ); EXPECT_EQ( std::remove( "cuda-test-file.tnl" ), 0 ); -}; +} #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 bab8bf5afbac9fa4f4c62d0a42f64facfeb72c12..d3e0a48f5598b5d955297f6af61e65ce8bf34d2a 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 b60daf091a291579f3c4e50318805ed2dc699163..8c8b77c0904690d6b478c1a94c7153de872920a5 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 c67386e8199fb486f7625279902a45736d67ebdd..f1661c997ec528638a5d586cee530e803dfb499f 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 ) ); @@ -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 2400b7a9ed17bc9758739c5ddd056af770551638..a2170dd1e97751110cdc5c0edab1a91ec01acdae 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 2885bac093d8a3e59144535baf892f27ef0cc24e..a38f294979cf47f336908424405383f426257319 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 78121bdf2af3f278b936e71c75225e17efe53073..c3716c116fedbcb3ba5f90a48039298d06c5b09c 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.hpp b/src/UnitTests/Matrices/SparseMatrixTest.hpp index 8c3858641d8622424e42cb182646f2d8c854b10b..28883ae76cc73c44f1eaab654cb953c4f2a75c82 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/Matrices/SparseMatrixTest_AdEllpack.h b/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.h index 24b4db1b2d14cf744232c78aab3f1c6dceb8b402..f6ab325b03b4f989993d58c1cb27f9e3cad38c71 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 a18e7cc52c266db532949abe8b41a14048196c8e..c3dd6abb4e372ff70184075fcb243fd22e3c4cd8 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 2eaecc76e78cbbe7925dbab4f4572e2c3504253c..9707f6b8419ba98a3e5153b58ffaebd1d99718c9 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 99ad9f0b45ddef8f1e996f6dd08409498a807562..1845255d3ad5e6113cf00b4296e99ca840d25fdc 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 c6ecd72b384eee16fb2ee3ee6fa0b558f775a1cd..f20208b7c525dd259549c6d6132582ecd7164654 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 0fc1f59e2f7369adc793f3e2c7094f42288c7f39..5341847711ee9a9d5194fa17f7e8be57b6fb640c 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 274ef974b78a2c41fa27ca08654723778bb95f9b..c83e407526e93910c8d5a8f5213307a0895a021a 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 383f8328b3e1b11475cc19a955b180cea646246f..1f6ddf2c7ddc6ba8e6ad79730ceb42dc408c49ce 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 587ec807ec0ad01515832f777cd444c5c9ac386a..54071032c5ceba47386286a7fd30c317859a8da3 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 caaf3f613e39a616da425b330799c6d12e817ae9..456cd01f617e951122d27fdd4505fe03538bc87e 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 @@ -592,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(); } @@ -612,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(); @@ -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 ce78b85680c69bba791d205661d918d1498ef3a0..854cdbda1e2dc8389b9cffeb8f85e0112fc7865a 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 b772ecda067d8563a838ce92fadc1fc03b6984fe..bc1f94f8af0ab5fe74e55c5d288d3b41da82f443 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/DistributedGridIOTest.h b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTest.h index 09be099c5507654e5075cfd36e5764017524efd0..e0b2e14eabd3d4784cbd40305a107aa84aa8f230 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/DistributedGridIOTestBase.h b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTestBase.h index 537bcd9239ddde38785b4c462d4bf9d71c0537c7..cd4a155ef6a3d59bec66ac209030f7dc42bfae29 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_MPIIOTest.h b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIO_MPIIOTest.h index b19c8641f2adfd3d30f8e3001b432d7231e9eab5..477b28c2e4c130ad794bfed2f265218c86d02d42 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/DistributedGridIO_MPIIOTestBase.h b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIO_MPIIOTestBase.h index 4e3603a7a40c36cc04d247f52148f029868dcbdf..f84de9065bf3fc1258531e1f269a843c4135a3cc 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 43af00161224122d7169c960f12a7d079764c0f3..1a5dcb8194ddcaf56e81fb3ce908506b38d34126 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 f5a0056de7acb66c237de39d7667e94c89b9ad42..2aaeaa06bec0458a5551eb075891cee686708ed9 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 f92ef08d7a58fb053541ae5f6b5e2b4dc75560a0..823c30db928996ca16e569d55609b9d6553d5142 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 67098fc5db6c801410425378ab5b609778b376f3..0a5ab3e37da3c3f0360fad0525425df95d2d6c9e 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/DistributedMeshes/DistributedVectorFieldIO_MPIIOTestBase.h b/src/UnitTests/Meshes/DistributedMeshes/DistributedVectorFieldIO_MPIIOTestBase.h index 055faa81226f3716d49594fe255b475a366f2797..f3eb667311fb0829f97338807fecf28960f3d71d 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;i 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 ac0281afa2fd66614da1393a8f12b027beaba8f8..9758e25b4a27734484a8fbad2863ee574cda62db 100644 --- a/src/UnitTests/ObjectTest.cpp +++ b/src/UnitTests/ObjectTest.cpp @@ -13,22 +13,22 @@ #include #include -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include #endif using namespace TNL; -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST 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", std::ios_base::out ) ); + ASSERT_NO_THROW( testObject.save( file ) ); + ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) ); + ASSERT_NO_THROW( testObject.load( file ) ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); } @@ -80,29 +80,16 @@ 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", std::ios_base::out ) ); + 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; - loadHeader( file, type ); - + ASSERT_NO_THROW( type = getObjectType( file ) ); EXPECT_EQ( type, "TYPE" ); 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 813054c140fc9ec7aa07784adf596670d5d17c40..c0d76b2cc050d074831a4a6065d71b99ea24a7e9 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 b7d441f70e8e714cd911ae27d8e3a6a92204277e..53501e774b784b73dc7d73df2b1e063b70acd1da 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 2fba352f588ed01a9369598f8cdfcd8506dc6a97..4473580171c087264e608dd611e7ebff66c10300 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 e7079e894b1353c969231c1efcd607e1e8d8e8c3..21e19e2971a1721c3bdc0c0dd5874bf22936fd0f 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), std::ios_base::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 ), std::ios_base::in ) ); + ASSERT_NO_THROW( loadMeshFunctionptr->boundLoad(file) ); + ASSERT_NO_THROW( file.close() ); for(int i=0;i::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 f44eac1c68ee30bfc053325b4f9a9803b6b013e2..d2588f5edb7ace425e0995522ac03e7681a2e623 100644 --- a/src/UnitTests/StringTest.cpp +++ b/src/UnitTests/StringTest.cpp @@ -10,7 +10,7 @@ // Implemented by Nina Dzugasova -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include #endif @@ -19,7 +19,7 @@ using namespace TNL; -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST TEST( StringTest, BasicConstructor ) { String str; @@ -306,27 +306,16 @@ 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", std::ios_base::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", std::ios_base::in ) ); String str2; ASSERT_NO_THROW( file >> str2 ); EXPECT_EQ( str1, str2 ); 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 6c20c4abb2bf6bbd6216db9feeaea7ef06d72d6e..dd46f30f3c120cbd6ac390a6c9856826b13ea6fa 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 0000000000000000000000000000000000000000..87da37fa894a7e0bced5dff59a26189e8f003e14 --- /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 0000000000000000000000000000000000000000..3c7c39a86f87f695f3ea00d099c66f36d2fd579a --- /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 +}