From 2eba6e84f8e0c8c279007e0e617fdc7ba9d455d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sun, 21 Oct 2018 12:58:14 +0200 Subject: [PATCH 01/39] Removed TNL_CPP_COMPILER_NAME from tnlConfig.h --- src/TNL/Devices/SystemInfo.cpp | 19 ++++++++++++++++++- tnlConfig.h.in | 2 -- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/TNL/Devices/SystemInfo.cpp b/src/TNL/Devices/SystemInfo.cpp index 377922b26..60606204c 100644 --- a/src/TNL/Devices/SystemInfo.cpp +++ b/src/TNL/Devices/SystemInfo.cpp @@ -157,11 +157,28 @@ void SystemInfo:: writeDeviceInfo( Logger& logger ) { +// compiler detection macros: +// http://nadeausoftware.com/articles/2012/10/c_c_tip_how_detect_compiler_name_and_version_using_compiler_predefined_macros +// https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#compilation-phases +#if defined(__NVCC__) + #define TNL_STRINGIFY(x) #x + const char* compiler_name = "Nvidia NVCC (" TNL_STRINGIFY(__CUDACC_VER_MAJOR__) "." TNL_STRINGIFY(__CUDACC_VER_MINOR__) "." TNL_STRINGIFY(__CUDACC_VER_BUILD__) ")"; + #undef TNL_STRINGIFY +#elif defined(__clang__) + const char* compiler_name = "Clang/LLVM (" __VERSION__ ")"; +#elif defined(__ICC) || defined(__INTEL_COMPILER) + const char* compiler_name = "Intel ICPC (" __VERSION__ ")"; +#elif defined(__GNUC__) || defined(__GNUG__) + const char* compiler_name = "GNU G++ (" __VERSION__ ")"; +#else + const char* compiler_name = "(unknown)"; +#endif + logger.writeParameter< String >( "Host name:", getHostname() ); logger.writeParameter< String >( "System:", getSystemName() ); logger.writeParameter< String >( "Release:", getSystemRelease() ); logger.writeParameter< String >( "Architecture:", getArchitecture() ); - logger.writeParameter< char* >( "TNL Compiler:", ( char* ) TNL_CPP_COMPILER_NAME ); + logger.writeParameter< String >( "TNL compiler:", compiler_name ); // FIXME: generalize for multi-socket systems, here we consider only the first found CPU const int cpu_id = 0; const int threads = getNumberOfThreads( cpu_id ); diff --git a/tnlConfig.h.in b/tnlConfig.h.in index 967ce8e26..eed3c525f 100644 --- a/tnlConfig.h.in +++ b/tnlConfig.h.in @@ -9,5 +9,3 @@ @HAVE_PNG_H@ @HAVE_JPEG_H@ - -#define TNL_CPP_COMPILER_NAME "@CMAKE_CXX_COMPILER_ID@ @CMAKE_CXX_COMPILER_VERSION@" -- GitLab From 17a72aeba29fba358223ac154ba3578a4743bd87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sun, 21 Oct 2018 15:37:14 +0200 Subject: [PATCH 02/39] Using std::chrono for real time measurement --- CMakeLists.txt | 12 ------------ src/TNL/Timer.cpp | 33 ++++++++++++++------------------- src/TNL/Timer.h | 24 ++++++++++++++---------- tnlConfig.h.in | 2 -- 4 files changed, 28 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8784170f8..2f2f672df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -312,18 +312,6 @@ endif() #### # Check for some system header # -find_path( SYS_TIME_INCLUDE_DIR sys/time.h - /usr/include/x86_64-linux-gnu - /usr/include - DOC "System timer headers." ) -if( ${SYS_TIME_INCLUDE_DIR} STREQUAL "SYS_TIME_INCLUDE_DIR-NOTFOUND" ) - message( "Missing header file sys/time.h" ) - set( HAVE_SYS_TIME_H "//#define HAVE_SYS_TIME_H 1" ) -else() - #include_directories( ${SYS_TIME_INCLUDE_DIR} ) - set( HAVE_SYS_TIME_H "#define HAVE_SYS_TIME_H 1" ) -endif() - find_path( SYS_RESOURCE_INCLUDE_DIR sys/resource.h /usr/include/x86_64-linux-gnu /usr/include diff --git a/src/TNL/Timer.cpp b/src/TNL/Timer.cpp index 2d11949ed..7e454722e 100644 --- a/src/TNL/Timer.cpp +++ b/src/TNL/Timer.cpp @@ -15,11 +15,6 @@ #ifdef HAVE_SYS_RESOURCE_H #include #endif -#ifdef HAVE_SYS_TIME_H - #include - #include - #define HAVE_TIME -#endif namespace TNL { @@ -34,8 +29,8 @@ void Timer::reset() { this->initialCPUTime = 0; this->totalCPUTime = 0.0; - this->initialRealTime = 0; - this->totalRealTime = 0.0; + this->initialRealTime = TimePoint(); + this->totalRealTime = Duration(); this->initialCPUCycles = 0; this->totalCPUCycles = 0; this->stopState = true; @@ -64,33 +59,27 @@ void Timer::start() double Timer::getRealTime() const { if( ! this->stopState ) - return this->readRealTime() - this->initialRealTime; - return this->totalRealTime; + return durationToDouble( this->readRealTime() - this->initialRealTime ); + return durationToDouble( this->totalRealTime ); } double Timer::getCPUTime() const { if( ! this->stopState ) - return this->readCPUTime() - this->initialCPUTime; + return this->readCPUTime() - this->initialCPUTime; return this->totalCPUTime; } unsigned long long int Timer::getCPUCycles() const { if( ! this->stopState ) - return this->readCPUCycles() - this->initialCPUCycles; + return this->readCPUCycles() - this->initialCPUCycles; return this->totalCPUCycles; } -double Timer::readRealTime() const +typename Timer::TimePoint Timer::readRealTime() const { -#ifdef HAVE_TIME - struct timeval tp; - int rtn = gettimeofday( &tp, NULL ); - return ( double ) tp. tv_sec + 1.0e-6 * ( double ) tp. tv_usec; -#else - return -1; -#endif + return std::chrono::high_resolution_clock::now(); } double Timer::readCPUTime() const @@ -109,6 +98,12 @@ unsigned long long int Timer::readCPUCycles() const return this->rdtsc(); } +double Timer::durationToDouble( const Duration& duration ) const +{ + std::chrono::duration< double > dur( duration ); + return dur.count(); +} + bool Timer::writeLog( Logger& logger, int logLevel ) const { diff --git a/src/TNL/Timer.h b/src/TNL/Timer.h index a2e01ea8e..530dcae21 100644 --- a/src/TNL/Timer.h +++ b/src/TNL/Timer.h @@ -8,9 +8,10 @@ /* See Copyright Notice in tnl/Copyright */ - #pragma once +#include + namespace TNL { class Logger; @@ -88,13 +89,14 @@ class Timer /// \param logger Name of Logger object. /// \param logLevel A non-negative integer recording the log record indent. bool writeLog( Logger& logger, int logLevel = 0 ) const; - + protected: + using TimePoint = typename std::chrono::high_resolution_clock::time_point; + using Duration = typename std::chrono::high_resolution_clock::duration; + /// \brief Function for measuring the real time. - /// - /// Returns number of seconds since Epoch, 1970-01-01 00:00:00 UTC. - double readRealTime() const; + TimePoint readRealTime() const; /// \brief Function for measuring the CPU time. /// @@ -104,11 +106,14 @@ class Timer /// \brief Function for counting the number of CPU cycles (machine cycles). unsigned long long int readCPUCycles() const; - - double initialRealTime, totalRealTime, - initialCPUTime, totalCPUTime; - + double durationToDouble( const Duration& duration ) const; + + TimePoint initialRealTime; + Duration totalRealTime; + + double initialCPUTime, totalCPUTime; + unsigned long long int initialCPUCycles, totalCPUCycles; /// \brief Saves information about the state of given timer. @@ -127,7 +132,6 @@ class Timer } }; -// !!! Odstranit ???!!! extern Timer defaultTimer; } // namespace TNL diff --git a/tnlConfig.h.in b/tnlConfig.h.in index eed3c525f..ca548696a 100644 --- a/tnlConfig.h.in +++ b/tnlConfig.h.in @@ -1,5 +1,3 @@ -@HAVE_SYS_TIME_H@ - @HAVE_SYS_RESOURCE_H@ @HAVE_SYS_IOCTL_H@ -- GitLab From 89be2b7c240b35c48c28512b96275f6b647af7bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sun, 21 Oct 2018 15:51:01 +0200 Subject: [PATCH 03/39] Removed useless checks for sys/resource.h and sys/ioctl.h They are part of POSIX so they should work on anything but Windows. This can be checked simply by a predefined macro, configuration during build is not necessary. See https://stackoverflow.com/a/4575466 for reference. --- CMakeLists.txt | 27 ------------------- src/TNL/Solvers/IterativeSolverMonitor_impl.h | 12 ++++----- src/TNL/Timer.cpp | 7 ++--- tnlConfig.h.in | 4 --- 4 files changed, 10 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f2f672df..fafed61af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -309,33 +309,6 @@ if( ${WITH_GMP} ) endif() endif() -#### -# Check for some system header -# -find_path( SYS_RESOURCE_INCLUDE_DIR sys/resource.h - /usr/include/x86_64-linux-gnu - /usr/include - DOC "System resources headers." ) -if( ${SYS_RESOURCE_INCLUDE_DIR} STREQUAL "SYS_RESOURCE_INCLUDE_DIR-NOTFOUND" ) - message( "Missing header file sys/time.h" ) - set( HAVE_SYS_RESOURCE_H "//#define HAVE_SYS_RESOURCE_H 1" ) -else() - #include_directories( ${SYS_RESOURCE_INCLUDE_DIR} ) - set( HAVE_SYS_RESOURCE_H "#define HAVE_SYS_RESOURCE_H 1" ) -endif() - -find_path( SYS_IOCTL_INCLUDE_DIR sys/ioctl.h - /usr/include/x86_64-linux-gnu - /usr/include - DOC "System ioctl headers." ) -if( ${SYS_IOCTL_INCLUDE_DIR} STREQUAL "SYS_IOCTL_INCLUDE_DIR-NOTFOUND" ) - message( "Missing header file sys/time.h" ) - set( HAVE_SYS_IOCTL_H "//#define HAVE_SYS_IOCTL_H 1" ) -else() - #include_directories( ${SYS_IOCTL_INCLUDE_DIR} ) - set( HAVE_SYS_IOCTL_H "#define HAVE_SYS_IOCTL_H 1" ) -endif() - if( ${WITH_TESTS} ) enable_testing() diff --git a/src/TNL/Solvers/IterativeSolverMonitor_impl.h b/src/TNL/Solvers/IterativeSolverMonitor_impl.h index 4cc1d1843..0343da3eb 100644 --- a/src/TNL/Solvers/IterativeSolverMonitor_impl.h +++ b/src/TNL/Solvers/IterativeSolverMonitor_impl.h @@ -13,11 +13,11 @@ #include #include -// make sure to include the config before the check -#include -#ifdef HAVE_SYS_IOCTL_H -#include -#include +// check if we are on a POSIX system or Windows, +// see https://stackoverflow.com/a/4575466 +#if !defined(_WIN32) && !defined(_WIN64) + #include + #include #endif #include @@ -190,7 +190,7 @@ void IterativeSolverMonitor< Real, Index > :: refresh() template< typename Real, typename Index> int IterativeSolverMonitor< Real, Index > :: getLineWidth() { -#ifdef HAVE_SYS_IOCTL_H +#if !defined(_WIN32) && !defined(_WIN64) struct winsize w; ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); return w.ws_col; diff --git a/src/TNL/Timer.cpp b/src/TNL/Timer.cpp index 7e454722e..e36493672 100644 --- a/src/TNL/Timer.cpp +++ b/src/TNL/Timer.cpp @@ -11,8 +11,9 @@ #include #include -#include -#ifdef HAVE_SYS_RESOURCE_H +// check if we are on a POSIX system or Windows, +// see https://stackoverflow.com/a/4575466 +#if !defined(_WIN32) && !defined(_WIN64) #include #endif @@ -84,7 +85,7 @@ typename Timer::TimePoint Timer::readRealTime() const double Timer::readCPUTime() const { -#ifdef HAVE_SYS_RESOURCE_H +#if !defined(_WIN32) && !defined(_WIN64) rusage initUsage; getrusage( RUSAGE_SELF, &initUsage ); return initUsage. ru_utime. tv_sec + 1.0e-6 * ( double ) initUsage. ru_utime. tv_usec; diff --git a/tnlConfig.h.in b/tnlConfig.h.in index ca548696a..fea4e189a 100644 --- a/tnlConfig.h.in +++ b/tnlConfig.h.in @@ -1,7 +1,3 @@ -@HAVE_SYS_RESOURCE_H@ - -@HAVE_SYS_IOCTL_H@ - @HAVE_DCMTK_H@ @HAVE_PNG_H@ -- GitLab From 674312d45958ad32dfa9889348797dee771cba88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sun, 21 Oct 2018 16:20:11 +0200 Subject: [PATCH 04/39] Removed the remaining autotools-like macros HAVE_*_H from tnlConfig.h TNL is not supposed to have any external dependencies, so an empty config file is useless. If some marginal parts of the project (such as code for image processing) need to depend on some non-standard library, they should be split into a separate module/project so that the dependencies can be properly specified. For now, the macros are specified as compiler parameters. Client software using the affected headers will have to do the same. --- CMakeLists.txt | 26 ++++--------------- .../tnl-benchmark-heat-equation.h | 1 - src/Examples/flow-sw/navierStokes.h | 1 - src/Examples/flow-vl/navierStokes.h | 1 - src/Examples/flow/navierStokes.h | 1 - src/Examples/inviscid-flow-sw/euler.h | 1 - src/Examples/inviscid-flow-vl/euler.h | 1 - src/Examples/inviscid-flow/3d/euler.h | 1 - src/Examples/inviscid-flow/euler.h | 1 - .../tnl-transport-equation-eoc.h | 1 - .../tnl-transport-equation.h | 1 - .../Algorithms/ArrayOperationsCuda_impl.h | 1 - .../Algorithms/ArrayOperationsHost_impl.h | 1 - .../Algorithms/ArrayOperationsMIC_impl.h | 1 - .../Algorithms/VectorOperationsCuda_impl.h | 1 - src/TNL/Devices/Cuda.cpp | 1 - src/TNL/Devices/SystemInfo.cpp | 3 +-- src/TNL/Images/CMakeLists.txt | 4 +-- src/TNL/Images/DicomHeader.h | 2 -- src/TNL/Images/DicomImageInfo.h | 2 -- src/TNL/Images/DicomPatientInfo.h | 1 - src/TNL/Images/DicomSeries.h | 1 - src/TNL/Images/DicomSeriesInfo.h | 1 - src/TNL/Images/JPEGImage.h | 2 -- src/TNL/Images/PNGImage.h | 2 -- src/TNL/Solvers/SolverConfig_impl.h | 1 - src/TNL/Solvers/SolverStarter_impl.h | 1 - src/Tools/tnl-dicom-reader.cpp | 2 +- tnlConfig.h.in | 5 ---- 29 files changed, 9 insertions(+), 59 deletions(-) delete mode 100644 tnlConfig.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index fafed61af..a0a015c03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,33 +249,20 @@ endif() find_package( DCMTK ) if( DCMTK_FOUND ) - set( HAVE_DCMTK_H "#define HAVE_DCMTK_H 1" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_DCMTK_H" ) include_directories( ${DCMTK_INCLUDE_DIRS} ) - set( HAVE_DCMTK TRUE) - set( DCMTK_LD_FLAGS "" ) - foreach( arg ${DCMTK_LIBRARIES} ) - set( DCMTK_LD_FLAGS "${DCMTK_LD_FLAGS} ${arg}" ) - endforeach( arg ${DCMTK_LIBRARIES} ) -else() - set( HAVE_DCMTK_H "//#define HAVE_DCMTK_H 1" ) endif() find_package( PNG ) -if( PNG_FOUND ) - set( HAVE_PNG_H "#define HAVE_PNG_H 1" ) +if( PNG_FOUND ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_PNG_H" ) include_directories( ${PNG_INCLUDE_DIRS} ) -else() - set( HAVE_PNG_H "//#define HAVE_PNG_H 1" ) - set( PNG_LIBRARIES "" ) endif() find_package( JPEG ) -if( JPEG_FOUND ) - set( HAVE_JPEG_H "#define HAVE_JPEG_H 1" ) +if( JPEG_FOUND ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_JPEG_H" ) include_directories( ${JPEG_INCLUDE_DIRS} ) -else() - set( HAVE_JPEG_H "//#define HAVE_JPEG_H 1" ) - set( JPEG_LIBRARIES "" ) endif() #### @@ -373,9 +360,6 @@ endif() # endif() #endif() -CONFIGURE_FILE( "tnlConfig.h.in" "${PROJECT_BUILD_PATH}/TNL/tnlConfig.h" ) -INSTALL( FILES ${PROJECT_BUILD_PATH}/TNL/tnlConfig.h DESTINATION ${TNL_TARGET_INCLUDE_DIRECTORY} ) - #Nastavime cesty k hlavickovym souborum a knihovnam INCLUDE_DIRECTORIES( src ) INCLUDE_DIRECTORIES( ${PROJECT_BUILD_PATH} ) diff --git a/src/Benchmarks/HeatEquation/tnl-benchmark-heat-equation.h b/src/Benchmarks/HeatEquation/tnl-benchmark-heat-equation.h index 1906508db..e0a3318c5 100644 --- a/src/Benchmarks/HeatEquation/tnl-benchmark-heat-equation.h +++ b/src/Benchmarks/HeatEquation/tnl-benchmark-heat-equation.h @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/src/Examples/flow-sw/navierStokes.h b/src/Examples/flow-sw/navierStokes.h index a298f14b2..0d37ad41c 100644 --- a/src/Examples/flow-sw/navierStokes.h +++ b/src/Examples/flow-sw/navierStokes.h @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/src/Examples/flow-vl/navierStokes.h b/src/Examples/flow-vl/navierStokes.h index a298f14b2..0d37ad41c 100644 --- a/src/Examples/flow-vl/navierStokes.h +++ b/src/Examples/flow-vl/navierStokes.h @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/src/Examples/flow/navierStokes.h b/src/Examples/flow/navierStokes.h index 8d60667fe..5b37345bc 100644 --- a/src/Examples/flow/navierStokes.h +++ b/src/Examples/flow/navierStokes.h @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/src/Examples/inviscid-flow-sw/euler.h b/src/Examples/inviscid-flow-sw/euler.h index 9248d901f..75279e605 100644 --- a/src/Examples/inviscid-flow-sw/euler.h +++ b/src/Examples/inviscid-flow-sw/euler.h @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/src/Examples/inviscid-flow-vl/euler.h b/src/Examples/inviscid-flow-vl/euler.h index 9248d901f..75279e605 100644 --- a/src/Examples/inviscid-flow-vl/euler.h +++ b/src/Examples/inviscid-flow-vl/euler.h @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/src/Examples/inviscid-flow/3d/euler.h b/src/Examples/inviscid-flow/3d/euler.h index d5550d0c7..3160fe898 100644 --- a/src/Examples/inviscid-flow/3d/euler.h +++ b/src/Examples/inviscid-flow/3d/euler.h @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/src/Examples/inviscid-flow/euler.h b/src/Examples/inviscid-flow/euler.h index 22c87ce0b..0bd0c6664 100644 --- a/src/Examples/inviscid-flow/euler.h +++ b/src/Examples/inviscid-flow/euler.h @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/src/Examples/transport-equation/tnl-transport-equation-eoc.h b/src/Examples/transport-equation/tnl-transport-equation-eoc.h index fc2eda333..dbf7610ef 100644 --- a/src/Examples/transport-equation/tnl-transport-equation-eoc.h +++ b/src/Examples/transport-equation/tnl-transport-equation-eoc.h @@ -9,7 +9,6 @@ /* See Copyright Notice in tnl/Copyright */ -#include #include #include #include diff --git a/src/Examples/transport-equation/tnl-transport-equation.h b/src/Examples/transport-equation/tnl-transport-equation.h index 7978de25a..9e669033a 100644 --- a/src/Examples/transport-equation/tnl-transport-equation.h +++ b/src/Examples/transport-equation/tnl-transport-equation.h @@ -8,7 +8,6 @@ /* See Copyright Notice in tnl/Copyright */ -#include #include #include #include diff --git a/src/TNL/Containers/Algorithms/ArrayOperationsCuda_impl.h b/src/TNL/Containers/Algorithms/ArrayOperationsCuda_impl.h index 9a87b5287..34946628a 100644 --- a/src/TNL/Containers/Algorithms/ArrayOperationsCuda_impl.h +++ b/src/TNL/Containers/Algorithms/ArrayOperationsCuda_impl.h @@ -13,7 +13,6 @@ #include #include -#include #include #include #include diff --git a/src/TNL/Containers/Algorithms/ArrayOperationsHost_impl.h b/src/TNL/Containers/Algorithms/ArrayOperationsHost_impl.h index c48d4b40b..18fe544ea 100644 --- a/src/TNL/Containers/Algorithms/ArrayOperationsHost_impl.h +++ b/src/TNL/Containers/Algorithms/ArrayOperationsHost_impl.h @@ -13,7 +13,6 @@ #include #include -#include #include #include #include diff --git a/src/TNL/Containers/Algorithms/ArrayOperationsMIC_impl.h b/src/TNL/Containers/Algorithms/ArrayOperationsMIC_impl.h index 0289c3c6c..1823d8077 100644 --- a/src/TNL/Containers/Algorithms/ArrayOperationsMIC_impl.h +++ b/src/TNL/Containers/Algorithms/ArrayOperationsMIC_impl.h @@ -14,7 +14,6 @@ #include -#include #include #include #include diff --git a/src/TNL/Containers/Algorithms/VectorOperationsCuda_impl.h b/src/TNL/Containers/Algorithms/VectorOperationsCuda_impl.h index 02d4329e1..438e74328 100644 --- a/src/TNL/Containers/Algorithms/VectorOperationsCuda_impl.h +++ b/src/TNL/Containers/Algorithms/VectorOperationsCuda_impl.h @@ -10,7 +10,6 @@ #pragma once -#include #include #include #include diff --git a/src/TNL/Devices/Cuda.cpp b/src/TNL/Devices/Cuda.cpp index 9dc2ff9d0..b9ff1aeae 100644 --- a/src/TNL/Devices/Cuda.cpp +++ b/src/TNL/Devices/Cuda.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include #include diff --git a/src/TNL/Devices/SystemInfo.cpp b/src/TNL/Devices/SystemInfo.cpp index 60606204c..9eacd856b 100644 --- a/src/TNL/Devices/SystemInfo.cpp +++ b/src/TNL/Devices/SystemInfo.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -252,7 +251,7 @@ size_t SystemInfo::getFreeMemory() long pages = sysconf(_SC_PHYS_PAGES); long page_size = sysconf(_SC_PAGE_SIZE); return pages * page_size; -}; +} } // namespace Devices } // namespace TNL diff --git a/src/TNL/Images/CMakeLists.txt b/src/TNL/Images/CMakeLists.txt index 9ffbdc0a0..d7a46f402 100644 --- a/src/TNL/Images/CMakeLists.txt +++ b/src/TNL/Images/CMakeLists.txt @@ -24,7 +24,7 @@ SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL/Images ) # DCMTK currently does not support shared libraries. When it does _impl.h files # could be replaced with .cpp and DCMTK might be link with TNL. # -if( HAVE_DCMTK ) +if( DCMTK_FOUND ) set( common_SOURCES ) else() set( common_SOURCES ) @@ -41,4 +41,4 @@ ELSE() ENDIF() -INSTALL( FILES ${headers} DESTINATION ${TNL_TARGET_INCLUDE_DIRECTORY}/Images ) \ No newline at end of file +INSTALL( FILES ${headers} DESTINATION ${TNL_TARGET_INCLUDE_DIRECTORY}/Images ) diff --git a/src/TNL/Images/DicomHeader.h b/src/TNL/Images/DicomHeader.h index 89cf69ba7..64f2b324e 100644 --- a/src/TNL/Images/DicomHeader.h +++ b/src/TNL/Images/DicomHeader.h @@ -13,8 +13,6 @@ #pragma once -#include - #ifdef HAVE_DCMTK_H #define HAVE_CONFIG_H #include diff --git a/src/TNL/Images/DicomImageInfo.h b/src/TNL/Images/DicomImageInfo.h index 989f68626..1d5f10191 100644 --- a/src/TNL/Images/DicomImageInfo.h +++ b/src/TNL/Images/DicomImageInfo.h @@ -13,8 +13,6 @@ #pragma once -#include - #ifdef HAVE_DCMTK_H #define HAVE_CONFIG_H #include diff --git a/src/TNL/Images/DicomPatientInfo.h b/src/TNL/Images/DicomPatientInfo.h index 73b3128e8..02b80638e 100644 --- a/src/TNL/Images/DicomPatientInfo.h +++ b/src/TNL/Images/DicomPatientInfo.h @@ -14,7 +14,6 @@ #pragma once #include -#include #ifdef HAVE_DCMTK_H #define HAVE_CONFIG_H diff --git a/src/TNL/Images/DicomSeries.h b/src/TNL/Images/DicomSeries.h index b3ee1fb11..36e626ab6 100644 --- a/src/TNL/Images/DicomSeries.h +++ b/src/TNL/Images/DicomSeries.h @@ -22,7 +22,6 @@ #include #include #include -#include #ifdef HAVE_DCMTK_H #define USING_STD_NAMESPACE diff --git a/src/TNL/Images/DicomSeriesInfo.h b/src/TNL/Images/DicomSeriesInfo.h index b097a469a..6f30a48f3 100644 --- a/src/TNL/Images/DicomSeriesInfo.h +++ b/src/TNL/Images/DicomSeriesInfo.h @@ -14,7 +14,6 @@ #pragma once #include -#include #ifdef HAVE_DCMTK_H #define HAVE_CONFIG_H diff --git a/src/TNL/Images/JPEGImage.h b/src/TNL/Images/JPEGImage.h index 637555117..3659ab243 100644 --- a/src/TNL/Images/JPEGImage.h +++ b/src/TNL/Images/JPEGImage.h @@ -10,8 +10,6 @@ #pragma once -#include - #ifdef HAVE_JPEG_H #include #endif diff --git a/src/TNL/Images/PNGImage.h b/src/TNL/Images/PNGImage.h index f384c947c..3c930a5c8 100644 --- a/src/TNL/Images/PNGImage.h +++ b/src/TNL/Images/PNGImage.h @@ -10,8 +10,6 @@ #pragma once -#include - #ifdef HAVE_PNG_H #include #endif diff --git a/src/TNL/Solvers/SolverConfig_impl.h b/src/TNL/Solvers/SolverConfig_impl.h index 598cee285..701c5eb73 100644 --- a/src/TNL/Solvers/SolverConfig_impl.h +++ b/src/TNL/Solvers/SolverConfig_impl.h @@ -10,7 +10,6 @@ #pragma once -#include #include #include #include diff --git a/src/TNL/Solvers/SolverStarter_impl.h b/src/TNL/Solvers/SolverStarter_impl.h index f848b774b..016622677 100644 --- a/src/TNL/Solvers/SolverStarter_impl.h +++ b/src/TNL/Solvers/SolverStarter_impl.h @@ -10,7 +10,6 @@ #pragma once -#include #include #include #include diff --git a/src/Tools/tnl-dicom-reader.cpp b/src/Tools/tnl-dicom-reader.cpp index 5b38b1230..55a66b7a6 100644 --- a/src/Tools/tnl-dicom-reader.cpp +++ b/src/Tools/tnl-dicom-reader.cpp @@ -8,7 +8,6 @@ /* See Copyright Notice in tnl/Copyright */ -#include #include #include #include @@ -105,5 +104,6 @@ int main( int argc, char* argv[] ) return EXIT_SUCCESS; #else std::cerr << "TNL was not compiled with DCMTK support." << std::endl; + return EXIT_FAILURE; #endif } diff --git a/tnlConfig.h.in b/tnlConfig.h.in deleted file mode 100644 index fea4e189a..000000000 --- a/tnlConfig.h.in +++ /dev/null @@ -1,5 +0,0 @@ -@HAVE_DCMTK_H@ - -@HAVE_PNG_H@ - -@HAVE_JPEG_H@ -- GitLab From 69488aac9b5089a7469419b3f98cbf1a87d46cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sun, 21 Oct 2018 16:39:23 +0200 Subject: [PATCH 05/39] Moved Cuda::configSetup and Cuda::setup from Cuda.cpp to Cuda_impl.h This will fix the bugs described in the FIXME notes. Compilation fails due to cyclic dependency between the headers, it will be fixed later. --- src/TNL/Devices/Cuda.cpp | 30 ------------------------------ src/TNL/Devices/Cuda_impl.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/TNL/Devices/Cuda.cpp b/src/TNL/Devices/Cuda.cpp index b9ff1aeae..24a007e21 100644 --- a/src/TNL/Devices/Cuda.cpp +++ b/src/TNL/Devices/Cuda.cpp @@ -10,8 +10,6 @@ #include #include -#include -#include #include namespace TNL { @@ -37,34 +35,6 @@ int Cuda::getNumberOfGrids( const int blocks, return roundUpDivision( blocks, gridSize ); } -void Cuda::configSetup( Config::ConfigDescription& config, - const String& prefix ) -{ -// FIXME: HAVE_CUDA is never defined in .cpp files -#ifdef HAVE_CUDA - config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device to run the computation.", 0 ); -#else - config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device to run the computation (not supported on this system).", 0 ); -#endif -} - -bool Cuda::setup( const Config::ParameterContainer& parameters, - const String& prefix ) -{ -// FIXME: HAVE_CUDA is never defined in .cpp files -#ifdef HAVE_CUDA - int cudaDevice = parameters.getParameter< int >( prefix + "cuda-device" ); - if( cudaSetDevice( cudaDevice ) != cudaSuccess ) - { - std::cerr << "I cannot activate CUDA device number " << cudaDevice << "." << std::endl; - return false; - } - smartPointersSynchronizationTimer.reset(); - smartPointersSynchronizationTimer.stop(); -#endif - return true; -} - void Cuda::insertSmartPointer( SmartPointer* pointer ) { smartPointersRegister.insert( pointer, Devices::CudaDeviceInfo::getActiveDevice() ); diff --git a/src/TNL/Devices/Cuda_impl.h b/src/TNL/Devices/Cuda_impl.h index e0b9c52a5..f697cc87d 100644 --- a/src/TNL/Devices/Cuda_impl.h +++ b/src/TNL/Devices/Cuda_impl.h @@ -14,6 +14,8 @@ #include #include #include +#include +#include namespace TNL { namespace Devices { @@ -160,6 +162,34 @@ __device__ Element* Cuda::getSharedMemory() return CudaSharedMemory< Element >(); } +inline void +Cuda::configSetup( Config::ConfigDescription& config, + const String& prefix ) +{ +#ifdef HAVE_CUDA + config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device to run the computation.", 0 ); +#else + config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device to run the computation (not supported on this system).", 0 ); +#endif +} + +inline bool +Cuda::setup( const Config::ParameterContainer& parameters, + const String& prefix ) +{ +#ifdef HAVE_CUDA + int cudaDevice = parameters.getParameter< int >( prefix + "cuda-device" ); + if( cudaSetDevice( cudaDevice ) != cudaSuccess ) + { + std::cerr << "I cannot activate CUDA device number " << cudaDevice << "." << std::endl; + return false; + } + smartPointersSynchronizationTimer.reset(); + smartPointersSynchronizationTimer.stop(); +#endif + return true; +} + // double-precision atomicAdd function for Maxwell and older GPUs // copied from: https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#atomic-functions #if __CUDA_ARCH__ < 600 -- GitLab From 07d4cb49d33d6ef2d4c751febc3f79702d7d0811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sun, 21 Oct 2018 16:57:11 +0200 Subject: [PATCH 06/39] Moved everything from Cuda.cpp and Cuda.cu into Cuda_impl.h Having 4 different files (Cuda.h, Cuda_impl.h, Cuda.cpp, Cuda.cu) for one class is not clear at all. On a related note, a class with 28 methods is clearly too long to be considered as well-designed, so it should be split into several subclasses. Obviously, the full CUDA support cannot be provided/wrapped by a single class so the design should be more flexible. --- src/TNL/Devices/CMakeLists.txt | 2 - src/TNL/Devices/Cuda.cpp | 64 ----------- src/TNL/Devices/Cuda.cu | 119 -------------------- src/TNL/Devices/Cuda.h | 50 +++++---- src/TNL/Devices/Cuda_impl.h | 195 ++++++++++++++++++++++++++++++--- 5 files changed, 204 insertions(+), 226 deletions(-) delete mode 100644 src/TNL/Devices/Cuda.cpp delete mode 100644 src/TNL/Devices/Cuda.cu diff --git a/src/TNL/Devices/CMakeLists.txt b/src/TNL/Devices/CMakeLists.txt index dbb88eede..7f8b25120 100644 --- a/src/TNL/Devices/CMakeLists.txt +++ b/src/TNL/Devices/CMakeLists.txt @@ -8,7 +8,6 @@ set (headers Cuda.h SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL/Devices ) set( common_SOURCES - ${CURRENT_DIR}/Cuda.cpp ${CURRENT_DIR}/Host.cpp ${CURRENT_DIR}/MIC.cpp ${CURRENT_DIR}/SystemInfo.cpp ) @@ -16,7 +15,6 @@ set( common_SOURCES IF( BUILD_CUDA ) set( tnl_devices_CUDA__SOURCES ${common_SOURCES} - ${CURRENT_DIR}/Cuda.cu ${CURRENT_DIR}/CudaDeviceInfo.cu PARENT_SCOPE ) ENDIF() diff --git a/src/TNL/Devices/Cuda.cpp b/src/TNL/Devices/Cuda.cpp deleted file mode 100644 index 24a007e21..000000000 --- a/src/TNL/Devices/Cuda.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - Cuda.cpp - description - ------------------- - begin : Jul 11, 2013 - copyright : (C) 2013 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#include -#include -#include - -namespace TNL { -namespace Devices { - -SmartPointersRegister Cuda::smartPointersRegister; -Timer Cuda::smartPointersSynchronizationTimer; - -String Cuda::getDeviceType() -{ - return String( "Devices::Cuda" ); -} - -int Cuda::getNumberOfBlocks( const int threads, - const int blockSize ) -{ - return roundUpDivision( threads, blockSize ); -} - -int Cuda::getNumberOfGrids( const int blocks, - const int gridSize ) -{ - return roundUpDivision( blocks, gridSize ); -} - -void Cuda::insertSmartPointer( SmartPointer* pointer ) -{ - smartPointersRegister.insert( pointer, Devices::CudaDeviceInfo::getActiveDevice() ); -} - -void Cuda::removeSmartPointer( SmartPointer* pointer ) -{ - smartPointersRegister.remove( pointer, Devices::CudaDeviceInfo::getActiveDevice() ); -} - -bool Cuda::synchronizeDevice( int deviceId ) -{ -#ifdef HAVE_CUDA_UNIFIED_MEMORY - return true; -#else - if( deviceId < 0 ) - deviceId = Devices::CudaDeviceInfo::getActiveDevice(); - smartPointersSynchronizationTimer.start(); - bool b = smartPointersRegister.synchronizeDevice( deviceId ); - smartPointersSynchronizationTimer.stop(); - return b; -#endif -} - -} // namespace Devices -} // namespace TNL - diff --git a/src/TNL/Devices/Cuda.cu b/src/TNL/Devices/Cuda.cu deleted file mode 100644 index c1e524833..000000000 --- a/src/TNL/Devices/Cuda.cu +++ /dev/null @@ -1,119 +0,0 @@ -/*************************************************************************** - Cuda.cu - description - ------------------- - begin : Dec 22, 2014 - copyright : (C) 2014 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#include -#include -#include -#include - -namespace TNL { -namespace Devices { - - -void Cuda::setupThreads( const dim3& blockSize, - dim3& blocksCount, - dim3& gridsCount, - long long int xThreads, - long long int yThreads, - long long int zThreads ) -{ - blocksCount.x = max( 1, xThreads / blockSize.x + ( xThreads % blockSize.x != 0 ) ); - blocksCount.y = max( 1, yThreads / blockSize.y + ( yThreads % blockSize.y != 0 ) ); - blocksCount.z = max( 1, zThreads / blockSize.z + ( zThreads % blockSize.z != 0 ) ); - - /**** - * TODO: Fix the following: - * I do not known how to get max grid size in kernels :( - * - * Also, this is very slow. */ - /*int currentDevice( 0 ); - cudaGetDevice( currentDevice ); - cudaDeviceProp properties; - cudaGetDeviceProperties( &properties, currentDevice ); - gridsCount.x = blocksCount.x / properties.maxGridSize[ 0 ] + ( blocksCount.x % properties.maxGridSize[ 0 ] != 0 ); - gridsCount.y = blocksCount.y / properties.maxGridSize[ 1 ] + ( blocksCount.y % properties.maxGridSize[ 1 ] != 0 ); - gridsCount.z = blocksCount.z / properties.maxGridSize[ 2 ] + ( blocksCount.z % properties.maxGridSize[ 2 ] != 0 ); - */ - gridsCount.x = blocksCount.x / getMaxGridSize() + ( blocksCount.x % getMaxGridSize() != 0 ); - gridsCount.y = blocksCount.y / getMaxGridSize() + ( blocksCount.y % getMaxGridSize() != 0 ); - gridsCount.z = blocksCount.z / getMaxGridSize() + ( blocksCount.z % getMaxGridSize() != 0 ); -} - -void Cuda::setupGrid( const dim3& blocksCount, - const dim3& gridsCount, - const dim3& gridIdx, - dim3& gridSize ) -{ - /* TODO: this is extremely slow!!!! - int currentDevice( 0 ); - cudaGetDevice( ¤tDevice ); - cudaDeviceProp properties; - cudaGetDeviceProperties( &properties, currentDevice );*/ - - /**** - * TODO: fix the following - if( gridIdx.x < gridsCount.x ) - gridSize.x = properties.maxGridSize[ 0 ]; - else - gridSize.x = blocksCount.x % properties.maxGridSize[ 0 ]; - - if( gridIdx.y < gridsCount.y ) - gridSize.y = properties.maxGridSize[ 1 ]; - else - gridSize.y = blocksCount.y % properties.maxGridSize[ 1 ]; - - if( gridIdx.z < gridsCount.z ) - gridSize.z = properties.maxGridSize[ 2 ]; - else - gridSize.z = blocksCount.z % properties.maxGridSize[ 2 ];*/ - - if( gridIdx.x < gridsCount.x - 1 ) - gridSize.x = getMaxGridSize(); - else - gridSize.x = blocksCount.x % getMaxGridSize(); - - if( gridIdx.y < gridsCount.y - 1 ) - gridSize.y = getMaxGridSize(); - else - gridSize.y = blocksCount.y % getMaxGridSize(); - - if( gridIdx.z < gridsCount.z - 1 ) - gridSize.z = getMaxGridSize(); - else - gridSize.z = blocksCount.z % getMaxGridSize(); -} - -void Cuda::printThreadsSetup( const dim3& blockSize, - const dim3& blocksCount, - const dim3& gridSize, - const dim3& gridsCount, - std::ostream& str ) -{ - str << "Block size: " << blockSize << std::endl - << " Blocks count: " << blocksCount << std::endl - << " Grid size: " << gridSize << std::endl - << " Grids count: " << gridsCount << std::endl; -} - - -void Cuda::checkDevice( const char* file_name, int line, cudaError error ) -{ - if( error != cudaSuccess ) - throw Exceptions::CudaRuntimeError( error, file_name, line ); -} - -std::ostream& operator << ( std::ostream& str, const dim3& d ) -{ - str << "( " << d.x << ", " << d.y << ", " << d.z << " )"; - return str; -} - -} // namespace Devices -} // namespace TNL diff --git a/src/TNL/Devices/Cuda.h b/src/TNL/Devices/Cuda.h index 123d3a96c..b352ec7d3 100644 --- a/src/TNL/Devices/Cuda.h +++ b/src/TNL/Devices/Cuda.h @@ -31,7 +31,12 @@ class Cuda { public: - static String getDeviceType(); + static inline String getDeviceType(); + + static inline void configSetup( Config::ConfigDescription& config, const String& prefix = "" ); + + static inline bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ); __cuda_callable__ static inline constexpr int getMaxGridSize(); @@ -66,16 +71,16 @@ class Cuda * number of the CUDA threads and the block size. * It is obsolete and it will be replaced by setupThreads. */ - static int getNumberOfBlocks( const int threads, - const int blockSize ); + static inline int getNumberOfBlocks( const int threads, + const int blockSize ); /**** * This functions helps to count number of CUDA grids depending on the * number of the CUDA blocks and maximum grid size. * It is obsolete and it will be replaced by setupThreads. */ - static int getNumberOfGrids( const int blocks, - const int gridSize = getMaxGridSize() ); + static inline int getNumberOfGrids( const int blocks, + const int gridSize = getMaxGridSize() ); #ifdef HAVE_CUDA /*! This method sets up gridSize and computes number of grids depending @@ -153,29 +158,24 @@ class Cuda * of calling cudaGetLastError() inside the method. * We recommend to use macro 'TNL_CHECK_CUDA_DEVICE' defined bellow. */ - static void checkDevice( const char* file_name, int line, cudaError error ); + static inline void checkDevice( const char* file_name, int line, cudaError error ); #else - static void checkDevice() {} + static inline void checkDevice() {} #endif - - static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ); - - static bool setup( const Config::ParameterContainer& parameters, - const String& prefix = "" ); - - static void insertSmartPointer( SmartPointer* pointer ); - - static void removeSmartPointer( SmartPointer* pointer ); - + + static inline void insertSmartPointer( SmartPointer* pointer ); + + static inline void removeSmartPointer( SmartPointer* pointer ); + // Negative deviceId means that CudaDeviceInfo::getActiveDevice will be // called to get the device ID. - static bool synchronizeDevice( int deviceId = -1 ); - - static Timer smartPointersSynchronizationTimer; - + static inline bool synchronizeDevice( int deviceId = -1 ); + + static inline Timer& getSmartPointersSynchronizationTimer(); + protected: - - static SmartPointersRegister smartPointersRegister; + + static inline SmartPointersRegister& getSmartPointersRegister(); }; #ifdef HAVE_CUDA @@ -185,7 +185,9 @@ class Cuda #endif #ifdef HAVE_CUDA -std::ostream& operator << ( std::ostream& str, const dim3& d ); +namespace { + std::ostream& operator << ( std::ostream& str, const dim3& d ); +} #endif #ifdef HAVE_CUDA diff --git a/src/TNL/Devices/Cuda_impl.h b/src/TNL/Devices/Cuda_impl.h index f697cc87d..861447cb8 100644 --- a/src/TNL/Devices/Cuda_impl.h +++ b/src/TNL/Devices/Cuda_impl.h @@ -10,9 +10,12 @@ #pragma once +#include #include +#include #include #include +#include #include #include #include @@ -20,6 +23,39 @@ namespace TNL { namespace Devices { +inline String Cuda::getDeviceType() +{ + return String( "Cuda" ); +} + +inline void +Cuda::configSetup( Config::ConfigDescription& config, + const String& prefix ) +{ +#ifdef HAVE_CUDA + config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device to run the computation.", 0 ); +#else + config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device to run the computation (not supported on this system).", 0 ); +#endif +} + +inline bool +Cuda::setup( const Config::ParameterContainer& parameters, + const String& prefix ) +{ +#ifdef HAVE_CUDA + int cudaDevice = parameters.getParameter< int >( prefix + "cuda-device" ); + if( cudaSetDevice( cudaDevice ) != cudaSuccess ) + { + std::cerr << "I cannot activate CUDA device number " << cudaDevice << "." << std::endl; + return false; + } + getSmartPointersSynchronizationTimer().reset(); + getSmartPointersSynchronizationTimer().stop(); +#endif + return true; +} + __cuda_callable__ inline constexpr int Cuda::getMaxGridSize() { @@ -71,6 +107,105 @@ __device__ inline int Cuda::getGlobalThreadIdx_z( const dim3& gridIdx ) } #endif +inline int Cuda::getNumberOfBlocks( const int threads, + const int blockSize ) +{ + return roundUpDivision( threads, blockSize ); +} + +inline int Cuda::getNumberOfGrids( const int blocks, + const int gridSize ) +{ + return roundUpDivision( blocks, gridSize ); +} + +#ifdef HAVE_CUDA +inline void Cuda::setupThreads( const dim3& blockSize, + dim3& blocksCount, + dim3& gridsCount, + long long int xThreads, + long long int yThreads, + long long int zThreads ) +{ + blocksCount.x = max( 1, xThreads / blockSize.x + ( xThreads % blockSize.x != 0 ) ); + blocksCount.y = max( 1, yThreads / blockSize.y + ( yThreads % blockSize.y != 0 ) ); + blocksCount.z = max( 1, zThreads / blockSize.z + ( zThreads % blockSize.z != 0 ) ); + + /**** + * TODO: Fix the following: + * I do not known how to get max grid size in kernels :( + * + * Also, this is very slow. */ + /*int currentDevice( 0 ); + cudaGetDevice( currentDevice ); + cudaDeviceProp properties; + cudaGetDeviceProperties( &properties, currentDevice ); + gridsCount.x = blocksCount.x / properties.maxGridSize[ 0 ] + ( blocksCount.x % properties.maxGridSize[ 0 ] != 0 ); + gridsCount.y = blocksCount.y / properties.maxGridSize[ 1 ] + ( blocksCount.y % properties.maxGridSize[ 1 ] != 0 ); + gridsCount.z = blocksCount.z / properties.maxGridSize[ 2 ] + ( blocksCount.z % properties.maxGridSize[ 2 ] != 0 ); + */ + gridsCount.x = blocksCount.x / getMaxGridSize() + ( blocksCount.x % getMaxGridSize() != 0 ); + gridsCount.y = blocksCount.y / getMaxGridSize() + ( blocksCount.y % getMaxGridSize() != 0 ); + gridsCount.z = blocksCount.z / getMaxGridSize() + ( blocksCount.z % getMaxGridSize() != 0 ); +} + +inline void Cuda::setupGrid( const dim3& blocksCount, + const dim3& gridsCount, + const dim3& gridIdx, + dim3& gridSize ) +{ + /* TODO: this is extremely slow!!!! + int currentDevice( 0 ); + cudaGetDevice( ¤tDevice ); + cudaDeviceProp properties; + cudaGetDeviceProperties( &properties, currentDevice );*/ + + /**** + * TODO: fix the following + if( gridIdx.x < gridsCount.x ) + gridSize.x = properties.maxGridSize[ 0 ]; + else + gridSize.x = blocksCount.x % properties.maxGridSize[ 0 ]; + + if( gridIdx.y < gridsCount.y ) + gridSize.y = properties.maxGridSize[ 1 ]; + else + gridSize.y = blocksCount.y % properties.maxGridSize[ 1 ]; + + if( gridIdx.z < gridsCount.z ) + gridSize.z = properties.maxGridSize[ 2 ]; + else + gridSize.z = blocksCount.z % properties.maxGridSize[ 2 ];*/ + + if( gridIdx.x < gridsCount.x - 1 ) + gridSize.x = getMaxGridSize(); + else + gridSize.x = blocksCount.x % getMaxGridSize(); + + if( gridIdx.y < gridsCount.y - 1 ) + gridSize.y = getMaxGridSize(); + else + gridSize.y = blocksCount.y % getMaxGridSize(); + + if( gridIdx.z < gridsCount.z - 1 ) + gridSize.z = getMaxGridSize(); + else + gridSize.z = blocksCount.z % getMaxGridSize(); +} + +inline void Cuda::printThreadsSetup( const dim3& blockSize, + const dim3& blocksCount, + const dim3& gridSize, + const dim3& gridsCount, + std::ostream& str ) +{ + str << "Block size: " << blockSize << std::endl + << " Blocks count: " << blocksCount << std::endl + << " Grid size: " << gridSize << std::endl + << " Grids count: " << gridsCount << std::endl; +} +#endif + template< typename ObjectType > ObjectType* Cuda::passToDevice( const ObjectType& object ) @@ -162,33 +297,59 @@ __device__ Element* Cuda::getSharedMemory() return CudaSharedMemory< Element >(); } -inline void -Cuda::configSetup( Config::ConfigDescription& config, - const String& prefix ) -{ #ifdef HAVE_CUDA - config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device to run the computation.", 0 ); +inline void Cuda::checkDevice( const char* file_name, int line, cudaError error ) +{ + if( error != cudaSuccess ) + throw Exceptions::CudaRuntimeError( error, file_name, line ); +} +#endif + +inline void Cuda::insertSmartPointer( SmartPointer* pointer ) +{ + getSmartPointersRegister().insert( pointer, Devices::CudaDeviceInfo::getActiveDevice() ); +} + +inline void Cuda::removeSmartPointer( SmartPointer* pointer ) +{ + getSmartPointersRegister().remove( pointer, Devices::CudaDeviceInfo::getActiveDevice() ); +} + +inline bool Cuda::synchronizeDevice( int deviceId ) +{ +#ifdef HAVE_CUDA_UNIFIED_MEMORY + return true; #else - config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device to run the computation (not supported on this system).", 0 ); + if( deviceId < 0 ) + deviceId = Devices::CudaDeviceInfo::getActiveDevice(); + getSmartPointersSynchronizationTimer().start(); + bool b = getSmartPointersRegister().synchronizeDevice( deviceId ); + getSmartPointersSynchronizationTimer().stop(); + return b; #endif } -inline bool -Cuda::setup( const Config::ParameterContainer& parameters, - const String& prefix ) +inline Timer& Cuda::getSmartPointersSynchronizationTimer() +{ + static Timer timer; + return timer; +} + +inline SmartPointersRegister& Cuda::getSmartPointersRegister() { + static SmartPointersRegister reg; + return reg; +} + #ifdef HAVE_CUDA - int cudaDevice = parameters.getParameter< int >( prefix + "cuda-device" ); - if( cudaSetDevice( cudaDevice ) != cudaSuccess ) +namespace { + std::ostream& operator << ( std::ostream& str, const dim3& d ) { - std::cerr << "I cannot activate CUDA device number " << cudaDevice << "." << std::endl; - return false; + str << "( " << d.x << ", " << d.y << ", " << d.z << " )"; + return str; } - smartPointersSynchronizationTimer.reset(); - smartPointersSynchronizationTimer.stop(); -#endif - return true; } +#endif // double-precision atomicAdd function for Maxwell and older GPUs // copied from: https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#atomic-functions -- GitLab From c29579e4af7bf92b5b3a448ed27114eddfde8736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sun, 21 Oct 2018 20:04:43 +0200 Subject: [PATCH 07/39] Removed unused file DefaultBasicTypesChecker.h --- src/TNL/Config/CMakeLists.txt | 1 - src/TNL/Config/DefaultBasicTypesChecker.h | 37 ----------------------- 2 files changed, 38 deletions(-) delete mode 100644 src/TNL/Config/DefaultBasicTypesChecker.h diff --git a/src/TNL/Config/CMakeLists.txt b/src/TNL/Config/CMakeLists.txt index ba12e2228..3e11699a7 100644 --- a/src/TNL/Config/CMakeLists.txt +++ b/src/TNL/Config/CMakeLists.txt @@ -6,7 +6,6 @@ SET( headers ConfigDelimiter.h ConfigDescription.h ParameterContainer.h - DefaultBasicTypesChecker.h ) SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL/Config ) diff --git a/src/TNL/Config/DefaultBasicTypesChecker.h b/src/TNL/Config/DefaultBasicTypesChecker.h deleted file mode 100644 index 01ba4126d..000000000 --- a/src/TNL/Config/DefaultBasicTypesChecker.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - tnlDefaultBasicTypesChecker.h - description - ------------------- - begin : Feb 24, 2013 - copyright : (C) 2013 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include -#include - -namespace TNL { -namespace Config { - -class tnlDefaultBasicTypesChecker -{ - public: - - static bool checkSupportedRealTypes( const String& realType, - const Config::ParameterContainer& parameters ); - - static bool checkSupportedIndexTypes( const String& indexType, - const Config::ParameterContainer& parameters ); - - static bool checkSupportedDevices( const String& device, - const Config::ParameterContainer& parameters ); -}; - -} // namespace Config -} // namespace TNL - -#include - -- GitLab From 25c05210fbc2869dec4332949f3d87755256695c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sun, 21 Oct 2018 23:49:33 +0200 Subject: [PATCH 08/39] Reimplemented Config::ConfigDescription and Config::ParameterContainer using std::vector instead of TNL::List This is much safer and simpler because it solves many problems due to cyclic inclusion of TNL headers. --- src/TNL/Communicators/MpiCommunicator.h | 2 + src/TNL/Config/ConfigDelimiter.h | 9 +- src/TNL/Config/ConfigDescription.cpp | 82 +++++++-------- src/TNL/Config/ConfigDescription.h | 133 ++++++++++++------------ src/TNL/Config/ConfigEntry.h | 65 ++++++------ src/TNL/Config/ConfigEntryBase.h | 19 ++-- src/TNL/Config/ConfigEntryList.h | 76 +++++++------- src/TNL/Config/ConfigEntryType.h | 19 ++-- src/TNL/Config/ParameterContainer.cpp | 59 ++--------- src/TNL/Config/ParameterContainer.h | 133 +++++++++++------------- src/TNL/Devices/Cuda.h | 10 +- src/TNL/Devices/Cuda_impl.h | 2 - src/TNL/Devices/SystemInfo.cpp | 1 + src/TNL/Solvers/SolverStarter_impl.h | 4 +- 14 files changed, 272 insertions(+), 342 deletions(-) diff --git a/src/TNL/Communicators/MpiCommunicator.h b/src/TNL/Communicators/MpiCommunicator.h index b3a3b2ce0..3df6a45a4 100644 --- a/src/TNL/Communicators/MpiCommunicator.h +++ b/src/TNL/Communicators/MpiCommunicator.h @@ -21,6 +21,8 @@ #include #endif +#include // getpid + #ifdef HAVE_CUDA #include diff --git a/src/TNL/Config/ConfigDelimiter.h b/src/TNL/Config/ConfigDelimiter.h index d96d7dffb..2c102c778 100644 --- a/src/TNL/Config/ConfigDelimiter.h +++ b/src/TNL/Config/ConfigDelimiter.h @@ -8,7 +8,9 @@ /* See Copyright Notice in tnl/Copyright */ -#pragma once +#pragma once + +#include namespace TNL { namespace Config { @@ -17,16 +19,13 @@ struct ConfigDelimiter : public ConfigEntryBase { ConfigDelimiter( const String& delimiter ) : ConfigEntryBase( "", delimiter, false ) - { - }; + {} bool isDelimiter() const { return true; }; String getEntryType() const { return ""; }; String getUIEntryType() const { return ""; }; - - //~ConfigDelimiter(){}; }; } //namespace Config diff --git a/src/TNL/Config/ConfigDescription.cpp b/src/TNL/Config/ConfigDescription.cpp index 6145103ef..e8859523c 100644 --- a/src/TNL/Config/ConfigDescription.cpp +++ b/src/TNL/Config/ConfigDescription.cpp @@ -10,31 +10,23 @@ #include #include +#include + #include #include namespace TNL { -namespace Config { - -ConfigDescription :: ConfigDescription() -: currentEntry( 0 ) -{ -} +namespace Config { -ConfigDescription :: ~ConfigDescription() -{ - entries.DeepEraseAll(); -} - -void ConfigDescription::printUsage( const char* program_name ) const +void +ConfigDescription:: +printUsage( const char* program_name ) const { std::cout << "Usage of: " << program_name << std::endl << std::endl; - int i, j; - //const int group_num = groups. getSize(); - const int entries_num = entries. getSize(); + const int entries_num = entries.size(); int max_name_length( 0 ); int max_type_length( 0 ); - for( j = 0; j < entries_num; j ++ ) + for( int j = 0; j < entries_num; j++ ) if( ! entries[ j ]->isDelimiter() ) { max_name_length = std::max( max_name_length, @@ -44,7 +36,7 @@ void ConfigDescription::printUsage( const char* program_name ) const } max_name_length += 2; // this is for '--' - for( j = 0; j < entries_num; j ++ ) + for( int j = 0; j < entries_num; j++ ) { if( entries[ j ]->isDelimiter() ) { @@ -81,11 +73,12 @@ void ConfigDescription::printUsage( const char* program_name ) const std::cout << std::endl; } -void Config::ConfigDescription :: addMissingEntries( Config::ParameterContainer& parameter_container ) const +void +ConfigDescription:: +addMissingEntries( Config::ParameterContainer& parameter_container ) const { - int i; - const int size = entries.getSize(); - for( i = 0; i < size; i ++ ) + const int size = entries.size(); + for( int i = 0; i < size; i++ ) { const char* entry_name = entries[ i ]->name.getString(); if( entries[ i ]->hasDefaultValue && @@ -93,57 +86,54 @@ void Config::ConfigDescription :: addMissingEntries( Config::ParameterContainer& { if( entries[ i ]->getEntryType() == "String" ) { - parameter_container. addParameter< String >( - entry_name, - ( ( ConfigEntry< String >* ) entries[ i ] ) -> defaultValue ); + ConfigEntry< String >& entry = dynamic_cast< ConfigEntry< String >& >( *entries[ i ] ); + parameter_container.addParameter< String >( entry_name, entry.defaultValue ); continue; } if( entries[ i ]->getEntryType() == "bool" ) { - parameter_container. addParameter< bool >( - entry_name, - ( ( ConfigEntry< bool >* ) entries[ i ] ) -> defaultValue ); + ConfigEntry< bool >& entry = dynamic_cast< ConfigEntry< bool >& >( *entries[ i ] ); + parameter_container.addParameter< bool >( entry_name, entry.defaultValue ); continue; } if( entries[ i ]->getEntryType() == "int" ) { - parameter_container. addParameter< int >( - entry_name, - ( ( ConfigEntry< int >* ) entries[ i ] ) -> defaultValue ); + ConfigEntry< int >& entry = dynamic_cast< ConfigEntry< int >& >( *entries[ i ] ); + parameter_container.addParameter< int >( entry_name, entry.defaultValue ); continue; } if( entries[ i ]->getEntryType() == "double" ) { - parameter_container. addParameter< double >( - entry_name, - ( ( ConfigEntry< double >* ) entries[ i ] ) -> defaultValue ); + ConfigEntry< double >& entry = dynamic_cast< ConfigEntry< double >& >( *entries[ i ] ); + parameter_container.addParameter< double >( entry_name, entry.defaultValue ); continue; } } } } -bool Config::ConfigDescription :: checkMissingEntries( Config::ParameterContainer& parameter_container, - bool printUsage, - const char* programName ) const +bool +Config::ConfigDescription:: +checkMissingEntries( Config::ParameterContainer& parameter_container, + bool printUsage, + const char* programName ) const { - int i; - const int size = entries. getSize(); - Containers::List< String > missingParameters; - for( i = 0; i < size; i ++ ) + const int size = entries.size(); + std::vector< std::string > missingParameters; + for( int i = 0; i < size; i++ ) { - const char* entry_name = entries[ i ] -> name. getString(); + const char* entry_name = entries[ i ] -> name.getString(); if( entries[ i ] -> required && - ! parameter_container. checkParameter( entry_name ) ) - missingParameters.Append( entry_name ); + ! parameter_container.checkParameter( entry_name ) ) + missingParameters.push_back( entry_name ); } - if( missingParameters.getSize() != 0 ) + if( missingParameters.size() > 0 ) { std::cerr << "Some mandatory parameters are misssing. They are listed at the end. " << std::endl; if( printUsage ) this->printUsage( programName ); - std::cerr << "Add the following missing parameters to the command line: " << std::endl << " "; - for( int i = 0; i < missingParameters.getSize(); i++ ) + std::cerr << "Add the following missing parameters to the command line: " << std::endl << " "; + for( int i = 0; i < (int) missingParameters.size(); i++ ) std::cerr << "--" << missingParameters[ i ] << " ... "; std::cerr << std::endl; return false; diff --git a/src/TNL/Config/ConfigDescription.h b/src/TNL/Config/ConfigDescription.h index 833e99a47..2f05be6dd 100644 --- a/src/TNL/Config/ConfigDescription.h +++ b/src/TNL/Config/ConfigDescription.h @@ -10,8 +10,23 @@ #pragma once +#include +#include + +// std::make_unique does not exist until C++14 +// https://stackoverflow.com/a/9657991 +#if __cplusplus < 201402L +namespace std { + template + std::unique_ptr make_unique( Args&& ...args ) + { + return std::unique_ptr( new T( std::forward(args)... ) ); + } +} +#endif + +#include #include -#include #include #include #include @@ -25,13 +40,7 @@ class ParameterContainer; class ConfigDescription { - public: - - /** - * \brief Basic constructor. - */ - ConfigDescription(); - +public: /** * \brief Adds new entry to the configuration description. * @@ -43,8 +52,8 @@ class ConfigDescription void addEntry( const String& name, const String& description ) { - currentEntry = new ConfigEntry< EntryType >( name, description, false ); - entries.Append( currentEntry ); + entries.push_back( std::make_unique< ConfigEntry< EntryType > >( name, description, false ) ); + currentEntry = entries.back().get(); } /** @@ -58,8 +67,8 @@ class ConfigDescription void addRequiredEntry( const String& name, const String& description ) { - currentEntry = new ConfigEntry< EntryType >( name, description, true ); - entries.Append( currentEntry ); + entries.push_back( std::make_unique< ConfigEntry< EntryType > >( name, description, true ) ); + currentEntry = entries.back().get(); } /** @@ -75,11 +84,8 @@ class ConfigDescription const String& description, const EntryType& defaultValue ) { - currentEntry = new ConfigEntry< EntryType >( name, - description, - false, - defaultValue ); - entries. Append( currentEntry ); + entries.push_back( std::make_unique< ConfigEntry< EntryType > >( name, description, false, defaultValue ) ); + currentEntry = entries.back().get(); } /** @@ -93,8 +99,8 @@ class ConfigDescription void addList( const String& name, const String& description ) { - currentEntry = new ConfigEntryList< EntryType >( name, description, false ); - entries.Append( currentEntry ); + entries.push_back( std::make_unique< ConfigEntryList< EntryType > >( name, description, false ) ); + currentEntry = entries.back().get(); } /** @@ -108,8 +114,8 @@ class ConfigDescription void addRequiredList( const String& name, const String& description ) { - currentEntry = new ConfigEntryList< EntryType >( name, description, true ); - entries.Append( currentEntry ); + entries.push_back( std::make_unique< ConfigEntryList< EntryType > >( name, description, true ) ); + currentEntry = entries.back().get(); } /** @@ -125,11 +131,8 @@ class ConfigDescription const String& description, const EntryType& defaultValue ) { - currentEntry = new ConfigEntryList< EntryType >( name, - description, - false, - defaultValue ); - entries. Append( currentEntry ); + entries.push_back( std::make_unique< ConfigEntryList< EntryType > >( name, description, false, defaultValue ) ); + currentEntry = entries.back().get(); } /** @@ -142,8 +145,9 @@ class ConfigDescription template< typename EntryType > void addEntryEnum( const EntryType& entryEnum ) { - TNL_ASSERT( this->currentEntry,); - ( ( ConfigEntry< EntryType >* ) currentEntry )->getEnumValues().Append( entryEnum ); + TNL_ASSERT_TRUE( this->currentEntry, "there is no current entry" ); + ConfigEntry< EntryType >& entry = dynamic_cast< ConfigEntry< EntryType >& >( *currentEntry ); + entry.getEnumValues().push_back( entryEnum ); } /** @@ -154,8 +158,9 @@ class ConfigDescription */ void addEntryEnum( const char* entryEnum ) { - TNL_ASSERT( this->currentEntry,); - ( ( ConfigEntry< String >* ) currentEntry )->getEnumValues().Append( String( entryEnum ) ); + TNL_ASSERT_TRUE( this->currentEntry, "there is no current entry" ); + ConfigEntry< String >& entry = dynamic_cast< ConfigEntry< String >& >( *currentEntry ); + entry.getEnumValues().push_back( String( entryEnum ) ); } /** @@ -165,8 +170,8 @@ class ConfigDescription */ void addDelimiter( const String& delimiter ) { - entries.Append( new ConfigDelimiter( delimiter ) ); - currentEntry = 0; + entries.push_back( std::make_unique< ConfigDelimiter >( delimiter ) ); + currentEntry = nullptr; } /** @@ -176,43 +181,46 @@ class ConfigDescription */ const ConfigEntryBase* getEntry( const String& name ) const { - for( int i = 0; i < entries.getSize(); i++ ) + const int entries_num = entries.size(); + for( int i = 0; i < entries_num; i++ ) if( entries[ i ]->name == name ) - return entries[ i ]; - return NULL; + return entries[ i ].get(); + return nullptr; } - + //! Returns empty string if given entry does not exist //const String getEntryType( const char* name ) const; //! Returns zero pointer if there is no default value - template< class T > const T* getDefaultValue( const String& name ) const + template< class T > + const T* getDefaultValue( const String& name ) const { - int i; - const int entries_num = entries. getSize(); - for( i = 0; i < entries_num; i ++ ) - if( entries[ i ] -> name == name ) - { - if( entries[ i ] -> hasDefaultValue ) - return ( ( ConfigEntry< T > * ) entries[ i ] ) -> default_value; - else return NULL; + const int entries_num = entries.size(); + for( int i = 0; i < entries_num; i++ ) + if( entries[ i ]->name == name ) { + if( entries[ i ]->hasDefaultValue ) { + const ConfigEntry< T >& entry = dynamic_cast< ConfigEntry< T >& >( *entries[ i ] ); + return entry->default_value; + } + return nullptr; } std::cerr << "Asking for the default value of unknown parameter." << std::endl; - return NULL; + return nullptr; } //! Returns zero pointer if there is no default value - template< class T > T* getDefaultValue( const String& name ) + template< class T > + T* getDefaultValue( const String& name ) { - int i; - const int entries_num = entries. getSize(); - for( i = 0; i < entries_num; i ++ ) - if( entries[ i ] -> name == name ) - { - if( entries[ i ] -> hasDefaultValue ) - return ( ( ConfigEntry< T > * ) entries[ i ] ) -> default_value; - else return NULL; + const int entries_num = entries.size(); + for( int i = 0; i < entries_num; i++ ) + if( entries[ i ] -> name == name ) { + if( entries[ i ] -> hasDefaultValue ) { + ConfigEntry< T >& entry = dynamic_cast< ConfigEntry< T >& >( *entries[ i ] ); + return entry->default_value; + } + return nullptr; } std::cerr << "Asking for the default value of unknown parameter." << std::endl; return NULL; @@ -243,19 +251,10 @@ class ConfigDescription //bool parseConfigDescription( const char* file_name ); - /** - * \brief Basic destructor. - */ - ~ConfigDescription(); - - protected: - - Containers::List< ConfigEntryBase* > entries; - - ConfigEntryBase* currentEntry; - +protected: + std::vector< std::unique_ptr< ConfigEntryBase > > entries; + ConfigEntryBase* currentEntry = nullptr; }; } //namespace Config } //namespace TNL - diff --git a/src/TNL/Config/ConfigEntry.h b/src/TNL/Config/ConfigEntry.h index 759a77ef3..1608a5b4b 100644 --- a/src/TNL/Config/ConfigEntry.h +++ b/src/TNL/Config/ConfigEntry.h @@ -8,10 +8,11 @@ /* See Copyright Notice in tnl/Copyright */ -#pragma once +#pragma once + +#include #include -#include namespace TNL { namespace Config { @@ -21,31 +22,31 @@ struct ConfigEntry : public ConfigEntryBase { EntryType defaultValue; - Containers::List< EntryType > enumValues; + std::vector< EntryType > enumValues; public: ConfigEntry( const String& name, - const String& description, - bool required ) - : ConfigEntryBase( name, - description, - required ) - { - hasDefaultValue = false; - } + const String& description, + bool required ) + : ConfigEntryBase( name, + description, + required ) + { + hasDefaultValue = false; + } ConfigEntry( const String& name, - const String& description, - bool required, - const EntryType& defaultValue) - : ConfigEntryBase( name, - description, - required ), - defaultValue( defaultValue ) - { - hasDefaultValue = true; - } + const String& description, + bool required, + const EntryType& defaultValue) + : ConfigEntryBase( name, + description, + required ), + defaultValue( defaultValue ) + { + hasDefaultValue = true; + } String getEntryType() const { @@ -62,34 +63,34 @@ struct ConfigEntry : public ConfigEntryBase return convertToString( defaultValue ); }; - Containers::List< EntryType >& getEnumValues() + std::vector< EntryType >& getEnumValues() { return this->enumValues; } bool hasEnumValues() const { - if( enumValues.getSize() != 0 ) + if( enumValues.size() > 0 ) return true; return false; } void printEnumValues() const { - std::cout << "- Can be: "; + std::cout << "- Can be: "; int i; - for( i = 0; i < enumValues.getSize() - 1; i++ ) - std::cout << enumValues[ i ] << ", "; - std::cout << enumValues[ i ]; - std::cout << " "; + for( i = 0; i < (int) enumValues.size() - 1; i++ ) + std::cout << enumValues[ i ] << ", "; + std::cout << enumValues[ i ]; + std::cout << " "; } bool checkValue( const EntryType& value ) const { - if( this->enumValues.getSize() != 0 ) + if( this->enumValues.size() > 0 ) { bool found( false ); - for( int i = 0; i < this->enumValues.getSize(); i++ ) + for( int i = 0; i < (int) this->enumValues.size(); i++ ) if( value == this->enumValues[ i ] ) { found = true; @@ -104,9 +105,7 @@ struct ConfigEntry : public ConfigEntryBase } } return true; - }; - - //~ConfigEntry(){}; + } }; } // namespace Config diff --git a/src/TNL/Config/ConfigEntryBase.h b/src/TNL/Config/ConfigEntryBase.h index f69729ef5..c6dc19fbf 100644 --- a/src/TNL/Config/ConfigEntryBase.h +++ b/src/TNL/Config/ConfigEntryBase.h @@ -11,7 +11,7 @@ #pragma once namespace TNL { -namespace Config { +namespace Config { struct ConfigEntryBase { @@ -24,26 +24,27 @@ struct ConfigEntryBase bool hasDefaultValue; ConfigEntryBase( const String& name, - const String& description, - bool required ) + const String& description, + bool required ) : name( name ), description( description ), required( required ), - hasDefaultValue( false ){} + hasDefaultValue( false ) + {} virtual String getEntryType() const = 0; virtual String getUIEntryType() const = 0; - virtual bool isDelimiter() const { return false; }; + virtual bool isDelimiter() const { return false; } - virtual String printDefaultValue() const { return "";}; + virtual String printDefaultValue() const { return ""; } - virtual bool hasEnumValues() const { return false; }; + virtual bool hasEnumValues() const { return false; } - virtual void printEnumValues() const {}; + virtual void printEnumValues() const {} - virtual ~ConfigEntryBase() {}; + virtual ~ConfigEntryBase() = default; }; } // namespace Config diff --git a/src/TNL/Config/ConfigEntryList.h b/src/TNL/Config/ConfigEntryList.h index e8fabf5c5..95879fa66 100644 --- a/src/TNL/Config/ConfigEntryList.h +++ b/src/TNL/Config/ConfigEntryList.h @@ -8,92 +8,92 @@ /* See Copyright Notice in tnl/Copyright */ -#pragma once +#pragma once + +#include #include -#include namespace TNL { -namespace Config { +namespace Config { template< typename EntryType > struct ConfigEntryList : public ConfigEntryBase { EntryType defaultValue; - Containers::List< EntryType > enumValues; + std::vector< EntryType > enumValues; public: ConfigEntryList( const String& name, - const String& description, - bool required ) - : ConfigEntryBase( name, - description, - required ) - { - hasDefaultValue = false; - } + const String& description, + bool required ) + : ConfigEntryBase( name, + description, + required ) + { + hasDefaultValue = false; + } ConfigEntryList( const String& name, - const String& description, - bool required, - const EntryType& defaultValue) - : ConfigEntryBase( name, - description, - required ), - defaultValue( defaultValue ) - { - hasDefaultValue = true; - - } + const String& description, + bool required, + const EntryType& defaultValue) + : ConfigEntryBase( name, + description, + required ), + defaultValue( defaultValue ) + { + hasDefaultValue = true; + } String getEntryType() const { - return TNL::getType< Containers::List< EntryType > >(); + return String("List< ") + TNL::getType< EntryType >() + " >"; } String getUIEntryType() const { - return TNL::Config::getUIEntryType< Containers::List< EntryType > >(); + return TNL::Config::getUIEntryType< std::vector< EntryType > >(); } String printDefaultValue() const { return convertToString( defaultValue ); - }; + } - Containers::List< EntryType >& getEnumValues() + std::vector< EntryType >& getEnumValues() { return this->enumValues; } bool hasEnumValues() const { - if( enumValues.getSize() != 0 ) + if( enumValues.size() > 0 ) return true; return false; } void printEnumValues() const { - std::cout << "- Can be: "; + std::cout << "- Can be: "; int i; - for( i = 0; i < enumValues.getSize() - 1; i++ ) - std::cout << enumValues[ i ] << ", "; - std::cout << enumValues[ i ]; - std::cout << " "; + for( i = 0; i < (int) enumValues.size() - 1; i++ ) + std::cout << enumValues[ i ] << ", "; + std::cout << enumValues[ i ]; + std::cout << " "; } - bool checkValue( const Containers::List< EntryType >& values ) const + bool checkValue( const std::vector< EntryType >& values ) const { - if( this->enumValues.getSize() != 0 ) + if( this->enumValues.size() != 0 ) { - for( int j = 0; j < values.getSize(); j++ ) + for( int j = 0; j < (int) values.size(); j++ ) { const EntryType& value = values[ j ]; bool found( false ); - for( int i = 0; i < this->enumValues.getSize(); i++ ) + for( int i = 0; i < (int) this->enumValues.size(); i++ ) if( value == this->enumValues[ i ] ) { found = true; @@ -109,7 +109,7 @@ struct ConfigEntryList : public ConfigEntryBase } } return true; - }; + } }; } // namespace Config diff --git a/src/TNL/Config/ConfigEntryType.h b/src/TNL/Config/ConfigEntryType.h index 4ba052d02..6c7b89299 100644 --- a/src/TNL/Config/ConfigEntryType.h +++ b/src/TNL/Config/ConfigEntryType.h @@ -8,9 +8,9 @@ /* See Copyright Notice in tnl/Copyright */ -#pragma once +#pragma once -#include +#include namespace TNL { namespace Config { @@ -23,10 +23,10 @@ template<> inline String getUIEntryType< bool >() { return "bool"; }; template<> inline String getUIEntryType< int >() { return "integer"; }; template<> inline String getUIEntryType< double >() { return "real"; }; -template<> inline String getUIEntryType< Containers::List< String > >() { return "list of string"; }; -template<> inline String getUIEntryType< Containers::List< bool > >() { return "list of bool"; }; -template<> inline String getUIEntryType< Containers::List< int > >() { return "list of integer"; }; -template<> inline String getUIEntryType< Containers::List< double > >() { return "list of real"; }; +template<> inline String getUIEntryType< std::vector< String > >() { return "list of string"; }; +template<> inline String getUIEntryType< std::vector< bool > >() { return "list of bool"; }; +template<> inline String getUIEntryType< std::vector< int > >() { return "list of integer"; }; +template<> inline String getUIEntryType< std::vector< double > >() { return "list of real"; }; struct ConfigEntryType { @@ -34,18 +34,19 @@ struct ConfigEntryType bool list_entry; - ConfigEntryType(){}; + ConfigEntryType() {} ConfigEntryType( const String& _basic_type, const bool _list_entry ) : basic_type( _basic_type ), - list_entry( _list_entry ){} + list_entry( _list_entry ) + {} void Reset() { basic_type. setString( 0 ); list_entry = false; - }; + } }; } // namespace Config diff --git a/src/TNL/Config/ParameterContainer.cpp b/src/TNL/Config/ParameterContainer.cpp index 1f01dfcf5..5329a8745 100644 --- a/src/TNL/Config/ParameterContainer.cpp +++ b/src/TNL/Config/ParameterContainer.cpp @@ -35,64 +35,17 @@ bool matob( const char* value, bool& ret_val ) return false; } -ParameterContainer:: -ParameterContainer() -{ -} - -bool -Config::ParameterContainer:: -addParameter( const String& name, - const String& value ) -{ - return parameters. Append( new tnlParameter< String >( name, TNL::getType< String >().getString(), String( value ) ) ); -} - -bool -Config::ParameterContainer:: -setParameter( const String& name, - const String& value ) -{ - int i; - for( i = 0; i < parameters. getSize(); i ++ ) - { - if( parameters[ i ] -> name == name ) - { - if( parameters[ i ] -> type == TNL::getType< String >() ) - { - ( ( tnlParameter< String > * ) parameters[ i ] )->value = value; - return true; - } - else - { - std::cerr << "Parameter " << name << " already exists with different type " - << parameters[ i ] -> type << " not " - << TNL::getType< String>() << std::endl; - abort(); - return false; - } - } - } - return addParameter( name, value ); -}; - bool Config::ParameterContainer:: checkParameter( const String& name ) const { - int i; - const int parameters_num = parameters. getSize(); - for( i = 0; i < parameters_num; i ++ ) - if( parameters[ i ] -> name == name ) return true; + const int size = parameters.size(); + for( int i = 0; i < size; i++ ) + if( parameters[ i ]->name == name ) + return true; return false; } -ParameterContainer:: -~ParameterContainer() -{ - parameters. DeepEraseAll(); -} - /*void ParameterContainer::MPIBcast( int root, MPI_Comm mpi_comm ) { #ifdef USE_MPI @@ -162,6 +115,8 @@ ParameterContainer:: #endif } */ + + bool parseCommandLine( int argc, char* argv[], const Config::ConfigDescription& config_description, @@ -221,7 +176,7 @@ parseCommandLine( int argc, char* argv[], integer_list = new Containers::List< int >; if( parsedEntryType[ 1 ] == "double" ) real_list = new Containers::List< double >; - + while( i < argc && ( ( argv[ i ] )[ 0 ] != '-' || ( atof( argv[ i ] ) < 0.0 && ( integer_list || real_list ) ) ) ) { const char* value = argv[ i ++ ]; diff --git a/src/TNL/Config/ParameterContainer.h b/src/TNL/Config/ParameterContainer.h index 4d36cb974..632865f0d 100644 --- a/src/TNL/Config/ParameterContainer.h +++ b/src/TNL/Config/ParameterContainer.h @@ -8,47 +8,47 @@ /* See Copyright Notice in tnl/Copyright */ -#pragma once +#pragma once + +#include +#include -#include #include #include //#include namespace TNL { -namespace Config { +namespace Config { -struct tnlParameterBase +struct ParameterBase { - tnlParameterBase( const String& _name, - const String& _type ) - : name( _name ), type( _type ){}; - + ParameterBase( const String& name, + const String& type ) + : name( name ), type( type ) + {} + String name, type; + // Virtual destructor is needed to avoid undefined behaviour when deleting the + // ParameterContainer::parameters vector, see https://stackoverflow.com/a/8752126 + virtual ~ParameterBase() = default; }; -template< class T > struct tnlParameter : public tnlParameterBase +template< class T > +struct Parameter : public ParameterBase { - tnlParameter( const String& _name, - const String& _type, - const T& val ) - : tnlParameterBase( _name, _type ), value( val ){}; + Parameter( const String& name, + const String& type, + const T& value ) + : ParameterBase( name, type ), value( value ) + {} T value; }; -//template< class T > const char* getType( const T& val ); - class ParameterContainer { - public: - - /** - * \brief Basic constructor. - */ - ParameterContainer(); - +public: /** * \brief Adds new parameter to the ParameterContainer. * @@ -56,11 +56,9 @@ class ParameterContainer * \param name Name of the new parameter. * \param value Value assigned to the parameter. */ - template< class T > bool addParameter( const String& name, - const T& value ); - + template< class T > bool addParameter( const String& name, - const String& value ); + const T& value ); /** * \brief Checks whether the parameter \e name already exists in ParameterContainer. @@ -76,11 +74,9 @@ class ParameterContainer * \param name Name of parameter. * \param value Value of type T assigned to the parameter. */ - template< class T > bool setParameter( const String& name, - const T& value ); - + template< class T > bool setParameter( const String& name, - const String& value ); + const T& value ); /** * \brief Checks whether the parameter \e name is given the \e value. @@ -96,22 +92,23 @@ class ParameterContainer * \par Example * \include ParameterContainerExample.cpp */ - template< class T > bool getParameter( const String& name, - T& value, - bool verbose = true ) const + template< class T > + bool getParameter( const String& name, + T& value, + bool verbose = true ) const { - int i; - const int size = parameters. getSize(); - for( i = 0; i < size; i ++ ) - if( parameters[ i ] -> name == name ) + for( int i = 0; i < (int) parameters.size(); i++ ) + if( parameters[ i ]->name == name ) { - value = ( ( tnlParameter< T >* ) parameters[ i ] ) -> value; + // dynamic_cast throws std::bad_cast if parameters[i] does not have the type Parameter + const Parameter< T >& parameter = dynamic_cast< Parameter< T >& >( *parameters[ i ] ); + value = parameter.value; return true; } if( verbose ) { std::cerr << "Missing parameter '" << name << "'." << std::endl; - throw(0); //PrintStackBacktrace; + throw 0; //PrintStackBacktrace; } return false; } @@ -121,30 +118,26 @@ class ParameterContainer * * \param name Name of parameter. */ - template< class T > const T& getParameter( const String& name ) const + template< class T > + T getParameter( const String& name ) const { - int i; - const int size = parameters. getSize(); - for( i = 0; i < size; i ++ ) - if( parameters[ i ] -> name == name ) - return ( ( tnlParameter< T >* ) parameters[ i ] ) -> value; + for( int i = 0; i < (int) parameters.size(); i++ ) + if( parameters[ i ]->name == name ) + { + // dynamic_cast throws std::bad_cast if parameters[i] does not have the type Parameter + const Parameter< T >& parameter = dynamic_cast< Parameter< T >& >( *parameters[ i ] ); + return parameter.value; + } std::cerr << "The program attempts to get unknown parameter " << name << std::endl; std::cerr << "Aborting the program." << std::endl; - abort(); + throw 0; } - - //! Broadcast to other nodes in MPI cluster - // void MPIBcast( int root, MPI_Comm mpi_comm = MPI_COMM_WORLD ); - - /** - * \brief Basic destructor. - */ - ~ParameterContainer(); - - protected: - Containers::List< tnlParameterBase* > parameters; + //! Broadcast to other nodes in MPI cluster + //void MPIBcast( int root, MPI_Comm mpi_comm = MPI_COMM_WORLD ); +protected: + std::vector< std::unique_ptr< ParameterBase > > parameters; }; bool parseCommandLine( int argc, char* argv[], @@ -157,7 +150,8 @@ bool ParameterContainer:: addParameter( const String& name, const T& value ) { - return parameters. Append( new tnlParameter< T >( name, TNL::getType< T >().getString(), value ) ); + parameters.push_back( std::make_unique< Parameter< T > >( name, TNL::getType< T >(), value ) ); + return true; }; template< class T > @@ -166,23 +160,18 @@ ParameterContainer:: setParameter( const String& name, const T& value ) { - int i; - for( i = 0; i < parameters. getSize(); i ++ ) - { - if( parameters[ i ] -> name == name ) - { - if( parameters[ i ] -> type == TNL::getType< T >() ) - { - ( ( tnlParameter< T > * ) parameters[ i ] ) -> value = value; + for( int i = 0; i < (int) parameters.size(); i++ ) { + if( parameters[ i ]->name == name ) { + if( parameters[ i ]->type == TNL::getType< T >() ) { + Parameter< T >& parameter = dynamic_cast< Parameter< T >& >( *parameters[ i ] ); + parameter.value = value; return true; } - else - { + else { std::cerr << "Parameter " << name << " already exists with different type " - << parameters[ i ] -> type << " not " - << TNL::getType< T >() << std::endl; - abort( ); - return false; + << parameters[ i ]->type << " not " + << TNL::getType< T >() << std::endl; + throw 0; } } } diff --git a/src/TNL/Devices/Cuda.h b/src/TNL/Devices/Cuda.h index b352ec7d3..088e67dd0 100644 --- a/src/TNL/Devices/Cuda.h +++ b/src/TNL/Devices/Cuda.h @@ -11,20 +11,16 @@ #pragma once #include -#include + #include #include #include #include #include +#include +#include namespace TNL { - -namespace Config { - class ConfigDescription; - class ParameterContainer; -} - namespace Devices { class Cuda diff --git a/src/TNL/Devices/Cuda_impl.h b/src/TNL/Devices/Cuda_impl.h index 861447cb8..210283563 100644 --- a/src/TNL/Devices/Cuda_impl.h +++ b/src/TNL/Devices/Cuda_impl.h @@ -17,8 +17,6 @@ #include #include #include -#include -#include namespace TNL { namespace Devices { diff --git a/src/TNL/Devices/SystemInfo.cpp b/src/TNL/Devices/SystemInfo.cpp index 9eacd856b..38f852301 100644 --- a/src/TNL/Devices/SystemInfo.cpp +++ b/src/TNL/Devices/SystemInfo.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include diff --git a/src/TNL/Solvers/SolverStarter_impl.h b/src/TNL/Solvers/SolverStarter_impl.h index 016622677..e52d03a4f 100644 --- a/src/TNL/Solvers/SolverStarter_impl.h +++ b/src/TNL/Solvers/SolverStarter_impl.h @@ -406,8 +406,8 @@ bool SolverStarter< ConfigTag > :: writeEpilog( std::ostream& str, const Solver& if( std::is_same< typename Solver::DeviceType, TNL::Devices::Cuda >::value ) { logger.writeParameter< const char* >( "GPU synchronization time:", "" ); - TNL::Devices::Cuda::smartPointersSynchronizationTimer.writeLog( logger, 1 ); - } + TNL::Devices::Cuda::getSmartPointersSynchronizationTimer().writeLog( logger, 1 ); + } logger.writeParameter< const char* >( "I/O time:", "" ); this->ioTimer.writeLog( logger, 1 ); logger.writeParameter< const char* >( "Total time:", "" ); -- GitLab From 985cfdf21259ad770420c9bb2f80786207a9b642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Mon, 22 Oct 2018 20:25:46 +0200 Subject: [PATCH 09/39] Benchmarks: replaced unsigned with int --- src/Benchmarks/BLAS/tnl-benchmark-blas.h | 10 +++++----- .../DistSpMV/tnl-benchmark-distributed-spmv.h | 4 ++-- .../LinearSolvers/tnl-benchmark-linear-solvers.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Benchmarks/BLAS/tnl-benchmark-blas.h b/src/Benchmarks/BLAS/tnl-benchmark-blas.h index 390b17279..49c624ac9 100644 --- a/src/Benchmarks/BLAS/tnl-benchmark-blas.h +++ b/src/Benchmarks/BLAS/tnl-benchmark-blas.h @@ -32,7 +32,7 @@ runBlasBenchmarks( Benchmark & benchmark, const std::size_t & minSize, const std::size_t & maxSize, const double & sizeStepFactor, - const unsigned & elementsPerRow ) + const int & elementsPerRow ) { const String precision = getType< Real >(); metadata["precision"] = precision; @@ -121,10 +121,10 @@ main( int argc, char* argv[] ) // const std::size_t maxSize = parameters.getParameter< std::size_t >( "max-size" ); const std::size_t minSize = parameters.getParameter< int >( "min-size" ); const std::size_t maxSize = parameters.getParameter< int >( "max-size" ); - const unsigned sizeStepFactor = parameters.getParameter< unsigned >( "size-step-factor" ); - const unsigned loops = parameters.getParameter< unsigned >( "loops" ); - const unsigned elementsPerRow = parameters.getParameter< unsigned >( "elements-per-row" ); - const unsigned verbose = parameters.getParameter< unsigned >( "verbose" ); + const int sizeStepFactor = parameters.getParameter< int >( "size-step-factor" ); + const int loops = parameters.getParameter< int >( "loops" ); + const int elementsPerRow = parameters.getParameter< int >( "elements-per-row" ); + const int verbose = parameters.getParameter< int >( "verbose" ); if( sizeStepFactor <= 1 ) { std::cerr << "The value of --size-step-factor must be greater than 1." << std::endl; diff --git a/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h b/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h index a3bd76753..73001e958 100644 --- a/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h +++ b/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h @@ -323,8 +323,8 @@ main( int argc, char* argv[] ) const String & logFileName = parameters.getParameter< String >( "log-file" ); const String & outputMode = parameters.getParameter< String >( "output-mode" ); - const unsigned loops = parameters.getParameter< unsigned >( "loops" ); - const unsigned verbose = (rank == 0) ? parameters.getParameter< unsigned >( "verbose" ) : 0; + const int loops = parameters.getParameter< int >( "loops" ); + const int verbose = (rank == 0) ? parameters.getParameter< int >( "verbose" ) : 0; // open log file auto mode = std::ios::out; diff --git a/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h b/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h index b766bd505..55211c4ed 100644 --- a/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h +++ b/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h @@ -546,8 +546,8 @@ main( int argc, char* argv[] ) const String & logFileName = parameters.getParameter< String >( "log-file" ); const String & outputMode = parameters.getParameter< String >( "output-mode" ); - const unsigned loops = parameters.getParameter< unsigned >( "loops" ); - const unsigned verbose = (rank == 0) ? parameters.getParameter< unsigned >( "verbose" ) : 0; + const int loops = parameters.getParameter< int >( "loops" ); + const int verbose = (rank == 0) ? parameters.getParameter< int >( "verbose" ) : 0; // open log file auto mode = std::ios::out; -- GitLab From 9714220cacd42ffc4f4f0f5aca6373dede912909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 26 Oct 2018 14:13:15 +0200 Subject: [PATCH 10/39] Moved stuff from SmartPointersRegister.cpp to SmartPointersRegister.h --- src/TNL/Pointers/CMakeLists.txt | 15 ------ src/TNL/Pointers/SmartPointersRegister.cpp | 53 ---------------------- src/TNL/Pointers/SmartPointersRegister.h | 35 ++++++++++++-- 3 files changed, 30 insertions(+), 73 deletions(-) delete mode 100644 src/TNL/Pointers/SmartPointersRegister.cpp diff --git a/src/TNL/Pointers/CMakeLists.txt b/src/TNL/Pointers/CMakeLists.txt index 6c69336cd..d1cd9c47f 100644 --- a/src/TNL/Pointers/CMakeLists.txt +++ b/src/TNL/Pointers/CMakeLists.txt @@ -7,20 +7,5 @@ SET( headers DevicePointer.h SmartPointersRegister.h UniquePointer.h ) - -SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL/Pointers ) -set( common_SOURCES - ${CURRENT_DIR}/SmartPointersRegister.cpp - ) - -SET( tnl_pointers_SOURCES - ${common_SOURCES} - PARENT_SCOPE ) - -if( BUILD_CUDA ) -SET( tnl_pointers_CUDA__SOURCES - ${common_SOURCES} - PARENT_SCOPE ) -endif() INSTALL( FILES ${headers} DESTINATION ${TNL_TARGET_INCLUDE_DIRECTORY}/Pointers ) diff --git a/src/TNL/Pointers/SmartPointersRegister.cpp b/src/TNL/Pointers/SmartPointersRegister.cpp deleted file mode 100644 index 01641661c..000000000 --- a/src/TNL/Pointers/SmartPointersRegister.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * * - * This program 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 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -/*************************************************************************** - SmartPointersRegister.cpp - description - ------------------- - begin : Apr 29, 2016 - copyright : (C) 2016 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -#include -#include -#include - -void SmartPointersRegister::insert( SmartPointer* pointer, int deviceId ) -{ - //std::cerr << "Inserting pointer " << pointer << " to the register..." << std::endl; - pointersOnDevices[ deviceId ].insert( pointer ); -} - -void SmartPointersRegister::remove( SmartPointer* pointer, int deviceId ) -{ - try { - pointersOnDevices.at( deviceId ).erase( pointer ); - } - catch( const std::out_of_range& ) { - std::cerr << "Given deviceId " << deviceId << " does not have any pointers yet. " - << "Requested to remove pointer " << pointer << ". " - << "This is most likely a bug in the smart pointer." << std::endl; - throw; - } -} - -bool SmartPointersRegister::synchronizeDevice( int deviceId ) -{ - try { - const auto & set = pointersOnDevices.at( deviceId ); - for( auto&& it : set ) - ( *it ).synchronize(); - TNL_CHECK_CUDA_DEVICE; - return true; - } - catch( const std::out_of_range& ) { - return false; - } -} diff --git a/src/TNL/Pointers/SmartPointersRegister.h b/src/TNL/Pointers/SmartPointersRegister.h index 569d62138..752eb672c 100644 --- a/src/TNL/Pointers/SmartPointersRegister.h +++ b/src/TNL/Pointers/SmartPointersRegister.h @@ -20,11 +20,36 @@ class SmartPointersRegister public: - void insert( SmartPointer* pointer, int deviceId ); - - void remove( SmartPointer* pointer, int deviceId ); - - bool synchronizeDevice( int deviceId ); + void insert( SmartPointer* pointer, int deviceId ) + { + pointersOnDevices[ deviceId ].insert( pointer ); + } + + void remove( SmartPointer* pointer, int deviceId ) + { + try { + pointersOnDevices.at( deviceId ).erase( pointer ); + } + catch( const std::out_of_range& ) { + std::cerr << "Given deviceId " << deviceId << " does not have any pointers yet. " + << "Requested to remove pointer " << pointer << ". " + << "This is most likely a bug in the smart pointer." << std::endl; + throw; + } + } + + bool synchronizeDevice( int deviceId ) + { + try { + const auto & set = pointersOnDevices.at( deviceId ); + for( auto&& it : set ) + ( *it ).synchronize(); + return true; + } + catch( const std::out_of_range& ) { + return false; + } + } protected: -- GitLab From 08b12e35269ac38c64150307b1788dc99a6177f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 26 Oct 2018 14:34:48 +0200 Subject: [PATCH 11/39] Moved stuff from Host.cpp to Host.h --- src/TNL/Devices/CMakeLists.txt | 1 - src/TNL/Devices/Host.cpp | 101 --------------------------- src/TNL/Devices/Host.h | 123 ++++++++++++++++++++++++--------- 3 files changed, 90 insertions(+), 135 deletions(-) delete mode 100644 src/TNL/Devices/Host.cpp diff --git a/src/TNL/Devices/CMakeLists.txt b/src/TNL/Devices/CMakeLists.txt index 7f8b25120..75c4f59a5 100644 --- a/src/TNL/Devices/CMakeLists.txt +++ b/src/TNL/Devices/CMakeLists.txt @@ -8,7 +8,6 @@ set (headers Cuda.h SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL/Devices ) set( common_SOURCES - ${CURRENT_DIR}/Host.cpp ${CURRENT_DIR}/MIC.cpp ${CURRENT_DIR}/SystemInfo.cpp ) diff --git a/src/TNL/Devices/Host.cpp b/src/TNL/Devices/Host.cpp deleted file mode 100644 index c45662849..000000000 --- a/src/TNL/Devices/Host.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/*************************************************************************** - Host.cpp - description - ------------------- - begin : Nov 7, 2012 - copyright : (C) 2012 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#ifdef HAVE_OPENMP -#include -#endif - -#include -#include -#include - -namespace TNL { -namespace Devices { - -bool Host::ompEnabled( true ); -int Host::maxThreadsCount( -1 ); - -String Host::getDeviceType() -{ - return String( "Devices::Host" ); -}; - -void Host::enableOMP() -{ - ompEnabled = true; -} - -void Host::disableOMP() -{ - ompEnabled = false; -} - -void Host::setMaxThreadsCount( int maxThreadsCount_ ) -{ - maxThreadsCount = maxThreadsCount_; -#ifdef HAVE_OPENMP - omp_set_num_threads( maxThreadsCount ); -#endif -} - -int Host::getMaxThreadsCount() -{ -#ifdef HAVE_OPENMP - if( maxThreadsCount == -1 ) - return omp_get_max_threads(); - return maxThreadsCount; -#else - return 0; -#endif -} - -int Host::getThreadIdx() -{ -#ifdef HAVE_OPENMP - return omp_get_thread_num(); -#else - return 0; -#endif -} - -void Host::configSetup( Config::ConfigDescription& config, const String& prefix ) -{ -#ifdef HAVE_OPENMP - config.addEntry< bool >( prefix + "openmp-enabled", "Enable support of OpenMP.", true ); - config.addEntry< int >( prefix + "openmp-max-threads", "Set maximum number of OpenMP threads.", omp_get_max_threads() ); -#else - config.addEntry< bool >( prefix + "openmp-enabled", "Enable support of OpenMP (not supported on this system).", false ); - config.addEntry< int >( prefix + "openmp-max-threads", "Set maximum number of OpenMP threads (not supported on this system).", 0 ); -#endif - -} - -bool Host::setup( const Config::ParameterContainer& parameters, - const String& prefix ) -{ - if( parameters.getParameter< bool >( prefix + "openmp-enabled" ) ) { -#ifdef HAVE_OPENMP - enableOMP(); -#else - std::cerr << "OpenMP is not supported - please recompile the TNL library with OpenMP." << std::endl; - return false; -#endif - } - else - disableOMP(); - const int threadsCount = parameters.getParameter< int >( prefix + "openmp-max-threads" ); - if( threadsCount > 1 && ! isOMPEnabled() ) - std::cerr << "Warning: openmp-max-threads was set to " << threadsCount << ", but OpenMP is disabled." << std::endl; - setMaxThreadsCount( threadsCount ); - return true; -} - -} // namespace Devices -} // namespace TNL diff --git a/src/TNL/Devices/Host.h b/src/TNL/Devices/Host.h index 2852b1a0f..6b56302a2 100644 --- a/src/TNL/Devices/Host.h +++ b/src/TNL/Devices/Host.h @@ -11,55 +11,112 @@ #pragma once #include +#include +#include -namespace TNL { - -namespace Config { - class ConfigDescription; - class ParameterContainer; -} +#ifdef HAVE_OPENMP +#include +#endif +namespace TNL { namespace Devices { +namespace { class Host { - public: +public: + static String getDeviceType() + { + return String( "Devices::Host" ); + } + + static void disableOMP() + { + ompEnabled = false; + } + + static void enableOMP() + { + ompEnabled = true; + } + + static inline bool isOMPEnabled() + { +#ifdef HAVE_OPENMP + return ompEnabled; +#else + return false; +#endif + } - static String getDeviceType(); + static void setMaxThreadsCount( int maxThreadsCount_ ) + { + maxThreadsCount = maxThreadsCount_; +#ifdef HAVE_OPENMP + omp_set_num_threads( maxThreadsCount ); +#endif + } - static void disableOMP(); + static int getMaxThreadsCount() + { +#ifdef HAVE_OPENMP + if( maxThreadsCount == -1 ) + return omp_get_max_threads(); + return maxThreadsCount; +#else + return 0; +#endif + } - static void enableOMP(); + static int getThreadIdx() + { +#ifdef HAVE_OPENMP + return omp_get_thread_num(); +#else + return 0; +#endif + } - static inline bool isOMPEnabled() - { - // This MUST stay in the header since we are interested in whether the - // client was compiled with OpenMP support, not the libtnl.so file. - // Also, keeping it in the header makes it inline-able. + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { #ifdef HAVE_OPENMP - return ompEnabled; + config.addEntry< bool >( prefix + "openmp-enabled", "Enable support of OpenMP.", true ); + config.addEntry< int >( prefix + "openmp-max-threads", "Set maximum number of OpenMP threads.", omp_get_max_threads() ); #else + config.addEntry< bool >( prefix + "openmp-enabled", "Enable support of OpenMP (not supported on this system).", false ); + config.addEntry< int >( prefix + "openmp-max-threads", "Set maximum number of OpenMP threads (not supported on this system).", 0 ); +#endif + } + + static bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + if( parameters.getParameter< bool >( prefix + "openmp-enabled" ) ) { +#ifdef HAVE_OPENMP + enableOMP(); +#else + std::cerr << "OpenMP is not supported - please recompile the TNL library with OpenMP." << std::endl; return false; #endif } - - static void setMaxThreadsCount( int maxThreadsCount ); - - static int getMaxThreadsCount(); - - static int getThreadIdx(); - - static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ); - - static bool setup( const Config::ParameterContainer& parameters, - const String& prefix = "" ); - - protected: - - static bool ompEnabled; - - static int maxThreadsCount; + else + disableOMP(); + const int threadsCount = parameters.getParameter< int >( prefix + "openmp-max-threads" ); + if( threadsCount > 1 && ! isOMPEnabled() ) + std::cerr << "Warning: openmp-max-threads was set to " << threadsCount << ", but OpenMP is disabled." << std::endl; + setMaxThreadsCount( threadsCount ); + return true; + } + +protected: + static bool ompEnabled; + static int maxThreadsCount; }; +bool Host::ompEnabled( true ); +int Host::maxThreadsCount( -1 ); + +} // namespace } // namespace Devices } // namespace TNL -- GitLab From c824ce42131ee22f933150760551fd3b49c81b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 26 Oct 2018 14:47:12 +0200 Subject: [PATCH 12/39] Moved stuff from MIC.cpp to MIC.h --- src/TNL/Devices/CMakeLists.txt | 1 - src/TNL/Devices/MIC.cpp | 41 ------------------- src/TNL/Devices/MIC.h | 75 +++++++++++++++++++--------------- 3 files changed, 43 insertions(+), 74 deletions(-) delete mode 100644 src/TNL/Devices/MIC.cpp diff --git a/src/TNL/Devices/CMakeLists.txt b/src/TNL/Devices/CMakeLists.txt index 75c4f59a5..d771a6c5b 100644 --- a/src/TNL/Devices/CMakeLists.txt +++ b/src/TNL/Devices/CMakeLists.txt @@ -8,7 +8,6 @@ set (headers Cuda.h SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL/Devices ) set( common_SOURCES - ${CURRENT_DIR}/MIC.cpp ${CURRENT_DIR}/SystemInfo.cpp ) IF( BUILD_CUDA ) diff --git a/src/TNL/Devices/MIC.cpp b/src/TNL/Devices/MIC.cpp deleted file mode 100644 index b16ac7854..000000000 --- a/src/TNL/Devices/MIC.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - MIC.cpp - description - ------------------- - begin : Feb 10, 2017 - copyright : (C) 2017 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -// Implemented by: Vit Hanousek - -#include - -namespace TNL { -namespace Devices { - -SmartPointersRegister MIC::smartPointersRegister; -Timer MIC::smartPointersSynchronizationTimer; - -void MIC::insertSmartPointer( SmartPointer* pointer ) -{ - smartPointersRegister.insert( pointer, -1 ); -} - -void MIC::removeSmartPointer( SmartPointer* pointer ) -{ - smartPointersRegister.remove( pointer, -1 ); -} - -bool MIC::synchronizeDevice( int deviceId ) -{ - smartPointersSynchronizationTimer.start(); - bool b = smartPointersRegister.synchronizeDevice( deviceId ); - smartPointersSynchronizationTimer.stop(); - return b; -} - - -} // namespace Devices -} // namespace TNL \ No newline at end of file diff --git a/src/TNL/Devices/MIC.h b/src/TNL/Devices/MIC.h index 5b6a9a4f8..9a49253c4 100644 --- a/src/TNL/Devices/MIC.h +++ b/src/TNL/Devices/MIC.h @@ -24,13 +24,13 @@ namespace TNL { - namespace Devices { - +namespace { + //useful macros from Intel's tutorials -- but we do not use it, becaouse it is tricky (system of maping variables CPU-MIC) #define ALLOC alloc_if(1) //alloac variable at begining of offloaded block -- default #define FREE free_if(1) // delete variable at the end of offloaded block -- default -#define RETAIN free_if(0) //do not delete variable at the end of offladed block +#define RETAIN free_if(0) //do not delete variable at the end of offladed block #define REUSE alloc_if(0) //do not alloc variable at begin of offloaded block, reuse variable on MIC which was not deleted befeore //structure which hides pointer - bypass mapping of variables and addresses of arrays and allow get RAW addres of MIC memory to RAM @@ -55,7 +55,7 @@ struct MICStruct{ #define TNLMICSTRUCTALLOC(bb,typ) typ * kernel ## bb = (typ*) malloc (sizeof(typ)); \ memcpy((void*)kernel ## bb,(void*) & s ## bb, sizeof(typ)); -//version which retypes pointer of object to pointer to array of uint8_t, +//version which retypes pointer of object to pointer to array of uint8_t, //object can be copied using uint8_t pointer as array with same length as object size #define TNLMICHIDE(bb,typ) uint8_t * u ## bb=(uint8_t *)&bb; \ MICHider kernel ## bb; @@ -68,14 +68,14 @@ struct MICStruct{ class MIC { public: - + static String getDeviceType() { return String( "Devices::MIC" ); }; - -#ifdef HAVE_MIC - + +#ifdef HAVE_MIC + //useful debuging -- but produce warning __cuda_callable__ static inline void CheckMIC(void) { @@ -85,26 +85,26 @@ class MIC std::cout<<"ON CPU" < static TYP * passToDevice(TYP &objektCPU) { - uint8_t * uk=(uint8_t *)&objektCPU; + uint8_t * uk=(uint8_t *)&objektCPU; MICHider ret; - + #pragma offload target(mic) in(uk:length(sizeof(TYP))) out(ret) { ret.pointer=(TYP*)malloc(sizeof(TYP)); std::memcpy((void*)ret.pointer,(void*)uk,sizeof(TYP)); } return ret.pointer; - + std::cout << "NÄ›kdo mnÄ› volá :-D" < static @@ -117,7 +117,7 @@ class MIC free((void*)ptr.pointer); } }; - + static inline void CopyToMIC(void* mic_ptr,void* ptr,size_t size) { @@ -152,28 +152,39 @@ class MIC free(hide_ptr.pointer); } }; - - + + #endif - - static void insertSmartPointer( SmartPointer* pointer ); - - static void removeSmartPointer( SmartPointer* pointer ); - + + static void insertSmartPointer( SmartPointer* pointer ) + { + smartPointersRegister.insert( pointer, -1 ); + } + + static void removeSmartPointer( SmartPointer* pointer ) + { + smartPointersRegister.remove( pointer, -1 ); + } + // Negative deviceId means that CudaDeviceInfo::getActiveDevice will be // called to get the device ID. - static bool synchronizeDevice( int deviceId = -1 ); - + static bool synchronizeDevice( int deviceId = -1 ) + { + smartPointersSynchronizationTimer.start(); + bool b = smartPointersRegister.synchronizeDevice( deviceId ); + smartPointersSynchronizationTimer.stop(); + return b; + } + static Timer smartPointersSynchronizationTimer; - - protected: - - static SmartPointersRegister smartPointersRegister; +protected: + static SmartPointersRegister smartPointersRegister; }; -}//namespace Devices - -}//namespace TNL - +SmartPointersRegister MIC::smartPointersRegister; +Timer MIC::smartPointersSynchronizationTimer; +} // namespace +} // namespace Devices +} // namespace TNL -- GitLab From 680b9315cb11de661395843144c048c2940ccea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 26 Oct 2018 15:47:49 +0200 Subject: [PATCH 13/39] Moved stuff from File.cpp to File_impl.h --- src/TNL/CMakeLists.txt | 1 - src/TNL/File.cpp | 77 ------------------------------------------ src/TNL/File.h | 12 +++---- src/TNL/File_impl.h | 52 ++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 84 deletions(-) delete mode 100644 src/TNL/File.cpp diff --git a/src/TNL/CMakeLists.txt b/src/TNL/CMakeLists.txt index 9b621af31..4a4484eea 100644 --- a/src/TNL/CMakeLists.txt +++ b/src/TNL/CMakeLists.txt @@ -37,7 +37,6 @@ set( headers StaticVectorFor.h ) set( common_SOURCES - File.cpp FileName.cpp Object.cpp Logger.cpp diff --git a/src/TNL/File.cpp b/src/TNL/File.cpp deleted file mode 100644 index f4be340ae..000000000 --- a/src/TNL/File.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/*************************************************************************** - File.cpp - description - ------------------- - begin : Oct 22, 2010 - copyright : (C) 2010 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#include - -namespace TNL { - -File :: File() -: mode( IOMode::undefined ), - file( NULL ), - fileOK( false ), - writtenElements( 0 ), - readElements( 0 ) -{ -} - -File :: ~File() -{ - // destroying a file without closing is a memory leak - // (an open file descriptor is left behind, on Linux there is typically - // only a limited number of descriptors available to each process) - close(); -} - -bool File :: open( const String& fileName, - const IOMode mode ) -{ - // close the existing file to avoid memory leaks - this->close(); - - this->fileName = fileName; - if( mode == IOMode::read ) - file = std::fopen( fileName.getString(), "rb" ); - if( mode == IOMode::write ) - file = std::fopen( fileName.getString(), "wb" ); - if( file == NULL ) - { - std::cerr << "I am not able to open the file " << fileName << ". "; - std::perror( "" ); - return false; - } - this->fileOK = true; - this->mode = mode; - return true; -} - -bool File :: close() -{ - if( file && std::fclose( file ) != 0 ) - { - std::cerr << "I was not able to close the file " << fileName << " properly!" << std::endl; - return false; - } - // reset all attributes - mode = IOMode::undefined; - file = NULL; - fileOK = false; - fileName = ""; - readElements = writtenElements = 0; - return true; -} - -bool fileExists( const String& fileName ) -{ - std::fstream file; - file.open( fileName.getString(), std::ios::in ); - return ! file.fail(); -} - -} // namespace TNL diff --git a/src/TNL/File.h b/src/TNL/File.h index afa5631f6..fecb44c9f 100644 --- a/src/TNL/File.h +++ b/src/TNL/File.h @@ -45,22 +45,22 @@ const size_t FileGPUvsCPUTransferBufferSize = 5 * 2<<20; // \include FileExample.out class File { - IOMode mode; + IOMode mode = IOMode::undefined; - std::FILE* file; + std::FILE* file = nullptr; - bool fileOK; + bool fileOK = false; String fileName; - std::size_t writtenElements; + std::size_t writtenElements = 0; - std::size_t readElements; + std::size_t readElements = 0; public: /// \brief Basic constructor. - File(); + File() = default; /// \brief Destructor. ~File(); diff --git a/src/TNL/File_impl.h b/src/TNL/File_impl.h index a27250242..b113bf513 100644 --- a/src/TNL/File_impl.h +++ b/src/TNL/File_impl.h @@ -19,6 +19,51 @@ namespace TNL { +inline File::~File() +{ + // destroying a file without closing is a memory leak + // (an open file descriptor is left behind, on Linux there is typically + // only a limited number of descriptors available to each process) + close(); +} + +inline bool File::open( const String& fileName, + const IOMode mode ) +{ + // close the existing file to avoid memory leaks + this->close(); + + this->fileName = fileName; + if( mode == IOMode::read ) + file = std::fopen( fileName.getString(), "rb" ); + if( mode == IOMode::write ) + file = std::fopen( fileName.getString(), "wb" ); + if( file == NULL ) + { + std::cerr << "I am not able to open the file " << fileName << ". "; + std::perror( "" ); + return false; + } + this->fileOK = true; + this->mode = mode; + return true; +} + +inline bool File::close() +{ + if( file && std::fclose( file ) != 0 ) + { + std::cerr << "I was not able to close the file " << fileName << " properly!" << std::endl; + return false; + } + // reset all attributes + mode = IOMode::undefined; + file = NULL; + fileOK = false; + fileName = ""; + readElements = writtenElements = 0; + return true; +} template< typename Type, typename Device > bool File::read( Type* buffer ) @@ -306,4 +351,11 @@ bool File::write_impl( const Type* buffer, #endif } +inline bool fileExists( const String& fileName ) +{ + std::fstream file; + file.open( fileName.getString(), std::ios::in ); + return ! file.fail(); +} + } // namespace TNL -- GitLab From c48fe4be21ae90d10cc5206c4e25d5f759004b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 27 Oct 2018 09:01:32 +0200 Subject: [PATCH 14/39] Rewritten TNL::File using std::fstream This is much simpler than using the C functions. As a bonus, I/O errors throw exceptions. --- src/TNL/Containers/Algorithms/ArrayIO.h | 4 +- src/TNL/Containers/StaticArray1D_impl.h | 2 +- src/TNL/Containers/StaticArray2D_impl.h | 4 +- src/TNL/Containers/StaticArray3D_impl.h | 4 +- src/TNL/Containers/StaticArray_impl.h | 4 +- src/TNL/File.h | 77 +++----- src/TNL/File_impl.h | 241 +++++++----------------- src/TNL/Object.cpp | 1 - src/UnitTests/FileTest.h | 4 +- 9 files changed, 99 insertions(+), 242 deletions(-) diff --git a/src/TNL/Containers/Algorithms/ArrayIO.h b/src/TNL/Containers/Algorithms/ArrayIO.h index 5be8d02ca..9b14f7cca 100644 --- a/src/TNL/Containers/Algorithms/ArrayIO.h +++ b/src/TNL/Containers/Algorithms/ArrayIO.h @@ -71,14 +71,14 @@ class ArrayIO< Value, Device, Index, false > const Value* data, const Index elements ) { - return file.write< Value, Device, Index >( data, elements ); + return file.write< Value, Device >( data, elements ); } static bool load( File& file, Value* data, const Index elements ) { - return file.read< Value, Device, Index >( data, elements ); + return file.read< Value, Device >( data, elements ); } }; diff --git a/src/TNL/Containers/StaticArray1D_impl.h b/src/TNL/Containers/StaticArray1D_impl.h index 81f5a08d2..e9b1fbc1d 100644 --- a/src/TNL/Containers/StaticArray1D_impl.h +++ b/src/TNL/Containers/StaticArray1D_impl.h @@ -162,7 +162,7 @@ inline void StaticArray< 1, Value >::setValue( const ValueType& val ) template< typename Value > bool StaticArray< 1, Value >::save( File& file ) const { - if( ! file. write< Value, Devices::Host, int >( data, size ) ) + if( ! file. write< Value, Devices::Host >( data, size ) ) { std::cerr << "Unable to write " << getType() << "." << std::endl; return false; diff --git a/src/TNL/Containers/StaticArray2D_impl.h b/src/TNL/Containers/StaticArray2D_impl.h index 55096abd0..664a938d7 100644 --- a/src/TNL/Containers/StaticArray2D_impl.h +++ b/src/TNL/Containers/StaticArray2D_impl.h @@ -192,7 +192,7 @@ inline void StaticArray< 2, Value >::setValue( const ValueType& val ) template< typename Value > bool StaticArray< 2, Value >::save( File& file ) const { - if( ! file. write< Value, Devices::Host, int >( data, size ) ) + if( ! file. write< Value, Devices::Host >( data, size ) ) { std::cerr << "Unable to write " << getType() << "." << std::endl; return false; @@ -203,7 +203,7 @@ bool StaticArray< 2, Value >::save( File& file ) const template< typename Value > bool StaticArray< 2, Value >::load( File& file) { - if( ! file.read< Value, Devices::Host, int >( data, size ) ) + if( ! file.read< Value, Devices::Host >( data, size ) ) { std::cerr << "Unable to read " << getType() << "." << std::endl; return false; diff --git a/src/TNL/Containers/StaticArray3D_impl.h b/src/TNL/Containers/StaticArray3D_impl.h index 1aac8cc89..2489196c0 100644 --- a/src/TNL/Containers/StaticArray3D_impl.h +++ b/src/TNL/Containers/StaticArray3D_impl.h @@ -213,7 +213,7 @@ void StaticArray< 3, Value >::setValue( const ValueType& val ) template< typename Value > bool StaticArray< 3, Value >::save( File& file ) const { - if( ! file. write< Value, Devices::Host, int >( data, size ) ) + if( ! file. write< Value, Devices::Host >( data, size ) ) { std::cerr << "Unable to write " << getType() << "." << std::endl; return false; @@ -224,7 +224,7 @@ bool StaticArray< 3, Value >::save( File& file ) const template< typename Value > bool StaticArray< 3, Value >::load( File& file) { - if( ! file.read< Value, Devices::Host, int >( data, size ) ) + if( ! file.read< Value, Devices::Host >( data, size ) ) { std::cerr << "Unable to read " << getType() << "." << std::endl; return false; diff --git a/src/TNL/Containers/StaticArray_impl.h b/src/TNL/Containers/StaticArray_impl.h index 0917b0f1c..a154ebc48 100644 --- a/src/TNL/Containers/StaticArray_impl.h +++ b/src/TNL/Containers/StaticArray_impl.h @@ -160,7 +160,7 @@ inline void StaticArray< Size, Value >::setValue( const ValueType& val ) template< int Size, typename Value > bool StaticArray< Size, Value >::save( File& file ) const { - if( ! file. write< Value, Devices::Host, int >( data, size ) ) + if( ! file. write< Value, Devices::Host >( data, size ) ) { std::cerr << "Unable to write " << getType() << "." << std::endl; return false; @@ -171,7 +171,7 @@ bool StaticArray< Size, Value >::save( File& file ) const template< int Size, typename Value > bool StaticArray< Size, Value >::load( File& file) { - if( ! file.read< Value, Devices::Host, int >( data, size ) ) + if( ! file.read< Value, Devices::Host >( data, size ) ) { std::cerr << "Unable to read " << getType() << "." << std::endl; return false; diff --git a/src/TNL/File.h b/src/TNL/File.h index fecb44c9f..daead1681 100644 --- a/src/TNL/File.h +++ b/src/TNL/File.h @@ -10,11 +10,9 @@ #pragma once -#include #include -#include +#include -#include #include #include #include @@ -24,7 +22,7 @@ namespace TNL { enum class IOMode { - undefined = 0, +// undefined = 0, read = 1, write = 2 }; @@ -34,7 +32,7 @@ enum class IOMode * http://wiki.accelereyes.com/wiki/index.php/GPU_Memory_Transfer * Similar constant is defined in tnlLonegVectorCUDA */ -const size_t FileGPUvsCPUTransferBufferSize = 5 * 2<<20; +static constexpr std::streamsize FileGPUvsCPUTransferBufferSize = 5 * 2<<20; ///\brief Class file is aimed mainly for saving and loading binary data. @@ -45,26 +43,13 @@ const size_t FileGPUvsCPUTransferBufferSize = 5 * 2<<20; // \include FileExample.out class File { - IOMode mode = IOMode::undefined; - - std::FILE* file = nullptr; - - bool fileOK = false; - + std::fstream file; String fileName; - std::size_t writtenElements = 0; - - std::size_t readElements = 0; - - public: - +public: /// \brief Basic constructor. File() = default; - /// \brief Destructor. - ~File(); - ///// /// \brief Attempts to open given file and returns \e true after the file is /// successfully opened. Otherwise returns \e false. @@ -76,36 +61,29 @@ class File bool open( const String& fileName, const IOMode mode ); + /// \brief Attempts to close given file and returns \e true when the file is + /// successfully closed. Otherwise returns \e false. + bool close(); + /// \brief Returns name of given file. const String& getFileName() const { return this->fileName; } - /// \brief Returns number of read elements. - long int getReadElements() const - { - return this->readElements; - } - - /// \brief Returns number of written elements. - long int getWrittenElements() const - { - return this->writtenElements; - } - /// \brief Method that can write particular data type from given file into GPU. (Function that gets particular elements from given file.) /// /// Returns \e true when the elements are successfully read from given file. Otherwise returns \e false. /// + /// Throws \e std::ios_base::failure on failure. + /// /// \tparam Type Type of data. /// \tparam Device Place where data are stored after reading from file. For example Devices::Host or Devices::Cuda. /// \tparam Index Type of index by which the elements are indexed. /// \param buffer Pointer in memory where the elements are loaded and stored after reading. /// \param elements Number of elements the user wants to get (read) from given file. - template< typename Type, typename Device = Devices::Host, typename Index = int > - bool read( Type* buffer, - const Index& elements ); + template< typename Type, typename Device = Devices::Host > + bool read( Type* buffer, std::streamsize elements ); // Toto je treba?? template< typename Type, typename Device = Devices::Host > @@ -115,65 +93,56 @@ class File /// /// Returns \e true when the elements are successfully written into given file. Otherwise returns \e false. /// + /// Throws \e std::ios_base::failure on failure. + /// /// \tparam Type Type of data. /// \tparam Device Place from where the data are loaded before writing into file. For example Devices::Host or Devices::Cuda. /// \tparam Index Type of index by which the elements are indexed. /// \param buffer Pointer in memory where the elements are loaded from before writing into file. /// \param elements Number of elements the user wants to write into the given file. - template< typename Type, typename Device = Devices::Host, typename Index = int > - bool write( const Type* buffer, - const Index elements ); + template< typename Type, typename Device = Devices::Host > + bool write( const Type* buffer, std::streamsize elements ); // Toto je treba? template< typename Type, typename Device = Devices::Host > bool write( const Type* buffer ); - /// \brief Attempts to close given file and returns \e true when the file is - /// successfully closed. Otherwise returns \e false. - bool close(); - protected: template< typename Type, typename Device, typename = typename std::enable_if< std::is_same< Device, Devices::Host >::value >::type > - bool read_impl( Type* buffer, - const std::size_t& elements ); + bool read_impl( Type* buffer, std::streamsize elements ); template< typename Type, typename Device, typename = typename std::enable_if< std::is_same< Device, Devices::Cuda >::value >::type, typename = void > - bool read_impl( Type* buffer, - const std::size_t& elements ); + bool read_impl( Type* buffer, std::streamsize elements ); template< typename Type, typename Device, typename = typename std::enable_if< std::is_same< Device, Devices::MIC >::value >::type, typename = void, typename = void > - bool read_impl( Type* buffer, - const std::size_t& elements ); + bool read_impl( Type* buffer, std::streamsize elements ); template< typename Type, typename Device, typename = typename std::enable_if< std::is_same< Device, Devices::Host >::value >::type > - bool write_impl( const Type* buffer, - const std::size_t& elements ); + bool write_impl( const Type* buffer, std::streamsize elements ); template< typename Type, typename Device, typename = typename std::enable_if< std::is_same< Device, Devices::Cuda >::value >::type, typename = void > - bool write_impl( const Type* buffer, - const std::size_t& elements ); + bool write_impl( const Type* buffer, std::streamsize elements ); template< typename Type, typename Device, typename = typename std::enable_if< std::is_same< Device, Devices::MIC >::value >::type, typename = void, typename = void > - bool write_impl( const Type* buffer, - const std::size_t& elements ); + bool write_impl( const Type* buffer, std::streamsize elements ); }; /// Returns true if the file exists and false otherwise. diff --git a/src/TNL/File_impl.h b/src/TNL/File_impl.h index b113bf513..702345ff6 100644 --- a/src/TNL/File_impl.h +++ b/src/TNL/File_impl.h @@ -10,95 +10,69 @@ #pragma once -#include #include +#include #include +#include #include #include namespace TNL { -inline File::~File() +inline bool File::open( const String& fileName, const IOMode mode ) { - // destroying a file without closing is a memory leak - // (an open file descriptor is left behind, on Linux there is typically - // only a limited number of descriptors available to each process) + // enable exceptions + file.exceptions( std::fstream::failbit | std::fstream::badbit | std::fstream::eofbit ); + close(); -} -inline bool File::open( const String& fileName, - const IOMode mode ) -{ - // close the existing file to avoid memory leaks - this->close(); + if( mode == IOMode::read ) + file.open( fileName.getString(), std::ios::binary | std::ios::in ); + else + file.open( fileName.getString(), std::ios::binary | std::ios::out ); this->fileName = fileName; - if( mode == IOMode::read ) - file = std::fopen( fileName.getString(), "rb" ); - if( mode == IOMode::write ) - file = std::fopen( fileName.getString(), "wb" ); - if( file == NULL ) - { + if( ! file.good() ) { std::cerr << "I am not able to open the file " << fileName << ". "; - std::perror( "" ); return false; } - this->fileOK = true; - this->mode = mode; return true; } inline bool File::close() { - if( file && std::fclose( file ) != 0 ) - { - std::cerr << "I was not able to close the file " << fileName << " properly!" << std::endl; - return false; + if( file.is_open() ) { + file.close(); + if( ! file.good() ) { + std::cerr << "I was not able to close the file " << fileName << " properly!" << std::endl; + return false; + } } // reset all attributes - mode = IOMode::undefined; - file = NULL; - fileOK = false; fileName = ""; - readElements = writtenElements = 0; return true; } template< typename Type, typename Device > bool File::read( Type* buffer ) { - return read< Type, Device, int >( buffer, 1 ); + return read< Type, Device >( buffer, 1 ); } template< typename Type, typename Device > bool File::write( const Type* buffer ) { - return write< Type, Device, int >( buffer, 1 ); + return write< Type, Device >( buffer, 1 ); } -template< typename Type, typename Device, typename Index > -bool File::read( Type* buffer, - const Index& _elements ) +template< typename Type, typename Device > +bool File::read( Type* buffer, std::streamsize elements ) { - TNL_ASSERT_GE( _elements, (Index) 0, "Number of elements to read must be non-negative." ); - - // convert _elements from Index to std::size_t, which is *unsigned* type - // (expected by fread etc) - std::size_t elements = (std::size_t) _elements; + TNL_ASSERT_GE( elements, 0, "Number of elements to read must be non-negative." ); if( ! elements ) return true; - if( ! fileOK ) - { - std::cerr << "File " << fileName << " was not properly opened. " << std::endl; - return false; - } - if( mode != IOMode::read ) - { - std::cerr << "File " << fileName << " was not opened for reading. " << std::endl; - return false; - } return read_impl< Type, Device >( buffer, elements ); } @@ -107,20 +81,9 @@ bool File::read( Type* buffer, template< typename Type, typename Device, typename > -bool File::read_impl( Type* buffer, - const std::size_t& elements ) +bool File::read_impl( Type* buffer, std::streamsize elements ) { - this->readElements = 0; - if( std::fread( buffer, - sizeof( Type ), - elements, - file ) != elements ) - { - std::cerr << "I am not able to read the data from the file " << fileName << "." << std::endl; - std::perror( "Fread ended with the error code" ); - return false; - } - this->readElements = elements; + file.read( reinterpret_cast(buffer), sizeof(Type) * elements ); return true; } @@ -128,33 +91,24 @@ bool File::read_impl( Type* buffer, template< typename Type, typename Device, typename, typename > -bool File::read_impl( Type* buffer, - const std::size_t& elements ) +bool File::read_impl( Type* buffer, std::streamsize elements ) { #ifdef HAVE_CUDA - this->readElements = 0; - const std::size_t host_buffer_size = std::min( FileGPUvsCPUTransferBufferSize / sizeof( Type ), elements ); + const std::streamsize host_buffer_size = std::min( FileGPUvsCPUTransferBufferSize / (std::streamsize) sizeof(Type), elements ); using BaseType = typename std::remove_cv< Type >::type; std::unique_ptr< BaseType[] > host_buffer{ new BaseType[ host_buffer_size ] }; + std::streamsize readElements = 0; while( readElements < elements ) { - std::size_t transfer = std::min( elements - readElements, host_buffer_size ); - std::size_t transfered = std::fread( host_buffer.get(), sizeof( Type ), transfer, file ); - if( transfered != transfer ) - { - std::cerr << "I am not able to read the data from the file " << fileName << "." << std::endl; - std::cerr << transfered << " bytes were transfered. " << std::endl; - std::perror( "Fread ended with the error code" ); - return false; - } - + const std::streamsize transfer = std::min( elements - readElements, host_buffer_size ); + file.read( reinterpret_cast(host_buffer.get()), sizeof(Type) * transfer ); cudaMemcpy( (void*) &buffer[ readElements ], (void*) host_buffer.get(), transfer * sizeof( Type ), cudaMemcpyHostToDevice ); TNL_CHECK_CUDA_DEVICE; - this->readElements += transfer; + readElements += transfer; } return true; #else @@ -166,32 +120,19 @@ bool File::read_impl( Type* buffer, template< typename Type, typename Device, typename, typename, typename > -bool File::read_impl( Type* buffer, - const std::size_t& elements ) +bool File::read_impl( Type* buffer, std::streamsize elements ) { #ifdef HAVE_MIC - this->readElements = 0; - const std::size_t host_buffer_size = std::min( FileGPUvsCPUTransferBufferSize / sizeof( Type ), elements ); - Type * host_buffer = (Type *)malloc( sizeof( Type ) * host_buffer_size ); - readElements = 0; - if( ! host_buffer ) - { - std::cerr << "I am sorry but I cannot allocate supporting buffer on the host for writing data from the GPU to the file " - << this->getFileName() << "." << std::endl; - return false; - } + const std::streamsize host_buffer_size = std::min( FileGPUvsCPUTransferBufferSize / (std::streamsize) sizeof(Type), elements ); + using BaseType = typename std::remove_cv< Type >::type; + std::unique_ptr< BaseType[] > host_buffer{ new BaseType[ host_buffer_size ] }; + std::streamsize readElements = 0; while( readElements < elements ) { - int transfer = std::min( elements - readElements , host_buffer_size ); - size_t transfered = fread( host_buffer, sizeof( Type ), transfer, file ); - if( transfered != transfer ) - { - std::cerr << "I am not able to read the data from the file " << fileName << "." << std::endl; - std::cerr << transfered << " bytes were transfered. " << std::endl; - perror( "Fread ended with the error code" ); - return false; - } + const std::streamsize transfer = std::min( elements - readElements, host_buffer_size ); + file.read( reinterpret_cast(host_buffer.get()), sizeof(Type) * transfer ); + Devices::MICHider device_buff; device_buff.pointer=buffer; #pragma offload target(mic) in(device_buff,readElements) in(host_buffer:length(transfer)) @@ -200,7 +141,7 @@ bool File::read_impl( Type* buffer, for(int i=0;i -bool File::write( const Type* buffer, - const Index _elements ) +template< class Type, typename Device > +bool File::write( const Type* buffer, std::streamsize elements ) { - TNL_ASSERT_GE( _elements, (Index) 0, "Number of elements to write must be non-negative." ); - - // convert _elements from Index to std::size_t, which is *unsigned* type - // (expected by fread etc) - std::size_t elements = (std::size_t) _elements; + TNL_ASSERT_GE( elements, 0, "Number of elements to write must be non-negative." ); if( ! elements ) return true; - if( ! fileOK ) - { - std::cerr << "File " << fileName << " was not properly opened. " << std::endl; - return false; - } - if( mode != IOMode::write ) - { - std::cerr << "File " << fileName << " was not opened for writing. " << std::endl; - return false; - } return write_impl< Type, Device >( buffer, elements ); } @@ -242,20 +168,9 @@ bool File::write( const Type* buffer, template< typename Type, typename Device, typename > -bool File::write_impl( const Type* buffer, - const std::size_t& elements ) +bool File::write_impl( const Type* buffer, std::streamsize elements ) { - this->writtenElements = 0; - if( std::fwrite( buffer, - sizeof( Type ), - elements, - this->file ) != elements ) - { - std::cerr << "I am not able to write the data to the file " << fileName << "." << std::endl; - std::perror( "Fwrite ended with the error code" ); - return false; - } - this->writtenElements = elements; + file.write( reinterpret_cast(buffer), sizeof(Type) * elements ); return true; } @@ -263,34 +178,24 @@ bool File::write_impl( const Type* buffer, template< typename Type, typename Device, typename, typename > -bool File::write_impl( const Type* buffer, - const std::size_t& elements ) +bool File::write_impl( const Type* buffer, std::streamsize elements ) { #ifdef HAVE_CUDA - this->writtenElements = 0; - const std::size_t host_buffer_size = std::min( FileGPUvsCPUTransferBufferSize / sizeof( Type ), - elements ); + const std::streamsize host_buffer_size = std::min( FileGPUvsCPUTransferBufferSize / (std::streamsize) sizeof(Type), elements ); using BaseType = typename std::remove_cv< Type >::type; std::unique_ptr< BaseType[] > host_buffer{ new BaseType[ host_buffer_size ] }; - while( this->writtenElements < elements ) + std::streamsize writtenElements = 0; + while( writtenElements < elements ) { - std::size_t transfer = std::min( elements - this->writtenElements, host_buffer_size ); + const std::streamsize transfer = std::min( elements - writtenElements, host_buffer_size ); cudaMemcpy( (void*) host_buffer.get(), - (void*) &buffer[ this->writtenElements ], - transfer * sizeof( Type ), + (void*) &buffer[ writtenElements ], + transfer * sizeof(Type), cudaMemcpyDeviceToHost ); TNL_CHECK_CUDA_DEVICE; - if( std::fwrite( host_buffer.get(), - sizeof( Type ), - transfer, - this->file ) != transfer ) - { - std::cerr << "I am not able to write the data to the file " << fileName << "." << std::endl; - std::perror( "Fwrite ended with the error code" ); - return false; - } - this->writtenElements += transfer; + file.write( reinterpret_cast(host_buffer.get()), sizeof(Type) * transfer ); + writtenElements += transfer; } return true; #else @@ -302,24 +207,17 @@ bool File::write_impl( const Type* buffer, template< typename Type, typename Device, typename, typename, typename > -bool File::write_impl( const Type* buffer, - const std::size_t& elements ) +bool File::write_impl( const Type* buffer, std::streamsize elements ) { #ifdef HAVE_MIC - this->writtenElements = 0; - const std::size_t host_buffer_size = std::min( FileGPUvsCPUTransferBufferSize / sizeof( Type ), - elements ); - Type * host_buffer = (Type *)malloc( sizeof( Type ) * host_buffer_size ); - if( ! host_buffer ) - { - std::cerr << "I am sorry but I cannot allocate supporting buffer on the host for writing data from the GPU to the file " - << this->getFileName() << "." << std::endl; - return false; - } + const std::streamsize host_buffer_size = std::min( FileGPUvsCPUTransferBufferSize / (std::streamsize) sizeof(Type), elements ); + using BaseType = typename std::remove_cv< Type >::type; + std::unique_ptr< BaseType[] > host_buffer{ new BaseType[ host_buffer_size ] }; + std::streamsize writtenElements = 0; while( this->writtenElements < elements ) { - std::size_t transfer = std::min( elements - this->writtenElements, host_buffer_size ); + const std::streamsize transfer = std::min( elements - writtenElements, host_buffer_size ); Devices::MICHider device_buff; device_buff.pointer=buffer; @@ -330,21 +228,12 @@ bool File::write_impl( const Type* buffer, host_buffer[i]=device_buff.pointer[writtenElements+i]; */ - memcpy(host_buffer,&(device_buff.pointer[writtenElements]), transfer*sizeof(Type) ); + memcpy(host_buffer.get(), &(device_buff.pointer[writtenElements]), transfer*sizeof(Type) ); } - if( fwrite( host_buffer, - sizeof( Type ), - transfer, - this->file ) != transfer ) - { - std::cerr << "I am not able to write the data to the file " << fileName << "." << std::endl; - perror( "Fwrite ended with the error code" ); - return false; - } - this->writtenElements += transfer; + file.write( reinterpret_cast(host_buffer.get()), sizeof(Type) * transfer ); + writtenElements += transfer; } - free( host_buffer ); return true; #else throw Exceptions::MICSupportMissing(); @@ -353,9 +242,9 @@ bool File::write_impl( const Type* buffer, inline bool fileExists( const String& fileName ) { - std::fstream file; - file.open( fileName.getString(), std::ios::in ); - return ! file.fail(); + std::fstream file; + file.open( fileName.getString(), std::ios::in ); + return ! file.fail(); } } // namespace TNL diff --git a/src/TNL/Object.cpp b/src/TNL/Object.cpp index 0beb54311..7afbc56ea 100644 --- a/src/TNL/Object.cpp +++ b/src/TNL/Object.cpp @@ -13,7 +13,6 @@ #include #include #include -#include namespace TNL { diff --git a/src/UnitTests/FileTest.h b/src/UnitTests/FileTest.h index b1385f412..10bf8caff 100644 --- a/src/UnitTests/FileTest.h +++ b/src/UnitTests/FileTest.h @@ -81,7 +81,7 @@ TEST( FileTest, WriteAndReadCUDA ) bool status = file.write< int, Devices::Cuda >( cudaIntData ); ASSERT_TRUE( status ); - status = file.write< float, Devices::Cuda, int >( cudaFloatData, 3 ); + status = file.write< float, Devices::Cuda >( cudaFloatData, 3 ); ASSERT_TRUE( status ); status = file.write< const double, Devices::Cuda >( cudaConstDoubleData ); ASSERT_TRUE( status ); @@ -99,7 +99,7 @@ TEST( FileTest, WriteAndReadCUDA ) cudaMalloc( ( void** ) &newCudaDoubleData, sizeof( double ) ); status = file.read< int, Devices::Cuda >( newCudaIntData, 1 ); ASSERT_TRUE( status ); - status = file.read< float, Devices::Cuda, int >( newCudaFloatData, 3 ); + status = file.read< float, Devices::Cuda >( newCudaFloatData, 3 ); ASSERT_TRUE( status ); status = file.read< double, Devices::Cuda >( newCudaDoubleData, 1 ); ASSERT_TRUE( status ); -- GitLab From 06b8db3bfc15bca94d7f4c36970416f51cf24f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 27 Oct 2018 09:02:09 +0200 Subject: [PATCH 15/39] Removed check for obsolete magic number in Object.cpp --- src/TNL/Object.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TNL/Object.cpp b/src/TNL/Object.cpp index 7afbc56ea..e83b2d0d7 100644 --- a/src/TNL/Object.cpp +++ b/src/TNL/Object.cpp @@ -106,8 +106,7 @@ bool getObjectType( File& file, String& type ) std::cerr << "Unable to read file " << file. getFileName() << " ... " << std::endl; return false; } - if( strncmp( mn, magic_number, 5 ) != 0 && - strncmp( mn, "SIM33", 5 ) != 0 ) + if( strncmp( mn, magic_number, 5 ) != 0 ) { std::cout << "Not a TNL file (wrong magic number)." << std::endl; return false; -- GitLab From 8bf0e00389870e10f99db0e0b453da6268366b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 27 Oct 2018 09:36:49 +0200 Subject: [PATCH 16/39] Rewritten String::split to return std::vector Return values are nicer than modifiable parameters. This also avoids the circular dependency between TNL::String and List. --- src/TNL/Matrices/MatrixReader_impl.h | 22 ++++---- src/TNL/String.cpp | 19 +++---- src/TNL/String.h | 8 +-- src/UnitTests/StringTest.cpp | 81 ++++++++++++++-------------- 4 files changed, 58 insertions(+), 72 deletions(-) diff --git a/src/TNL/Matrices/MatrixReader_impl.h b/src/TNL/Matrices/MatrixReader_impl.h index 2cfa66394..fb5bf06d6 100644 --- a/src/TNL/Matrices/MatrixReader_impl.h +++ b/src/TNL/Matrices/MatrixReader_impl.h @@ -11,7 +11,6 @@ #pragma once #include -#include #include #include #include @@ -166,9 +165,8 @@ template< typename Matrix > bool MatrixReader< Matrix >::checkMtxHeader( const String& header, bool& symmetric ) { - Containers::List< String > parsedLine; - header.split( parsedLine ); - if( parsedLine.getSize() < 5 ) + std::vector< String > parsedLine = header.split(); + if( (int) parsedLine.size() < 5 ) return false; if( parsedLine[ 0 ] != "%%MatrixMarket" ) return false; @@ -212,7 +210,7 @@ bool MatrixReader< Matrix >::readMtxHeader( std::istream& file, file.seekg( 0, std::ios::beg ); String line; bool headerParsed( false ); - Containers::List< String > parsedLine; + std::vector< String > parsedLine; while( true ) { line.getLine( file ); @@ -233,15 +231,14 @@ bool MatrixReader< Matrix >::readMtxHeader( std::istream& file, return false; } - parsedLine.reset(); - line.split( parsedLine ); - if( parsedLine. getSize() != 3 ) + parsedLine = line.split(); + if( (int) parsedLine.size() != 3 ) { std::cerr << "Wrong number of parameters in the matrix header." << std::endl; return false; } - rows = atoi( parsedLine[ 0 ]. getString() ); - columns = atoi( parsedLine[ 1 ]. getString() ); + rows = atoi( parsedLine[ 0 ].getString() ); + columns = atoi( parsedLine[ 1 ].getString() ); if( verbose ) std::cout << " The matrix has " << rows << " rows and " << columns << " columns. " << std::endl; @@ -389,9 +386,8 @@ bool MatrixReader< Matrix >::parseMtxLineWithElement( const String& line, IndexType& column, RealType& value ) { - Containers::List< String > parsedLine; - line.split( parsedLine ); - if( parsedLine.getSize() != 3 ) + std::vector< String > parsedLine = line.split(); + if( (int) parsedLine.size() != 3 ) { std::cerr << "Wrong number of parameters in the matrix row at line:" << line << std::endl; return false; diff --git a/src/TNL/String.cpp b/src/TNL/String.cpp index d814a662c..2c9f7d5c3 100644 --- a/src/TNL/String.cpp +++ b/src/TNL/String.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #ifdef USE_MPI @@ -335,25 +334,21 @@ String::strip( char strip ) const return ""; } -int String::split( Containers::List< String >& list, - const char separator, - bool skipEmpty ) const +std::vector< String > String::split( const char separator, bool skipEmpty ) const { - list.reset(); + std::vector< String > parts; String s; - for( int i = 0; i < this->getLength(); i ++ ) - { - if( ( *this )[ i ] == separator ) - { + for( int i = 0; i < this->getLength(); i++ ) { + if( ( *this )[ i ] == separator ) { if( ! skipEmpty || s != "" ) - list.Append( s ); + parts.push_back( s ); s = ""; } else s += ( *this )[ i ]; } if( ! skipEmpty || s != "" ) - list.Append( s ); - return list.getSize(); + parts.push_back( s ); + return parts; } diff --git a/src/TNL/String.h b/src/TNL/String.h index 9e2fb201d..e69fa36f0 100644 --- a/src/TNL/String.h +++ b/src/TNL/String.h @@ -12,14 +12,11 @@ #include #include +#include namespace TNL { class File; -namespace Containers { - template< class T > class List; -} - class String; template< typename T > @@ -237,10 +234,9 @@ class String /// and returs list of those strings. When \e separator does not appear /// anywhere in the given string, this function returns a single-element list /// containing given sting. - /// @param list Name of list. /// @param separator Character, which separates substrings in given string. /// Empty character can not be used. - int split( Containers::List< String >& list, const char separator = ' ', bool skipEmpty = false ) const; + std::vector< String > split( const char separator = ' ', bool skipEmpty = false ) const; ///// /// \brief Function for saving file. diff --git a/src/UnitTests/StringTest.cpp b/src/UnitTests/StringTest.cpp index 389c208e7..b1346355f 100644 --- a/src/UnitTests/StringTest.cpp +++ b/src/UnitTests/StringTest.cpp @@ -16,7 +16,6 @@ #include #include -#include using namespace TNL; @@ -286,46 +285,46 @@ TEST( StringTest, strip ) TEST( StringTest, split ) { - Containers::List< String > list; - - String( "A B C" ).split( list, ' ' ); - ASSERT_EQ( list.getSize(), 3 ); - EXPECT_EQ( list[ 0 ], "A" ); - EXPECT_EQ( list[ 1 ], "B" ); - EXPECT_EQ( list[ 2 ], "C" ); - - String( "abracadabra" ).split( list, 'a' ); - ASSERT_EQ( list.getSize(), 6 ); - EXPECT_EQ( list[ 0 ], "" ); - EXPECT_EQ( list[ 1 ], "br" ); - EXPECT_EQ( list[ 2 ], "c" ); - EXPECT_EQ( list[ 3 ], "d" ); - EXPECT_EQ( list[ 4 ], "br" ); - EXPECT_EQ( list[ 5 ], "" ); - - String( "abracadabra" ).split( list, 'a', true ); - ASSERT_EQ( list.getSize(), 4 ); - EXPECT_EQ( list[ 0 ], "br" ); - EXPECT_EQ( list[ 1 ], "c" ); - EXPECT_EQ( list[ 2 ], "d" ); - EXPECT_EQ( list[ 3 ], "br" ); - - String( "abracadabra" ).split( list, 'b' ); - ASSERT_EQ( list.getSize(), 3 ); - EXPECT_EQ( list[ 0 ], "a" ); - EXPECT_EQ( list[ 1 ], "racada" ); - EXPECT_EQ( list[ 2 ], "ra" ); - - String( "abracadabra" ).split( list, 'A' ); - ASSERT_EQ( list.getSize(), 1 ); - EXPECT_EQ( list[ 0 ], "abracadabra" ); - - String( "a,,b,c" ).split( list, ',' ); - ASSERT_EQ( list.getSize(), 4 ); - EXPECT_EQ( list[ 0 ], "a" ); - EXPECT_EQ( list[ 1 ], "" ); - EXPECT_EQ( list[ 2 ], "b" ); - EXPECT_EQ( list[ 3 ], "c" ); + std::vector< String > parts; + + parts = String( "A B C" ).split( ' ' ); + ASSERT_EQ( (int) parts.size(), 3 ); + EXPECT_EQ( parts[ 0 ], "A" ); + EXPECT_EQ( parts[ 1 ], "B" ); + EXPECT_EQ( parts[ 2 ], "C" ); + + parts = String( "abracadabra" ).split( 'a' ); + ASSERT_EQ( (int) parts.size(), 6 ); + EXPECT_EQ( parts[ 0 ], "" ); + EXPECT_EQ( parts[ 1 ], "br" ); + EXPECT_EQ( parts[ 2 ], "c" ); + EXPECT_EQ( parts[ 3 ], "d" ); + EXPECT_EQ( parts[ 4 ], "br" ); + EXPECT_EQ( parts[ 5 ], "" ); + + parts = String( "abracadabra" ).split( 'a', true ); + ASSERT_EQ( (int) parts.size(), 4 ); + EXPECT_EQ( parts[ 0 ], "br" ); + EXPECT_EQ( parts[ 1 ], "c" ); + EXPECT_EQ( parts[ 2 ], "d" ); + EXPECT_EQ( parts[ 3 ], "br" ); + + parts = String( "abracadabra" ).split( 'b' ); + ASSERT_EQ( (int) parts.size(), 3 ); + EXPECT_EQ( parts[ 0 ], "a" ); + EXPECT_EQ( parts[ 1 ], "racada" ); + EXPECT_EQ( parts[ 2 ], "ra" ); + + parts = String( "abracadabra" ).split( 'A' ); + ASSERT_EQ( (int) parts.size(), 1 ); + EXPECT_EQ( parts[ 0 ], "abracadabra" ); + + parts = String( "a,,b,c" ).split( ',' ); + ASSERT_EQ( (int) parts.size(), 4 ); + EXPECT_EQ( parts[ 0 ], "a" ); + EXPECT_EQ( parts[ 1 ], "" ); + EXPECT_EQ( parts[ 2 ], "b" ); + EXPECT_EQ( parts[ 3 ], "c" ); } TEST( StringTest, SaveLoad ) -- GitLab From f077ff7ef158b9691255f8b74d48736baf625187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 27 Oct 2018 10:09:38 +0200 Subject: [PATCH 17/39] Added FileTest::OpenInvalid --- src/UnitTests/FileTest.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/UnitTests/FileTest.h b/src/UnitTests/FileTest.h index 10bf8caff..4da741892 100644 --- a/src/UnitTests/FileTest.h +++ b/src/UnitTests/FileTest.h @@ -10,7 +10,7 @@ #include -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include using namespace TNL; @@ -21,6 +21,12 @@ TEST( FileTest, CloseEmpty ) ASSERT_TRUE( file.close() ); } +TEST( FileTest, OpenInvalid ) +{ + File file; + EXPECT_THROW( file.open( "invalid-file.tnl", IOMode::read ), std::ios_base::failure ); +} + TEST( FileTest, WriteAndRead ) { File file; -- GitLab From 32b0eb5d0d10c693dfe7fb5037b046f1f99d66c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 09:27:29 +0100 Subject: [PATCH 18/39] Removed useless semicolons from param-types.h --- src/TNL/param-types.h | 74 +++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/TNL/param-types.h b/src/TNL/param-types.h index 333f3620e..58445912f 100644 --- a/src/TNL/param-types.h +++ b/src/TNL/param-types.h @@ -16,50 +16,50 @@ namespace TNL { template< typename T > -String getType() { return T::getType(); }; +String getType() { return T::getType(); } // non-const specializations -template<> inline String getType< void >() { return String( "void" ); }; -template<> inline String getType< bool >() { return String( "bool" ); }; +template<> inline String getType< void >() { return String( "void" ); } +template<> inline String getType< bool >() { return String( "bool" ); } -template<> inline String getType< char >() { return String( "char" ); }; -template<> inline String getType< short int >() { return String( "short int" ); }; -template<> inline String getType< int >() { return String( "int" ); }; -template<> inline String getType< long int >() { return String( "long int" ); }; +template<> inline String getType< char >() { return String( "char" ); } +template<> inline String getType< short int >() { return String( "short int" ); } +template<> inline String getType< int >() { return String( "int" ); } +template<> inline String getType< long int >() { return String( "long int" ); } -template<> inline String getType< unsigned char >() { return String( "unsigned char" ); }; -template<> inline String getType< unsigned short >() { return String( "unsigned short" ); }; -template<> inline String getType< unsigned int >() { return String( "unsigned int" ); }; -template<> inline String getType< unsigned long >() { return String( "unsigned long" ); }; +template<> inline String getType< unsigned char >() { return String( "unsigned char" ); } +template<> inline String getType< unsigned short >() { return String( "unsigned short" ); } +template<> inline String getType< unsigned int >() { return String( "unsigned int" ); } +template<> inline String getType< unsigned long >() { return String( "unsigned long" ); } -template<> inline String getType< signed char >() { return String( "signed char" ); }; +template<> inline String getType< signed char >() { return String( "signed char" ); } -template<> inline String getType< float >() { return String( "float" ); }; -template<> inline String getType< double >() { return String( "double" ); }; -template<> inline String getType< long double >() { return String( "long double" ); }; -template<> inline String getType< tnlFloat >() { return String( "tnlFloat" ); }; -template<> inline String getType< tnlDouble> () { return String( "tnlDouble" ); }; +template<> inline String getType< float >() { return String( "float" ); } +template<> inline String getType< double >() { return String( "double" ); } +template<> inline String getType< long double >() { return String( "long double" ); } +template<> inline String getType< tnlFloat >() { return String( "tnlFloat" ); } +template<> inline String getType< tnlDouble>() { return String( "tnlDouble" ); } // const specializations -template<> inline String getType< const void >() { return String( "const void" ); }; -template<> inline String getType< const bool >() { return String( "const bool" ); }; - -template<> inline String getType< const char >() { return String( "const char" ); }; -template<> inline String getType< const short int >() { return String( "const short int" ); }; -template<> inline String getType< const int >() { return String( "const int" ); }; -template<> inline String getType< const long int >() { return String( "const long int" ); }; - -template<> inline String getType< const unsigned char >() { return String( "const unsigned char" ); }; -template<> inline String getType< const unsigned short >() { return String( "const unsigned short" ); }; -template<> inline String getType< const unsigned int >() { return String( "const unsigned int" ); }; -template<> inline String getType< const unsigned long >() { return String( "const unsigned long" ); }; - -template<> inline String getType< const signed char >() { return String( "const signed char" ); }; - -template<> inline String getType< const float >() { return String( "const float" ); }; -template<> inline String getType< const double >() { return String( "const double" ); }; -template<> inline String getType< const long double >() { return String( "const long double" ); }; -template<> inline String getType< const tnlFloat >() { return String( "const tnlFloat" ); }; -template<> inline String getType< const tnlDouble> () { return String( "const tnlDouble" ); }; +template<> inline String getType< const void >() { return String( "const void" ); } +template<> inline String getType< const bool >() { return String( "const bool" ); } + +template<> inline String getType< const char >() { return String( "const char" ); } +template<> inline String getType< const short int >() { return String( "const short int" ); } +template<> inline String getType< const int >() { return String( "const int" ); } +template<> inline String getType< const long int >() { return String( "const long int" ); } + +template<> inline String getType< const unsigned char >() { return String( "const unsigned char" ); } +template<> inline String getType< const unsigned short >() { return String( "const unsigned short" ); } +template<> inline String getType< const unsigned int >() { return String( "const unsigned int" ); } +template<> inline String getType< const unsigned long >() { return String( "const unsigned long" ); } + +template<> inline String getType< const signed char >() { return String( "const signed char" ); } + +template<> inline String getType< const float >() { return String( "const float" ); } +template<> inline String getType< const double >() { return String( "const double" ); } +template<> inline String getType< const long double >() { return String( "const long double" ); } +template<> inline String getType< const tnlFloat >() { return String( "const tnlFloat" ); } +template<> inline String getType< const tnlDouble>() { return String( "const tnlDouble" ); } } // namespace TNL -- GitLab From 50fc314d5346dd14cd294e4c3b98849e87d273e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 10:26:45 +0100 Subject: [PATCH 19/39] Removed Containers::List from the parseObjectType function --- src/Benchmarks/BLAS/spmv.h | 4 +- src/TNL/Config/ConfigEntryList.h | 2 +- src/TNL/Config/ParameterContainer.cpp | 84 ++++++++------------------- src/TNL/Meshes/Readers/TNLReader.h | 18 +++--- src/TNL/Object.cpp | 31 +++++----- src/TNL/Object.h | 7 ++- src/TNL/param-types.h | 26 ++++++++- src/Tools/tnl-diff.cpp | 9 ++- src/Tools/tnl-diff.h | 41 +++++++------ src/Tools/tnl-image-converter.cpp | 9 ++- src/Tools/tnl-init.cpp | 4 +- src/Tools/tnl-init.h | 8 +-- src/Tools/tnl-lattice-init.h | 20 +++---- src/Tools/tnl-view.h | 40 ++++++------- src/UnitTests/ObjectTest.cpp | 64 ++++++-------------- 15 files changed, 161 insertions(+), 206 deletions(-) diff --git a/src/Benchmarks/BLAS/spmv.h b/src/Benchmarks/BLAS/spmv.h index 9df40f4ec..5c3813b0a 100644 --- a/src/Benchmarks/BLAS/spmv.h +++ b/src/Benchmarks/BLAS/spmv.h @@ -14,7 +14,6 @@ #include "../Benchmarks.h" -#include #include #include #include @@ -111,8 +110,7 @@ benchmarkSpMV( Benchmark & benchmark, CudaVector deviceVector, deviceVector2; // create benchmark group - Containers::List< String > parsedType; - parseObjectType( HostMatrix::getType(), parsedType ); + const std::vector< String > parsedType = parseObjectType( HostMatrix::getType() ); #ifdef HAVE_CUDA benchmark.createHorizontalGroup( parsedType[ 0 ], 2 ); #else diff --git a/src/TNL/Config/ConfigEntryList.h b/src/TNL/Config/ConfigEntryList.h index 95879fa66..50284e37c 100644 --- a/src/TNL/Config/ConfigEntryList.h +++ b/src/TNL/Config/ConfigEntryList.h @@ -50,7 +50,7 @@ struct ConfigEntryList : public ConfigEntryBase String getEntryType() const { - return String("List< ") + TNL::getType< EntryType >() + " >"; + return String("ConfigEntryList< ") + TNL::getType< EntryType >() + " >"; } String getUIEntryType() const diff --git a/src/TNL/Config/ParameterContainer.cpp b/src/TNL/Config/ParameterContainer.cpp index 5329a8745..f318acabb 100644 --- a/src/TNL/Config/ParameterContainer.cpp +++ b/src/TNL/Config/ParameterContainer.cpp @@ -155,41 +155,27 @@ parseCommandLine( int argc, char* argv[], std::cerr << "Missing value for the parameter " << option << "." << std::endl; return false; } - Containers::List< String > parsedEntryType; - if( ! parseObjectType( entryType, parsedEntryType ) ) + std::vector< String > parsedEntryType = parseObjectType( entryType ); + if( parsedEntryType.size() == 0 ) { std::cerr << "Internal error: Unknown config entry type " << entryType << "." << std::endl; return false; } - if( parsedEntryType[ 0 ] == "Containers::List" ) + if( parsedEntryType[ 0 ] == "ConfigEntryList" ) { - Containers::List< String >* string_list( 0 ); - Containers::List< bool >* bool_list( 0 ); - Containers::List< int >* integer_list( 0 ); - Containers::List< double >* real_list( 0 ); + std::vector< String > string_list; + std::vector< bool > bool_list; + std::vector< int > integer_list; + std::vector< double > real_list; - if( parsedEntryType[ 1 ] == "String" ) - string_list = new Containers::List< String >; - if( parsedEntryType[ 1 ] == "bool" ) - bool_list = new Containers::List< bool >; - if( parsedEntryType[ 1 ] == "int" ) - integer_list = new Containers::List< int >; - if( parsedEntryType[ 1 ] == "double" ) - real_list = new Containers::List< double >; - - while( i < argc && ( ( argv[ i ] )[ 0 ] != '-' || ( atof( argv[ i ] ) < 0.0 && ( integer_list || real_list ) ) ) ) + while( i < argc && ( ( argv[ i ] )[ 0 ] != '-' || ( atof( argv[ i ] ) < 0.0 && ( parsedEntryType[ 1 ] == "int" || parsedEntryType[ 1 ] == "double" ) ) ) ) { const char* value = argv[ i ++ ]; - if( string_list ) + if( parsedEntryType[ 1 ] == "String" ) { - /*if( ! ( ( ConfigEntry< Containers::List< String > >* ) entry )->checkValue( String( value ) ) ) - { - delete string_list; - return false; - }*/ - string_list -> Append( String( value ) ); + string_list.push_back( String( value ) ); } - if( bool_list ) + if( parsedEntryType[ 1 ] == "bool" ) { bool bool_val; if( ! matob( value, bool_val ) ) @@ -197,47 +183,25 @@ parseCommandLine( int argc, char* argv[], std::cerr << "Yes/true or no/false is required for the parameter " << option << "." << std::endl; parse_error = true; } - else bool_list -> Append( bool_val ); + else bool_list.push_back( bool_val ); } - if( integer_list ) + if( parsedEntryType[ 1 ] == "int" ) { - /*if( ! ( ConfigEntry< Containers::List< int > >* ) entry->checkValue( atoi( value ) ) ) - { - delete integer_list; - return false; - }*/ - integer_list -> Append( atoi( value ) ); + integer_list.push_back( atoi( value ) ); } - if( real_list ) + if( parsedEntryType[ 1 ] == "double" ) { - /*if( ! ( ConfigEntry< Containers::List< double > >* ) entry->checkValue( atof( value ) ) ) - { - delete real_list; - return false; - }*/ - real_list -> Append( atof( value ) ); + real_list.push_back( atof( value ) ); } } - if( string_list ) - { - parameters.addParameter< Containers::List< String > >( option, *string_list ); - delete string_list; - } - if( bool_list ) - { - parameters.addParameter< Containers::List< bool > >( option, *bool_list ); - delete bool_list; - } - if( integer_list ) - { - parameters.addParameter< Containers::List< int > >( option, *integer_list ); - delete integer_list; - } - if( real_list ) - { - parameters.addParameter< Containers::List< double > >( option, *real_list ); - delete real_list; - } + if( string_list.size() ) + parameters.addParameter< std::vector< String > >( option, string_list ); + if( bool_list.size() ) + parameters.addParameter< std::vector< bool > >( option, bool_list ); + if( integer_list.size() ) + parameters.addParameter< std::vector< int > >( option, integer_list ); + if( real_list.size() ) + parameters.addParameter< std::vector< double > >( option, real_list ); if( i < argc ) i --; continue; } diff --git a/src/TNL/Meshes/Readers/TNLReader.h b/src/TNL/Meshes/Readers/TNLReader.h index ba602b0f9..68f4d13a2 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 { @@ -34,8 +33,8 @@ public: return EXIT_FAILURE; } - Containers::List< String > parsedMeshType; - if( ! parseObjectType( objectType, parsedMeshType ) ) { + const std::vector< String > parsedMeshType = parseObjectType( objectType ); + if( ! parsedMeshType.size() ) { std::cerr << "Unable to parse the mesh type " << meshType << "." << std::endl; return false; } @@ -55,14 +54,17 @@ public: cellShape = EntityShape::Hexahedron; } else if( meshType == "Meshes::Mesh" ) { - Containers::List< String > parsedMeshConfig; - if( ! parseObjectType( parsedMeshType[ 1 ], parsedMeshConfig ) ) { + const std::vector< String > parsedMeshConfig = parseObjectType( parsedMeshType[ 1 ] ); + if( ! parsedMeshConfig.size() ) { std::cerr << "Unable to parse the mesh config type " << parsedMeshType[ 1 ] << "." << std::endl; return false; } - if( parsedMeshConfig.getSize() != 7 ) { - std::cerr << "The parsed mesh config type has wrong size (expected 7 elements):" << std::endl - << parsedMeshConfig << std::endl; + if( parsedMeshConfig.size() != 7 ) { + std::cerr << "The parsed mesh config type has wrong size (expected 7 elements):" << std::endl; + std::cerr << "[ "; + for( std::size_t i = 0; i < parsedMeshConfig.size() - 1; i++ ) + std::cerr << parsedMeshConfig[ i ] << ", "; + std::cerr << parsedMeshConfig.back() << " ]" << std::endl; return false; } diff --git a/src/TNL/Object.cpp b/src/TNL/Object.cpp index e83b2d0d7..c0cc9a446 100644 --- a/src/TNL/Object.cpp +++ b/src/TNL/Object.cpp @@ -130,11 +130,11 @@ bool getObjectType( const String& fileName, String& type ) return getObjectType( binaryFile, type ); } -bool parseObjectType( const String& objectType, - Containers::List< String >& parsedObjectType ) +std::vector< String > +parseObjectType( const String& objectType ) { - parsedObjectType.reset(); - int objectTypeLength = objectType. getLength(); + std::vector< String > parsedObjectType; + const int objectTypeLength = objectType.getLength(); int i = 0; /**** * The object type consists of the following: @@ -143,11 +143,10 @@ bool parseObjectType( const String& objectType, * character '<'. */ while( i < objectTypeLength && objectType[ i ] != '<' ) - i ++; - String objectName( objectType. getString(), 0, objectTypeLength - i ); - if( ! parsedObjectType. Append( objectName ) ) - return false; - i ++; + i++; + String objectName( objectType.getString(), 0, objectTypeLength - i ); + parsedObjectType.push_back( objectName ); + i++; /**** * Now, we will extract the parameters. @@ -160,7 +159,7 @@ bool parseObjectType( const String& objectType, while( i < objectTypeLength ) { if( objectType[ i ] == '<' ) - templateBrackets ++; + templateBrackets++; if( ! templateBrackets ) { if( objectType[ i ] == ',' || @@ -168,19 +167,19 @@ bool parseObjectType( const String& objectType, { if( buffer != "" ) { - if( ! parsedObjectType. Append( buffer.strip( ' ' ) ) ) - return false; - buffer. setString( "" ); + parsedObjectType.push_back( buffer.strip( ' ' ) ); + buffer.setString( "" ); } } else buffer += objectType[ i ]; } else buffer += objectType[ i ]; if( objectType[ i ] == '>' ) - templateBrackets --; - i ++; + templateBrackets--; + i++; } - return true; + + return parsedObjectType; } } // namespace TNL diff --git a/src/TNL/Object.h b/src/TNL/Object.h index 405bcd76d..e4fd274f8 100644 --- a/src/TNL/Object.h +++ b/src/TNL/Object.h @@ -10,10 +10,11 @@ #pragma once +#include + #include #include #include -#include namespace TNL { @@ -108,7 +109,7 @@ bool getObjectType( File& file, String& type ); bool getObjectType( const String& file_name, String& type ); -bool parseObjectType( const String& objectType, - Containers::List< String >& parsedObjectType ); +std::vector< String > +parseObjectType( const String& objectType ); } // namespace TNL diff --git a/src/TNL/param-types.h b/src/TNL/param-types.h index 58445912f..e7552d848 100644 --- a/src/TNL/param-types.h +++ b/src/TNL/param-types.h @@ -8,7 +8,9 @@ /* See Copyright Notice in tnl/Copyright */ -#pragma once +#pragma once + +#include #include #include @@ -16,7 +18,27 @@ namespace TNL { template< typename T > -String getType() { return T::getType(); } +String getType(); + +namespace __getType_impl { + +template< typename T > +struct getTypeHelper +{ + static String get() { return T::getType(); } +}; + +// wrappers for STL containers +template< typename T > +struct getTypeHelper< std::vector< T > > +{ + static String get() { return String( "std::vector< " ) + TNL::getType< T >() + " >"; } +}; + +} // namespace __getType_impl + +template< typename T > +String getType() { return __getType_impl::getTypeHelper< T >::get(); } // non-const specializations template<> inline String getType< void >() { return String( "void" ); } diff --git a/src/Tools/tnl-diff.cpp b/src/Tools/tnl-diff.cpp index 611cd53f4..360423de7 100644 --- a/src/Tools/tnl-diff.cpp +++ b/src/Tools/tnl-diff.cpp @@ -15,7 +15,7 @@ void setupConfig( Config::ConfigDescription& config ) { config.addEntry< String >( "mesh", "Input mesh file.", "mesh.tnl" ); - config.addRequiredEntry< Containers::List< String > >( "input-files", "The first set of the input files." ); + config.addRequiredList< String >( "input-files", "The first set of the input files." ); config.addEntry< String >( "output-file", "File for the output data.", "tnl-diff.log" ); config.addEntry< String >( "mode", "Mode 'couples' compares two subsequent files. Mode 'sequence' compares the input files against the first one. 'halves' compares the files from the and the second half of the intput files.", "couples" ); config.addEntryEnum< String >( "couples" ); @@ -42,7 +42,6 @@ int main( int argc, char* argv[] ) return 1; } - int verbose = parameters.getParameter< int >( "verbose" ); String meshFile = parameters.getParameter< String >( "mesh" ); /*if( meshFile == "" ) { @@ -57,8 +56,8 @@ int main( int argc, char* argv[] ) return EXIT_FAILURE; } std::cout << meshType << " detected in " << meshFile << " file." << std::endl; - Containers::List< String > parsedMeshType; - if( ! parseObjectType( meshType, parsedMeshType ) ) + const std::vector< String > parsedMeshType = parseObjectType( meshType ); + if( ! parsedMeshType.size() ) { std::cerr << "Unable to parse the mesh type " << meshType << "." << std::endl; return EXIT_FAILURE; @@ -66,7 +65,7 @@ int main( int argc, char* argv[] ) if( parsedMeshType[ 0 ] == "Meshes::Grid" || parsedMeshType[ 0 ] == "tnlGrid" ) // TODO: remove deprecated type name { - int dimensions = atoi( parsedMeshType[ 1 ].getString() ); + const int dimensions = atoi( parsedMeshType[ 1 ].getString() ); if( dimensions == 1 ) if( ! resolveGridRealType< 1 >( parsedMeshType, parameters ) ) return EXIT_FAILURE; diff --git a/src/Tools/tnl-diff.h b/src/Tools/tnl-diff.h index b070d0dfe..47d058de1 100644 --- a/src/Tools/tnl-diff.h +++ b/src/Tools/tnl-diff.h @@ -24,7 +24,7 @@ template< typename MeshPointer, typename Value, typename Real, typename Index > bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Config::ParameterContainer& parameters ) { bool verbose = parameters. getParameter< bool >( "verbose" ); - Containers::List< String > inputFiles = parameters. getParameter< Containers::List< String > >( "input-files" ); + std::vector< String > inputFiles = parameters. getParameter< std::vector< String > >( "input-files" ); String mode = parameters. getParameter< String >( "mode" ); String outputFileName = parameters. getParameter< String >( "output-file" ); double snapshotPeriod = parameters. getParameter< double >( "snapshot-period" ); @@ -53,12 +53,12 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con typedef typename MeshPointer::ObjectType Mesh; Functions::MeshFunction< Mesh, Mesh::getMeshDimension(), Real > v1( meshPointer ), v2( meshPointer ), diff( meshPointer ); Real totalL1Diff( 0.0 ), totalL2Diff( 0.0 ), totalMaxDiff( 0.0 ); - for( int i = 0; i < inputFiles. getSize(); i ++ ) + for( int i = 0; i < (int) inputFiles.size(); i ++ ) { String file1, file2; if( mode == "couples" ) { - if( i + 1 == inputFiles.getSize() ) + if( i + 1 == (int) inputFiles.size() ) { std::cerr << std::endl << "Skipping the file " << inputFiles[ i ] << " since there is no file to couple it with." << std::endl; outputFile.close(); @@ -105,7 +105,7 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con } if( mode == "halves" ) { - const int half = inputFiles. getSize() / 2; + const int half = inputFiles.size() / 2; if( i == 0 ) i = half; if( verbose ) @@ -178,7 +178,7 @@ template< typename MeshPointer, typename Value, typename Real, typename Index > bool computeDifferenceOfVectors( const MeshPointer& meshPointer, const Config::ParameterContainer& parameters ) { bool verbose = parameters. getParameter< bool >( "verbose" ); - Containers::List< String > inputFiles = parameters. getParameter< Containers::List< String > >( "input-files" ); + std::vector< String > inputFiles = parameters. getParameter< std::vector< String > >( "input-files" ); String mode = parameters. getParameter< String >( "mode" ); String outputFileName = parameters. getParameter< String >( "output-file" ); double snapshotPeriod = parameters. getParameter< double >( "snapshot-period" ); @@ -205,11 +205,11 @@ bool computeDifferenceOfVectors( const MeshPointer& meshPointer, const Config::P Containers::Vector< Real, Devices::Host, Index > v1, v2; Real totalL1Diff( 0.0 ), totalL2Diff( 0.0 ), totalMaxDiff( 0.0 ); - for( int i = 0; i < inputFiles. getSize(); i ++ ) + for( int i = 0; i < (int) inputFiles.size(); i++ ) { if( mode == "couples" ) { - if( i + 1 == inputFiles.getSize() ) + if( i + 1 == (int) inputFiles.size() ) { std::cerr << std::endl << "Skipping the file " << inputFiles[ i ] << " since there is no file to couple it with." << std::endl; outputFile.close(); @@ -252,7 +252,7 @@ bool computeDifferenceOfVectors( const MeshPointer& meshPointer, const Config::P } if( mode == "halves" ) { - const int half = inputFiles. getSize() / 2; + const int half = inputFiles.size() / 2; if( i == 0 ) i = half; if( verbose ) @@ -325,7 +325,7 @@ bool computeDifference( const MeshPointer& meshPointer, const String& objectType template< typename MeshPointer, typename Value, typename Real > bool setIndexType( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { String indexType; @@ -353,8 +353,8 @@ bool setIndexType( const MeshPointer& meshPointer, template< typename MeshPointer > bool setTupleType( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, - const Containers::List< String >& parsedValueType, + const std::vector< String >& parsedObjectType, + const std::vector< String >& parsedValueType, const Config::ParameterContainer& parameters ) { int dimensions = atoi( parsedValueType[ 1 ].getString() ); @@ -404,7 +404,7 @@ bool setTupleType( const MeshPointer& meshPointer, template< typename MeshPointer > bool setValueType( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { String elementType; @@ -428,8 +428,8 @@ bool setValueType( const MeshPointer& meshPointer, return setIndexType< MeshPointer, double, double >( meshPointer, inputFileName, parsedObjectType, parameters ); if( elementType == "long double" ) return setIndexType< MeshPointer, long double, long double >( meshPointer, inputFileName, parsedObjectType, parameters ); - Containers::List< String > parsedValueType; - if( ! parseObjectType( elementType, parsedValueType ) ) + const std::vector< String > parsedValueType = parseObjectType( elementType ); + if( ! parsedValueType.size() ) { std::cerr << "Unable to parse object type " << elementType << "." << std::endl; return false; @@ -445,8 +445,7 @@ template< typename Mesh > bool processFiles( const Config::ParameterContainer& parameters ) { int verbose = parameters. getParameter< int >( "verbose"); - Containers::List< String > inputFiles = parameters. getParameter< Containers::List< String > >( "input-files" ); - String& inputFile = inputFiles[ 0 ]; + std::vector< String > inputFiles = parameters. getParameter< std::vector< String > >( "input-files" ); /**** * Reading the mesh @@ -472,8 +471,8 @@ bool processFiles( const Config::ParameterContainer& parameters ) if( verbose ) std::cout << objectType << " detected ... "; - Containers::List< String > parsedObjectType; - if( ! parseObjectType( objectType, parsedObjectType ) ) + const std::vector< String > parsedObjectType = parseObjectType( objectType ); + if( ! parsedObjectType.size() ) { std::cerr << "Unable to parse object type " << objectType << "." << std::endl; return false; @@ -483,7 +482,7 @@ bool processFiles( const Config::ParameterContainer& parameters ) } template< int Dim, typename Real > -bool resolveGridIndexType( const Containers::List< String >& parsedMeshType, +bool resolveGridIndexType( const std::vector< String >& parsedMeshType, const Config::ParameterContainer& parameters ) { if( parsedMeshType[ 4 ] == "int" ) @@ -495,7 +494,7 @@ bool resolveGridIndexType( const Containers::List< String >& parsedMeshType, } template< int Dim > -bool resolveGridRealType( const Containers::List< String >& parsedMeshType, +bool resolveGridRealType( const std::vector< String >& parsedMeshType, const Config::ParameterContainer& parameters ) { if( parsedMeshType[ 2 ] == "float" ) @@ -508,4 +507,4 @@ bool resolveGridRealType( const Containers::List< String >& parsedMeshType, return false; } -#endif /* TNL_DIFF_H_ */ \ No newline at end of file +#endif /* TNL_DIFF_H_ */ diff --git a/src/Tools/tnl-image-converter.cpp b/src/Tools/tnl-image-converter.cpp index 29c633058..f06ba841d 100644 --- a/src/Tools/tnl-image-converter.cpp +++ b/src/Tools/tnl-image-converter.cpp @@ -43,7 +43,7 @@ void configSetup( Config::ConfigDescription& config ) template< typename Real > bool processImages( const Config::ParameterContainer& parameters ) { - const Containers::List< String >& inputImages = parameters.getParameter< Containers::List< String > >( "input-images" ); + const std::vector< String >& inputImages = parameters.getParameter< std::vector< String > >( "input-images" ); String meshFile = parameters.getParameter< String >( "mesh-file" ); bool verbose = parameters.getParameter< bool >( "verbose" ); @@ -54,7 +54,7 @@ bool processImages( const Config::ParameterContainer& parameters ) MeshFunctionType meshFunction; Images::RegionOfInterest< int > roi; - for( int i = 0; i < inputImages.getSize(); i++ ) + for( int i = 0; i < (int) inputImages.size(); i++ ) { const String& fileName = inputImages[ i ]; std::cout << "Processing image file " << fileName << "... "; @@ -145,10 +145,9 @@ bool processImages( const Config::ParameterContainer& parameters ) bool processFiles( const Config::ParameterContainer& parameters ) { - const Containers::List< String >& inputFiles = parameters.getParameter< Containers::List< String > >( "input-files" ); + const std::vector< String >& inputFiles = parameters.getParameter< std::vector< String > >( "input-files" ); const String& imageFormat = parameters.getParameter< String >( "image-format" ); String meshFile = parameters.getParameter< String >( "mesh-file" ); - bool verbose = parameters.getParameter< bool >( "verbose" ); Meshes::Grid< 2, double, Devices::Host, int > grid; if( ! grid.load( meshFile ) ) @@ -157,7 +156,7 @@ bool processFiles( const Config::ParameterContainer& parameters ) return false; } Containers::Vector< double, Devices::Host, int > vector; - for( int i = 0; i < inputFiles.getSize(); i++ ) + for( int i = 0; i < (int) inputFiles.size(); i++ ) { const String& fileName = inputFiles[ i ]; std::cout << "Processing file " << fileName << "... "; diff --git a/src/Tools/tnl-init.cpp b/src/Tools/tnl-init.cpp index 7dd703281..0695d62e1 100644 --- a/src/Tools/tnl-init.cpp +++ b/src/Tools/tnl-init.cpp @@ -70,8 +70,8 @@ int main( int argc, char* argv[] ) return EXIT_FAILURE; } std::cout << meshType << " detected in " << meshFile << " file." << std::endl; - Containers::List< String > parsedMeshType; - if( ! parseObjectType( meshType, parsedMeshType ) ) + std::vector< String > parsedMeshType = parseObjectType( meshType ); + if( ! parsedMeshType.size() ) { std::cerr << "Unable to parse the mesh type " << meshType << "." << std::endl; return EXIT_FAILURE; diff --git a/src/Tools/tnl-init.h b/src/Tools/tnl-init.h index 3f2a8f15f..5530ee5ad 100644 --- a/src/Tools/tnl-init.h +++ b/src/Tools/tnl-init.h @@ -264,7 +264,7 @@ bool resolveRealType( const Config::ParameterContainer& parameters ) template< int Dimension, typename RealType, typename IndexType > -bool resolveMesh( const Containers::List< String >& parsedMeshType, +bool resolveMesh( const std::vector< String >& parsedMeshType, const Config::ParameterContainer& parameters ) { std::cout << "+ -> Setting mesh type to " << parsedMeshType[ 0 ] << " ... " << std::endl; @@ -279,7 +279,7 @@ bool resolveMesh( const Containers::List< String >& parsedMeshType, } template< int Dimension, typename RealType > -bool resolveIndexType( const Containers::List< String >& parsedMeshType, +bool resolveIndexType( const std::vector< String >& parsedMeshType, const Config::ParameterContainer& parameters ) { std::cout << "+ -> Setting index type to " << parsedMeshType[ 4 ] << " ... " << std::endl; @@ -293,7 +293,7 @@ bool resolveIndexType( const Containers::List< String >& parsedMeshType, } template< int Dimension > -bool resolveRealType( const Containers::List< String >& parsedMeshType, +bool resolveRealType( const std::vector< String >& parsedMeshType, const Config::ParameterContainer& parameters ) { std::cout << "+ -> Setting real type to " << parsedMeshType[ 2 ] << " ... " << std::endl; @@ -309,7 +309,7 @@ bool resolveRealType( const Containers::List< String >& parsedMeshType, return false; } -bool resolveMeshType( const Containers::List< String >& parsedMeshType, +bool resolveMeshType( const std::vector< String >& parsedMeshType, const Config::ParameterContainer& parameters ) { std::cout << "+ -> Setting dimensions to " << parsedMeshType[ 1 ] << " ... " << std::endl; diff --git a/src/Tools/tnl-lattice-init.h b/src/Tools/tnl-lattice-init.h index b22e71f96..0b42a72ea 100644 --- a/src/Tools/tnl-lattice-init.h +++ b/src/Tools/tnl-lattice-init.h @@ -227,8 +227,8 @@ bool resolveProfileReal( const Config::ParameterContainer& parameters ) return EXIT_FAILURE; } //std::cout << meshFunctionType << " detected in " << profileFile << " file." << std::endl; - Containers::List< String > parsedMeshFunctionType; - if( ! parseObjectType( meshFunctionType, parsedMeshFunctionType ) ) + const std::vector< String > parsedMeshFunctionType = parseObjectType( meshFunctionType ); + if( ! parsedMeshFunctionType.size() ) { std::cerr << "Unable to parse the mesh function type " << meshFunctionType << "." << std::endl; return EXIT_FAILURE; @@ -259,7 +259,7 @@ bool resolveProfileReal( const Config::ParameterContainer& parameters ) } template< typename ProfileMesh, typename Real, typename MeshReal > -bool resolveMeshIndexType( const Containers::List< String >& parsedMeshType, +bool resolveMeshIndexType( const std::vector< String >& parsedMeshType, const Config::ParameterContainer& parameters ) { if( parsedMeshType[ 4 ] == "int" ) @@ -283,8 +283,8 @@ bool resolveMesh( const Config::ParameterContainer& parameters ) return EXIT_FAILURE; } std::cout << meshType << " detected in " << meshFile << " file." << std::endl; - Containers::List< String > parsedMeshType; - if( ! parseObjectType( meshType, parsedMeshType ) ) + const std::vector< String > parsedMeshType = parseObjectType( meshType ); + if( ! parsedMeshType.size() ) { std::cerr << "Unable to parse the mesh type " << meshType << "." << std::endl; return EXIT_FAILURE; @@ -325,7 +325,7 @@ bool resolveRealType( const Config::ParameterContainer& parameters ) } template< typename RealType, typename IndexType > -bool resolveProfileMesh( const Containers::List< String >& parsedMeshType, +bool resolveProfileMesh( const std::vector< String >& parsedMeshType, const Config::ParameterContainer& parameters ) { std::cout << "+ -> Setting mesh type to " << parsedMeshType[ 0 ] << " ... " << std::endl; @@ -339,7 +339,7 @@ bool resolveProfileMesh( const Containers::List< String >& parsedMeshType, } template< typename RealType > -bool resolveProfileMeshIndexType( const Containers::List< String >& parsedMeshType, +bool resolveProfileMeshIndexType( const std::vector< String >& parsedMeshType, const Config::ParameterContainer& parameters ) { std::cout << "+ -> Setting index type to " << parsedMeshType[ 4 ] << " ... " << std::endl; @@ -352,7 +352,7 @@ bool resolveProfileMeshIndexType( const Containers::List< String >& parsedMeshTy return false; } -bool resolveProfileMeshRealType( const Containers::List< String >& parsedMeshType, +bool resolveProfileMeshRealType( const std::vector< String >& parsedMeshType, const Config::ParameterContainer& parameters ) { std::cout << "+ -> Setting real type to " << parsedMeshType[ 2 ] << " ... " << std::endl; @@ -378,8 +378,8 @@ bool resolveProfileMeshType( const Config::ParameterContainer& parameters ) return EXIT_FAILURE; } std::cout << meshType << " detected in " << meshFile << " file." << std::endl; - Containers::List< String > parsedMeshType; - if( ! parseObjectType( meshType, parsedMeshType ) ) + const std::vector< String > parsedMeshType = parseObjectType( meshType ); + if( ! parsedMeshType.size() ) { std::cerr << "Unable to parse the mesh type " << meshType << "." << std::endl; return EXIT_FAILURE; diff --git a/src/Tools/tnl-view.h b/src/Tools/tnl-view.h index c231d606d..b5fa04ba9 100644 --- a/src/Tools/tnl-view.h +++ b/src/Tools/tnl-view.h @@ -110,7 +110,7 @@ template< typename MeshPointer, int VectorFieldSize > bool setMeshFunctionRealType( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { if( VectorFieldSize == 0 ) @@ -124,7 +124,7 @@ template< typename MeshPointer, typename = typename std::enable_if< EntityDimension <= MeshPointer::ObjectType::getMeshDimension() >::type > bool setMeshEntityType( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { if( parsedObjectType[ 3 ] == "float" ) @@ -144,7 +144,7 @@ template< typename MeshPointer, typename = void > bool setMeshEntityType( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { std::cerr << "Unsupported mesh functions entity dimension: " << EntityDimension << "." << std::endl; @@ -155,7 +155,7 @@ template< int VectorFieldSize, typename MeshPointer > bool setMeshEntityDimension( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { int meshEntityDimension = atoi( parsedObjectType[ 2 ].getString() ); @@ -182,7 +182,7 @@ bool setMeshEntityDimension( const MeshPointer& meshPointer, template< typename MeshPointer, int VectorFieldSize = 0 > bool setMeshFunction( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { std::cerr << parsedObjectType[ 1 ] << std::endl; @@ -197,12 +197,12 @@ bool setMeshFunction( const MeshPointer& meshPointer, template< typename MeshPointer > bool setVectorFieldSize( const MeshPointer& meshPointer, const String& inputFileName, - Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { int vectorFieldSize = atoi( parsedObjectType[ 1 ].getString() ); - Containers::List< String > parsedMeshFunctionType; - if( ! parseObjectType( parsedObjectType[ 2 ], parsedMeshFunctionType ) ) + const std::vector< String > parsedMeshFunctionType = parseObjectType( parsedObjectType[ 2 ] ); + if( ! parsedMeshFunctionType.size() ) { std::cerr << "Unable to parse mesh function type " << parsedObjectType[ 2 ] << " in a vector field." << std::endl; return false; @@ -223,7 +223,7 @@ bool setVectorFieldSize( const MeshPointer& meshPointer, template< typename MeshPointer, typename Value, typename Real, typename Index, int Dimension > bool convertObject( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { int verbose = parameters. getParameter< int >( "verbose"); @@ -275,7 +275,7 @@ bool convertObject( const MeshPointer& meshPointer, template< typename MeshPointer, typename Value, typename Real, typename Index > bool setDimension( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { int dimensions( 0 ); @@ -303,7 +303,7 @@ bool setDimension( const MeshPointer& meshPointer, template< typename MeshPointer, typename Value, typename Real > bool setIndexType( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { String indexType; @@ -327,8 +327,8 @@ bool setIndexType( const MeshPointer& meshPointer, template< typename MeshPointer > bool setTupleType( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, - const Containers::List< String >& parsedValueType, + const std::vector< String >& parsedObjectType, + const std::vector< String >& parsedValueType, const Config::ParameterContainer& parameters ) { int dimensions = atoi( parsedValueType[ 1 ].getString() ); @@ -378,7 +378,7 @@ bool setTupleType( const MeshPointer& meshPointer, template< typename MeshPointer > bool setValueType( const MeshPointer& meshPointer, const String& inputFileName, - const Containers::List< String >& parsedObjectType, + const std::vector< String >& parsedObjectType, const Config::ParameterContainer& parameters ) { String elementType; @@ -400,8 +400,8 @@ bool setValueType( const MeshPointer& meshPointer, return setIndexType< MeshPointer, double, double >( meshPointer, inputFileName, parsedObjectType, parameters ); if( elementType == "long double" ) return setIndexType< MeshPointer, long double, long double >( meshPointer, inputFileName, parsedObjectType, parameters ); - Containers::List< String > parsedValueType; - if( ! parseObjectType( elementType, parsedValueType ) ) + const std::vector< String > parsedValueType = parseObjectType( elementType ); + if( ! parsedValueType.size() ) { std::cerr << "Unable to parse object type " << elementType << "." << std::endl; return false; @@ -433,12 +433,12 @@ struct FilesProcessor } bool checkOutputFile = parameters. getParameter< bool >( "check-output-file" ); - Containers::List< String > inputFiles = parameters. getParameter< Containers::List< String > >( "input-files" ); + std::vector< String > inputFiles = parameters. getParameter< std::vector< String > >( "input-files" ); bool error( false ); //#ifdef HAVE_OPENMP //#pragma omp parallel for //#endif - for( int i = 0; i < inputFiles. getSize(); i ++ ) + for( int i = 0; i < (int) inputFiles.size(); i++ ) { if( verbose ) std::cout << "Processing file " << inputFiles[ i ] << " ... " << std::flush; @@ -467,8 +467,8 @@ struct FilesProcessor if( verbose ) std::cout << objectType << " detected ... "; - Containers::List< String > parsedObjectType; - if( ! parseObjectType( objectType, parsedObjectType ) ) + const std::vector< String > parsedObjectType = parseObjectType( objectType ); + if( ! parsedObjectType.size() ) { std::cerr << "Unable to parse object type " << objectType << "." << std::endl; error = true; diff --git a/src/UnitTests/ObjectTest.cpp b/src/UnitTests/ObjectTest.cpp index 7b9badd8f..488f7a497 100644 --- a/src/UnitTests/ObjectTest.cpp +++ b/src/UnitTests/ObjectTest.cpp @@ -35,72 +35,44 @@ TEST( ObjectTest, SaveAndLoadTest ) TEST( ObjectTest, parseObjectTypeTest ) { - Containers::List< String > parsed; - Containers::List< String > expected; + std::vector< String > parsed; + std::vector< String > expected; // plain type - parsed.reset(); - expected.reset(); - ASSERT_TRUE( parseObjectType( "int", parsed ) ); - expected.Append( "int" ); + parsed = parseObjectType( "int" ); + expected = {"int"}; EXPECT_EQ( parsed, expected ); // type with space - parsed.reset(); - expected.reset(); - ASSERT_TRUE( parseObjectType( "short int", parsed ) ); - expected.Append( "short int" ); + parsed = parseObjectType( "short int" ); + expected = {"short int"}; EXPECT_EQ( parsed, expected ); - parsed.reset(); - expected.reset(); - ASSERT_TRUE( parseObjectType( "unsigned short int", parsed ) ); - expected.Append( "unsigned short int" ); + parsed = parseObjectType( "unsigned short int" ); + expected = {"unsigned short int"}; EXPECT_EQ( parsed, expected ); // composed type - parsed.reset(); - expected.reset(); - ASSERT_TRUE( parseObjectType( "Containers::Vector< double, Devices::Host, int >", parsed ) ); - expected.Append( "Containers::Vector" ); - expected.Append( "double" ); - expected.Append( "Devices::Host" ); - expected.Append( "int" ); + parsed = parseObjectType( "Containers::Vector< double, Devices::Host, int >" ); + expected = { "Containers::Vector", "double", "Devices::Host", "int" }; EXPECT_EQ( parsed, expected ); - parsed.reset(); - expected.reset(); - ASSERT_TRUE( parseObjectType( "Containers::Vector< Containers::List< String >, Devices::Host, int >", parsed ) ); - expected.Append( "Containers::Vector" ); - expected.Append( "Containers::List< String >" ); - expected.Append( "Devices::Host" ); - expected.Append( "int" ); + parsed = parseObjectType( "Containers::Vector< Containers::List< String >, Devices::Host, int >" ); + expected = { "Containers::Vector", "Containers::List< String >", "Devices::Host", "int" }; EXPECT_EQ( parsed, expected ); // spaces in the template parameter - parsed.reset(); - expected.reset(); - ASSERT_TRUE( parseObjectType( "A< short int >", parsed ) ); - expected.Append( "A" ); - expected.Append( "short int" ); + parsed = parseObjectType( "A< short int >" ); + expected = { "A", "short int" }; EXPECT_EQ( parsed, expected ); - parsed.reset(); - expected.reset(); - ASSERT_TRUE( parseObjectType( "A< B< short int >, C >", parsed ) ); - expected.Append( "A" ); - expected.Append( "B< short int >" ); - expected.Append( "C" ); + parsed = parseObjectType( "A< B< short int >, C >" ); + expected = { "A", "B< short int >", "C" }; EXPECT_EQ( parsed, expected ); // spaces at different places in the template parameter - parsed.reset(); - expected.reset(); - ASSERT_TRUE( parseObjectType( "A< b , c ,d>", parsed ) ); - expected.Append( "A" ); - expected.Append( "b" ); - expected.Append( "c " ); - expected.Append( "d" ); + parsed = parseObjectType( "A< b , c ,d>" ); + expected = { "A", "b", "c ", "d" }; EXPECT_EQ( parsed, expected ); } #endif -- GitLab From 536010374e3a5b59928c1e2d9cbf6e857f3cc778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 10:57:42 +0100 Subject: [PATCH 20/39] Fixed ConfigDescription --- src/TNL/Config/ConfigDescription.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/TNL/Config/ConfigDescription.h b/src/TNL/Config/ConfigDescription.h index 2f05be6dd..6aa1c52f8 100644 --- a/src/TNL/Config/ConfigDescription.h +++ b/src/TNL/Config/ConfigDescription.h @@ -181,6 +181,10 @@ public: */ const ConfigEntryBase* getEntry( const String& name ) const { + // ConfigDelimiter has empty name + if( ! name ) + return nullptr; + const int entries_num = entries.size(); for( int i = 0; i < entries_num; i++ ) if( entries[ i ]->name == name ) @@ -196,6 +200,10 @@ public: template< class T > const T* getDefaultValue( const String& name ) const { + // ConfigDelimiter has empty name + if( ! name ) + return nullptr; + const int entries_num = entries.size(); for( int i = 0; i < entries_num; i++ ) if( entries[ i ]->name == name ) { @@ -213,6 +221,10 @@ public: template< class T > T* getDefaultValue( const String& name ) { + // ConfigDelimiter has empty name + if( ! name ) + return nullptr; + const int entries_num = entries.size(); for( int i = 0; i < entries_num; i++ ) if( entries[ i ] -> name == name ) { @@ -223,7 +235,7 @@ public: return nullptr; } std::cerr << "Asking for the default value of unknown parameter." << std::endl; - return NULL; + return nullptr; } /** -- GitLab From 35b0e1055da40101ba544d31771427e352c41e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 13:23:05 +0100 Subject: [PATCH 21/39] Moved stuff from ConfigDescription.cpp and ParameterContainer.cpp into header files --- src/TNL/Config/CMakeLists.txt | 22 +-- src/TNL/Config/ConfigDescription.cpp | 146 ------------------ src/TNL/Config/ConfigDescription.h | 135 ++++++++++++++-- src/TNL/Config/ParameterContainer.h | 144 ++++++++++++----- src/TNL/Config/make_unique.h | 15 ++ ...ameterContainer.cpp => parseCommandLine.h} | 146 +++++------------- 6 files changed, 275 insertions(+), 333 deletions(-) delete mode 100644 src/TNL/Config/ConfigDescription.cpp create mode 100644 src/TNL/Config/make_unique.h rename src/TNL/Config/{ParameterContainer.cpp => parseCommandLine.h} (63%) diff --git a/src/TNL/Config/CMakeLists.txt b/src/TNL/Config/CMakeLists.txt index 3e11699a7..b88a173fe 100644 --- a/src/TNL/Config/CMakeLists.txt +++ b/src/TNL/Config/CMakeLists.txt @@ -1,25 +1,13 @@ -SET( headers +SET( headers ConfigEntryType.h ConfigEntryBase.h ConfigEntry.h ConfigEntryList.h ConfigDelimiter.h - ConfigDescription.h + ConfigDescription.h + make_unique.h ParameterContainer.h - ) - -SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL/Config ) -set( common_SOURCES - ${CURRENT_DIR}/ConfigDescription.cpp - ${CURRENT_DIR}/ParameterContainer.cpp ) -SET( tnl_config_SOURCES - ${common_SOURCES} - PARENT_SCOPE ) - -if( BUILD_CUDA ) -SET( tnl_config_CUDA__SOURCES - ${common_SOURCES} - PARENT_SCOPE ) -endif() + parseCommandLine.h +) INSTALL( FILES ${headers} DESTINATION ${TNL_TARGET_INCLUDE_DIRECTORY}/Config ) diff --git a/src/TNL/Config/ConfigDescription.cpp b/src/TNL/Config/ConfigDescription.cpp deleted file mode 100644 index e8859523c..000000000 --- a/src/TNL/Config/ConfigDescription.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/*************************************************************************** - Config::ConfigDescription.cpp - description - ------------------- - begin : 2007/06/09 - copyright : (C) 2007 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#include -#include -#include - -#include -#include - -namespace TNL { -namespace Config { - -void -ConfigDescription:: -printUsage( const char* program_name ) const -{ - std::cout << "Usage of: " << program_name << std::endl << std::endl; - const int entries_num = entries.size(); - int max_name_length( 0 ); - int max_type_length( 0 ); - for( int j = 0; j < entries_num; j++ ) - if( ! entries[ j ]->isDelimiter() ) - { - max_name_length = std::max( max_name_length, - entries[ j ] -> name. getLength() ); - max_type_length = std::max( max_type_length, - entries[ j ] -> getUIEntryType().getLength() ); - } - max_name_length += 2; // this is for '--' - - for( int j = 0; j < entries_num; j++ ) - { - if( entries[ j ]->isDelimiter() ) - { - std::cout << std::endl; - std::cout << entries[ j ]->description; - std::cout << std::endl << std::endl; - } - else - { - std::cout << std::setw( max_name_length + 3 ) << String( "--" ) + entries[ j ]->name - << std::setw( max_type_length + 5 ) << entries[ j ] -> getUIEntryType() - << " " << entries[ j ]->description; - if( entries[ j ] -> required ) - std::cout << " *** REQUIRED ***"; - if( entries[ j ]->hasEnumValues() ) - { - std::cout << std::endl - << std::setw( max_name_length + 3 ) << "" - << std::setw( max_type_length + 5 ) << "" - << " "; - entries[ j ]->printEnumValues(); - } - if( entries[ j ]->hasDefaultValue ) - { - std::cout << std::endl - << std::setw( max_name_length + 3 ) << "" - << std::setw( max_type_length + 5 ) << "" - << " "; - std::cout << "- Default value is: " << entries[ j ]->printDefaultValue(); - } - std::cout << std::endl; - } - } - std::cout << std::endl; -} - -void -ConfigDescription:: -addMissingEntries( Config::ParameterContainer& parameter_container ) const -{ - const int size = entries.size(); - for( int i = 0; i < size; i++ ) - { - const char* entry_name = entries[ i ]->name.getString(); - if( entries[ i ]->hasDefaultValue && - ! parameter_container.checkParameter( entry_name ) ) - { - if( entries[ i ]->getEntryType() == "String" ) - { - ConfigEntry< String >& entry = dynamic_cast< ConfigEntry< String >& >( *entries[ i ] ); - parameter_container.addParameter< String >( entry_name, entry.defaultValue ); - continue; - } - if( entries[ i ]->getEntryType() == "bool" ) - { - ConfigEntry< bool >& entry = dynamic_cast< ConfigEntry< bool >& >( *entries[ i ] ); - parameter_container.addParameter< bool >( entry_name, entry.defaultValue ); - continue; - } - if( entries[ i ]->getEntryType() == "int" ) - { - ConfigEntry< int >& entry = dynamic_cast< ConfigEntry< int >& >( *entries[ i ] ); - parameter_container.addParameter< int >( entry_name, entry.defaultValue ); - continue; - } - if( entries[ i ]->getEntryType() == "double" ) - { - ConfigEntry< double >& entry = dynamic_cast< ConfigEntry< double >& >( *entries[ i ] ); - parameter_container.addParameter< double >( entry_name, entry.defaultValue ); - continue; - } - } - } -} - -bool -Config::ConfigDescription:: -checkMissingEntries( Config::ParameterContainer& parameter_container, - bool printUsage, - const char* programName ) const -{ - const int size = entries.size(); - std::vector< std::string > missingParameters; - for( int i = 0; i < size; i++ ) - { - const char* entry_name = entries[ i ] -> name.getString(); - if( entries[ i ] -> required && - ! parameter_container.checkParameter( entry_name ) ) - missingParameters.push_back( entry_name ); - } - if( missingParameters.size() > 0 ) - { - std::cerr << "Some mandatory parameters are misssing. They are listed at the end. " << std::endl; - if( printUsage ) - this->printUsage( programName ); - std::cerr << "Add the following missing parameters to the command line: " << std::endl << " "; - for( int i = 0; i < (int) missingParameters.size(); i++ ) - std::cerr << "--" << missingParameters[ i ] << " ... "; - std::cerr << std::endl; - return false; - } - return true; -} - -} // namespace Config -} // namespace TNL - diff --git a/src/TNL/Config/ConfigDescription.h b/src/TNL/Config/ConfigDescription.h index 6aa1c52f8..7d05b0976 100644 --- a/src/TNL/Config/ConfigDescription.h +++ b/src/TNL/Config/ConfigDescription.h @@ -10,20 +10,11 @@ #pragma once +#include +#include #include #include - -// std::make_unique does not exist until C++14 -// https://stackoverflow.com/a/9657991 -#if __cplusplus < 201402L -namespace std { - template - std::unique_ptr make_unique( Args&& ...args ) - { - return std::unique_ptr( new T( std::forward(args)... ) ); - } -} -#endif +#include "make_unique.h" #include #include @@ -32,12 +23,11 @@ namespace std { #include #include #include +#include namespace TNL { namespace Config { -class ParameterContainer; - class ConfigDescription { public: @@ -245,21 +235,130 @@ public: * If there is missing entry with defined default value in the Config::ParameterContainer it is going to be added. * \param parameter_container Name of the ParameterContainer object. */ - void addMissingEntries( Config::ParameterContainer& parameter_container ) const; + void addMissingEntries( Config::ParameterContainer& parameter_container ) const + { + const int size = entries.size(); + for( int i = 0; i < size; i++ ) + { + const char* entry_name = entries[ i ]->name.getString(); + if( entries[ i ]->hasDefaultValue && + ! parameter_container.checkParameter( entry_name ) ) + { + if( entries[ i ]->getEntryType() == "String" ) + { + ConfigEntry< String >& entry = dynamic_cast< ConfigEntry< String >& >( *entries[ i ] ); + parameter_container.addParameter< String >( entry_name, entry.defaultValue ); + continue; + } + if( entries[ i ]->getEntryType() == "bool" ) + { + ConfigEntry< bool >& entry = dynamic_cast< ConfigEntry< bool >& >( *entries[ i ] ); + parameter_container.addParameter< bool >( entry_name, entry.defaultValue ); + continue; + } + if( entries[ i ]->getEntryType() == "int" ) + { + ConfigEntry< int >& entry = dynamic_cast< ConfigEntry< int >& >( *entries[ i ] ); + parameter_container.addParameter< int >( entry_name, entry.defaultValue ); + continue; + } + if( entries[ i ]->getEntryType() == "double" ) + { + ConfigEntry< double >& entry = dynamic_cast< ConfigEntry< double >& >( *entries[ i ] ); + parameter_container.addParameter< double >( entry_name, entry.defaultValue ); + continue; + } + } + } + } //! Check for all entries with the flag 'required'. /*! Returns false if any parameter is missing. */ bool checkMissingEntries( Config::ParameterContainer& parameter_container, bool printUsage, - const char* programName ) const; + const char* programName ) const + { + const int size = entries.size(); + std::vector< std::string > missingParameters; + for( int i = 0; i < size; i++ ) + { + const char* entry_name = entries[ i ] -> name.getString(); + if( entries[ i ] -> required && + ! parameter_container.checkParameter( entry_name ) ) + missingParameters.push_back( entry_name ); + } + if( missingParameters.size() > 0 ) + { + std::cerr << "Some mandatory parameters are misssing. They are listed at the end. " << std::endl; + if( printUsage ) + this->printUsage( programName ); + std::cerr << "Add the following missing parameters to the command line: " << std::endl << " "; + for( int i = 0; i < (int) missingParameters.size(); i++ ) + std::cerr << "--" << missingParameters[ i ] << " ... "; + std::cerr << std::endl; + return false; + } + return true; + } /** * \brief Prints configuration description with the \e program_name at the top. * * \param program_name Name of the program */ - void printUsage( const char* program_name ) const; + void printUsage( const char* program_name ) const + { + std::cout << "Usage of: " << program_name << std::endl << std::endl; + const int entries_num = entries.size(); + int max_name_length( 0 ); + int max_type_length( 0 ); + for( int j = 0; j < entries_num; j++ ) + if( ! entries[ j ]->isDelimiter() ) + { + max_name_length = std::max( max_name_length, + entries[ j ] -> name. getLength() ); + max_type_length = std::max( max_type_length, + entries[ j ] -> getUIEntryType().getLength() ); + } + max_name_length += 2; // this is for '--' + + for( int j = 0; j < entries_num; j++ ) + { + if( entries[ j ]->isDelimiter() ) + { + std::cout << std::endl; + std::cout << entries[ j ]->description; + std::cout << std::endl << std::endl; + } + else + { + std::cout << std::setw( max_name_length + 3 ) << String( "--" ) + entries[ j ]->name + << std::setw( max_type_length + 5 ) << entries[ j ] -> getUIEntryType() + << " " << entries[ j ]->description; + if( entries[ j ] -> required ) + std::cout << " *** REQUIRED ***"; + if( entries[ j ]->hasEnumValues() ) + { + std::cout << std::endl + << std::setw( max_name_length + 3 ) << "" + << std::setw( max_type_length + 5 ) << "" + << " "; + entries[ j ]->printEnumValues(); + } + if( entries[ j ]->hasDefaultValue ) + { + std::cout << std::endl + << std::setw( max_name_length + 3 ) << "" + << std::setw( max_type_length + 5 ) << "" + << " "; + std::cout << "- Default value is: " << entries[ j ]->printDefaultValue(); + } + std::cout << std::endl; + } + } + std::cout << std::endl; + } //bool parseConfigDescription( const char* file_name ); @@ -270,3 +369,5 @@ protected: } //namespace Config } //namespace TNL + +#include diff --git a/src/TNL/Config/ParameterContainer.h b/src/TNL/Config/ParameterContainer.h index 632865f0d..209b77a7c 100644 --- a/src/TNL/Config/ParameterContainer.h +++ b/src/TNL/Config/ParameterContainer.h @@ -12,8 +12,8 @@ #include #include +#include "make_unique.h" -#include #include //#include @@ -58,14 +58,25 @@ public: */ template< class T > bool addParameter( const String& name, - const T& value ); + const T& value ) + { + parameters.push_back( std::make_unique< Parameter< T > >( name, TNL::getType< T >(), value ) ); + return true; + } /** * \brief Checks whether the parameter \e name already exists in ParameterContainer. * * \param name Name of the parameter. */ - bool checkParameter( const String& name ) const; + bool checkParameter( const String& name ) const + { + const int size = parameters.size(); + for( int i = 0; i < size; i++ ) + if( parameters[ i ]->name == name ) + return true; + return false; + } /** * \brief Assigns new \e value to the parameter \e name. @@ -76,7 +87,25 @@ public: */ template< class T > bool setParameter( const String& name, - const T& value ); + const T& value ) + { + for( int i = 0; i < (int) parameters.size(); i++ ) { + if( parameters[ i ]->name == name ) { + if( parameters[ i ]->type == TNL::getType< T >() ) { + Parameter< T >& parameter = dynamic_cast< Parameter< T >& >( *parameters[ i ] ); + parameter.value = value; + return true; + } + else { + std::cerr << "Parameter " << name << " already exists with different type " + << parameters[ i ]->type << " not " + << TNL::getType< T >() << std::endl; + throw 0; + } + } + } + return addParameter< T >( name, value ); + } /** * \brief Checks whether the parameter \e name is given the \e value. @@ -133,49 +162,80 @@ public: throw 0; } +/* //! Broadcast to other nodes in MPI cluster - //void MPIBcast( int root, MPI_Comm mpi_comm = MPI_COMM_WORLD ); - -protected: - std::vector< std::unique_ptr< ParameterBase > > parameters; -}; - -bool parseCommandLine( int argc, char* argv[], - const ConfigDescription& config_description, - ParameterContainer& parameters, - bool printUsage = true ); - -template< class T > -bool -ParameterContainer:: -addParameter( const String& name, const T& value ) -{ - parameters.push_back( std::make_unique< Parameter< T > >( name, TNL::getType< T >(), value ) ); - return true; -}; - -template< class T > -bool -ParameterContainer:: -setParameter( const String& name, - const T& value ) -{ - for( int i = 0; i < (int) parameters.size(); i++ ) { - if( parameters[ i ]->name == name ) { - if( parameters[ i ]->type == TNL::getType< T >() ) { - Parameter< T >& parameter = dynamic_cast< Parameter< T >& >( *parameters[ i ] ); - parameter.value = value; - return true; + void MPIBcast( int root, MPI_Comm mpi_comm = MPI_COMM_WORLD ) + { + #ifdef USE_MPI + int i; + int size = parameters. getSize(); + :: MPIBcast( size, 1, root, mpi_comm ); + for( i = 0; i < size; i ++ ) + { + if( MPIGetRank() == root ) + { + tnlParameterBase* param = parameters[ i ]; + param -> type. MPIBcast( root, MPI_COMM_WORLD ); + param -> name. MPIBcast( root, MPI_COMM_WORLD ); + if( param -> type == "String" ) + { + ( ( tnlParameter< String >* ) param ) -> value. MPIBcast( root, mpi_comm ); + } + if( param -> type == "bool" ) + { + :: MPIBcast( ( ( tnlParameter< bool >* ) param ) -> value, 1, root, mpi_comm ); + } + if( param -> type == "int" ) + { + :: MPIBcast( ( ( tnlParameter< int >* ) param ) -> value, 1, root, mpi_comm ); + } + if( param -> type == "double" ) + { + :: MPIBcast( ( ( tnlParameter< double >* ) param ) -> value, 1, root, mpi_comm ); + } } - else { - std::cerr << "Parameter " << name << " already exists with different type " - << parameters[ i ]->type << " not " - << TNL::getType< T >() << std::endl; - throw 0; + else + { + String param_type, param_name; + param_type. MPIBcast( root, MPI_COMM_WORLD ); + param_name. MPIBcast( root, MPI_COMM_WORLD ); + if( param_type == "mString" ) + { + String val; + val. MPIBcast( root, mpi_comm ); + addParameter< String >( param_name. getString(), + val ); + } + if( param_type == "bool" ) + { + bool val; + :: MPIBcast( val, 1, root, mpi_comm ); + addParameter< bool >( param_name. getString(), + val ); + } + if( param_type == "int" ) + { + int val; + :: MPIBcast( val, 1, root, mpi_comm ); + addParameter< int >( param_name. getString(), + val ); + } + if( param_type == "double" ) + { + double val; + :: MPIBcast( val, 1, root, mpi_comm ); + addParameter< double >( param_name. getString(), + val ); + } + } } + #endif } - return addParameter< T >( name, value ); +*/ + +protected: + std::vector< std::unique_ptr< ParameterBase > > parameters; }; } // namespace Config diff --git a/src/TNL/Config/make_unique.h b/src/TNL/Config/make_unique.h new file mode 100644 index 000000000..4a4078a02 --- /dev/null +++ b/src/TNL/Config/make_unique.h @@ -0,0 +1,15 @@ +#pragma once + +// std::make_unique does not exist until C++14 +// https://stackoverflow.com/a/9657991 +#if __cplusplus < 201402L +#include + +namespace std { + template + std::unique_ptr make_unique( Args&& ...args ) + { + return std::unique_ptr( new T( std::forward(args)... ) ); + } +} +#endif diff --git a/src/TNL/Config/ParameterContainer.cpp b/src/TNL/Config/parseCommandLine.h similarity index 63% rename from src/TNL/Config/ParameterContainer.cpp rename to src/TNL/Config/parseCommandLine.h index f318acabb..2c8c62090 100644 --- a/src/TNL/Config/ParameterContainer.cpp +++ b/src/TNL/Config/parseCommandLine.h @@ -1,5 +1,5 @@ /*************************************************************************** - Config::ParameterContainer.cpp - description + parseCommandLine.h - description ------------------- begin : 2007/06/15 copyright : (C) 2007 by Tomas Oberhuber @@ -8,121 +8,47 @@ /* See Copyright Notice in tnl/Copyright */ -#include +#pragma once + #include -#include +#include -#include "ParameterContainer.h" -#include +//#include +#include +#include namespace TNL { -namespace Config { - -bool matob( const char* value, bool& ret_val ) -{ - if( strcasecmp( value, "yes" ) == 0 || - strcasecmp( value, "true" ) == 0 ) - { - ret_val = true; - return true; - } - if( strcasecmp( value, "no" ) == 0 || - strcasecmp( value, "false" ) == 0 ) - { - ret_val = false; - return true; - } - return false; -} - -bool -Config::ParameterContainer:: -checkParameter( const String& name ) const -{ - const int size = parameters.size(); - for( int i = 0; i < size; i++ ) - if( parameters[ i ]->name == name ) - return true; - return false; -} - -/*void ParameterContainer::MPIBcast( int root, MPI_Comm mpi_comm ) -{ -#ifdef USE_MPI - int i; - int size = parameters. getSize(); - :: MPIBcast( size, 1, root, mpi_comm ); - for( i = 0; i < size; i ++ ) - { - if( MPIGetRank() == root ) - { - tnlParameterBase* param = parameters[ i ]; - param -> type. MPIBcast( root, MPI_COMM_WORLD ); - param -> name. MPIBcast( root, MPI_COMM_WORLD ); - if( param -> type == "String" ) - { - ( ( tnlParameter< String >* ) param ) -> value. MPIBcast( root, mpi_comm ); - } - if( param -> type == "bool" ) - { - :: MPIBcast( ( ( tnlParameter< bool >* ) param ) -> value, 1, root, mpi_comm ); - } - if( param -> type == "int" ) - { - :: MPIBcast( ( ( tnlParameter< int >* ) param ) -> value, 1, root, mpi_comm ); - } - if( param -> type == "double" ) - { - :: MPIBcast( ( ( tnlParameter< double >* ) param ) -> value, 1, root, mpi_comm ); - } - } - else - { - String param_type, param_name; - param_type. MPIBcast( root, MPI_COMM_WORLD ); - param_name. MPIBcast( root, MPI_COMM_WORLD ); - if( param_type == "mString" ) - { - String val; - val. MPIBcast( root, mpi_comm ); - addParameter< String >( param_name. getString(), - val ); - } - if( param_type == "bool" ) - { - bool val; - :: MPIBcast( val, 1, root, mpi_comm ); - addParameter< bool >( param_name. getString(), - val ); - } - if( param_type == "int" ) - { - int val; - :: MPIBcast( val, 1, root, mpi_comm ); - addParameter< int >( param_name. getString(), - val ); - } - if( param_type == "double" ) - { - double val; - :: MPIBcast( val, 1, root, mpi_comm ); - addParameter< double >( param_name. getString(), - val ); - } - } - } -#endif -} -*/ +std::vector< String > +parseObjectType( const String& objectType ); +namespace Config { -bool +inline bool parseCommandLine( int argc, char* argv[], const Config::ConfigDescription& config_description, Config::ParameterContainer& parameters, - bool printUsage ) + bool printUsage = true ) { + auto iequals = []( const std::string& a, const std::string& b ) + { + if( a.size() != b.size() ) + return false; + for( unsigned int i = 0; i < a.size(); i++ ) + if( std::tolower(a[i]) != std::tolower(b[i]) ) + return false; + return true; + }; + + auto matob = [iequals]( const char* value ) + { + if( iequals( value, "yes" ) || iequals( value, "true" ) ) + return true; + if( iequals( value, "no" ) || iequals( value, "false" ) ) + return true; + return false; + }; + int i; bool parse_error( false ); for( i = 1; i < argc; i ++ ) @@ -177,13 +103,12 @@ parseCommandLine( int argc, char* argv[], } if( parsedEntryType[ 1 ] == "bool" ) { - bool bool_val; - if( ! matob( value, bool_val ) ) + if( ! matob( value ) ) { std::cerr << "Yes/true or no/false is required for the parameter " << option << "." << std::endl; parse_error = true; } - else bool_list.push_back( bool_val ); + else bool_list.push_back( true ); } if( parsedEntryType[ 1 ] == "int" ) { @@ -216,13 +141,12 @@ parseCommandLine( int argc, char* argv[], } if( parsedEntryType[ 0 ] == "bool" ) { - bool bool_val; - if( ! matob( value, bool_val ) ) + if( ! matob( value ) ) { std::cerr << "Yes/true or no/false is required for the parameter " << option << "." << std::endl; parse_error = true; } - else parameters.addParameter< bool >( option, bool_val ); + else parameters.addParameter< bool >( option, true ); continue; } if( parsedEntryType[ 0 ] == "int" ) -- GitLab From c573f43c7a6ec5d31075447eae319ef874a9ea24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 13:44:46 +0100 Subject: [PATCH 22/39] Moved stuff from Logger.cpp to Logger_impl.h --- src/TNL/CMakeLists.txt | 1 - src/TNL/Logger.cpp | 57 ------------------------------- src/TNL/Logger.h | 12 +++---- src/TNL/Logger_impl.h | 77 ++++++++++++++++++++++++++++++++---------- 4 files changed, 66 insertions(+), 81 deletions(-) delete mode 100644 src/TNL/Logger.cpp diff --git a/src/TNL/CMakeLists.txt b/src/TNL/CMakeLists.txt index 4a4484eea..fdf140c50 100644 --- a/src/TNL/CMakeLists.txt +++ b/src/TNL/CMakeLists.txt @@ -39,7 +39,6 @@ set( headers set( common_SOURCES FileName.cpp Object.cpp - Logger.cpp String.cpp Timer.cpp ) diff --git a/src/TNL/Logger.cpp b/src/TNL/Logger.cpp deleted file mode 100644 index 988d4ed68..000000000 --- a/src/TNL/Logger.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - Logger.cpp - description - ------------------- - begin : 2007/08/22 - copyright : (C) 2007 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#include -#include -#include -#include - -namespace TNL { - -Logger :: Logger( int _width, std::ostream& _stream ) -: width( _width ), - stream( _stream ) -{ -} - -void Logger :: writeHeader( const String& title ) -{ - int fill = stream. fill(); - int titleLength = title. getLength(); - stream << "+" << std::setfill( '-' ) << std::setw( width ) << "+" << std::endl; - stream << "|" << std::setfill( ' ' ) << std::setw( width ) << "|" << std::endl; - stream << "|" << std::setw( width / 2 + titleLength / 2 ) - << title << std::setw( width / 2 - titleLength / 2 ) << "|" << std::endl; - stream << "|" << std::setfill( ' ' ) << std::setw( width ) << "|" << std::endl; - stream << "+" << std::setfill( '-' ) << std::setw( width ) << "+" << std::endl; - stream. fill( fill ); -} - -void Logger :: writeSeparator() -{ - int fill = stream. fill(); - stream << "+" << std::setfill( '-' ) << std::setw( width ) << "+" << std::endl; - stream. fill( fill ); -} - -bool Logger :: writeSystemInformation( const Config::ParameterContainer& parameters ) -{ - Devices::SystemInfo::writeDeviceInfo( *this ); - if( parameters.getParameter< String >( "device" ) == "cuda" ) - Devices::CudaDeviceInfo::writeDeviceInfo( *this ); - return true; -} - -void Logger :: writeCurrentTime( const char* label ) -{ - writeParameter< String >( label, Devices::SystemInfo::getCurrentTime() ); -} - -} // namespace TNL diff --git a/src/TNL/Logger.h b/src/TNL/Logger.h index 7a6472bfa..d1f6c5c67 100644 --- a/src/TNL/Logger.h +++ b/src/TNL/Logger.h @@ -11,6 +11,7 @@ #pragma once #include + #include namespace TNL { @@ -18,15 +19,15 @@ namespace TNL { /// Creates calculations log in the form of a table. class Logger { - public: - +public: ///// /// \brief Basic constructor. /// /// \param _width Integer that defines the width of the log. /// \param _stream Defines output stream where the log will be printed out. - Logger( int _width, - std::ostream& _stream ); + Logger( int width, std::ostream& stream ) + : width( width ), stream( stream ) + {} ///// /// \brief Creates header in given log. @@ -76,8 +77,7 @@ class Logger const ParameterType& value, int parameterLevel = 0 ); - protected: - +protected: /// \brief Integer defining the width of the log. int width; diff --git a/src/TNL/Logger_impl.h b/src/TNL/Logger_impl.h index 08181070f..4a42e55dc 100644 --- a/src/TNL/Logger_impl.h +++ b/src/TNL/Logger_impl.h @@ -13,29 +13,72 @@ #include #include +#include +#include +#include + namespace TNL { -template< typename ParameterType > -void Logger::writeParameter( const String& label, - const String& parameterName, - const Config::ParameterContainer& parameters, - int parameterLevel ) +inline void +Logger::writeHeader( const String& title ) +{ + const int fill = stream.fill(); + const int titleLength = title.getLength(); + stream << "+" << std::setfill( '-' ) << std::setw( width ) << "+" << std::endl; + stream << "|" << std::setfill( ' ' ) << std::setw( width ) << "|" << std::endl; + stream << "|" << std::setw( width / 2 + titleLength / 2 ) + << title << std::setw( width / 2 - titleLength / 2 ) << "|" << std::endl; + stream << "|" << std::setfill( ' ' ) << std::setw( width ) << "|" << std::endl; + stream << "+" << std::setfill( '-' ) << std::setw( width ) << "+" << std::endl; + stream.fill( fill ); +} + +inline void +Logger::writeSeparator() +{ + const int fill = stream.fill(); + stream << "+" << std::setfill( '-' ) << std::setw( width ) << "+" << std::endl; + stream.fill( fill ); +} + +inline bool +Logger::writeSystemInformation( const Config::ParameterContainer& parameters ) +{ + Devices::SystemInfo::writeDeviceInfo( *this ); + if( parameters.getParameter< String >( "device" ) == "cuda" ) + Devices::CudaDeviceInfo::writeDeviceInfo( *this ); + return true; +} + +inline void +Logger::writeCurrentTime( const char* label ) +{ + writeParameter< String >( label, Devices::SystemInfo::getCurrentTime() ); +} + +template< typename T > +void +Logger::writeParameter( const String& label, + const String& parameterName, + const Config::ParameterContainer& parameters, + int parameterLevel ) { stream << "| "; int i; for( i = 0; i < parameterLevel; i ++ ) stream << " "; std::stringstream str; - str << parameters.getParameter< ParameterType >( parameterName ); - stream << label - << std::setw( width - label.getLength() - parameterLevel - 3 ) - << str.str() << " |" << std::endl; + str << parameters.getParameter< T >( parameterName ); + stream << label + << std::setw( width - label.getLength() - parameterLevel - 3 ) + << str.str() << " |" << std::endl; } -template< typename ParameterType > -void Logger :: writeParameter( const String& label, - const ParameterType& value, - int parameterLevel ) +template< typename T > +void +Logger::writeParameter( const String& label, + const T& value, + int parameterLevel ) { stream << "| "; int i; @@ -43,9 +86,9 @@ void Logger :: writeParameter( const String& label, stream << " "; std::stringstream str; str << value; - stream << label - << std::setw( width - label.getLength() - parameterLevel - 3 ) - << str.str() << " |" << std::endl; -}; + stream << label + << std::setw( width - label.getLength() - parameterLevel - 3 ) + << str.str() << " |" << std::endl; +} } // namespace TNL -- GitLab From 0f50590753cd420a0e4758e70a39beab3e49129e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 13:53:39 +0100 Subject: [PATCH 23/39] Moved stuff from Object.cpp to Object_impl.h --- src/TNL/CMakeLists.txt | 2 +- src/TNL/Object.h | 2 ++ src/TNL/{Object.cpp => Object_impl.h} | 36 ++++++++++++++------------- 3 files changed, 22 insertions(+), 18 deletions(-) rename src/TNL/{Object.cpp => Object_impl.h} (84%) diff --git a/src/TNL/CMakeLists.txt b/src/TNL/CMakeLists.txt index fdf140c50..da996f196 100644 --- a/src/TNL/CMakeLists.txt +++ b/src/TNL/CMakeLists.txt @@ -26,6 +26,7 @@ set( headers FileName.h FileName.hpp Object.h + Object_impl.h Logger.h Logger_impl.h Math.h @@ -38,7 +39,6 @@ set( headers set( common_SOURCES FileName.cpp - Object.cpp String.cpp Timer.cpp ) diff --git a/src/TNL/Object.h b/src/TNL/Object.h index e4fd274f8..04fc84113 100644 --- a/src/TNL/Object.h +++ b/src/TNL/Object.h @@ -113,3 +113,5 @@ std::vector< String > parseObjectType( const String& objectType ); } // namespace TNL + +#include diff --git a/src/TNL/Object.cpp b/src/TNL/Object_impl.h similarity index 84% rename from src/TNL/Object.cpp rename to src/TNL/Object_impl.h index c0cc9a446..51075d85a 100644 --- a/src/TNL/Object.cpp +++ b/src/TNL/Object_impl.h @@ -1,5 +1,5 @@ /*************************************************************************** - Object.cpp - description + Object_impl.h - description ------------------- begin : 2005/10/15 copyright : (C) 2005 by Tomas Oberhuber @@ -8,37 +8,39 @@ /* See Copyright Notice in tnl/Copyright */ -#include -#include +#pragma once + #include #include #include +#include + namespace TNL { -const char magic_number[] = "TNLMN"; +static constexpr char magic_number[] = "TNLMN"; -String Object :: getType() +inline String Object :: getType() { return String( "Object" ); } -String Object :: getTypeVirtual() const +inline String Object :: getTypeVirtual() const { return this->getType(); } -String Object :: getSerializationType() +inline String Object :: getSerializationType() { return String( "Object" ); } -String Object :: getSerializationTypeVirtual() const +inline String Object :: getSerializationTypeVirtual() const { return this->getSerializationType(); } -bool Object :: save( File& file ) const +inline bool Object :: save( File& file ) const { if( ! file. write( magic_number, strlen( magic_number ) ) ) return false; @@ -46,7 +48,7 @@ bool Object :: save( File& file ) const return true; } -bool Object :: load( File& file ) +inline bool Object :: load( File& file ) { String objectType; if( ! getObjectType( file, objectType ) ) @@ -59,12 +61,12 @@ bool Object :: load( File& file ) return true; } -bool Object :: boundLoad( File& file ) +inline bool Object :: boundLoad( File& file ) { return load( file ); } -bool Object :: save( const String& fileName ) const +inline bool Object :: save( const String& fileName ) const { File file; if( ! file. open( fileName, IOMode::write ) ) @@ -75,7 +77,7 @@ bool Object :: save( const String& fileName ) const return this->save( file ); } -bool Object :: load( const String& fileName ) +inline bool Object :: load( const String& fileName ) { File file; if( ! file. open( fileName, IOMode::read ) ) @@ -86,7 +88,7 @@ bool Object :: load( const String& fileName ) return this->load( file ); } -bool Object :: boundLoad( const String& fileName ) +inline bool Object :: boundLoad( const String& fileName ) { File file; if( ! file. open( fileName, IOMode::read ) ) @@ -98,7 +100,7 @@ bool Object :: boundLoad( const String& fileName ) } -bool getObjectType( File& file, String& type ) +inline bool getObjectType( File& file, String& type ) { char mn[ 10 ]; if( ! file. read( mn, strlen( magic_number ) ) ) @@ -119,7 +121,7 @@ bool getObjectType( File& file, String& type ) return true; } -bool getObjectType( const String& fileName, String& type ) +inline bool getObjectType( const String& fileName, String& type ) { File binaryFile; if( ! binaryFile. open( fileName, IOMode::read ) ) @@ -130,7 +132,7 @@ bool getObjectType( const String& fileName, String& type ) return getObjectType( binaryFile, type ); } -std::vector< String > +inline std::vector< String > parseObjectType( const String& objectType ) { std::vector< String > parsedObjectType; -- GitLab From b91b9403baeed2d4981f3538a87423c27500df55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 14:23:26 +0100 Subject: [PATCH 24/39] Removed unused timer from ExplicitSolver --- src/TNL/Solvers/ODE/ExplicitSolver.h | 5 ----- src/TNL/Solvers/ODE/ExplicitSolver_impl.h | 9 --------- 2 files changed, 14 deletions(-) diff --git a/src/TNL/Solvers/ODE/ExplicitSolver.h b/src/TNL/Solvers/ODE/ExplicitSolver.h index 4e20911de..c1431c0fb 100644 --- a/src/TNL/Solvers/ODE/ExplicitSolver.h +++ b/src/TNL/Solvers/ODE/ExplicitSolver.h @@ -11,7 +11,6 @@ #pragma once #include -#include #include #include #include @@ -67,8 +66,6 @@ class ExplicitSolver : public IterativeSolver< typename Problem::RealType, void setVerbose( IndexType v ); - void setTimer( Timer* timer ); - virtual bool solve( DofVectorPointer& u ) = 0; void setTestingMode( bool testingMode ); @@ -98,8 +95,6 @@ protected: IndexType verbosity; - Timer* timer; - bool testingMode; Problem* problem; diff --git a/src/TNL/Solvers/ODE/ExplicitSolver_impl.h b/src/TNL/Solvers/ODE/ExplicitSolver_impl.h index 78f0b0e69..04748c588 100644 --- a/src/TNL/Solvers/ODE/ExplicitSolver_impl.h +++ b/src/TNL/Solvers/ODE/ExplicitSolver_impl.h @@ -22,7 +22,6 @@ ExplicitSolver() tau( 0.0 ), maxTau( DBL_MAX ), verbosity( 0 ), - timer( &defaultTimer ), testingMode( false ), problem( 0 )//, //solverMonitor( 0 ) @@ -130,14 +129,6 @@ setVerbose( IndexType v ) this->verbosity = v; }; -template< class Problem > -void -ExplicitSolver< Problem >:: -setTimer( Timer* timer ) -{ - this->timer = timer; -}; - template< class Problem > void ExplicitSolver< Problem >:: -- GitLab From 7d1069bb2c54b6c8e313dbfab2da2d35db297778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 14:24:35 +0100 Subject: [PATCH 25/39] Moved stuff from Timer.cpp to Timer_impl.h --- src/TNL/CMakeLists.txt | 4 ++-- src/TNL/Timer.h | 3 +-- src/TNL/{Timer.cpp => Timer_impl.h} | 30 ++++++++++++++--------------- 3 files changed, 18 insertions(+), 19 deletions(-) rename src/TNL/{Timer.cpp => Timer_impl.h} (80%) diff --git a/src/TNL/CMakeLists.txt b/src/TNL/CMakeLists.txt index da996f196..99362ccf2 100644 --- a/src/TNL/CMakeLists.txt +++ b/src/TNL/CMakeLists.txt @@ -35,12 +35,12 @@ set( headers StaticFor.h String.h Timer.h + Timer_impl.h StaticVectorFor.h ) set( common_SOURCES FileName.cpp - String.cpp - Timer.cpp ) + String.cpp ) set( tnl_SOURCES ${tnl_config_SOURCES} ${tnl_containers_SOURCES} diff --git a/src/TNL/Timer.h b/src/TNL/Timer.h index 530dcae21..7f2331f18 100644 --- a/src/TNL/Timer.h +++ b/src/TNL/Timer.h @@ -132,7 +132,6 @@ class Timer } }; -extern Timer defaultTimer; - } // namespace TNL +#include diff --git a/src/TNL/Timer.cpp b/src/TNL/Timer_impl.h similarity index 80% rename from src/TNL/Timer.cpp rename to src/TNL/Timer_impl.h index e36493672..5a1cec336 100644 --- a/src/TNL/Timer.cpp +++ b/src/TNL/Timer_impl.h @@ -1,5 +1,5 @@ /*************************************************************************** - Timer.cpp - description + Timer_impl.h - description ------------------- begin : Mar 14, 2016 copyright : (C) 2016 by Tomas Oberhuber @@ -8,6 +8,8 @@ /* See Copyright Notice in tnl/Copyright */ +#pragma once + #include #include @@ -19,14 +21,12 @@ namespace TNL { -Timer defaultTimer; - -Timer::Timer() +inline Timer::Timer() { reset(); } -void Timer::reset() +inline void Timer::reset() { this->initialCPUTime = 0; this->totalCPUTime = 0.0; @@ -37,7 +37,7 @@ void Timer::reset() this->stopState = true; } -void Timer::stop() +inline void Timer::stop() { if( ! this->stopState ) @@ -49,7 +49,7 @@ void Timer::stop() } } -void Timer::start() +inline void Timer::start() { this->initialRealTime = this->readRealTime(); this->initialCPUTime = this->readCPUTime(); @@ -57,33 +57,33 @@ void Timer::start() this->stopState = false; } -double Timer::getRealTime() const +inline double Timer::getRealTime() const { if( ! this->stopState ) return durationToDouble( this->readRealTime() - this->initialRealTime ); return durationToDouble( this->totalRealTime ); } -double Timer::getCPUTime() const +inline double Timer::getCPUTime() const { if( ! this->stopState ) return this->readCPUTime() - this->initialCPUTime; return this->totalCPUTime; } -unsigned long long int Timer::getCPUCycles() const +inline unsigned long long int Timer::getCPUCycles() const { if( ! this->stopState ) return this->readCPUCycles() - this->initialCPUCycles; return this->totalCPUCycles; } -typename Timer::TimePoint Timer::readRealTime() const +inline typename Timer::TimePoint Timer::readRealTime() const { return std::chrono::high_resolution_clock::now(); } -double Timer::readCPUTime() const +inline double Timer::readCPUTime() const { #if !defined(_WIN32) && !defined(_WIN64) rusage initUsage; @@ -94,19 +94,19 @@ double Timer::readCPUTime() const #endif } -unsigned long long int Timer::readCPUCycles() const +inline unsigned long long int Timer::readCPUCycles() const { return this->rdtsc(); } -double Timer::durationToDouble( const Duration& duration ) const +inline double Timer::durationToDouble( const Duration& duration ) const { std::chrono::duration< double > dur( duration ); return dur.count(); } -bool Timer::writeLog( Logger& logger, int logLevel ) const +inline bool Timer::writeLog( Logger& logger, int logLevel ) const { logger.writeParameter< double >( "Real time:", this->getRealTime(), logLevel ); logger.writeParameter< double >( "CPU time:", this->getCPUTime(), logLevel ); -- GitLab From 32c753103d19c8cd1c888e6e856036b46b24e5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 14:28:57 +0100 Subject: [PATCH 26/39] Moved stuff from FileName.cpp to FileName.hpp --- src/TNL/CMakeLists.txt | 1 - src/TNL/FileName.cpp | 98 ------------------------------------------ src/TNL/FileName.h | 5 +-- src/TNL/FileName.hpp | 84 ++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 102 deletions(-) delete mode 100644 src/TNL/FileName.cpp diff --git a/src/TNL/CMakeLists.txt b/src/TNL/CMakeLists.txt index 99362ccf2..eb3d871f5 100644 --- a/src/TNL/CMakeLists.txt +++ b/src/TNL/CMakeLists.txt @@ -39,7 +39,6 @@ set( headers StaticVectorFor.h ) set( common_SOURCES - FileName.cpp String.cpp ) set( tnl_SOURCES ${tnl_config_SOURCES} diff --git a/src/TNL/FileName.cpp b/src/TNL/FileName.cpp deleted file mode 100644 index ecbe0a664..000000000 --- a/src/TNL/FileName.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/*************************************************************************** - FileName.cpp - description - ------------------- - begin : 2007/06/18 - copyright : (C) 2007 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#include -#include -#include -#include -#include -#include -#include - -namespace TNL { - -FileName::FileName() -: index( 0 ), digitsCount( 5 ) -{ -} - -FileName::FileName( const String& fileNameBase ) -: fileNameBase( fileNameBase ), - index( 0 ), - digitsCount( 5 ) -{ -} - -FileName::FileName( const String& fileNameBase, - const String& extension ) -: fileNameBase( fileNameBase ), - extension( extension ), - index( 0 ), - digitsCount( 5 ) -{ -} - -void FileName::setFileNameBase( const String& fileNameBase ) -{ - this->fileNameBase = fileNameBase; -} - -void FileName::setExtension( const String& extension ) -{ - this->extension = extension; -} - -void FileName::setIndex( const int index ) -{ - this->index = index; -} - -void FileName::setDigitsCount( const int digitsCount ) -{ - this->digitsCount = digitsCount; -} - -void FileName::setDistributedSystemNodeId( int nodeId ) -{ - this->distributedSystemNodeId = "-"; - this->distributedSystemNodeId += convertToString( nodeId ); -} - -String FileName::getFileName() -{ - std::stringstream stream; - stream << this->fileNameBase - << std::setw( this->digitsCount ) - << std::setfill( '0' ) - << this->index - << this->distributedSystemNodeId - << "." << this->extension; - return String( stream.str().data() ); -} - -String getFileExtension( const String fileName ) -{ - int size = fileName. getLength(); - int i = 1; - while( fileName. getString()[ size - i ] != '.' && size > i ) i ++ ; - String result; - result.setString( fileName. getString(), size - i + 1 ); - return result; -} - -void removeFileExtension( String& fileName ) -{ - int size = fileName. getLength(); - int i = 1; - while( fileName. getString()[ size - i ] != '.' && size > i ) i ++ ; - fileName. setString( fileName. getString(), 0, i ); -} - -} // namespace TNL diff --git a/src/TNL/FileName.h b/src/TNL/FileName.h index 3dae01c54..a36e3db3f 100644 --- a/src/TNL/FileName.h +++ b/src/TNL/FileName.h @@ -8,7 +8,7 @@ /* See Copyright Notice in tnl/Copyright */ -#pragma once +#pragma once #include @@ -70,13 +70,12 @@ class FileName /// Creates particular file name using \e fileNameBase, \e digitsCount, /// \e index and \e extension. String getFileName(); - + protected: String fileNameBase, extension, distributedSystemNodeId; int index, digitsCount; - }; } // namespace TNL diff --git a/src/TNL/FileName.hpp b/src/TNL/FileName.hpp index 4f1628df5..325335b6d 100644 --- a/src/TNL/FileName.hpp +++ b/src/TNL/FileName.hpp @@ -8,10 +8,64 @@ /* See Copyright Notice in tnl/Copyright */ +#pragma once + +#include +#include + #include +#include +#include namespace TNL { +inline FileName::FileName() +: index( 0 ), digitsCount( 5 ) +{ +} + +inline FileName::FileName( const String& fileNameBase ) +: fileNameBase( fileNameBase ), + index( 0 ), + digitsCount( 5 ) +{ +} + +inline FileName::FileName( const String& fileNameBase, + const String& extension ) +: fileNameBase( fileNameBase ), + extension( extension ), + index( 0 ), + digitsCount( 5 ) +{ +} + +inline void FileName::setFileNameBase( const String& fileNameBase ) +{ + this->fileNameBase = fileNameBase; +} + +inline void FileName::setExtension( const String& extension ) +{ + this->extension = extension; +} + +inline void FileName::setIndex( const int index ) +{ + this->index = index; +} + +inline void FileName::setDigitsCount( const int digitsCount ) +{ + this->digitsCount = digitsCount; +} + +inline void FileName::setDistributedSystemNodeId( int nodeId ) +{ + this->distributedSystemNodeId = "-"; + this->distributedSystemNodeId += convertToString( nodeId ); +} + template< typename Coordinates > void FileName:: @@ -26,4 +80,34 @@ setDistributedSystemNodeId( const Coordinates& nodeId ) } } +inline String FileName::getFileName() +{ + std::stringstream stream; + stream << this->fileNameBase + << std::setw( this->digitsCount ) + << std::setfill( '0' ) + << this->index + << this->distributedSystemNodeId + << "." << this->extension; + return String( stream.str().data() ); +} + +inline String getFileExtension( const String fileName ) +{ + int size = fileName. getLength(); + int i = 1; + while( fileName. getString()[ size - i ] != '.' && size > i ) i ++ ; + String result; + result.setString( fileName. getString(), size - i + 1 ); + return result; +} + +inline void removeFileExtension( String& fileName ) +{ + int size = fileName. getLength(); + int i = 1; + while( fileName. getString()[ size - i ] != '.' && size > i ) i ++ ; + fileName. setString( fileName. getString(), 0, i ); +} + } // namespace TNL -- GitLab From bd7bc17ce2e6a40fd73bf05dee11d815ec214678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 14:38:55 +0100 Subject: [PATCH 27/39] Used std::put_time instead of std::strftime in SystemInfo --- src/TNL/Devices/SystemInfo.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/TNL/Devices/SystemInfo.cpp b/src/TNL/Devices/SystemInfo.cpp index 38f852301..9ad5e19b9 100644 --- a/src/TNL/Devices/SystemInfo.cpp +++ b/src/TNL/Devices/SystemInfo.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -65,13 +64,9 @@ SystemInfo::getCurrentTime( const char* format ) { const std::time_t time_since_epoch = std::time( nullptr ); std::tm* localtime = std::localtime( &time_since_epoch ); - // TODO: use std::put_time in the future (available since GCC 5) -// std::stringstream ss; -// ss << std::put_time( localtime, format ); -// return String( ss.str().c_str() ); - char buffer[1024]; - std::strftime( buffer, 1024, format, localtime ); - return String( buffer ); + std::stringstream ss; + ss << std::put_time( localtime, format ); + return String( ss.str().c_str() ); } -- GitLab From a2fedda002320ce769127454421232b7053ab6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 15:35:53 +0100 Subject: [PATCH 28/39] Moved stuff from CudaDeviceInfo.{cpp,cu} and SystemInfo.cpp into header files --- src/TNL/Devices/CMakeLists.txt | 23 +- src/TNL/Devices/CudaDeviceInfo.cpp | 126 --------- src/TNL/Devices/CudaDeviceInfo.cu | 218 ---------------- src/TNL/Devices/CudaDeviceInfo.h | 7 +- src/TNL/Devices/CudaDeviceInfo_impl.h | 243 ++++++++++++++++++ src/TNL/Devices/SystemInfo.h | 20 +- .../{SystemInfo.cpp => SystemInfo_impl.h} | 132 ++++------ src/TNL/Logger_impl.h | 69 ++++- 8 files changed, 374 insertions(+), 464 deletions(-) delete mode 100644 src/TNL/Devices/CudaDeviceInfo.cpp delete mode 100644 src/TNL/Devices/CudaDeviceInfo.cu create mode 100644 src/TNL/Devices/CudaDeviceInfo_impl.h rename src/TNL/Devices/{SystemInfo.cpp => SystemInfo_impl.h} (58%) diff --git a/src/TNL/Devices/CMakeLists.txt b/src/TNL/Devices/CMakeLists.txt index d771a6c5b..b2beec096 100644 --- a/src/TNL/Devices/CMakeLists.txt +++ b/src/TNL/Devices/CMakeLists.txt @@ -2,26 +2,11 @@ set (headers Cuda.h Cuda_impl.h CudaCallable.h CudaDeviceInfo.h + CudaDeviceInfo_impl.h Host.h MIC.h - SystemInfo.h ) + SystemInfo.h + SystemInfo_impl.h +) -SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL/Devices ) -set( common_SOURCES - ${CURRENT_DIR}/SystemInfo.cpp ) - -IF( BUILD_CUDA ) - set( tnl_devices_CUDA__SOURCES - ${common_SOURCES} - ${CURRENT_DIR}/CudaDeviceInfo.cu - PARENT_SCOPE ) -ENDIF() - -set( tnl_devices_SOURCES - ${common_SOURCES} - ${CURRENT_DIR}/CudaDeviceInfo.cpp - PARENT_SCOPE ) - -#SET( libtnlcoreincludedir ${TNL_INCLUDE_DIR}/core ) -#SET( libtnlcoreinclude_HEADERS ${headers} ) INSTALL( FILES ${headers} DESTINATION ${TNL_TARGET_INCLUDE_DIRECTORY}/Devices ) diff --git a/src/TNL/Devices/CudaDeviceInfo.cpp b/src/TNL/Devices/CudaDeviceInfo.cpp deleted file mode 100644 index 85a6604d8..000000000 --- a/src/TNL/Devices/CudaDeviceInfo.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/*************************************************************************** - Devices::CudaDeviceInfo.cpp - description - ------------------- - begin : Jun 21, 2015 - copyright : (C) 2007 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#ifndef HAVE_CUDA - -#include -#include - -namespace TNL { -namespace Devices { - -int -CudaDeviceInfo:: -getNumberOfDevices() -{ - return -1; -} - -int -CudaDeviceInfo:: -getActiveDevice() -{ - return -1; -} - -String -CudaDeviceInfo:: -getDeviceName( int deviceNum ) -{ - return String( "" ); -} - -int -CudaDeviceInfo:: -getArchitectureMajor( int deviceNum ) -{ - return 0; -} - -int -CudaDeviceInfo:: -getArchitectureMinor( int deviceNum ) -{ - return 0; -} - -int -CudaDeviceInfo:: -getClockRate( int deviceNum ) -{ - return 0; -} - -size_t -CudaDeviceInfo:: -getGlobalMemory( int deviceNum ) -{ - return 0; -} - -size_t -CudaDeviceInfo:: -getFreeGlobalMemory() -{ - return 0; -} - -int -CudaDeviceInfo:: -getMemoryClockRate( int deviceNum ) -{ - return 0; -} - -bool -CudaDeviceInfo:: -getECCEnabled( int deviceNum ) -{ - return 0; -} - -int -CudaDeviceInfo:: -getCudaMultiprocessors( int deviceNum ) -{ - return 0; -} - -int -CudaDeviceInfo:: -getCudaCoresPerMultiprocessors( int deviceNum ) -{ - return 0; -} - -int -CudaDeviceInfo:: -getCudaCores( int deviceNum ) -{ - return 0; -} - -int -CudaDeviceInfo:: -getRegistersPerMultiprocessor( int deviceNum ) -{ - return 0; -} - -void -CudaDeviceInfo:: -writeDeviceInfo( Logger& logger ) -{ -} - -} // namespace Devices -} // namespace TNL - -#endif diff --git a/src/TNL/Devices/CudaDeviceInfo.cu b/src/TNL/Devices/CudaDeviceInfo.cu deleted file mode 100644 index 4e66c095d..000000000 --- a/src/TNL/Devices/CudaDeviceInfo.cu +++ /dev/null @@ -1,218 +0,0 @@ -/*************************************************************************** - CudaDeviceInfo.cu - description - ------------------- - begin : Jun 21, 2015 - copyright : (C) 2007 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#ifdef HAVE_CUDA - -#include - -#include -#include - -namespace TNL { -namespace Devices { - -int -CudaDeviceInfo:: -getNumberOfDevices() -{ - int devices; - cudaGetDeviceCount( &devices ); - return devices; -} - -int -CudaDeviceInfo:: -getActiveDevice() -{ - int device; - cudaGetDevice( &device ); - return device; -} - -String -CudaDeviceInfo:: -getDeviceName( int deviceNum ) -{ - cudaDeviceProp properties; - cudaGetDeviceProperties( &properties, deviceNum ); - return String( properties.name ); -} - -int -CudaDeviceInfo:: -getArchitectureMajor( int deviceNum ) -{ - cudaDeviceProp properties; - cudaGetDeviceProperties( &properties, deviceNum ); - return properties.major; -} - -int -CudaDeviceInfo:: -getArchitectureMinor( int deviceNum ) -{ - cudaDeviceProp properties; - cudaGetDeviceProperties( &properties, deviceNum ); - return properties.minor; -} - -int -CudaDeviceInfo:: -getClockRate( int deviceNum ) -{ - cudaDeviceProp properties; - cudaGetDeviceProperties( &properties, deviceNum ); - return properties.clockRate; -} - -size_t -CudaDeviceInfo:: -getGlobalMemory( int deviceNum ) -{ - cudaDeviceProp properties; - cudaGetDeviceProperties( &properties, deviceNum ); - return properties.totalGlobalMem; -} - -size_t -CudaDeviceInfo:: -getFreeGlobalMemory() -{ - size_t free = 0; - size_t total = 0; - cudaMemGetInfo( &free, &total ); - return free; -} - -int -CudaDeviceInfo:: -getMemoryClockRate( int deviceNum ) -{ - cudaDeviceProp properties; - cudaGetDeviceProperties( &properties, deviceNum ); - return properties.memoryClockRate; -} - -bool -CudaDeviceInfo:: -getECCEnabled( int deviceNum ) -{ - cudaDeviceProp properties; - cudaGetDeviceProperties( &properties, deviceNum ); - return properties.ECCEnabled; -} - -int -CudaDeviceInfo:: -getCudaMultiprocessors( int deviceNum ) -{ - // results are cached because they are used for configuration of some kernels - static std::unordered_map< int, int > results; - if( results.count( deviceNum ) == 0 ) { - cudaDeviceProp properties; - cudaGetDeviceProperties( &properties, deviceNum ); - results.emplace( deviceNum, properties.multiProcessorCount ); - return properties.multiProcessorCount; - } - return results[ deviceNum ]; -} - -int -CudaDeviceInfo:: -getCudaCoresPerMultiprocessors( int deviceNum ) -{ - int major = CudaDeviceInfo::getArchitectureMajor( deviceNum ); - int minor = CudaDeviceInfo::getArchitectureMinor( deviceNum ); - switch( major ) - { - case 1: // Tesla generation, G80, G8x, G9x classes - return 8; - case 2: // Fermi generation - switch( minor ) - { - case 0: // GF100 class - return 32; - case 1: // GF10x class - return 48; - } - case 3: // Kepler generation -- GK10x, GK11x classes - return 192; - case 5: // Maxwell generation -- GM10x, GM20x classes - return 128; - case 6: // Pascal generation - switch( minor ) - { - case 0: // GP100 class - return 64; - case 1: // GP10x classes - case 2: - return 128; - } - default: - return -1; - } -} - -int -CudaDeviceInfo:: -getCudaCores( int deviceNum ) -{ - return CudaDeviceInfo::getCudaMultiprocessors( deviceNum ) * - CudaDeviceInfo::getCudaCoresPerMultiprocessors( deviceNum ); -} - -int -CudaDeviceInfo:: -getRegistersPerMultiprocessor( int deviceNum ) -{ - // results are cached because they are used for configuration of some kernels - static std::unordered_map< int, int > results; - if( results.count( deviceNum ) == 0 ) { - cudaDeviceProp properties; - cudaGetDeviceProperties( &properties, deviceNum ); - results.emplace( deviceNum, properties.regsPerMultiprocessor ); - return properties.regsPerMultiprocessor; - } - return results[ deviceNum ]; -} - -void -CudaDeviceInfo:: -writeDeviceInfo( Logger& logger ) -{ - logger.writeParameter< String >( "CUDA GPU info", String("") ); - // TODO: Printing all devices does not make sense until TNL can actually - // use more than one device for computations. Printing only the active - // device for now... -// int devices = getNumberOfDevices(); -// writeParameter< int >( "Number of devices", devices, 1 ); -// for( int i = 0; i < devices; i++ ) -// { -// logger.writeParameter< int >( "Device no.", i, 1 ); - int i = getActiveDevice(); - logger.writeParameter< String >( "Name", getDeviceName( i ), 2 ); - String deviceArch = convertToString( getArchitectureMajor( i ) ) + "." + - convertToString( getArchitectureMinor( i ) ); - logger.writeParameter< String >( "Architecture", deviceArch, 2 ); - logger.writeParameter< int >( "CUDA cores", getCudaCores( i ), 2 ); - double clockRate = ( double ) getClockRate( i ) / 1.0e3; - logger.writeParameter< double >( "Clock rate (in MHz)", clockRate, 2 ); - double globalMemory = ( double ) getGlobalMemory( i ) / 1.0e9; - logger.writeParameter< double >( "Global memory (in GB)", globalMemory, 2 ); - double memoryClockRate = ( double ) getMemoryClockRate( i ) / 1.0e3; - logger.writeParameter< double >( "Memory clock rate (in Mhz)", memoryClockRate, 2 ); - logger.writeParameter< bool >( "ECC enabled", getECCEnabled( i ), 2 ); -// } -} - -} // namespace Devices -} // namespace TNL - -#endif diff --git a/src/TNL/Devices/CudaDeviceInfo.h b/src/TNL/Devices/CudaDeviceInfo.h index 0b02daee5..9eefe3bad 100644 --- a/src/TNL/Devices/CudaDeviceInfo.h +++ b/src/TNL/Devices/CudaDeviceInfo.h @@ -15,9 +15,6 @@ #include namespace TNL { - -class Logger; - namespace Devices { class CudaDeviceInfo @@ -51,9 +48,9 @@ class CudaDeviceInfo static int getCudaCores( int deviceNum ); static int getRegistersPerMultiprocessor( int deviceNum ); - - static void writeDeviceInfo( Logger& logger ); }; } // namespace Devices } // namespace TNL + +#include diff --git a/src/TNL/Devices/CudaDeviceInfo_impl.h b/src/TNL/Devices/CudaDeviceInfo_impl.h new file mode 100644 index 000000000..f29ecd8c9 --- /dev/null +++ b/src/TNL/Devices/CudaDeviceInfo_impl.h @@ -0,0 +1,243 @@ +/*************************************************************************** + CudaDeviceInfo_impl.h - description + ------------------- + begin : Jun 21, 2015 + copyright : (C) 2007 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include + +#include +#include + +namespace TNL { +namespace Devices { + +inline int +CudaDeviceInfo:: +getNumberOfDevices() +{ +#ifdef HAVE_CUDA + int devices; + cudaGetDeviceCount( &devices ); + return devices; +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline int +CudaDeviceInfo:: +getActiveDevice() +{ +#ifdef HAVE_CUDA + int device; + cudaGetDevice( &device ); + return device; +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline String +CudaDeviceInfo:: +getDeviceName( int deviceNum ) +{ +#ifdef HAVE_CUDA + cudaDeviceProp properties; + cudaGetDeviceProperties( &properties, deviceNum ); + return String( properties.name ); +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline int +CudaDeviceInfo:: +getArchitectureMajor( int deviceNum ) +{ +#ifdef HAVE_CUDA + cudaDeviceProp properties; + cudaGetDeviceProperties( &properties, deviceNum ); + return properties.major; +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline int +CudaDeviceInfo:: +getArchitectureMinor( int deviceNum ) +{ +#ifdef HAVE_CUDA + cudaDeviceProp properties; + cudaGetDeviceProperties( &properties, deviceNum ); + return properties.minor; +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline int +CudaDeviceInfo:: +getClockRate( int deviceNum ) +{ +#ifdef HAVE_CUDA + cudaDeviceProp properties; + cudaGetDeviceProperties( &properties, deviceNum ); + return properties.clockRate; +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline size_t +CudaDeviceInfo:: +getGlobalMemory( int deviceNum ) +{ +#ifdef HAVE_CUDA + cudaDeviceProp properties; + cudaGetDeviceProperties( &properties, deviceNum ); + return properties.totalGlobalMem; +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline size_t +CudaDeviceInfo:: +getFreeGlobalMemory() +{ +#ifdef HAVE_CUDA + size_t free = 0; + size_t total = 0; + cudaMemGetInfo( &free, &total ); + return free; +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline int +CudaDeviceInfo:: +getMemoryClockRate( int deviceNum ) +{ +#ifdef HAVE_CUDA + cudaDeviceProp properties; + cudaGetDeviceProperties( &properties, deviceNum ); + return properties.memoryClockRate; +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline bool +CudaDeviceInfo:: +getECCEnabled( int deviceNum ) +{ +#ifdef HAVE_CUDA + cudaDeviceProp properties; + cudaGetDeviceProperties( &properties, deviceNum ); + return properties.ECCEnabled; +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline int +CudaDeviceInfo:: +getCudaMultiprocessors( int deviceNum ) +{ +#ifdef HAVE_CUDA + // results are cached because they are used for configuration of some kernels + static std::unordered_map< int, int > results; + if( results.count( deviceNum ) == 0 ) { + cudaDeviceProp properties; + cudaGetDeviceProperties( &properties, deviceNum ); + results.emplace( deviceNum, properties.multiProcessorCount ); + return properties.multiProcessorCount; + } + return results[ deviceNum ]; +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline int +CudaDeviceInfo:: +getCudaCoresPerMultiprocessors( int deviceNum ) +{ +#ifdef HAVE_CUDA + int major = CudaDeviceInfo::getArchitectureMajor( deviceNum ); + int minor = CudaDeviceInfo::getArchitectureMinor( deviceNum ); + switch( major ) + { + case 1: // Tesla generation, G80, G8x, G9x classes + return 8; + case 2: // Fermi generation + switch( minor ) + { + case 0: // GF100 class + return 32; + case 1: // GF10x class + return 48; + } + case 3: // Kepler generation -- GK10x, GK11x classes + return 192; + case 5: // Maxwell generation -- GM10x, GM20x classes + return 128; + case 6: // Pascal generation + switch( minor ) + { + case 0: // GP100 class + return 64; + case 1: // GP10x classes + case 2: + return 128; + } + default: + return -1; + } +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline int +CudaDeviceInfo:: +getCudaCores( int deviceNum ) +{ +#ifdef HAVE_CUDA + return CudaDeviceInfo::getCudaMultiprocessors( deviceNum ) * + CudaDeviceInfo::getCudaCoresPerMultiprocessors( deviceNum ); +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +inline int +CudaDeviceInfo:: +getRegistersPerMultiprocessor( int deviceNum ) +{ +#ifdef HAVE_CUDA + // results are cached because they are used for configuration of some kernels + static std::unordered_map< int, int > results; + if( results.count( deviceNum ) == 0 ) { + cudaDeviceProp properties; + cudaGetDeviceProperties( &properties, deviceNum ); + results.emplace( deviceNum, properties.regsPerMultiprocessor ); + return properties.regsPerMultiprocessor; + } + return results[ deviceNum ]; +#else + throw Exceptions::CudaSupportMissing(); +#endif +} + +} // namespace Devices +} // namespace TNL diff --git a/src/TNL/Devices/SystemInfo.h b/src/TNL/Devices/SystemInfo.h index bafcdd428..f62321d6f 100644 --- a/src/TNL/Devices/SystemInfo.h +++ b/src/TNL/Devices/SystemInfo.h @@ -15,9 +15,6 @@ #include namespace TNL { - -class Logger; - namespace Devices { struct CacheSizes { @@ -45,15 +42,16 @@ public: static CacheSizes getCPUCacheSizes( int cpu_id ); static size_t getFreeMemory(); - static void writeDeviceInfo( Logger& logger ); - protected: - static int numberOfProcessors; - static String CPUModelName; - static int CPUThreads; - static int CPUCores; + struct CPUInfo + { + int numberOfProcessors = 0; + String CPUModelName; + int CPUThreads = 0; + int CPUCores = 0; + }; - static void parseCPUInfo(); + static CPUInfo parseCPUInfo(); template< typename ResultType > static ResultType @@ -72,3 +70,5 @@ protected: } // namespace Devices } // namespace TNL + +#include diff --git a/src/TNL/Devices/SystemInfo.cpp b/src/TNL/Devices/SystemInfo_impl.h similarity index 58% rename from src/TNL/Devices/SystemInfo.cpp rename to src/TNL/Devices/SystemInfo_impl.h index 9ad5e19b9..008ec644c 100644 --- a/src/TNL/Devices/SystemInfo.cpp +++ b/src/TNL/Devices/SystemInfo_impl.h @@ -1,5 +1,5 @@ /*************************************************************************** - SystemInfo.cpp - description + SystemInfo_impl.h - description ------------------- begin : Jul 8, 2018 copyright : (C) 2018 by Tomas Oberhuber et al. @@ -8,6 +8,8 @@ /* See Copyright Notice in tnl/Copyright */ +#pragma once + #include #include #include @@ -17,17 +19,11 @@ #include #include -#include namespace TNL { namespace Devices { -int SystemInfo::numberOfProcessors( 0 ); -String SystemInfo::CPUModelName( "" ); -int SystemInfo::CPUThreads( 0 ); -int SystemInfo::CPUCores( 0 ); - -String +inline String SystemInfo::getHostname( void ) { char host_name[ 256 ]; @@ -35,7 +31,7 @@ SystemInfo::getHostname( void ) return String( host_name ); } -String +inline String SystemInfo::getArchitecture( void ) { utsname uts; @@ -43,7 +39,7 @@ SystemInfo::getArchitecture( void ) return String( uts.machine ); } -String +inline String SystemInfo::getSystemName( void ) { utsname uts; @@ -51,7 +47,7 @@ SystemInfo::getSystemName( void ) return String( uts.sysname ); } -String +inline String SystemInfo::getSystemRelease( void ) { utsname uts; @@ -59,7 +55,7 @@ SystemInfo::getSystemRelease( void ) return String( uts.release ); } -String +inline String SystemInfo::getCurrentTime( const char* format ) { const std::time_t time_since_epoch = std::time( nullptr ); @@ -70,46 +66,58 @@ SystemInfo::getCurrentTime( const char* format ) } -int +inline int SystemInfo::getNumberOfProcessors( void ) { - if( numberOfProcessors == 0 ) - parseCPUInfo(); + static int numberOfProcessors = 0; + if( numberOfProcessors == 0 ) { + CPUInfo info = parseCPUInfo(); + numberOfProcessors = info.numberOfProcessors; + } return numberOfProcessors; } -String +inline String SystemInfo::getOnlineCPUs( void ) { std::string online = readFile< std::string >( "/sys/devices/system/cpu/online" ); return String( online.c_str() ); } -int +inline int SystemInfo::getNumberOfCores( int cpu_id ) { - if( CPUCores == 0 ) - parseCPUInfo(); + static int CPUCores = 0; + if( CPUCores == 0 ) { + CPUInfo info = parseCPUInfo(); + CPUCores = info.CPUCores; + } return CPUCores; } -int +inline int SystemInfo::getNumberOfThreads( int cpu_id ) { - if( CPUThreads == 0 ) - parseCPUInfo(); + static int CPUThreads = 0; + if( CPUThreads == 0 ) { + CPUInfo info = parseCPUInfo(); + CPUThreads = info.CPUThreads; + } return CPUThreads; } -String +inline String SystemInfo::getCPUModelName( int cpu_id ) { - if( CPUModelName == "" ) - parseCPUInfo(); + static String CPUModelName; + if( CPUModelName == "" ) { + CPUInfo info = parseCPUInfo(); + CPUModelName = info.CPUModelName; + } return CPUModelName; } -int +inline int SystemInfo::getCPUMaxFrequency( int cpu_id ) { String fileName( "/sys/devices/system/cpu/cpu" ); @@ -117,7 +125,7 @@ SystemInfo::getCPUMaxFrequency( int cpu_id ) return readFile< int >( fileName ); } -CacheSizes +inline CacheSizes SystemInfo::getCPUCacheSizes( int cpu_id ) { String directory( "/sys/devices/system/cpu/cpu" ); @@ -148,59 +156,23 @@ SystemInfo::getCPUCacheSizes( int cpu_id ) return sizes; } -void -SystemInfo:: -writeDeviceInfo( Logger& logger ) +inline size_t +SystemInfo::getFreeMemory() { -// compiler detection macros: -// http://nadeausoftware.com/articles/2012/10/c_c_tip_how_detect_compiler_name_and_version_using_compiler_predefined_macros -// https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#compilation-phases -#if defined(__NVCC__) - #define TNL_STRINGIFY(x) #x - const char* compiler_name = "Nvidia NVCC (" TNL_STRINGIFY(__CUDACC_VER_MAJOR__) "." TNL_STRINGIFY(__CUDACC_VER_MINOR__) "." TNL_STRINGIFY(__CUDACC_VER_BUILD__) ")"; - #undef TNL_STRINGIFY -#elif defined(__clang__) - const char* compiler_name = "Clang/LLVM (" __VERSION__ ")"; -#elif defined(__ICC) || defined(__INTEL_COMPILER) - const char* compiler_name = "Intel ICPC (" __VERSION__ ")"; -#elif defined(__GNUC__) || defined(__GNUG__) - const char* compiler_name = "GNU G++ (" __VERSION__ ")"; -#else - const char* compiler_name = "(unknown)"; -#endif - - logger.writeParameter< String >( "Host name:", getHostname() ); - logger.writeParameter< String >( "System:", getSystemName() ); - logger.writeParameter< String >( "Release:", getSystemRelease() ); - logger.writeParameter< String >( "Architecture:", getArchitecture() ); - logger.writeParameter< String >( "TNL compiler:", compiler_name ); - // FIXME: generalize for multi-socket systems, here we consider only the first found CPU - const int cpu_id = 0; - const int threads = getNumberOfThreads( cpu_id ); - const int cores = getNumberOfCores( cpu_id ); - int threadsPerCore = 0; - if( cores > 0 ) - threadsPerCore = threads / cores; - logger.writeParameter< String >( "CPU info", String("") ); - logger.writeParameter< String >( "Model name:", getCPUModelName( cpu_id ), 1 ); - logger.writeParameter< int >( "Cores:", cores, 1 ); - logger.writeParameter< int >( "Threads per core:", threadsPerCore, 1 ); - logger.writeParameter< float >( "Max clock rate (in MHz):", getCPUMaxFrequency( cpu_id ) / 1000, 1 ); - CacheSizes cacheSizes = getCPUCacheSizes( cpu_id ); - String cacheInfo = convertToString( cacheSizes.L1data ) + ", " - + convertToString( cacheSizes.L1instruction ) + ", " - + convertToString( cacheSizes.L2 ) + ", " - + convertToString( cacheSizes.L3 ); - logger.writeParameter< String >( "Cache (L1d, L1i, L2, L3):", cacheInfo, 1 ); + long pages = sysconf(_SC_PHYS_PAGES); + long page_size = sysconf(_SC_PAGE_SIZE); + return pages * page_size; } -void + +inline SystemInfo::CPUInfo SystemInfo::parseCPUInfo( void ) { + CPUInfo info; std::ifstream file( "/proc/cpuinfo" ); if( ! file ) { std::cerr << "Unable to read information from /proc/cpuinfo." << std::endl; - return; + return info; } char line[ 1024 ]; @@ -221,32 +193,26 @@ SystemInfo::parseCPUInfo( void ) { i = strlen( "model name" ); while( line[ i ] != ':' && line[ i ] ) i ++; - CPUModelName.setString( &line[ i + 1 ] ); + info.CPUModelName.setString( &line[ i + 1 ] ); continue; } if( strncmp( line, "cpu cores", strlen( "cpu cores" ) ) == 0 ) { i = strlen( "cpu MHz" ); while( line[ i ] != ':' && line[ i ] ) i ++; - CPUCores = atoi( &line[ i + 1 ] ); + info.CPUCores = atoi( &line[ i + 1 ] ); continue; } if( strncmp( line, "siblings", strlen( "siblings" ) ) == 0 ) { i = strlen( "siblings" ); while( line[ i ] != ':' && line[ i ] ) i ++; - CPUThreads = atoi( &line[ i + 1 ] ); + info.CPUThreads = atoi( &line[ i + 1 ] ); } } - numberOfProcessors = processors.size(); -} - + info.numberOfProcessors = processors.size(); -size_t SystemInfo::getFreeMemory() -{ - long pages = sysconf(_SC_PHYS_PAGES); - long page_size = sysconf(_SC_PAGE_SIZE); - return pages * page_size; + return info; } } // namespace Devices diff --git a/src/TNL/Logger_impl.h b/src/TNL/Logger_impl.h index 4a42e55dc..0e1dd8dc6 100644 --- a/src/TNL/Logger_impl.h +++ b/src/TNL/Logger_impl.h @@ -44,9 +44,72 @@ Logger::writeSeparator() inline bool Logger::writeSystemInformation( const Config::ParameterContainer& parameters ) { - Devices::SystemInfo::writeDeviceInfo( *this ); - if( parameters.getParameter< String >( "device" ) == "cuda" ) - Devices::CudaDeviceInfo::writeDeviceInfo( *this ); +// compiler detection macros: +// http://nadeausoftware.com/articles/2012/10/c_c_tip_how_detect_compiler_name_and_version_using_compiler_predefined_macros +// https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#compilation-phases +#if defined(__NVCC__) + #define TNL_STRINGIFY(x) #x + const char* compiler_name = "Nvidia NVCC (" TNL_STRINGIFY(__CUDACC_VER_MAJOR__) "." TNL_STRINGIFY(__CUDACC_VER_MINOR__) "." TNL_STRINGIFY(__CUDACC_VER_BUILD__) ")"; + #undef TNL_STRINGIFY +#elif defined(__clang__) + const char* compiler_name = "Clang/LLVM (" __VERSION__ ")"; +#elif defined(__ICC) || defined(__INTEL_COMPILER) + const char* compiler_name = "Intel ICPC (" __VERSION__ ")"; +#elif defined(__GNUC__) || defined(__GNUG__) + const char* compiler_name = "GNU G++ (" __VERSION__ ")"; +#else + const char* compiler_name = "(unknown)"; +#endif + + writeParameter< String >( "Host name:", Devices::SystemInfo::getHostname() ); + writeParameter< String >( "System:", Devices::SystemInfo::getSystemName() ); + writeParameter< String >( "Release:", Devices::SystemInfo::getSystemRelease() ); + writeParameter< String >( "Architecture:", Devices::SystemInfo::getArchitecture() ); + writeParameter< String >( "TNL compiler:", compiler_name ); + // FIXME: generalize for multi-socket systems, here we consider only the first found CPU + const int cpu_id = 0; + const int threads = Devices::SystemInfo::getNumberOfThreads( cpu_id ); + const int cores = Devices::SystemInfo::getNumberOfCores( cpu_id ); + int threadsPerCore = 0; + if( cores > 0 ) + threadsPerCore = threads / cores; + writeParameter< String >( "CPU info", "" ); + writeParameter< String >( "Model name:", Devices::SystemInfo::getCPUModelName( cpu_id ), 1 ); + writeParameter< int >( "Cores:", cores, 1 ); + writeParameter< int >( "Threads per core:", threadsPerCore, 1 ); + writeParameter< double >( "Max clock rate (in MHz):", Devices::SystemInfo::getCPUMaxFrequency( cpu_id ) / 1000, 1 ); + const Devices::CacheSizes cacheSizes = Devices::SystemInfo::getCPUCacheSizes( cpu_id ); + const String cacheInfo = convertToString( cacheSizes.L1data ) + ", " + + convertToString( cacheSizes.L1instruction ) + ", " + + convertToString( cacheSizes.L2 ) + ", " + + convertToString( cacheSizes.L3 ); + writeParameter< String >( "Cache (L1d, L1i, L2, L3):", cacheInfo, 1 ); + + if( parameters.getParameter< String >( "device" ) == "cuda" ) { + writeParameter< String >( "CUDA GPU info", "" ); + // TODO: Printing all devices does not make sense until TNL can actually + // use more than one device for computations. Printing only the active + // device for now... + // int devices = getNumberOfDevices(); + // writeParameter< int >( "Number of devices", devices, 1 ); + // for( int i = 0; i < devices; i++ ) + // { + // logger.writeParameter< int >( "Device no.", i, 1 ); + const int i = Devices::CudaDeviceInfo::getActiveDevice(); + writeParameter< String >( "Name", Devices::CudaDeviceInfo::getDeviceName( i ), 2 ); + const String deviceArch = convertToString( Devices::CudaDeviceInfo::getArchitectureMajor( i ) ) + "." + + convertToString( Devices::CudaDeviceInfo::getArchitectureMinor( i ) ); + writeParameter< String >( "Architecture", deviceArch, 2 ); + writeParameter< int >( "CUDA cores", Devices::CudaDeviceInfo::getCudaCores( i ), 2 ); + const double clockRate = ( double ) Devices::CudaDeviceInfo::getClockRate( i ) / 1.0e3; + writeParameter< double >( "Clock rate (in MHz)", clockRate, 2 ); + const double globalMemory = ( double ) Devices::CudaDeviceInfo::getGlobalMemory( i ) / 1.0e9; + writeParameter< double >( "Global memory (in GB)", globalMemory, 2 ); + const double memoryClockRate = ( double ) Devices::CudaDeviceInfo::getMemoryClockRate( i ) / 1.0e3; + writeParameter< double >( "Memory clock rate (in Mhz)", memoryClockRate, 2 ); + writeParameter< bool >( "ECC enabled", Devices::CudaDeviceInfo::getECCEnabled( i ), 2 ); + // } + } return true; } -- GitLab From 6cd364342a4a8428989620d80b4a119e0a7bc3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 18:45:58 +0100 Subject: [PATCH 29/39] Removed explicit template instances of TestFunction --- src/TNL/Functions/CMakeLists.txt | 19 ++---------- src/TNL/Functions/TestFunction_impl.cpp | 41 ------------------------- src/TNL/Functions/TestFunction_impl.cu | 39 ----------------------- src/TNL/Functions/TestFunction_impl.h | 40 ------------------------ 4 files changed, 2 insertions(+), 137 deletions(-) delete mode 100644 src/TNL/Functions/TestFunction_impl.cpp delete mode 100644 src/TNL/Functions/TestFunction_impl.cu diff --git a/src/TNL/Functions/CMakeLists.txt b/src/TNL/Functions/CMakeLists.txt index 828720eb2..f596e3da6 100644 --- a/src/TNL/Functions/CMakeLists.txt +++ b/src/TNL/Functions/CMakeLists.txt @@ -12,7 +12,7 @@ SET( headers BoundaryMeshFunction.h MeshFunctionNormGetter.h MeshFunctionVTKWriter.h OperatorFunction.h - TestFunction.h + TestFunction.h TestFunction_impl.h VectorField.h VectorFieldEvaluator.h @@ -22,21 +22,6 @@ SET( headers BoundaryMeshFunction.h VectorFieldVTKWriter.h VectorFieldVTKWriter_impl.h CutMeshFunction.h - ) +) -SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL/Functions ) -set( common_SOURCES - ${CURRENT_DIR}/TestFunction_impl.cpp ) - -IF( BUILD_CUDA ) - set( tnl_functions_CUDA__SOURCES - ${common_SOURCES} - ${CURRENT_DIR}/TestFunction_impl.cu - PARENT_SCOPE ) -ENDIF() - -set( tnl_functions_SOURCES - ${common_SOURCES} - PARENT_SCOPE ) - INSTALL( FILES ${headers} DESTINATION ${TNL_TARGET_INCLUDE_DIRECTORY}/Functions ) diff --git a/src/TNL/Functions/TestFunction_impl.cpp b/src/TNL/Functions/TestFunction_impl.cpp deleted file mode 100644 index 83ab81ced..000000000 --- a/src/TNL/Functions/TestFunction_impl.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - TestFunction_impl.cpp - description - ------------------- - begin : Sep 21, 2014 - copyright : (C) 2014 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - - -#ifdef TEMPLATE_EXPLICIT_INSTANTIATION - -#include - - -namespace TNL { -namespace Functions { - -#ifdef INSTANTIATE_FLOAT -template class TestFunction< 1, float, Devices::Host >; -template class TestFunction< 2, float, Devices::Host >; -template class TestFunction< 3, float, Devices::Host >; -#endif - -template class TestFunction< 1, double, Devices::Host >; -template class TestFunction< 2, double, Devices::Host >; -template class TestFunction< 3, double, Devices::Host >; - -#ifdef INSTANTIATE_LONG_DOUBLE -template class TestFunction< 1, long double, Devices::Host >; -template class TestFunction< 2, long double, Devices::Host >; -template class TestFunction< 3, long double, Devices::Host >; -#endif - -} // namespace Functions -} // namespace TNL - - -#endif - diff --git a/src/TNL/Functions/TestFunction_impl.cu b/src/TNL/Functions/TestFunction_impl.cu deleted file mode 100644 index 3a6b701f3..000000000 --- a/src/TNL/Functions/TestFunction_impl.cu +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************** - TestFunction_impl.cu - description - ------------------- - begin : Sep 21, 2014 - copyright : (C) 2014 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#ifdef TEMPLATE_EXPLICIT_INSTANTIATION -#ifdef HAVE_CUDA - -#include - -namespace TNL { -namespace Functions { - -#ifdef INSTANTIATE_FLOAT -template class TestFunction< 1, float, Devices::Cuda >; -template class TestFunction< 2, float, Devices::Cuda >; -template class TestFunction< 3, float, Devices::Cuda >; -#endif - -template class TestFunction< 1, double, Devices::Cuda >; -template class TestFunction< 2, double, Devices::Cuda >; -template class TestFunction< 3, double, Devices::Cuda >; - -#ifdef INSTANTIATE_LONG_DOUBLE -template class TestFunction< 1, long double, Devices::Cuda >; -template class TestFunction< 2, long double, Devices::Cuda >; -template class TestFunction< 3, long double, Devices::Cuda >; -#endif - -} // namespace Functions -} // namespace TNL - -#endif -#endif diff --git a/src/TNL/Functions/TestFunction_impl.h b/src/TNL/Functions/TestFunction_impl.h index 3e7da8c33..f1776783c 100644 --- a/src/TNL/Functions/TestFunction_impl.h +++ b/src/TNL/Functions/TestFunction_impl.h @@ -960,45 +960,5 @@ TestFunction< FunctionDimension, Real, Device >:: deleteFunctions(); } - -#ifdef TEMPLATE_EXPLICIT_INSTANTIATION - -#ifdef INSTANTIATE_FLOAT -extern template class TestFunction< 1, float, Devices::Host >; -extern template class TestFunction< 2, float, Devices::Host >; -extern template class TestFunction< 3, float, Devices::Host >; -#endif - -extern template class TestFunction< 1, double, Devices::Host >; -extern template class TestFunction< 2, double, Devices::Host >; -extern template class TestFunction< 3, double, Devices::Host >; - -#ifdef INSTANTIATE_LONG_DOUBLE -extern template class TestFunction< 1, long double, Devices::Host >; -extern template class TestFunction< 2, long double, Devices::Host >; -extern template class TestFunction< 3, long double, Devices::Host >; -#endif - -#ifdef HAVE_CUDA -#ifdef INSTANTIATE_FLOAT -extern template class TestFunction< 1, float, Devices::Cuda>; -extern template class TestFunction< 2, float, Devices::Cuda >; -extern template class TestFunction< 3, float, Devices::Cuda >; -#endif - -extern template class TestFunction< 1, double, Devices::Cuda >; -extern template class TestFunction< 2, double, Devices::Cuda >; -extern template class TestFunction< 3, double, Devices::Cuda >; - -#ifdef INSTANTIATE_LONG_DOUBLE -extern template class TestFunction< 1, long double, Devices::Cuda >; -extern template class TestFunction< 2, long double, Devices::Cuda >; -extern template class TestFunction< 3, long double, Devices::Cuda >; -#endif -#endif - -#endif - } // namespace Functions } // namespace TNL - -- GitLab From 216d8284d8c5b0e16a3350531482793fb7a8b557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 20:08:55 +0100 Subject: [PATCH 30/39] Reimplemented TNL::String using std::string --- src/TNL/Config/ConfigEntryType.h | 20 +- src/TNL/Devices/SystemInfo_impl.h | 2 +- src/TNL/FileName.hpp | 14 +- src/TNL/Matrices/MatrixReader_impl.h | 10 +- src/TNL/Object_impl.h | 4 +- src/TNL/String.cpp | 275 +++++----------- src/TNL/String.h | 447 ++++++++++++--------------- src/UnitTests/StringTest.cpp | 123 +++----- 8 files changed, 346 insertions(+), 549 deletions(-) diff --git a/src/TNL/Config/ConfigEntryType.h b/src/TNL/Config/ConfigEntryType.h index 6c7b89299..bb656f8fc 100644 --- a/src/TNL/Config/ConfigEntryType.h +++ b/src/TNL/Config/ConfigEntryType.h @@ -12,6 +12,8 @@ #include +#include + namespace TNL { namespace Config { @@ -19,14 +21,14 @@ template< typename EntryType > inline String getUIEntryType() { return "Unknown type."; }; template<> inline String getUIEntryType< String >() { return "string"; }; -template<> inline String getUIEntryType< bool >() { return "bool"; }; -template<> inline String getUIEntryType< int >() { return "integer"; }; -template<> inline String getUIEntryType< double >() { return "real"; }; +template<> inline String getUIEntryType< bool >() { return "bool"; }; +template<> inline String getUIEntryType< int >() { return "integer"; }; +template<> inline String getUIEntryType< double >() { return "real"; }; template<> inline String getUIEntryType< std::vector< String > >() { return "list of string"; }; -template<> inline String getUIEntryType< std::vector< bool > >() { return "list of bool"; }; -template<> inline String getUIEntryType< std::vector< int > >() { return "list of integer"; }; -template<> inline String getUIEntryType< std::vector< double > >() { return "list of real"; }; +template<> inline String getUIEntryType< std::vector< bool > >() { return "list of bool"; }; +template<> inline String getUIEntryType< std::vector< int > >() { return "list of integer"; }; +template<> inline String getUIEntryType< std::vector< double > >() { return "list of real"; }; struct ConfigEntryType { @@ -34,17 +36,17 @@ struct ConfigEntryType bool list_entry; - ConfigEntryType() {} + ConfigEntryType() = default; ConfigEntryType( const String& _basic_type, - const bool _list_entry ) + const bool _list_entry ) : basic_type( _basic_type ), list_entry( _list_entry ) {} void Reset() { - basic_type. setString( 0 ); + basic_type.clear(); list_entry = false; } }; diff --git a/src/TNL/Devices/SystemInfo_impl.h b/src/TNL/Devices/SystemInfo_impl.h index 008ec644c..0bc426011 100644 --- a/src/TNL/Devices/SystemInfo_impl.h +++ b/src/TNL/Devices/SystemInfo_impl.h @@ -193,7 +193,7 @@ SystemInfo::parseCPUInfo( void ) { i = strlen( "model name" ); while( line[ i ] != ':' && line[ i ] ) i ++; - info.CPUModelName.setString( &line[ i + 1 ] ); + info.CPUModelName = &line[ i + 1 ]; continue; } if( strncmp( line, "cpu cores", strlen( "cpu cores" ) ) == 0 ) diff --git a/src/TNL/FileName.hpp b/src/TNL/FileName.hpp index 325335b6d..4cda1fda2 100644 --- a/src/TNL/FileName.hpp +++ b/src/TNL/FileName.hpp @@ -94,20 +94,18 @@ inline String FileName::getFileName() inline String getFileExtension( const String fileName ) { - int size = fileName. getLength(); + const int size = fileName.getLength(); int i = 1; - while( fileName. getString()[ size - i ] != '.' && size > i ) i ++ ; - String result; - result.setString( fileName. getString(), size - i + 1 ); - return result; + while( fileName[ size - i ] != '.' && size > i ) i++; + return fileName.substr( size - i + 1 ); } inline void removeFileExtension( String& fileName ) { - int size = fileName. getLength(); + const int size = fileName.getLength(); int i = 1; - while( fileName. getString()[ size - i ] != '.' && size > i ) i ++ ; - fileName. setString( fileName. getString(), 0, i ); + while( fileName[ size - i ] != '.' && size > i ) i++; + fileName = fileName.substr( 0, size - i + 1 ); } } // namespace TNL diff --git a/src/TNL/Matrices/MatrixReader_impl.h b/src/TNL/Matrices/MatrixReader_impl.h index fb5bf06d6..eacf8911a 100644 --- a/src/TNL/Matrices/MatrixReader_impl.h +++ b/src/TNL/Matrices/MatrixReader_impl.h @@ -92,7 +92,7 @@ bool MatrixReader< Matrix >::verifyMtxFile( std::istream& file, IndexType processedElements( 0 ); Timer timer; timer.start(); - while( line.getLine( file ) ) + while( std::getline( file, line ) ) { if( line[ 0 ] == '%' ) continue; if( ! dimensionsLine ) @@ -141,7 +141,7 @@ bool MatrixReader< Matrix >::findLineByElement( std::istream& file, bool symmetricMatrix( false ); bool dimensionsLine( false ); lineNumber = 0; - while( line.getLine( file ) ) + while( std::getline( file, line ) ) { lineNumber++; if( line[ 0 ] == '%' ) continue; @@ -213,7 +213,7 @@ bool MatrixReader< Matrix >::readMtxHeader( std::istream& file, std::vector< String > parsedLine; while( true ) { - line.getLine( file ); + std::getline( file, line ); if( ! headerParsed ) { headerParsed = checkMtxHeader( line, symmetric ); @@ -269,7 +269,7 @@ bool MatrixReader< Matrix >::computeCompressedRowLengthsFromMtxFile( std::istrea IndexType numberOfElements( 0 ); Timer timer; timer.start(); - while( line.getLine( file ) ) + while( std::getline( file, line ) ) { if( line[ 0 ] == '%' ) continue; if( ! dimensionsLine ) @@ -340,7 +340,7 @@ bool MatrixReader< Matrix >::readMatrixElementsFromMtxFile( std::istream& file, IndexType processedElements( 0 ); Timer timer; timer.start(); - while( line.getLine( file ) ) + while( std::getline( file, line ) ) { if( line[ 0 ] == '%' ) continue; if( ! dimensionsLine ) diff --git a/src/TNL/Object_impl.h b/src/TNL/Object_impl.h index 51075d85a..fe09ac5f3 100644 --- a/src/TNL/Object_impl.h +++ b/src/TNL/Object_impl.h @@ -146,7 +146,7 @@ parseObjectType( const String& objectType ) */ while( i < objectTypeLength && objectType[ i ] != '<' ) i++; - String objectName( objectType.getString(), 0, objectTypeLength - i ); + String objectName = objectType.substr( 0, i ); parsedObjectType.push_back( objectName ); i++; @@ -170,7 +170,7 @@ parseObjectType( const String& objectType ) if( buffer != "" ) { parsedObjectType.push_back( buffer.strip( ' ' ) ); - buffer.setString( "" ); + buffer.clear(); } } else buffer += objectType[ i ]; diff --git a/src/TNL/String.cpp b/src/TNL/String.cpp index 2c9f7d5c3..ec75f0c35 100644 --- a/src/TNL/String.cpp +++ b/src/TNL/String.cpp @@ -8,48 +8,21 @@ /* See Copyright Notice in tnl/Copyright */ -#include -#include #include #include #include #include -#ifdef USE_MPI - #include -#endif +//#ifdef USE_MPI +// #include +//#endif namespace TNL { -const unsigned int STRING_PAGE = 256; - -String::String() - : string( nullptr ), length( 0 ) -{ - setString( nullptr ); -} - -String::String( const char* c, int prefix_cut_off, int sufix_cut_off ) - : string( nullptr ), length( 0 ) -{ - setString( c, prefix_cut_off, sufix_cut_off ); -} - -String::String( const String& str ) - : string( nullptr ), length( 0 ) -{ - setString( str.getString() ); -} - String String::getType() { return String( "String" ); } -String::~String() -{ - if( string ) delete[] string; -} - int String::getLength() const { return getSize(); @@ -57,99 +30,72 @@ int String::getLength() const int String::getSize() const { - return strlen( string ); + return this->size(); } int String::getAllocatedSize() const { - return length; + return this->capacity(); } void String::setSize( int size ) { TNL_ASSERT_GE( size, 0, "string size must be non-negative" ); - const int _length = STRING_PAGE * ( size / STRING_PAGE + 1 ); - TNL_ASSERT_GE( _length, 0, "_length size must be non-negative" ); - if( length != _length ) { - if( string ) { - delete[] string; - string = nullptr; - } - string = new char[ _length ]; - length = _length; - } -} - -void String::setString( const char* c, int prefix_cut_off, int sufix_cut_off ) -{ - if( ! c ) { - if( ! string ) - setSize( 1 ); - string[ 0 ] = 0; - return; - } - const int c_len = ( int ) strlen( c ); - const int _length = max( 0, c_len - prefix_cut_off - sufix_cut_off ); - - if( length < _length || length == 0 ) - setSize( _length ); - TNL_ASSERT( string, ); - memcpy( string, c + min( c_len, prefix_cut_off ), _length * sizeof( char ) ); - string[ _length ] = 0; + this->reserve( size ); } const char* String::getString() const { - return string; -} - -char* String::getString() -{ - return string; + return this->c_str(); } const char& String::operator[]( int i ) const { - TNL_ASSERT( i >= 0 && i < length, + TNL_ASSERT( i >= 0 && i < getLength(), std::cerr << "Accessing char outside the string." ); - return string[ i ]; + return std::string::operator[]( i ); } char& String::operator[]( int i ) { - TNL_ASSERT( i >= 0 && i < length, + TNL_ASSERT( i >= 0 && i < getLength(), std::cerr << "Accessing char outside the string." ); - return string[ i ]; + return std::string::operator[]( i ); } /**** - * Operators for C strings + * Operators for single characters */ -String& String::operator=( const char* str ) +String& String::operator+=( char str ) { - setString( str ); + std::string::operator+=( str ); return *this; } +String String::operator+( char str ) const +{ + return String( *this ) += str; +} + +bool String::operator==( char str ) const +{ + return std::string( *this ) == std::string( 1, str ); +} + +bool String::operator!=( char str ) const +{ + return ! operator==( str ); +} + + +/**** + * Operators for C strings + */ String& String::operator+=( const char* str ) { - if( str ) - { - const int len1 = strlen( string ); - const int len2 = strlen( str ); - if( len1 + len2 < length ) - memcpy( string + len1, str, sizeof( char ) * ( len2 + 1 ) ); - else - { - char* tmp_string = string; - length = STRING_PAGE * ( ( len1 + len2 ) / STRING_PAGE + 1 ); - string = new char[ length ]; - memcpy( string, tmp_string, sizeof( char ) * len1 ); - memcpy( string + len1, str, sizeof( char ) * ( len2 + 1 ) ); - } - } + std::string::operator+=( str ); return *this; } @@ -160,8 +106,7 @@ String String::operator+( const char* str ) const bool String::operator==( const char* str ) const { - TNL_ASSERT( string && str, ); - return strcmp( string, str ) == 0; + return std::string( *this ) == str; } bool String::operator!=( const char* str ) const @@ -171,78 +116,50 @@ bool String::operator!=( const char* str ) const /**** - * Operators for Strings + * Operators for std::string */ -String& String::operator=( const String& str ) +String& String::operator+=( const std::string& str ) { - setString( str.getString() ); + std::string::operator+=( str ); return *this; } -String& String::operator+=( const String& str ) -{ - return operator+=( str.getString() ); -} - -String String::operator+( const String& str ) const +String String::operator+( const std::string& str ) const { return String( *this ) += str; } -bool String::operator==( const String& str ) const +bool String::operator==( const std::string& str ) const { - TNL_ASSERT( string && str.string, ); - return strcmp( string, str.string ) == 0; + return std::string( *this ) == str; } -bool String::operator!=( const String& str ) const +bool String::operator!=( const std::string& str ) const { return ! operator==( str ); } /**** - * Operators for single characters + * Operators for String */ -String& String::operator=( char str ) -{ - string[ 0 ] = str; - string[ 1 ] = 0; - return *this; -} - -String& String::operator+=( const char str ) +String& String::operator+=( const String& str ) { - const int len1 = strlen( string ); - if( len1 + 1 < length ) - { - string[ len1 ] = str; - string[ len1 + 1 ] = 0; - } - else - { - char* tmp_string = string; - length += STRING_PAGE; - string = new char[ length ]; - memcpy( string, tmp_string, sizeof( char ) * len1 ); - string[ len1 ] = str; - string[ len1 + 1 ] = 0; - } - + std::string::operator+=( str ); return *this; } -String String::operator+( char str ) const +String String::operator+( const String& str ) const { return String( *this ) += str; } -bool String::operator==( char str ) const +bool String::operator==( const String& str ) const { - return *this == convertToString( str ); + return std::string( *this ) == str; } -bool String::operator!=( char str ) const +bool String::operator!=( const String& str ) const { return ! operator==( str ); } @@ -250,8 +167,7 @@ bool String::operator!=( char str ) const String::operator bool () const { - if( string[ 0 ] ) return true; - return false; + return getLength(); } bool String::operator!() const @@ -263,56 +179,19 @@ String String::replace( const String& pattern, const String& replaceWith, int count ) const { - const int length = this->getLength(); - const int patternLength = pattern.getLength(); - const int replaceWithLength = replaceWith.getLength(); + std::string newString = *this; - int patternPointer = 0; - int occurrences = 0; - for( int i = 0; i < length; i++ ) - { - if( this->string[ i ] == pattern[ patternPointer ] ) - patternPointer++; - if( patternPointer == patternLength ) - { - occurrences++; - patternPointer = 0; - } - } - if( count > 0 && occurrences > count ) - occurrences = count; - - String newString; - const int newStringLength = length + occurrences * ( replaceWithLength - patternLength ); - newString.setSize( newStringLength ); - - int newStringHead = 0; - patternPointer = 0; - occurrences = 0; - for( int i = 0; i < length; i++ ) { - // copy current character - newString[ newStringHead++ ] = this->string[ i ]; - - // check if pattern matches - if( this->string[ i ] == pattern[ patternPointer ] ) - patternPointer++; - else - patternPointer = 0; - - // handle full match - if( patternPointer == patternLength ) { - // skip unwanted replacements - if( count == 0 || occurrences < count ) { - newStringHead -= patternLength; - for( int j = 0; j < replaceWithLength; j++ ) - newString[ newStringHead++ ] = replaceWith[ j ]; - } - occurrences++; - patternPointer = 0; - } - } + std::size_t index = 0; + for( int i = 0; i < count || count == 0; i++ ) { + // locate the substring to replace + index = newString.find( pattern, index ); + if( index == std::string::npos ) + break; - newString[ newStringHead ] = 0; + // make the replacement + newString.replace( index, pattern.getLength(), replaceWith ); + index += replaceWith.getLength(); + } return newString; } @@ -330,7 +209,7 @@ String::strip( char strip ) const sufix_cut_off++; if( prefix_cut_off + sufix_cut_off < getLength() ) - return String( getString(), prefix_cut_off, sufix_cut_off ); + return substr( prefix_cut_off, getLength() - prefix_cut_off - sufix_cut_off ); return ""; } @@ -354,30 +233,27 @@ std::vector< String > String::split( const char separator, bool skipEmpty ) cons bool String::save( File& file ) const { - TNL_ASSERT( string, - std::cerr << "string = " << string ); - - int len = strlen( string ); + const int len = getLength(); if( ! file.write( &len ) ) return false; - if( ! file.write( string, len ) ) + if( ! file.write( this->c_str(), len ) ) return false; return true; } bool String::load( File& file ) { - int _length; - if( ! file.read( &_length ) ) { + int length; + if( ! file.read( &length ) ) { std::cerr << "I was not able to read String length." << std::endl; return false; } - setSize( _length ); - if( _length && ! file.read( string, _length ) ) { + char buffer[ length ]; + if( length && ! file.read( buffer, length ) ) { std::cerr << "I was not able to read a String with a length " << length << "." << std::endl; return false; } - string[ _length ] = 0; + this->assign( buffer, length ); return true; } @@ -408,14 +284,6 @@ bool String::load( File& file ) #endif } */ -bool String :: getLine( std::istream& stream ) -{ - std::string str; - getline( stream, str ); - this->setString( str.c_str() ); - if( ! ( *this ) ) return false; - return true; -} String operator+( char string1, const String& string2 ) { @@ -427,6 +295,11 @@ String operator+( const char* string1, const String& string2 ) return String( string1 ) + string2; } +String operator+( const std::string& string1, const String& string2 ) +{ + return String( string1 ) + string2; +} + std::ostream& operator<<( std::ostream& stream, const String& str ) { stream << str.getString(); diff --git a/src/TNL/String.h b/src/TNL/String.h index e69fa36f0..baeaf6545 100644 --- a/src/TNL/String.h +++ b/src/TNL/String.h @@ -13,15 +13,13 @@ #include #include #include +#include namespace TNL { class File; class String; -template< typename T > -String convertToString( const T& value ); - ///// /// \brief Class for managing strings. /// @@ -30,244 +28,208 @@ String convertToString( const T& value ); /// \par Output /// \include StringExample.out class String +: public std::string { - public: - - ///// - /// \brief Basic constructor. - /// - /// Constructs an empty string object. - String(); - - ///// - /// \brief Constructor with char pointer. - /// - /// Constructs a string initialized with the 8-bit string \e c, excluding - /// the given number of \e prefix_cut_off and \e sufix_cut_off characters. - /// - /// @param c Pointer to an array of characters. - /// @param prefix_cut_off Determines the length of the prefix that is going - /// to be omitted from the string \e c. - /// @param sufix_cut_off Determines the length of the sufix that is going - /// to be omitted from the string \e c. - String( const char* c, - int prefix_cut_off = 0, - int sufix_cut_off = 0 ); - - /// \brief Returns type of string - String. - static String getType(); - - ///// - /// \brief Copy constructor. - /// - /// Constructs a copy of the string \e str. - /// @param str Another string object, whose value is copied. - String( const String& str ); - - /// \brief Destructor. - ~String(); - - /// \brief Returns the number of characters in given string. Equivalent to getSize(). - int getLength() const; - - /// \brief Returns the number of characters in given string. - /// - /// \par Example - /// \include StringExampleGetSize.cpp - /// \par Output - /// \include StringExampleGetSize.out - int getSize() const; - - /// \brief Returns size of allocated storage for given string. - /// - /// \par Example - /// \include StringExampleGetAllocatedSize.cpp - /// \par Output - /// \include StringExampleGetAllocatedSize.out - int getAllocatedSize() const; - - ///// - /// \brief Reserves space for given \e size. - /// - /// Requests to allocate storage space of given \e size to avoid memory reallocation. - /// It allocates one more byte for the terminating 0. - /// @param size Number of characters. - /// - /// \par Example - /// \include StringExampleSetSize.cpp - /// \par Output - /// \include StringExampleSetSize.out - void setSize( int size ); - - ///// - /// \brief Sets string from given char pointer \e c. - /// - /// @param prefix_cut_off determines the length of the prefix that is - /// going to be omitted from the string \e c - /// @param sufix_cut_off determines the length of the sufix that is going - /// to be omitted from the string \e c - void setString( const char* c, - int prefix_cut_off = 0, - int sufix_cut_off = 0 ); - - ///// - /// \brief Returns pointer to data. - /// - /// It returns the content of the given string as a constant pointer to char. - const char* getString() const; - - /// \brief Returns pointer to data. - /// - /// It returns the content of the given string as a non-constant pointer to char. - char* getString(); - - ///// - /// \brief Operator for accessing particular chars of the string. - /// - /// This function overloads operator[](). It returns a reference to - /// the character at position \e i in given string. - /// The character can not be changed be user. - const char& operator[]( int i ) const; - - /// \brief Operator for accessing particular chars of the string. - /// - /// It returns the character at the position \e i in given string as - /// a modifiable reference. - char& operator[]( int i ); - - ///// - // Operators for C strings. - - /// \brief This function overloads operator=(). - /// - /// It assigns C string \e str to this string, replacing its current contents. - String& operator=( const char* str ); - /// \brief This function overloads operator+=(). - /// - /// It appends the C string \e str to this string. - String& operator+=( const char* str ); - /// \brief This function concatenates C strings \e str and returns a newly - /// constructed string object. - String operator+( const char* str ) const; - /// \brief This function overloads operator==(). - bool operator==( const char* str ) const; - /// \brief This function overloads operator!=(). - bool operator!=( const char* str ) const; - - ///// - // Operators for Strings. - - /// \brief This function assigns \e str to this string and returns a reference to - /// this string. - String& operator=( const String& str ); - /// \brief This function appends the string \e str onto the end of this string - /// and returns a reference to this string. - String& operator+=( const String& str ); - /// \brief This function concatenates strings \e str and returns a newly - /// constructed string object. - String operator+( const String& str ) const; - /// \brief This function overloads operator==(). - /// - /// Returns \c true if this string is equal to \e str, otherwise returns - /// \c false. - bool operator==( const String& str ) const; - /// \brief This function overloads operator!=(). - /// - /// Returns \c true if this string is not equal to \e str, otherwise - /// returns \c false. - bool operator!=( const String& str ) const; - - ///// - // Operators for single characters. - - /// \brief This function overloads operator=(). - /// - /// Assigns character \e str to this string. - String& operator=( char str ); - /// \brief This function overloads operator+=(). - /// - /// Appends character \e str to this string. - String& operator+=( char str ); - /// \brief This function concatenates strings and returns a newly constructed string object. - String operator+( char str ) const; - /// \brief This function checks whether the given string is equal to \e str. - /// - /// It returns \e true when the given string is equal to \e str. Otherwise returns \e false. - bool operator==( char str ) const; - /// \brief This function overloads operator!=(). - bool operator!=( char str ) const; - - /// \brief Cast to bool operator. - /// - /// This function overloads operator bool(). It converts string to boolean - /// expression (true or false). - operator bool() const; - - /// \brief Cast to bool with negation operator. - /// - /// This function overloads operator!(). It converts string to boolean - /// expression (false or true). - bool operator!() const; - - ///// - /// \brief Replaces portion of string. - /// - /// Replaces section \e pattern from this string with new piece of string \e replaceWith. - /// If parameter \e count is defined, the function makes replacement several times, - /// every time when it finds the same pattern in this string. - /// @param pattern Section of given string that will be replaced. - /// @param replaceWith New piece of string that will be used to replace \e pattern. - /// @param count A whole number that specifies how many replacements should be done. - String replace( const String& pattern, - const String& replaceWith, - int count = 0 ) const; - - ///// - /// \brief Trims/strips given string. - /// - /// Removes all spaces from given string except for single spaces between words. - String strip( char strip = ' ' ) const; - - /// \brief Splits string into list of strings with respect to given \e separator. - /// - /// Splits the string into list of substrings wherever \e separator occurs, - /// and returs list of those strings. When \e separator does not appear - /// anywhere in the given string, this function returns a single-element list - /// containing given sting. - /// @param separator Character, which separates substrings in given string. - /// Empty character can not be used. - std::vector< String > split( const char separator = ' ', bool skipEmpty = false ) const; - - ///// - /// \brief Function for saving file. - /// - /// Writes the string to a binary file and returns boolean expression based on the - /// success in writing into the file. - bool save( File& file ) const; - - ///// - /// \brief Function for loading from file. - /// - /// Reads a string from binary file and returns boolean expression based on the - /// success in reading the file. - bool load( File& file ); - - ///// - /// \brief Function for getting a line from stream. - /// - /// Reads one line from given stream and returns either the line or boolean - /// expression based on the success in reading the line. - bool getLine( std::istream& stream ); - - protected: - - /// \brief Pointer to char ended with zero byte. - char* string; - - /// \brief Length of allocated piece of memory. - int length; - -}; // class String +public: + ///// + /// \brief Default constructor. + /// + /// Constructs an empty string object. + String() = default; + + /// \brief Default copy constructor. + String( const String& ) = default; + + /// \brief Default move constructor. + String( String&& ) = default; + + /// \brief Initialization by \e std::string. + String( const std::string& str ) : std::string( str ) {} + + /// \brief Default copy assignment operator. + String& operator=( const String& ) = default; + + /// \brief Default move assignment operator. + String& operator=( String&& ) = default; + + /// \brief Inherited constructors and assignment operators. + using std::string::string; + using std::string::operator=; + + + /// \brief Returns type of string - String. + static String getType(); + + /// \brief Returns the number of characters in given string. Equivalent to getSize(). + int getLength() const; + + /// \brief Returns the number of characters in given string. + /// + /// \par Example + /// \include StringExampleGetSize.cpp + /// \par Output + /// \include StringExampleGetSize.out + int getSize() const; + + /// \brief Returns size of allocated storage for given string. + /// + /// \par Example + /// \include StringExampleGetAllocatedSize.cpp + /// \par Output + /// \include StringExampleGetAllocatedSize.out + int getAllocatedSize() const; + + ///// + /// \brief Reserves space for given \e size. + /// + /// Requests to allocate storage space of given \e size to avoid memory reallocation. + /// It allocates one more byte for the terminating 0. + /// @param size Number of characters. + /// + /// \par Example + /// \include StringExampleSetSize.cpp + /// \par Output + /// \include StringExampleSetSize.out + void setSize( int size ); + + ///// + /// \brief Returns pointer to data. + /// + /// It returns the content of the given string as a constant pointer to char. + const char* getString() const; + + ///// + /// \brief Operator for accessing particular chars of the string. + /// + /// This function overloads operator[](). It returns a reference to + /// the character at position \e i in given string. + /// The character can not be changed be user. + const char& operator[]( int i ) const; + + /// \brief Operator for accessing particular chars of the string. + /// + /// It returns the character at the position \e i in given string as + /// a modifiable reference. + char& operator[]( int i ); + + ///// + // Operators for single characters. + + /// \brief This function overloads operator+=(). + /// + /// Appends character \e str to this string. + String& operator+=( char str ); + /// \brief This function concatenates strings and returns a newly constructed string object. + String operator+( char str ) const; + /// \brief This function checks whether the given string is equal to \e str. + /// + /// It returns \e true when the given string is equal to \e str. Otherwise returns \e false. + bool operator==( char str ) const; + /// \brief This function overloads operator!=(). + bool operator!=( char str ) const; + + ///// + // Operators for C strings. + + /// \brief This function overloads operator+=(). + /// + /// It appends the C string \e str to this string. + String& operator+=( const char* str ); + /// \brief This function concatenates C strings \e str and returns a newly + /// constructed string object. + String operator+( const char* str ) const; + /// \brief This function overloads operator==(). + bool operator==( const char* str ) const; + /// \brief This function overloads operator!=(). + bool operator!=( const char* str ) const; + + ///// + // Operators for std::string. + + /// \brief This function overloads operator+=(). + /// + /// It appends the C string \e str to this string. + String& operator+=( const std::string& str ); + /// \brief This function concatenates C strings \e str and returns a newly + /// constructed string object. + String operator+( const std::string& str ) const; + /// \brief This function overloads operator==(). + bool operator==( const std::string& str ) const; + /// \brief This function overloads operator!=(). + bool operator!=( const std::string& str ) const; + + ///// + // Operators for String. + + /// \brief This function overloads operator+=(). + /// + /// It appends the C string \e str to this string. + String& operator+=( const String& str ); + /// \brief This function concatenates C strings \e str and returns a newly + /// constructed string object. + String operator+( const String& str ) const; + /// \brief This function overloads operator==(). + bool operator==( const String& str ) const; + /// \brief This function overloads operator!=(). + bool operator!=( const String& str ) const; + + /// \brief Cast to bool operator. + /// + /// This function overloads operator bool(). It converts string to boolean + /// expression (true or false). + operator bool() const; + + /// \brief Cast to bool with negation operator. + /// + /// This function overloads operator!(). It converts string to boolean + /// expression (false or true). + bool operator!() const; + + ///// + /// \brief Replaces portion of string. + /// + /// Replaces section \e pattern from this string with new piece of string \e replaceWith. + /// If parameter \e count is defined, the function makes replacement several times, + /// every time when it finds the same pattern in this string. + /// @param pattern Section of given string that will be replaced. + /// @param replaceWith New piece of string that will be used to replace \e pattern. + /// @param count A whole number that specifies how many replacements should be done. + String replace( const String& pattern, + const String& replaceWith, + int count = 0 ) const; + + ///// + /// \brief Trims/strips given string. + /// + /// Removes all spaces from given string except for single spaces between words. + String strip( char strip = ' ' ) const; + + /// \brief Splits string into list of strings with respect to given \e separator. + /// + /// Splits the string into list of substrings wherever \e separator occurs, + /// and returs list of those strings. When \e separator does not appear + /// anywhere in the given string, this function returns a single-element list + /// containing given sting. + /// @param separator Character, which separates substrings in given string. + std::vector< String > split( const char separator = ' ', bool skipEmpty = false ) const; + + ///// + /// \brief Function for saving file. + /// + /// Writes the string to a binary file and returns boolean expression based on the + /// success in writing into the file. + bool save( File& file ) const; + + ///// + /// \brief Function for loading from file. + /// + /// Reads a string from binary file and returns boolean expression based on the + /// success in reading the file. + bool load( File& file ); + + //! Broadcast to other nodes in MPI cluster +// void MPIBcast( int root, MPI_Comm mpi_comm = MPI_COMM_WORLD ); +}; /// \brief Returns concatenation of \e string1 and \e string2. String operator+( char string1, const String& string2 ); @@ -275,6 +237,9 @@ String operator+( char string1, const String& string2 ); /// \brief Returns concatenation of \e string1 and \e string2. String operator+( const char* string1, const String& string2 ); +/// \brief Returns concatenation of \e string1 and \e string2. +String operator+( const std::string& string1, const String& string2 ); + /// \brief Performs the string output to a stream std::ostream& operator<<( std::ostream& stream, const String& str ); @@ -284,7 +249,7 @@ String convertToString( const T& value ) std::stringstream str; str << value; return String( str.str().data() ); -}; +} template<> inline String convertToString( const bool& b ) { diff --git a/src/UnitTests/StringTest.cpp b/src/UnitTests/StringTest.cpp index b1346355f..53934e950 100644 --- a/src/UnitTests/StringTest.cpp +++ b/src/UnitTests/StringTest.cpp @@ -23,20 +23,7 @@ using namespace TNL; TEST( StringTest, BasicConstructor ) { String str; - EXPECT_EQ( strcmp( str.getString(), "" ), 0 ); -} - -TEST( StringTest, ConstructorWithChar ) -{ - String str1( "string1" ); - String str2( "xxxstring2", 3 ); - String str3( "string3xxx", 0, 3 ); - String str4( "xxxstring4xxx", 3, 3 ); - - EXPECT_EQ( strcmp( str1.getString(), "string1" ), 0 ); - EXPECT_EQ( strcmp( str2.getString(), "string2" ), 0 ); - EXPECT_EQ( strcmp( str3.getString(), "string3" ), 0 ); - EXPECT_EQ( strcmp( str4.getString(), "string4" ), 0 ); + EXPECT_STREQ( str.getString(), "" ); } TEST( StringTest, CopyConstructor ) @@ -46,8 +33,8 @@ TEST( StringTest, CopyConstructor ) String string2( string ); String emptyString2( emptyString ); - EXPECT_EQ( strcmp( string2.getString(), "string1" ), 0 ); - EXPECT_EQ( strcmp( emptyString2.getString(), "" ), 0 ); + EXPECT_STREQ( string2.getString(), "string1" ); + EXPECT_STREQ( emptyString2.getString(), "" ); } TEST( StringTest, convertToString ) @@ -57,10 +44,10 @@ TEST( StringTest, convertToString ) String string3 = convertToString( true ); String string4 = convertToString( false ); - EXPECT_EQ( strcmp( string1.getString(), "10" ), 0 ); - EXPECT_EQ( strcmp( string2.getString(), "-5" ), 0 ); - EXPECT_EQ( strcmp( string3.getString(), "true" ), 0 ); - EXPECT_EQ( strcmp( string4.getString(), "false" ), 0 ); + EXPECT_STREQ( string1.getString(), "10" ); + EXPECT_STREQ( string2.getString(), "-5" ); + EXPECT_STREQ( string3.getString(), "true" ); + EXPECT_STREQ( string4.getString(), "false" ); } TEST( StringTest, GetSize ) @@ -88,35 +75,15 @@ TEST( StringTest, GetAllocatedSize ) { String str( "MeineKleine" ); - EXPECT_EQ( str.getAllocatedSize(), 256 ); + EXPECT_EQ( str.getLength(), 11 ); + EXPECT_GE( str.getAllocatedSize(), str.getLength() ); } TEST( StringTest, SetSize ) { String str; str.setSize( 42 ); - EXPECT_EQ( str.getAllocatedSize(), 256 ); - // it allocates one more byte for the terminating 0 - str.setSize( 256 ); - EXPECT_EQ( str.getAllocatedSize(), 512 ); -} - -TEST( StringTest, SetString ) -{ - String str1, str2, str3, str4; - - str1.setString( "string1" ); - str2.setString( "xxxstring2", 3 ); - str3.setString( "string3xxx", 0, 3 ); - str4.setString( "xxxstring4xxx", 3, 3 ); - - EXPECT_EQ( strcmp( str1.getString(), "string1" ), 0 ); - EXPECT_EQ( strcmp( str2.getString(), "string2" ), 0 ); - EXPECT_EQ( strcmp( str3.getString(), "string3" ), 0 ); - EXPECT_EQ( strcmp( str4.getString(), "string4" ), 0 ); - - str4.setString( "string4_2", 0, 2 ); - EXPECT_EQ( strcmp( str4.getString(), "string4" ), 0 ); + EXPECT_GT( str.getAllocatedSize(), 0 ); } TEST( StringTest, GetString ) @@ -145,28 +112,28 @@ TEST( StringTest, CStringOperators ) // assignment operator String string1; string1 = "string"; - EXPECT_EQ( strcmp( string1.getString(), "string" ), 0 ); + EXPECT_STREQ( string1.getString(), "string" ); // addition string1 += "string2"; - EXPECT_EQ( strcmp( string1.getString(), "stringstring2" ), 0 ); + EXPECT_STREQ( string1.getString(), "stringstring2" ); // addition that forces a new page allocation string1 += " long long long long long long long long long long long long long long" " long long long long long long long long long long long long long long" " long long long long long long long long long long long long long long" " long long long long long long long long long long long long long long"; - EXPECT_EQ( strcmp( string1.getString(), + EXPECT_STREQ( string1.getString(), "stringstring2" " long long long long long long long long long long long long long long" " long long long long long long long long long long long long long long" " long long long long long long long long long long long long long long" - " long long long long long long long long long long long long long long" ), - 0 ); + " long long long long long long long long long long long long long long" + ); // addition - EXPECT_EQ( strcmp( (String( "foo " ) + "bar").getString(), "foo bar" ), 0 ); - EXPECT_EQ( strcmp( ("foo" + String( " bar" )).getString(), "foo bar" ), 0 ); + EXPECT_STREQ( (String( "foo " ) + "bar").getString(), "foo bar" ); + EXPECT_STREQ( ("foo" + String( " bar" )).getString(), "foo bar" ); // comparison EXPECT_EQ( String( "foo" ), "foo" ); @@ -180,12 +147,12 @@ TEST( StringTest, StringOperators ) String string1( "string" ); String string2; string2 = string1; - EXPECT_EQ( strcmp( string2.getString(), "string" ), 0 ); + EXPECT_STREQ( string2.getString(), "string" ); // addition - string1.setString( "foo " ); + string1 = "foo "; string1 += String( "bar" ); - EXPECT_EQ( strcmp( string1.getString(), "foo bar" ), 0 ); + EXPECT_STREQ( string1.getString(), "foo bar" ); // comparison EXPECT_EQ( String( "foo bar" ), string1 ); @@ -205,12 +172,20 @@ TEST( StringTest, StringOperators ) "long long long long long long long long long long long " "long long long long long long long long long long long" ); string3[ 255 ] = 0; - EXPECT_EQ( string3, + // std::string knows the original length + EXPECT_NE( string3, String( "long long long long long long long long long long long " "long long long long long long long long long long long " "long long long long long long long long long long long " "long long long long long long long long long long long " "long long long long long long long " ) ); + // C string can be terminated in the middle + EXPECT_STREQ( string3.getString(), + "long long long long long long long long long long long " + "long long long long long long long long long long long " + "long long long long long long long long long long long " + "long long long long long long long long long long long " + "long long long long long long long " ); // addition EXPECT_EQ( String( "foo " ) + String( "bar" ), "foo bar" ); @@ -221,30 +196,30 @@ TEST( StringTest, SingleCharacterOperators ) // assignment String string1; string1 = 'A'; - EXPECT_EQ( strcmp( string1.getString(), "A" ), 0 ); + EXPECT_STREQ( string1.getString(), "A" ); // addition of a single character String string2( "string " ); string2 += 'A'; - EXPECT_EQ( strcmp( string2.getString(), "string A" ), 0 ); + EXPECT_STREQ( string2.getString(), "string A" ); // addition of a single character that causes new page allocation - string2.setString( "long long long long long long long long long long long long long " - "long long long long long long long long long long long long long " - "long long long long long long long long long long long long long " - "long long long long long long long long long long long long " ); + string2 = "long long long long long long long long long long long long long " + "long long long long long long long long long long long long long " + "long long long long long long long long long long long long long " + "long long long long long long long long long long long long "; ASSERT_EQ( string2.getLength(), 255 ); string2 += 'B'; - EXPECT_EQ( strcmp( string2.getString(), + EXPECT_STREQ( string2.getString(), "long long long long long long long long long long long long long " "long long long long long long long long long long long long long " "long long long long long long long long long long long long long " - "long long long long long long long long long long long long B" ), - 0 ); + "long long long long long long long long long long long long B" + ); // addition - EXPECT_EQ( strcmp( (String( "A " ) + 'B').getString(), "A B" ), 0 ); - EXPECT_EQ( strcmp( ('A' + String( " B" )).getString(), "A B" ), 0 ); + EXPECT_STREQ( (String( "A " ) + 'B').getString(), "A B" ); + EXPECT_STREQ( ('A' + String( " B" )).getString(), "A B" ); // comparison EXPECT_EQ( String( "A" ), 'A' ); @@ -257,7 +232,7 @@ TEST( StringTest, CastToBoolOperator ) String string; EXPECT_TRUE( ! string ); EXPECT_FALSE( string ); - string.setString( "foo" ); + string = "foo"; EXPECT_TRUE( string ); EXPECT_FALSE( ! string ); } @@ -342,22 +317,6 @@ TEST( StringTest, SaveLoad ) EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); }; -TEST( StringTest, getLine ) -{ - std::stringstream str; - str << "Line 1" << std::endl; - str << "Line 2" << std::endl; - str.seekg( 0 ); - - String s; - - s.getLine( str ); - EXPECT_EQ( s, "Line 1" ); - - s.getLine( str ); - EXPECT_EQ( s, "Line 2" ); -}; - #endif #include "GtestMissingError.h" -- GitLab From b6d5bf7cca8ab4976c5bcf8d34696eb0370a3bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 20:39:40 +0100 Subject: [PATCH 31/39] New way of (de)serialization of objects into TNL::File using operator<< and operator>> (starting with string) This is nicer and safer (thanks to exceptions) than save/load functions. Moreover, it breaks the last cyclic dependency between TNL classes. --- src/Python/pytnl/tnl/String.cpp | 9 ++---- src/TNL/Exceptions/FileDeserializationError.h | 31 +++++++++++++++++++ src/TNL/Exceptions/FileSerializationError.h | 31 +++++++++++++++++++ src/TNL/File.h | 6 ++++ src/TNL/File_impl.h | 27 ++++++++++++++++ src/TNL/Object_impl.h | 22 ++++++------- src/TNL/String.cpp | 28 ----------------- src/TNL/String.h | 15 --------- src/UnitTests/StringTest.cpp | 4 +-- 9 files changed, 108 insertions(+), 65 deletions(-) create mode 100644 src/TNL/Exceptions/FileDeserializationError.h create mode 100644 src/TNL/Exceptions/FileSerializationError.h diff --git a/src/Python/pytnl/tnl/String.cpp b/src/Python/pytnl/tnl/String.cpp index 551f94ddf..f9fff7d92 100644 --- a/src/Python/pytnl/tnl/String.cpp +++ b/src/Python/pytnl/tnl/String.cpp @@ -10,11 +10,6 @@ namespace py = pybind11; void export_String( py::module & m ) { - // function pointers for overloaded methods -// const char* (TNL::String::* _String_getString)() const = &TNL::String::getString; - bool (TNL::String::* _String_save)(TNL::File &) const = &TNL::String::save; - bool (TNL::String::* _String_load)(TNL::File &) = &TNL::String::load; - py::class_(m, "String") .def(py::init()) .def(py::init()) @@ -35,7 +30,7 @@ void export_String( py::module & m ) .def("__len__", &TNL::String::getLength) // FIXME // .def("replace", &TNL::String::replace) - .def("save", _String_save) - .def("load", _String_load) + .def("save", []( const TNL::String& str, TNL::File& file ){ file << str; } ) + .def("load", []( TNL::String& str, TNL::File& file ){ file >> str; } ) ; } diff --git a/src/TNL/Exceptions/FileDeserializationError.h b/src/TNL/Exceptions/FileDeserializationError.h new file mode 100644 index 000000000..d6c02cbf2 --- /dev/null +++ b/src/TNL/Exceptions/FileDeserializationError.h @@ -0,0 +1,31 @@ +/*************************************************************************** + FileDeserializationError.h - description + ------------------- + begin : Nov 17, 2018 + copyright : (C) 2018 by Tomas Oberhuber et al. + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +// Implemented by: Jakub Klinkovsky + +#pragma once + +#include +#include + +namespace TNL { +namespace Exceptions { + +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 + "'." ) + {} +}; + +} // namespace Exceptions +} // namespace TNL diff --git a/src/TNL/Exceptions/FileSerializationError.h b/src/TNL/Exceptions/FileSerializationError.h new file mode 100644 index 000000000..6336efa54 --- /dev/null +++ b/src/TNL/Exceptions/FileSerializationError.h @@ -0,0 +1,31 @@ +/*************************************************************************** + FileSerializationError.h - description + ------------------- + begin : Nov 17, 2018 + copyright : (C) 2018 by Tomas Oberhuber et al. + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +// Implemented by: Jakub Klinkovsky + +#pragma once + +#include +#include + +namespace TNL { +namespace Exceptions { + +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 + "'." ) + {} +}; + +} // namespace Exceptions +} // namespace TNL diff --git a/src/TNL/File.h b/src/TNL/File.h index daead1681..ca4d4a85f 100644 --- a/src/TNL/File.h +++ b/src/TNL/File.h @@ -151,6 +151,12 @@ protected: /// \param fileName Name of the file that user wants to find in the PC. bool fileExists( const String& fileName ); +// serialization of strings +File& operator<<( File& file, const std::string& str ); + +// deserialization of strings +File& operator>>( File& file, std::string& str ); + } // namespace TNL #include diff --git a/src/TNL/File_impl.h b/src/TNL/File_impl.h index 702345ff6..03c3f0d4a 100644 --- a/src/TNL/File_impl.h +++ b/src/TNL/File_impl.h @@ -17,6 +17,8 @@ #include #include #include +#include +#include namespace TNL { @@ -247,4 +249,29 @@ inline bool fileExists( const String& fileName ) return ! file.fail(); } + +// serialization of strings +inline File& operator<<( File& file, const std::string& str ) +{ + const int len = str.size(); + if( ! file.write( &len ) ) + throw Exceptions::FileSerializationError( getType< int >(), file.getFileName() ); + if( ! file.write( str.c_str(), len ) ) + throw Exceptions::FileSerializationError( "String", file.getFileName() ); + return file; +} + +// deserialization of strings +inline File& operator>>( File& file, std::string& str ) +{ + int length; + if( ! file.read( &length ) ) + throw Exceptions::FileDeserializationError( getType< int >(), file.getFileName() ); + char buffer[ length ]; + if( length && ! file.read( buffer, length ) ) + throw Exceptions::FileDeserializationError( "String", file.getFileName() ); + str.assign( buffer, length ); + return file; +} + } // namespace TNL diff --git a/src/TNL/Object_impl.h b/src/TNL/Object_impl.h index fe09ac5f3..70415f8e8 100644 --- a/src/TNL/Object_impl.h +++ b/src/TNL/Object_impl.h @@ -42,9 +42,9 @@ inline String Object :: getSerializationTypeVirtual() const inline bool Object :: save( File& file ) const { - if( ! file. write( magic_number, strlen( magic_number ) ) ) + if( ! file.write( magic_number, strlen( magic_number ) ) ) return false; - if( ! this->getSerializationTypeVirtual().save( file ) ) return false; + file << this->getSerializationTypeVirtual(); return true; } @@ -69,7 +69,7 @@ inline bool Object :: boundLoad( File& file ) inline bool Object :: save( const String& fileName ) const { File file; - if( ! file. open( fileName, IOMode::write ) ) + if( ! file.open( fileName, IOMode::write ) ) { std::cerr << "I am not able to open the file " << fileName << " for writing." << std::endl; return false; @@ -80,7 +80,7 @@ inline bool Object :: save( const String& fileName ) const inline bool Object :: load( const String& fileName ) { File file; - if( ! file. open( fileName, IOMode::read ) ) + if( ! file.open( fileName, IOMode::read ) ) { std::cerr << "I am not able to open the file " << fileName << " for reading." << std::endl; return false; @@ -91,7 +91,7 @@ inline bool Object :: load( const String& fileName ) inline bool Object :: boundLoad( const String& fileName ) { File file; - if( ! file. open( fileName, IOMode::read ) ) + if( ! file.open( fileName, IOMode::read ) ) { std::cerr << "I am not able to open the file " << fileName << " for reading." << std::endl; return false; @@ -103,9 +103,9 @@ inline bool Object :: boundLoad( const String& fileName ) inline bool getObjectType( File& file, String& type ) { char mn[ 10 ]; - if( ! file. read( mn, strlen( magic_number ) ) ) + if( ! file.read( mn, strlen( magic_number ) ) ) { - std::cerr << "Unable to read file " << file. getFileName() << " ... " << std::endl; + std::cerr << "Unable to read file " << file.getFileName() << " ... " << std::endl; return false; } if( strncmp( mn, magic_number, 5 ) != 0 ) @@ -113,18 +113,14 @@ inline bool getObjectType( File& file, String& type ) std::cout << "Not a TNL file (wrong magic number)." << std::endl; return false; } - if( ! type. load( file ) ) - { - std::cerr << "Cannot load the object type." << std::endl; - return false; - } + file >> type; return true; } inline bool getObjectType( const String& fileName, String& type ) { File binaryFile; - if( ! binaryFile. open( fileName, IOMode::read ) ) + if( ! binaryFile.open( fileName, IOMode::read ) ) { std::cerr << "I am not able to open the file " << fileName << " for detecting the object inside!" << std::endl; return false; diff --git a/src/TNL/String.cpp b/src/TNL/String.cpp index ec75f0c35..9bacdaaf0 100644 --- a/src/TNL/String.cpp +++ b/src/TNL/String.cpp @@ -10,7 +10,6 @@ #include #include -#include #include //#ifdef USE_MPI // #include @@ -230,33 +229,6 @@ std::vector< String > String::split( const char separator, bool skipEmpty ) cons return parts; } - -bool String::save( File& file ) const -{ - const int len = getLength(); - if( ! file.write( &len ) ) - return false; - if( ! file.write( this->c_str(), len ) ) - return false; - return true; -} - -bool String::load( File& file ) -{ - int length; - if( ! file.read( &length ) ) { - std::cerr << "I was not able to read String length." << std::endl; - return false; - } - char buffer[ length ]; - if( length && ! file.read( buffer, length ) ) { - std::cerr << "I was not able to read a String with a length " << length << "." << std::endl; - return false; - } - this->assign( buffer, length ); - return true; -} - /*void String :: MPIBcast( int root, MPI_Comm comm ) { #ifdef USE_MPI diff --git a/src/TNL/String.h b/src/TNL/String.h index baeaf6545..9af651d4d 100644 --- a/src/TNL/String.h +++ b/src/TNL/String.h @@ -17,7 +17,6 @@ namespace TNL { -class File; class String; ///// @@ -213,20 +212,6 @@ public: /// @param separator Character, which separates substrings in given string. std::vector< String > split( const char separator = ' ', bool skipEmpty = false ) const; - ///// - /// \brief Function for saving file. - /// - /// Writes the string to a binary file and returns boolean expression based on the - /// success in writing into the file. - bool save( File& file ) const; - - ///// - /// \brief Function for loading from file. - /// - /// Reads a string from binary file and returns boolean expression based on the - /// success in reading the file. - bool load( File& file ); - //! Broadcast to other nodes in MPI cluster // void MPIBcast( int root, MPI_Comm mpi_comm = MPI_COMM_WORLD ); }; diff --git a/src/UnitTests/StringTest.cpp b/src/UnitTests/StringTest.cpp index 53934e950..10c85497b 100644 --- a/src/UnitTests/StringTest.cpp +++ b/src/UnitTests/StringTest.cpp @@ -307,11 +307,11 @@ TEST( StringTest, SaveLoad ) String str1( "testing-string" ); File file; file.open( "test-file.tnl", IOMode::write ); - ASSERT_TRUE( str1.save( file ) ); + ASSERT_NO_THROW( file << str1 ); file.close(); file.open( "test-file.tnl", IOMode::read ); String str2; - ASSERT_TRUE( str2.load( file ) ); + ASSERT_NO_THROW( file >> str2 ); EXPECT_EQ( str1, str2 ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); -- GitLab From 3a66f15cf02a43d1ac51589aba1ac0beb7a1a10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Mon, 24 Dec 2018 14:23:57 +0100 Subject: [PATCH 32/39] Fixed StringExample --- src/Examples/StringExample.cpp | 36 +++++++++++----------------------- src/Examples/StringExample.out | 3 --- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/Examples/StringExample.cpp b/src/Examples/StringExample.cpp index 9ef9a4a9a..a23904a4f 100644 --- a/src/Examples/StringExample.cpp +++ b/src/Examples/StringExample.cpp @@ -5,12 +5,12 @@ using namespace TNL; using namespace std; - + int main( int argc, char* argv[] ) { // constructors String str1; - String str2( "xxstringxxx", 2, 3 ); + String str2( "string" ); String str3( str2 ); // copy constructor String str4 = convertToString( 28.4 ); // converts to string @@ -30,9 +30,7 @@ int main( int argc, char* argv[] ) size = str3.getSize(); cout << "size of string:" << size << "bytes" << endl;*/ - String str; - str.setString( "Something new" ); - String setter = str; + String setter = "Something new"; cout << "setter:" << setter << endl; const char* getter = str4.getString(); @@ -121,33 +119,21 @@ int main( int argc, char* argv[] ) // split String dates("3/4/2005;8/7/2011;11/12/2019"); - Containers::List list; - dates.split( list, ';' ); - cout << "list_dates:" << list << endl; + std::vector list = dates.split(';'); + cout << "list_dates: " << list[0] << ", " << list[1] << ", " << list[2] << endl; String cars("opel,mazda,,skoda,"); - Containers::List list3, list5; - cars.split(list3, ',', true); - cars.split(list5, ','); - cout << "split with true:" << list3 << endl; - cout << "split with false:" << list5 << endl; + std::vector list3 = cars.split(',', true); + cout << "split with true:" << list3[0] << ", " << list3[1] << ", " << list3[2] << endl; + std::vector list5 = cars.split(','); + cout << "split with false:" << list5[0] << ", " << list5[1] << ", " << list5[2] << ", " << list5[3] << endl; // save File myFile; - String("Header").save(myFile); // saves "Header" into myFile + myFile << String("Header"); // saves "Header" into myFile // load String strg; - strg.load(myFile); + myFile >> strg; cout << "strg:" << strg << endl; - - // get line - std::stringstream text; - text << "Hello!" << std::endl; - text << "What's up?" << std::endl; - - String string; - string.getLine( text ); - cout << "str:" << string << endl; - } diff --git a/src/Examples/StringExample.out b/src/Examples/StringExample.out index 61886792a..0b0a958b6 100644 --- a/src/Examples/StringExample.out +++ b/src/Examples/StringExample.out @@ -47,6 +47,3 @@ true // load strg: Header - -// get line -str: Hello! \ No newline at end of file -- GitLab From 4c610bf6d67ccbde601cdfc4233dd4f14a55c4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 21:02:04 +0100 Subject: [PATCH 33/39] Moved stuff from String.cpp to String_impl.h --- src/TNL/String.h | 2 + src/TNL/{String.cpp => String_impl.h} | 79 ++++++++++++++------------- 2 files changed, 44 insertions(+), 37 deletions(-) rename src/TNL/{String.cpp => String_impl.h} (67%) diff --git a/src/TNL/String.h b/src/TNL/String.h index 9af651d4d..9bad1c4eb 100644 --- a/src/TNL/String.h +++ b/src/TNL/String.h @@ -243,3 +243,5 @@ template<> inline String convertToString( const bool& b ) } } // namespace TNL + +#include diff --git a/src/TNL/String.cpp b/src/TNL/String_impl.h similarity index 67% rename from src/TNL/String.cpp rename to src/TNL/String_impl.h index 9bacdaaf0..17ba9359d 100644 --- a/src/TNL/String.cpp +++ b/src/TNL/String_impl.h @@ -1,5 +1,5 @@ /*************************************************************************** - String.cpp - description + String_impl.h - description ------------------- begin : 2004/04/10 16:36 copyright : (C) 2004 by Tomas Oberhuber @@ -8,6 +8,8 @@ /* See Copyright Notice in tnl/Copyright */ +#pragma once + #include #include #include @@ -17,46 +19,46 @@ namespace TNL { -String String::getType() +inline String String::getType() { return String( "String" ); } -int String::getLength() const +inline int String::getLength() const { return getSize(); } -int String::getSize() const +inline int String::getSize() const { return this->size(); } -int String::getAllocatedSize() const +inline int String::getAllocatedSize() const { return this->capacity(); } -void String::setSize( int size ) +inline void String::setSize( int size ) { TNL_ASSERT_GE( size, 0, "string size must be non-negative" ); this->reserve( size ); } -const char* String::getString() const +inline const char* String::getString() const { return this->c_str(); } -const char& String::operator[]( int i ) const +inline const char& String::operator[]( int i ) const { TNL_ASSERT( i >= 0 && i < getLength(), std::cerr << "Accessing char outside the string." ); return std::string::operator[]( i ); } -char& String::operator[]( int i ) +inline char& String::operator[]( int i ) { TNL_ASSERT( i >= 0 && i < getLength(), std::cerr << "Accessing char outside the string." ); @@ -67,23 +69,23 @@ char& String::operator[]( int i ) /**** * Operators for single characters */ -String& String::operator+=( char str ) +inline String& String::operator+=( char str ) { std::string::operator+=( str ); return *this; } -String String::operator+( char str ) const +inline String String::operator+( char str ) const { return String( *this ) += str; } -bool String::operator==( char str ) const +inline bool String::operator==( char str ) const { return std::string( *this ) == std::string( 1, str ); } -bool String::operator!=( char str ) const +inline bool String::operator!=( char str ) const { return ! operator==( str ); } @@ -92,23 +94,23 @@ bool String::operator!=( char str ) const /**** * Operators for C strings */ -String& String::operator+=( const char* str ) +inline String& String::operator+=( const char* str ) { std::string::operator+=( str ); return *this; } -String String::operator+( const char* str ) const +inline String String::operator+( const char* str ) const { return String( *this ) += str; } -bool String::operator==( const char* str ) const +inline bool String::operator==( const char* str ) const { return std::string( *this ) == str; } -bool String::operator!=( const char* str ) const +inline bool String::operator!=( const char* str ) const { return ! operator==( str ); } @@ -117,23 +119,23 @@ bool String::operator!=( const char* str ) const /**** * Operators for std::string */ -String& String::operator+=( const std::string& str ) +inline String& String::operator+=( const std::string& str ) { std::string::operator+=( str ); return *this; } -String String::operator+( const std::string& str ) const +inline String String::operator+( const std::string& str ) const { return String( *this ) += str; } -bool String::operator==( const std::string& str ) const +inline bool String::operator==( const std::string& str ) const { return std::string( *this ) == str; } -bool String::operator!=( const std::string& str ) const +inline bool String::operator!=( const std::string& str ) const { return ! operator==( str ); } @@ -142,41 +144,42 @@ bool String::operator!=( const std::string& str ) const /**** * Operators for String */ -String& String::operator+=( const String& str ) +inline String& String::operator+=( const String& str ) { std::string::operator+=( str ); return *this; } -String String::operator+( const String& str ) const +inline String String::operator+( const String& str ) const { return String( *this ) += str; } -bool String::operator==( const String& str ) const +inline bool String::operator==( const String& str ) const { return std::string( *this ) == str; } -bool String::operator!=( const String& str ) const +inline bool String::operator!=( const String& str ) const { return ! operator==( str ); } -String::operator bool () const +inline String::operator bool () const { return getLength(); } -bool String::operator!() const +inline bool String::operator!() const { return ! operator bool(); } -String String::replace( const String& pattern, - const String& replaceWith, - int count ) const +inline String +String::replace( const String& pattern, + const String& replaceWith, + int count ) const { std::string newString = *this; @@ -195,7 +198,7 @@ String String::replace( const String& pattern, return newString; } -String +inline String String::strip( char strip ) const { int prefix_cut_off = 0; @@ -212,7 +215,8 @@ String::strip( char strip ) const return ""; } -std::vector< String > String::split( const char separator, bool skipEmpty ) const +inline std::vector< String > +String::split( const char separator, bool skipEmpty ) const { std::vector< String > parts; String s; @@ -229,7 +233,8 @@ std::vector< String > String::split( const char separator, bool skipEmpty ) cons return parts; } -/*void String :: MPIBcast( int root, MPI_Comm comm ) +/* +inline void String :: MPIBcast( int root, MPI_Comm comm ) { #ifdef USE_MPI dbgFunctionName( "mString", "MPIBcast" ); @@ -257,22 +262,22 @@ std::vector< String > String::split( const char separator, bool skipEmpty ) cons } */ -String operator+( char string1, const String& string2 ) +inline String operator+( char string1, const String& string2 ) { return convertToString( string1 ) + string2; } -String operator+( const char* string1, const String& string2 ) +inline String operator+( const char* string1, const String& string2 ) { return String( string1 ) + string2; } -String operator+( const std::string& string1, const String& string2 ) +inline String operator+( const std::string& string1, const String& string2 ) { return String( string1 ) + string2; } -std::ostream& operator<<( std::ostream& stream, const String& str ) +inline std::ostream& operator<<( std::ostream& stream, const String& str ) { stream << str.getString(); return stream; -- GitLab From 4543022d5b47aaf5fe3fb4b931d76369f541a17c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 17 Nov 2018 21:07:18 +0100 Subject: [PATCH 34/39] CMakeLists.txt: removed libtnl.so (TNL is now header-only!) --- src/Benchmarks/BLAS/CMakeLists.txt | 2 - src/Benchmarks/DistSpMV/CMakeLists.txt | 2 - src/Benchmarks/HeatEquation/CMakeLists.txt | 10 +-- src/Benchmarks/LinearSolvers/CMakeLists.txt | 3 +- src/Benchmarks/SpMV/CMakeLists.txt | 3 +- src/Examples/CMakeLists.txt | 21 ----- src/Examples/flow-sw/CMakeLists.txt | 3 +- src/Examples/flow-vl/CMakeLists.txt | 2 - src/Examples/flow/CMakeLists.txt | 2 - src/Examples/heat-equation/CMakeLists.txt | 6 +- src/Examples/inviscid-flow-sw/CMakeLists.txt | 2 - src/Examples/inviscid-flow-vl/CMakeLists.txt | 2 - src/Examples/inviscid-flow/CMakeLists.txt | 3 +- src/Examples/simple-examples/CMakeLists.txt | 16 +--- .../transport-equation/CMakeLists.txt | 6 +- src/Python/pytnl/tnl/CMakeLists.txt | 3 - src/TNL/CMakeLists.txt | 86 +------------------ .../Arithmetics/UnitTests/CMakeLists.txt | 11 +-- .../Solvers/hamilton-jacobi/CMakeLists.txt | 3 - src/Tools/CMakeLists.txt | 19 +--- src/UnitTests/CMakeLists.txt | 26 ++---- src/UnitTests/Containers/CMakeLists.txt | 76 ++++------------ .../Containers/Multimaps/CMakeLists.txt | 8 +- src/UnitTests/Functions/CMakeLists.txt | 10 +-- src/UnitTests/Matrices/CMakeLists.txt | 26 ++---- src/UnitTests/Meshes/CMakeLists.txt | 30 ++----- .../Meshes/DistributedMeshes/CMakeLists.txt | 54 +++--------- src/UnitTests/Pointers/CMakeLists.txt | 12 +-- tests/long-time-unit-tests/CMakeLists.txt | 4 +- tests/mpi/CMakeLists.txt | 16 ++-- 30 files changed, 97 insertions(+), 370 deletions(-) diff --git a/src/Benchmarks/BLAS/CMakeLists.txt b/src/Benchmarks/BLAS/CMakeLists.txt index dc396c46e..a6c99a994 100644 --- a/src/Benchmarks/BLAS/CMakeLists.txt +++ b/src/Benchmarks/BLAS/CMakeLists.txt @@ -1,10 +1,8 @@ if( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( tnl-benchmark-blas tnl-benchmark-blas.cu ) CUDA_ADD_CUBLAS_TO_TARGET( tnl-benchmark-blas ) - TARGET_LINK_LIBRARIES( tnl-benchmark-blas tnl ) else() ADD_EXECUTABLE( tnl-benchmark-blas tnl-benchmark-blas.cpp ) - TARGET_LINK_LIBRARIES( tnl-benchmark-blas tnl ) endif() install( TARGETS tnl-benchmark-blas RUNTIME DESTINATION bin ) diff --git a/src/Benchmarks/DistSpMV/CMakeLists.txt b/src/Benchmarks/DistSpMV/CMakeLists.txt index 57ccdd7a9..78fc992ad 100644 --- a/src/Benchmarks/DistSpMV/CMakeLists.txt +++ b/src/Benchmarks/DistSpMV/CMakeLists.txt @@ -1,11 +1,9 @@ if( BUILD_CUDA ) cuda_add_executable( tnl-benchmark-distributed-spmv-cuda tnl-benchmark-distributed-spmv.cu ) - target_link_libraries( tnl-benchmark-distributed-spmv-cuda tnl ) install( TARGETS tnl-benchmark-distributed-spmv-cuda RUNTIME DESTINATION bin ) endif() add_executable( tnl-benchmark-distributed-spmv tnl-benchmark-distributed-spmv.cpp ) -target_link_libraries( tnl-benchmark-distributed-spmv tnl ) install( TARGETS tnl-benchmark-distributed-spmv RUNTIME DESTINATION bin ) diff --git a/src/Benchmarks/HeatEquation/CMakeLists.txt b/src/Benchmarks/HeatEquation/CMakeLists.txt index 867ab2c1e..d7bccc7ce 100644 --- a/src/Benchmarks/HeatEquation/CMakeLists.txt +++ b/src/Benchmarks/HeatEquation/CMakeLists.txt @@ -1,19 +1,13 @@ IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( tnl-benchmark-simple-heat-equation tnl-benchmark-simple-heat-equation.cu ) - TARGET_LINK_LIBRARIES( tnl-benchmark-simple-heat-equation tnl ) CUDA_ADD_EXECUTABLE( tnl-benchmark-simple-heat-equation-bug tnl-benchmark-simple-heat-equation-bug.cu ) - TARGET_LINK_LIBRARIES( tnl-benchmark-simple-heat-equation-bug tnl ) - CUDA_ADD_EXECUTABLE( tnl-benchmark-heat-equation tnl-benchmark-heat-equation.cu ) - TARGET_LINK_LIBRARIES( tnl-benchmark-heat-equation tnl ) ELSE() - ADD_EXECUTABLE( tnl-benchmark-heat-equation tnl-benchmark-heat-equation.cpp ) - TARGET_LINK_LIBRARIES( tnl-benchmark-heat-equation tnl ) + ADD_EXECUTABLE( tnl-benchmark-heat-equation tnl-benchmark-heat-equation.cpp ) - ADD_EXECUTABLE( tnl-benchmark-simple-heat-equation tnl-benchmark-simple-heat-equation.cpp ) - TARGET_LINK_LIBRARIES( tnl-benchmark-simple-heat-equation tnl ) + ADD_EXECUTABLE( tnl-benchmark-simple-heat-equation tnl-benchmark-simple-heat-equation.cpp ) ENDIF() diff --git a/src/Benchmarks/LinearSolvers/CMakeLists.txt b/src/Benchmarks/LinearSolvers/CMakeLists.txt index af0187928..29456bde5 100644 --- a/src/Benchmarks/LinearSolvers/CMakeLists.txt +++ b/src/Benchmarks/LinearSolvers/CMakeLists.txt @@ -1,12 +1,11 @@ if( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( tnl-benchmark-linear-solvers-cuda tnl-benchmark-linear-solvers.cu OPTIONS -DHAVE_CUSPARSE ) - TARGET_LINK_LIBRARIES( tnl-benchmark-linear-solvers-cuda tnl ${CUDA_cusparse_LIBRARY} ) + TARGET_LINK_LIBRARIES( tnl-benchmark-linear-solvers-cuda ${CUDA_cusparse_LIBRARY} ) install( TARGETS tnl-benchmark-linear-solvers-cuda RUNTIME DESTINATION bin ) endif() ADD_EXECUTABLE( tnl-benchmark-linear-solvers tnl-benchmark-linear-solvers.cpp ) -TARGET_LINK_LIBRARIES( tnl-benchmark-linear-solvers tnl ) install( TARGETS tnl-benchmark-linear-solvers RUNTIME DESTINATION bin ) diff --git a/src/Benchmarks/SpMV/CMakeLists.txt b/src/Benchmarks/SpMV/CMakeLists.txt index a73e6738c..7cb9c4fcd 100644 --- a/src/Benchmarks/SpMV/CMakeLists.txt +++ b/src/Benchmarks/SpMV/CMakeLists.txt @@ -1,9 +1,8 @@ if( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( tnl-benchmark-spmv tnl-benchmark-spmv.cu ) - TARGET_LINK_LIBRARIES( tnl-benchmark-spmv tnl ${CUDA_cusparse_LIBRARY} ) + TARGET_LINK_LIBRARIES( tnl-benchmark-spmv ${CUDA_cusparse_LIBRARY} ) else() ADD_EXECUTABLE( tnl-benchmark-spmv tnl-benchmark-spmv.cpp ) - TARGET_LINK_LIBRARIES( tnl-benchmark-spmv tnl ) endif() install( TARGETS tnl-benchmark-spmv RUNTIME DESTINATION bin ) diff --git a/src/Examples/CMakeLists.txt b/src/Examples/CMakeLists.txt index f827d6695..1c52839e9 100644 --- a/src/Examples/CMakeLists.txt +++ b/src/Examples/CMakeLists.txt @@ -19,40 +19,19 @@ add_subdirectory( flow-vl ) #add_subdirectory( narrow-band ) ADD_EXECUTABLE( ArrayExample ArrayExample.cpp ) -target_link_libraries( ArrayExample tnl ) ADD_EXECUTABLE( ConfigDescriptionExample ConfigDescriptionExample.cpp ) -target_link_libraries( ConfigDescriptionExample tnl ) - ADD_EXECUTABLE( FileExample FileExample.cpp ) -target_link_libraries( FileExample tnl ) - ADD_EXECUTABLE( ListExample ListExample.cpp ) -target_link_libraries( ListExample tnl ) - ADD_EXECUTABLE( LoggerExample LoggerExample.cpp ) -target_link_libraries( LoggerExample tnl ) - ADD_EXECUTABLE( MathExample MathExample.cpp ) -target_link_libraries( MathExample tnl ) ADD_EXECUTABLE( ParameterContainerExample ParameterContainerExample.cpp ) -target_link_libraries( ParameterContainerExample tnl ) ADD_EXECUTABLE( StringExample StringExample.cpp ) -target_link_libraries( StringExample tnl ) - ADD_EXECUTABLE( StringExampleGetAllocatedSize StringExampleGetAllocatedSize.cpp ) -target_link_libraries( StringExampleGetAllocatedSize tnl ) - ADD_EXECUTABLE( StringExampleGetSize StringExampleGetSize.cpp ) -target_link_libraries( StringExampleGetSize tnl ) - ADD_EXECUTABLE( StringExampleSetSize StringExampleSetSize.cpp ) -target_link_libraries( StringExampleSetSize tnl ) - ADD_EXECUTABLE( TimerExample TimerExample.cpp ) -target_link_libraries( TimerExample tnl ) ADD_EXECUTABLE( VectorExample VectorExample.cpp ) -target_link_libraries( VectorExample tnl ) \ No newline at end of file diff --git a/src/Examples/flow-sw/CMakeLists.txt b/src/Examples/flow-sw/CMakeLists.txt index 685514053..cd53d411c 100644 --- a/src/Examples/flow-sw/CMakeLists.txt +++ b/src/Examples/flow-sw/CMakeLists.txt @@ -7,10 +7,9 @@ set( tnl_flow_sw_SOURCES IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE(tnl-navier-stokes-sw navierStokes.cu) - target_link_libraries (tnl-navier-stokes-sw tnl ${CUSPARSE_LIBRARY} ) + target_link_libraries (tnl-navier-stokes-sw ${CUSPARSE_LIBRARY} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE(tnl-navier-stokes-sw navierStokes.cpp) - target_link_libraries (tnl-navier-stokes-sw tnl ) ENDIF( BUILD_CUDA ) diff --git a/src/Examples/flow-vl/CMakeLists.txt b/src/Examples/flow-vl/CMakeLists.txt index 6162093ea..47bb72276 100644 --- a/src/Examples/flow-vl/CMakeLists.txt +++ b/src/Examples/flow-vl/CMakeLists.txt @@ -7,10 +7,8 @@ set( tnl_flow_vl_SOURCES IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE(tnl-navier-stokes-vl navierStokes.cu) - target_link_libraries (tnl-navier-stokes-vl tnl ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE(tnl-navier-stokes-vl navierStokes.cpp) - target_link_libraries (tnl-navier-stokes-vl tnl ) ENDIF( BUILD_CUDA ) diff --git a/src/Examples/flow/CMakeLists.txt b/src/Examples/flow/CMakeLists.txt index f6ec4bda1..6b156036b 100644 --- a/src/Examples/flow/CMakeLists.txt +++ b/src/Examples/flow/CMakeLists.txt @@ -7,10 +7,8 @@ set( tnl_flow_SOURCES IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cu) - target_link_libraries (tnl-navier-stokes tnl ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cpp) - target_link_libraries (tnl-navier-stokes tnl ) ENDIF( BUILD_CUDA ) diff --git a/src/Examples/heat-equation/CMakeLists.txt b/src/Examples/heat-equation/CMakeLists.txt index d58ffd58d..c89519906 100644 --- a/src/Examples/heat-equation/CMakeLists.txt +++ b/src/Examples/heat-equation/CMakeLists.txt @@ -7,13 +7,11 @@ set( tnl_heat_equation_SOURCES IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE(tnl-heat-equation tnl-heat-equation.cu) CUDA_ADD_EXECUTABLE(tnl-heat-equation-eoc-test tnl-heat-equation-eoc.cu) - target_link_libraries (tnl-heat-equation tnl ${CUSPARSE_LIBRARY} ) - target_link_libraries (tnl-heat-equation-eoc-test tnl ${CUSPARSE_LIBRARY} ) + target_link_libraries (tnl-heat-equation ${CUSPARSE_LIBRARY} ) + target_link_libraries (tnl-heat-equation-eoc-test ${CUSPARSE_LIBRARY} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE(tnl-heat-equation tnl-heat-equation.cpp) ADD_EXECUTABLE(tnl-heat-equation-eoc-test tnl-heat-equation-eoc.cpp) - target_link_libraries (tnl-heat-equation tnl) - target_link_libraries (tnl-heat-equation-eoc-test tnl ) TARGET_COMPILE_DEFINITIONS( tnl-heat-equation PUBLIC ${MIC_CXX_FLAGS} ) ENDIF( BUILD_CUDA ) diff --git a/src/Examples/inviscid-flow-sw/CMakeLists.txt b/src/Examples/inviscid-flow-sw/CMakeLists.txt index cf5e0cb58..427def126 100644 --- a/src/Examples/inviscid-flow-sw/CMakeLists.txt +++ b/src/Examples/inviscid-flow-sw/CMakeLists.txt @@ -7,10 +7,8 @@ set( tnl_inviscid_flow_sw_SOURCES IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE(tnl-euler-sw euler.cu) - target_link_libraries (tnl-euler-sw tnl ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE(tnl-euler-sw${debugExt} euler.cpp) - target_link_libraries (tnl-euler-sw tnl ) ENDIF( BUILD_CUDA ) diff --git a/src/Examples/inviscid-flow-vl/CMakeLists.txt b/src/Examples/inviscid-flow-vl/CMakeLists.txt index 77afc9d3e..d0111a5a1 100644 --- a/src/Examples/inviscid-flow-vl/CMakeLists.txt +++ b/src/Examples/inviscid-flow-vl/CMakeLists.txt @@ -7,10 +7,8 @@ set( tnl_inviscid_flow_vl_SOURCES IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE(tnl-euler-vl euler.cu) - target_link_libraries (tnl-euler-vl tnl ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE(tnl-euler-vl euler.cpp) - target_link_libraries (tnl-euler-vl tnl ) ENDIF( BUILD_CUDA ) diff --git a/src/Examples/inviscid-flow/CMakeLists.txt b/src/Examples/inviscid-flow/CMakeLists.txt index a77942815..dbfe2024d 100644 --- a/src/Examples/inviscid-flow/CMakeLists.txt +++ b/src/Examples/inviscid-flow/CMakeLists.txt @@ -7,10 +7,9 @@ set( tnl_inviscid_flow_SOURCES IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE(tnl-euler euler.cu) - target_link_libraries (tnl-euler tnl ${CUSPARSE_LIBRARY} ) + target_link_libraries (tnl-euler ${CUSPARSE_LIBRARY} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE(tnl-euler euler.cpp) - target_link_libraries (tnl-euler tnl ) ENDIF( BUILD_CUDA ) diff --git a/src/Examples/simple-examples/CMakeLists.txt b/src/Examples/simple-examples/CMakeLists.txt index 5e8829e23..21fed2b18 100644 --- a/src/Examples/simple-examples/CMakeLists.txt +++ b/src/Examples/simple-examples/CMakeLists.txt @@ -1,17 +1,9 @@ - IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( large-meshfunction-example large-meshfunction-example.cu ) TARGET_COMPILE_OPTIONS( large-meshfunction-example PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( large-meshfunction-example - ${GTEST_BOTH_LIBRARIES} - tnl ) - -ELSE( BUILD_CUDA ) + TARGET_LINK_LIBRARIES( large-meshfunction-example ${GTEST_BOTH_LIBRARIES} ) +ELSE( BUILD_CUDA ) ADD_EXECUTABLE( large-meshfunction-example large-meshfunction-example.cpp ) TARGET_COMPILE_OPTIONS( large-meshfunction-example PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( large-meshfunction-example - ${GTEST_BOTH_LIBRARIES} - tnl ) - - -ENDIF( BUILD_CUDA ) + TARGET_LINK_LIBRARIES( large-meshfunction-example ${GTEST_BOTH_LIBRARIES} ) +ENDIF( BUILD_CUDA ) diff --git a/src/Examples/transport-equation/CMakeLists.txt b/src/Examples/transport-equation/CMakeLists.txt index 4af252899..2f29a66cd 100644 --- a/src/Examples/transport-equation/CMakeLists.txt +++ b/src/Examples/transport-equation/CMakeLists.txt @@ -11,15 +11,13 @@ set( tnl_transport_equation_HEADERS IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( tnl-transport-equation tnl-transport-equation.cu) - target_link_libraries( tnl-transport-equation tnl ${CUSPARSE_LIBRARY} ) + target_link_libraries( tnl-transport-equation ${CUSPARSE_LIBRARY} ) CUDA_ADD_EXECUTABLE( tnl-transport-equation-eoc tnl-transport-equation-eoc.cu) - target_link_libraries( tnl-transport-equation-eoc tnl ${CUSPARSE_LIBRARY} ) + target_link_libraries( tnl-transport-equation-eoc ${CUSPARSE_LIBRARY} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE( tnl-transport-equation tnl-transport-equation.cpp) - target_link_libraries( tnl-transport-equation tnl ) ADD_EXECUTABLE( tnl-transport-equation-eoc tnl-transport-equation-eoc.cpp) - target_link_libraries( tnl-transport-equation-eoc tnl ) ENDIF( BUILD_CUDA ) diff --git a/src/Python/pytnl/tnl/CMakeLists.txt b/src/Python/pytnl/tnl/CMakeLists.txt index 254c73c57..b6c4182b8 100644 --- a/src/Python/pytnl/tnl/CMakeLists.txt +++ b/src/Python/pytnl/tnl/CMakeLists.txt @@ -13,9 +13,6 @@ set( sources ) pybind11_add_module( pytnl ${sources} ) -# link against tnl.so -target_link_libraries( pytnl PRIVATE tnl ) - # rename the shared library to tnl.cpython-XXm-x86_64-linux-gnu.so set_target_properties( pytnl PROPERTIES LIBRARY_OUTPUT_NAME tnl ) diff --git a/src/TNL/CMakeLists.txt b/src/TNL/CMakeLists.txt index eb3d871f5..a5162c7a6 100644 --- a/src/TNL/CMakeLists.txt +++ b/src/TNL/CMakeLists.txt @@ -14,8 +14,6 @@ ADD_SUBDIRECTORY( Pointers ) ADD_SUBDIRECTORY( Problems ) ADD_SUBDIRECTORY( Solvers ) -SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL ) - set( headers Atomic.h Assert.h @@ -34,91 +32,9 @@ set( headers param-types.h StaticFor.h String.h + String_impl.h Timer.h Timer_impl.h StaticVectorFor.h ) -set( common_SOURCES - String.cpp ) - -set( tnl_SOURCES ${tnl_config_SOURCES} - ${tnl_containers_SOURCES} - ${tnl_devices_SOURCES} - ${tnl_experimental_SOURCES} - ${tnl_functions_SOURCES} - ${tnl_images_SOURCES} - ${tnl_matrices_SOURCES} - ${tnl_operators_SOURCES} - ${tnl_problems_SOURCES} - ${tnl_pointers_SOURCES} - ${tnl_solvers_SOURCES} - - ${common_SOURCES} ) - -set( tnl_CUDA__SOURCES ${tnl_config_CUDA__SOURCES} - ${tnl_containers_CUDA__SOURCES} - ${tnl_devices_CUDA__SOURCES} - ${tnl_experimental_CUDA__SOURCES} - ${tnl_functions_CUDA__SOURCES} - ${tnl_images_CUDA__SOURCES} - ${tnl_matrices_CUDA__SOURCES} - ${tnl_operators_CUDA__SOURCES} - ${tnl_pointers_CUDA__SOURCES} - ${tnl_problems_CUDA__SOURCES} - ${tnl_solvers_CUDA__SOURCES} - - ${common_SOURCES} ) - - -ADD_LIBRARY( tnl_static STATIC ${tnl_SOURCES} ) -INSTALL( TARGETS tnl_static DESTINATION lib ) - -if( BUILD_CUDA ) - CUDA_ADD_LIBRARY( tnl SHARED ${tnl_CUDA__SOURCES} - OPTIONS ${CUDA_ADD_LIBRARY_OPTIONS} ) - # the static library with CUDA support has to be built separately - CUDA_ADD_LIBRARY( tnl-cuda_static STATIC ${tnl_CUDA__SOURCES} ) - INSTALL( TARGETS tnl-cuda_static DESTINATION lib ) -else( BUILD_CUDA ) - ADD_LIBRARY( tnl SHARED ${tnl_SOURCES} ) -#ifMIC - #TARGET_COMPILE_DEFINITIONS( tnl PUBLIC -DHAVE_MIC ) -endif( BUILD_CUDA ) - -SET_TARGET_PROPERTIES( tnl PROPERTIES - VERSION ${tnlVersion} ) -TARGET_LINK_LIBRARIES( tnl - ${DCMTK_LIBRARIES} ) - - -INSTALL( TARGETS tnl DESTINATION lib ) - -# NOTE: this is not necessary until something in the library file actually depends on MPI -#IF( BUILD_MPI ) -# -# ADD_LIBRARY( tnl-mpi_static STATIC ${tnl_SOURCES} ) -# INSTALL( TARGETS tnl-mpi_static DESTINATION lib ) -# -# if( BUILD_CUDA ) -# CUDA_ADD_LIBRARY( tnl-mpi SHARED ${tnl_CUDA__SOURCES} -# OPTIONS ${CUDA_ADD_LIBRARY_OPTIONS} ) -# # the static library with CUDA support has to be built separately -# CUDA_ADD_LIBRARY( tnl-mpi-cuda_static STATIC ${tnl_CUDA__SOURCES} ) -# INSTALL( TARGETS tnl-mpi-cuda_static DESTINATION lib ) -# else( BUILD_CUDA ) -# ADD_LIBRARY( tnl-mpi SHARED ${tnl_SOURCES} ) -# endif( BUILD_CUDA ) -# -# SET_TARGET_PROPERTIES( tnl-mpi PROPERTIES -# VERSION ${tnlVersion} ) -## SET_TARGET_PROPERTIES( tnl-mpi -## LINK_INTERFACE_LIBRARIES "") -# -# -# TARGET_LINK_LIBRARIES( tnl-mpi -# ${MPI_LIBRARIES} ) -# INSTALL( TARGETS tnl-mpi DESTINATION lib ) -# -#endif() - INSTALL( FILES ${headers} DESTINATION ${TNL_TARGET_INCLUDE_DIRECTORY} ) diff --git a/src/TNL/Experimental/Arithmetics/UnitTests/CMakeLists.txt b/src/TNL/Experimental/Arithmetics/UnitTests/CMakeLists.txt index c133e1d0b..d02caaae8 100644 --- a/src/TNL/Experimental/Arithmetics/UnitTests/CMakeLists.txt +++ b/src/TNL/Experimental/Arithmetics/UnitTests/CMakeLists.txt @@ -5,8 +5,7 @@ if( HAVE_GMP ) TARGET_COMPILE_OPTIONS( MultiPrecisionTest PRIVATE ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( MultiPrecisionTest ${GTEST_BOTH_LIBRARIES} - ${GMP_LIBRARIES} - tnl ) + ${GMP_LIBRARIES} ) ADD_TEST( MultiPrecisionTest ${EXECUTABLE_OUTPUT_PATH}/MultiPrecisionTest${CMAKE_EXECUTABLE_SUFFIX} ) endif( HAVE_GMP ) @@ -14,15 +13,11 @@ endif( HAVE_GMP ) # TODO: Fix the following tests #ADD_EXECUTABLE( QuadTest QuadTest.cpp ) #TARGET_COMPILE_OPTIONS( QuadTest PRIVATE ${CXX_TESTS_FLAGS} ) -#TARGET_LINK_LIBRARIES( QuadTest -# ${GTEST_BOTH_LIBRARIES} -# tnl ) +#TARGET_LINK_LIBRARIES( QuadTest ${GTEST_BOTH_LIBRARIES} ) #ADD_EXECUTABLE( DoubleTest DoubleTest.cpp ) #TARGET_COMPILE_OPTIONS( DoubleTest PRIVATE ${CXX_TESTS_FLAGS} ) -#TARGET_LINK_LIBRARIES( DoubleTest -# ${GTEST_BOTH_LIBRARIES} -# tnl ) +#TARGET_LINK_LIBRARIES( DoubleTest ${GTEST_BOTH_LIBRARIES} ) #ADD_TEST( QuadTest ${EXECUTABLE_OUTPUT_PATH}/QuadTest${CMAKE_EXECUTABLE_SUFFIX} ) diff --git a/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/CMakeLists.txt b/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/CMakeLists.txt index edb30a70c..480a5ccb8 100644 --- a/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/CMakeLists.txt +++ b/src/TNL/Experimental/Hamilton-Jacobi/Solvers/hamilton-jacobi/CMakeLists.txt @@ -8,14 +8,11 @@ set( tnl_hamilton_jacobi_SOURCES tnl-direct-eikonal-solver.h ) #ADD_EXECUTABLE(tnl-hamilton-jacobi main.cpp) -#target_link_libraries (tnl-hamilton-jacobi tnl ) IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE(tnl-direct-eikonal-solver tnl-direct-eikonal-solver.cu ) - target_link_libraries (tnl-direct-eikonal-solver tnl ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE(tnl-direct-eikonal-solver tnl-direct-eikonal-solver.cpp ) - target_link_libraries (tnl-direct-eikonal-solver tnl ) ENDIF( BUILD_CUDA ) diff --git a/src/Tools/CMakeLists.txt b/src/Tools/CMakeLists.txt index 3dc914c9d..faaace89f 100644 --- a/src/Tools/CMakeLists.txt +++ b/src/Tools/CMakeLists.txt @@ -5,31 +5,18 @@ CONFIGURE_FILE( "tnl-link.in" "${PROJECT_TOOLS_PATH}/tnl-link" @ONLY ) CONFIGURE_FILE( "tnl-bindir.in" "${PROJECT_TOOLS_PATH}/tnl-bindir" @ONLY ) ADD_EXECUTABLE(tnl-grid-setup tnl-grid-setup.cpp ) -target_link_libraries (tnl-grid-setup tnl ) - ADD_EXECUTABLE(tnl-grid-to-mesh tnl-grid-to-mesh.cpp ) -target_link_libraries (tnl-grid-to-mesh tnl ) - ADD_EXECUTABLE(tnl-mesh-converter tnl-mesh-converter.cpp ) -target_link_libraries (tnl-mesh-converter tnl ) - ADD_EXECUTABLE(tnl-init tnl-init.cpp ) -target_link_libraries (tnl-init tnl ) - ADD_EXECUTABLE(tnl-view tnl-view.cpp ) -target_link_libraries (tnl-view tnl ) - ADD_EXECUTABLE(tnl-diff tnl-diff.cpp ) -target_link_libraries (tnl-diff tnl ) +ADD_EXECUTABLE(tnl-lattice-init tnl-lattice-init.cpp ) ADD_EXECUTABLE(tnl-image-converter tnl-image-converter.cpp ) -target_link_libraries (tnl-image-converter tnl ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ) +target_link_libraries(tnl-image-converter ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ) ADD_EXECUTABLE(tnl-dicom-reader tnl-dicom-reader.cpp ) -target_link_libraries (tnl-dicom-reader tnl ${DCMTK_LIBRARIES} ) - -ADD_EXECUTABLE(tnl-lattice-init tnl-lattice-init.cpp ) -target_link_libraries (tnl-lattice-init tnl ) +target_link_libraries(tnl-dicom-reader ${DCMTK_LIBRARIES} ) IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( tnl-cuda-arch tnl-cuda-arch.cu ) diff --git a/src/UnitTests/CMakeLists.txt b/src/UnitTests/CMakeLists.txt index 7c3958736..95cca1efb 100644 --- a/src/UnitTests/CMakeLists.txt +++ b/src/UnitTests/CMakeLists.txt @@ -6,47 +6,37 @@ ADD_SUBDIRECTORY( Pointers ) ADD_EXECUTABLE( AssertTest AssertTest.cpp ) TARGET_COMPILE_OPTIONS( AssertTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( AssertTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +TARGET_LINK_LIBRARIES( AssertTest ${GTEST_BOTH_LIBRARIES} ) if( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( AssertCudaTest AssertCudaTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( AssertCudaTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( AssertCudaTest ${GTEST_BOTH_LIBRARIES} ) endif() if( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( FileTest FileTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( FileTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( FileTest ${GTEST_BOTH_LIBRARIES} ) else() ADD_EXECUTABLE( FileTest FileTest.cpp ) TARGET_COMPILE_OPTIONS( FileTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( FileTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( FileTest ${GTEST_BOTH_LIBRARIES} ) endif() ADD_EXECUTABLE( FileNameTest FileNameTest.cpp ) TARGET_COMPILE_OPTIONS( FileNameTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( FileNameTest ${GTEST_BOTH_LIBRARIES} tnl ) +TARGET_LINK_LIBRARIES( FileNameTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( StringTest StringTest.cpp ) TARGET_COMPILE_OPTIONS( StringTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( StringTest ${GTEST_BOTH_LIBRARIES} tnl ) +TARGET_LINK_LIBRARIES( StringTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( ObjectTest ObjectTest.cpp ) TARGET_COMPILE_OPTIONS( ObjectTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( ObjectTest ${GTEST_BOTH_LIBRARIES} tnl ) +TARGET_LINK_LIBRARIES( ObjectTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( SaveAndLoadMeshfunctionTest SaveAndLoadMeshfunctionTest.cpp ) TARGET_COMPILE_OPTIONS( SaveAndLoadMeshfunctionTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( SaveAndLoadMeshfunctionTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +TARGET_LINK_LIBRARIES( SaveAndLoadMeshfunctionTest ${GTEST_BOTH_LIBRARIES} ) ADD_TEST( AssertTest ${EXECUTABLE_OUTPUT_PATH}/AssertTest${CMAKE_EXECUTABLE_SUFFIX} ) if( BUILD_CUDA ) diff --git a/src/UnitTests/Containers/CMakeLists.txt b/src/UnitTests/Containers/CMakeLists.txt index 7e7c39717..f9556a479 100644 --- a/src/UnitTests/Containers/CMakeLists.txt +++ b/src/UnitTests/Containers/CMakeLists.txt @@ -1,103 +1,73 @@ ADD_EXECUTABLE( ListTest ListTest.cpp ) TARGET_COMPILE_OPTIONS( ListTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( ListTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +TARGET_LINK_LIBRARIES( ListTest ${GTEST_BOTH_LIBRARIES} ) IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( ArrayOperationsTest ArrayOperationsTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayOperationsTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( ArrayOperationsTest ${GTEST_BOTH_LIBRARIES} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE( ArrayOperationsTest ArrayOperationsTest.cpp ) TARGET_COMPILE_OPTIONS( ArrayOperationsTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayOperationsTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( ArrayOperationsTest ${GTEST_BOTH_LIBRARIES} ) ENDIF( BUILD_CUDA ) IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( ArrayTest ArrayTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( ArrayTest ${GTEST_BOTH_LIBRARIES} ) CUDA_ADD_EXECUTABLE( ArrayViewTest ArrayViewTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayViewTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( ArrayViewTest ${GTEST_BOTH_LIBRARIES} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE( ArrayTest ArrayTest.cpp ) TARGET_COMPILE_OPTIONS( ArrayTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( ArrayTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( ArrayViewTest ArrayViewTest.cpp ) TARGET_COMPILE_OPTIONS( ArrayViewTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayViewTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( ArrayViewTest ${GTEST_BOTH_LIBRARIES} ) ENDIF( BUILD_CUDA ) ADD_EXECUTABLE( StaticArrayTest StaticArrayTest.cpp ) TARGET_COMPILE_OPTIONS( StaticArrayTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( StaticArrayTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +TARGET_LINK_LIBRARIES( StaticArrayTest ${GTEST_BOTH_LIBRARIES} ) # NOTE: Vector = Array + VectorOperations, VectorView = ArrayView + VectorOperations, # so we test Vector, VectorView and VectorOperations at the same time IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( VectorTest VectorTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( VectorTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( VectorTest ${GTEST_BOTH_LIBRARIES} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE( VectorTest VectorTest.cpp ) TARGET_COMPILE_OPTIONS( VectorTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( VectorTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( VectorTest ${GTEST_BOTH_LIBRARIES} ) ENDIF( BUILD_CUDA ) IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( MultireductionTest MultireductionTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( MultireductionTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( MultireductionTest ${GTEST_BOTH_LIBRARIES} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE( MultireductionTest MultireductionTest.cpp ) TARGET_COMPILE_OPTIONS( MultireductionTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( MultireductionTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( MultireductionTest ${GTEST_BOTH_LIBRARIES} ) ENDIF( BUILD_CUDA ) ADD_EXECUTABLE( StaticVectorTest StaticVectorTest.cpp ) TARGET_COMPILE_OPTIONS( StaticVectorTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( StaticVectorTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +TARGET_LINK_LIBRARIES( StaticVectorTest ${GTEST_BOTH_LIBRARIES} ) #IF( BUILD_CUDA ) # CUDA_ADD_EXECUTABLE( MultiArrayTest MultiArrayTest.cu # OPTIONS ${CXX_TESTS_FLAGS} ) -# TARGET_LINK_LIBRARIES( MultiArrayTest -# ${GTEST_BOTH_LIBRARIES} -# tnl ) +# TARGET_LINK_LIBRARIES( MultiArrayTest ${GTEST_BOTH_LIBRARIES} ) #ELSE( BUILD_CUDA ) # ADD_EXECUTABLE( MultiArrayTest MultiArrayTest.cpp ) # TARGET_COMPILE_OPTIONS( MultiArrayTest PRIVATE ${CXX_TESTS_FLAGS} ) -# TARGET_LINK_LIBRARIES( MultiArrayTest -# ${GTEST_BOTH_LIBRARIES} -# tnl ) +# TARGET_LINK_LIBRARIES( MultiArrayTest ${GTEST_BOTH_LIBRARIES} ) #ENDIF( BUILD_CUDA ) @@ -119,27 +89,19 @@ if( ${BUILD_MPI} ) if( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( DistributedArrayTest DistributedArrayTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedArrayTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedArrayTest ${GTEST_BOTH_LIBRARIES} ) CUDA_ADD_EXECUTABLE( DistributedVectorTest DistributedVectorTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedVectorTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedVectorTest ${GTEST_BOTH_LIBRARIES} ) else() ADD_EXECUTABLE( DistributedArrayTest DistributedArrayTest.cpp ) TARGET_COMPILE_OPTIONS( DistributedArrayTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedArrayTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedArrayTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( DistributedVectorTest DistributedVectorTest.cpp ) TARGET_COMPILE_OPTIONS( DistributedVectorTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedVectorTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedVectorTest ${GTEST_BOTH_LIBRARIES} ) endif() SET( mpi_test_parameters -np 4 -H localhost:4 "${EXECUTABLE_OUTPUT_PATH}/DistributedArrayTest${CMAKE_EXECUTABLE_SUFFIX}" ) diff --git a/src/UnitTests/Containers/Multimaps/CMakeLists.txt b/src/UnitTests/Containers/Multimaps/CMakeLists.txt index 5fb63a521..0cf3ae746 100644 --- a/src/UnitTests/Containers/Multimaps/CMakeLists.txt +++ b/src/UnitTests/Containers/Multimaps/CMakeLists.txt @@ -1,14 +1,10 @@ ADD_EXECUTABLE( MultimapTest MultimapTest.cpp ) TARGET_COMPILE_OPTIONS( MultimapTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( MultimapTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +TARGET_LINK_LIBRARIES( MultimapTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( StaticMultimapTest StaticMultimapTest.cpp ) TARGET_COMPILE_OPTIONS( StaticMultimapTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( StaticMultimapTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +TARGET_LINK_LIBRARIES( StaticMultimapTest ${GTEST_BOTH_LIBRARIES} ) ADD_TEST( MultimapTest ${EXECUTABLE_OUTPUT_PATH}/MultimapTest${CMAKE_EXECUTABLE_SUFFIX} ) ADD_TEST( StaticMultimapTest ${EXECUTABLE_OUTPUT_PATH}/MultimapTest${CMAKE_EXECUTABLE_SUFFIX} ) diff --git a/src/UnitTests/Functions/CMakeLists.txt b/src/UnitTests/Functions/CMakeLists.txt index cf9466de4..f49f346c9 100644 --- a/src/UnitTests/Functions/CMakeLists.txt +++ b/src/UnitTests/Functions/CMakeLists.txt @@ -1,20 +1,20 @@ IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( MeshFunctionTest MeshFunctionTest.h MeshFunctionTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) TARGET_COMPILE_OPTIONS( MeshFunctionTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( MeshFunctionTest ${GTEST_BOTH_LIBRARIES} tnl ) + TARGET_LINK_LIBRARIES( MeshFunctionTest ${GTEST_BOTH_LIBRARIES} ) CUDA_ADD_EXECUTABLE( BoundaryMeshFunctionTest BoundaryMeshFunctionTest.h BoundaryMeshFunctionTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) TARGET_COMPILE_OPTIONS( BoundaryMeshFunctionTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( BoundaryMeshFunctionTest ${GTEST_BOTH_LIBRARIES} tnl ) + TARGET_LINK_LIBRARIES( BoundaryMeshFunctionTest ${GTEST_BOTH_LIBRARIES} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE( MeshFunctionTest MeshFunctionTest.h MeshFunctionTest.cpp ) TARGET_COMPILE_OPTIONS( MeshFunctionTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( MeshFunctionTest ${GTEST_BOTH_LIBRARIES} tnl ) + TARGET_LINK_LIBRARIES( MeshFunctionTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( BoundaryMeshFunctionTest BoundaryMeshFunctionTest.h BoundaryMeshFunctionTest.cpp ) TARGET_COMPILE_OPTIONS( BoundaryMeshFunctionTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( BoundaryMeshFunctionTest ${GTEST_BOTH_LIBRARIES} tnl ) + TARGET_LINK_LIBRARIES( BoundaryMeshFunctionTest ${GTEST_BOTH_LIBRARIES} ) ENDIF( BUILD_CUDA ) ADD_TEST( MeshFunctionTest ${EXECUTABLE_OUTPUT_PATH}/MeshFunctionTest${CMAKE_EXECUTABLE_SUFFIX} ) -ADD_TEST( BoundaryMeshFunctionTest ${EXECUTABLE_OUTPUT_PATH}/BoundaryMeshFunctionTest${CMAKE_EXECUTABLE_SUFFIX} ) \ No newline at end of file +ADD_TEST( BoundaryMeshFunctionTest ${EXECUTABLE_OUTPUT_PATH}/BoundaryMeshFunctionTest${CMAKE_EXECUTABLE_SUFFIX} ) diff --git a/src/UnitTests/Matrices/CMakeLists.txt b/src/UnitTests/Matrices/CMakeLists.txt index 8e4d0a5c1..ec90bee57 100644 --- a/src/UnitTests/Matrices/CMakeLists.txt +++ b/src/UnitTests/Matrices/CMakeLists.txt @@ -1,30 +1,24 @@ IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( SparseMatrixCopyTest SparseMatrixCopyTest.h SparseMatrixCopyTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( SparseMatrixCopyTest ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( SparseMatrixCopyTest ${GTEST_BOTH_LIBRARIES} ) CUDA_ADD_EXECUTABLE( SparseMatrixTest SparseMatrixTest.h SparseMatrixTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( SparseMatrixTest ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( SparseMatrixTest ${GTEST_BOTH_LIBRARIES} ) CUDA_ADD_EXECUTABLE( DenseMatrixTest DenseMatrixTest.h DenseMatrixTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DenseMatrixTest ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DenseMatrixTest ${GTEST_BOTH_LIBRARIES} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE( SparseMatrixCopyTest SparseMatrixCopyTest.h SparseMatrixCopyTest.cpp ) TARGET_COMPILE_OPTIONS( SparseMatrixCopyTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( SparseMatrixCopyTest ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( SparseMatrixCopyTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( SparseMatrixTest SparseMatrixTest.h SparseMatrixTest.cpp ) TARGET_COMPILE_OPTIONS( SparseMatrixTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( SparseMatrixTest ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( SparseMatrixTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( DenseMatrixTest DenseMatrixTest.h DenseMatrixTest.cpp ) TARGET_COMPILE_OPTIONS( DenseMatrixTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DenseMatrixTest ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DenseMatrixTest ${GTEST_BOTH_LIBRARIES} ) ENDIF( BUILD_CUDA ) @@ -37,15 +31,11 @@ if( ${BUILD_MPI} ) if( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( DistributedMatrixTest DistributedMatrixTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedMatrixTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedMatrixTest ${GTEST_BOTH_LIBRARIES} ) else() ADD_EXECUTABLE( DistributedMatrixTest DistributedMatrixTest.cpp ) TARGET_COMPILE_OPTIONS( DistributedMatrixTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedMatrixTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedMatrixTest ${GTEST_BOTH_LIBRARIES} ) endif() SET( mpi_test_parameters -np 4 -H localhost:4 "${EXECUTABLE_OUTPUT_PATH}/DistributedMatrixTest${CMAKE_EXECUTABLE_SUFFIX}" ) diff --git a/src/UnitTests/Meshes/CMakeLists.txt b/src/UnitTests/Meshes/CMakeLists.txt index 9cc6ed47e..c71bde352 100644 --- a/src/UnitTests/Meshes/CMakeLists.txt +++ b/src/UnitTests/Meshes/CMakeLists.txt @@ -2,42 +2,30 @@ ADD_SUBDIRECTORY( DistributedMeshes ) ADD_EXECUTABLE( BoundaryTagsTest BoundaryTagsTest.cpp ) TARGET_COMPILE_OPTIONS( BoundaryTagsTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( BoundaryTagsTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +TARGET_LINK_LIBRARIES( BoundaryTagsTest ${GTEST_BOTH_LIBRARIES} ) # Mesh cannot be compiled by nvcc < 9 due to bugs in the compiler if( ${BUILD_CUDA} AND ${CUDA_VERSION_MAJOR} GREATER_EQUAL 9 ) CUDA_ADD_EXECUTABLE( MeshTest MeshTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( MeshTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( MeshTest ${GTEST_BOTH_LIBRARIES} ) CUDA_ADD_EXECUTABLE( MeshOrderingTest MeshOrderingTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( MeshOrderingTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( MeshOrderingTest ${GTEST_BOTH_LIBRARIES} ) else() ADD_EXECUTABLE( MeshTest MeshTest.cpp ) TARGET_COMPILE_OPTIONS( MeshTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( MeshTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( MeshTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( MeshOrderingTest MeshOrderingTest.cpp ) TARGET_COMPILE_OPTIONS( MeshOrderingTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( MeshOrderingTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( MeshOrderingTest ${GTEST_BOTH_LIBRARIES} ) endif() ADD_EXECUTABLE( MeshEntityTest MeshEntityTest.cpp ) TARGET_COMPILE_OPTIONS( MeshEntityTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( MeshEntityTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +TARGET_LINK_LIBRARIES( MeshEntityTest ${GTEST_BOTH_LIBRARIES} ) ADD_TEST( BoundaryTagsTest ${EXECUTABLE_OUTPUT_PATH}/BoundaryTagsTest${CMAKE_EXECUTABLE_SUFFIX} ) @@ -68,13 +56,11 @@ ADD_TEST( MeshEntityTest ${EXECUTABLE_OUTPUT_PATH}/MeshEntityTest${CMAKE_EXECUTA # OPTIONS ${CXX_TESTS_FLAGS} ) # TARGET_LINK_LIBRARIES( MeshReaderTest # ${GTEST_BOTH_LIBRARIES} -# ${VTK_COMMON_LIBRARIES} -# tnl ) +# ${VTK_COMMON_LIBRARIES} ) #else() # ADD_EXECUTABLE( MeshReaderTest MeshReaderTest.cpp ) # TARGET_COMPILE_OPTIONS( MeshReaderTest PRIVATE ${CXX_TESTS_FLAGS} ) # TARGET_LINK_LIBRARIES( MeshReaderTest # ${GTEST_BOTH_LIBRARIES} -# ${VTK_COMMON_LIBRARIES} -# tnl ) +# ${VTK_COMMON_LIBRARIES} ) #endif() diff --git a/src/UnitTests/Meshes/DistributedMeshes/CMakeLists.txt b/src/UnitTests/Meshes/DistributedMeshes/CMakeLists.txt index ad4127dbd..068c0485a 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/CMakeLists.txt +++ b/src/UnitTests/Meshes/DistributedMeshes/CMakeLists.txt @@ -1,20 +1,14 @@ ADD_EXECUTABLE( DirectionsTest DirectionsTest.cpp ) TARGET_COMPILE_OPTIONS( DirectionsTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DirectionsTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DirectionsTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( CopyEntitesTest CopyEntitiesTest.cpp ) TARGET_COMPILE_OPTIONS( CopyEntitesTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( CopyEntitesTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( CopyEntitesTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( CutMeshFunctionTest CutMeshFunctionTest.cpp ) TARGET_COMPILE_OPTIONS( CutMeshFunctionTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( CutMeshFunctionTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( CutMeshFunctionTest ${GTEST_BOTH_LIBRARIES} ) ADD_TEST( NAME DirectionsTest COMMAND ${EXECUTABLE_OUTPUT_PATH}/DirectionsTest${CMAKE_EXECUTABLE_SUFFIX} ) ADD_TEST( NAME CopyEntitesTest COMMAND ${EXECUTABLE_OUTPUT_PATH}/CopyEntitesTest${CMAKE_EXECUTABLE_SUFFIX} ) @@ -23,63 +17,43 @@ ADD_TEST( NAME CutMeshFunctionTest COMMAND ${EXECUTABLE_OUTPUT_PATH}/CutMeshFunc if( BUILD_MPI ) ADD_EXECUTABLE( DistributedGridTest_1D DistributedGridTest_1D.cpp ) TARGET_COMPILE_OPTIONS( DistributedGridTest_1D PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedGridTest_1D - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedGridTest_1D ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( DistributedVectorFieldIO_MPIIOTest DistributedVectorFieldIO_MPIIOTest.cpp ) TARGET_COMPILE_OPTIONS( DistributedVectorFieldIO_MPIIOTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedVectorFieldIO_MPIIOTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedVectorFieldIO_MPIIOTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( DistributedGridTest_2D DistributedGridTest_2D.cpp ) TARGET_COMPILE_OPTIONS( DistributedGridTest_2D PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedGridTest_2D - ${GTEST_BOTH_LIBRARIES} - tnl) + TARGET_LINK_LIBRARIES( DistributedGridTest_2D ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( DistributedGridTest_3D DistributedGridTest_3D.cpp ) TARGET_COMPILE_OPTIONS( DistributedGridTest_3D PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedGridTest_3D - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedGridTest_3D ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( CutDistributedGridTest CutDistributedGridTest.cpp ) TARGET_COMPILE_OPTIONS( CutDistributedGridTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( CutDistributedGridTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( CutDistributedGridTest ${GTEST_BOTH_LIBRARIES} ) ADD_EXECUTABLE( CutDistributedMeshFunctionTest CutDistributedMeshFunctionTest.cpp ) TARGET_COMPILE_OPTIONS( CutDistributedMeshFunctionTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( CutDistributedMeshFunctionTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( CutDistributedMeshFunctionTest ${GTEST_BOTH_LIBRARIES} ) IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( DistributedGridIOTest DistributedGridIOTest.cu OPTIONS ${CXX_TESTS_FLAGS}) - TARGET_LINK_LIBRARIES( DistributedGridIOTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedGridIOTest ${GTEST_BOTH_LIBRARIES} ) CUDA_ADD_EXECUTABLE( DistributedGridIO_MPIIOTest DistributedGridIO_MPIIOTest.cu OPTIONS ${CXX_TESTS_FLAGS}) - TARGET_LINK_LIBRARIES( DistributedGridIO_MPIIOTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedGridIO_MPIIOTest ${GTEST_BOTH_LIBRARIES} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE( DistributedGridIO_MPIIOTest DistributedGridIO_MPIIOTest.cpp ) TARGET_COMPILE_OPTIONS( DistributedGridIO_MPIIOTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedGridIO_MPIIOTest - ${GTEST_BOTH_LIBRARIES} - tnl ) - + TARGET_LINK_LIBRARIES( DistributedGridIO_MPIIOTest ${GTEST_BOTH_LIBRARIES} ) + ADD_EXECUTABLE( DistributedGridIOTest DistributedGridIOTest.cpp ) TARGET_COMPILE_OPTIONS( DistributedGridIOTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( DistributedGridIOTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( DistributedGridIOTest ${GTEST_BOTH_LIBRARIES} ) ENDIF( BUILD_CUDA ) diff --git a/src/UnitTests/Pointers/CMakeLists.txt b/src/UnitTests/Pointers/CMakeLists.txt index bd7276363..0f5e98656 100644 --- a/src/UnitTests/Pointers/CMakeLists.txt +++ b/src/UnitTests/Pointers/CMakeLists.txt @@ -1,23 +1,17 @@ ADD_EXECUTABLE( UniquePointerTest UniquePointerTest.cpp ) TARGET_COMPILE_OPTIONS( UniquePointerTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( UniquePointerTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +TARGET_LINK_LIBRARIES( UniquePointerTest ${GTEST_BOTH_LIBRARIES} ) ADD_TEST( UniquePointerTest ${EXECUTABLE_OUTPUT_PATH}/UniquePointerTest${CMAKE_EXECUTABLE_SUFFIX} ) ADD_EXECUTABLE( SharedPointerHostTest SharedPointerHostTest.cpp ) TARGET_COMPILE_OPTIONS( SharedPointerHostTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( SharedPointerHostTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +TARGET_LINK_LIBRARIES( SharedPointerHostTest ${GTEST_BOTH_LIBRARIES} ) ADD_TEST( SharedPointerHostTest ${EXECUTABLE_OUTPUT_PATH}/SharedPointerHostTest${CMAKE_EXECUTABLE_SUFFIX} ) if( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( SharedPointerCudaTest SharedPointerCudaTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( SharedPointerCudaTest - ${GTEST_BOTH_LIBRARIES} - tnl ) + TARGET_LINK_LIBRARIES( SharedPointerCudaTest ${GTEST_BOTH_LIBRARIES} ) ADD_TEST( SharedPointerCudaTest ${EXECUTABLE_OUTPUT_PATH}/SharedPointerCudaTest${CMAKE_EXECUTABLE_SUFFIX} ) endif( BUILD_CUDA ) diff --git a/tests/long-time-unit-tests/CMakeLists.txt b/tests/long-time-unit-tests/CMakeLists.txt index 61065e506..9a3b0cafb 100644 --- a/tests/long-time-unit-tests/CMakeLists.txt +++ b/tests/long-time-unit-tests/CMakeLists.txt @@ -8,8 +8,6 @@ else() ADD_EXECUTABLE( tnl-test-matrix-formats ${headers} matrix-formats-test.cpp ) endif() -TARGET_LINK_LIBRARIES( tnl-test-matrix-formats tnl ) - INSTALL( TARGETS tnl-test-matrix-formats RUNTIME DESTINATION bin @@ -26,7 +24,7 @@ IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( matrix-cpu-cuda-test${debugExt} matrix-cpu-cuda-test.cu OPTIONS ${CUDA_ADD_EXECUTABLE_OPTIONS} ) SET_TARGET_PROPERTIES( matrix-cpu-cuda-test${debugExt} PROPERTIES CUDA_COMPILE_FLAG "${CXX_OPTIMIZE_FLAGS}" ) - TARGET_LINK_LIBRARIES( matrix-cpu-cuda-test${debugExt} tnl ${CUSPARSE_LIBRARY} ) + TARGET_LINK_LIBRARIES( matrix-cpu-cuda-test${debugExt} ${CUSPARSE_LIBRARY} ) INSTALL( TARGETS matrix-cpu-cuda-test${debugExt} RUNTIME DESTINATION bin ) ENDIF() diff --git a/tests/mpi/CMakeLists.txt b/tests/mpi/CMakeLists.txt index 96f461a3c..53aab9037 100644 --- a/tests/mpi/CMakeLists.txt +++ b/tests/mpi/CMakeLists.txt @@ -1,35 +1,35 @@ ADD_EXECUTABLE( MeshFunctionEvaluateTest ${headers} MeshFunctionEvaluateTest.cpp ) -TARGET_LINK_LIBRARIES( MeshFunctionEvaluateTest ${CPPUNIT_LIBRARIES} tnl ) +TARGET_LINK_LIBRARIES( MeshFunctionEvaluateTest ${CPPUNIT_LIBRARIES} ) TARGET_COMPILE_DEFINITIONS( MeshFunctionEvaluateTest PUBLIC "-DDIMENSION=2" ) TARGET_COMPILE_DEFINITIONS( MeshFunctionEvaluateTest PUBLIC "-DXDISTR -DYDISTR" ) ADD_EXECUTABLE( MeshFunctionEvaluateTestX ${headers} MeshFunctionEvaluateTest.cpp ) -TARGET_LINK_LIBRARIES( MeshFunctionEvaluateTestX ${CPPUNIT_LIBRARIES} tnl ) +TARGET_LINK_LIBRARIES( MeshFunctionEvaluateTestX ${CPPUNIT_LIBRARIES} ) TARGET_COMPILE_DEFINITIONS( MeshFunctionEvaluateTestX PUBLIC "-DDIMENSION=2" ) TARGET_COMPILE_DEFINITIONS( MeshFunctionEvaluateTestX PUBLIC "-DXDISTR" ) ADD_EXECUTABLE( MeshFunctionEvaluateTestY ${headers} MeshFunctionEvaluateTest.cpp ) -TARGET_LINK_LIBRARIES( MeshFunctionEvaluateTestY ${CPPUNIT_LIBRARIES} tnl ) +TARGET_LINK_LIBRARIES( MeshFunctionEvaluateTestY ${CPPUNIT_LIBRARIES} ) TARGET_COMPILE_DEFINITIONS( MeshFunctionEvaluateTestY PUBLIC "-DDIMENSION=2" ) TARGET_COMPILE_DEFINITIONS( MeshFunctionEvaluateTestY PUBLIC "-DYDISTR" ) ADD_EXECUTABLE( mpiio-save-test ${headers} mpiio-save-test.cpp ) -TARGET_LINK_LIBRARIES( mpiio-save-test ${CPPUNIT_LIBRARIES} tnl ) +TARGET_LINK_LIBRARIES( mpiio-save-test ${CPPUNIT_LIBRARIES} ) ADD_EXECUTABLE( mpiio-save-load-test ${headers} mpiio-save-load-test.cpp ) -TARGET_LINK_LIBRARIES( mpiio-save-load-test ${CPPUNIT_LIBRARIES} tnl ) +TARGET_LINK_LIBRARIES( mpiio-save-load-test ${CPPUNIT_LIBRARIES} ) IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( mpi-gpu-test ${headers} mpi-gpu.cu ) - TARGET_LINK_LIBRARIES( mpi-gpu-test ${CPPUNIT_LIBRARIES} tnl ) + TARGET_LINK_LIBRARIES( mpi-gpu-test ${CPPUNIT_LIBRARIES} ) TARGET_COMPILE_DEFINITIONS( mpi-gpu-test PUBLIC ${MIC_CXX_FLAGS} ) CUDA_ADD_EXECUTABLE( GPUmeshFunctionEvaluateTest ${headers} GPUmeshFunctionEvaluateTest.cu ) - TARGET_LINK_LIBRARIES( GPUmeshFunctionEvaluateTest ${CPPUNIT_LIBRARIES} tnl ) + TARGET_LINK_LIBRARIES( GPUmeshFunctionEvaluateTest ${CPPUNIT_LIBRARIES} ) TARGET_COMPILE_DEFINITIONS( GPUmeshFunctionEvaluateTest PUBLIC ${MIC_CXX_FLAGS} ) CUDA_ADD_EXECUTABLE( mpiio-save-test-gpu ${headers} mpiio-save-test.cu ) - TARGET_LINK_LIBRARIES( mpiio-save-test-gpu ${CPPUNIT_LIBRARIES} tnl ) + TARGET_LINK_LIBRARIES( mpiio-save-test-gpu ${CPPUNIT_LIBRARIES} ) TARGET_COMPILE_DEFINITIONS( mpiio-save-test-gpu PUBLIC ${MIC_CXX_FLAGS} ) ENDIF( BUILD_CUDA ) -- GitLab From 20ee006ba1a774f017ca0446b9f5ef7d59e9516f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sun, 18 Nov 2018 13:17:49 +0100 Subject: [PATCH 35/39] Split templated tests into separate compilation units per device to speed up parallel build --- .../Containers/ArrayOperationsTest.h | 1 - src/UnitTests/Containers/ArrayTest.h | 16 +++-- src/UnitTests/Containers/ArrayViewTest.h | 12 +++- src/UnitTests/Containers/CMakeLists.txt | 61 ++++++++++--------- src/UnitTests/Containers/VectorTest.h | 3 +- 5 files changed, 54 insertions(+), 39 deletions(-) diff --git a/src/UnitTests/Containers/ArrayOperationsTest.h b/src/UnitTests/Containers/ArrayOperationsTest.h index aff044601..948747541 100644 --- a/src/UnitTests/Containers/ArrayOperationsTest.h +++ b/src/UnitTests/Containers/ArrayOperationsTest.h @@ -12,7 +12,6 @@ #ifdef HAVE_GTEST #include -#include #include "gtest/gtest.h" diff --git a/src/UnitTests/Containers/ArrayTest.h b/src/UnitTests/Containers/ArrayTest.h index f92954df3..9e4b1f572 100644 --- a/src/UnitTests/Containers/ArrayTest.h +++ b/src/UnitTests/Containers/ArrayTest.h @@ -62,6 +62,7 @@ protected: // types for which ArrayTest is instantiated using ArrayTypes = ::testing::Types< +#ifndef HAVE_CUDA Array< int, Devices::Host, short >, Array< long, Devices::Host, short >, Array< float, Devices::Host, short >, @@ -76,9 +77,10 @@ using ArrayTypes = ::testing::Types< Array< long, Devices::Host, long >, Array< float, Devices::Host, long >, Array< double, Devices::Host, long >, - Array< MyData, Devices::Host, long >, + Array< MyData, Devices::Host, long > // FIXME: this segfaults in String::~String() -// Array< String, Devices::Host, long >, +// Array< String, Devices::Host, long > +#endif #ifdef HAVE_CUDA Array< int, Devices::Cuda, short >, Array< long, Devices::Cuda, short >, @@ -94,9 +96,10 @@ using ArrayTypes = ::testing::Types< Array< long, Devices::Cuda, long >, Array< float, Devices::Cuda, long >, Array< double, Devices::Cuda, long >, - Array< MyData, Devices::Cuda, long >, + Array< MyData, Devices::Cuda, long > #endif #ifdef HAVE_MIC + , Array< int, Devices::MIC, short >, Array< long, Devices::MIC, short >, Array< float, Devices::MIC, short >, @@ -112,15 +115,18 @@ using ArrayTypes = ::testing::Types< Array< int, Devices::MIC, long >, Array< long, Devices::MIC, long >, Array< float, Devices::MIC, long >, - Array< double, Devices::MIC, long >, + Array< double, Devices::MIC, long > // TODO: MyData does not work on MIC -// Array< MyData, Devices::MIC, long >, +// Array< MyData, Devices::MIC, long > #endif // all array tests should also work with Vector // (but we can't test all types because the argument list would be too long...) +#ifndef HAVE_CUDA + , Vector< float, Devices::Host, long >, Vector< double, Devices::Host, long > +#endif #ifdef HAVE_CUDA , Vector< float, Devices::Cuda, long >, diff --git a/src/UnitTests/Containers/ArrayViewTest.h b/src/UnitTests/Containers/ArrayViewTest.h index 2fa6fb3af..ccc9ba9f0 100644 --- a/src/UnitTests/Containers/ArrayViewTest.h +++ b/src/UnitTests/Containers/ArrayViewTest.h @@ -65,6 +65,7 @@ protected: // types for which ArrayViewTest is instantiated using ViewTypes = ::testing::Types< +#ifndef HAVE_CUDA ArrayView< int, Devices::Host, short >, ArrayView< long, Devices::Host, short >, ArrayView< float, Devices::Host, short >, @@ -79,9 +80,10 @@ using ViewTypes = ::testing::Types< ArrayView< long, Devices::Host, long >, ArrayView< float, Devices::Host, long >, ArrayView< double, Devices::Host, long >, - ArrayView< MyData, Devices::Host, long >, + ArrayView< MyData, Devices::Host, long > // FIXME: this segfaults in String::~String() -// , ArrayView< String, Devices::Host, long >, +// , ArrayView< String, Devices::Host, long > +#endif #ifdef HAVE_CUDA ArrayView< int, Devices::Cuda, short >, ArrayView< long, Devices::Cuda, short >, @@ -97,9 +99,10 @@ using ViewTypes = ::testing::Types< ArrayView< long, Devices::Cuda, long >, ArrayView< float, Devices::Cuda, long >, ArrayView< double, Devices::Cuda, long >, - ArrayView< MyData, Devices::Cuda, long >, + ArrayView< MyData, Devices::Cuda, long > #endif #ifdef HAVE_MIC + , ArrayView< int, Devices::MIC, short >, ArrayView< long, Devices::MIC, short >, ArrayView< float, Devices::MIC, short >, @@ -122,8 +125,11 @@ using ViewTypes = ::testing::Types< // all ArrayView tests should also work with VectorView // (but we can't test all types because the argument list would be too long...) +#ifndef HAVE_CUDA + , VectorView< float, Devices::Host, long >, VectorView< double, Devices::Host, long > +#endif #ifdef HAVE_CUDA , VectorView< float, Devices::Cuda, long >, diff --git a/src/UnitTests/Containers/CMakeLists.txt b/src/UnitTests/Containers/CMakeLists.txt index f9556a479..fe75ed458 100644 --- a/src/UnitTests/Containers/CMakeLists.txt +++ b/src/UnitTests/Containers/CMakeLists.txt @@ -6,56 +6,54 @@ IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( ArrayOperationsTest ArrayOperationsTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( ArrayOperationsTest ${GTEST_BOTH_LIBRARIES} ) -ELSE( BUILD_CUDA ) +ELSE( BUILD_CUDA ) ADD_EXECUTABLE( ArrayOperationsTest ArrayOperationsTest.cpp ) TARGET_COMPILE_OPTIONS( ArrayOperationsTest PRIVATE ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( ArrayOperationsTest ${GTEST_BOTH_LIBRARIES} ) ENDIF( BUILD_CUDA ) -IF( BUILD_CUDA ) - CUDA_ADD_EXECUTABLE( ArrayTest ArrayTest.cu - OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayTest ${GTEST_BOTH_LIBRARIES} ) - - CUDA_ADD_EXECUTABLE( ArrayViewTest ArrayViewTest.cu - OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayViewTest ${GTEST_BOTH_LIBRARIES} ) -ELSE( BUILD_CUDA ) - ADD_EXECUTABLE( ArrayTest ArrayTest.cpp ) - TARGET_COMPILE_OPTIONS( ArrayTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayTest ${GTEST_BOTH_LIBRARIES} ) - - ADD_EXECUTABLE( ArrayViewTest ArrayViewTest.cpp ) - TARGET_COMPILE_OPTIONS( ArrayViewTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayViewTest ${GTEST_BOTH_LIBRARIES} ) -ENDIF( BUILD_CUDA ) +ADD_EXECUTABLE( ArrayTest ArrayTest.cpp ) +TARGET_COMPILE_OPTIONS( ArrayTest PRIVATE ${CXX_TESTS_FLAGS} ) +TARGET_LINK_LIBRARIES( ArrayTest ${GTEST_BOTH_LIBRARIES} ) -ADD_EXECUTABLE( StaticArrayTest StaticArrayTest.cpp ) -TARGET_COMPILE_OPTIONS( StaticArrayTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( StaticArrayTest ${GTEST_BOTH_LIBRARIES} ) +ADD_EXECUTABLE( ArrayViewTest ArrayViewTest.cpp ) +TARGET_COMPILE_OPTIONS( ArrayViewTest PRIVATE ${CXX_TESTS_FLAGS} ) +TARGET_LINK_LIBRARIES( ArrayViewTest ${GTEST_BOTH_LIBRARIES} ) # NOTE: Vector = Array + VectorOperations, VectorView = ArrayView + VectorOperations, # so we test Vector, VectorView and VectorOperations at the same time +ADD_EXECUTABLE( VectorTest VectorTest.cpp ) +TARGET_COMPILE_OPTIONS( VectorTest PRIVATE ${CXX_TESTS_FLAGS} ) +TARGET_LINK_LIBRARIES( VectorTest ${GTEST_BOTH_LIBRARIES} ) + IF( BUILD_CUDA ) - CUDA_ADD_EXECUTABLE( VectorTest VectorTest.cu + CUDA_ADD_EXECUTABLE( ArrayTestCuda ArrayTest.cu + OPTIONS ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( ArrayTestCuda ${GTEST_BOTH_LIBRARIES} ) + + CUDA_ADD_EXECUTABLE( ArrayViewTestCuda ArrayViewTest.cu + OPTIONS ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( ArrayViewTestCuda ${GTEST_BOTH_LIBRARIES} ) + + CUDA_ADD_EXECUTABLE( VectorTestCuda VectorTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( VectorTest ${GTEST_BOTH_LIBRARIES} ) -ELSE( BUILD_CUDA ) - ADD_EXECUTABLE( VectorTest VectorTest.cpp ) - TARGET_COMPILE_OPTIONS( VectorTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( VectorTest ${GTEST_BOTH_LIBRARIES} ) + TARGET_LINK_LIBRARIES( VectorTestCuda ${GTEST_BOTH_LIBRARIES} ) ENDIF( BUILD_CUDA ) IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( MultireductionTest MultireductionTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( MultireductionTest ${GTEST_BOTH_LIBRARIES} ) -ELSE( BUILD_CUDA ) +ELSE( BUILD_CUDA ) ADD_EXECUTABLE( MultireductionTest MultireductionTest.cpp ) TARGET_COMPILE_OPTIONS( MultireductionTest PRIVATE ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( MultireductionTest ${GTEST_BOTH_LIBRARIES} ) ENDIF( BUILD_CUDA ) +ADD_EXECUTABLE( StaticArrayTest StaticArrayTest.cpp ) +TARGET_COMPILE_OPTIONS( StaticArrayTest PRIVATE ${CXX_TESTS_FLAGS} ) +TARGET_LINK_LIBRARIES( StaticArrayTest ${GTEST_BOTH_LIBRARIES} ) + ADD_EXECUTABLE( StaticVectorTest StaticVectorTest.cpp ) TARGET_COMPILE_OPTIONS( StaticVectorTest PRIVATE ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( StaticVectorTest ${GTEST_BOTH_LIBRARIES} ) @@ -75,9 +73,14 @@ ADD_TEST( ListTest ${EXECUTABLE_OUTPUT_PATH}/ListTest${CMAKE_EXECUTABLE_SUFFIX} ADD_TEST( ArrayOperationsTest ${EXECUTABLE_OUTPUT_PATH}/ArrayOperationsTest${CMAKE_EXECUTABLE_SUFFIX} ) ADD_TEST( ArrayTest ${EXECUTABLE_OUTPUT_PATH}/ArrayTest${CMAKE_EXECUTABLE_SUFFIX} ) ADD_TEST( ArrayViewTest ${EXECUTABLE_OUTPUT_PATH}/ArrayViewTest${CMAKE_EXECUTABLE_SUFFIX} ) -ADD_TEST( StaticArrayTest ${EXECUTABLE_OUTPUT_PATH}/StaticArrayTest${CMAKE_EXECUTABLE_SUFFIX} ) ADD_TEST( VectorTest ${EXECUTABLE_OUTPUT_PATH}/VectorTest${CMAKE_EXECUTABLE_SUFFIX} ) +IF( BUILD_CUDA ) + ADD_TEST( ArrayTestCuda ${EXECUTABLE_OUTPUT_PATH}/ArrayTestCuda${CMAKE_EXECUTABLE_SUFFIX} ) + ADD_TEST( ArrayViewTestCuda ${EXECUTABLE_OUTPUT_PATH}/ArrayViewTestCuda${CMAKE_EXECUTABLE_SUFFIX} ) + ADD_TEST( VectorTestCuda ${EXECUTABLE_OUTPUT_PATH}/VectorTestCuda${CMAKE_EXECUTABLE_SUFFIX} ) +ENDIF() ADD_TEST( MultireductionTest ${EXECUTABLE_OUTPUT_PATH}/MultireductionTest${CMAKE_EXECUTABLE_SUFFIX} ) +ADD_TEST( StaticArrayTest ${EXECUTABLE_OUTPUT_PATH}/StaticArrayTest${CMAKE_EXECUTABLE_SUFFIX} ) ADD_TEST( StaticVectorTest ${EXECUTABLE_OUTPUT_PATH}/StaticVectorTest${CMAKE_EXECUTABLE_SUFFIX} ) #ADD_TEST( MultiArrayTest ${EXECUTABLE_OUTPUT_PATH}/MultiArrayTest${CMAKE_EXECUTABLE_SUFFIX} ) diff --git a/src/UnitTests/Containers/VectorTest.h b/src/UnitTests/Containers/VectorTest.h index 81242fe1a..05df280d6 100644 --- a/src/UnitTests/Containers/VectorTest.h +++ b/src/UnitTests/Containers/VectorTest.h @@ -86,6 +86,7 @@ protected: // types for which VectorTest is instantiated // TODO: Quad must be fixed using VectorTypes = ::testing::Types< +#ifndef HAVE_CUDA Vector< int, Devices::Host, short >, Vector< long, Devices::Host, short >, Vector< float, Devices::Host, short >, @@ -104,8 +105,8 @@ using VectorTypes = ::testing::Types< Vector< double, Devices::Host, long > //Vector< Quad< float >, Devices::Host, long >, //Vector< Quad< double >, Devices::Host, long > +#endif #ifdef HAVE_CUDA - , Vector< int, Devices::Cuda, short >, Vector< long, Devices::Cuda, short >, Vector< float, Devices::Cuda, short >, -- GitLab From d415ad4c3f2e593bd3fc93842ab15209984e2c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sun, 18 Nov 2018 15:56:50 +0100 Subject: [PATCH 36/39] Removed tnl-link script - useless for a header-only library --- src/Tools/CMakeLists.txt | 2 -- src/Tools/tnl-link.in | 12 ------------ src/Tools/tnl-quickstart/Makefile.in | 2 -- 3 files changed, 16 deletions(-) delete mode 100644 src/Tools/tnl-link.in diff --git a/src/Tools/CMakeLists.txt b/src/Tools/CMakeLists.txt index faaace89f..961737a95 100644 --- a/src/Tools/CMakeLists.txt +++ b/src/Tools/CMakeLists.txt @@ -1,7 +1,6 @@ add_subdirectory (tnl-quickstart) CONFIGURE_FILE( "tnl-compile.in" "${PROJECT_TOOLS_PATH}/tnl-compile" @ONLY ) -CONFIGURE_FILE( "tnl-link.in" "${PROJECT_TOOLS_PATH}/tnl-link" @ONLY ) CONFIGURE_FILE( "tnl-bindir.in" "${PROJECT_TOOLS_PATH}/tnl-bindir" @ONLY ) ADD_EXECUTABLE(tnl-grid-setup tnl-grid-setup.cpp ) @@ -38,7 +37,6 @@ INSTALL( TARGETS tnl-init INSTALL( FILES ${PROJECT_TOOLS_PATH}/tnl-bindir ${PROJECT_TOOLS_PATH}/tnl-compile - ${PROJECT_TOOLS_PATH}/tnl-link tnl-err2eoc tnl-log-to-html.py DESTINATION bin diff --git a/src/Tools/tnl-link.in b/src/Tools/tnl-link.in deleted file mode 100644 index 8be63b0f4..000000000 --- a/src/Tools/tnl-link.in +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -DEBUG="" - -for option in "$@" -do - case $option in - --debug ) DEBUG="-dbg" - esac -done - -echo -L@CMAKE_INSTALL_PREFIX@/lib -ltnl${DEBUG} @CUSPARSE_LIBRARY@ diff --git a/src/Tools/tnl-quickstart/Makefile.in b/src/Tools/tnl-quickstart/Makefile.in index c2954e00e..cc9e46b4b 100644 --- a/src/Tools/tnl-quickstart/Makefile.in +++ b/src/Tools/tnl-quickstart/Makefile.in @@ -1,8 +1,6 @@ TARGET = {problemBaseName} INSTALL_DIR = ${{HOME}}/local -LDFLAGS = $(shell tnl-link ) - ifdef WITH_CUDA CXX = nvcc CXX_FLAGS = $(shell tnl-compile --cuda) -- GitLab From c6d2c7904c0c19da2e2e2f2c1b35788b70891b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Mon, 24 Dec 2018 17:21:03 +0100 Subject: [PATCH 37/39] Fixed cmake error --- src/Tools/CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Tools/CMakeLists.txt b/src/Tools/CMakeLists.txt index 961737a95..787bf40bf 100644 --- a/src/Tools/CMakeLists.txt +++ b/src/Tools/CMakeLists.txt @@ -12,10 +12,17 @@ ADD_EXECUTABLE(tnl-diff tnl-diff.cpp ) ADD_EXECUTABLE(tnl-lattice-init tnl-lattice-init.cpp ) ADD_EXECUTABLE(tnl-image-converter tnl-image-converter.cpp ) -target_link_libraries(tnl-image-converter ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ) +if( PNG_FOUND ) + target_link_libraries(tnl-image-converter ${PNG_LIBRARIES} ) +endif() +if( JPEG_FOUND ) + target_link_libraries(tnl-image-converter ${JPEG_LIBRARIES} ) +endif() ADD_EXECUTABLE(tnl-dicom-reader tnl-dicom-reader.cpp ) -target_link_libraries(tnl-dicom-reader ${DCMTK_LIBRARIES} ) +if( DCMTK_FOUND ) + target_link_libraries(tnl-dicom-reader ${DCMTK_LIBRARIES} ) +endif() IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( tnl-cuda-arch tnl-cuda-arch.cu ) -- GitLab From 3a9a74785a0381b2b65cdc9689b6196d9314fb50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 24 Jan 2019 22:12:02 +0100 Subject: [PATCH 38/39] Fixed typo in CMakeLists.txt and disabled unfinished DenseMatrixTest --- src/UnitTests/Matrices/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/UnitTests/Matrices/CMakeLists.txt b/src/UnitTests/Matrices/CMakeLists.txt index ec90bee57..1ae83cf89 100644 --- a/src/UnitTests/Matrices/CMakeLists.txt +++ b/src/UnitTests/Matrices/CMakeLists.txt @@ -24,7 +24,8 @@ ENDIF( BUILD_CUDA ) ADD_TEST( SparseMatrixCopyTest ${EXECUTABLE_OUTPUT_PATH}/SparseMatrixCopyTest${CMAKE_EXECUTABLE_SUFFIX} ) ADD_TEST( SparseMatrixTest ${EXECUTABLE_OUTPUT_PATH}/SparseMatrixTest${CMAKE_EXECUTABLE_SUFFIX} ) -ADD_TEST( DenseMatrixTest ${EXECUTABLE_OUTPUT_PATH}/SparseMatrixTest${CMAKE_EXECUTABLE_SUFFIX} ) +# TODO: DenseMatrixTest is not finished +#ADD_TEST( DenseMatrixTest ${EXECUTABLE_OUTPUT_PATH}/DenseMatrixTest${CMAKE_EXECUTABLE_SUFFIX} ) if( ${BUILD_MPI} ) -- GitLab From d289751fcf83def655969470e242ae3aa6e4e770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 24 Jan 2019 22:13:27 +0100 Subject: [PATCH 39/39] Split SparseMatrixTest into multiple source files to speed up parallel build --- src/UnitTests/Matrices/CMakeLists.txt | 60 +- src/UnitTests/Matrices/SparseMatrixTest.h | 786 +----------------- ...MatrixTest_impl.h => SparseMatrixTest.hpp} | 0 .../Matrices/SparseMatrixTest_AdEllpack.cpp | 1 + .../Matrices/SparseMatrixTest_AdEllpack.cu | 1 + .../Matrices/SparseMatrixTest_AdEllpack.h | 151 ++++ .../Matrices/SparseMatrixTest_BiEllpack.cpp | 1 + .../Matrices/SparseMatrixTest_BiEllpack.cu | 1 + .../Matrices/SparseMatrixTest_BiEllpack.h | 150 ++++ .../Matrices/SparseMatrixTest_CSR.cpp | 1 + .../Matrices/SparseMatrixTest_CSR.cu | 1 + src/UnitTests/Matrices/SparseMatrixTest_CSR.h | 148 ++++ .../SparseMatrixTest_ChunkedEllpack.cpp | 1 + .../SparseMatrixTest_ChunkedEllpack.cu | 1 + .../SparseMatrixTest_ChunkedEllpack.h | 153 ++++ .../Matrices/SparseMatrixTest_Ellpack.cpp | 1 + .../Matrices/SparseMatrixTest_Ellpack.cu | 1 + .../Matrices/SparseMatrixTest_Ellpack.h | 148 ++++ .../SparseMatrixTest_SlicedEllpack.cpp | 1 + .../SparseMatrixTest_SlicedEllpack.cu | 1 + .../Matrices/SparseMatrixTest_SlicedEllpack.h | 148 ++++ 21 files changed, 966 insertions(+), 790 deletions(-) rename src/UnitTests/Matrices/{SparseMatrixTest_impl.h => SparseMatrixTest.hpp} (100%) create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.cpp create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.cu create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.h create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.cpp create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.cu create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.h create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_CSR.cpp create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_CSR.cu create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_CSR.h create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cpp create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cu create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.h create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_Ellpack.cpp create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_Ellpack.cu create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_Ellpack.h create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.cpp create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.cu create mode 100644 src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.h diff --git a/src/UnitTests/Matrices/CMakeLists.txt b/src/UnitTests/Matrices/CMakeLists.txt index 1ae83cf89..adc2c6dbb 100644 --- a/src/UnitTests/Matrices/CMakeLists.txt +++ b/src/UnitTests/Matrices/CMakeLists.txt @@ -1,22 +1,64 @@ IF( BUILD_CUDA ) - CUDA_ADD_EXECUTABLE( SparseMatrixCopyTest SparseMatrixCopyTest.h SparseMatrixCopyTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) + CUDA_ADD_EXECUTABLE( SparseMatrixCopyTest SparseMatrixCopyTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( SparseMatrixCopyTest ${GTEST_BOTH_LIBRARIES} ) - CUDA_ADD_EXECUTABLE( SparseMatrixTest SparseMatrixTest.h SparseMatrixTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) + CUDA_ADD_EXECUTABLE( SparseMatrixTest SparseMatrixTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( SparseMatrixTest ${GTEST_BOTH_LIBRARIES} ) - CUDA_ADD_EXECUTABLE( DenseMatrixTest DenseMatrixTest.h DenseMatrixTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) + CUDA_ADD_EXECUTABLE( SparseMatrixTest_AdEllpack SparseMatrixTest_AdEllpack.cu OPTIONS ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_AdEllpack ${GTEST_BOTH_LIBRARIES} ) + + CUDA_ADD_EXECUTABLE( SparseMatrixTest_BiEllpack SparseMatrixTest_BiEllpack.cu OPTIONS ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_BiEllpack ${GTEST_BOTH_LIBRARIES} ) + + CUDA_ADD_EXECUTABLE( SparseMatrixTest_ChunkedEllpack SparseMatrixTest_ChunkedEllpack.cu OPTIONS ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_ChunkedEllpack ${GTEST_BOTH_LIBRARIES} ) + + CUDA_ADD_EXECUTABLE( SparseMatrixTest_CSR SparseMatrixTest_CSR.cu OPTIONS ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_CSR ${GTEST_BOTH_LIBRARIES} ) + + CUDA_ADD_EXECUTABLE( SparseMatrixTest_Ellpack SparseMatrixTest_Ellpack.cu OPTIONS ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_Ellpack ${GTEST_BOTH_LIBRARIES} ) + + CUDA_ADD_EXECUTABLE( SparseMatrixTest_SlicedEllpack SparseMatrixTest_SlicedEllpack.cu OPTIONS ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_SlicedEllpack ${GTEST_BOTH_LIBRARIES} ) + + CUDA_ADD_EXECUTABLE( DenseMatrixTest DenseMatrixTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( DenseMatrixTest ${GTEST_BOTH_LIBRARIES} ) ELSE( BUILD_CUDA ) - ADD_EXECUTABLE( SparseMatrixCopyTest SparseMatrixCopyTest.h SparseMatrixCopyTest.cpp ) + ADD_EXECUTABLE( SparseMatrixCopyTest SparseMatrixCopyTest.cpp ) TARGET_COMPILE_OPTIONS( SparseMatrixCopyTest PRIVATE ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( SparseMatrixCopyTest ${GTEST_BOTH_LIBRARIES} ) - ADD_EXECUTABLE( SparseMatrixTest SparseMatrixTest.h SparseMatrixTest.cpp ) + ADD_EXECUTABLE( SparseMatrixTest SparseMatrixTest.cpp ) TARGET_COMPILE_OPTIONS( SparseMatrixTest PRIVATE ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( SparseMatrixTest ${GTEST_BOTH_LIBRARIES} ) - ADD_EXECUTABLE( DenseMatrixTest DenseMatrixTest.h DenseMatrixTest.cpp ) + ADD_EXECUTABLE( SparseMatrixTest_AdEllpack SparseMatrixTest_AdEllpack.cpp ) + TARGET_COMPILE_OPTIONS( SparseMatrixTest_AdEllpack PRIVATE ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_AdEllpack ${GTEST_BOTH_LIBRARIES} ) + + ADD_EXECUTABLE( SparseMatrixTest_BiEllpack SparseMatrixTest_BiEllpack.cpp ) + TARGET_COMPILE_OPTIONS( SparseMatrixTest_BiEllpack PRIVATE ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_BiEllpack ${GTEST_BOTH_LIBRARIES} ) + + ADD_EXECUTABLE( SparseMatrixTest_ChunkedEllpack SparseMatrixTest_ChunkedEllpack.cpp ) + TARGET_COMPILE_OPTIONS( SparseMatrixTest_ChunkedEllpack PRIVATE ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_ChunkedEllpack ${GTEST_BOTH_LIBRARIES} ) + + ADD_EXECUTABLE( SparseMatrixTest_CSR SparseMatrixTest_CSR.cpp ) + TARGET_COMPILE_OPTIONS( SparseMatrixTest_CSR PRIVATE ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_CSR ${GTEST_BOTH_LIBRARIES} ) + + ADD_EXECUTABLE( SparseMatrixTest_Ellpack SparseMatrixTest_Ellpack.cpp ) + TARGET_COMPILE_OPTIONS( SparseMatrixTest_Ellpack PRIVATE ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_Ellpack ${GTEST_BOTH_LIBRARIES} ) + + ADD_EXECUTABLE( SparseMatrixTest_SlicedEllpack SparseMatrixTest_SlicedEllpack.cpp ) + TARGET_COMPILE_OPTIONS( SparseMatrixTest_SlicedEllpack PRIVATE ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( SparseMatrixTest_SlicedEllpack ${GTEST_BOTH_LIBRARIES} ) + + ADD_EXECUTABLE( DenseMatrixTest DenseMatrixTest.cpp ) TARGET_COMPILE_OPTIONS( DenseMatrixTest PRIVATE ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( DenseMatrixTest ${GTEST_BOTH_LIBRARIES} ) ENDIF( BUILD_CUDA ) @@ -24,6 +66,12 @@ ENDIF( BUILD_CUDA ) ADD_TEST( SparseMatrixCopyTest ${EXECUTABLE_OUTPUT_PATH}/SparseMatrixCopyTest${CMAKE_EXECUTABLE_SUFFIX} ) ADD_TEST( SparseMatrixTest ${EXECUTABLE_OUTPUT_PATH}/SparseMatrixTest${CMAKE_EXECUTABLE_SUFFIX} ) +ADD_TEST( SparseMatrixTest_AdEllpack ${EXECUTABLE_OUTPUT_PATH}/SparseMatrixTest_AdEllpack${CMAKE_EXECUTABLE_SUFFIX} ) +ADD_TEST( SparseMatrixTest_BiEllpack ${EXECUTABLE_OUTPUT_PATH}/SparseMatrixTest_BiEllpack${CMAKE_EXECUTABLE_SUFFIX} ) +ADD_TEST( SparseMatrixTest_ChunkedEllpack ${EXECUTABLE_OUTPUT_PATH}/SparseMatrixTest_ChunkedEllpack${CMAKE_EXECUTABLE_SUFFIX} ) +ADD_TEST( SparseMatrixTest_CSR ${EXECUTABLE_OUTPUT_PATH}/SparseMatrixTest_CSR${CMAKE_EXECUTABLE_SUFFIX} ) +ADD_TEST( SparseMatrixTest_Ellpack ${EXECUTABLE_OUTPUT_PATH}/SparseMatrixTest_Ellpack${CMAKE_EXECUTABLE_SUFFIX} ) +ADD_TEST( SparseMatrixTest_SlicedEllpack ${EXECUTABLE_OUTPUT_PATH}/SparseMatrixTest_SlicedEllpack${CMAKE_EXECUTABLE_SUFFIX} ) # TODO: DenseMatrixTest is not finished #ADD_TEST( DenseMatrixTest ${EXECUTABLE_OUTPUT_PATH}/DenseMatrixTest${CMAKE_EXECUTABLE_SUFFIX} ) diff --git a/src/UnitTests/Matrices/SparseMatrixTest.h b/src/UnitTests/Matrices/SparseMatrixTest.h index 1145570b2..78121bdf2 100644 --- a/src/UnitTests/Matrices/SparseMatrixTest.h +++ b/src/UnitTests/Matrices/SparseMatrixTest.h @@ -8,73 +8,9 @@ /* See Copyright Notice in tnl/Copyright */ -// TODO -/* - * getType() ::HOW? How to test this for each format? edit string how? - * Found the mistake for Cuda instead of Devices::Cuda. Incorrect String in src/TNL/Devices/Cuda.cpp - * MISSING: indexType is missing in CSR_impl.h - * getTypeVirtual() ::TEST? This just calls getType(). - * getSerializationType() ::TEST? This just calls HostType::getType(). - * getSerializationTypeVirtual() ::TEST? This just calls getSerializationType(). - * setDimensions() ::DONE - * setCompressedRowLengths() ::DONE - * getRowLength() ::USED! In test_SetCompressedRowLengths() to verify the test itself. - * getRowLengthFast() ::TEST? How to test __cuda_callable__? ONLY TEST ON CPU FOR NOW - * setLike() ::DONE - * reset() ::DONE - * setElementFast() ::TEST? How to test __cuda_callable__? ONLY TEST ON CPU FOR NOW - * setElement() ::DONE - * addElementFast() ::TEST? How to test __cuda_callable__? ONLY TEST ON CPU FOR NOW - * addElement() ::DONE - * setRowFast() ::TEST? How to test __cuda_callable__? ONLY TEST ON CPU FOR NOW - * setRow() ::DONE - * MISTAKE!!! In SlicedEllpack: addElement(), line 263, "column <= this->rows" shouldn't it be: "column <= this->columns", otherwise test_SetRow causes the assertion to fail. - * addRowFast() ::TEST? How to test __cuda_callable__? ONLY TEST ON CPU FOR NOW - * addRow() ::NOT IMPLEMENTED! This calls addRowFast() which isn't implemented. Implement? Is it supposed to add an extra row to the matrix or add elements of a row to another row in the matrix? - * getElementFast() ::TEST? How to test __cuda_callable__? ONLY TEST ON CPU FOR NOW - * getElement() ::USED! In test_SetElement(), test_AddElement() and test_setRow() to verify the test itself. - * getRowFast() ::TEST? How to test __cuda_callable__? ONLY TEST ON CPU FOR NOW - * MatrixRow getRow() ::TEST? How to test __cuda_callable__? ONLY TEST ON CPU FOR NOW - * ConstMatrixRow getRow() ::TEST? How to test __cuda_callable__? ONLY TEST ON CPU FOR NOW - * rowVectorProduct() ::TEST? How to test __cuda_callable__? ONLY TEST ON CPU FOR NOW - * vectorProduct() ::DONE - * This used to throw illegal memory access, but instead of using ints for vectors, using Types, helped. - * addMatrix() ::NOT IMPLEMENTED! - * getTransposition() ::NOT IMPLMENETED! - * performSORIteration() ::HOW? Throws segmentation fault CUDA. - * operator=() ::HOW? What is this supposed to enable? Overloading operators? - * save( File& file) ::USED! In save( String& fileName ) - * load( File& file ) ::USED! In load( String& fileName ) - * save( String& fileName ) ::DONE - * load( String& fileName ) ::DONE - * print() ::DONE - * setCudaKernelType() ::NOT SUPPOSED TO TEST! via notes from 1.11.2018 supervisor meeting. - * getCudaKernelType() ::NOT SUPPOSED TO TEST! via notes from 1.11.2018 supervisor meeting. - * setCudaWarpSize() ::NOT SUPPOSED TO TEST! via notes from 1.11.2018 supervisor meeting. - * getCudaWarpSize() ::NOT SUPPOSED TO TEST! via notes from 1.11.2018 supervisor meeting. - * setHybridModeSplit() ::NOT SUPPOSED TO TEST! via notes from 1.11.2018 supervisor meeting. - * getHybridModeSplit() ::NOT SUPPOSED TO TEST! via notes from 1.11.2018 supervisor meeting. - * spmvCudaVectorized() ::TEST? How to test __device__? - * vectorProductCuda() ::TEST? How to test __device__? - */ - -// GENERAL TODO -/* - * For every function, EXPECT_EQ needs to be done, even for zeros in matrices. - * Figure out __cuda_callable_. When trying to call __cuda_callable__ functions - * a segmentation fault (core dumped) is thrown. - * ==>__cuda_callable__ works only for CPU at the moment. (for loops vs thread kernel assignment) - */ - #include -#include -#include -#include -#include -#include - -#include +#include "SparseMatrixTest.hpp" #include #ifdef HAVE_GTEST @@ -86,724 +22,6 @@ using CSR_host_int = TNL::Matrices::CSR< int, TNL::Devices::Host, int >; using CSR_cuda_float = TNL::Matrices::CSR< float, TNL::Devices::Cuda, int >; using CSR_cuda_int = TNL::Matrices::CSR< int, TNL::Devices::Cuda, int >; -#ifdef NOT_WORKING -// test fixture for typed tests -template< typename Matrix > -class AdEllpackMatrixTest : public ::testing::Test -{ -protected: - using AdEllpackMatrixType = Matrix; -}; - -// types for which MatrixTest is instantiated -using AdEllpackMatrixTypes = ::testing::Types -< - TNL::Matrices::AdEllpack< int, TNL::Devices::Host, short >, - TNL::Matrices::AdEllpack< long, TNL::Devices::Host, short >, - TNL::Matrices::AdEllpack< float, TNL::Devices::Host, short >, - TNL::Matrices::AdEllpack< double, TNL::Devices::Host, short >, - TNL::Matrices::AdEllpack< int, TNL::Devices::Host, int >, - TNL::Matrices::AdEllpack< long, TNL::Devices::Host, int >, - TNL::Matrices::AdEllpack< float, TNL::Devices::Host, int >, - TNL::Matrices::AdEllpack< double, TNL::Devices::Host, int >, - TNL::Matrices::AdEllpack< int, TNL::Devices::Host, long >, - TNL::Matrices::AdEllpack< long, TNL::Devices::Host, long >, - TNL::Matrices::AdEllpack< float, TNL::Devices::Host, long >, - TNL::Matrices::AdEllpack< double, TNL::Devices::Host, long >, -#ifdef HAVE_CUDA - TNL::Matrices::AdEllpack< int, TNL::Devices::Cuda, short >, - TNL::Matrices::AdEllpack< long, TNL::Devices::Cuda, short >, - TNL::Matrices::AdEllpack< float, TNL::Devices::Cuda, short >, - TNL::Matrices::AdEllpack< double, TNL::Devices::Cuda, short >, - TNL::Matrices::AdEllpack< int, TNL::Devices::Cuda, int >, - TNL::Matrices::AdEllpack< long, TNL::Devices::Cuda, int >, - TNL::Matrices::AdEllpack< float, TNL::Devices::Cuda, int >, - TNL::Matrices::AdEllpack< double, TNL::Devices::Cuda, int >, - TNL::Matrices::AdEllpack< int, TNL::Devices::Cuda, long >, - TNL::Matrices::AdEllpack< long, TNL::Devices::Cuda, long >, - TNL::Matrices::AdEllpack< float, TNL::Devices::Cuda, long >, - TNL::Matrices::AdEllpack< double, TNL::Devices::Cuda, long > -#endif ->; - -TYPED_TEST_CASE( AdEllpackMatrixTest, AdEllpackMatrixTypes); - -TYPED_TEST( AdEllpackMatrixTest, setDimensionsTest ) -{ - using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; - - test_SetDimensions< AdEllpackMatrixType >(); -} - -TYPED_TEST( AdEllpackMatrixTest, setCompressedRowLengthsTest ) -{ -// using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; - -// test_SetCompressedRowLengths< AdEllpackMatrixType >(); - - bool testRan = false; - EXPECT_TRUE( testRan ); - std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; - std::cout << " This test is dependent on the input format. \n"; - std::cout << " Almost every format allocates elements per row differently.\n\n"; - std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; -} - -TYPED_TEST( AdEllpackMatrixTest, setLikeTest ) -{ - using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; - - test_SetLike< AdEllpackMatrixType, AdEllpackMatrixType >(); -} - -TYPED_TEST( AdEllpackMatrixTest, resetTest ) -{ - using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; - - test_Reset< AdEllpackMatrixType >(); -} - -TYPED_TEST( AdEllpackMatrixTest, setElementTest ) -{ - using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; - - test_SetElement< AdEllpackMatrixType >(); -} - -TYPED_TEST( AdEllpackMatrixTest, addElementTest ) -{ - using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; - - test_AddElement< AdEllpackMatrixType >(); -} - -TYPED_TEST( AdEllpackMatrixTest, setRowTest ) -{ - using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; - - test_SetRow< AdEllpackMatrixType >(); -} - -TYPED_TEST( AdEllpackMatrixTest, vectorProductTest ) -{ - using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; - - test_VectorProduct< AdEllpackMatrixType >(); -} - -TYPED_TEST( AdEllpackMatrixTest, saveAndLoadTest ) -{ - using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; - - test_SaveAndLoad< AdEllpackMatrixType >(); -} - -TYPED_TEST( AdEllpackMatrixTest, printTest ) -{ - using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; - - test_Print< AdEllpackMatrixType >(); -} - -// test fixture for typed tests -template< typename Matrix > -class BiEllpackMatrixTest : public ::testing::Test -{ -protected: - using BiEllpackMatrixType = Matrix; -}; - -// types for which MatrixTest is instantiated -using BiEllpackMatrixTypes = ::testing::Types -< - TNL::Matrices::BiEllpack< int, TNL::Devices::Host, short >, - TNL::Matrices::BiEllpack< long, TNL::Devices::Host, short >, - TNL::Matrices::BiEllpack< float, TNL::Devices::Host, short >, - TNL::Matrices::BiEllpack< double, TNL::Devices::Host, short >, - TNL::Matrices::BiEllpack< int, TNL::Devices::Host, int >, - TNL::Matrices::BiEllpack< long, TNL::Devices::Host, int >, - TNL::Matrices::BiEllpack< float, TNL::Devices::Host, int >, - TNL::Matrices::BiEllpack< double, TNL::Devices::Host, int >, - TNL::Matrices::BiEllpack< int, TNL::Devices::Host, long >, - TNL::Matrices::BiEllpack< long, TNL::Devices::Host, long >, - TNL::Matrices::BiEllpack< float, TNL::Devices::Host, long >, - TNL::Matrices::BiEllpack< double, TNL::Devices::Host, long >//, -//#ifdef HAVE_CUDA -// TNL::Matrices::BiEllpack< int, TNL::Devices::Cuda, short >, -// TNL::Matrices::BiEllpack< long, TNL::Devices::Cuda, short >, -// TNL::Matrices::BiEllpack< float, TNL::Devices::Cuda, short >, -// TNL::Matrices::BiEllpack< double, TNL::Devices::Cuda, short >, -// TNL::Matrices::BiEllpack< int, TNL::Devices::Cuda, int >, -// TNL::Matrices::BiEllpack< long, TNL::Devices::Cuda, int >, -// TNL::Matrices::BiEllpack< float, TNL::Devices::Cuda, int >, -// TNL::Matrices::BiEllpack< double, TNL::Devices::Cuda, int >, -// TNL::Matrices::BiEllpack< int, TNL::Devices::Cuda, long >, -// TNL::Matrices::BiEllpack< long, TNL::Devices::Cuda, long >, -// TNL::Matrices::BiEllpack< float, TNL::Devices::Cuda, long >, -// TNL::Matrices::BiEllpack< double, TNL::Devices::Cuda, long > -//#endif ->; - -TYPED_TEST_CASE( BiEllpackMatrixTest, BiEllpackMatrixTypes); - -TYPED_TEST( BiEllpackMatrixTest, setDimensionsTest ) -{ - using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; - - test_SetDimensions< BiEllpackMatrixType >(); -} - -TYPED_TEST( BiEllpackMatrixTest, setCompressedRowLengthsTest ) -{ -// using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; - -// test_SetCompressedRowLengths< BiEllpackMatrixType >(); - - bool testRan = false; - EXPECT_TRUE( testRan ); - std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; - std::cout << " This test is dependent on the input format. \n"; - std::cout << " Almost every format allocates elements per row differently.\n\n"; - std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; -} - -TYPED_TEST( BiEllpackMatrixTest, setLikeTest ) -{ - using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; - - test_SetLike< BiEllpackMatrixType, BiEllpackMatrixType >(); -} - -TYPED_TEST( BiEllpackMatrixTest, resetTest ) -{ - using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; - - test_Reset< BiEllpackMatrixType >(); -} - -TYPED_TEST( BiEllpackMatrixTest, setElementTest ) -{ - using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; - - test_SetElement< BiEllpackMatrixType >(); -} - -TYPED_TEST( BiEllpackMatrixTest, addElementTest ) -{ - using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; - - test_AddElement< BiEllpackMatrixType >(); -} - -TYPED_TEST( BiEllpackMatrixTest, setRowTest ) -{ - using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; - - test_SetRow< BiEllpackMatrixType >(); -} - -TYPED_TEST( BiEllpackMatrixTest, vectorProductTest ) -{ - using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; - - test_VectorProduct< BiEllpackMatrixType >(); -} - -TYPED_TEST( BiEllpackMatrixTest, saveAndLoadTest ) -{ - using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; - - test_SaveAndLoad< BiEllpackMatrixType >(); -} - -TYPED_TEST( BiEllpackMatrixTest, printTest ) -{ - using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; - - test_Print< BiEllpackMatrixType >(); -} - -#endif - -// GTEST ::testing::Types<> has a limit of 38. - -// test fixture for typed tests -template< typename Matrix > -class ChunkedEllpackMatrixTest : public ::testing::Test -{ -protected: - using ChunkedEllpackMatrixType = Matrix; -}; - -// columnIndexes of ChunkedEllpack appear to be broken, when printed, it prints out a bunch of 4s. -// rowPointers have interesting elements? 0 18 36 42 54 72 96 126 162 204 256 when rows = 10, cols = 11; rowLengths = 3 3 1 2 3 4 5 6 7 8 -// and 0 52 103 154 205 256 when rows = 5, cols = 4; rowLengths = 3 3 3 3 3 - - -// types for which MatrixTest is instantiated -using ChEllpackMatrixTypes = ::testing::Types -< - TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Host, short >, - TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Host, short >, - TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Host, short >, - TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Host, short >, - TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Host, int >, - TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Host, int >, - TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Host, int >, - TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Host, int >, - TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Host, long >, - TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Host, long >, - TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Host, long >, - TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Host, long > -#ifdef HAVE_CUDA - ,TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Cuda, short >, - TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Cuda, short >, - TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Cuda, short >, - TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Cuda, short >, - TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Cuda, int >, - TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Cuda, int >, - TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Cuda, int >, - TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Cuda, int >, - TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Cuda, long >, - TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Cuda, long >, - TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Cuda, long >, - TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Cuda, long > -#endif ->; - -TYPED_TEST_CASE( ChunkedEllpackMatrixTest, ChEllpackMatrixTypes); - -TYPED_TEST( ChunkedEllpackMatrixTest, setDimensionsTest ) -{ - using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; - - test_SetDimensions< ChunkedEllpackMatrixType >(); -} - -//TYPED_TEST( ChunkedEllpackMatrixTest, setCompressedRowLengthsTest ) -//{ -//// using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; -// -//// test_SetCompressedRowLengths< ChunkedEllpackMatrixType >(); -// -// bool testRan = false; -// EXPECT_TRUE( testRan ); -// std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; -// std::cout << " This test is dependent on the input format. \n"; -// std::cout << " Almost every format allocates elements per row differently.\n\n"; -// std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; -//} - -TYPED_TEST( ChunkedEllpackMatrixTest, setLikeTest ) -{ - using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; - - test_SetLike< ChunkedEllpackMatrixType, ChunkedEllpackMatrixType >(); -} - -TYPED_TEST( ChunkedEllpackMatrixTest, resetTest ) -{ - using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; - - test_Reset< ChunkedEllpackMatrixType >(); -} - -TYPED_TEST( ChunkedEllpackMatrixTest, setElementTest ) -{ - using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; - - test_SetElement< ChunkedEllpackMatrixType >(); -} - -TYPED_TEST( ChunkedEllpackMatrixTest, addElementTest ) -{ - using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; - - test_AddElement< ChunkedEllpackMatrixType >(); -} - -TYPED_TEST( ChunkedEllpackMatrixTest, setRowTest ) -{ - using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; - - test_SetRow< ChunkedEllpackMatrixType >(); -} - -TYPED_TEST( ChunkedEllpackMatrixTest, vectorProductTest ) -{ - using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; - - test_VectorProduct< ChunkedEllpackMatrixType >(); -} - -TYPED_TEST( ChunkedEllpackMatrixTest, saveAndLoadTest ) -{ - using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; - - test_SaveAndLoad< ChunkedEllpackMatrixType >(); -} - -TYPED_TEST( ChunkedEllpackMatrixTest, printTest ) -{ - using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; - - test_Print< ChunkedEllpackMatrixType >(); -} - -// test fixture for typed tests -template< typename Matrix > -class CSRMatrixTest : public ::testing::Test -{ -protected: - using CSRMatrixType = Matrix; -}; - -// types for which MatrixTest is instantiated -using CSRMatrixTypes = ::testing::Types -< - TNL::Matrices::CSR< int, TNL::Devices::Host, short >, - TNL::Matrices::CSR< long, TNL::Devices::Host, short >, - TNL::Matrices::CSR< float, TNL::Devices::Host, short >, - TNL::Matrices::CSR< double, TNL::Devices::Host, short >, - TNL::Matrices::CSR< int, TNL::Devices::Host, int >, - TNL::Matrices::CSR< long, TNL::Devices::Host, int >, - TNL::Matrices::CSR< float, TNL::Devices::Host, int >, - TNL::Matrices::CSR< double, TNL::Devices::Host, int >, - TNL::Matrices::CSR< int, TNL::Devices::Host, long >, - TNL::Matrices::CSR< long, TNL::Devices::Host, long >, - TNL::Matrices::CSR< float, TNL::Devices::Host, long >, - TNL::Matrices::CSR< double, TNL::Devices::Host, long > -#ifdef HAVE_CUDA - ,TNL::Matrices::CSR< int, TNL::Devices::Cuda, short >, - TNL::Matrices::CSR< long, TNL::Devices::Cuda, short >, - TNL::Matrices::CSR< float, TNL::Devices::Cuda, short >, - TNL::Matrices::CSR< double, TNL::Devices::Cuda, short >, - TNL::Matrices::CSR< int, TNL::Devices::Cuda, int >, - TNL::Matrices::CSR< long, TNL::Devices::Cuda, int >, - TNL::Matrices::CSR< float, TNL::Devices::Cuda, int >, - TNL::Matrices::CSR< double, TNL::Devices::Cuda, int >, - TNL::Matrices::CSR< int, TNL::Devices::Cuda, long >, - TNL::Matrices::CSR< long, TNL::Devices::Cuda, long >, - TNL::Matrices::CSR< float, TNL::Devices::Cuda, long >, - TNL::Matrices::CSR< double, TNL::Devices::Cuda, long > -#endif ->; - -TYPED_TEST_CASE( CSRMatrixTest, CSRMatrixTypes); - -TYPED_TEST( CSRMatrixTest, setDimensionsTest ) -{ - using CSRMatrixType = typename TestFixture::CSRMatrixType; - - test_SetDimensions< CSRMatrixType >(); -} - -//TYPED_TEST( CSRMatrixTest, setCompressedRowLengthsTest ) -//{ -//// using CSRMatrixType = typename TestFixture::CSRMatrixType; -// -//// test_SetCompressedRowLengths< CSRMatrixType >(); -// -// bool testRan = false; -// EXPECT_TRUE( testRan ); -// std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; -// std::cout << " This test is dependent on the input format. \n"; -// std::cout << " Almost every format allocates elements per row differently.\n\n"; -// std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; -//} - -TYPED_TEST( CSRMatrixTest, setLikeTest ) -{ - using CSRMatrixType = typename TestFixture::CSRMatrixType; - - test_SetLike< CSRMatrixType, CSRMatrixType >(); -} - -TYPED_TEST( CSRMatrixTest, resetTest ) -{ - using CSRMatrixType = typename TestFixture::CSRMatrixType; - - test_Reset< CSRMatrixType >(); -} - -TYPED_TEST( CSRMatrixTest, setElementTest ) -{ - using CSRMatrixType = typename TestFixture::CSRMatrixType; - - test_SetElement< CSRMatrixType >(); -} - -TYPED_TEST( CSRMatrixTest, addElementTest ) -{ - using CSRMatrixType = typename TestFixture::CSRMatrixType; - - test_AddElement< CSRMatrixType >(); -} - -TYPED_TEST( CSRMatrixTest, setRowTest ) -{ - using CSRMatrixType = typename TestFixture::CSRMatrixType; - - test_SetRow< CSRMatrixType >(); -} - -TYPED_TEST( CSRMatrixTest, vectorProductTest ) -{ - using CSRMatrixType = typename TestFixture::CSRMatrixType; - - test_VectorProduct< CSRMatrixType >(); -} - -TYPED_TEST( CSRMatrixTest, saveAndLoadTest ) -{ - using CSRMatrixType = typename TestFixture::CSRMatrixType; - - test_SaveAndLoad< CSRMatrixType >(); -} - -TYPED_TEST( CSRMatrixTest, printTest ) -{ - using CSRMatrixType = typename TestFixture::CSRMatrixType; - - test_Print< CSRMatrixType >(); -} - -// test fixture for typed tests -template< typename Matrix > -class EllpackMatrixTest : public ::testing::Test -{ -protected: - using EllpackMatrixType = Matrix; -}; - -// types for which MatrixTest is instantiated -using EllpackMatrixTypes = ::testing::Types -< - TNL::Matrices::Ellpack< int, TNL::Devices::Host, short >, - TNL::Matrices::Ellpack< long, TNL::Devices::Host, short >, - TNL::Matrices::Ellpack< float, TNL::Devices::Host, short >, - TNL::Matrices::Ellpack< double, TNL::Devices::Host, short >, - TNL::Matrices::Ellpack< int, TNL::Devices::Host, int >, - TNL::Matrices::Ellpack< long, TNL::Devices::Host, int >, - TNL::Matrices::Ellpack< float, TNL::Devices::Host, int >, - TNL::Matrices::Ellpack< double, TNL::Devices::Host, int >, - TNL::Matrices::Ellpack< int, TNL::Devices::Host, long >, - TNL::Matrices::Ellpack< long, TNL::Devices::Host, long >, - TNL::Matrices::Ellpack< float, TNL::Devices::Host, long >, - TNL::Matrices::Ellpack< double, TNL::Devices::Host, long > -#ifdef HAVE_CUDA - ,TNL::Matrices::Ellpack< int, TNL::Devices::Cuda, short >, - TNL::Matrices::Ellpack< long, TNL::Devices::Cuda, short >, - TNL::Matrices::Ellpack< float, TNL::Devices::Cuda, short >, - TNL::Matrices::Ellpack< double, TNL::Devices::Cuda, short >, - TNL::Matrices::Ellpack< int, TNL::Devices::Cuda, int >, - TNL::Matrices::Ellpack< long, TNL::Devices::Cuda, int >, - TNL::Matrices::Ellpack< float, TNL::Devices::Cuda, int >, - TNL::Matrices::Ellpack< double, TNL::Devices::Cuda, int >, - TNL::Matrices::Ellpack< int, TNL::Devices::Cuda, long >, - TNL::Matrices::Ellpack< long, TNL::Devices::Cuda, long >, - TNL::Matrices::Ellpack< float, TNL::Devices::Cuda, long >, - TNL::Matrices::Ellpack< double, TNL::Devices::Cuda, long > -#endif ->; - -TYPED_TEST_CASE( EllpackMatrixTest, EllpackMatrixTypes ); - -TYPED_TEST( EllpackMatrixTest, setDimensionsTest ) -{ - using EllpackMatrixType = typename TestFixture::EllpackMatrixType; - - test_SetDimensions< EllpackMatrixType >(); -} - -//TYPED_TEST( EllpackMatrixTest, setCompressedRowLengthsTest ) -//{ -//// using EllpackMatrixType = typename TestFixture::EllpackMatrixType; -// -//// test_SetCompressedRowLengths< EllpackMatrixType >(); -// -// bool testRan = false; -// EXPECT_TRUE( testRan ); -// std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; -// std::cout << " This test is dependent on the input format. \n"; -// std::cout << " Almost every format allocates elements per row differently.\n\n"; -// std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; -//} - -TYPED_TEST( EllpackMatrixTest, setLikeTest ) -{ - using EllpackMatrixType = typename TestFixture::EllpackMatrixType; - - test_SetLike< EllpackMatrixType, EllpackMatrixType >(); -} - -TYPED_TEST( EllpackMatrixTest, resetTest ) -{ - using EllpackMatrixType = typename TestFixture::EllpackMatrixType; - - test_Reset< EllpackMatrixType >(); -} - -TYPED_TEST( EllpackMatrixTest, setElementTest ) -{ - using EllpackMatrixType = typename TestFixture::EllpackMatrixType; - - test_SetElement< EllpackMatrixType >(); -} - -TYPED_TEST( EllpackMatrixTest, addElementTest ) -{ - using EllpackMatrixType = typename TestFixture::EllpackMatrixType; - - test_AddElement< EllpackMatrixType >(); -} - -TYPED_TEST( EllpackMatrixTest, setRowTest ) -{ - using EllpackMatrixType = typename TestFixture::EllpackMatrixType; - - test_SetRow< EllpackMatrixType >(); -} - -TYPED_TEST( EllpackMatrixTest, vectorProductTest ) -{ - using EllpackMatrixType = typename TestFixture::EllpackMatrixType; - - test_VectorProduct< EllpackMatrixType >(); -} - -TYPED_TEST( EllpackMatrixTest, saveAndLoadTest ) -{ - using EllpackMatrixType = typename TestFixture::EllpackMatrixType; - - test_SaveAndLoad< EllpackMatrixType >(); -} - -TYPED_TEST( EllpackMatrixTest, printTest ) -{ - using EllpackMatrixType = typename TestFixture::EllpackMatrixType; - - test_Print< EllpackMatrixType >(); -} - -// test fixture for typed tests -template< typename Matrix > -class SlicedEllpackMatrixTest : public ::testing::Test -{ -protected: - using SlicedEllpackMatrixType = Matrix; -}; - -// types for which MatrixTest is instantiated -using SlicedEllpackMatrixTypes = ::testing::Types -< - TNL::Matrices::SlicedEllpack< int, TNL::Devices::Host, short >, - TNL::Matrices::SlicedEllpack< long, TNL::Devices::Host, short >, - TNL::Matrices::SlicedEllpack< float, TNL::Devices::Host, short >, - TNL::Matrices::SlicedEllpack< double, TNL::Devices::Host, short >, - TNL::Matrices::SlicedEllpack< int, TNL::Devices::Host, int >, - TNL::Matrices::SlicedEllpack< long, TNL::Devices::Host, int >, - TNL::Matrices::SlicedEllpack< float, TNL::Devices::Host, int >, - TNL::Matrices::SlicedEllpack< double, TNL::Devices::Host, int >, - TNL::Matrices::SlicedEllpack< int, TNL::Devices::Host, long >, - TNL::Matrices::SlicedEllpack< long, TNL::Devices::Host, long >, - TNL::Matrices::SlicedEllpack< float, TNL::Devices::Host, long >, - TNL::Matrices::SlicedEllpack< double, TNL::Devices::Host, long > -#ifdef HAVE_CUDA - ,TNL::Matrices::SlicedEllpack< int, TNL::Devices::Cuda, short >, - TNL::Matrices::SlicedEllpack< long, TNL::Devices::Cuda, short >, - TNL::Matrices::SlicedEllpack< float, TNL::Devices::Cuda, short >, - TNL::Matrices::SlicedEllpack< double, TNL::Devices::Cuda, short >, - TNL::Matrices::SlicedEllpack< int, TNL::Devices::Cuda, int >, - TNL::Matrices::SlicedEllpack< long, TNL::Devices::Cuda, int >, - TNL::Matrices::SlicedEllpack< float, TNL::Devices::Cuda, int >, - TNL::Matrices::SlicedEllpack< double, TNL::Devices::Cuda, int >, - TNL::Matrices::SlicedEllpack< int, TNL::Devices::Cuda, long >, - TNL::Matrices::SlicedEllpack< long, TNL::Devices::Cuda, long >, - TNL::Matrices::SlicedEllpack< float, TNL::Devices::Cuda, long >, - TNL::Matrices::SlicedEllpack< double, TNL::Devices::Cuda, long > -#endif ->; - -TYPED_TEST_CASE( SlicedEllpackMatrixTest, SlicedEllpackMatrixTypes ); - -TYPED_TEST( SlicedEllpackMatrixTest, setDimensionsTest ) -{ - using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; - - test_SetDimensions< SlicedEllpackMatrixType >(); -} - -//TYPED_TEST( SlicedEllpackMatrixTest, setCompressedRowLengthsTest ) -//{ -//// using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; -// -//// test_SetCompressedRowLengths< SlicedEllpackMatrixType >(); -// -// bool testRan = false; -// EXPECT_TRUE( testRan ); -// std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; -// std::cout << " This test is dependent on the input format. \n"; -// std::cout << " Almost every format allocates elements per row differently.\n\n"; -// std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; -//} - -TYPED_TEST( SlicedEllpackMatrixTest, setLikeTest ) -{ - using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; - - test_SetLike< SlicedEllpackMatrixType, SlicedEllpackMatrixType >(); -} - -TYPED_TEST( SlicedEllpackMatrixTest, resetTest ) -{ - using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; - - test_Reset< SlicedEllpackMatrixType >(); -} - -TYPED_TEST( SlicedEllpackMatrixTest, setElementTest ) -{ - using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; - - test_SetElement< SlicedEllpackMatrixType >(); -} - -TYPED_TEST( SlicedEllpackMatrixTest, addElementTest ) -{ - using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; - - test_AddElement< SlicedEllpackMatrixType >(); -} - -TYPED_TEST( SlicedEllpackMatrixTest, setRowTest ) -{ - using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; - - test_SetRow< SlicedEllpackMatrixType >(); -} - -TYPED_TEST( SlicedEllpackMatrixTest, vectorProductTest ) -{ - using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; - - test_VectorProduct< SlicedEllpackMatrixType >(); -} - -TYPED_TEST( SlicedEllpackMatrixTest, saveAndLoadTest ) -{ - using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; - - test_SaveAndLoad< SlicedEllpackMatrixType >(); -} - -TYPED_TEST( SlicedEllpackMatrixTest, printTest ) -{ - using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; - - test_Print< SlicedEllpackMatrixType >(); -} - //// test_getType is not general enough yet. DO NOT TEST IT YET. //TEST( SparseMatrixTest, CSR_GetTypeTest_Host ) @@ -841,4 +59,4 @@ int main( int argc, char* argv[] ) #else throw GtestMissingError(); #endif -} \ No newline at end of file +} diff --git a/src/UnitTests/Matrices/SparseMatrixTest_impl.h b/src/UnitTests/Matrices/SparseMatrixTest.hpp similarity index 100% rename from src/UnitTests/Matrices/SparseMatrixTest_impl.h rename to src/UnitTests/Matrices/SparseMatrixTest.hpp diff --git a/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.cpp b/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.cpp new file mode 100644 index 000000000..563a3dc26 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.cpp @@ -0,0 +1 @@ +#include "SparseMatrixTest_AdEllpack.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.cu b/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.cu new file mode 100644 index 000000000..563a3dc26 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.cu @@ -0,0 +1 @@ +#include "SparseMatrixTest_AdEllpack.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.h b/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.h new file mode 100644 index 000000000..24b4db1b2 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_AdEllpack.h @@ -0,0 +1,151 @@ +/*************************************************************************** + SparseMatrixTest_AdEllpack.h - description + ------------------- + begin : Nov 2, 2018 + copyright : (C) 2018 by Tomas Oberhuber et al. + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#include + +#include "SparseMatrixTest.hpp" +#include + +#ifdef HAVE_GTEST +#include + +#ifdef NOT_WORKING +// test fixture for typed tests +template< typename Matrix > +class AdEllpackMatrixTest : public ::testing::Test +{ +protected: + using AdEllpackMatrixType = Matrix; +}; + +// types for which MatrixTest is instantiated +using AdEllpackMatrixTypes = ::testing::Types +< + TNL::Matrices::AdEllpack< int, TNL::Devices::Host, short >, + TNL::Matrices::AdEllpack< long, TNL::Devices::Host, short >, + TNL::Matrices::AdEllpack< float, TNL::Devices::Host, short >, + TNL::Matrices::AdEllpack< double, TNL::Devices::Host, short >, + TNL::Matrices::AdEllpack< int, TNL::Devices::Host, int >, + TNL::Matrices::AdEllpack< long, TNL::Devices::Host, int >, + TNL::Matrices::AdEllpack< float, TNL::Devices::Host, int >, + TNL::Matrices::AdEllpack< double, TNL::Devices::Host, int >, + TNL::Matrices::AdEllpack< int, TNL::Devices::Host, long >, + TNL::Matrices::AdEllpack< long, TNL::Devices::Host, long >, + TNL::Matrices::AdEllpack< float, TNL::Devices::Host, long >, + TNL::Matrices::AdEllpack< double, TNL::Devices::Host, long >, +#ifdef HAVE_CUDA + TNL::Matrices::AdEllpack< int, TNL::Devices::Cuda, short >, + TNL::Matrices::AdEllpack< long, TNL::Devices::Cuda, short >, + TNL::Matrices::AdEllpack< float, TNL::Devices::Cuda, short >, + TNL::Matrices::AdEllpack< double, TNL::Devices::Cuda, short >, + TNL::Matrices::AdEllpack< int, TNL::Devices::Cuda, int >, + TNL::Matrices::AdEllpack< long, TNL::Devices::Cuda, int >, + TNL::Matrices::AdEllpack< float, TNL::Devices::Cuda, int >, + TNL::Matrices::AdEllpack< double, TNL::Devices::Cuda, int >, + TNL::Matrices::AdEllpack< int, TNL::Devices::Cuda, long >, + TNL::Matrices::AdEllpack< long, TNL::Devices::Cuda, long >, + TNL::Matrices::AdEllpack< float, TNL::Devices::Cuda, long >, + TNL::Matrices::AdEllpack< double, TNL::Devices::Cuda, long > +#endif +>; + +TYPED_TEST_CASE( AdEllpackMatrixTest, AdEllpackMatrixTypes); + +TYPED_TEST( AdEllpackMatrixTest, setDimensionsTest ) +{ + using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; + + test_SetDimensions< AdEllpackMatrixType >(); +} + +TYPED_TEST( AdEllpackMatrixTest, setCompressedRowLengthsTest ) +{ +// using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; + +// test_SetCompressedRowLengths< AdEllpackMatrixType >(); + + bool testRan = false; + EXPECT_TRUE( testRan ); + std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; + std::cout << " This test is dependent on the input format. \n"; + std::cout << " Almost every format allocates elements per row differently.\n\n"; + std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; +} + +TYPED_TEST( AdEllpackMatrixTest, setLikeTest ) +{ + using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; + + test_SetLike< AdEllpackMatrixType, AdEllpackMatrixType >(); +} + +TYPED_TEST( AdEllpackMatrixTest, resetTest ) +{ + using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; + + test_Reset< AdEllpackMatrixType >(); +} + +TYPED_TEST( AdEllpackMatrixTest, setElementTest ) +{ + using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; + + test_SetElement< AdEllpackMatrixType >(); +} + +TYPED_TEST( AdEllpackMatrixTest, addElementTest ) +{ + using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; + + test_AddElement< AdEllpackMatrixType >(); +} + +TYPED_TEST( AdEllpackMatrixTest, setRowTest ) +{ + using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; + + test_SetRow< AdEllpackMatrixType >(); +} + +TYPED_TEST( AdEllpackMatrixTest, vectorProductTest ) +{ + using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; + + test_VectorProduct< AdEllpackMatrixType >(); +} + +TYPED_TEST( AdEllpackMatrixTest, saveAndLoadTest ) +{ + using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; + + test_SaveAndLoad< AdEllpackMatrixType >(); +} + +TYPED_TEST( AdEllpackMatrixTest, printTest ) +{ + using AdEllpackMatrixType = typename TestFixture::AdEllpackMatrixType; + + test_Print< AdEllpackMatrixType >(); +} +#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 +} diff --git a/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.cpp b/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.cpp new file mode 100644 index 000000000..ccb62e4a8 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.cpp @@ -0,0 +1 @@ +#include "SparseMatrixTest_BiEllpack.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.cu b/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.cu new file mode 100644 index 000000000..ccb62e4a8 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.cu @@ -0,0 +1 @@ +#include "SparseMatrixTest_BiEllpack.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.h b/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.h new file mode 100644 index 000000000..a18e7cc52 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_BiEllpack.h @@ -0,0 +1,150 @@ +/*************************************************************************** + SparseMatrixTest_BiEllpack.h - description + ------------------- + begin : Nov 2, 2018 + copyright : (C) 2018 by Tomas Oberhuber et al. + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#include + +#include "SparseMatrixTest.hpp" +#include + +#ifdef HAVE_GTEST +#include + +#ifdef NOT_WORKING +// test fixture for typed tests +template< typename Matrix > +class BiEllpackMatrixTest : public ::testing::Test +{ +protected: + using BiEllpackMatrixType = Matrix; +}; + +// types for which MatrixTest is instantiated +using BiEllpackMatrixTypes = ::testing::Types +< + TNL::Matrices::BiEllpack< int, TNL::Devices::Host, short >, + TNL::Matrices::BiEllpack< long, TNL::Devices::Host, short >, + TNL::Matrices::BiEllpack< float, TNL::Devices::Host, short >, + TNL::Matrices::BiEllpack< double, TNL::Devices::Host, short >, + TNL::Matrices::BiEllpack< int, TNL::Devices::Host, int >, + TNL::Matrices::BiEllpack< long, TNL::Devices::Host, int >, + TNL::Matrices::BiEllpack< float, TNL::Devices::Host, int >, + TNL::Matrices::BiEllpack< double, TNL::Devices::Host, int >, + TNL::Matrices::BiEllpack< int, TNL::Devices::Host, long >, + TNL::Matrices::BiEllpack< long, TNL::Devices::Host, long >, + TNL::Matrices::BiEllpack< float, TNL::Devices::Host, long >, + TNL::Matrices::BiEllpack< double, TNL::Devices::Host, long >//, +//#ifdef HAVE_CUDA +// TNL::Matrices::BiEllpack< int, TNL::Devices::Cuda, short >, +// TNL::Matrices::BiEllpack< long, TNL::Devices::Cuda, short >, +// TNL::Matrices::BiEllpack< float, TNL::Devices::Cuda, short >, +// TNL::Matrices::BiEllpack< double, TNL::Devices::Cuda, short >, +// TNL::Matrices::BiEllpack< int, TNL::Devices::Cuda, int >, +// TNL::Matrices::BiEllpack< long, TNL::Devices::Cuda, int >, +// TNL::Matrices::BiEllpack< float, TNL::Devices::Cuda, int >, +// TNL::Matrices::BiEllpack< double, TNL::Devices::Cuda, int >, +// TNL::Matrices::BiEllpack< int, TNL::Devices::Cuda, long >, +// TNL::Matrices::BiEllpack< long, TNL::Devices::Cuda, long >, +// TNL::Matrices::BiEllpack< float, TNL::Devices::Cuda, long >, +// TNL::Matrices::BiEllpack< double, TNL::Devices::Cuda, long > +//#endif +>; + +TYPED_TEST_CASE( BiEllpackMatrixTest, BiEllpackMatrixTypes); + +TYPED_TEST( BiEllpackMatrixTest, setDimensionsTest ) +{ + using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; + + test_SetDimensions< BiEllpackMatrixType >(); +} + +TYPED_TEST( BiEllpackMatrixTest, setCompressedRowLengthsTest ) +{ +// using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; + +// test_SetCompressedRowLengths< BiEllpackMatrixType >(); + + bool testRan = false; + EXPECT_TRUE( testRan ); + std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; + std::cout << " This test is dependent on the input format. \n"; + std::cout << " Almost every format allocates elements per row differently.\n\n"; + std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; +} + +TYPED_TEST( BiEllpackMatrixTest, setLikeTest ) +{ + using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; + + test_SetLike< BiEllpackMatrixType, BiEllpackMatrixType >(); +} + +TYPED_TEST( BiEllpackMatrixTest, resetTest ) +{ + using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; + + test_Reset< BiEllpackMatrixType >(); +} + +TYPED_TEST( BiEllpackMatrixTest, setElementTest ) +{ + using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; + + test_SetElement< BiEllpackMatrixType >(); +} + +TYPED_TEST( BiEllpackMatrixTest, addElementTest ) +{ + using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; + + test_AddElement< BiEllpackMatrixType >(); +} + +TYPED_TEST( BiEllpackMatrixTest, setRowTest ) +{ + using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; + + test_SetRow< BiEllpackMatrixType >(); +} + +TYPED_TEST( BiEllpackMatrixTest, vectorProductTest ) +{ + using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; + + test_VectorProduct< BiEllpackMatrixType >(); +} + +TYPED_TEST( BiEllpackMatrixTest, saveAndLoadTest ) +{ + using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; + + test_SaveAndLoad< BiEllpackMatrixType >(); +} + +TYPED_TEST( BiEllpackMatrixTest, printTest ) +{ + using BiEllpackMatrixType = typename TestFixture::BiEllpackMatrixType; + + test_Print< BiEllpackMatrixType >(); +} +#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 +} diff --git a/src/UnitTests/Matrices/SparseMatrixTest_CSR.cpp b/src/UnitTests/Matrices/SparseMatrixTest_CSR.cpp new file mode 100644 index 000000000..258ad2c53 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_CSR.cpp @@ -0,0 +1 @@ +#include "SparseMatrixTest_CSR.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_CSR.cu b/src/UnitTests/Matrices/SparseMatrixTest_CSR.cu new file mode 100644 index 000000000..258ad2c53 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_CSR.cu @@ -0,0 +1 @@ +#include "SparseMatrixTest_CSR.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_CSR.h b/src/UnitTests/Matrices/SparseMatrixTest_CSR.h new file mode 100644 index 000000000..2eaecc76e --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_CSR.h @@ -0,0 +1,148 @@ +/*************************************************************************** + SparseMatrixTest_CSR.h - description + ------------------- + begin : Nov 2, 2018 + copyright : (C) 2018 by Tomas Oberhuber et al. + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#include + +#include "SparseMatrixTest.hpp" +#include + +#ifdef HAVE_GTEST +#include + +// test fixture for typed tests +template< typename Matrix > +class CSRMatrixTest : public ::testing::Test +{ +protected: + using CSRMatrixType = Matrix; +}; + +// types for which MatrixTest is instantiated +using CSRMatrixTypes = ::testing::Types +< + TNL::Matrices::CSR< int, TNL::Devices::Host, short >, + TNL::Matrices::CSR< long, TNL::Devices::Host, short >, + TNL::Matrices::CSR< float, TNL::Devices::Host, short >, + TNL::Matrices::CSR< double, TNL::Devices::Host, short >, + TNL::Matrices::CSR< int, TNL::Devices::Host, int >, + TNL::Matrices::CSR< long, TNL::Devices::Host, int >, + TNL::Matrices::CSR< float, TNL::Devices::Host, int >, + TNL::Matrices::CSR< double, TNL::Devices::Host, int >, + TNL::Matrices::CSR< int, TNL::Devices::Host, long >, + TNL::Matrices::CSR< long, TNL::Devices::Host, long >, + TNL::Matrices::CSR< float, TNL::Devices::Host, long >, + TNL::Matrices::CSR< double, TNL::Devices::Host, long > +#ifdef HAVE_CUDA + ,TNL::Matrices::CSR< int, TNL::Devices::Cuda, short >, + TNL::Matrices::CSR< long, TNL::Devices::Cuda, short >, + TNL::Matrices::CSR< float, TNL::Devices::Cuda, short >, + TNL::Matrices::CSR< double, TNL::Devices::Cuda, short >, + TNL::Matrices::CSR< int, TNL::Devices::Cuda, int >, + TNL::Matrices::CSR< long, TNL::Devices::Cuda, int >, + TNL::Matrices::CSR< float, TNL::Devices::Cuda, int >, + TNL::Matrices::CSR< double, TNL::Devices::Cuda, int >, + TNL::Matrices::CSR< int, TNL::Devices::Cuda, long >, + TNL::Matrices::CSR< long, TNL::Devices::Cuda, long >, + TNL::Matrices::CSR< float, TNL::Devices::Cuda, long >, + TNL::Matrices::CSR< double, TNL::Devices::Cuda, long > +#endif +>; + +TYPED_TEST_CASE( CSRMatrixTest, CSRMatrixTypes); + +TYPED_TEST( CSRMatrixTest, setDimensionsTest ) +{ + using CSRMatrixType = typename TestFixture::CSRMatrixType; + + test_SetDimensions< CSRMatrixType >(); +} + +//TYPED_TEST( CSRMatrixTest, setCompressedRowLengthsTest ) +//{ +//// using CSRMatrixType = typename TestFixture::CSRMatrixType; +// +//// test_SetCompressedRowLengths< CSRMatrixType >(); +// +// bool testRan = false; +// EXPECT_TRUE( testRan ); +// std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; +// std::cout << " This test is dependent on the input format. \n"; +// std::cout << " Almost every format allocates elements per row differently.\n\n"; +// std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; +//} + +TYPED_TEST( CSRMatrixTest, setLikeTest ) +{ + using CSRMatrixType = typename TestFixture::CSRMatrixType; + + test_SetLike< CSRMatrixType, CSRMatrixType >(); +} + +TYPED_TEST( CSRMatrixTest, resetTest ) +{ + using CSRMatrixType = typename TestFixture::CSRMatrixType; + + test_Reset< CSRMatrixType >(); +} + +TYPED_TEST( CSRMatrixTest, setElementTest ) +{ + using CSRMatrixType = typename TestFixture::CSRMatrixType; + + test_SetElement< CSRMatrixType >(); +} + +TYPED_TEST( CSRMatrixTest, addElementTest ) +{ + using CSRMatrixType = typename TestFixture::CSRMatrixType; + + test_AddElement< CSRMatrixType >(); +} + +TYPED_TEST( CSRMatrixTest, setRowTest ) +{ + using CSRMatrixType = typename TestFixture::CSRMatrixType; + + test_SetRow< CSRMatrixType >(); +} + +TYPED_TEST( CSRMatrixTest, vectorProductTest ) +{ + using CSRMatrixType = typename TestFixture::CSRMatrixType; + + test_VectorProduct< CSRMatrixType >(); +} + +TYPED_TEST( CSRMatrixTest, saveAndLoadTest ) +{ + using CSRMatrixType = typename TestFixture::CSRMatrixType; + + test_SaveAndLoad< CSRMatrixType >(); +} + +TYPED_TEST( CSRMatrixTest, printTest ) +{ + using CSRMatrixType = typename TestFixture::CSRMatrixType; + + test_Print< CSRMatrixType >(); +} + +#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 +} diff --git a/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cpp b/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cpp new file mode 100644 index 000000000..c09609ae6 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cpp @@ -0,0 +1 @@ +#include "SparseMatrixTest_ChunkedEllpack.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cu b/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cu new file mode 100644 index 000000000..c09609ae6 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cu @@ -0,0 +1 @@ +#include "SparseMatrixTest_ChunkedEllpack.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.h b/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.h new file mode 100644 index 000000000..99ad9f0b4 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.h @@ -0,0 +1,153 @@ +/*************************************************************************** + SparseMatrixTest_ChunkedEllpack.h - description + ------------------- + begin : Nov 2, 2018 + copyright : (C) 2018 by Tomas Oberhuber et al. + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#include + +#include "SparseMatrixTest.hpp" +#include + +#ifdef HAVE_GTEST +#include + +// test fixture for typed tests +template< typename Matrix > +class ChunkedEllpackMatrixTest : public ::testing::Test +{ +protected: + using ChunkedEllpackMatrixType = Matrix; +}; + +// columnIndexes of ChunkedEllpack appear to be broken, when printed, it prints out a bunch of 4s. +// rowPointers have interesting elements? 0 18 36 42 54 72 96 126 162 204 256 when rows = 10, cols = 11; rowLengths = 3 3 1 2 3 4 5 6 7 8 +// and 0 52 103 154 205 256 when rows = 5, cols = 4; rowLengths = 3 3 3 3 3 + + +// types for which MatrixTest is instantiated +using ChEllpackMatrixTypes = ::testing::Types +< + TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Host, short >, + TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Host, short >, + TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Host, short >, + TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Host, short >, + TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Host, int >, + TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Host, int >, + TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Host, int >, + TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Host, int >, + TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Host, long >, + TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Host, long >, + TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Host, long >, + TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Host, long > +#ifdef HAVE_CUDA + ,TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Cuda, short >, + TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Cuda, short >, + TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Cuda, short >, + TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Cuda, short >, + TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Cuda, int >, + TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Cuda, int >, + TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Cuda, int >, + TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Cuda, int >, + TNL::Matrices::ChunkedEllpack< int, TNL::Devices::Cuda, long >, + TNL::Matrices::ChunkedEllpack< long, TNL::Devices::Cuda, long >, + TNL::Matrices::ChunkedEllpack< float, TNL::Devices::Cuda, long >, + TNL::Matrices::ChunkedEllpack< double, TNL::Devices::Cuda, long > +#endif +>; + +TYPED_TEST_CASE( ChunkedEllpackMatrixTest, ChEllpackMatrixTypes); + +TYPED_TEST( ChunkedEllpackMatrixTest, setDimensionsTest ) +{ + using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; + + test_SetDimensions< ChunkedEllpackMatrixType >(); +} + +//TYPED_TEST( ChunkedEllpackMatrixTest, setCompressedRowLengthsTest ) +//{ +//// using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; +// +//// test_SetCompressedRowLengths< ChunkedEllpackMatrixType >(); +// +// bool testRan = false; +// EXPECT_TRUE( testRan ); +// std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; +// std::cout << " This test is dependent on the input format. \n"; +// std::cout << " Almost every format allocates elements per row differently.\n\n"; +// std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; +//} + +TYPED_TEST( ChunkedEllpackMatrixTest, setLikeTest ) +{ + using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; + + test_SetLike< ChunkedEllpackMatrixType, ChunkedEllpackMatrixType >(); +} + +TYPED_TEST( ChunkedEllpackMatrixTest, resetTest ) +{ + using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; + + test_Reset< ChunkedEllpackMatrixType >(); +} + +TYPED_TEST( ChunkedEllpackMatrixTest, setElementTest ) +{ + using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; + + test_SetElement< ChunkedEllpackMatrixType >(); +} + +TYPED_TEST( ChunkedEllpackMatrixTest, addElementTest ) +{ + using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; + + test_AddElement< ChunkedEllpackMatrixType >(); +} + +TYPED_TEST( ChunkedEllpackMatrixTest, setRowTest ) +{ + using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; + + test_SetRow< ChunkedEllpackMatrixType >(); +} + +TYPED_TEST( ChunkedEllpackMatrixTest, vectorProductTest ) +{ + using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; + + test_VectorProduct< ChunkedEllpackMatrixType >(); +} + +TYPED_TEST( ChunkedEllpackMatrixTest, saveAndLoadTest ) +{ + using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; + + test_SaveAndLoad< ChunkedEllpackMatrixType >(); +} + +TYPED_TEST( ChunkedEllpackMatrixTest, printTest ) +{ + using ChunkedEllpackMatrixType = typename TestFixture::ChunkedEllpackMatrixType; + + test_Print< ChunkedEllpackMatrixType >(); +} + +#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 +} diff --git a/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.cpp b/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.cpp new file mode 100644 index 000000000..c454706f0 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.cpp @@ -0,0 +1 @@ +#include "SparseMatrixTest_Ellpack.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.cu b/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.cu new file mode 100644 index 000000000..c454706f0 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.cu @@ -0,0 +1 @@ +#include "SparseMatrixTest_Ellpack.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.h b/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.h new file mode 100644 index 000000000..c6ecd72b3 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_Ellpack.h @@ -0,0 +1,148 @@ +/*************************************************************************** + SparseMatrixTest_Ellpack.h - description + ------------------- + begin : Nov 2, 2018 + copyright : (C) 2018 by Tomas Oberhuber et al. + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#include + +#include "SparseMatrixTest.hpp" +#include + +#ifdef HAVE_GTEST +#include + +// test fixture for typed tests +template< typename Matrix > +class EllpackMatrixTest : public ::testing::Test +{ +protected: + using EllpackMatrixType = Matrix; +}; + +// types for which MatrixTest is instantiated +using EllpackMatrixTypes = ::testing::Types +< + TNL::Matrices::Ellpack< int, TNL::Devices::Host, short >, + TNL::Matrices::Ellpack< long, TNL::Devices::Host, short >, + TNL::Matrices::Ellpack< float, TNL::Devices::Host, short >, + TNL::Matrices::Ellpack< double, TNL::Devices::Host, short >, + TNL::Matrices::Ellpack< int, TNL::Devices::Host, int >, + TNL::Matrices::Ellpack< long, TNL::Devices::Host, int >, + TNL::Matrices::Ellpack< float, TNL::Devices::Host, int >, + TNL::Matrices::Ellpack< double, TNL::Devices::Host, int >, + TNL::Matrices::Ellpack< int, TNL::Devices::Host, long >, + TNL::Matrices::Ellpack< long, TNL::Devices::Host, long >, + TNL::Matrices::Ellpack< float, TNL::Devices::Host, long >, + TNL::Matrices::Ellpack< double, TNL::Devices::Host, long > +#ifdef HAVE_CUDA + ,TNL::Matrices::Ellpack< int, TNL::Devices::Cuda, short >, + TNL::Matrices::Ellpack< long, TNL::Devices::Cuda, short >, + TNL::Matrices::Ellpack< float, TNL::Devices::Cuda, short >, + TNL::Matrices::Ellpack< double, TNL::Devices::Cuda, short >, + TNL::Matrices::Ellpack< int, TNL::Devices::Cuda, int >, + TNL::Matrices::Ellpack< long, TNL::Devices::Cuda, int >, + TNL::Matrices::Ellpack< float, TNL::Devices::Cuda, int >, + TNL::Matrices::Ellpack< double, TNL::Devices::Cuda, int >, + TNL::Matrices::Ellpack< int, TNL::Devices::Cuda, long >, + TNL::Matrices::Ellpack< long, TNL::Devices::Cuda, long >, + TNL::Matrices::Ellpack< float, TNL::Devices::Cuda, long >, + TNL::Matrices::Ellpack< double, TNL::Devices::Cuda, long > +#endif +>; + +TYPED_TEST_CASE( EllpackMatrixTest, EllpackMatrixTypes ); + +TYPED_TEST( EllpackMatrixTest, setDimensionsTest ) +{ + using EllpackMatrixType = typename TestFixture::EllpackMatrixType; + + test_SetDimensions< EllpackMatrixType >(); +} + +//TYPED_TEST( EllpackMatrixTest, setCompressedRowLengthsTest ) +//{ +//// using EllpackMatrixType = typename TestFixture::EllpackMatrixType; +// +//// test_SetCompressedRowLengths< EllpackMatrixType >(); +// +// bool testRan = false; +// EXPECT_TRUE( testRan ); +// std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; +// std::cout << " This test is dependent on the input format. \n"; +// std::cout << " Almost every format allocates elements per row differently.\n\n"; +// std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; +//} + +TYPED_TEST( EllpackMatrixTest, setLikeTest ) +{ + using EllpackMatrixType = typename TestFixture::EllpackMatrixType; + + test_SetLike< EllpackMatrixType, EllpackMatrixType >(); +} + +TYPED_TEST( EllpackMatrixTest, resetTest ) +{ + using EllpackMatrixType = typename TestFixture::EllpackMatrixType; + + test_Reset< EllpackMatrixType >(); +} + +TYPED_TEST( EllpackMatrixTest, setElementTest ) +{ + using EllpackMatrixType = typename TestFixture::EllpackMatrixType; + + test_SetElement< EllpackMatrixType >(); +} + +TYPED_TEST( EllpackMatrixTest, addElementTest ) +{ + using EllpackMatrixType = typename TestFixture::EllpackMatrixType; + + test_AddElement< EllpackMatrixType >(); +} + +TYPED_TEST( EllpackMatrixTest, setRowTest ) +{ + using EllpackMatrixType = typename TestFixture::EllpackMatrixType; + + test_SetRow< EllpackMatrixType >(); +} + +TYPED_TEST( EllpackMatrixTest, vectorProductTest ) +{ + using EllpackMatrixType = typename TestFixture::EllpackMatrixType; + + test_VectorProduct< EllpackMatrixType >(); +} + +TYPED_TEST( EllpackMatrixTest, saveAndLoadTest ) +{ + using EllpackMatrixType = typename TestFixture::EllpackMatrixType; + + test_SaveAndLoad< EllpackMatrixType >(); +} + +TYPED_TEST( EllpackMatrixTest, printTest ) +{ + using EllpackMatrixType = typename TestFixture::EllpackMatrixType; + + test_Print< EllpackMatrixType >(); +} + +#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 +} diff --git a/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.cpp b/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.cpp new file mode 100644 index 000000000..40e2e94b8 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.cpp @@ -0,0 +1 @@ +#include "SparseMatrixTest_SlicedEllpack.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.cu b/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.cu new file mode 100644 index 000000000..40e2e94b8 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.cu @@ -0,0 +1 @@ +#include "SparseMatrixTest_SlicedEllpack.h" diff --git a/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.h b/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.h new file mode 100644 index 000000000..0fc1f59e2 --- /dev/null +++ b/src/UnitTests/Matrices/SparseMatrixTest_SlicedEllpack.h @@ -0,0 +1,148 @@ +/*************************************************************************** + SparseMatrixTest_SlicedEllpack.h - description + ------------------- + begin : Nov 2, 2018 + copyright : (C) 2018 by Tomas Oberhuber et al. + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#include + +#include "SparseMatrixTest.hpp" +#include + +#ifdef HAVE_GTEST +#include + +// test fixture for typed tests +template< typename Matrix > +class SlicedEllpackMatrixTest : public ::testing::Test +{ +protected: + using SlicedEllpackMatrixType = Matrix; +}; + +// types for which MatrixTest is instantiated +using SlicedEllpackMatrixTypes = ::testing::Types +< + TNL::Matrices::SlicedEllpack< int, TNL::Devices::Host, short >, + TNL::Matrices::SlicedEllpack< long, TNL::Devices::Host, short >, + TNL::Matrices::SlicedEllpack< float, TNL::Devices::Host, short >, + TNL::Matrices::SlicedEllpack< double, TNL::Devices::Host, short >, + TNL::Matrices::SlicedEllpack< int, TNL::Devices::Host, int >, + TNL::Matrices::SlicedEllpack< long, TNL::Devices::Host, int >, + TNL::Matrices::SlicedEllpack< float, TNL::Devices::Host, int >, + TNL::Matrices::SlicedEllpack< double, TNL::Devices::Host, int >, + TNL::Matrices::SlicedEllpack< int, TNL::Devices::Host, long >, + TNL::Matrices::SlicedEllpack< long, TNL::Devices::Host, long >, + TNL::Matrices::SlicedEllpack< float, TNL::Devices::Host, long >, + TNL::Matrices::SlicedEllpack< double, TNL::Devices::Host, long > +#ifdef HAVE_CUDA + ,TNL::Matrices::SlicedEllpack< int, TNL::Devices::Cuda, short >, + TNL::Matrices::SlicedEllpack< long, TNL::Devices::Cuda, short >, + TNL::Matrices::SlicedEllpack< float, TNL::Devices::Cuda, short >, + TNL::Matrices::SlicedEllpack< double, TNL::Devices::Cuda, short >, + TNL::Matrices::SlicedEllpack< int, TNL::Devices::Cuda, int >, + TNL::Matrices::SlicedEllpack< long, TNL::Devices::Cuda, int >, + TNL::Matrices::SlicedEllpack< float, TNL::Devices::Cuda, int >, + TNL::Matrices::SlicedEllpack< double, TNL::Devices::Cuda, int >, + TNL::Matrices::SlicedEllpack< int, TNL::Devices::Cuda, long >, + TNL::Matrices::SlicedEllpack< long, TNL::Devices::Cuda, long >, + TNL::Matrices::SlicedEllpack< float, TNL::Devices::Cuda, long >, + TNL::Matrices::SlicedEllpack< double, TNL::Devices::Cuda, long > +#endif +>; + +TYPED_TEST_CASE( SlicedEllpackMatrixTest, SlicedEllpackMatrixTypes ); + +TYPED_TEST( SlicedEllpackMatrixTest, setDimensionsTest ) +{ + using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; + + test_SetDimensions< SlicedEllpackMatrixType >(); +} + +//TYPED_TEST( SlicedEllpackMatrixTest, setCompressedRowLengthsTest ) +//{ +//// using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; +// +//// test_SetCompressedRowLengths< SlicedEllpackMatrixType >(); +// +// bool testRan = false; +// EXPECT_TRUE( testRan ); +// std::cout << "\nTEST DID NOT RUN. NOT WORKING.\n\n"; +// std::cout << " This test is dependent on the input format. \n"; +// std::cout << " Almost every format allocates elements per row differently.\n\n"; +// std::cout << "\n TODO: Finish implementation of getNonZeroRowLength (Only non-zero elements, not the number of allocated elements.)\n\n"; +//} + +TYPED_TEST( SlicedEllpackMatrixTest, setLikeTest ) +{ + using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; + + test_SetLike< SlicedEllpackMatrixType, SlicedEllpackMatrixType >(); +} + +TYPED_TEST( SlicedEllpackMatrixTest, resetTest ) +{ + using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; + + test_Reset< SlicedEllpackMatrixType >(); +} + +TYPED_TEST( SlicedEllpackMatrixTest, setElementTest ) +{ + using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; + + test_SetElement< SlicedEllpackMatrixType >(); +} + +TYPED_TEST( SlicedEllpackMatrixTest, addElementTest ) +{ + using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; + + test_AddElement< SlicedEllpackMatrixType >(); +} + +TYPED_TEST( SlicedEllpackMatrixTest, setRowTest ) +{ + using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; + + test_SetRow< SlicedEllpackMatrixType >(); +} + +TYPED_TEST( SlicedEllpackMatrixTest, vectorProductTest ) +{ + using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; + + test_VectorProduct< SlicedEllpackMatrixType >(); +} + +TYPED_TEST( SlicedEllpackMatrixTest, saveAndLoadTest ) +{ + using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; + + test_SaveAndLoad< SlicedEllpackMatrixType >(); +} + +TYPED_TEST( SlicedEllpackMatrixTest, printTest ) +{ + using SlicedEllpackMatrixType = typename TestFixture::SlicedEllpackMatrixType; + + test_Print< SlicedEllpackMatrixType >(); +} + +#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 +} -- GitLab