From f4f277ddf8951dac4257280904aa0d6264ad3adf Mon Sep 17 00:00:00 2001 From: Sebastian Eibl Date: Mon, 15 Jun 2020 11:58:56 +0200 Subject: [PATCH 1/6] also trace benchmarks, tutorials and tests in build time benchmark --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a97c9c31b..6b98c3d51 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1932,11 +1932,11 @@ benchmark_ClangBuildAnalyzer: - export PATH+=:$(pwd) - mkdir $CI_PROJECT_DIR/build - cd $CI_PROJECT_DIR/build - - cmake .. -DWALBERLA_BUFFER_DEBUG=OFF -DWALBERLA_BUILD_TESTS=OFF -DWALBERLA_BUILD_BENCHMARKS=OFF -DWALBERLA_BUILD_TUTORIALS=OFF -DWALBERLA_BUILD_TOOLS=OFF -DWALBERLA_BUILD_WITH_MPI=ON -DWALBERLA_BUILD_WITH_CUDA=OFF -DWALBERLA_BUILD_WITH_PYTHON=OFF -DWALBERLA_BUILD_WITH_OPENMP=OFF -DCMAKE_BUILD_TYPE=RELEASE -DMPIEXEC_PREFLAGS=$MPIEXEC_PREFLAGS -DWALBERLA_DOUBLE_ACCURACY=ON -DWARNING_ERROR=ON -DWALBERLA_BUILD_WITH_METIS=OFF -DWALBERLA_BUILD_WITH_PARMETIS=OFF -DWALBERLA_OPTIMIZE_FOR_LOCALHOST=ON -DWALBERLA_BUILD_WITH_FASTMATH=ON -DWALBERLA_BUILD_WITH_LTO=ON -DCMAKE_CXX_FLAGS=-ftime-trace -G Ninja + - cmake .. -DWALBERLA_BUFFER_DEBUG=OFF -DWALBERLA_BUILD_TESTS=ON -DWALBERLA_BUILD_BENCHMARKS=ON -DWALBERLA_BUILD_TUTORIALS=ON -DWALBERLA_BUILD_TOOLS=OFF -DWALBERLA_BUILD_WITH_MPI=ON -DWALBERLA_BUILD_WITH_CUDA=OFF -DWALBERLA_BUILD_WITH_PYTHON=OFF -DWALBERLA_BUILD_WITH_OPENMP=OFF -DCMAKE_BUILD_TYPE=RELEASE -DMPIEXEC_PREFLAGS=$MPIEXEC_PREFLAGS -DWALBERLA_DOUBLE_ACCURACY=ON -DWARNING_ERROR=ON -DWALBERLA_BUILD_WITH_METIS=OFF -DWALBERLA_BUILD_WITH_PARMETIS=OFF -DWALBERLA_OPTIMIZE_FOR_LOCALHOST=ON -DWALBERLA_BUILD_WITH_FASTMATH=ON -DWALBERLA_BUILD_WITH_LTO=ON -DCMAKE_CXX_FLAGS=-ftime-trace -G Ninja - cmake . -LAH - - ClangBuildAnalyzer --start src - - ninja src/all - - ClangBuildAnalyzer --stop src CBA + - ClangBuildAnalyzer --start . + - ninja all + - ClangBuildAnalyzer --stop . CBA - ClangBuildAnalyzer --analyze CBA image: i10git.cs.fau.de:5005/walberla/buildenvs/clang:9.0 tags: -- GitLab From 932f536bf789c07755d2ddd18161f0f270164e1d Mon Sep 17 00:00:00 2001 From: Sebastian Eibl Date: Mon, 15 Jun 2020 12:04:48 +0200 Subject: [PATCH 2/6] moved isInIgnoreCallerPaths to cpp file --- src/core/logging/Logging.cpp | 18 ++++++++++++++++++ src/core/logging/Logging.h | 22 ++-------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/core/logging/Logging.cpp b/src/core/logging/Logging.cpp index 60fc970bc..0c3718d0f 100644 --- a/src/core/logging/Logging.cpp +++ b/src/core/logging/Logging.cpp @@ -22,6 +22,7 @@ #include "Logging.h" #include "core/Filesystem.h" +#include "core/Regex.h" #include @@ -195,6 +196,23 @@ std::string Logging::createLog( const std::string & type, const std::string & me } +bool Logging::isInIgnoreCallerPaths( const std::vector< walberla::regex > & regexes, + const std::string & callerPath, const int line ) const +{ + if( !regexes.empty() ) + { + std::stringstream callerPathAndLine; + callerPathAndLine << callerPath << ":" << line; + + for( auto regex = regexes.begin(); regex != regexes.end(); ++regex ) + if( walberla::regex_search( callerPathAndLine.str(), *regex ) ) + return true; + } + + return false; +} + + } // namespace logging } // namespace walberla diff --git a/src/core/logging/Logging.h b/src/core/logging/Logging.h index d3671e0ea..1a4377851 100644 --- a/src/core/logging/Logging.h +++ b/src/core/logging/Logging.h @@ -140,8 +140,8 @@ private: inline Logging(); - inline bool isInIgnoreCallerPaths( const std::vector< walberla::regex > & regexes, - const std::string & callerPath, const int line ) const; + bool isInIgnoreCallerPaths( const std::vector< walberla::regex > & regexes, + const std::string & callerPath, const int line ) const; inline void logError ( const std::string & message, const std::string & callerPath, const int line ); inline void logDevel ( const std::string & message, const std::string & callerPath, const int line ); @@ -306,24 +306,6 @@ inline bool Logging::logTracing( const std::string & /*callerPath*/, const int / -inline bool Logging::isInIgnoreCallerPaths( const std::vector< walberla::regex > & regexes, - const std::string & callerPath, const int line ) const -{ - if( !regexes.empty() ) - { - std::stringstream callerPathAndLine; - callerPathAndLine << callerPath << ":" << line; - - for( auto regex = regexes.begin(); regex != regexes.end(); ++regex ) - if( walberla::regex_search( callerPathAndLine.str(), *regex ) ) - return true; - } - - return false; -} - - - inline void Logging::logError( const std::string & message, const std::string & callerPath, const int line ) { #ifdef WALBERLA_THREAD_SAFE_LOGGING -- GitLab From 230c48778740e6d0e5a1486d58c6dbe519d72c0c Mon Sep 17 00:00:00 2001 From: Sebastian Eibl Date: Mon, 15 Jun 2020 14:31:06 +0200 Subject: [PATCH 3/6] [API] moved demangle from DataTypes.h to demangle.h --- src/core/DataTypes.h | 35 ------------------ src/core/debug/PrintStacktrace.cpp | 1 + src/core/debug/demangle.h | 59 ++++++++++++++++++++++++++++++ src/domain_decomposition/IBlock.h | 5 ++- src/pe/communication/Instantiate.h | 3 +- 5 files changed, 65 insertions(+), 38 deletions(-) create mode 100644 src/core/debug/demangle.h diff --git a/src/core/DataTypes.h b/src/core/DataTypes.h index 5bcae7599..f90781461 100644 --- a/src/core/DataTypes.h +++ b/src/core/DataTypes.h @@ -31,19 +31,6 @@ #include #include -#ifdef __GLIBCXX__ -#define HAVE_CXXABI_H -#include -#else -#ifdef __has_include -#if __has_include() -#define HAVE_CXXABI_H -#include -#endif -#endif -#endif - - namespace walberla { @@ -332,28 +319,6 @@ TypeToString(double) template< typename T > inline const char* typeToString( T ) { return typeToString(); } -// type info demangling - -inline std::string demangle( const std::string & name ) -{ -#ifdef HAVE_CXXABI_H - int status = 0; - std::size_t size = 0; - const char * demangled = abi::__cxa_demangle( name.c_str(), NULL, &size, &status ); - if( demangled == nullptr ) - { - return name; - } - std::string demangled_str(demangled); - std::free( const_cast(demangled) ); - return demangled_str; -#else - return name; -#endif -} - - - } // namespace walberla #define WALBERLA_UNUSED(x) (void)(x) diff --git a/src/core/debug/PrintStacktrace.cpp b/src/core/debug/PrintStacktrace.cpp index f939d19d5..7eff6bcb9 100644 --- a/src/core/debug/PrintStacktrace.cpp +++ b/src/core/debug/PrintStacktrace.cpp @@ -20,6 +20,7 @@ //====================================================================================================================== #include "PrintStacktrace.h" +#include "demangle.h" #include "core/DataTypes.h" #include diff --git a/src/core/debug/demangle.h b/src/core/debug/demangle.h new file mode 100644 index 000000000..2e317436e --- /dev/null +++ b/src/core/debug/demangle.h @@ -0,0 +1,59 @@ +//====================================================================================================================== +// +// This file is part of waLBerla. waLBerla is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// waLBerla is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with waLBerla (see COPYING.txt). If not, see . +// +//! \file demangle.h +//! \author Florian Schornbaum +// +//====================================================================================================================== + +#pragma once + +#include + +#ifdef __GLIBCXX__ +#define HAVE_CXXABI_H +#include +#else +#ifdef __has_include +#if __has_include() +#define HAVE_CXXABI_H +#include +#endif +#endif +#endif + +namespace walberla { +namespace debug { + +inline std::string demangle( const std::string & name ) +{ +#ifdef HAVE_CXXABI_H + int status = 0; + std::size_t size = 0; + const char * demangled = abi::__cxa_demangle( name.c_str(), NULL, &size, &status ); + if( demangled == nullptr ) + { + return name; + } + std::string demangled_str(demangled); + std::free( const_cast(demangled) ); + return demangled_str; +#else + return name; +#endif +} + +} // namespace debug +} // namespace walberla diff --git a/src/domain_decomposition/IBlock.h b/src/domain_decomposition/IBlock.h index 215f8a51d..c25c55ee9 100644 --- a/src/domain_decomposition/IBlock.h +++ b/src/domain_decomposition/IBlock.h @@ -25,6 +25,7 @@ #include "IBlockID.h" #include "core/Abort.h" +#include "core/debug/demangle.h" #include "core/NonCopyable.h" #include "core/debug/Debug.h" #include "core/math/AABB.h" @@ -103,8 +104,8 @@ public: catch (...) {} #ifndef NDEBUG WALBERLA_ABORT( "BlockData access type violation! (The block data you added is of a different type than the block data you are trying to access!)" - "\nThe original data type was: " << demangle( typeInfo_ ) << - "\nYou try to retrieve data of type: " << demangle( typeid(U).name() ) ) + "\nThe original data type was: " << debug::demangle( typeInfo_ ) << + "\nYou try to retrieve data of type: " << debug::demangle( typeid(U).name() ) ) #else WALBERLA_ABORT( "BlockData access type violation! (The block data you added is of a different type than the block data you are trying to access!)" ) #endif diff --git a/src/pe/communication/Instantiate.h b/src/pe/communication/Instantiate.h index f10a27ddd..8c157be22 100644 --- a/src/pe/communication/Instantiate.h +++ b/src/pe/communication/Instantiate.h @@ -28,6 +28,7 @@ //************************************************************************************************* #include "core/Abort.h" +#include "core/debug/demangle.h" #include "core/math/AABB.h" #include "core/math/Vector3.h" @@ -57,7 +58,7 @@ void correctBodyPosition(const math::AABB& domain, const Vec3& center, Vec3& pos template < class BodyT > std::unique_ptr instantiate( mpi::RecvBuffer& /*buffer*/, const math::AABB& /*domain*/, const math::AABB& /*block*/, BodyT*& /*newBody*/ ) { - WALBERLA_ABORT( "Body instantiation not implemented! (" << demangle(typeid(BodyT).name()) << ")" ); + WALBERLA_ABORT( "Body instantiation not implemented! (" << debug::demangle(typeid(BodyT).name()) << ")" ); } } // namespace communication -- GitLab From cd9c77b98b710b59effc97e9a94b09fe2ae8ca00 Mon Sep 17 00:00:00 2001 From: Sebastian Eibl Date: Mon, 15 Jun 2020 14:46:14 +0200 Subject: [PATCH 4/6] [API] move typeToString to own file --- src/blockforest/SetupBlockForest.cpp | 1 + src/core/DataTypes.h | 29 ----------- src/core/typeToString.h | 52 +++++++++++++++++++ .../containment_octree/ContainmentOctree.h | 1 + .../distance_octree/DistanceOctree.h | 2 + 5 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 src/core/typeToString.h diff --git a/src/blockforest/SetupBlockForest.cpp b/src/blockforest/SetupBlockForest.cpp index b57abcccf..449e8bea3 100644 --- a/src/blockforest/SetupBlockForest.cpp +++ b/src/blockforest/SetupBlockForest.cpp @@ -34,6 +34,7 @@ #include "core/debug/CheckFunctions.h" #include "core/logging/Logging.h" #include "core/math/Sample.h" +#include "core/typeToString.h" #include "domain_decomposition/MapPointToPeriodicDomain.h" diff --git a/src/core/DataTypes.h b/src/core/DataTypes.h index f90781461..5694e7fbc 100644 --- a/src/core/DataTypes.h +++ b/src/core/DataTypes.h @@ -290,35 +290,6 @@ inline bool floatIsEqual( float lhs, float rhs, const float epsilon = real_compa return std::fabs( lhs - rhs ) < epsilon; } - - -// data type to string conversion - -template< typename T > inline const char* typeToString(); - -#define TypeToString(X) template<> inline const char* typeToString< X >() { \ - static char string[] = #X; \ - return string; \ -} - -TypeToString(bool) -TypeToString(char) -TypeToString(short) -TypeToString(int) -TypeToString(long) -TypeToString(long long) -TypeToString(unsigned char) -TypeToString(unsigned short) -TypeToString(unsigned int) -TypeToString(unsigned long) -TypeToString(unsigned long long) -TypeToString(float) -TypeToString(double) - -#undef TypeToString - -template< typename T > inline const char* typeToString( T ) { return typeToString(); } - } // namespace walberla #define WALBERLA_UNUSED(x) (void)(x) diff --git a/src/core/typeToString.h b/src/core/typeToString.h new file mode 100644 index 000000000..ca49ecefa --- /dev/null +++ b/src/core/typeToString.h @@ -0,0 +1,52 @@ +//====================================================================================================================== +// +// This file is part of waLBerla. waLBerla is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// waLBerla is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with waLBerla (see COPYING.txt). If not, see . +// +//! \file typeToString.h +//! \author Florian Schornbaum +// +//====================================================================================================================== + +#pragma once + +namespace walberla { + +// data type to string conversion + +template< typename T > inline const char* typeToString(); + +#define TypeToString(X) template<> inline const char* typeToString< X >() { \ + static char string[] = #X; \ + return string; \ +} + +TypeToString(bool) +TypeToString(char) +TypeToString(short) +TypeToString(int) +TypeToString(long) +TypeToString(long long) +TypeToString(unsigned char) +TypeToString(unsigned short) +TypeToString(unsigned int) +TypeToString(unsigned long) +TypeToString(unsigned long long) +TypeToString(float) +TypeToString(double) + +#undef TypeToString + +template< typename T > inline const char* typeToString( T ) { return typeToString(); } + +} // namespace walberla diff --git a/src/geometry/containment_octree/ContainmentOctree.h b/src/geometry/containment_octree/ContainmentOctree.h index f83014c05..96d091c00 100644 --- a/src/geometry/containment_octree/ContainmentOctree.h +++ b/src/geometry/containment_octree/ContainmentOctree.h @@ -30,6 +30,7 @@ #include "core/DataTypes.h" #include "core/math/GenericAABB.h" #include "core/math/KahanSummation.h" +#include "core/typeToString.h" #include #include diff --git a/src/mesh_common/distance_octree/DistanceOctree.h b/src/mesh_common/distance_octree/DistanceOctree.h index 2c34b9c6c..ce1a21c16 100644 --- a/src/mesh_common/distance_octree/DistanceOctree.h +++ b/src/mesh_common/distance_octree/DistanceOctree.h @@ -33,6 +33,8 @@ #include "core/math/GenericAABB.h" #include "core/math/Vector3.h" +#include "core/typeToString.h" + #include #include -- GitLab From 0c8c717a4599ec0b27bff87066ffa97314ee864e Mon Sep 17 00:00:00 2001 From: Sebastian Eibl Date: Mon, 15 Jun 2020 14:58:22 +0200 Subject: [PATCH 5/6] [API] moved string_to_num to own header and renamed it to stringToNum --- .../MeshDistance/MeshDistanceBenchmark.cpp | 5 ++- src/core/DataTypes.h | 15 ------- src/core/stringToNum.h | 40 +++++++++++++++++++ .../initializer/ScalarFieldFromBody.impl.h | 3 +- .../ScalarFieldFromCellInterval.impl.h | 4 +- src/vtk/Initialization.cpp | 7 ++-- tests/core/load_balancing/MetisTest.cpp | 5 ++- tests/core/load_balancing/ParMetisTest.cpp | 5 ++- tests/core/mpi/MPITextFileTest.cpp | 4 +- tests/field/FieldFileIOTest.cpp | 9 +++-- tests/lbm/DiffusionTest.cpp | 17 ++++---- tests/lbm/boundary/DiffusionDirichlet.cpp | 13 +++--- .../lbm/boundary/SimpleDiffusionDirichlet.cpp | 15 +++---- tests/lbm/boundary/SimplePABTest.cpp | 11 ++--- tests/lbm/refinement/NonConstantDiffusion.cpp | 19 ++++----- tests/mesh/MeshAABBIntersectionTest.cpp | 3 +- tests/mesh/MeshAABBSelectionTest.cpp | 5 ++- tests/mesh/MeshBlockExclusionTest.cpp | 3 +- tests/mesh/MeshDistancePlausibilityTest.cpp | 3 +- tests/mesh/MeshInitilizationTest.cpp | 5 ++- 20 files changed, 117 insertions(+), 74 deletions(-) create mode 100644 src/core/stringToNum.h diff --git a/apps/benchmarks/MeshDistance/MeshDistanceBenchmark.cpp b/apps/benchmarks/MeshDistance/MeshDistanceBenchmark.cpp index 5d2f225f4..8ede6cbb6 100644 --- a/apps/benchmarks/MeshDistance/MeshDistanceBenchmark.cpp +++ b/apps/benchmarks/MeshDistance/MeshDistanceBenchmark.cpp @@ -22,6 +22,7 @@ #include "core/debug/TestSubsystem.h" #include "core/logging/Logging.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "core/timing/Timer.h" #include "geometry/containment_octree/ContainmentOctree.h" @@ -164,8 +165,8 @@ int main( int argc, char * argv[] ) WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " [--no-brute-force] [--force-float] MESH_FILE NUM_POINTS NUM_REPETITIONS" ); const std::string & meshFile = args[1]; - const uint_t numPoints = string_to_num( args[2] ); - const uint_t numRepetitions = string_to_num( args[3] ); + const uint_t numPoints = stringToNum( args[2] ); + const uint_t numRepetitions = stringToNum( args[3] ); if(forceFloat) { diff --git a/src/core/DataTypes.h b/src/core/DataTypes.h index 5694e7fbc..315404e26 100644 --- a/src/core/DataTypes.h +++ b/src/core/DataTypes.h @@ -28,7 +28,6 @@ #include #include #include -#include #include namespace walberla { @@ -86,20 +85,6 @@ inline S numeric_cast( T t ) { } - -template -inline S string_to_num( std::string & t ); -template <> inline float string_to_num( std::string & t ) { return std::stof(t); } -template <> inline double string_to_num( std::string & t ) { return std::stod(t); } -template <> inline long double string_to_num( std::string & t ) { return std::stold(t); } -template <> inline int string_to_num( std::string & t ) { return std::stoi(t); } -template <> inline long string_to_num( std::string & t ) { return std::stol(t); } -template <> inline long long string_to_num( std::string & t ) { return std::stoll(t); } -template <> inline unsigned long string_to_num( std::string & t ) { return std::stoul(t); } -template <> inline unsigned long long string_to_num( std::string & t ) { return std::stoull(t); } - - - // fixed size signed integral types typedef std::int8_t int8_t; ///< 8 bit signed integer typedef std::int16_t int16_t; ///< 16 bit signed integer diff --git a/src/core/stringToNum.h b/src/core/stringToNum.h new file mode 100644 index 000000000..00723d913 --- /dev/null +++ b/src/core/stringToNum.h @@ -0,0 +1,40 @@ +//====================================================================================================================== +// +// This file is part of waLBerla. waLBerla is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// waLBerla is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with waLBerla (see COPYING.txt). If not, see . +// +//! \file stringToNum.h +//! \author Florian Schornbaum +// +//====================================================================================================================== + +#pragma once + +#include + +namespace walberla { + +template +inline S stringToNum( std::string & t ); +template <> inline float stringToNum( std::string & t ) { return std::stof(t); } +template <> inline double stringToNum( std::string & t ) { return std::stod(t); } +template <> inline long double stringToNum( std::string & t ) { return std::stold(t); } +template <> inline int stringToNum( std::string & t ) { return std::stoi(t); } +template <> inline long stringToNum( std::string & t ) { return std::stol(t); } +template <> inline long long stringToNum( std::string & t ) { return std::stoll(t); } +template <> inline unsigned long stringToNum( std::string & t ) { return std::stoul(t); } +template <> inline unsigned long long stringToNum( std::string & t ) { return std::stoull(t); } + +} // namespace walberla + + diff --git a/src/geometry/initializer/ScalarFieldFromBody.impl.h b/src/geometry/initializer/ScalarFieldFromBody.impl.h index 25f459552..fc4042954 100644 --- a/src/geometry/initializer/ScalarFieldFromBody.impl.h +++ b/src/geometry/initializer/ScalarFieldFromBody.impl.h @@ -30,6 +30,7 @@ #include "core/config/Config.h" #include "core/logging/Logging.h" #include "core/mpi/Reduce.h" +#include "core/stringToNum.h" namespace walberla { @@ -64,7 +65,7 @@ namespace initializer { try { - Value_T value = string_to_num(expression); + Value_T value = stringToNum(expression); init ( *bodyFromConfig ( subBlock ), value, addOrSet, id ); } diff --git a/src/geometry/initializer/ScalarFieldFromCellInterval.impl.h b/src/geometry/initializer/ScalarFieldFromCellInterval.impl.h index 8e65dcfb4..8cbbb9514 100644 --- a/src/geometry/initializer/ScalarFieldFromCellInterval.impl.h +++ b/src/geometry/initializer/ScalarFieldFromCellInterval.impl.h @@ -20,7 +20,7 @@ // //====================================================================================================================== - +#include "core/stringToNum.h" namespace walberla { namespace geometry { @@ -62,7 +62,7 @@ void ScalarFieldFromCellInterval::init( const Config::BlockHandle & blo try { - Value_T value = string_to_num(expression); + Value_T value = stringToNum(expression); init(globalCellInterval, value, id); } diff --git a/src/vtk/Initialization.cpp b/src/vtk/Initialization.cpp index c69f039f2..0b4fa4567 100644 --- a/src/vtk/Initialization.cpp +++ b/src/vtk/Initialization.cpp @@ -24,6 +24,7 @@ #include "core/Abort.h" #include "core/logging/Logging.h" +#include "core/stringToNum.h" #include "core/StringUtility.h" #include @@ -46,9 +47,9 @@ static void splitVector( T& x, T& y, T& z, const Config::BlockHandle& bb, const if( coordinates.size() != 3 ) WALBERLA_ABORT( errorMsg ); - x = string_to_num< T >( coordinates[0] ); - y = string_to_num< T >( coordinates[1] ); - z = string_to_num< T >( coordinates[2] ); + x = stringToNum< T >( coordinates[0] ); + y = stringToNum< T >( coordinates[1] ); + z = stringToNum< T >( coordinates[2] ); } diff --git a/tests/core/load_balancing/MetisTest.cpp b/tests/core/load_balancing/MetisTest.cpp index 5db60e5ae..98d13eeb6 100644 --- a/tests/core/load_balancing/MetisTest.cpp +++ b/tests/core/load_balancing/MetisTest.cpp @@ -28,6 +28,7 @@ #include "core/load_balancing/MetisWrapper.h" #include "core/math/Vector2.h" #include "core/logging/Logging.h" +#include "core/stringToNum.h" #include "field/AddToStorage.h" #include "field/GhostLayerField.h" @@ -60,8 +61,8 @@ int main( int argc, char * argv[] ) } try { - fieldSize.set( string_to_num< uint_t >( args.at(1) ), string_to_num< uint_t >( args.at(2) ) ); - partitions = string_to_num< uint_t >( args.at(3) ); + fieldSize.set( stringToNum< uint_t >( args.at(1) ), stringToNum< uint_t >( args.at(2) ) ); + partitions = stringToNum< uint_t >( args.at(3) ); } catch( std::exception & e ) { diff --git a/tests/core/load_balancing/ParMetisTest.cpp b/tests/core/load_balancing/ParMetisTest.cpp index a9e79d384..a02634c83 100644 --- a/tests/core/load_balancing/ParMetisTest.cpp +++ b/tests/core/load_balancing/ParMetisTest.cpp @@ -29,6 +29,7 @@ #include "core/math/Vector2.h" #include "core/math/IntegerFactorization.h" #include "core/logging/Logging.h" +#include "core/stringToNum.h" #include "field/AddToStorage.h" #include "field/GhostLayerField.h" @@ -55,8 +56,8 @@ int main( int argc, char * argv[] ) bool vtk = true; try { - fieldSize.set( string_to_num< uint_t >( args.at(1) ), string_to_num< uint_t >( args.at(2) ) ); - partitions = string_to_num< uint_t >( args.at(3) ); + fieldSize.set( stringToNum< uint_t >( args.at(1) ), stringToNum< uint_t >( args.at(2) ) ); + partitions = stringToNum< uint_t >( args.at(3) ); auto it = std::find( args.begin(), args.end(), "--no-vtk" ); if(it != args.end()) diff --git a/tests/core/mpi/MPITextFileTest.cpp b/tests/core/mpi/MPITextFileTest.cpp index a0ed6e61c..f3e17dbd1 100644 --- a/tests/core/mpi/MPITextFileTest.cpp +++ b/tests/core/mpi/MPITextFileTest.cpp @@ -27,6 +27,8 @@ #include "core/mpi/MPIManager.h" #include "core/mpi/MPITextFile.h" +#include "core/stringToNum.h" + #include "core/Filesystem.h" #include @@ -120,7 +122,7 @@ int main( int argc, char * argv[] ) std::string filename; try { - chunkSize = walberla::string_to_num( args.at(2) ); + chunkSize = walberla::stringToNum( args.at(2) ); filename = args.at( 1 ); } catch( ... ) diff --git a/tests/field/FieldFileIOTest.cpp b/tests/field/FieldFileIOTest.cpp index 1214f0199..53d1c1061 100644 --- a/tests/field/FieldFileIOTest.cpp +++ b/tests/field/FieldFileIOTest.cpp @@ -28,6 +28,7 @@ #include "core/mpi/Environment.h" #include "core/timing/Timer.h" #include "core/math/IntegerFactorization.h" +#include "core/stringToNum.h" #include "field/AddToStorage.h" #include "field/Field.h" @@ -84,10 +85,10 @@ int main( int argc, char* argv[] ) if( args.size() == 5 ) { - numBlocks = string_to_num( args[1] ); - xBlockSize = string_to_num( args[2] ); - yBlockSize = string_to_num( args[3] ); - zBlockSize = string_to_num( args[4] ); + numBlocks = stringToNum( args[1] ); + xBlockSize = stringToNum( args[2] ); + yBlockSize = stringToNum( args[3] ); + zBlockSize = stringToNum( args[4] ); } else if( args.size() > 5 ) { diff --git a/tests/lbm/DiffusionTest.cpp b/tests/lbm/DiffusionTest.cpp index a01187c45..e834fb062 100644 --- a/tests/lbm/DiffusionTest.cpp +++ b/tests/lbm/DiffusionTest.cpp @@ -62,6 +62,7 @@ #include "core/math/Constants.h" #include "core/math/IntegerFactorization.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "domain_decomposition/SharedSweep.h" @@ -198,14 +199,14 @@ int run( int argc, char **argv ) if( argc > 1 ) { std::vector args( argv, argv + argc ); for( uint_t i = 1; i < uint_c(argc); ++i ) { - if( std::string(argv[i]) == "-d" ) d = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-dim" ) dim = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-dx" ) dx = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-dt" ) dt = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-dv" ) dv = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-v" ) u_in = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-t" ) time = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-err" ) err = string_to_num( args[++i] ); + if( std::string(argv[i]) == "-d" ) d = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-dim" ) dim = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-dx" ) dx = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-dt" ) dt = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-dv" ) dv = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-v" ) u_in = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-t" ) time = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-err" ) err = stringToNum( args[++i] ); else if( std::string(argv[i]) == "--gui" ) useGui = true; else if( std::string(argv[i]) == "--quiet" ) quiet = true; else if( std::string(argv[i]) == "--vtk" ) useVTK = true; diff --git a/tests/lbm/boundary/DiffusionDirichlet.cpp b/tests/lbm/boundary/DiffusionDirichlet.cpp index b9215d432..a8c3348f8 100644 --- a/tests/lbm/boundary/DiffusionDirichlet.cpp +++ b/tests/lbm/boundary/DiffusionDirichlet.cpp @@ -59,6 +59,7 @@ #include "core/math/Constants.h" #include "core/math/IntegerFactorization.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "domain_decomposition/SharedSweep.h" @@ -222,12 +223,12 @@ int main( int argc, char **argv ) if( argc > 1 ) { std::vector args( argv, argv + argc ); for( uint_t i = 1; i < uint_c(argc); ++i ) { - if( std::string(argv[i]) == "-o" ) omega = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-l" ) length = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-w" ) width = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-v" ) velx = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-t" ) time = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-e" ) error = string_to_num( args[++i] ); + if( std::string(argv[i]) == "-o" ) omega = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-l" ) length = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-w" ) width = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-v" ) velx = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-t" ) time = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-e" ) error = stringToNum( args[++i] ); else if( std::string(argv[i]) == "--gui" ) useGui = true; else if( std::string(argv[i]) == "--vtk" ) useVTK = true; else if( argv[i][0] != '-' ){ diff --git a/tests/lbm/boundary/SimpleDiffusionDirichlet.cpp b/tests/lbm/boundary/SimpleDiffusionDirichlet.cpp index ab7efa8e0..9bcc236e9 100644 --- a/tests/lbm/boundary/SimpleDiffusionDirichlet.cpp +++ b/tests/lbm/boundary/SimpleDiffusionDirichlet.cpp @@ -51,6 +51,7 @@ #include "core/math/IntegerFactorization.h" #include "core/math/Limits.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "domain_decomposition/SharedSweep.h" @@ -430,13 +431,13 @@ int main( int argc, char **argv ) if( argc > 1 ) { std::vector args( argv, argv + argc ); for( uint_t i = 1; i < uint_c(argc); ++i ) { - if( std::string(argv[i]) == "-l" ) length = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-w" ) width = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-t" ) time = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-d" ) dv = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-o" ) omega = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-c" ) closed = string_to_num( args[++i] ) != 0; - else if( std::string(argv[i]) == "-r" ) levels += string_to_num( args[++i] ); + if( std::string(argv[i]) == "-l" ) length = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-w" ) width = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-t" ) time = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-d" ) dv = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-o" ) omega = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-c" ) closed = stringToNum( args[++i] ) != 0; + else if( std::string(argv[i]) == "-r" ) levels += stringToNum( args[++i] ); else if( std::string(argv[i]) == "--vtk" ) useVTK = true; else if( argv[i][0] != '-' ){ std::cerr << "Usage: -option value" << std::endl; return EXIT_FAILURE; diff --git a/tests/lbm/boundary/SimplePABTest.cpp b/tests/lbm/boundary/SimplePABTest.cpp index a1de4f92f..c02562a96 100644 --- a/tests/lbm/boundary/SimplePABTest.cpp +++ b/tests/lbm/boundary/SimplePABTest.cpp @@ -42,6 +42,7 @@ #include "core/debug/TestSubsystem.h" #include "core/math/IntegerFactorization.h" #include "core/mpi/MPIManager.h" +#include "core/stringToNum.h" #include "domain_decomposition/SharedSweep.h" @@ -215,11 +216,11 @@ int main( int argc, char **argv ) if( args.size() != 6 ) throw std::invalid_argument( "Wrong number of command line arguments!" ); - channelLength = string_to_num( args[1] ); - channelWidth = string_to_num( args[2] ); - omega = string_to_num( args[3] ); - deltaDensity = string_to_num( args[4] ); - numTimesteps = string_to_num( args[5] ); + channelLength = stringToNum( args[1] ); + channelWidth = stringToNum( args[2] ); + omega = stringToNum( args[3] ); + deltaDensity = stringToNum( args[4] ); + numTimesteps = stringToNum( args[5] ); } catch( std::exception & ) { diff --git a/tests/lbm/refinement/NonConstantDiffusion.cpp b/tests/lbm/refinement/NonConstantDiffusion.cpp index d931cb35e..3a12591a5 100644 --- a/tests/lbm/refinement/NonConstantDiffusion.cpp +++ b/tests/lbm/refinement/NonConstantDiffusion.cpp @@ -50,6 +50,7 @@ #include "core/math/IntegerFactorization.h" #include "core/math/Limits.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "domain_decomposition/SharedSweep.h" @@ -274,15 +275,15 @@ int main( int argc, char **argv ) if( argc > 1 ) { std::vector args( argv, argv + argc ); for( uint_t i = 1; i < uint_c(argc); ++i ) { - if( std::string(argv[i]) == "-l" ) length = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-w" ) width = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-t" ) time = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-dv" ) dv = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-v" ) v = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-do" ) domega = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-o" ) omega = string_to_num( args[++i] ); - else if( std::string(argv[i]) == "-c" ) closed = string_to_num( args[++i] ) != 0; - else if( std::string(argv[i]) == "-r" ) levels += string_to_num( args[++i] ); + if( std::string(argv[i]) == "-l" ) length = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-w" ) width = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-t" ) time = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-dv" ) dv = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-v" ) v = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-do" ) domega = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-o" ) omega = stringToNum( args[++i] ); + else if( std::string(argv[i]) == "-c" ) closed = stringToNum( args[++i] ) != 0; + else if( std::string(argv[i]) == "-r" ) levels += stringToNum( args[++i] ); else if( std::string(argv[i]) == "--vtk" ) useVTK = true; else if( argv[i][0] != '-' ){ std::cerr << "Usage: -option value" << std::endl; return EXIT_FAILURE; diff --git a/tests/mesh/MeshAABBIntersectionTest.cpp b/tests/mesh/MeshAABBIntersectionTest.cpp index 45f38ecc6..451fe062b 100644 --- a/tests/mesh/MeshAABBIntersectionTest.cpp +++ b/tests/mesh/MeshAABBIntersectionTest.cpp @@ -24,6 +24,7 @@ #include "core/math/AABB.h" #include "core/mpi/Environment.h" #include "core/Optional.h" +#include "core/stringToNum.h" #include "mesh_common/MeshIO.h" #include "mesh_common/MeshOperations.h" @@ -87,7 +88,7 @@ int main( int argc, char * argv[] ) if( args.size() != 2 ) WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " NUM_AABBS" ); - const uint_t numAABBs = string_to_num< uint_t >( args[1] ); + const uint_t numAABBs = stringToNum< uint_t >( args[1] ); runTests< mesh::TriangleMesh >( numAABBs ); runTests< mesh::FloatTriangleMesh >( numAABBs ); diff --git a/tests/mesh/MeshAABBSelectionTest.cpp b/tests/mesh/MeshAABBSelectionTest.cpp index 94bdad9a2..3e92e09e7 100644 --- a/tests/mesh/MeshAABBSelectionTest.cpp +++ b/tests/mesh/MeshAABBSelectionTest.cpp @@ -22,6 +22,7 @@ #include "core/debug/TestSubsystem.h" #include "core/mpi/Environment.h" #include "core/logging/Logging.h" +#include "core/stringToNum.h" #include "geometry/mesh/TriangleMesh.h" #include "geometry/mesh/TriangleMeshIO.h" @@ -51,8 +52,8 @@ int main( int argc, char * argv[] ) WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " MESH_FILE NUM_BOXES NUM_POINTS_TESTED_PER_BOX" ); const std::string & meshFile = args[1]; - const uint_t numBoxes = string_to_num( args[2] ); - const uint_t numPointsTestedPerBox = string_to_num( args[3] ); + const uint_t numBoxes = stringToNum( args[2] ); + const uint_t numPointsTestedPerBox = stringToNum( args[3] ); auto mesh = make_shared(); mesh::readAndBroadcast( meshFile, *mesh ); diff --git a/tests/mesh/MeshBlockExclusionTest.cpp b/tests/mesh/MeshBlockExclusionTest.cpp index d3cb21efb..cebd9c96d 100644 --- a/tests/mesh/MeshBlockExclusionTest.cpp +++ b/tests/mesh/MeshBlockExclusionTest.cpp @@ -26,6 +26,7 @@ #include "core/logging/Logging.h" #include "core/math/IntegerFactorization.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "geometry/mesh/TriangleMesh.h" #include "geometry/mesh/TriangleMeshIO.h" @@ -148,7 +149,7 @@ int main( int argc, char * argv[] ) WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " MESH_FILE NUM_BLOCKS" ); const std::string & meshFile = args[1]; - const uint_t numTotalBlocks = string_to_num< uint_t >( args[2] ); + const uint_t numTotalBlocks = stringToNum< uint_t >( args[2] ); run< mesh::TriangleMesh >( meshFile, numTotalBlocks ); run< mesh::FloatTriangleMesh >( meshFile, numTotalBlocks ); diff --git a/tests/mesh/MeshDistancePlausibilityTest.cpp b/tests/mesh/MeshDistancePlausibilityTest.cpp index 8b7ccb585..1263b06b3 100644 --- a/tests/mesh/MeshDistancePlausibilityTest.cpp +++ b/tests/mesh/MeshDistancePlausibilityTest.cpp @@ -26,6 +26,7 @@ #include "core/debug/TestSubsystem.h" #include "core/logging/Logging.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "field/AddToStorage.h" #include "field/vtk/VTKWriter.h" @@ -72,7 +73,7 @@ int main( int argc, char * argv[] ) args.erase( vtkArgIt ); } const std::string & meshFile = args[1]; - real_t dx = string_to_num( args[2] ); + real_t dx = stringToNum( args[2] ); auto mesh = make_shared(); mesh::readAndBroadcast( meshFile, *mesh); diff --git a/tests/mesh/MeshInitilizationTest.cpp b/tests/mesh/MeshInitilizationTest.cpp index e3460d3ce..c536f5e34 100644 --- a/tests/mesh/MeshInitilizationTest.cpp +++ b/tests/mesh/MeshInitilizationTest.cpp @@ -27,6 +27,7 @@ #include "core/logging/Logging.h" #include "core/math/IntegerFactorization.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "geometry/mesh/TriangleMesh.h" #include "geometry/mesh/TriangleMeshIO.h" @@ -177,8 +178,8 @@ int main( int argc, char * argv[] ) WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " MESH_FILE NUM_PROCESSES NUM_BLOCKS" ); const std::string & meshFile = args[1]; - const uint_t numProcesses = string_to_num< uint_t >( args[2] ); - const uint_t numTotalBlocks = string_to_num< uint_t >( args[3] ); + const uint_t numProcesses = stringToNum< uint_t >( args[2] ); + const uint_t numTotalBlocks = stringToNum< uint_t >( args[3] ); test< mesh::TriangleMesh >( meshFile, numProcesses, numTotalBlocks ); //test< mesh::FloatTriangleMesh >( meshFile, numProcesses, numTotalBlocks ); -- GitLab From 59fa0056e2b571022b03122c025e9b01846d8bb3 Mon Sep 17 00:00:00 2001 From: Sebastian Eibl Date: Mon, 15 Jun 2020 17:23:43 +0200 Subject: [PATCH 6/6] [API] moved uint utility to core/Uint.h --- src/blockforest/BlockForest.h | 3 +- src/blockforest/BlockID.cpp | 22 ++++----- src/blockforest/BlockID.h | 27 +++++------ src/blockforest/PhantomBlockForest.cpp | 3 +- src/core/DataTypes.cpp | 6 --- src/core/DataTypes.h | 54 ---------------------- src/core/EndianIndependentSerialization.h | 5 +- src/core/math/Uint.cpp | 6 ++- src/core/math/Uint.h | 50 ++++++++++++++++++++ src/core/mpi/BufferDataTypeExtensions.h | 5 +- tests/blockforest/BlockIDTest.cpp | 6 +-- tests/blockforest/SetupBlockForestTest.cpp | 4 +- tests/core/DataTypesTest.cpp | 19 ++++---- 13 files changed, 104 insertions(+), 106 deletions(-) diff --git a/src/blockforest/BlockForest.h b/src/blockforest/BlockForest.h index 45f39dcef..695b5cf34 100644 --- a/src/blockforest/BlockForest.h +++ b/src/blockforest/BlockForest.h @@ -28,6 +28,7 @@ #include "Types.h" #include "core/debug/Debug.h" +#include "core/math/Uint.h" #include "core/timing/TimingPool.h" #include "domain_decomposition/BlockStorage.h" @@ -259,7 +260,7 @@ public: uint_t getMaxDepth() const { #ifdef WALBERLA_BLOCKFOREST_PRIMITIVE_BLOCKID - return ( UINT_BITS - treeIdDigits_ ) / uint_t(3); + return ( math::UINT_BITS - treeIdDigits_ ) / uint_t(3); #else return std::numeric_limits< uint_t >::max(); #endif diff --git a/src/blockforest/BlockID.cpp b/src/blockforest/BlockID.cpp index 060a19b59..886567ed9 100644 --- a/src/blockforest/BlockID.cpp +++ b/src/blockforest/BlockID.cpp @@ -51,12 +51,12 @@ BlockID::BlockID( const std::vector< uint8_t >& array, const uint_t offset, cons WALBERLA_ASSERT_UNEQUAL( usedBits_, 0 ); - const uint_t blocks = ( usedBits_ / UINT_BITS ) + ( ( (usedBits_ & ( UINT_BITS - 1 )) == 0 ) ? 0 : 1 ); + const uint_t blocks = ( usedBits_ / math::UINT_BITS ) + ( ( (usedBits_ & ( math::UINT_BITS - 1 )) == 0 ) ? 0 : 1 ); uint_t b = offset; for( uint_t i = 0; i != blocks; ++i ) { blocks_.push_back(0); - for( uint_t j = 0; j != UINT_BYTES && b != offset + bytes; ++j, ++b ) { + for( uint_t j = 0; j != math::UINT_BYTES && b != offset + bytes; ++j, ++b ) { blocks_.back() |= uint_c( array[b] ) << ( j * 8 ); } } @@ -68,11 +68,11 @@ void BlockID::appendBranchId( const uint_t branchId ) { WALBERLA_ASSERT( !blocks_.empty() ); WALBERLA_ASSERT_LESS( branchId, 8 ); - WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + UINT_BITS * (blocks_.size()-1) ); + WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + math::UINT_BITS * (blocks_.size()-1) ); - const uint_t unusedBits = UINT_BITS - ( usedBits_ & ( UINT_BITS - 1 ) ); + const uint_t unusedBits = math::UINT_BITS - ( usedBits_ & ( math::UINT_BITS - 1 ) ); - if( unusedBits < 3 || unusedBits == UINT_BITS ) + if( unusedBits < 3 || unusedBits == math::UINT_BITS ) blocks_.push_back(0); for( uint_t i = static_cast< uint_t >( blocks_.size() ) - 1; i != 0; --i ) @@ -81,8 +81,8 @@ void BlockID::appendBranchId( const uint_t branchId ) blocks_[0] = ( blocks_[0] << 3 ) | branchId; usedBits_ += 3; - WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + UINT_BITS * (blocks_.size()-1) ); - WALBERLA_ASSERT_GREATER_EQUAL( blocks_.size() * UINT_BITS, usedBits_ ); + WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + math::UINT_BITS * (blocks_.size()-1) ); + WALBERLA_ASSERT_GREATER_EQUAL( blocks_.size() * math::UINT_BITS, usedBits_ ); } @@ -91,19 +91,19 @@ void BlockID::removeBranchId() { WALBERLA_ASSERT( !blocks_.empty() ); WALBERLA_ASSERT_GREATER( usedBits_, 3 ); - WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + UINT_BITS * (blocks_.size()-1) ); + WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + math::UINT_BITS * (blocks_.size()-1) ); for( uint_t i = 0; i != static_cast< uint_t >( blocks_.size() ) - 1; ++i ) blocks_[i] = ( blocks_[i] >> 3 ) | ( (blocks_[i+1] & uint_c(7)) << SHIFT ); - const uint_t bits = usedBits_ & ( UINT_BITS - 1 ); + const uint_t bits = usedBits_ & ( math::UINT_BITS - 1 ); if( 0 < bits && bits < 4 ) blocks_.pop_back(); else blocks_.back() >>= 3; usedBits_ -= 3; - WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + UINT_BITS * (blocks_.size()-1) ); + WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + math::UINT_BITS * (blocks_.size()-1) ); WALBERLA_ASSERT( !blocks_.empty() ); } @@ -124,7 +124,7 @@ void BlockID::toByteArray( std::vector< uint8_t >& array, const uint_t offset, c uint_t block = blocks_[i]; - for( uint_t j = 0; j != UINT_BYTES && b != offset + bytes; ++j, ++b ) { + for( uint_t j = 0; j != math::UINT_BYTES && b != offset + bytes; ++j, ++b ) { array[b] = static_cast< uint8_t >( block & uint_c(255) ); block >>= 8; diff --git a/src/blockforest/BlockID.h b/src/blockforest/BlockID.h index 9a28bc690..ff64a5b19 100644 --- a/src/blockforest/BlockID.h +++ b/src/blockforest/BlockID.h @@ -25,6 +25,7 @@ #include "Utility.h" #include "core/debug/Debug.h" +#include "core/math/Uint.h" #include "core/mpi/RecvBuffer.h" #include "core/mpi/SendBuffer.h" @@ -91,10 +92,10 @@ private: uint_t usedBits_; std::vector< uint_t > blocks_; - static const uint_t SHIFT = UINT_BITS - 3; + static const uint_t SHIFT = math::UINT_BITS - 3; - WALBERLA_STATIC_ASSERT( UINT_BITS > 31 ); - WALBERLA_STATIC_ASSERT( !(UINT_BITS & (UINT_BITS - 1)) ); // power of two + WALBERLA_STATIC_ASSERT( math::UINT_BITS > 31 ); + WALBERLA_STATIC_ASSERT( !(math::UINT_BITS & (math::UINT_BITS - 1)) ); // power of two }; // class BlockID @@ -141,7 +142,7 @@ inline void BlockID::init( const uint_t treeIndex, const uint_t treeIdMarker ) inline uint_t BlockID::getTreeId() const { WALBERLA_ASSERT_GREATER( usedBits_, 0 ); - WALBERLA_ASSERT_LESS_EQUAL( usedBits_, UINT_BITS ); + WALBERLA_ASSERT_LESS_EQUAL( usedBits_, math::UINT_BITS ); WALBERLA_CHECK_EQUAL( blocks_.size(), 1 ); WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_[0] ) ); @@ -153,7 +154,7 @@ inline uint_t BlockID::getTreeId() const inline uint_t BlockID::getTreeIndex() const { WALBERLA_ASSERT_GREATER( usedBits_, 0 ); - WALBERLA_ASSERT_LESS_EQUAL( usedBits_, UINT_BITS ); + WALBERLA_ASSERT_LESS_EQUAL( usedBits_, math::UINT_BITS ); WALBERLA_CHECK_EQUAL( blocks_.size(), 1 ); WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_[0] ) ); @@ -220,7 +221,7 @@ void BlockID::toBuffer( Buffer_T& buffer ) const uint8_t b(0); for( uint_t i = 0; i != blocks_.size(); ++i ) - for( uint_t j = 0; j != UINT_BYTES && b != bytes; ++j, ++b ) + for( uint_t j = 0; j != math::UINT_BYTES && b != bytes; ++j, ++b ) buffer << uint8_c( ( blocks_[i] >> ( uint_c(j) * uint_c(8) ) ) & uint_c(255) ); } @@ -232,22 +233,22 @@ void BlockID::fromBuffer( Buffer_T& buffer ) { uint8_t bytes(0); buffer >> bytes; - const uint_t blocks = ( bytes / UINT_BYTES ) + ( ( (bytes & ( UINT_BYTES - 1 )) == 0 ) ? 0 : 1 ); + const uint_t blocks = ( bytes / math::UINT_BYTES ) + ( ( (bytes & ( math::UINT_BYTES - 1 )) == 0 ) ? 0 : 1 ); uint8_t b(0); blocks_.clear(); for( uint_t i = 0; i != blocks; ++i ) { blocks_.push_back(0); - for( uint_t j = 0; j != UINT_BYTES && b != bytes; ++j, ++b ) { + for( uint_t j = 0; j != math::UINT_BYTES && b != bytes; ++j, ++b ) { uint8_t byte(0); buffer >> byte; blocks_.back() |= uint_c( byte ) << ( uint_c(j) * uint_c(8) ); } } - for( uint_t i = 0; i != UINT_BITS; ++i ) + for( uint_t i = 0; i != math::UINT_BITS; ++i ) if( ( blocks_[ blocks-1 ] & ( uint_c(1) << uint_c(i) ) ) != uint_c(0) ) - usedBits_ = i + 1 + (blocks-1) * UINT_BITS; + usedBits_ = i + 1 + (blocks-1) * math::UINT_BITS; } @@ -278,7 +279,7 @@ public: BlockID getSuperId() const { WALBERLA_ASSERT_GREATER_EQUAL( getUsedBits(), uint_c(4) ); return BlockID( id_ >> 3 ); } BlockID getFatherId() const { return getSuperId(); } - void appendBranchId( const uint_t branchId ) { WALBERLA_ASSERT_LESS_EQUAL( getUsedBits() + 3, UINT_BITS ); WALBERLA_ASSERT_LESS( branchId, 8 ); id_ = (id_ << 3) + branchId; } + void appendBranchId( const uint_t branchId ) { WALBERLA_ASSERT_LESS_EQUAL( getUsedBits() + 3, math::UINT_BITS ); WALBERLA_ASSERT_LESS( branchId, 8 ); id_ = (id_ << 3) + branchId; } void removeBranchId() { WALBERLA_ASSERT_GREATER_EQUAL( getUsedBits(), uint_c(4) ); id_ >>= 3; } uint_t getBranchId() const { WALBERLA_ASSERT_GREATER_EQUAL( getUsedBits(), uint_c(4) ); return id_ & uint_c(7); } @@ -317,7 +318,7 @@ inline BlockID::BlockID( const uint_t treeIndex, const uint_t treeIdMarker ) : i inline BlockID::BlockID( const BlockID& id, const uint_t branchId ) : id_( (id.id_ << 3) + branchId ) { - WALBERLA_ASSERT_LESS_EQUAL( id.getUsedBits() + 3, UINT_BITS ); + WALBERLA_ASSERT_LESS_EQUAL( id.getUsedBits() + 3, math::UINT_BITS ); WALBERLA_ASSERT_LESS( branchId, 8 ); } @@ -366,7 +367,7 @@ void BlockID::fromBuffer( Buffer_T& buffer ) { uint8_t bytes(0); buffer >> bytes; - WALBERLA_ASSERT_LESS_EQUAL( bytes, UINT_BYTES ); + WALBERLA_ASSERT_LESS_EQUAL( bytes, math::UINT_BYTES ); id_ = uint_c(0); for( uint8_t i = 0; i != bytes; ++i ) { diff --git a/src/blockforest/PhantomBlockForest.cpp b/src/blockforest/PhantomBlockForest.cpp index d6867a9dd..fe7f8e1d3 100644 --- a/src/blockforest/PhantomBlockForest.cpp +++ b/src/blockforest/PhantomBlockForest.cpp @@ -26,6 +26,7 @@ #include "core/debug/CheckFunctions.h" #include "core/debug/Debug.h" #include "core/logging/Logging.h" +#include "core/math/Uint.h" #include "core/mpi/BufferSizeTrait.h" #include "core/mpi/BufferSystem.h" #include "core/mpi/MPIManager.h" @@ -188,7 +189,7 @@ void PhantomBlockForest::initialize( const BlockStateDeterminationFunction & fun depth_ = blockforest_.getDepth(); #ifdef WALBERLA_BLOCKFOREST_PRIMITIVE_BLOCKID - WALBERLA_CHECK_LESS_EQUAL( blockforest_.getTreeIdDigits() + depth_ * uint_t(3), UINT_BITS ); + WALBERLA_CHECK_LESS_EQUAL( blockforest_.getTreeIdDigits() + depth_ * uint_t(3), math::UINT_BITS ); #endif // phantom block neighborhood construction diff --git a/src/core/DataTypes.cpp b/src/core/DataTypes.cpp index 529b19e10..ead9f6fb6 100644 --- a/src/core/DataTypes.cpp +++ b/src/core/DataTypes.cpp @@ -24,12 +24,6 @@ namespace walberla { -#ifndef WALBERLA_CXX_COMPILER_IS_MSVC - -const uint_t int_ld<1>::exp; - -#endif - namespace real_comparison { const float Epsilon< float >::value = static_cast< float >(1e-4); diff --git a/src/core/DataTypes.h b/src/core/DataTypes.h index 315404e26..3ae37218d 100644 --- a/src/core/DataTypes.h +++ b/src/core/DataTypes.h @@ -142,60 +142,6 @@ inline void static_assert_uint_t() { !std::numeric_limits::is_signed, "Unsigned integer type required/expected!" ); } -template< uint_t size > struct uintFromBitWidth; -template<> struct uintFromBitWidth< 8 > { typedef uint8_t type; }; -template<> struct uintFromBitWidth< 16 > { typedef uint16_t type; }; -template<> struct uintFromBitWidth< 32 > { typedef uint32_t type; }; -template<> struct uintFromBitWidth< 64 > { typedef uint64_t type; }; - -constexpr uint_t leastUnsignedIntegerBitWidth( uint_t width ) -{ - if ( width <= 8 ) return 8; - if ( width <= 16 ) return 16; - if ( width <= 32 ) return 32; - if ( width <= 64 ) return 64; - return width; -} - -/// \brief Provides the smallest unsigned integer type that has at least minSize bits. -/// -/// Example: -/// -/// leastUnsignedInteger< 5 >::type a; // a is an 8-bit unsigned integer -/// leastUnsignedInteger< 9 >::type b; // b is a 16-bit unsigned integer -/// -template< uint_t minSize > -struct leastUnsignedInteger -{ - typedef typename uintFromBitWidth< leastUnsignedIntegerBitWidth( minSize ) >::type type; -}; - -/// \cond internal -static const uint_t UINT_BITS = static_cast< uint_t >( std::numeric_limits< uint_t >::digits ); -static const uint_t UINT_BYTES = static_cast< uint_t >( std::numeric_limits< uint_t >::digits ) >> 3; - -static_assert( !(UINT_BITS & (UINT_BITS - 1)), "Type \"uint_t\" must consist of 2^x Bits!" ); // power of two - -template< int N > -struct int_ld -{ - static_assert( N >= 1 && !(N & (N - 1)), "Calculating log_2(N) -> \"N\" must be a power of two!" ); - static const uint_t exp = 1 + int_ld< (N >> 1) >::exp; -}; - -template< int N > const uint_t int_ld::exp; - -template<> -struct int_ld<1> -{ - static const uint_t exp = 0; -}; - -static const uint_t UINT_BITS_LD = int_ld< std::numeric_limits< uint_t >::digits >::exp; -/// \endcond - - - // data structure specific data types typedef int cell_idx_t; diff --git a/src/core/EndianIndependentSerialization.h b/src/core/EndianIndependentSerialization.h index e33b8ab3a..b45b19c8e 100644 --- a/src/core/EndianIndependentSerialization.h +++ b/src/core/EndianIndependentSerialization.h @@ -23,6 +23,7 @@ #include "DataTypes.h" #include "core/debug/Debug.h" +#include "core/math/Uint.h" #include #include @@ -52,7 +53,7 @@ namespace walberla { inline void uintToByteArray( uint_t value, std::vector< uint8_t >& array, const uint_t offset, const uint_t bytes ) { WALBERLA_ASSERT_LESS_EQUAL( offset + bytes, array.size() ); - WALBERLA_ASSERT_LESS_EQUAL( bytes, UINT_BYTES ); + WALBERLA_ASSERT_LESS_EQUAL( bytes, math::UINT_BYTES ); for( uint_t i = 0; i != bytes; ++i ) { @@ -79,7 +80,7 @@ inline void uintToByteArray( uint_t value, std::vector< uint8_t >& array, const inline uint_t byteArrayToUint( const std::vector< uint8_t >& array, const uint_t offset, const uint_t bytes ) { WALBERLA_ASSERT_LESS_EQUAL( offset + bytes, array.size() ); - WALBERLA_ASSERT_LESS_EQUAL( bytes, UINT_BYTES ); + WALBERLA_ASSERT_LESS_EQUAL( bytes, math::UINT_BYTES ); uint_t value = 0; for( uint_t i = 0; i != bytes; ++i ) diff --git a/src/core/math/Uint.cpp b/src/core/math/Uint.cpp index ee16588d1..38f8003e7 100644 --- a/src/core/math/Uint.cpp +++ b/src/core/math/Uint.cpp @@ -25,8 +25,6 @@ namespace walberla { namespace math { - - template<> uint_t uintMSBPosition< uint64_t >( uint64_t value ) { // for the documentation see the header file uint64_t i; @@ -51,7 +49,11 @@ template<> uint_t uintMSBPosition< uint64_t >( uint64_t value ) { // for the doc return ( i != 0 ) ? (8 + msbLookupTable[i]) : msbLookupTable[value]; } +#ifndef WALBERLA_CXX_COMPILER_IS_MSVC + +const uint_t int_ld<1>::exp; +#endif } // namespace math } // namespace walberla diff --git a/src/core/math/Uint.h b/src/core/math/Uint.h index 71fe07fea..5a76bc8fa 100644 --- a/src/core/math/Uint.h +++ b/src/core/math/Uint.h @@ -193,7 +193,57 @@ template<> inline uint_t uintMSBPosition< uint8_t >( uint8_t value ) { return msbLookupTable[value]; } +template< uint_t size > struct uintFromBitWidth; +template<> struct uintFromBitWidth< 8 > { typedef uint8_t type; }; +template<> struct uintFromBitWidth< 16 > { typedef uint16_t type; }; +template<> struct uintFromBitWidth< 32 > { typedef uint32_t type; }; +template<> struct uintFromBitWidth< 64 > { typedef uint64_t type; }; +constexpr uint_t leastUnsignedIntegerBitWidth( uint_t width ) +{ + if ( width <= 8 ) return 8; + if ( width <= 16 ) return 16; + if ( width <= 32 ) return 32; + if ( width <= 64 ) return 64; + return width; +} + +/// \brief Provides the smallest unsigned integer type that has at least minSize bits. +/// +/// Example: +/// +/// leastUnsignedInteger< 5 >::type a; // a is an 8-bit unsigned integer +/// leastUnsignedInteger< 9 >::type b; // b is a 16-bit unsigned integer +/// +template< uint_t minSize > +struct leastUnsignedInteger +{ + typedef typename uintFromBitWidth< leastUnsignedIntegerBitWidth( minSize ) >::type type; +}; + +/// \cond internal +static const uint_t UINT_BITS = static_cast< uint_t >( std::numeric_limits< uint_t >::digits ); +static const uint_t UINT_BYTES = static_cast< uint_t >( std::numeric_limits< uint_t >::digits ) >> 3; + +static_assert( !(UINT_BITS & (UINT_BITS - 1)), "Type \"uint_t\" must consist of 2^x Bits!" ); // power of two + +template< int N > +struct int_ld +{ + static_assert( N >= 1 && !(N & (N - 1)), "Calculating log_2(N) -> \"N\" must be a power of two!" ); + static const uint_t exp = 1 + int_ld< (N >> 1) >::exp; +}; + +template< int N > const uint_t int_ld::exp; + +template<> +struct int_ld<1> +{ + static const uint_t exp = 0; +}; + +static const uint_t UINT_BITS_LD = int_ld< std::numeric_limits< uint_t >::digits >::exp; +/// \endcond } // namespace math } // namespace walberla diff --git a/src/core/mpi/BufferDataTypeExtensions.h b/src/core/mpi/BufferDataTypeExtensions.h index e1ec37550..9685d6ac2 100644 --- a/src/core/mpi/BufferDataTypeExtensions.h +++ b/src/core/mpi/BufferDataTypeExtensions.h @@ -27,6 +27,7 @@ #include "SendBuffer.h" #include "core/Conversion.h" #include "core/DataTypes.h" +#include "core/math/Uint.h" #include "core/Optional.h" #include "core/RandomUUID.h" @@ -276,7 +277,7 @@ template< typename T, // Element type of SendBuffer GenericSendBuffer& packBoolVectorWithoutSize(GenericSendBuffer & buf, const std::vector & bools ) { // Use an unsigned type at least as large as the SendBuffer base type as container for the bools - typedef typename leastUnsignedInteger< std::numeric_limits::digits >::type ContainerType; + typedef typename math::leastUnsignedInteger< std::numeric_limits::digits >::type ContainerType; static const size_t NUM_BITS = std::numeric_limits::digits; auto it = bools.begin(); @@ -297,7 +298,7 @@ template< typename T > // Element type of RecvBuffer GenericRecvBuffer& unpackBoolVectorWithoutSize(GenericRecvBuffer & buf, std::vector & bools, size_t size ) { // Use an unsigned type at least as large as the RecvBuffer base type as container for the bools - typedef typename leastUnsignedInteger::digits>::type ContainerType; + typedef typename math::leastUnsignedInteger::digits>::type ContainerType; static const size_t NUM_BITS = std::numeric_limits::digits; bools.resize(size); diff --git a/tests/blockforest/BlockIDTest.cpp b/tests/blockforest/BlockIDTest.cpp index 10979b1f6..45e8fdbf0 100644 --- a/tests/blockforest/BlockIDTest.cpp +++ b/tests/blockforest/BlockIDTest.cpp @@ -41,7 +41,7 @@ static void test() { uint_t bit = 1; uint_t mask = 0; - for( uint_t i = 0; i != UINT_BITS; ++i ) { + for( uint_t i = 0; i != math::UINT_BITS; ++i ) { for( uint_t j = 0; j !=10000; ++j ) { @@ -50,7 +50,7 @@ static void test() { #ifndef WALBERLA_BLOCKFOREST_PRIMITIVE_BLOCKID const uint_t branches = walberla::math::intRandom(); #else - const uint_t branches = walberla::math::intRandom( uint_t(0), uint_c( ( UINT_BITS - i - 1 ) / 3 ) ); + const uint_t branches = walberla::math::intRandom( uint_t(0), uint_c( ( math::UINT_BITS - i - 1 ) / 3 ) ); #endif std::vector< uint_t > branch; for( uint_t b = 0; b != branches; ++b ) @@ -102,7 +102,7 @@ static void test() { #ifndef WALBERLA_BLOCKFOREST_PRIMITIVE_BLOCKID const uint_t branches = walberla::math::intRandom(); #else - const uint_t branches = walberla::math::intRandom( uint_t(0), uint_c( ( UINT_BITS - i - 1 ) / 3 ) ); + const uint_t branches = walberla::math::intRandom( uint_t(0), uint_c( ( math::UINT_BITS - i - 1 ) / 3 ) ); #endif BlockID id( treeIndex, bit ); for( uint_t b = 0; b != branches; ++b ) diff --git a/tests/blockforest/SetupBlockForestTest.cpp b/tests/blockforest/SetupBlockForestTest.cpp index f910fe4ec..46d6d2cb2 100644 --- a/tests/blockforest/SetupBlockForestTest.cpp +++ b/tests/blockforest/SetupBlockForestTest.cpp @@ -52,8 +52,8 @@ static void refinementSelectionFunctionRandom( SetupBlockForest& forest ) { #ifndef WALBERLA_BLOCKFOREST_PRIMITIVE_BLOCKID const uint_t maxLevel = 25; #else - WALBERLA_ASSERT_GREATER_EQUAL( UINT_BITS, 32 ); - const uint_t maxLevel = ( UINT_BITS - 14 ) / 3; + WALBERLA_ASSERT_GREATER_EQUAL( math::UINT_BITS, 32 ); + const uint_t maxLevel = ( math::UINT_BITS - 14 ) / 3; #endif std::vector< SetupBlock* > blocks; diff --git a/tests/core/DataTypesTest.cpp b/tests/core/DataTypesTest.cpp index 8c8946b66..4250c8d33 100644 --- a/tests/core/DataTypesTest.cpp +++ b/tests/core/DataTypesTest.cpp @@ -22,6 +22,7 @@ #include "core/DataTypes.h" #include "core/debug/Debug.h" #include "core/debug/TestSubsystem.h" +#include "core/math/Uint.h" #include #include @@ -39,17 +40,17 @@ int main( int /*argc*/, char** /*argv*/ ) { debug::enterTestMode(); - WALBERLA_CHECK_EQUAL( UINT_BITS_LD, uintBitsLd( UINT_BITS ) ); + WALBERLA_CHECK_EQUAL( math::UINT_BITS_LD, uintBitsLd( math::UINT_BITS ) ); - WALBERLA_CHECK_EQUAL( int_ld< 2048 >::exp, 11 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 2048 >::exp, 11 ); - WALBERLA_CHECK_EQUAL( int_ld< 64 >::exp, 6 ); - WALBERLA_CHECK_EQUAL( int_ld< 32 >::exp, 5 ); - WALBERLA_CHECK_EQUAL( int_ld< 16 >::exp, 4 ); - WALBERLA_CHECK_EQUAL( int_ld< 8 >::exp, 3 ); - WALBERLA_CHECK_EQUAL( int_ld< 4 >::exp, 2 ); - WALBERLA_CHECK_EQUAL( int_ld< 2 >::exp, 1 ); - WALBERLA_CHECK_EQUAL( int_ld< 1 >::exp, 0 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 64 >::exp, 6 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 32 >::exp, 5 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 16 >::exp, 4 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 8 >::exp, 3 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 4 >::exp, 2 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 2 >::exp, 1 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 1 >::exp, 0 ); return EXIT_SUCCESS; } -- GitLab