diff --git a/CMakeLists.txt b/CMakeLists.txt index 8784170f8a2d0b3f1671b1c0847ec5fed7a6633a..a0a015c037becdddc6d3152d350b98148c4518cc 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() #### @@ -309,45 +296,6 @@ if( ${WITH_GMP} ) endif() 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 - 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() @@ -412,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/BLAS/CMakeLists.txt b/src/Benchmarks/BLAS/CMakeLists.txt index dc396c46e60512b5cab5f5f7455756f609b76c47..a6c99a994eceee890f106f628c7c5bfd6a330941 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/BLAS/spmv.h b/src/Benchmarks/BLAS/spmv.h index 9df40f4ec6b0db6d8d268dd5d38cef92b9fc61c8..5c3813b0a9f1798582ce2ee8a04f52ae4ee78408 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/Benchmarks/BLAS/tnl-benchmark-blas.h b/src/Benchmarks/BLAS/tnl-benchmark-blas.h index 390b17279db2dd153172b7fcb6c294e0a6969d9b..49c624ac9cefb6a4182d6c372d5eeac2023174e5 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/CMakeLists.txt b/src/Benchmarks/DistSpMV/CMakeLists.txt index 57ccdd7a9f3d896c6f32cd969e691afbff8759b9..78fc992ad61c42dc107bcb556b4c08fd699c773a 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/DistSpMV/tnl-benchmark-distributed-spmv.h b/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h index a3bd76753aaab02367e5f509cead9dacee2f1b62..73001e95820b8d10e1e7dc1845bb825f02e05c02 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/HeatEquation/CMakeLists.txt b/src/Benchmarks/HeatEquation/CMakeLists.txt index 867ab2c1e0d6f75b341de6dcb6c8868b1aa666f3..d7bccc7ceb8e20a44871d83fe08eae575ecb3cbe 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/HeatEquation/tnl-benchmark-heat-equation.h b/src/Benchmarks/HeatEquation/tnl-benchmark-heat-equation.h index 1906508db4360794ae48ffd218cd07d62670b349..e0a3318c5bcbb3e43ec8dcee5e16705f1780fcb3 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/Benchmarks/LinearSolvers/CMakeLists.txt b/src/Benchmarks/LinearSolvers/CMakeLists.txt index af0187928335a85638fa07680b79a7ad797c601a..29456bde5f7ae44207d2d11dabc3ece728ee8ca2 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/LinearSolvers/tnl-benchmark-linear-solvers.h b/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h index b766bd5056dc0fbf84ee9940732946421b90d3d7..55211c4edb9043e1ae0258e041fcfd2846976e51 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; diff --git a/src/Benchmarks/SpMV/CMakeLists.txt b/src/Benchmarks/SpMV/CMakeLists.txt index a73e6738cdb8bb4effd889960f3ffcd5b7255b90..7cb9c4fcd976e88ec61fc4579aaa612c9da7b656 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 f827d6695eb4f3271b2deaf9a91b01c71e06f612..1c52839e9116646d982eafaea5ba30bf04a9b995 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/StringExample.cpp b/src/Examples/StringExample.cpp index 9ef9a4a9a2045716956374ef4f783605a1a9c372..a23904a4f96118ff3139f0403462e934fc8a7641 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 61886792acbdb70945a2d05e0c731620e613d15f..0b0a958b6c2bc760914cac1f4f5dffe75b1749e2 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 diff --git a/src/Examples/flow-sw/CMakeLists.txt b/src/Examples/flow-sw/CMakeLists.txt index 685514053115b43eeb0aa201a4f6ace5bc9a174c..cd53d411c9bbbe508f711890f9e1a3eab5063cb8 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-sw/navierStokes.h b/src/Examples/flow-sw/navierStokes.h index a298f14b24e552e355a5864bd7ba8e653afa92fb..0d37ad41cb9435f34d142b0b4af06b0e161c4ada 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/CMakeLists.txt b/src/Examples/flow-vl/CMakeLists.txt index 6162093eae83924167406f70c6ac5519fb32c470..47bb72276e06c9a7944b964260b23f78c572e988 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-vl/navierStokes.h b/src/Examples/flow-vl/navierStokes.h index a298f14b24e552e355a5864bd7ba8e653afa92fb..0d37ad41cb9435f34d142b0b4af06b0e161c4ada 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/CMakeLists.txt b/src/Examples/flow/CMakeLists.txt index f6ec4bda103ea2dc545103b329bb4fd9f5de79ac..6b156036bf3e283f4aa1d0c3bb8b6bc46978a86f 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/flow/navierStokes.h b/src/Examples/flow/navierStokes.h index 8d60667fe42e0ce403459ed5c1bc13e692612d72..5b37345bc6bc18ae1355b458a1cff5eaef64a346 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/heat-equation/CMakeLists.txt b/src/Examples/heat-equation/CMakeLists.txt index d58ffd58d258f458e227afaa19cb6e24034d80ab..c895199060481cd4e20e22c30a4a5b473faeb552 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 cf5e0cb5891a77c133981d3a0606763dc35fde73..427def1267f5e5e8f67c803bd0ca217c6246d202 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-sw/euler.h b/src/Examples/inviscid-flow-sw/euler.h index 9248d901fa50ec38bdc9bae3d81b5d595315301d..75279e605d9afa4d25531e7e63a91e33424c2c9f 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/CMakeLists.txt b/src/Examples/inviscid-flow-vl/CMakeLists.txt index 77afc9d3e384d9beddbf3b4ea3c1c3e9cb547538..d0111a5a130efc93dc357300700cfade296835fc 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-vl/euler.h b/src/Examples/inviscid-flow-vl/euler.h index 9248d901fa50ec38bdc9bae3d81b5d595315301d..75279e605d9afa4d25531e7e63a91e33424c2c9f 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 d5550d0c72dcc1624db2f227d2298346bbb1d73d..3160fe898bfdb2c37fa451ff19090e99b6f46dcb 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/CMakeLists.txt b/src/Examples/inviscid-flow/CMakeLists.txt index a77942815d7e0f7250a6721dbd232c27c771b60c..dbfe2024d4cf6c8639593e754ca40c884f7604b3 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/inviscid-flow/euler.h b/src/Examples/inviscid-flow/euler.h index 22c87ce0bdd9af86f6a90ee6f2c5524572470355..0bd0c6664c03ffd062568b424d23aaaf9e374b15 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/simple-examples/CMakeLists.txt b/src/Examples/simple-examples/CMakeLists.txt index 5e8829e23ef8596945866785345b411ca5f62048..21fed2b1837f746a190bc1757f7caa359948f225 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 4af25289924e618832e90bf77b98d753470bc073..2f29a66cd02b230b30bff3d88baadd53f5b57f0a 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/Examples/transport-equation/tnl-transport-equation-eoc.h b/src/Examples/transport-equation/tnl-transport-equation-eoc.h index fc2eda33336e8c93d196a3aad5643697c80863ef..dbf7610ef657292c78b3ec3f84c669cd3491db8b 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 7978de25a11627349e790ad8caa5d548431eeac8..9e669033a756892b016e549cc5e58fa8c5afb83b 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/Python/pytnl/tnl/CMakeLists.txt b/src/Python/pytnl/tnl/CMakeLists.txt index 254c73c5781cd54abeb368ccb1bdc3a8efe486a8..b6c4182b88d7f8c4d1f2ca9acb8478daec0bd45e 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/Python/pytnl/tnl/String.cpp b/src/Python/pytnl/tnl/String.cpp index 551f94ddf61f3e492dbeefb2b140d570dd779c6f..f9fff7d920e49f4eedd55ad9ab5190b644171eaf 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/CMakeLists.txt b/src/TNL/CMakeLists.txt index 9b621af312205e47a6b89756dd08c53185516cd1..a5162c7a6997664713727f409d7cfd8f429a913f 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 @@ -26,6 +24,7 @@ set( headers FileName.h FileName.hpp Object.h + Object_impl.h Logger.h Logger_impl.h Math.h @@ -33,95 +32,9 @@ set( headers param-types.h StaticFor.h String.h + String_impl.h Timer.h + Timer_impl.h StaticVectorFor.h ) -set( common_SOURCES - File.cpp - FileName.cpp - Object.cpp - Logger.cpp - String.cpp - Timer.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/Communicators/MpiCommunicator.h b/src/TNL/Communicators/MpiCommunicator.h index b3a3b2ce0d68d7d0469e966073c28cf4a4f3d336..3df6a45a4378d44fe80687d1ef91189cf1b810f2 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/CMakeLists.txt b/src/TNL/Config/CMakeLists.txt index ba12e2228b67418116e60ac28a454dfd121d58ea..b88a173fe84f6df4002e4cf5f1c07896844bcf8f 100644 --- a/src/TNL/Config/CMakeLists.txt +++ b/src/TNL/Config/CMakeLists.txt @@ -1,26 +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 - DefaultBasicTypesChecker.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/ConfigDelimiter.h b/src/TNL/Config/ConfigDelimiter.h index d96d7dffb0d6303b10908fd657462727828f5ce9..2c102c77888c18114fe39272782b0386434685aa 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 deleted file mode 100644 index 6145103ef64c155cd8b4387d381e135ce47cba70..0000000000000000000000000000000000000000 --- a/src/TNL/Config/ConfigDescription.cpp +++ /dev/null @@ -1,156 +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 - -namespace TNL { -namespace Config { - -ConfigDescription :: ConfigDescription() -: currentEntry( 0 ) -{ -} - -ConfigDescription :: ~ConfigDescription() -{ - entries.DeepEraseAll(); -} - -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(); - int max_name_length( 0 ); - int max_type_length( 0 ); - for( 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( 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 Config::ConfigDescription :: addMissingEntries( Config::ParameterContainer& parameter_container ) const -{ - int i; - const int size = entries.getSize(); - for( 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" ) - { - parameter_container. addParameter< String >( - entry_name, - ( ( ConfigEntry< String >* ) entries[ i ] ) -> defaultValue ); - continue; - } - if( entries[ i ]->getEntryType() == "bool" ) - { - parameter_container. addParameter< bool >( - entry_name, - ( ( ConfigEntry< bool >* ) entries[ i ] ) -> defaultValue ); - continue; - } - if( entries[ i ]->getEntryType() == "int" ) - { - parameter_container. addParameter< int >( - entry_name, - ( ( ConfigEntry< int >* ) entries[ i ] ) -> defaultValue ); - continue; - } - if( entries[ i ]->getEntryType() == "double" ) - { - parameter_container. addParameter< double >( - entry_name, - ( ( ConfigEntry< double >* ) entries[ i ] ) -> defaultValue ); - continue; - } - } - } -} - -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 char* entry_name = entries[ i ] -> name. getString(); - if( entries[ i ] -> required && - ! parameter_container. checkParameter( entry_name ) ) - missingParameters.Append( entry_name ); - } - if( missingParameters.getSize() != 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 << "--" << 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 833e99a47af2a11b19fcdbd3b2ed9c5f5cccf0f4..7d05b0976318c0bc60411fb7c9d62a57bb884528 100644 --- a/src/TNL/Config/ConfigDescription.h +++ b/src/TNL/Config/ConfigDescription.h @@ -10,28 +10,27 @@ #pragma once +#include +#include +#include +#include +#include "make_unique.h" + +#include #include -#include #include #include #include #include #include +#include namespace TNL { namespace Config { -class ParameterContainer; - class ConfigDescription { - public: - - /** - * \brief Basic constructor. - */ - ConfigDescription(); - +public: /** * \brief Adds new entry to the configuration description. * @@ -43,8 +42,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 +57,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 +74,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 +89,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 +104,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 +121,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 +135,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 +148,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 +160,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,46 +171,61 @@ class ConfigDescription */ const ConfigEntryBase* getEntry( const String& name ) const { - for( int i = 0; i < entries.getSize(); i++ ) + // 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 ) - 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; + // 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 ) { + 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; + // 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 ) { + 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; + return nullptr; } /** @@ -225,37 +235,139 @@ class ConfigDescription * 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; - - //bool parseConfigDescription( const char* file_name ); - - /** - * \brief Basic destructor. - */ - ~ConfigDescription(); - - protected: + 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 '--' - Containers::List< ConfigEntryBase* > entries; + 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; + } - ConfigEntryBase* currentEntry; + //bool parseConfigDescription( const char* file_name ); +protected: + std::vector< std::unique_ptr< ConfigEntryBase > > entries; + ConfigEntryBase* currentEntry = nullptr; }; } //namespace Config } //namespace TNL +#include diff --git a/src/TNL/Config/ConfigEntry.h b/src/TNL/Config/ConfigEntry.h index 759a77ef3d52d991c4a1f879a7e1e5390023159d..1608a5b4b1311ded6ca6d02c01fbe6afd7524d75 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 f69729ef5aaaa0d8120307eecfc8608d12742dfc..c6dc19fbfecaeb61a7dfcefcd2720522357e9922 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 e8fabf5c58338177e38fa8a1ef652400c2ac79c7..50284e37c1195916ab5c2ccfd3f72dd4d6ed7ed8 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("ConfigEntryList< ") + 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 4ba052d022dd160ad633983d255b5dbfbb318edb..bb656f8fcf6b38d07e68bb06a3c65e11a90e0269 100644 --- a/src/TNL/Config/ConfigEntryType.h +++ b/src/TNL/Config/ConfigEntryType.h @@ -8,9 +8,11 @@ /* See Copyright Notice in tnl/Copyright */ -#pragma once +#pragma once -#include +#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< 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 +36,19 @@ 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 ){} + list_entry( _list_entry ) + {} void Reset() { - basic_type. setString( 0 ); + basic_type.clear(); list_entry = false; - }; + } }; } // namespace Config diff --git a/src/TNL/Config/DefaultBasicTypesChecker.h b/src/TNL/Config/DefaultBasicTypesChecker.h deleted file mode 100644 index 01ba4126d50d5bd91b30cc0da7d0f25763b4f66c..0000000000000000000000000000000000000000 --- 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 - diff --git a/src/TNL/Config/ParameterContainer.cpp b/src/TNL/Config/ParameterContainer.cpp deleted file mode 100644 index 1f01dfcf52b9112b65085ecf4d1aaa952b2d107a..0000000000000000000000000000000000000000 --- a/src/TNL/Config/ParameterContainer.cpp +++ /dev/null @@ -1,343 +0,0 @@ -/*************************************************************************** - Config::ParameterContainer.cpp - description - ------------------- - begin : 2007/06/15 - copyright : (C) 2007 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#include -#include -#include - -#include "ParameterContainer.h" -#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; -} - -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; - return false; -} - -ParameterContainer:: -~ParameterContainer() -{ - parameters. DeepEraseAll(); -} - -/*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 -} -*/ -bool -parseCommandLine( int argc, char* argv[], - const Config::ConfigDescription& config_description, - Config::ParameterContainer& parameters, - bool printUsage ) -{ - int i; - bool parse_error( false ); - for( i = 1; i < argc; i ++ ) - { - const char* _option = argv[ i ]; - if( _option[ 0 ] != '-' ) - { - std::cerr << "Unknown option " << _option << ". Options must have prefix '--' or '-'." << std::endl; - parse_error = true; - continue; - } - if( strcmp( _option, "--help" ) == 0 ) - { - config_description.printUsage( argv[ 0 ] ); - return true; - } - const char* option = _option + 2; - const ConfigEntryBase* entry; - if( ( entry = config_description.getEntry( option ) ) == NULL ) - { - std::cerr << "Unknown parameter " << _option << "." << std::endl; - parse_error = true; - } - else - { - const String& entryType = entry->getEntryType(); - const char* value = argv[ ++ i ]; - if( ! value ) - { - std::cerr << "Missing value for the parameter " << option << "." << std::endl; - return false; - } - Containers::List< String > parsedEntryType; - if( ! parseObjectType( entryType, parsedEntryType ) ) - { - std::cerr << "Internal error: Unknown config entry type " << entryType << "." << std::endl; - return false; - } - if( parsedEntryType[ 0 ] == "Containers::List" ) - { - Containers::List< String >* string_list( 0 ); - Containers::List< bool >* bool_list( 0 ); - Containers::List< int >* integer_list( 0 ); - Containers::List< double >* real_list( 0 ); - - 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 ) ) ) ) - { - const char* value = argv[ i ++ ]; - if( string_list ) - { - /*if( ! ( ( ConfigEntry< Containers::List< String > >* ) entry )->checkValue( String( value ) ) ) - { - delete string_list; - return false; - }*/ - string_list -> Append( String( value ) ); - } - if( bool_list ) - { - bool bool_val; - if( ! matob( value, bool_val ) ) - { - std::cerr << "Yes/true or no/false is required for the parameter " << option << "." << std::endl; - parse_error = true; - } - else bool_list -> Append( bool_val ); - } - if( integer_list ) - { - /*if( ! ( ConfigEntry< Containers::List< int > >* ) entry->checkValue( atoi( value ) ) ) - { - delete integer_list; - return false; - }*/ - integer_list -> Append( atoi( value ) ); - } - if( real_list ) - { - /*if( ! ( ConfigEntry< Containers::List< double > >* ) entry->checkValue( atof( value ) ) ) - { - delete real_list; - return false; - }*/ - real_list -> Append( 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( i < argc ) i --; - continue; - } - else - { - if( parsedEntryType[ 0 ] == "String" ) - { - if( ! ( ( ConfigEntry< String >* ) entry )->checkValue( value ) ) - return false; - parameters.addParameter< String >( option, value ); - continue; - } - if( parsedEntryType[ 0 ] == "bool" ) - { - bool bool_val; - if( ! matob( value, bool_val ) ) - { - 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 ); - continue; - } - if( parsedEntryType[ 0 ] == "int" ) - { - /*if( ! std::isdigit( value ) ) //TODO: Check for real number - { - std::cerr << "Integer constant is required for the parameter " << option << "." << std::endl; - parse_error = true; - continue; - }*/ - if( ! ( ( ConfigEntry< int >* ) entry )->checkValue( atoi( value ) ) ) - return false; - parameters.addParameter< int >( option, atoi( value ) ); - } - if( parsedEntryType[ 0 ] == "double" ) - { - /*if( ! std::isdigit( value ) ) //TODO: Check for real number - { - std::cerr << "Real constant is required for the parameter " << option << "." << std::endl; - parse_error = true; - continue; - }*/ - if( ! ( ( ConfigEntry< double >* ) entry )->checkValue( atof( value ) ) ) - return false; - parameters.addParameter< double >( option, atof( value ) ); - } - } - } - } - config_description.addMissingEntries( parameters ); - if( ! config_description.checkMissingEntries( parameters, printUsage, argv[ 0 ] ) ) - return false; - return ! parse_error; -} - -} // namespace Config -} // namespace TNL diff --git a/src/TNL/Config/ParameterContainer.h b/src/TNL/Config/ParameterContainer.h index 4d36cb9748246eb6a3d6a9d93253a5d5a1b1d98e..209b77a7c4cf659ca5391931686d14f3825533f4 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 "make_unique.h" -#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,18 +56,27 @@ 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 ) + { + 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,11 +85,27 @@ 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 ) + { + 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. @@ -96,22 +121,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,72 +147,95 @@ 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; - -}; - -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 ) -{ - return parameters. Append( new tnlParameter< T >( name, TNL::getType< T >().getString(), value ) ); -}; -template< class T > -bool -ParameterContainer:: -setParameter( const String& name, - const T& value ) -{ - int i; - for( i = 0; i < parameters. getSize(); i ++ ) +/* + //! Broadcast to other nodes in MPI cluster + void MPIBcast( int root, MPI_Comm mpi_comm = MPI_COMM_WORLD ) { - if( parameters[ i ] -> name == name ) + #ifdef USE_MPI + int i; + int size = parameters. getSize(); + :: MPIBcast( size, 1, root, mpi_comm ); + for( i = 0; i < size; i ++ ) { - if( parameters[ i ] -> type == TNL::getType< T >() ) + if( MPIGetRank() == root ) { - ( ( tnlParameter< T > * ) parameters[ i ] ) -> value = value; - return true; + 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; - abort( ); - return false; + 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 0000000000000000000000000000000000000000..4a4078a028e2c1cb9feec357080d20bc3f05454b --- /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/parseCommandLine.h b/src/TNL/Config/parseCommandLine.h new file mode 100644 index 0000000000000000000000000000000000000000..2c8c62090aea9eb6c71789d322ca2d9bb070a391 --- /dev/null +++ b/src/TNL/Config/parseCommandLine.h @@ -0,0 +1,186 @@ +/*************************************************************************** + parseCommandLine.h - description + ------------------- + begin : 2007/06/15 + copyright : (C) 2007 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include +#include + +//#include +#include +#include + +namespace TNL { + +std::vector< String > +parseObjectType( const String& objectType ); + +namespace Config { + +inline bool +parseCommandLine( int argc, char* argv[], + const Config::ConfigDescription& config_description, + Config::ParameterContainer& parameters, + 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 ++ ) + { + const char* _option = argv[ i ]; + if( _option[ 0 ] != '-' ) + { + std::cerr << "Unknown option " << _option << ". Options must have prefix '--' or '-'." << std::endl; + parse_error = true; + continue; + } + if( strcmp( _option, "--help" ) == 0 ) + { + config_description.printUsage( argv[ 0 ] ); + return true; + } + const char* option = _option + 2; + const ConfigEntryBase* entry; + if( ( entry = config_description.getEntry( option ) ) == NULL ) + { + std::cerr << "Unknown parameter " << _option << "." << std::endl; + parse_error = true; + } + else + { + const String& entryType = entry->getEntryType(); + const char* value = argv[ ++ i ]; + if( ! value ) + { + std::cerr << "Missing value for the parameter " << option << "." << std::endl; + return false; + } + 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 ] == "ConfigEntryList" ) + { + std::vector< String > string_list; + std::vector< bool > bool_list; + std::vector< int > integer_list; + std::vector< double > 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( parsedEntryType[ 1 ] == "String" ) + { + string_list.push_back( String( value ) ); + } + if( parsedEntryType[ 1 ] == "bool" ) + { + 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( true ); + } + if( parsedEntryType[ 1 ] == "int" ) + { + integer_list.push_back( atoi( value ) ); + } + if( parsedEntryType[ 1 ] == "double" ) + { + real_list.push_back( atof( value ) ); + } + } + 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; + } + else + { + if( parsedEntryType[ 0 ] == "String" ) + { + if( ! ( ( ConfigEntry< String >* ) entry )->checkValue( value ) ) + return false; + parameters.addParameter< String >( option, value ); + continue; + } + if( parsedEntryType[ 0 ] == "bool" ) + { + 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, true ); + continue; + } + if( parsedEntryType[ 0 ] == "int" ) + { + /*if( ! std::isdigit( value ) ) //TODO: Check for real number + { + std::cerr << "Integer constant is required for the parameter " << option << "." << std::endl; + parse_error = true; + continue; + }*/ + if( ! ( ( ConfigEntry< int >* ) entry )->checkValue( atoi( value ) ) ) + return false; + parameters.addParameter< int >( option, atoi( value ) ); + } + if( parsedEntryType[ 0 ] == "double" ) + { + /*if( ! std::isdigit( value ) ) //TODO: Check for real number + { + std::cerr << "Real constant is required for the parameter " << option << "." << std::endl; + parse_error = true; + continue; + }*/ + if( ! ( ( ConfigEntry< double >* ) entry )->checkValue( atof( value ) ) ) + return false; + parameters.addParameter< double >( option, atof( value ) ); + } + } + } + } + config_description.addMissingEntries( parameters ); + if( ! config_description.checkMissingEntries( parameters, printUsage, argv[ 0 ] ) ) + return false; + return ! parse_error; +} + +} // namespace Config +} // namespace TNL diff --git a/src/TNL/Containers/Algorithms/ArrayIO.h b/src/TNL/Containers/Algorithms/ArrayIO.h index 5be8d02caf81d7fd8f284060e6697f78829a9fcb..9b14f7cca0e68a928ac166ed4ae7f2ba147784f7 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/Algorithms/ArrayOperationsCuda_impl.h b/src/TNL/Containers/Algorithms/ArrayOperationsCuda_impl.h index 9a87b52874f6f34f6f788362623060804052399b..34946628a0ed9bb60b70b8802e30cc4c1385e8c6 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 c48d4b40bb3fc8997fe0e8adbf5c3fc1a64fb8a1..18fe544ea120c8ebd7596e325a8bf01a9a9274c3 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 0289c3c6c85d482340d74a6f100ad26695294a45..1823d8077eb8a69364c457708e2287b19179cc31 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 02d4329e1175f1bff91ec25a5bb7924c554e0d82..438e743281f3197989af5eec7fc39c73c5c25263 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/Containers/StaticArray1D_impl.h b/src/TNL/Containers/StaticArray1D_impl.h index 81f5a08d24c01780a3ba5e96757399a96d4e746f..e9b1fbc1d0726dcdb03414b8e0ad0ff0fa8c29bc 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 55096abd08da4b319f3e59bbb2b5445be2249723..664a938d79f4df5259609f74d5a379e26927b770 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 1aac8cc890b0ba46572e1fffca4a53616cb20f11..2489196c05f91c294507fc9dd105b4da36f7a2bb 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 0917b0f1cb9019665a3b0f829953ecf45f677d66..a154ebc480ea8ba0529f3f452652fe5cc426f134 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/Devices/CMakeLists.txt b/src/TNL/Devices/CMakeLists.txt index dbb88eede53a422af86444c6b313f50ffcb3b11b..b2beec09623a675a0fb9743e388dd8befb90b957 100644 --- a/src/TNL/Devices/CMakeLists.txt +++ b/src/TNL/Devices/CMakeLists.txt @@ -2,30 +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}/Cuda.cpp - ${CURRENT_DIR}/Host.cpp - ${CURRENT_DIR}/MIC.cpp - ${CURRENT_DIR}/SystemInfo.cpp ) - -IF( BUILD_CUDA ) - set( tnl_devices_CUDA__SOURCES - ${common_SOURCES} - ${CURRENT_DIR}/Cuda.cu - ${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/Cuda.cpp b/src/TNL/Devices/Cuda.cpp deleted file mode 100644 index 9dc2ff9d00b035154195d4ef81dc39a94a36345a..0000000000000000000000000000000000000000 --- a/src/TNL/Devices/Cuda.cpp +++ /dev/null @@ -1,95 +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 -#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::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() ); -} - -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 c1e5248330d0b46d23258a200238756c36aa314d..0000000000000000000000000000000000000000 --- 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 123d3a96c6d940be44208785fb5c776586a0d52d..088e67dd0161982437ceace9e0e6a265e22f1d83 100644 --- a/src/TNL/Devices/Cuda.h +++ b/src/TNL/Devices/Cuda.h @@ -11,27 +11,28 @@ #pragma once #include -#include + #include #include #include #include #include +#include +#include namespace TNL { - -namespace Config { - class ConfigDescription; - class ParameterContainer; -} - namespace Devices { 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 +67,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 +154,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 +181,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/CudaDeviceInfo.cpp b/src/TNL/Devices/CudaDeviceInfo.cpp deleted file mode 100644 index 85a6604d87bba8655aac46609d4ae0db8dc24934..0000000000000000000000000000000000000000 --- 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 4e66c095d6579385f668de4cf93b255b3182c87f..0000000000000000000000000000000000000000 --- 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 0b02daee53071d5899f4de14041e40f2da96adaa..9eefe3bad8932670af271204e03f72b5eb501a95 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 0000000000000000000000000000000000000000..f29ecd8c91493edb538f11a8ced6c9ee6503983a --- /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/Cuda_impl.h b/src/TNL/Devices/Cuda_impl.h index e0b9c52a5abd0cc32cff37983ad16aed023009de..21028356393b7e78cceb2681ef33afefae171713 100644 --- a/src/TNL/Devices/Cuda_impl.h +++ b/src/TNL/Devices/Cuda_impl.h @@ -10,14 +10,50 @@ #pragma once +#include #include +#include #include #include +#include #include 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() { @@ -69,6 +105,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 ) @@ -160,6 +295,60 @@ __device__ Element* Cuda::getSharedMemory() return CudaSharedMemory< Element >(); } +#ifdef HAVE_CUDA +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 + if( deviceId < 0 ) + deviceId = Devices::CudaDeviceInfo::getActiveDevice(); + getSmartPointersSynchronizationTimer().start(); + bool b = getSmartPointersRegister().synchronizeDevice( deviceId ); + getSmartPointersSynchronizationTimer().stop(); + return b; +#endif +} + +inline Timer& Cuda::getSmartPointersSynchronizationTimer() +{ + static Timer timer; + return timer; +} + +inline SmartPointersRegister& Cuda::getSmartPointersRegister() +{ + static SmartPointersRegister reg; + return reg; +} + +#ifdef HAVE_CUDA +namespace { + std::ostream& operator << ( std::ostream& str, const dim3& d ) + { + str << "( " << d.x << ", " << d.y << ", " << d.z << " )"; + return str; + } +} +#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 #if __CUDA_ARCH__ < 600 diff --git a/src/TNL/Devices/Host.cpp b/src/TNL/Devices/Host.cpp deleted file mode 100644 index c45662849cd6e953910842c7ea5ddde8313fbed0..0000000000000000000000000000000000000000 --- 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 2852b1a0fe1e1445d4f33559a8956174802a6081..6b56302a248d98182c030ed3eb1c846a051ccd7f 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 diff --git a/src/TNL/Devices/MIC.cpp b/src/TNL/Devices/MIC.cpp deleted file mode 100644 index b16ac7854dd29ced0ed433228f5aa783d1f017ac..0000000000000000000000000000000000000000 --- 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 5b6a9a4f8c40adf1b26bfdc687254db1d1241872..9a49253c48fe6a9de6010eb6b54bd229e7d6e49d 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 diff --git a/src/TNL/Devices/SystemInfo.h b/src/TNL/Devices/SystemInfo.h index bafcdd428264f9586f72802916bafbe26ce1eda9..f62321d6f819303ec4c12d174a71305f26792ac1 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 61% rename from src/TNL/Devices/SystemInfo.cpp rename to src/TNL/Devices/SystemInfo_impl.h index 377922b26e320db704fe327050e93e77de932ada..0bc42601191aad2fd8a09fa8080a0295ebe6c075 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,27 +8,22 @@ /* See Copyright Notice in tnl/Copyright */ +#pragma once + #include #include #include -#include +#include #include #include -#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 ]; @@ -36,7 +31,7 @@ SystemInfo::getHostname( void ) return String( host_name ); } -String +inline String SystemInfo::getArchitecture( void ) { utsname uts; @@ -44,7 +39,7 @@ SystemInfo::getArchitecture( void ) return String( uts.machine ); } -String +inline String SystemInfo::getSystemName( void ) { utsname uts; @@ -52,7 +47,7 @@ SystemInfo::getSystemName( void ) return String( uts.sysname ); } -String +inline String SystemInfo::getSystemRelease( void ) { utsname uts; @@ -60,61 +55,69 @@ 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 ); 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() ); } -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" ); @@ -122,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" ); @@ -153,42 +156,23 @@ SystemInfo::getCPUCacheSizes( int cpu_id ) return sizes; } -void -SystemInfo:: -writeDeviceInfo( Logger& logger ) +inline size_t +SystemInfo::getFreeMemory() { - 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 ); - // 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 ]; @@ -209,33 +193,27 @@ SystemInfo::parseCPUInfo( void ) { i = strlen( "model name" ); while( line[ i ] != ':' && line[ i ] ) i ++; - CPUModelName.setString( &line[ i + 1 ] ); + info.CPUModelName = &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 } // namespace TNL diff --git a/src/TNL/Exceptions/FileDeserializationError.h b/src/TNL/Exceptions/FileDeserializationError.h new file mode 100644 index 0000000000000000000000000000000000000000..d6c02cbf20dc9db9c4c39821834d8a7ce8de935b --- /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 0000000000000000000000000000000000000000..6336efa5498cd751863af11ac563bf0dcf6f9c1a --- /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/Experimental/Arithmetics/UnitTests/CMakeLists.txt b/src/TNL/Experimental/Arithmetics/UnitTests/CMakeLists.txt index c133e1d0b055401439e0ef6ca9e21a381fcd91d6..d02caaae89a14a12308984fd4c05f4543b741a86 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 edb30a70cae874f2ac46808c8c5543d4171244da..480a5ccb80add384ee19897831f761a958109c67 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/TNL/File.cpp b/src/TNL/File.cpp deleted file mode 100644 index f4be340ae998ac48a3786a21cfa2305361fe4c65..0000000000000000000000000000000000000000 --- 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 afa5631f642b6c0774bf6bf639f1ec8ade3aafc0..ca4d4a85ff99008f603cd6ce546d03268a51d1d2 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,25 +43,12 @@ const size_t FileGPUvsCPUTransferBufferSize = 5 * 2<<20; // \include FileExample.out class File { - IOMode mode; - - std::FILE* file; - - bool fileOK; - + std::fstream file; String fileName; - std::size_t writtenElements; - - std::size_t readElements; - - public: - +public: /// \brief Basic constructor. - File(); - - /// \brief Destructor. - ~File(); + File() = default; ///// /// \brief Attempts to open given file and returns \e true after the file is @@ -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. @@ -182,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/FileName.cpp b/src/TNL/FileName.cpp deleted file mode 100644 index ecbe0a664bb30c254067c20619e3b6370f83d3b5..0000000000000000000000000000000000000000 --- 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 3dae01c5407153357d91a45e74b73382cc3559e0..a36e3db3fc6da84df9403dde905f74f17a0cf49a 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 4f1628df54c808322e61d30ad7c2210c67ee507d..4cda1fda29d5b4f74c7368ec55efc60321fdac43 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,32 @@ 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 ) +{ + const int size = fileName.getLength(); + int i = 1; + while( fileName[ size - i ] != '.' && size > i ) i++; + return fileName.substr( size - i + 1 ); +} + +inline void removeFileExtension( String& fileName ) +{ + const int size = fileName.getLength(); + int i = 1; + while( fileName[ size - i ] != '.' && size > i ) i++; + fileName = fileName.substr( 0, size - i + 1 ); +} + } // namespace TNL diff --git a/src/TNL/File_impl.h b/src/TNL/File_impl.h index a27250242144156fdf156b3d889cda3420b069e0..03c3f0d4a23cb8ba7a4972e09c0846f03bb39503 100644 --- a/src/TNL/File_impl.h +++ b/src/TNL/File_impl.h @@ -10,50 +10,71 @@ #pragma once -#include #include +#include #include +#include #include #include +#include +#include namespace TNL { +inline bool File::open( const String& fileName, const IOMode mode ) +{ + // enable exceptions + file.exceptions( std::fstream::failbit | std::fstream::badbit | std::fstream::eofbit ); + + 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( ! file.good() ) { + std::cerr << "I am not able to open the file " << fileName << ". "; + return false; + } + return true; +} + +inline bool File::close() +{ + 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 + fileName = ""; + 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 ); } @@ -62,20 +83,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; } @@ -83,33 +93,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 @@ -121,32 +122,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)) @@ -155,7 +143,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 ); } @@ -197,20 +170,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; } @@ -218,34 +180,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 @@ -257,24 +209,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; @@ -285,25 +230,48 @@ 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(); #endif } +inline bool fileExists( const String& fileName ) +{ + std::fstream file; + file.open( fileName.getString(), std::ios::in ); + 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/Functions/CMakeLists.txt b/src/TNL/Functions/CMakeLists.txt index 828720eb2e98718fa2e785c9023e0afd3d58af35..f596e3da6980356bbe1abd5c422b2a053872dd93 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 83ab81ced563fc77bea5a504a14b5ec10ce8a5b5..0000000000000000000000000000000000000000 --- 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 3a6b701f3d94ab947d3708d58184872818b2066b..0000000000000000000000000000000000000000 --- 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 3e7da8c33ddc00b236f75cfac25646741eb0e78d..f1776783c5da14a127d78cb84c5fba817db4bfcf 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 - diff --git a/src/TNL/Images/CMakeLists.txt b/src/TNL/Images/CMakeLists.txt index 9ffbdc0a0419f20f6cedc590ebe73f2c9fff9a86..d7a46f4022f16d57ea927a55a55238ea272a8908 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 89cf69ba7b1ac1f74eb680f642048fde9e8268c4..64f2b324e22c36170c14af8ff5d64e97082245d1 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 989f68626417c4ee58b920e08edfda828be120c2..1d5f10191a40db9cd129a2543f2dc2362df96a06 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 73b3128e889442eecce45978c74ae4ffb40a219f..02b80638ea80b3d22a866b12717caed662a59afe 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 b3ee1fb11c88f221512e6c27071f60fbdafddbc8..36e626ab6691a32b3c207d25aac294600b84ac65 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 b097a469aa28c4d65a89e1a13a976c2ba20178df..6f30a48f3876a7a196ef41b3e109bc870b3a6cdb 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 637555117a8f149b2009e05c9403ef0841be792b..3659ab243024ecf89e909edfd7582a920318a396 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 f384c947c661a5ad4a7319cc23e9321858f3cb54..3c930a5c8ad39c01bf51c6c0b2a989f17523d16e 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/Logger.cpp b/src/TNL/Logger.cpp deleted file mode 100644 index 988d4ed68edb1c9674b3370a978712bf3901edcd..0000000000000000000000000000000000000000 --- 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 7a6472bfae4e80e180b3ceabb03e9168a91543cd..d1f6c5c678c7c80c241e99f7d67d13f24403dabc 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 08181070f48b33ca691c93f1ae0b9b7b78a17d97..0e1dd8dc62434faf07b64a95f1f896ed9b8af940 100644 --- a/src/TNL/Logger_impl.h +++ b/src/TNL/Logger_impl.h @@ -13,29 +13,135 @@ #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 ) +{ +// 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; +} + +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 +149,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 diff --git a/src/TNL/Matrices/MatrixReader_impl.h b/src/TNL/Matrices/MatrixReader_impl.h index 2cfa66394e4bba3ecd62451fa686b8470a2453ac..eacf8911a149faed530f3fd6138051dfb2795071 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 @@ -93,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 ) @@ -142,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; @@ -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,10 +210,10 @@ 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 ); + std::getline( file, line ); if( ! headerParsed ) { headerParsed = checkMtxHeader( line, symmetric ); @@ -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; @@ -272,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 ) @@ -343,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 ) @@ -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/Meshes/Readers/TNLReader.h b/src/TNL/Meshes/Readers/TNLReader.h index ba602b0f97fda13115b171a46d9a3dd4d884c835..68f4d13a21c99bb2ce93bd6e0bdf2f0e32f1bcf4 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.h b/src/TNL/Object.h index 405bcd76d05ec1bafcfad6ed71bc04280f3d1659..04fc84113017fcee24e8047a5bf29080caa364e3 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,9 @@ 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 + +#include diff --git a/src/TNL/Object.cpp b/src/TNL/Object_impl.h similarity index 59% rename from src/TNL/Object.cpp rename to src/TNL/Object_impl.h index 0beb5431171fbdc8e1a8834176408966952ef275..70415f8e81d78c5bd326624961573dcb5cb8a5bd 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,46 +8,47 @@ /* See Copyright Notice in tnl/Copyright */ -#include -#include +#pragma once + #include #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 ) ) ) + if( ! file.write( magic_number, strlen( magic_number ) ) ) return false; - if( ! this->getSerializationTypeVirtual().save( file ) ) return false; + file << this->getSerializationTypeVirtual(); return true; } -bool Object :: load( File& file ) +inline bool Object :: load( File& file ) { String objectType; if( ! getObjectType( file, objectType ) ) @@ -60,15 +61,15 @@ 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 ) ) + if( ! file.open( fileName, IOMode::write ) ) { std::cerr << "I am not able to open the file " << fileName << " for writing." << std::endl; return false; @@ -76,10 +77,10 @@ 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 ) ) + if( ! file.open( fileName, IOMode::read ) ) { std::cerr << "I am not able to open the file " << fileName << " for reading." << std::endl; return false; @@ -87,10 +88,10 @@ 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 ) ) + if( ! file.open( fileName, IOMode::read ) ) { std::cerr << "I am not able to open the file " << fileName << " for reading." << std::endl; return false; @@ -99,32 +100,27 @@ 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 ) ) ) + 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 && - 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; } - if( ! type. load( file ) ) - { - std::cerr << "Cannot load the object type." << std::endl; - return false; - } + file >> 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 ) ) + 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; @@ -132,11 +128,11 @@ bool getObjectType( const String& fileName, String& type ) return getObjectType( binaryFile, type ); } -bool parseObjectType( const String& objectType, - Containers::List< String >& parsedObjectType ) +inline 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: @@ -145,11 +141,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.substr( 0, i ); + parsedObjectType.push_back( objectName ); + i++; /**** * Now, we will extract the parameters. @@ -162,7 +157,7 @@ bool parseObjectType( const String& objectType, while( i < objectTypeLength ) { if( objectType[ i ] == '<' ) - templateBrackets ++; + templateBrackets++; if( ! templateBrackets ) { if( objectType[ i ] == ',' || @@ -170,19 +165,19 @@ bool parseObjectType( const String& objectType, { if( buffer != "" ) { - if( ! parsedObjectType. Append( buffer.strip( ' ' ) ) ) - return false; - buffer. setString( "" ); + parsedObjectType.push_back( buffer.strip( ' ' ) ); + buffer.clear(); } } 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/Pointers/CMakeLists.txt b/src/TNL/Pointers/CMakeLists.txt index 6c69336cd29044deb7909e0dcc12291ec6d1f56f..d1cd9c47fe99b6b2b7334c853ef1f4069d328a0b 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 01641661c1ae008e6517232fc0bb56572f09ff5a..0000000000000000000000000000000000000000 --- 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 569d62138137459fa52137a7b2658b4216b61c3b..752eb672c96386e6ed5e05759e96049285b72350 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: diff --git a/src/TNL/Solvers/IterativeSolverMonitor_impl.h b/src/TNL/Solvers/IterativeSolverMonitor_impl.h index 4cc1d18432ca8f46ccf48e1abc700fe27b0afe38..0343da3ebaddc14449429cc27a71f62c7acdbc1c 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/Solvers/ODE/ExplicitSolver.h b/src/TNL/Solvers/ODE/ExplicitSolver.h index 4e20911de02879126c3b4360167cea39e5ae6343..c1431c0fb8a31f58985c5817ff327c1360756b6a 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 78f0b0e69dca0ab2e107a17a055cccc12f32dd60..04748c5889c8f6605093824254d12e297743c3cc 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 >:: diff --git a/src/TNL/Solvers/SolverConfig_impl.h b/src/TNL/Solvers/SolverConfig_impl.h index 598cee285a968ddfa4b4d5a1bde24bc7a382fc5d..701c5eb730b99e2487e56bd5e56a9ffdec0b916d 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 f848b774b1252f8abfff24fd3a97d71f3fbae8f3..e52d03a4f7377c5fc80ade50d7981a3a07a48f08 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 @@ -407,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:", "" ); diff --git a/src/TNL/String.cpp b/src/TNL/String.cpp deleted file mode 100644 index d814a662c32ab562cefbddac714186366568b5f4..0000000000000000000000000000000000000000 --- a/src/TNL/String.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/*************************************************************************** - String.cpp - description - ------------------- - begin : 2004/04/10 16:36 - copyright : (C) 2004 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#include -#include -#include -#include -#include -#include -#include -#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(); -} - -int String::getSize() const -{ - return strlen( string ); -} - -int String::getAllocatedSize() const -{ - return length; -} - -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; -} - -const char* String::getString() const -{ - return string; -} - -char* String::getString() -{ - return string; -} - - -const char& String::operator[]( int i ) const -{ - TNL_ASSERT( i >= 0 && i < length, - std::cerr << "Accessing char outside the string." ); - return string[ i ]; -} - -char& String::operator[]( int i ) -{ - TNL_ASSERT( i >= 0 && i < length, - std::cerr << "Accessing char outside the string." ); - return string[ i ]; -} - - -/**** - * Operators for C strings - */ -String& String::operator=( const char* str ) -{ - setString( str ); - return *this; -} - -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 ) ); - } - } - return *this; -} - -String String::operator+( const char* str ) const -{ - return String( *this ) += str; -} - -bool String::operator==( const char* str ) const -{ - TNL_ASSERT( string && str, ); - return strcmp( string, str ) == 0; -} - -bool String::operator!=( const char* str ) const -{ - return ! operator==( str ); -} - - -/**** - * Operators for Strings - */ -String& String::operator=( const String& str ) -{ - setString( str.getString() ); - return *this; -} - -String& String::operator+=( const String& str ) -{ - return operator+=( str.getString() ); -} - -String String::operator+( const String& str ) const -{ - return String( *this ) += str; -} - -bool String::operator==( const String& str ) const -{ - TNL_ASSERT( string && str.string, ); - return strcmp( string, str.string ) == 0; -} - -bool String::operator!=( const String& str ) const -{ - return ! operator==( str ); -} - - -/**** - * Operators for single characters - */ -String& String::operator=( char str ) -{ - string[ 0 ] = str; - string[ 1 ] = 0; - return *this; -} - -String& String::operator+=( const char 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; - } - - return *this; -} - -String String::operator+( char str ) const -{ - return String( *this ) += str; -} - -bool String::operator==( char str ) const -{ - return *this == convertToString( str ); -} - -bool String::operator!=( char str ) const -{ - return ! operator==( str ); -} - - -String::operator bool () const -{ - if( string[ 0 ] ) return true; - return false; -} - -bool String::operator!() const -{ - return ! operator bool(); -} - -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(); - - 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; - } - } - - newString[ newStringHead ] = 0; - - return newString; -} - -String -String::strip( char strip ) const -{ - int prefix_cut_off = 0; - int sufix_cut_off = 0; - - while( prefix_cut_off < getLength() && (*this)[ prefix_cut_off ] == strip ) - prefix_cut_off++; - - while( sufix_cut_off < getLength() && (*this)[ getLength() - 1 - sufix_cut_off ] == strip ) - sufix_cut_off++; - - if( prefix_cut_off + sufix_cut_off < getLength() ) - return String( getString(), prefix_cut_off, sufix_cut_off ); - return ""; -} - -int String::split( Containers::List< String >& list, - const char separator, - bool skipEmpty ) const -{ - list.reset(); - String s; - for( int i = 0; i < this->getLength(); i ++ ) - { - if( ( *this )[ i ] == separator ) - { - if( ! skipEmpty || s != "" ) - list.Append( s ); - s = ""; - } - else s += ( *this )[ i ]; - } - if( ! skipEmpty || s != "" ) - list.Append( s ); - return list.getSize(); -} - - -bool String::save( File& file ) const -{ - TNL_ASSERT( string, - std::cerr << "string = " << string ); - - int len = strlen( string ); - if( ! file.write( &len ) ) - return false; - if( ! file.write( string, 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; - } - setSize( _length ); - if( _length && ! file.read( string, _length ) ) { - std::cerr << "I was not able to read a String with a length " << length << "." << std::endl; - return false; - } - string[ _length ] = 0; - return true; -} - -/*void String :: MPIBcast( int root, MPI_Comm comm ) -{ -#ifdef USE_MPI - dbgFunctionName( "mString", "MPIBcast" ); - int iproc; - MPI_Comm_rank( MPI_COMM_WORLD, &iproc ); - TNL_ASSERT( string, ); - int len = strlen( string ); - MPI_Bcast( &len, 1, MPI_INT, root, comm ); - dbgExpr( iproc ); - dbgExpr( len ); - if( iproc != root ) - { - if( length < len ) - { - delete[] string; - length = STRING_PAGE * ( len / STRING_PAGE + 1 ); - string = new char[ length ]; - } - } - - MPI_Bcast( string, len + 1, MPI_CHAR, root, comm ); - dbgExpr( iproc ); - dbgExpr( string ); -#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 ) -{ - return convertToString( string1 ) + string2; -} - -String operator+( const char* string1, const String& string2 ) -{ - return String( string1 ) + string2; -} - -std::ostream& operator<<( std::ostream& stream, const String& str ) -{ - stream << str.getString(); - return stream; -} - -} // namespace TNL diff --git a/src/TNL/String.h b/src/TNL/String.h index 9e2fb201d0af02d3573d0f03b37c32cddf1e3ee2..9bad1c4ebc2b40a546c23c1831799c50e1ecb1c7 100644 --- a/src/TNL/String.h +++ b/src/TNL/String.h @@ -12,19 +12,13 @@ #include #include +#include +#include namespace TNL { -class File; -namespace Containers { - template< class T > class List; -} - class String; -template< typename T > -String convertToString( const T& value ); - ///// /// \brief Class for managing strings. /// @@ -33,245 +27,194 @@ 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 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; - - ///// - /// \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; + + //! 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 ); @@ -279,6 +222,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 ); @@ -288,7 +234,7 @@ String convertToString( const T& value ) std::stringstream str; str << value; return String( str.str().data() ); -}; +} template<> inline String convertToString( const bool& b ) { @@ -297,3 +243,5 @@ template<> inline String convertToString( const bool& b ) } } // namespace TNL + +#include diff --git a/src/TNL/String_impl.h b/src/TNL/String_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..17ba9359d5aa907d2ba0f472cdb077147ee7729c --- /dev/null +++ b/src/TNL/String_impl.h @@ -0,0 +1,286 @@ +/*************************************************************************** + String_impl.h - description + ------------------- + begin : 2004/04/10 16:36 + copyright : (C) 2004 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include +#include +#include +//#ifdef USE_MPI +// #include +//#endif + +namespace TNL { + +inline String String::getType() +{ + return String( "String" ); +} + +inline int String::getLength() const +{ + return getSize(); +} + +inline int String::getSize() const +{ + return this->size(); +} + +inline int String::getAllocatedSize() const +{ + return this->capacity(); +} + +inline void String::setSize( int size ) +{ + TNL_ASSERT_GE( size, 0, "string size must be non-negative" ); + this->reserve( size ); +} + +inline const char* String::getString() const +{ + return this->c_str(); +} + + +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 ); +} + +inline char& String::operator[]( int i ) +{ + TNL_ASSERT( i >= 0 && i < getLength(), + std::cerr << "Accessing char outside the string." ); + return std::string::operator[]( i ); +} + + +/**** + * Operators for single characters + */ +inline String& String::operator+=( char str ) +{ + std::string::operator+=( str ); + return *this; +} + +inline String String::operator+( char str ) const +{ + return String( *this ) += str; +} + +inline bool String::operator==( char str ) const +{ + return std::string( *this ) == std::string( 1, str ); +} + +inline bool String::operator!=( char str ) const +{ + return ! operator==( str ); +} + + +/**** + * Operators for C strings + */ +inline String& String::operator+=( const char* str ) +{ + std::string::operator+=( str ); + return *this; +} + +inline String String::operator+( const char* str ) const +{ + return String( *this ) += str; +} + +inline bool String::operator==( const char* str ) const +{ + return std::string( *this ) == str; +} + +inline bool String::operator!=( const char* str ) const +{ + return ! operator==( str ); +} + + +/**** + * Operators for std::string + */ +inline String& String::operator+=( const std::string& str ) +{ + std::string::operator+=( str ); + return *this; +} + +inline String String::operator+( const std::string& str ) const +{ + return String( *this ) += str; +} + +inline bool String::operator==( const std::string& str ) const +{ + return std::string( *this ) == str; +} + +inline bool String::operator!=( const std::string& str ) const +{ + return ! operator==( str ); +} + + +/**** + * Operators for String + */ +inline String& String::operator+=( const String& str ) +{ + std::string::operator+=( str ); + return *this; +} + +inline String String::operator+( const String& str ) const +{ + return String( *this ) += str; +} + +inline bool String::operator==( const String& str ) const +{ + return std::string( *this ) == str; +} + +inline bool String::operator!=( const String& str ) const +{ + return ! operator==( str ); +} + + +inline String::operator bool () const +{ + return getLength(); +} + +inline bool String::operator!() const +{ + return ! operator bool(); +} + +inline String +String::replace( const String& pattern, + const String& replaceWith, + int count ) const +{ + std::string newString = *this; + + 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; + + // make the replacement + newString.replace( index, pattern.getLength(), replaceWith ); + index += replaceWith.getLength(); + } + + return newString; +} + +inline String +String::strip( char strip ) const +{ + int prefix_cut_off = 0; + int sufix_cut_off = 0; + + while( prefix_cut_off < getLength() && (*this)[ prefix_cut_off ] == strip ) + prefix_cut_off++; + + while( sufix_cut_off < getLength() && (*this)[ getLength() - 1 - sufix_cut_off ] == strip ) + sufix_cut_off++; + + if( prefix_cut_off + sufix_cut_off < getLength() ) + return substr( prefix_cut_off, getLength() - prefix_cut_off - sufix_cut_off ); + return ""; +} + +inline std::vector< String > +String::split( const char separator, bool skipEmpty ) const +{ + std::vector< String > parts; + String s; + for( int i = 0; i < this->getLength(); i++ ) { + if( ( *this )[ i ] == separator ) { + if( ! skipEmpty || s != "" ) + parts.push_back( s ); + s = ""; + } + else s += ( *this )[ i ]; + } + if( ! skipEmpty || s != "" ) + parts.push_back( s ); + return parts; +} + +/* +inline void String :: MPIBcast( int root, MPI_Comm comm ) +{ +#ifdef USE_MPI + dbgFunctionName( "mString", "MPIBcast" ); + int iproc; + MPI_Comm_rank( MPI_COMM_WORLD, &iproc ); + TNL_ASSERT( string, ); + int len = strlen( string ); + MPI_Bcast( &len, 1, MPI_INT, root, comm ); + dbgExpr( iproc ); + dbgExpr( len ); + if( iproc != root ) + { + if( length < len ) + { + delete[] string; + length = STRING_PAGE * ( len / STRING_PAGE + 1 ); + string = new char[ length ]; + } + } + + MPI_Bcast( string, len + 1, MPI_CHAR, root, comm ); + dbgExpr( iproc ); + dbgExpr( string ); +#endif +} +*/ + +inline String operator+( char string1, const String& string2 ) +{ + return convertToString( string1 ) + string2; +} + +inline String operator+( const char* string1, const String& string2 ) +{ + return String( string1 ) + string2; +} + +inline String operator+( const std::string& string1, const String& string2 ) +{ + return String( string1 ) + string2; +} + +inline std::ostream& operator<<( std::ostream& stream, const String& str ) +{ + stream << str.getString(); + return stream; +} + +} // namespace TNL diff --git a/src/TNL/Timer.h b/src/TNL/Timer.h index a2e01ea8eea32d53a072fbf9ab866a6ca4f499ab..7f2331f185817ba42aa84b3f36e8c0ce9a0dbae5 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,8 +132,6 @@ class Timer } }; -// !!! Odstranit ???!!! -extern Timer defaultTimer; - } // namespace TNL +#include diff --git a/src/TNL/Timer.cpp b/src/TNL/Timer_impl.h similarity index 60% rename from src/TNL/Timer.cpp rename to src/TNL/Timer_impl.h index 2d11949edc05706fd5d6200faf84e7f263bed921..5a1cec336efcb1b226949064a62a9f573eb1ee61 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,40 +8,36 @@ /* See Copyright Notice in tnl/Copyright */ +#pragma once + #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 -#ifdef HAVE_SYS_TIME_H - #include - #include - #define HAVE_TIME -#endif namespace TNL { -Timer defaultTimer; - -Timer::Timer() +inline Timer::Timer() { reset(); } -void Timer::reset() +inline 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; } -void Timer::stop() +inline void Timer::stop() { if( ! this->stopState ) @@ -53,7 +49,7 @@ void Timer::stop() } } -void Timer::start() +inline void Timer::start() { this->initialRealTime = this->readRealTime(); this->initialCPUTime = this->readCPUTime(); @@ -61,41 +57,35 @@ void Timer::start() this->stopState = false; } -double Timer::getRealTime() const +inline 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 +inline 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 +inline 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 +inline 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 +inline 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; @@ -104,13 +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(); } +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 ); diff --git a/src/TNL/param-types.h b/src/TNL/param-types.h index 333f3620ea79175dd19e94a058dd713555fcfc59..e7552d84891126b08251a99b5618341c9019f20b 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,50 +18,70 @@ 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" ); }; -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 diff --git a/src/Tools/CMakeLists.txt b/src/Tools/CMakeLists.txt index 3dc914c9d0ed8e3feac4c463cd3ab23e05a32833..787bf40bf96f7d74cfcfad26f370323e6607fac0 100644 --- a/src/Tools/CMakeLists.txt +++ b/src/Tools/CMakeLists.txt @@ -1,35 +1,28 @@ 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 ) -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} ) +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 tnl ${DCMTK_LIBRARIES} ) - -ADD_EXECUTABLE(tnl-lattice-init tnl-lattice-init.cpp ) -target_link_libraries (tnl-lattice-init tnl ) +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 ) @@ -51,7 +44,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-dicom-reader.cpp b/src/Tools/tnl-dicom-reader.cpp index 5b38b123092ccadf5c1d0fab1df842e7d258640a..55a66b7a6c85ac86888beb9c700e50e8cccc0e19 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/src/Tools/tnl-diff.cpp b/src/Tools/tnl-diff.cpp index 611cd53f4a03e58bc076fea1f54896c9b80ff6ed..360423de72b98ff0d49c54fd04bd4f068773c915 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 b070d0dfeb92980ce9c98b837dbde9782062b7f6..47d058de1695bc85ef05f47ee288a3140de3b564 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 29c633058d69250965293681a2d010b9349eb5e4..f06ba841df524c4bd7522b81dc947f8080c0debe 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 7dd7032810794f5f2ee43023472be6773fcb2de6..0695d62e106b6959c852f96c27f7a398025e4202 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 3f2a8f15fd01df8c61785ffae155ccf84ac86ddd..5530ee5ad5a68107242c01092409d77bee2ac196 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 b22e71f96ad7c8e31e18cc22a35105cab31723e8..0b42a72ead2ea71758697dbf70190fb15639094c 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-link.in b/src/Tools/tnl-link.in deleted file mode 100644 index 8be63b0f4d67cd7b2ed91b66902c28d64da47d01..0000000000000000000000000000000000000000 --- 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 c2954e00e8f855f14bd52eda44fc77f95c8a9416..cc9e46b4b232d248280c48c47998466694f3f48d 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) diff --git a/src/Tools/tnl-view.h b/src/Tools/tnl-view.h index c231d606dd064a6e96730d7698d0043871bda693..b5fa04ba97abe3afc877d74b24de93e964e62e26 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/CMakeLists.txt b/src/UnitTests/CMakeLists.txt index 7c395873644619a90e18c32fe9be5f0072961deb..95cca1efb985fb9ce1f29af994ab39c1d2ffc8af 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/ArrayOperationsTest.h b/src/UnitTests/Containers/ArrayOperationsTest.h index aff044601cfcc326fa43134d6da5d903cdabf5f5..9487475418914432a52648ff3957477f2049627f 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 f92954df3be4b2bb850859cad143f1ec9d0daae2..9e4b1f572d2ffd98de22fdca495a0ba4aa56f0a8 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 2fa6fb3afd551dabf3b26386004096ce5028226a..ccc9ba9f03c0aa7145473c03f46ae3014147e35a 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 7e7c39717b90ee2d63f16f3d3ba87371c1c5ca12..fe75ed458bad9e8e8314a4e351e86dcfc6870bea 100644 --- a/src/UnitTests/Containers/CMakeLists.txt +++ b/src/UnitTests/Containers/CMakeLists.txt @@ -1,103 +1,71 @@ 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 ) -ELSE( BUILD_CUDA ) + 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 ) +ADD_EXECUTABLE( ArrayTest ArrayTest.cpp ) +TARGET_COMPILE_OPTIONS( ArrayTest PRIVATE ${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} - tnl ) -ELSE( BUILD_CUDA ) - ADD_EXECUTABLE( ArrayTest ArrayTest.cpp ) - TARGET_COMPILE_OPTIONS( ArrayTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayTest - ${GTEST_BOTH_LIBRARIES} - tnl ) - - ADD_EXECUTABLE( ArrayViewTest ArrayViewTest.cpp ) - TARGET_COMPILE_OPTIONS( ArrayViewTest PRIVATE ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( ArrayViewTest - ${GTEST_BOTH_LIBRARIES} - tnl ) -ENDIF( BUILD_CUDA ) - -ADD_EXECUTABLE( StaticArrayTest StaticArrayTest.cpp ) -TARGET_COMPILE_OPTIONS( StaticArrayTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( StaticArrayTest - ${GTEST_BOTH_LIBRARIES} - tnl ) +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} - tnl ) -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( 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} - tnl ) -ELSE( BUILD_CUDA ) + 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( 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} - 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 ) @@ -105,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} ) @@ -119,27 +92,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 5fb63a52191ede8885ca920420a991175f867823..0cf3ae746674680d5858c7e6f11f2ba42b7f0437 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/Containers/VectorTest.h b/src/UnitTests/Containers/VectorTest.h index 81242fe1ad2e030bc22b864c76cd77b6da72b38f..05df280d64dfaab839f38e0813c624e13fa359b1 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 >, diff --git a/src/UnitTests/FileTest.h b/src/UnitTests/FileTest.h index b1385f4122924185cfa898b569238e0118aa84af..4da7418924b5b8e0089bac8f53b8daeb627f91bc 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; @@ -81,7 +87,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 +105,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 ); diff --git a/src/UnitTests/Functions/CMakeLists.txt b/src/UnitTests/Functions/CMakeLists.txt index cf9466de4525130a3ba2c6c0f9dd3c3bd988af8c..f49f346c9e5ec262c32b4279451915b94c62d0a3 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 8e4d0a5c1e1d0e4cffc539f644be03273c8ed3e5..adc2c6dbbfcaaf9dcf616e3c0f1c65af24cfe8b2 100644 --- a/src/UnitTests/Matrices/CMakeLists.txt +++ b/src/UnitTests/Matrices/CMakeLists.txt @@ -1,51 +1,90 @@ IF( BUILD_CUDA ) - CUDA_ADD_EXECUTABLE( SparseMatrixCopyTest SparseMatrixCopyTest.h SparseMatrixCopyTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) - TARGET_LINK_LIBRARIES( SparseMatrixCopyTest ${GTEST_BOTH_LIBRARIES} - tnl ) + 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} ) - TARGET_LINK_LIBRARIES( SparseMatrixTest ${GTEST_BOTH_LIBRARIES} - tnl ) + 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} ) - TARGET_LINK_LIBRARIES( DenseMatrixTest ${GTEST_BOTH_LIBRARIES} - tnl ) + 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} - tnl ) + 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} - tnl ) + TARGET_LINK_LIBRARIES( SparseMatrixTest ${GTEST_BOTH_LIBRARIES} ) + + 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.h DenseMatrixTest.cpp ) + ADD_EXECUTABLE( DenseMatrixTest 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 ) 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} ) +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} ) 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/Matrices/SparseMatrixTest.h b/src/UnitTests/Matrices/SparseMatrixTest.h index 1145570b2df29ef8de343f7ca17f161d3a4cf0db..78121bdf2af3f278b936e71c75225e17efe53073 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 0000000000000000000000000000000000000000..563a3dc2686b30d8d73dda8a37d2187508139b16 --- /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 0000000000000000000000000000000000000000..563a3dc2686b30d8d73dda8a37d2187508139b16 --- /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 0000000000000000000000000000000000000000..24b4db1b2d14cf744232c78aab3f1c6dceb8b402 --- /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 0000000000000000000000000000000000000000..ccb62e4a87cb3abada95e807bca652106fb92538 --- /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 0000000000000000000000000000000000000000..ccb62e4a87cb3abada95e807bca652106fb92538 --- /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 0000000000000000000000000000000000000000..a18e7cc52c266db532949abe8b41a14048196c8e --- /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 0000000000000000000000000000000000000000..258ad2c53831010111eeec9dc240368ae5dffb35 --- /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 0000000000000000000000000000000000000000..258ad2c53831010111eeec9dc240368ae5dffb35 --- /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 0000000000000000000000000000000000000000..2eaecc76e78cbbe7925dbab4f4572e2c3504253c --- /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 0000000000000000000000000000000000000000..c09609ae6c664298693799efe3751ca082e2d129 --- /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 0000000000000000000000000000000000000000..c09609ae6c664298693799efe3751ca082e2d129 --- /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 0000000000000000000000000000000000000000..99ad9f0b45ddef8f1e996f6dd08409498a807562 --- /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 0000000000000000000000000000000000000000..c454706f0b1d437b798f2d7a1e93ccf4c0291d3f --- /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 0000000000000000000000000000000000000000..c454706f0b1d437b798f2d7a1e93ccf4c0291d3f --- /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 0000000000000000000000000000000000000000..c6ecd72b384eee16fb2ee3ee6fa0b558f775a1cd --- /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 0000000000000000000000000000000000000000..40e2e94b81ca64051ddceee82f46dd2d20e66e42 --- /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 0000000000000000000000000000000000000000..40e2e94b81ca64051ddceee82f46dd2d20e66e42 --- /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 0000000000000000000000000000000000000000..0fc1f59e2f7369adc793f3e2c7094f42288c7f39 --- /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 +} diff --git a/src/UnitTests/Meshes/CMakeLists.txt b/src/UnitTests/Meshes/CMakeLists.txt index 9cc6ed47eefe673b427c392b8bf0cd4008364984..c71bde352dc80832dc9dce44a896905372635579 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 ad4127dbd724d0fba9cc03bc21e065e3ae91c179..068c0485a0e417a5108864e78119794c68a19b4d 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/ObjectTest.cpp b/src/UnitTests/ObjectTest.cpp index 7b9badd8f9d14ce3a9af45249efe9360b07b2e69..488f7a49756727fd9314a50413d3f40f85a70172 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 diff --git a/src/UnitTests/Pointers/CMakeLists.txt b/src/UnitTests/Pointers/CMakeLists.txt index bd727636361f20d3516b26a81b1e3f48d9beeaaf..0f5e9865610e99d48699b35b8b9fd96fd8352877 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/src/UnitTests/StringTest.cpp b/src/UnitTests/StringTest.cpp index 389c208e7f83d67a16ff0d70dace341976f55444..10c85497b0044d03653b91cdc8b8729862158074 100644 --- a/src/UnitTests/StringTest.cpp +++ b/src/UnitTests/StringTest.cpp @@ -16,7 +16,6 @@ #include #include -#include using namespace TNL; @@ -24,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 ) @@ -47,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 ) @@ -58,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 ) @@ -89,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 ) @@ -146,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" ); @@ -181,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 ); @@ -206,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" ); @@ -222,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' ); @@ -258,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 ); } @@ -286,46 +260,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 ) @@ -333,32 +307,16 @@ 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 ); }; -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" diff --git a/tests/long-time-unit-tests/CMakeLists.txt b/tests/long-time-unit-tests/CMakeLists.txt index 61065e506d15b869237982dfce6eaad84aa548c9..9a3b0cafb1b3122228654c9272e7d3cf26743539 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 96f461a3cda8b415abb7ba6a0c16821cdf9f2578..53aab9037a75ecd281e6ecbf72a75361ae5aaf9d 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 ) diff --git a/tnlConfig.h.in b/tnlConfig.h.in deleted file mode 100644 index 967ce8e268db25a1be0acf9edb95f81277c3786a..0000000000000000000000000000000000000000 --- a/tnlConfig.h.in +++ /dev/null @@ -1,13 +0,0 @@ -@HAVE_SYS_TIME_H@ - -@HAVE_SYS_RESOURCE_H@ - -@HAVE_SYS_IOCTL_H@ - -@HAVE_DCMTK_H@ - -@HAVE_PNG_H@ - -@HAVE_JPEG_H@ - -#define TNL_CPP_COMPILER_NAME "@CMAKE_CXX_COMPILER_ID@ @CMAKE_CXX_COMPILER_VERSION@"