diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f412e0eed12819cf2d9f7e233ea9bee6ac459e5..ecbe2de6115d175969526e0764bd9ba8818badcc 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ # Vladimir Klement # Jakub Klinkovsky -cmake_minimum_required( VERSION 3.0 ) +cmake_minimum_required( VERSION 3.4 ) project( tnl ) @@ -33,7 +33,6 @@ if( CMAKE_BUILD_TYPE STREQUAL "Debug") set( LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/Debug/lib ) set( EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/Debug/bin ) set( debugExt -dbg ) - set( CMAKE_CXX_FLAGS "${CXXFLAGS} -g ") else() set( PROJECT_BUILD_PATH ${PROJECT_SOURCE_DIR}/Release/src ) set( PROJECT_TESTS_PATH ${PROJECT_SOURCE_DIR}/Release/tests ) @@ -41,10 +40,12 @@ else() set( LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/Release/lib) set( EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/Release/bin) endif() + # set Debug/Release options set( CMAKE_CXX_FLAGS "-std=c++11" ) set( CMAKE_CXX_FLAGS_DEBUG "-g" ) -set( CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG -g" ) +set( CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG" ) +#set( CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG -ftree-vectorizer-verbose=1 -ftree-vectorize -fopt-info-vec-missed -funroll-loops" ) # pass -rdynamic only in Debug mode set( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "" ) set( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS_DEBUG "-rdynamic" ) @@ -65,8 +66,8 @@ if( WITH_CUDA STREQUAL "yes" ) set( BUILD_CUDA TRUE) set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF) set(BUILD_SHARED_LIBS ON) - set(CUDA_SEPARABLE_COMPILATION ON) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ; -DHAVE_CUDA ) + set(CUDA_SEPARABLE_COMPILATION ON) + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ;-DHAVE_CUDA ) #AddCompilerFlag( "-DHAVE_NOT_CXX11" ) # -U_GLIBCXX_ATOMIC_BUILTINS -U_GLIBCXX_USE_INT128 " ) set( ALL_CUDA_ARCHS -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 @@ -110,6 +111,9 @@ if( WITH_CUDA STREQUAL "yes" ) set( CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ; ${CUDA_ARCH} ) # TODO: this is necessary only due to a bug in cmake set( CUDA_ADD_LIBRARY_OPTIONS -shared ) + # TODO: workaround for a bug in cmake 3.5.0 (fixed in 3.5.1) + set( CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ; -ccbin "${CMAKE_CXX_COMPILER}" ) + set( CUDA_HOST_COMPILER "" ) #### # Check for cuBLAS @@ -152,7 +156,7 @@ if( WITH_CUDA STREQUAL "yes" ) cuda_include_directories( ${CUSPARSE_INCLUDE_DIR} ) set( CUSPARSE_LIBRARY "${CUDA_cusparse_LIBRARY}" ) endif() - endif( NOT WITH_CUSPARSE STREQUAL "no" ) + endif( NOT WITH_CUSPARSE STREQUAL "no" ) endif( CUDA_FOUND ) endif( WITH_CUDA STREQUAL "yes" ) diff --git a/examples/navier-stokes/navierStokesBoundaryConditions_impl.h b/examples/navier-stokes/navierStokesBoundaryConditions_impl.h index 40a22ffa9e7a5cf040b7c84614bf9c9f3ac6c7ad..99b16931c1d3ecc36ab52e14b3068c8d050175a0 100644 --- a/examples/navier-stokes/navierStokesBoundaryConditions_impl.h +++ b/examples/navier-stokes/navierStokesBoundaryConditions_impl.h @@ -31,11 +31,11 @@ navierStokesBoundaryConditions< Mesh >::navierStokesBoundaryConditions() template< typename Mesh > bool navierStokesBoundaryConditions< Mesh >::setup( const tnlParameterContainer& parameters ) { - this -> maxInflowVelocity = parameters. getParameter< double >( "max-inflow-velocity" ); - //this -> maxOutflowVelocity = parameters. getParameter< double >( "max-outflow-velocity" ); - this -> startUp = parameters. getParameter< double >( "start-up" ); - this -> T = parameters. getParameter< double >( "T" ); - this -> R = parameters. getParameter< double >( "R" ); + this->maxInflowVelocity = parameters. getParameter< double >( "max-inflow-velocity" ); + //this->maxOutflowVelocity = parameters. getParameter< double >( "max-outflow-velocity" ); + this->startUp = parameters. getParameter< double >( "start-up" ); + this->T = parameters. getParameter< double >( "T" ); + this->R = parameters. getParameter< double >( "R" ); this->p0 = parameters. getParameter< double >( "p0" ); this->gamma = parameters. getParameter< double >( "gamma" ); return true; @@ -67,8 +67,8 @@ void navierStokesBoundaryConditions< Mesh >::apply( const RealType& time, const RealType hx = this->mesh->getParametricStep().x(); const RealType hy = this->mesh->getParametricStep().y(); RealType startUpCoefficient( 1.0 ); - if( this -> startUp != 0.0 ) - startUpCoefficient = Min( ( RealType ) 1.0, time / this -> startUp ); + if( this->startUp != 0.0 ) + startUpCoefficient = Min( ( RealType ) 1.0, time / this->startUp ); for( IndexType i = 0; i < xSize; i ++ ) { @@ -86,14 +86,14 @@ void navierStokesBoundaryConditions< Mesh >::apply( const RealType& time, { u1[ c1 ] = 0; u2[ c1 ] = 0; - u1[ c3 ] = sin( M_PI * x ) * startUpCoefficient * this -> maxInflowVelocity; + u1[ c3 ] = sin( M_PI * x ) * startUpCoefficient * this->maxInflowVelocity; u2[ c3 ] = 0; rho[ c1 ] = rho[ c2 ]; rho[ c3 ] = rho[ c4 ]; energy[ c1 ] = energy[ c2 ]; energy[ c3 ] = energy[ c4 ]; - //rho[ c3 ] = this -> p_0 / ( this -> R * this -> T ); + //rho[ c3 ] = this->p_0 / ( this->R * this->T ); } } for( IndexType j = 0; j < ySize; j ++ ) @@ -122,10 +122,10 @@ void navierStokesBoundaryConditions< Mesh >::apply( const RealType& time, energy[ c1 ] = this->p0 / ( this->gamma - 1.0 ); //energy[ c2 ];// - tau*( energy[ c2 ] - energy[ c1 ] ) / hx; energy[ c3 ] = this->p0 / ( this->gamma - 1.0 ); //energy[ c4 ];// - tau*( energy[ c3 ] - energy[ c4 ] ) / hx; } - /*rho_u1[ c1 ] = rho[ c1 ] * this -> u1[ c1 ]; - rho_u2[ c1 ] = rho[ c1 ] * this -> u2[ c1 ]; - rho_u1[ c3 ] = rho[ c3 ] * this -> u1[ c3 ]; - rho_u2[ c3 ] = rho[ c3 ] * this -> u2[ c3 ];*/ + /*rho_u1[ c1 ] = rho[ c1 ] * this->u1[ c1 ]; + rho_u2[ c1 ] = rho[ c1 ] * this->u2[ c1 ]; + rho_u1[ c3 ] = rho[ c3 ] * this->u1[ c3 ]; + rho_u2[ c3 ] = rho[ c3 ] * this->u2[ c3 ];*/ } } diff --git a/examples/navier-stokes/navierStokesSolverMonitor_impl.h b/examples/navier-stokes/navierStokesSolverMonitor_impl.h index db69fe7b212a453a43b0e7c2cbae5a50060a7dec..dbaf40c9da3796d54e719bca4d6fb6ace98b54f1 100644 --- a/examples/navier-stokes/navierStokesSolverMonitor_impl.h +++ b/examples/navier-stokes/navierStokesSolverMonitor_impl.h @@ -30,7 +30,7 @@ navierStokesSolverMonitor< Real, Index > :: navierStokesSolverMonitor() template< typename Real, typename Index > void navierStokesSolverMonitor< Real, Index > :: refresh() { - if( this -> verbose > 0 && this -> refresRate % this -> refreshRate == 0 ) + if( this->verbose > 0 && this->refresRate % this->refreshRate == 0 ) { cout << "V=( " << uMax << " , " << uAvg diff --git a/examples/navier-stokes/navierStokesSolver_impl.h b/examples/navier-stokes/navierStokesSolver_impl.h index f10e8eb64c7f157f8dd2426baa8e65e51e9f55af..af5d256c17650b67d9b589813d611b5df3ff493d 100644 --- a/examples/navier-stokes/navierStokesSolver_impl.h +++ b/examples/navier-stokes/navierStokesSolver_impl.h @@ -147,8 +147,8 @@ bool navierStokesSolver< Mesh, EulerScheme >::setup( const tnlParameterContainer cerr << "Error: height must be positive real number! It is " << proportions. y() << " now." << endl; return false; } - this -> mesh. setOrigin( tnlStaticVector< 2, RealType >( 0, 0 ) ); - this -> mesh. setProportions( proportions ); + this->mesh. setOrigin( tnlStaticVector< 2, RealType >( 0, 0 ) ); + this->mesh. setProportions( proportions ); if( ! this->initMesh( this->mesh, parameters ) ) return false; @@ -187,15 +187,15 @@ bool navierStokesSolver< Mesh, EulerScheme >::setup( const tnlParameterContainer */ pressureGradient.setFunction( nsSolver.getPressure() ); - pressureGradient.bindMesh( this -> mesh ); - this->eulerScheme. bindMesh( this -> mesh ); - this->eulerScheme. setPressureGradient( this -> pressureGradient ); - this->u1Viscosity. bindMesh( this -> mesh ); - this->u1Viscosity. setFunction( this -> nsSolver.getU1() ); - this->u2Viscosity. bindMesh( this -> mesh ); - this->u2Viscosity. setFunction( this -> nsSolver.getU2() ); - this->eViscosity. bindMesh( this -> mesh ); - this->eViscosity.setFunction( this -> nsSolver.getEnergy() ); + pressureGradient.bindMesh( this->mesh ); + this->eulerScheme. bindMesh( this->mesh ); + this->eulerScheme. setPressureGradient( this->pressureGradient ); + this->u1Viscosity. bindMesh( this->mesh ); + this->u1Viscosity. setFunction( this->nsSolver.getU1() ); + this->u2Viscosity. bindMesh( this->mesh ); + this->u2Viscosity. setFunction( this->nsSolver.getU2() ); + this->eViscosity. bindMesh( this->mesh ); + this->eViscosity.setFunction( this->nsSolver.getEnergy() ); nsSolver.setAdvectionScheme( this->eulerScheme ); nsSolver.setDiffusionScheme( this->u1Viscosity, this->u2Viscosity, @@ -244,7 +244,7 @@ bool navierStokesSolver< Mesh, EulerScheme > :: setInitialCondition( const tnlPa template< typename Mesh, typename EulerScheme > typename navierStokesSolver< Mesh, EulerScheme > :: DofVectorType& navierStokesSolver< Mesh, EulerScheme > :: getDofVector() { - return this -> dofVector; + return this->dofVector; } template< typename Mesh, typename EulerScheme > diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 942dc176e05bcc5dd6db68afba49015699a6f1ba..ba9da977671d770fc9d6fa0eaf265b01400a0549 100755 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -15,17 +15,20 @@ set (headers tnlAssert.h tnlDynamicTypeTag.h tnlFeature.h tnlFile.h + tnlFile_impl.h tnlFlopsCounter.h tnlHost.h tnlIndexedSet.h tnlList.h - tnlLogger.h + tnlList_impl.h + tnlLogger.h tnlObject.h tnlStack.h tnlStaticFor.h tnlStatistics.h tnlString.h tnlReal.h + tnlTimer.h tnlTimerCPU.h tnlTimerRT.h mfilename.h @@ -45,11 +48,12 @@ set( common_SOURCES ${CURRENT_DIR}/tnlObject.cpp ${CURRENT_DIR}/tnlStatistics.cpp ${CURRENT_DIR}/tnlString.cpp + ${CURRENT_DIR}/tnlTimer.cpp ${CURRENT_DIR}/tnlTimerCPU.cpp ${CURRENT_DIR}/mfilename.cpp ${CURRENT_DIR}/mpi-supp.cpp ${CURRENT_DIR}/tnlCuda.cpp - ${CURRENT_DIR}/tnlHost.cpp ) + ${CURRENT_DIR}/tnlHost.cpp ) IF( BUILD_CUDA ) set( tnl_core_CUDA__SOURCES diff --git a/src/core/arrays/tnlArray_impl.h b/src/core/arrays/tnlArray_impl.h index 06bbc013c31faa86885b0e72fc25e52749cf7c61..0e0aa9c6a2dda92192e8ffd56e3d90948d41a314 100644 --- a/src/core/arrays/tnlArray_impl.h +++ b/src/core/arrays/tnlArray_impl.h @@ -189,7 +189,7 @@ setSize( const Index size ) { cerr << "I am not able to allocate new array with size " << ( double ) this->size * sizeof( ElementType ) / 1.0e9 << " GB." << endl; - this -> size = 0; + this->size = 0; return false; } return true; @@ -304,7 +304,7 @@ Index tnlArray< Element, Device, Index >:: getSize() const { - return this -> size; + return this->size; } template< typename Element, @@ -314,11 +314,11 @@ void tnlArray< Element, Device, Index >:: setElement( const Index& i, const Element& x ) { - tnlAssert( 0 <= i && i < this -> getSize(), + tnlAssert( 0 <= i && i < this->getSize(), cerr << "Wrong index for setElement method in tnlArray " << " index is " << i - << " and array size is " << this -> getSize() ); - return tnlArrayOperations< Device > :: setMemoryElement( &( this -> data[ i ] ), x ); + << " and array size is " << this->getSize() ); + return tnlArrayOperations< Device > :: setMemoryElement( &( this->data[ i ] ), x ); }; template< typename Element, @@ -328,11 +328,11 @@ Element tnlArray< Element, Device, Index >:: getElement( const Index& i ) const { - tnlAssert( 0 <= i && i < this -> getSize(), + tnlAssert( 0 <= i && i < this->getSize(), cerr << "Wrong index for getElement method in tnlArray " << " index is " << i - << " and array size is " << this -> getSize() ); - return tnlArrayOperations< Device > :: getMemoryElement( & ( this -> data[ i ] ) ); + << " and array size is " << this->getSize() ); + return tnlArrayOperations< Device > :: getMemoryElement( & ( this->data[ i ] ) ); }; template< typename Element, @@ -343,10 +343,10 @@ inline Element& tnlArray< Element, Device, Index >:: operator[] ( const Index& i ) { - tnlAssert( 0 <= i && i < this -> getSize(), + tnlAssert( 0 <= i && i < this->getSize(), cerr << "Wrong index for operator[] in tnlArray " << " index is " << i - << " and array size is " << this -> getSize() ); + << " and array size is " << this->getSize() ); return this->data[ i ]; }; @@ -358,10 +358,10 @@ inline const Element& tnlArray< Element, Device, Index >:: operator[] ( const Index& i ) const { - tnlAssert( 0 <= i && i < this -> getSize(), + tnlAssert( 0 <= i && i < this->getSize(), cerr << "Wrong index for operator[] in tnlArray " << " index is " << i - << " and array size is " << this -> getSize() ); + << " and array size is " << this->getSize() ); return this->data[ i ]; }; @@ -372,14 +372,14 @@ tnlArray< Element, Device, Index >& tnlArray< Element, Device, Index >:: operator = ( const tnlArray< Element, Device, Index >& array ) { - tnlAssert( array. getSize() == this -> getSize(), + tnlAssert( array. getSize() == this->getSize(), cerr << "Source size: " << array. getSize() << endl - << "Target size: " << this -> getSize() << endl ); + << "Target size: " << this->getSize() << endl ); tnlArrayOperations< Device > :: template copyMemory< Element, Element, Index > - ( this -> getData(), + ( this->getData(), array. getData(), array. getSize() ); return ( *this ); @@ -393,15 +393,15 @@ tnlArray< Element, Device, Index >& tnlArray< Element, Device, Index >:: operator = ( const Array& array ) { - tnlAssert( array. getSize() == this -> getSize(), + tnlAssert( array. getSize() == this->getSize(), cerr << "Source size: " << array. getSize() << endl - << "Target size: " << this -> getSize() << endl ); + << "Target size: " << this->getSize() << endl ); tnlArrayOperations< Device, typename Array :: DeviceType > :: template copyMemory< Element, typename Array :: ElementType, typename Array :: IndexType > - ( this -> getData(), + ( this->getData(), array. getData(), array. getSize() ); return ( *this ); @@ -415,14 +415,14 @@ bool tnlArray< Element, Device, Index >:: operator == ( const Array& array ) const { - if( array. getSize() != this -> getSize() ) + if( array. getSize() != this->getSize() ) return false; return tnlArrayOperations< Device, typename Array :: DeviceType > :: template compareMemory< typename Array :: ElementType, Element, typename Array :: IndexType > - ( this -> getData(), + ( this->getData(), array. getData(), array. getSize() ); } @@ -443,7 +443,7 @@ template< typename Element, void tnlArray< Element, Device, Index > :: setValue( const Element& e ) { tnlAssert( this->getData(),); - tnlArrayOperations< Device > :: setMemory( this -> getData(), e, this -> getSize() ); + tnlArrayOperations< Device > :: setMemory( this->getData(), e, this->getSize() ); } template< typename Element, @@ -452,7 +452,7 @@ template< typename Element, __cuda_callable__ const Element* tnlArray< Element, Device, Index > :: getData() const { - return this -> data; + return this->data; } template< typename Element, @@ -461,7 +461,7 @@ template< typename Element, __cuda_callable__ Element* tnlArray< Element, Device, Index > :: getData() { - return this -> data; + return this->data; } template< typename Element, @@ -496,10 +496,10 @@ bool tnlArray< Element, Device, Index > :: save( tnlFile& file ) const if( ! file. write( &this->size ) ) return false; #endif - if( this -> size != 0 && ! tnlArrayIO< Element, Device, Index >::save( file, this -> data, this -> size ) ) + if( this->size != 0 && ! tnlArrayIO< Element, Device, Index >::save( file, this->data, this->size ) ) { cerr << "I was not able to save " << this->getType() - << " with size " << this -> getSize() << endl; + << " with size " << this->getSize() << endl; return false; } return true; @@ -530,10 +530,10 @@ load( tnlFile& file ) setSize( _size ); if( _size ) { - if( ! tnlArrayIO< Element, Device, Index >::load( file, this -> data, this -> size ) ) + if( ! tnlArrayIO< Element, Device, Index >::load( file, this->data, this->size ) ) { cerr << "I was not able to load " << this->getType() - << " with size " << this -> getSize() << endl; + << " with size " << this->getSize() << endl; return false; } } @@ -574,10 +574,10 @@ boundLoad( tnlFile& file ) else setSize( _size ); if( _size ) { - if( ! tnlArrayIO< Element, Device, Index >::load( file, this -> data, this -> size ) ) + if( ! tnlArrayIO< Element, Device, Index >::load( file, this->data, this->size ) ) { cerr << "I was not able to load " << this->getType() - << " with size " << this -> getSize() << endl; + << " with size " << this->getSize() << endl; return false; } } diff --git a/src/core/arrays/tnlConstSharedArray_impl.h b/src/core/arrays/tnlConstSharedArray_impl.h index ce0065859c45fe94f40c8879307f6f5e55e46045..5ede952e742d41af1dbfdb4ebb065aa7acd8e2e2 100644 --- a/src/core/arrays/tnlConstSharedArray_impl.h +++ b/src/core/arrays/tnlConstSharedArray_impl.h @@ -82,8 +82,8 @@ void tnlConstSharedArray< Element, Device, Index > :: bind( const Element* data, tnlAssert( data != 0, cerr << "You try to use null pointer to data for tnlConstSharedArray." ); - this -> size = size; - this -> data = data; + this->size = size; + this->data = data; }; template< typename Element, @@ -110,8 +110,8 @@ template< typename Element, typename Index > void tnlConstSharedArray< Element, Device, Index > :: swap( tnlConstSharedArray< Element, Device, Index >& array ) { - :: swap( this -> size, array. size ); - :: swap( this -> data, array. data ); + :: swap( this->size, array. size ); + :: swap( this->data, array. data ); }; template< typename Element, @@ -119,8 +119,8 @@ template< typename Element, typename Index > void tnlConstSharedArray< Element, Device, Index > :: reset() { - this -> size = 0; - this -> data = 0; + this->size = 0; + this->data = 0; }; template< typename Element, @@ -129,7 +129,7 @@ template< typename Element, __cuda_callable__ Index tnlConstSharedArray< Element, Device, Index > :: getSize() const { - return this -> size; + return this->size; } template< typename Element, @@ -137,11 +137,11 @@ template< typename Element, typename Index > Element tnlConstSharedArray< Element, Device, Index > :: getElement( Index i ) const { - tnlAssert( 0 <= i && i < this -> getSize(), + tnlAssert( 0 <= i && i < this->getSize(), cerr << "Wrong index for getElement method in tnlConstSharedArray with name " << " index is " << i - << " and array size is " << this -> getSize() ); - return tnlArrayOperations< Device >::getMemoryElement( &( this -> data[ i ] ) ); + << " and array size is " << this->getSize() ); + return tnlArrayOperations< Device >::getMemoryElement( &( this->data[ i ] ) ); }; template< typename Element, @@ -150,12 +150,12 @@ template< typename Element, __cuda_callable__ const Element& tnlConstSharedArray< Element, Device, Index > :: operator[] ( Index i ) const { - tnlAssert( 0 <= i && i < this -> getSize(), + tnlAssert( 0 <= i && i < this->getSize(), cerr << "Wrong index for operator[] in tnlConstSharedArray with name " << " index is " << i - << " and array size is " << this -> getSize() ); + << " and array size is " << this->getSize() ); // TODO: add static assert - this does not make sense for tnlCudaDevice - return tnlArrayOperations< Device >::getArrayElementReference( this -> data, i ); + return tnlArrayOperations< Device >::getArrayElementReference( this->data, i ); }; template< typename Element, @@ -184,14 +184,14 @@ template< typename Element, template< typename Array > bool tnlConstSharedArray< Element, Device, Index > :: operator == ( const Array& array ) const { - if( array. getSize() != this -> getSize() ) + if( array. getSize() != this->getSize() ) return false; return tnlArrayOperations< Device, typename Array :: DeviceType > :: template compareMemory< typename Array :: ElementType, Element, typename Array :: IndexType > - ( this -> getData(), + ( this->getData(), array. getData(), array. getSize() ); } @@ -210,7 +210,7 @@ template< typename Element, typename Index > const Element* tnlConstSharedArray< Element, Device, Index > :: getData() const { - return this -> data; + return this->data; } template< typename Element, @@ -236,20 +236,20 @@ template< typename Element, typename Index > bool tnlConstSharedArray< Element, Device, Index > :: save( tnlFile& file ) const { - tnlAssert( this -> size != 0, + tnlAssert( this->size != 0, cerr << "You try to save empty array." ); if( ! tnlObject :: save( file ) ) return false; #ifdef HAVE_NOT_CXX11 - if( ! file. write< const Index, Device >( &this -> size ) ) + if( ! file. write< const Index, Device >( &this->size ) ) #else - if( ! file. write( &this -> size ) ) + if( ! file. write( &this->size ) ) #endif return false; - if( ! file. write< Element, Device, Index >( this -> data, this -> size ) ) + if( ! file. write< Element, Device, Index >( this->data, this->size ) ) { cerr << "I was not able to WRITE tnlConstSharedArray " - << " with size " << this -> getSize() << endl; + << " with size " << this->getSize() << endl; return false; } return true; diff --git a/src/core/arrays/tnlMultiArray1D_impl.h b/src/core/arrays/tnlMultiArray1D_impl.h index 17591b814a358a706961d473aafba5026bb4146b..943bace852349f27fd4c9fe313f428d54769c8ae 100644 --- a/src/core/arrays/tnlMultiArray1D_impl.h +++ b/src/core/arrays/tnlMultiArray1D_impl.h @@ -75,8 +75,8 @@ bool tnlMultiArray< 1, Element, Device, Index > :: setDimensions( const tnlStati { tnlAssert( dimensions[ 0 ] > 0, cerr << " dimensions[ 0 ] = " << dimensions[ 0 ] ); - this -> dimensions = dimensions; - return tnlArray< Element, Device, Index >::setSize( this -> dimensions[ 0 ] ); + this->dimensions = dimensions; + return tnlArray< Element, Device, Index >::setSize( this->dimensions[ 0 ] ); } template< typename Element, typename Device, typename Index > @@ -97,22 +97,22 @@ template< typename Element, typename Device, typename Index > __cuda_callable__ void tnlMultiArray< 1, Element, Device, Index > :: getDimensions( Index& xSize ) const { - xSize = this -> dimensions[ 0 ]; + xSize = this->dimensions[ 0 ]; } template< typename Element, typename Device, typename Index > __cuda_callable__ const tnlStaticVector< 1, Index >& tnlMultiArray< 1, Element, Device, Index > :: getDimensions() const { - return this -> dimensions; + return this->dimensions; } template< typename Element, typename Device, typename Index > __cuda_callable__ Index tnlMultiArray< 1, Element, Device, Index > :: getElementIndex( const Index i ) const { - tnlAssert( i >= 0 && i < this -> dimensions[ 0 ], - cerr << "i = " << i << " this -> dimensions[ 0 ] = " << this -> dimensions[ 0 ] ); + tnlAssert( i >= 0 && i < this->dimensions[ 0 ], + cerr << "i = " << i << " this->dimensions[ 0 ] = " << this->dimensions[ 0 ] ); return i; } @@ -147,9 +147,9 @@ template< typename Element, typename Device, typename Index > bool tnlMultiArray< 1, Element, Device, Index > :: operator == ( const MultiArray& array ) const { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to compare two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); return tnlArray< Element, Device, Index > :: operator == ( array ); } @@ -166,9 +166,9 @@ tnlMultiArray< 1, Element, Device, Index >& tnlMultiArray< 1, Element, Device, Index > :: operator = ( const tnlMultiArray< 1, Element, Device, Index >& array ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to assign two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); tnlArray< Element, Device, Index > :: operator = ( array ); return ( *this ); @@ -180,9 +180,9 @@ tnlMultiArray< 1, Element, Device, Index >& tnlMultiArray< 1, Element, Device, Index > :: operator = ( const MultiArray& array ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to assign two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); tnlArray< Element, Device, Index > :: operator = ( array ); return ( *this ); diff --git a/src/core/arrays/tnlMultiArray2D_impl.h b/src/core/arrays/tnlMultiArray2D_impl.h index 2b51149244a19719c77cfe01b65f47c5484739de..fb2de4d4e722869c6dcd07aa4eae799d38c9c6cc 100644 --- a/src/core/arrays/tnlMultiArray2D_impl.h +++ b/src/core/arrays/tnlMultiArray2D_impl.h @@ -84,9 +84,9 @@ bool tnlMultiArray< 2, Element, Device, Index > :: setDimensions( const tnlStati /**** * Swap the dimensions in the tuple to be compatible with the previous method. */ - this -> dimensions. x() = dimensions. y(); - this -> dimensions. y() = dimensions. x(); - return tnlArray< Element, Device, Index > :: setSize( this -> dimensions[ 1 ] * this -> dimensions[ 0 ] ); + this->dimensions. x() = dimensions. y(); + this->dimensions. y() = dimensions. x(); + return tnlArray< Element, Device, Index > :: setSize( this->dimensions[ 1 ] * this->dimensions[ 0 ] ); } template< typename Element, typename Device, typename Index > @@ -107,25 +107,25 @@ template< typename Element, typename Device, typename Index > __cuda_callable__ void tnlMultiArray< 2, Element, Device, Index > :: getDimensions( Index& jSize, Index& iSize ) const { - iSize = this -> dimensions[ 0 ]; - jSize = this -> dimensions[ 1 ]; + iSize = this->dimensions[ 0 ]; + jSize = this->dimensions[ 1 ]; } template< typename Element, typename Device, typename Index > __cuda_callable__ const tnlStaticVector< 2, Index >& tnlMultiArray< 2, Element, Device, Index > :: getDimensions() const { - return this -> dimensions; + return this->dimensions; } template< typename Element, typename Device, typename Index > __cuda_callable__ Index tnlMultiArray< 2, Element, Device, Index > :: getElementIndex( const Index j, const Index i ) const { - tnlAssert( i >= 0 && i < this -> dimensions[ 0 ] && j >= 0 && j < this -> dimensions[ 1 ], - cerr << "i = " << i << " j = " << j << " this -> dimensions[ 0 ] = " << this -> dimensions[ 0 ] - << " this -> dimensions[ 1 ] = " << this -> dimensions[ 1 ] ); - return j * this -> dimensions[ 0 ] + i; + tnlAssert( i >= 0 && i < this->dimensions[ 0 ] && j >= 0 && j < this->dimensions[ 1 ], + cerr << "i = " << i << " j = " << j << " this->dimensions[ 0 ] = " << this->dimensions[ 0 ] + << " this->dimensions[ 1 ] = " << this->dimensions[ 1 ] ); + return j * this->dimensions[ 0 ] + i; } template< typename Element, typename Device, typename Index > @@ -159,9 +159,9 @@ template< typename Element, typename Device, typename Index > bool tnlMultiArray< 2, Element, Device, Index > :: operator == ( const MultiArray& array ) const { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to compare two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); return tnlArray< Element, Device, Index > :: operator == ( array ); } @@ -178,9 +178,9 @@ tnlMultiArray< 2, Element, Device, Index >& tnlMultiArray< 2, Element, Device, Index > :: operator = ( const tnlMultiArray< 2, Element, Device, Index >& array ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to assign two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); tnlArray< Element, Device, Index > :: operator = ( array ); return ( *this ); @@ -192,9 +192,9 @@ tnlMultiArray< 2, Element, Device, Index >& tnlMultiArray< 2, Element, Device, Index > :: operator = ( const MultiArray& array ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to assign two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); tnlArray< Element, Device, Index > :: operator = ( array ); return ( *this ); diff --git a/src/core/arrays/tnlMultiArray3D_impl.h b/src/core/arrays/tnlMultiArray3D_impl.h index 25a91599dfa95d51d2817818315a711ce3adc916..b8b30ad91ebc409c50437000d4a094fd9d3f1d33 100644 --- a/src/core/arrays/tnlMultiArray3D_impl.h +++ b/src/core/arrays/tnlMultiArray3D_impl.h @@ -87,12 +87,12 @@ bool tnlMultiArray< 3, Element, Device, Index > :: setDimensions( const tnlStati /**** * Swap the dimensions in the tuple to be compatible with the previous method. */ - this -> dimensions. x() = dimensions. z(); - this -> dimensions. y() = dimensions. y(); - this -> dimensions. z() = dimensions. x(); - return tnlArray< Element, Device, Index > :: setSize( this -> dimensions[ 2 ] * - this -> dimensions[ 1 ] * - this -> dimensions[ 0 ] ); + this->dimensions. x() = dimensions. z(); + this->dimensions. y() = dimensions. y(); + this->dimensions. z() = dimensions. x(); + return tnlArray< Element, Device, Index > :: setSize( this->dimensions[ 2 ] * + this->dimensions[ 1 ] * + this->dimensions[ 0 ] ); } template< typename Element, typename Device, typename Index > @@ -115,16 +115,16 @@ void tnlMultiArray< 3, Element, Device, Index > :: getDimensions( Index& kSize, Index& jSize, Index& iSize ) const { - iSize = this -> dimensions[ 0 ]; - jSize = this -> dimensions[ 1 ]; - kSize = this -> dimensions[ 2 ]; + iSize = this->dimensions[ 0 ]; + jSize = this->dimensions[ 1 ]; + kSize = this->dimensions[ 2 ]; } template< typename Element, typename Device, typename Index > __cuda_callable__ const tnlStaticVector< 3, Index >& tnlMultiArray< 3, Element, Device, Index > :: getDimensions() const { - return this -> dimensions; + return this->dimensions; } template< typename Element, typename Device, typename Index > @@ -133,14 +133,14 @@ Index tnlMultiArray< 3, Element, Device, Index > :: getElementIndex( const Index const Index j, const Index i ) const { - tnlAssert( i >= 0 && i < this -> dimensions[ 0 ] && - j >= 0 && j < this -> dimensions[ 1 ] && - k >= 0 && k < this -> dimensions[ 2 ], + tnlAssert( i >= 0 && i < this->dimensions[ 0 ] && + j >= 0 && j < this->dimensions[ 1 ] && + k >= 0 && k < this->dimensions[ 2 ], cerr << " i = " << i << " j = " << j << " k = " << k - << " this -> dimensions = " << this -> dimensions ); - return ( k * this -> dimensions[ 1 ] + j ) * this -> dimensions[ 0 ] + i; + << " this->dimensions = " << this->dimensions ); + return ( k * this->dimensions[ 1 ] + j ) * this->dimensions[ 0 ] + i; } template< typename Element, typename Device, typename Index > @@ -183,9 +183,9 @@ template< typename Element, typename Device, typename Index > bool tnlMultiArray< 3, Element, Device, Index > :: operator == ( const MultiArray& array ) const { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to compare two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); return tnlArray< Element, Device, Index > :: operator == ( array ); } @@ -202,9 +202,9 @@ tnlMultiArray< 3, Element, Device, Index >& tnlMultiArray< 3, Element, Device, Index > :: operator = ( const tnlMultiArray< 3, Element, Device, Index >& array ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to assign two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); tnlArray< Element, Device, Index > :: operator = ( array ); return ( *this ); @@ -216,9 +216,9 @@ tnlMultiArray< 3, Element, Device, Index >& tnlMultiArray< 3, Element, Device, Index > :: operator = ( const MultiArray& array ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to assign two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); tnlArray< Element, Device, Index > :: operator = ( array ); return ( *this ); diff --git a/src/core/arrays/tnlMultiArray4D_impl.h b/src/core/arrays/tnlMultiArray4D_impl.h index 67d492fa119a6b6b980e5228702b060a694becfc..f03b942ddc5c691c6cf0c2b29b8e42262fba126f 100644 --- a/src/core/arrays/tnlMultiArray4D_impl.h +++ b/src/core/arrays/tnlMultiArray4D_impl.h @@ -90,14 +90,14 @@ bool tnlMultiArray< 4, Element, Device, Index > :: setDimensions( const tnlStati /**** * Swap the dimensions in the tuple to be compatible with the previous method. */ - this -> dimensions[ 0 ] = dimensions[ 3 ]; - this -> dimensions[ 1 ] = dimensions[ 2 ]; - this -> dimensions[ 2 ] = dimensions[ 1 ]; - this -> dimensions[ 3 ] = dimensions[ 0 ]; - return tnlArray< Element, Device, Index > :: setSize( this -> dimensions[ 3 ] * - this -> dimensions[ 2 ] * - this -> dimensions[ 1 ] * - this -> dimensions[ 0 ] ); + this->dimensions[ 0 ] = dimensions[ 3 ]; + this->dimensions[ 1 ] = dimensions[ 2 ]; + this->dimensions[ 2 ] = dimensions[ 1 ]; + this->dimensions[ 3 ] = dimensions[ 0 ]; + return tnlArray< Element, Device, Index > :: setSize( this->dimensions[ 3 ] * + this->dimensions[ 2 ] * + this->dimensions[ 1 ] * + this->dimensions[ 0 ] ); } template< typename Element, typename Device, typename Index > @@ -121,17 +121,17 @@ void tnlMultiArray< 4, Element, Device, Index > :: getDimensions( Index& lSize, Index& jSize, Index& iSize ) const { - iSize = this -> dimensions[ 0 ]; - jSize = this -> dimensions[ 1 ]; - kSize = this -> dimensions[ 2 ]; - lSize = this -> dimensions[ 3 ]; + iSize = this->dimensions[ 0 ]; + jSize = this->dimensions[ 1 ]; + kSize = this->dimensions[ 2 ]; + lSize = this->dimensions[ 3 ]; } template< typename Element, typename Device, typename Index > __cuda_callable__ const tnlStaticVector< 4, Index >& tnlMultiArray< 4, Element, Device, Index > :: getDimensions() const { - return this -> dimensions; + return this->dimensions; } template< typename Element, typename Device, typename Index > @@ -141,16 +141,16 @@ Index tnlMultiArray< 4, Element, Device, Index > :: getElementIndex( const Index const Index j, const Index i ) const { - tnlAssert( i >= 0 && i < this -> dimensions[ 0 ] && - j >= 0 && j < this -> dimensions[ 1 ] && - k >= 0 && k < this -> dimensions[ 2 ] && - l >= 0 && l < this -> dimensions[ 3 ], + tnlAssert( i >= 0 && i < this->dimensions[ 0 ] && + j >= 0 && j < this->dimensions[ 1 ] && + k >= 0 && k < this->dimensions[ 2 ] && + l >= 0 && l < this->dimensions[ 3 ], cerr << " i = " << i << " j = " << j << " k = " << k << " l = " << l - << " this -> dimensions = " << this -> dimensions ); - return ( ( l * this -> dimensions[ 2 ] + k ) * this -> dimensions[ 1 ] + j ) * this -> dimensions[ 0 ] + i; + << " this->dimensions = " << this->dimensions ); + return ( ( l * this->dimensions[ 2 ] + k ) * this->dimensions[ 1 ] + j ) * this->dimensions[ 0 ] + i; } template< typename Element, typename Device, typename Index > @@ -197,9 +197,9 @@ template< typename Element, typename Device, typename Index > bool tnlMultiArray< 4, Element, Device, Index > :: operator == ( const MultiArray& array ) const { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to compare two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); return tnlArray< Element, Device, Index > :: operator == ( array ); } @@ -216,9 +216,9 @@ tnlMultiArray< 4, Element, Device, Index >& tnlMultiArray< 4, Element, Device, Index > :: operator = ( const tnlMultiArray< 4, Element, Device, Index >& array ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to assign two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); tnlArray< Element, Device, Index > :: operator = ( array ); return ( *this ); @@ -230,9 +230,9 @@ tnlMultiArray< 4, Element, Device, Index >& tnlMultiArray< 4, Element, Device, Index > :: operator = ( const MultiArray& array ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == array. getDimensions(), + tnlAssert( this->getDimensions() == array. getDimensions(), cerr << "You are attempting to assign two arrays with different dimensions." << endl - << "First array dimensions are ( " << this -> getDimensions() << " )" << endl + << "First array dimensions are ( " << this->getDimensions() << " )" << endl << "Second array dimensions are ( " << array. getDimensions() << " )" << endl; ); tnlArray< Element, Device, Index > :: operator = ( array ); return ( *this ); diff --git a/src/core/arrays/tnlSharedArray_impl.h b/src/core/arrays/tnlSharedArray_impl.h index 3aad6dd486edc45ff944823be9b9dfe35156a46f..a41fa22b4ca3bdc7443cf6ae2cf2b8fa1b9472ee 100644 --- a/src/core/arrays/tnlSharedArray_impl.h +++ b/src/core/arrays/tnlSharedArray_impl.h @@ -113,8 +113,8 @@ void tnlSharedArray< Element, Device, Index > :: bind( Element* data, tnlAssert( data != 0, cerr << "You try to use null pointer to data for tnlSharedArray." ); - this -> size = size; - this -> data = data; + this->size = size; + this->data = data; }; template< typename Element, @@ -154,8 +154,8 @@ template< typename Element, __cuda_callable__ void tnlSharedArray< Element, Device, Index > :: bind( tnlSharedArray< Element, Device, Index >& array ) { - this -> size = array. getSize(); - this -> data = array. getData(); + this->size = array. getSize(); + this->data = array. getData(); }; template< typename Element, @@ -163,8 +163,8 @@ template< typename Element, typename Index > void tnlSharedArray< Element, Device, Index > :: swap( tnlSharedArray< Element, Device, Index >& array ) { - :: swap( this -> size, array. size ); - :: swap( this -> data, array. data ); + :: swap( this->size, array. size ); + :: swap( this->data, array. data ); }; template< typename Element, @@ -172,8 +172,8 @@ template< typename Element, typename Index > void tnlSharedArray< Element, Device, Index > :: reset() { - this -> size = 0; - this -> data = 0; + this->size = 0; + this->data = 0; }; template< typename Element, @@ -182,7 +182,7 @@ template< typename Element, __cuda_callable__ Index tnlSharedArray< Element, Device, Index > :: getSize() const { - return this -> size; + return this->size; } template< typename Element, @@ -190,11 +190,11 @@ template< typename Element, typename Index > void tnlSharedArray< Element, Device, Index > :: setElement( const Index& i, const Element& x ) { - tnlAssert( 0 <= i && i < this -> getSize(), + tnlAssert( 0 <= i && i < this->getSize(), cerr << "Wrong index for setElement method in tnlSharedArray " << " index is " << i - << " and array size is " << this -> getSize() ); - return tnlArrayOperations< Device >::setMemoryElement( & ( this -> data[ i ] ), x ); + << " and array size is " << this->getSize() ); + return tnlArrayOperations< Device >::setMemoryElement( & ( this->data[ i ] ), x ); }; template< typename Element, @@ -202,11 +202,11 @@ template< typename Element, typename Index > Element tnlSharedArray< Element, Device, Index > :: getElement( const Index& i ) const { - tnlAssert( 0 <= i && i < this -> getSize(), + tnlAssert( 0 <= i && i < this->getSize(), cerr << "Wrong index for getElement method in tnlSharedArray " << " index is " << i - << " and array size is " << this -> getSize() ); - return tnlArrayOperations< Device >::getMemoryElement( &( this -> data[ i ] ) ); + << " and array size is " << this->getSize() ); + return tnlArrayOperations< Device >::getMemoryElement( &( this->data[ i ] ) ); }; template< typename Element, @@ -215,10 +215,10 @@ template< typename Element, __cuda_callable__ Element& tnlSharedArray< Element, Device, Index > :: operator[] ( const Index& i ) { - tnlAssert( 0 <= i && i < this -> getSize(), + tnlAssert( 0 <= i && i < this->getSize(), cerr << "Wrong index for operator[] in tnlSharedArray " << " index is " << i - << " and array size is " << this -> getSize() ); + << " and array size is " << this->getSize() ); return this->data[ i ]; }; @@ -228,10 +228,10 @@ template< typename Element, __cuda_callable__ const Element& tnlSharedArray< Element, Device, Index > :: operator[] ( const Index& i ) const { - tnlAssert( 0 <= i && i < this -> getSize(), + tnlAssert( 0 <= i && i < this->getSize(), cerr << "Wrong index for operator[] in tnlSharedArray " << " index is " << i - << " and array size is " << this -> getSize() ); + << " and array size is " << this->getSize() ); return this->data[ i ]; }; @@ -241,14 +241,14 @@ template< typename Element, tnlSharedArray< Element, Device, Index >& tnlSharedArray< Element, Device, Index > :: operator = ( const tnlSharedArray< Element, Device, Index >& array ) { - tnlAssert( array. getSize() == this -> getSize(), + tnlAssert( array. getSize() == this->getSize(), cerr << "Source size: " << array. getSize() << endl - << "Target size: " << this -> getSize() << endl ); + << "Target size: " << this->getSize() << endl ); tnlArrayOperations< Device > :: template copyMemory< Element, Element, Index > - ( this -> getData(), + ( this->getData(), array. getData(), array. getSize() ); return ( *this ); @@ -260,15 +260,15 @@ template< typename Element, template< typename Array > tnlSharedArray< Element, Device, Index >& tnlSharedArray< Element, Device, Index > :: operator = ( const Array& array ) { - tnlAssert( array. getSize() == this -> getSize(), + tnlAssert( array. getSize() == this->getSize(), cerr << "Source size: " << array. getSize() << endl - << "Target size: " << this -> getSize() << endl ); + << "Target size: " << this->getSize() << endl ); tnlArrayOperations< typename Array :: DeviceType, Device > :: template copyMemory< Element, typename Array :: ElementType, typename Array :: IndexType > - ( this -> getData(), + ( this->getData(), array. getData(), array. getSize() ); return ( *this ); @@ -280,14 +280,14 @@ template< typename Element, template< typename Array > bool tnlSharedArray< Element, Device, Index > :: operator == ( const Array& array ) const { - if( array. getSize() != this -> getSize() ) + if( array. getSize() != this->getSize() ) return false; return tnlArrayOperations< Device, typename Array :: DeviceType > :: template compareMemory< typename Array :: ElementType, Element, typename Array :: IndexType > - ( this -> getData(), + ( this->getData(), array. getData(), array. getSize() ); } @@ -306,9 +306,9 @@ template< typename Element, typename Index > void tnlSharedArray< Element, Device, Index > :: setValue( const Element& e ) { - tnlAssert( this -> size != 0, ); + tnlAssert( this->size != 0, ); tnlArrayOperations< Device >::template setMemory< Element, Index > - ( this -> getData(), e, this -> getSize() ); + ( this->getData(), e, this->getSize() ); } @@ -317,7 +317,7 @@ template< typename Element, typename Index > const Element* tnlSharedArray< Element, Device, Index > :: getData() const { - return this -> data; + return this->data; } template< typename Element, @@ -325,7 +325,7 @@ template< typename Element, typename Index > Element* tnlSharedArray< Element, Device, Index > :: getData() { - return this -> data; + return this->data; } template< typename Element, @@ -351,19 +351,19 @@ template< typename Element, typename Index > bool tnlSharedArray< Element, Device, Index > :: save( tnlFile& file ) const { - tnlAssert( this -> size != 0, + tnlAssert( this->size != 0, cerr << "You try to save empty array." << endl ); if( ! tnlObject :: save( file ) ) return false; #ifdef HAVE_NOT_CXX11 - if( ! file. write< const Index, tnlHost >( &this -> size ) ) + if( ! file. write< const Index, tnlHost >( &this->size ) ) #else - if( ! file. write( &this -> size ) ) + if( ! file. write( &this->size ) ) #endif return false; - if( ! file. write< Element, Device, Index >( this -> data, this -> size ) ) + if( ! file. write< Element, Device, Index >( this->data, this->size ) ) { - cerr << "I was not able to WRITE tnlSharedArray with size " << this -> getSize() << endl; + cerr << "I was not able to WRITE tnlSharedArray with size " << this->getSize() << endl; return false; } return true; @@ -400,9 +400,9 @@ bool tnlSharedArray< Element, Device, Index > :: load( tnlFile& file ) } if( _size ) { - if( ! file. read< Element, Device, Index >( this -> data, this -> size ) ) + if( ! file. read< Element, Device, Index >( this->data, this->size ) ) { - cerr << "I was not able to READ tnlSharedArray with size " << this -> getSize() << endl; + cerr << "I was not able to READ tnlSharedArray with size " << this->getSize() << endl; return false; } } diff --git a/src/core/cuda/reduction-operations.h b/src/core/cuda/reduction-operations.h index da18c6c39ca816ad797c2d5bbf453c3be25ad1b9..0cc066e946329302fc4eed5e6e31e7fc81745be4 100644 --- a/src/core/cuda/reduction-operations.h +++ b/src/core/cuda/reduction-operations.h @@ -545,7 +545,7 @@ class tnlParallelReductionLpNorm : public tnlParallelReductionSum< Real, Index > void setPower( const RealType& p ) { - this -> p = p; + this->p = p; }; ResultType reduceOnHost( const IndexType& idx, @@ -879,7 +879,7 @@ class tnlParallelReductionDiffLpNorm : public tnlParallelReductionSum< Real, Ind void setPower( const RealType& p ) { - this -> p = p; + this->p = p; }; ResultType reduceOnHost( const IndexType& idx, diff --git a/src/core/images/tnlPGMImage_impl.h b/src/core/images/tnlPGMImage_impl.h index 2539fa6b67aacf566039f6e2986bbb7c64a3910f..128068ac06e050f5af3b260af5f5fb8d46278db1 100644 --- a/src/core/images/tnlPGMImage_impl.h +++ b/src/core/images/tnlPGMImage_impl.h @@ -34,8 +34,8 @@ tnlPGMImage< Index >:: readHeader() { char magicNumber[ 3 ]; - this -> file >> magicNumber; - if( this -> file.fail() ) + this->file >> magicNumber; + if( this->file.fail() ) { cerr << "Unable to read the magic number." << endl; return false; @@ -49,17 +49,17 @@ readHeader() this->binary = true; char character; - this -> file.get(character); - while ( ! this -> file.eof() and ( character == ' ' || character == '\t' || character == '\r' || character == '\n') ) + this->file.get(character); + while ( ! this->file.eof() and ( character == ' ' || character == '\t' || character == '\r' || character == '\n') ) { - this -> file.get(character); + this->file.get(character); if ( character == '#' ) - while (! this -> file.eof() && ( character != '\n' ) ) - this -> file.get( character ); + while (! this->file.eof() && ( character != '\n' ) ) + this->file.get( character ); } - this -> file.unget(); + this->file.unget(); - this -> file >> this -> width >> this -> height >> this -> maxColors; + this->file >> this->width >> this->height >> this->maxColors; return true; } @@ -69,7 +69,7 @@ tnlPGMImage< Index >:: openForRead( const tnlString& fileName ) { this->close(); - if ( this -> binary ) + if ( this->binary ) this->file.open( fileName.getString(), fstream::in | fstream::binary); else this->file.open( fileName.getString(), fstream::in ); @@ -102,13 +102,13 @@ read( const tnlRegionOfInterest< Index > roi, for( j = 0; j < this->width; j ++ ) { int col; - unsigned char col_aux; - if( this->binary ) - { - this -> file >> col_aux; - col = (int)col_aux; - } - else this -> file >> col; + unsigned char col_aux; + if( this->binary ) + { + this->file >> col_aux; + col = (int)col_aux; + } + else this->file >> col; if( roi.isIn( i, j ) ) { cell.getCoordinates().x() = j - roi.getLeft(); @@ -190,7 +190,7 @@ write( const tnlGrid< 2, Real, Device, Index >& grid, // grid.getDimensions().y() - 1 - i ) ); unsigned char color = 255 * vector.getElement( cell.getIndex() ); - if ( ! this -> binary ) + if ( ! this->binary ) { int color_aux = (int)color; this->file << color_aux; @@ -199,7 +199,7 @@ write( const tnlGrid< 2, Real, Device, Index >& grid, else this->file << color; } - if ( ! this -> binary ) + if ( ! this->binary ) this->file << '\n'; } return true; diff --git a/src/core/terminal-colors.h b/src/core/terminal-colors.h index 2c67d00c51a06e57f0300f8a0b9d7a73cb61eda9..9a1d123f21a612a19c4ce00765e6bd13db6712a0 100644 --- a/src/core/terminal-colors.h +++ b/src/core/terminal-colors.h @@ -18,12 +18,13 @@ #ifndef TERMINAL_COLORS_H #define TERMINAL_COLORS_H -const std::string red( "\033[0;31m" ); -const std::string green( "\033[1;32m" ); -const std::string yellow( "\033[1;33m" ); -const std::string cyan( "\033[0;36m" ); -const std::string magenta( "\033[0;35m" ); -const std::string reset( "\033[0m" ); +const tnlString red( "\033[0;31m" ); +const tnlString green( "\033[1;32m" ); +const tnlString yellow( "\033[1;33m" ); +const tnlString cyan( "\033[0;36m" ); +const tnlString magenta( "\033[0;35m" ); +const tnlString bold(); +const tnlString reset( "\033[0m" ); #endif /* TERMINAL_COLORS_H */ diff --git a/src/core/tnlCommunicator.h b/src/core/tnlCommunicator.h index ea02f1e65bb9cabd379e775ac51da802b662f1f8..770bc79197b9082285c15046f46a98d6dfcece1f 100644 --- a/src/core/tnlCommunicator.h +++ b/src/core/tnlCommunicator.h @@ -155,38 +155,38 @@ tnlCommunicator< Dimensions, Device > :: tnlCommunicator() template< int Dimensions, typename Device > int tnlCommunicator< Dimensions, Device > :: getCommunicationGroupSize() const { - return this -> communicationGroupSize; + return this->communicationGroupSize; } template< int Dimensions, typename Device > bool tnlCommunicator< Dimensions, Device > :: setDimensions( const tnlStaticVector< Dimensions, int >& dimensions ) { - this -> dimensions = dimensions; + this->dimensions = dimensions; // TODO: add automatic dimensions setting from the group size } template< int Dimensions, typename Device > const tnlStaticVector< Dimensions, int >& tnlCommunicator< Dimensions, Device > :: getDimensions() const { - return this -> dimensions; + return this->dimensions; } template< int Dimensions, typename Device > const tnlStaticVector< Dimensions, int >& tnlCommunicator< Dimensions, Device > :: getNodeCoordinates() const { - return this -> nodeCoordinates; + return this->nodeCoordinates; } template< int Dimensions, typename Device > int tnlCommunicator< Dimensions, Device > :: getDeviceId() const { - return this -> deviceID; + return this->deviceID; } template< int Dimensions, typename Device > bool tnlCommunicator< Dimensions, Device > :: setCommunicationGroupSize( int communicationGroupSize ) { - this -> communicationGroupSize = communicationGroupSize; + this->communicationGroupSize = communicationGroupSize; // TODO: add automatic groupsize setting } @@ -194,18 +194,18 @@ template< int Dimensions, typename Device > bool tnlCommunicator< Dimensions, Device > :: start() { dbgFunctionName( "tnlCommunicator", "start" ); - if( this -> getCommunicationGroupSize() < 1 ) - this -> setCommunicationGroupSize(); - if( this -> getCommunicationGroupSize() < 1 ) + if( this->getCommunicationGroupSize() < 1 ) + this->setCommunicationGroupSize(); + if( this->getCommunicationGroupSize() < 1 ) { - cerr << "Sorry, but I have wrong size ( " << this -> getCommunicationGroupSize() << " of the communication group. I cannot create a communicator." << endl; + cerr << "Sorry, but I have wrong size ( " << this->getCommunicationGroupSize() << " of the communication group. I cannot create a communicator." << endl; return false; } - if( this -> getDimensions() == tnlStaticVector< Dimensions, int >( 0 ) ) - this -> setDimensions( tnlStaticVector< Dimensions, int >( 0 ) ); - if( this -> getDimensions() == tnlStaticVector< Dimensions, int >( -1 ) ) + if( this->getDimensions() == tnlStaticVector< Dimensions, int >( 0 ) ) + this->setDimensions( tnlStaticVector< Dimensions, int >( 0 ) ); + if( this->getDimensions() == tnlStaticVector< Dimensions, int >( -1 ) ) { - cerr << "Sorry, but I have wrong dimensions ( " << this -> getDimensions() << " of the communication group. I cannot create a communicator." << endl; + cerr << "Sorry, but I have wrong dimensions ( " << this->getDimensions() << " of the communication group. I cannot create a communicator." << endl; return false; } if( Device :: getDeviceType() == "tnlCuda" || @@ -213,7 +213,7 @@ bool tnlCommunicator< Dimensions, Device > :: start() { deviceID = 0; int currentDeviceID = 1; - for( int i = 0; i < this -> getCommunicationGroupSize() - 1; i ++ ) + for( int i = 0; i < this->getCommunicationGroupSize() - 1; i ++ ) { pid_t child_pid = fork(); if( child_pid != 0 ) @@ -230,7 +230,7 @@ bool tnlCommunicator< Dimensions, Device > :: start() dbgCout( "The CHILD process is setting ID to " << deviceID ); return true; } // if( child_pid != 0 ) - else - } // for( int i = 0; i < this -> getCommunicationGroupSize() - 1; i ++ ) + } // for( int i = 0; i < this->getCommunicationGroupSize() - 1; i ++ ) } } diff --git a/src/core/tnlCuda.cpp b/src/core/tnlCuda.cpp index bd69fb2cabb148a4b49ec05ead16bbc0652a72fc..20f6272a30f42c66f2fccbd27ed1be1c4cd631d6 100644 --- a/src/core/tnlCuda.cpp +++ b/src/core/tnlCuda.cpp @@ -18,7 +18,9 @@ #include <core/tnlCuda.h> #include <core/mfuncs.h> #include <tnlConfig.h> - +#include <config/tnlConfigDescription.h> +#include <config/tnlParameterContainer.h> + tnlString tnlCuda :: getDeviceType() { return tnlString( "tnlCuda" ); @@ -46,3 +48,26 @@ int tnlCuda::getNumberOfGrids( const int blocks, }*/ +void tnlCuda::configSetup( tnlConfigDescription& config, const tnlString& prefix ) +{ +#ifdef HAVE_CUDA + config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device to run the computationon.", 0 ); +#else + config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device to run the computationon (not supported on this system).", 0 ); +#endif +} + +bool tnlCuda::setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ +#ifdef HAVE_CUDA + int cudaDevice = parameters.getParameter< int >( "cuda-device" ); + if( cudaSetDevice( cudaDevice ) != cudaSuccess ) + { + std::cerr << "I cannot activate CUDA device number " << cudaDevice << "." << std::endl; + return false; + } +#endif + return true; +} + diff --git a/src/core/tnlCuda.cu b/src/core/tnlCuda.cu index 9178a3261e48a300267b0f292f06cec68575ba4d..113cba35227a0c461f1a32dc1148cd1e9646ac0f 100644 --- a/src/core/tnlCuda.cu +++ b/src/core/tnlCuda.cu @@ -16,6 +16,30 @@ ***************************************************************************/ #include <core/tnlCuda.h> +#include <config/tnlConfigDescription.h> +#include <config/tnlParameterContainer.h> + + +/*void tnlCuda::configSetup( tnlConfigDescription& config, const tnlString& prefix ) +{ +#ifdef HAVE_CUDA + config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device.", 0 ); +#else + config.addEntry< int >( prefix + "cuda-device", "Choose CUDA device (CUDA is not supported on this system).", 0 ); +#endif +} + +bool tnlCuda::setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + int cudaDevice = parameters.getParameter< int >( prefix + "cuda-device" ); +#ifdef HAVE_CUDA + cudaSetDevice( cudaDevice ); + checkCudaDevice; +#endif + return true; +} +*/ bool tnlCuda::checkDevice( const char* file_name, int line ) { diff --git a/src/core/tnlCuda.h b/src/core/tnlCuda.h index 6889f3f109f9075205eaa0591bf29b06703ad6fd..3d5e6eb6ebfd391e634a2bb9ad2979d425b5353a 100644 --- a/src/core/tnlCuda.h +++ b/src/core/tnlCuda.h @@ -24,6 +24,9 @@ #include <core/tnlString.h> #include <core/tnlAssert.h> +class tnlConfigDescription; +class tnlParameterContainer; + #ifdef HAVE_CUDA #define __cuda_callable__ __device__ __host__ #else @@ -90,6 +93,12 @@ class tnlCuda #else static bool checkDevice( const char* file_name, int line ) { return false;}; #endif + + static void configSetup( tnlConfigDescription& config, const tnlString& prefix = "" ); + + static bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); + }; diff --git a/src/core/tnlFile.cpp b/src/core/tnlFile.cpp index bd543cce9d2fd0a730942f8e7d4e14a20e11f439..7c02c0db864b68d29b9a53fe101c18745e45928d 100644 --- a/src/core/tnlFile.cpp +++ b/src/core/tnlFile.cpp @@ -68,3 +68,15 @@ bool tnlFile :: close() readElements = writtenElements = 0; return true; }; + +bool fileExists( const tnlString& fileName ) +{ + fstream file; + file.open( fileName. getString(), ios::in ); + bool result( true ); + if( ! file ) + result = false; + file.close(); + return result; +}; + diff --git a/src/core/tnlFile.h b/src/core/tnlFile.h index 5accc399c1afc1e586a497eb5e3b48f94aa0d3a2..c0819ea3015da49cf242eae007d1a0d9d54f639b 100644 --- a/src/core/tnlFile.h +++ b/src/core/tnlFile.h @@ -124,212 +124,8 @@ class tnlFile }; -template< typename Type, typename Device > -bool tnlFile :: read( Type* buffer ) -{ - return read< Type, Device, int >( buffer, 1 ); -}; - -template< typename Type, typename Device > -bool tnlFile :: write( const Type* buffer ) -{ - return write< Type, Device, int >( buffer, 1 ); -}; +bool fileExists( const tnlString& fileName ); - -template< typename Type, typename Device, typename Index > -bool tnlFile :: read( Type* buffer, - const Index& elements ) -{ - tnlAssert( elements >= 0, - cerr << " elements = " << elements << endl; ); - if( ! elements ) - return true; - if( ! fileOK ) - { - cerr << "File " << fileName << " was not properly opened. " << endl; - return false; - } - if( mode != tnlReadMode ) - { - cerr << "File " << fileName << " was not opened for reading. " << endl; - return false; - } - this->readElements = 0; - const Index host_buffer_size = :: Min( ( Index ) ( tnlFileGPUvsCPUTransferBufferSize / sizeof( Type ) ), - elements ); - void* host_buffer( 0 ); - if( Device :: getDeviceType() == "tnlHost" ) - { - if( fread( buffer, - sizeof( Type ), - elements, - file ) != elements ) - { - cerr << "I am not able to read the data from the file " << fileName << "." << endl; - perror( "Fread ended with the error code" ); - return false; - } - this->readElements = elements; - return true; - } - if( Device :: getDeviceType() == "tnlCuda" ) - { -#ifdef HAVE_CUDA - /*!*** - * Here we cannot use - * - * host_buffer = new Type[ host_buffer_size ]; - * - * because it does not work for constant types like - * T = const bool. - */ - host_buffer = malloc( sizeof( Type ) * host_buffer_size ); - readElements = 0; - if( ! host_buffer ) - { - cerr << "I am sorry but I cannot allocate supporting buffer on the host for writing data from the GPU to the file " - << this -> getFileName() << "." << endl; - return false; - - } - - while( readElements < elements ) - { - int transfer = :: Min( ( Index ) ( elements - readElements ), host_buffer_size ); - size_t transfered = fread( host_buffer, sizeof( Type ), transfer, file ); - if( transfered != transfer ) - { - cerr << "I am not able to read the data from the file " << fileName << "." << endl; - cerr << transfered << " bytes were transfered. " << endl; - perror( "Fread ended with the error code" ); - return false; - } - - cudaMemcpy( ( void* ) & ( buffer[ readElements ] ), - host_buffer, - transfer * sizeof( Type ), - cudaMemcpyHostToDevice ); - if( ! checkCudaDevice ) - { - cerr << "Transfer of data from the CUDA device to the file " << this -> fileName - << " failed." << endl; - free( host_buffer ); - return false; - } - readElements += transfer; - } - free( host_buffer ); - return true; -#else - tnlCudaSupportMissingMessage;; - return false; -#endif - } - return true; -}; - -template< class Type, typename Device, typename Index > -bool tnlFile :: write( const Type* buffer, - const Index elements ) -{ - tnlAssert( elements >= 0, - cerr << " elements = " << elements << endl; ); - if( ! elements ) - return true; - if( ! fileOK ) - { - cerr << "File " << fileName << " was not properly opened. " << endl; - return false; - } - if( mode != tnlWriteMode ) - { - cerr << "File " << fileName << " was not opened for writing. " << endl; - return false; - } - - Type* buf = const_cast< Type* >( buffer ); - void* host_buffer( 0 ); - this->writtenElements = 0; - const long int host_buffer_size = :: Min( ( Index ) ( tnlFileGPUvsCPUTransferBufferSize / sizeof( Type ) ), - elements ); - if( Device :: getDeviceType() == "tnlHost" ) - { - if( fwrite( buf, - sizeof( Type ), - elements, - this->file ) != elements ) - { - cerr << "I am not able to write the data to the file " << fileName << "." << endl; - perror( "Fwrite ended with the error code" ); - return false; - } - this->writtenElements = elements; - return true; - } - if( Device :: getDeviceType() == "tnlCuda" ) - { -#ifdef HAVE_CUDA - /*!*** - * Here we cannot use - * - * host_buffer = new Type[ host_buffer_size ]; - * - * because it does not work for constant types like - * T = const bool. - */ - host_buffer = malloc( sizeof( Type ) * host_buffer_size ); - if( ! host_buffer ) - { - cerr << "I am sorry but I cannot allocate supporting buffer on the host for writing data from the GPU to the file " - << this -> getFileName() << "." << endl; - return false; - } - - while( this->writtenElements < elements ) - { - Index transfer = Min( elements - this->writtenElements, host_buffer_size ); - cudaMemcpy( host_buffer, - ( void* ) & ( buffer[ this->writtenElements ] ), - transfer * sizeof( Type ), - cudaMemcpyDeviceToHost ); - if( ! checkCudaDevice ) - { - cerr << "Transfer of data from the file " << this -> fileName - << " to the CUDA device failed." << endl; - free( host_buffer ); - return false; - } - if( fwrite( host_buffer, - sizeof( Type ), - transfer, - this->file ) != transfer ) - { - cerr << "I am not able to write the data to the file " << fileName << "." << endl; - perror( "Fwrite ended with the error code" ); - return false; - } - this->writtenElements += transfer; - } - free( host_buffer ); - return true; -#else - tnlCudaSupportMissingMessage;; - return false; -#endif - } - return true; -}; - -inline bool fileExists( const tnlString& fileName ) -{ - fstream file; - file.open( fileName. getString(), ios::in ); - bool result( true ); - if( ! file ) - result = false; - file.close(); - return result; -}; +#include <core/tnlFile_impl.h> #endif /* TNLFILE_H_ */ diff --git a/src/core/tnlFile_impl.h b/src/core/tnlFile_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..e3e6eb32f1ce86688355b11219af6dc4aa28da46 --- /dev/null +++ b/src/core/tnlFile_impl.h @@ -0,0 +1,221 @@ +/*************************************************************************** + tnlFile_impl.h - description + ------------------- + begin : Mar 5, Oct 2016 + copyright : (C) 2016 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef TNLFILE_IMPL_H +#define TNLFILE_IMPL_H + +template< typename Type, typename Device > +bool tnlFile :: read( Type* buffer ) +{ + return read< Type, Device, int >( buffer, 1 ); +}; + +template< typename Type, typename Device > +bool tnlFile :: write( const Type* buffer ) +{ + return write< Type, Device, int >( buffer, 1 ); +}; + + +template< typename Type, typename Device, typename Index > +bool tnlFile :: read( Type* buffer, + const Index& elements ) +{ + tnlAssert( elements >= 0, + cerr << " elements = " << elements << endl; ); + if( ! elements ) + return true; + if( ! fileOK ) + { + cerr << "File " << fileName << " was not properly opened. " << endl; + return false; + } + if( mode != tnlReadMode ) + { + cerr << "File " << fileName << " was not opened for reading. " << endl; + return false; + } + this->readElements = 0; + const Index host_buffer_size = :: Min( ( Index ) ( tnlFileGPUvsCPUTransferBufferSize / sizeof( Type ) ), + elements ); + void* host_buffer( 0 ); + if( Device :: getDeviceType() == "tnlHost" ) + { + if( fread( buffer, + sizeof( Type ), + elements, + file ) != elements ) + { + cerr << "I am not able to read the data from the file " << fileName << "." << endl; + perror( "Fread ended with the error code" ); + return false; + } + this->readElements = elements; + return true; + } + if( Device :: getDeviceType() == "tnlCuda" ) + { +#ifdef HAVE_CUDA + /*!*** + * Here we cannot use + * + * host_buffer = new Type[ host_buffer_size ]; + * + * because it does not work for constant types like + * T = const bool. + */ + host_buffer = malloc( sizeof( Type ) * host_buffer_size ); + readElements = 0; + if( ! host_buffer ) + { + cerr << "I am sorry but I cannot allocate supporting buffer on the host for writing data from the GPU to the file " + << this->getFileName() << "." << endl; + return false; + + } + + while( readElements < elements ) + { + int transfer = :: Min( ( Index ) ( elements - readElements ), host_buffer_size ); + size_t transfered = fread( host_buffer, sizeof( Type ), transfer, file ); + if( transfered != transfer ) + { + cerr << "I am not able to read the data from the file " << fileName << "." << endl; + cerr << transfered << " bytes were transfered. " << endl; + perror( "Fread ended with the error code" ); + return false; + } + + cudaMemcpy( ( void* ) & ( buffer[ readElements ] ), + host_buffer, + transfer * sizeof( Type ), + cudaMemcpyHostToDevice ); + if( ! checkCudaDevice ) + { + cerr << "Transfer of data from the CUDA device to the file " << this->fileName + << " failed." << endl; + free( host_buffer ); + return false; + } + readElements += transfer; + } + free( host_buffer ); + return true; +#else + tnlCudaSupportMissingMessage;; + return false; +#endif + } + return true; +}; + +template< class Type, typename Device, typename Index > +bool tnlFile :: write( const Type* buffer, + const Index elements ) +{ + tnlAssert( elements >= 0, + cerr << " elements = " << elements << endl; ); + if( ! elements ) + return true; + if( ! fileOK ) + { + cerr << "File " << fileName << " was not properly opened. " << endl; + return false; + } + if( mode != tnlWriteMode ) + { + cerr << "File " << fileName << " was not opened for writing. " << endl; + return false; + } + + Type* buf = const_cast< Type* >( buffer ); + void* host_buffer( 0 ); + this->writtenElements = 0; + const long int host_buffer_size = :: Min( ( Index ) ( tnlFileGPUvsCPUTransferBufferSize / sizeof( Type ) ), + elements ); + if( Device :: getDeviceType() == "tnlHost" ) + { + if( fwrite( buf, + sizeof( Type ), + elements, + this->file ) != elements ) + { + cerr << "I am not able to write the data to the file " << fileName << "." << endl; + perror( "Fwrite ended with the error code" ); + return false; + } + this->writtenElements = elements; + return true; + } + if( Device :: getDeviceType() == "tnlCuda" ) + { +#ifdef HAVE_CUDA + /*!*** + * Here we cannot use + * + * host_buffer = new Type[ host_buffer_size ]; + * + * because it does not work for constant types like + * T = const bool. + */ + host_buffer = malloc( sizeof( Type ) * host_buffer_size ); + if( ! host_buffer ) + { + cerr << "I am sorry but I cannot allocate supporting buffer on the host for writing data from the GPU to the file " + << this->getFileName() << "." << endl; + return false; + } + + while( this->writtenElements < elements ) + { + Index transfer = Min( elements - this->writtenElements, host_buffer_size ); + cudaMemcpy( host_buffer, + ( void* ) & ( buffer[ this->writtenElements ] ), + transfer * sizeof( Type ), + cudaMemcpyDeviceToHost ); + if( ! checkCudaDevice ) + { + cerr << "Transfer of data from the file " << this->fileName + << " to the CUDA device failed." << endl; + free( host_buffer ); + return false; + } + if( fwrite( host_buffer, + sizeof( Type ), + transfer, + this->file ) != transfer ) + { + cerr << "I am not able to write the data to the file " << fileName << "." << endl; + perror( "Fwrite ended with the error code" ); + return false; + } + this->writtenElements += transfer; + } + free( host_buffer ); + return true; +#else + tnlCudaSupportMissingMessage;; + return false; +#endif + } + return true; +}; + + + +#endif /* TNLFILE_IMPL_H */ + diff --git a/src/core/tnlHost.cpp b/src/core/tnlHost.cpp index 7d53f0435cdc88f707af57ad46b0ee45b6b3d8af..639ea76eecbe38758270d950ac8dfdcba5eb9503 100644 --- a/src/core/tnlHost.cpp +++ b/src/core/tnlHost.cpp @@ -19,6 +19,15 @@ #define TNLHOSTL_H_ #include <core/tnlHost.h> +#ifdef HAVE_OPENMP +#include <omp.h> +#endif +#include <config/tnlConfigDescription.h> +#include <config/tnlParameterContainer.h> + + +bool tnlHost::ompEnabled( true ); +int tnlHost::maxThreadsCount( -1 ); tnlString tnlHost::getDeviceType() { @@ -32,4 +41,63 @@ size_t tnlHost::getFreeMemory() return pages * page_size; }; +void tnlHost::enableOMP() +{ + ompEnabled = true; +} + +void tnlHost::disableOMP() +{ + ompEnabled = false; +} + +void tnlHost::setMaxThreadsCount( int maxThreadsCount_ ) +{ + maxThreadsCount = maxThreadsCount_; +#ifdef HAVE_OPENMP + omp_set_num_threads( maxThreadsCount ); +#endif +} + +int tnlHost::getMaxThreadsCount() +{ +#ifdef HAVE_OPENMP + if( maxThreadsCount == -1 ) + return omp_get_max_threads(); + return maxThreadsCount; +#else + return 0; +#endif +} + +int tnlHost::getThreadIdx() +{ +#ifdef HAVE_OPENMP + return omp_get_thread_num(); +#else + return 0; +#endif +} + +void tnlHost::configSetup( tnlConfigDescription& config, const tnlString& prefix ) +{ +#ifdef HAVE_OPENMP + config.addEntry< bool >( prefix + "omp-enabled", "Enable support of OpenMP.", true ); + config.addEntry< int >( prefix + "omp-max-threads", "Set maximum number of OpenMP threads.", omp_get_max_threads() ); +#else + config.addEntry< bool >( prefix + "omp-enabled", "Enable support of OpenMP (not supported on this system).", false ); + config.addEntry< int >( prefix + "omp-max-threads", "Set maximum number of OpenMP threads (not supported on this system).", 0 ); +#endif + +} + +bool tnlHost::setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + ompEnabled = parameters.getParameter< bool >( prefix + "omp-enabled" ); + maxThreadsCount = parameters.getParameter< int >( prefix + "omp-max-threads" ); + return true; +} + + #endif /* TNLHOST_H_ */ diff --git a/src/core/tnlHost.h b/src/core/tnlHost.h index 6f921492dfb24f0b5c2f8c5106eacf2ff56252c2..23826c968e7d81b4d4bd0f0b0283ec4546dda886 100644 --- a/src/core/tnlHost.h +++ b/src/core/tnlHost.h @@ -22,20 +22,48 @@ #include <core/tnlDevice.h> #include <core/tnlString.h> +class tnlConfigDescription; +class tnlParameterContainer; + class tnlHost { public: - enum { DeviceType = tnlHostDevice }; + enum { DeviceType = tnlHostDevice }; + + static tnlString getDeviceType(); + + #ifdef HAVE_CUDA + __host__ __device__ + #endif + static inline tnlDeviceEnum getDevice() { return tnlHostDevice; }; + + static size_t getFreeMemory(); + + static void disableOMP(); + + static void enableOMP(); + + static inline bool isOMPEnabled() { return ompEnabled; }; + + static void setMaxThreadsCount( int maxThreadsCount ); + + static int getMaxThreadsCount(); + + static int getThreadIdx(); + + static void configSetup( tnlConfigDescription& config, const tnlString& prefix = "" ); + + static bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); - static tnlString getDeviceType(); + protected: + + static bool ompEnabled; + + static int maxThreadsCount; -#ifdef HAVE_CUDA - __host__ __device__ -#endif - static inline tnlDeviceEnum getDevice() { return tnlHostDevice; }; - static size_t getFreeMemory(); }; #endif /* TNLHOST_H_ */ diff --git a/src/core/tnlList.h b/src/core/tnlList.h index b6ec489c82bc2986d42ae1c607a6d274f693a5b7..7d3c4579396e66968967f62df65604e33fd87c80 100644 --- a/src/core/tnlList.h +++ b/src/core/tnlList.h @@ -23,10 +23,10 @@ #include <iostream> #include <core/tnlDataElement.h> #include <core/tnlString.h> -#include <core/tnlFile.h> + #include <core/param-types.h> -using namespace :: std; +class tnlFile; //! Template for double linked lists /*! To acces elements in the list one can use method getSize() and @@ -46,397 +46,102 @@ using namespace :: std; */ template< class T > class tnlList { - protected: - //! Pointer to the first element - tnlDataElement< T >* first; + public: - //! Pointer to the last element - /*! We use pointer to last element while adding new element to keep order of elements - */ - tnlDataElement< T >* last; - - //! List size - int size; + typedef T ElementType; - //! Iterator - mutable tnlDataElement< T >* iterator; + //! Basic constructor + tnlList(); - //! Iterator index - mutable int index; + //! Copy constructor + tnlList( const tnlList& list ); - public: - typedef T ElementType; - - //! Basic constructor - tnlList() - : first( 0 ), - last( 0 ), - size( 0 ), - iterator( 0 ), - index( 0 ){}; - - //! Copy constructor - tnlList( const tnlList& list ) - : first( 0 ), - last( 0 ), - size( 0 ), - iterator( 0 ), - index( 0 ) - { - AppendList( list ); - }; - - //! Destructor - ~tnlList() { reset(); }; - - static tnlString getType() - { - return tnlString( "tnlList< " ) + ::getType< T >() + tnlString( " >" ); - }; - - //! If the list is empty return 'true' - bool isEmpty() const { return ! size; }; - - //! Return size of the list - int getSize() const { return size; }; - - //! Indexing operator - T& operator[] ( int ind ) - { - tnlAssert( ind < size, ); - //if( ! size ) return NULL; - // find fastest way to element with index i - // we can use iterator as it is set now or - // we can start from the first ro from the last - // element - //cout << "List operator[]: size = " << size - // << " current index = " << index - // << " index = " << ind << endl; - int iter_dist = abs( index - ind ); - if( ! iterator || - iter_dist > ind || - iter_dist > size - ind ) - { - // it is better to start from the first one or the last one - if( ind < size - ind ) - { - // start from the first one - //cout << "Setting curent index to 0." << endl; - index = 0; - iterator = first; - } - else - { - //cout << "Setting curent index to size - 1." << endl; - index = size - 1; - iterator = last; - } - } - while( index != ind ) - { - //cout << " current index = " << index - // << " index = " << ind << endl; - if( ind < index ) - { - iterator = iterator -> Previous(); - index --; - } - else - { - iterator = iterator -> Next(); - index ++; - } - tnlAssert( iterator, ); - } - return iterator -> Data(); - }; - - //! Indexing operator for constant instances - const T& operator[] ( int ind ) const - { - return const_cast< tnlList< T >* >( this ) -> operator[]( ind ); - } - - const tnlList& operator = ( const tnlList& lst ) - { - AppendList( lst ); - return( *this ); - } - - //! Append new data element - bool Append( const T& data ) - { - if( ! first ) - { - tnlAssert( ! last, ); - first = last = new tnlDataElement< T >( data ); - if( ! first ) return false; - } - else - { - tnlDataElement< T >* new_element = new tnlDataElement< T >( data, last, 0 ); - if( ! new_element ) return false; - tnlAssert( last, ); - last = last -> Next() = new_element; - } - size ++; - return true; - }; - - //! Prepend new data element - bool Prepend( const T& data ) - { - if( ! first ) - { - tnlAssert( ! last, ); - first = last = new tnlDataElement< T >( data ); - if( ! first ) return false; - } - else - { - tnlDataElement< T >* new_element = new tnlDataElement< T >( data, 0, first ); - if( ! new_element ) return false; - first = first -> Previous() = new_element; - } - size ++; - index ++; - return true; - }; - - //! Insert new data element at given position - bool Insert( const T& data, int ind ) - { - tnlAssert( ind <= size || ! size, ); - if( ind == 0 ) return Prepend( data ); - if( ind == size ) return Append( data ); - operator[]( ind ); - tnlDataElement< T >* new_el = - new tnlDataElement< T >( data, - iterator -> Previous(), - iterator ); - if( ! new_el ) return false; - iterator -> Previous() -> Next() = new_el; - iterator -> Previous() = new_el; - iterator = new_el; - size ++; - return true; - }; - - //! Append copy of another list - bool AppendList( const tnlList< T >& lst ) - { - int i; - for( i = 0; i < lst. getSize(); i ++ ) - { - if( ! Append( lst[ i ] ) ) return false; - } - return true; - }; - - //! Prepend copy of another list - bool PrependList( const tnlList< T >& lst ) - - { - int i; - for( i = lst. getSize(); i > 0; i -- ) - if( ! Prepend( lst[ i - 1 ] ) ) return false; - return true; - }; - - template< typename Array > - void toArray( Array& array ) - { - tnlAssert( this->getSize() <= array.getSize(), - cerr << "this->getSize() = " << this->getSize() - << " array.getSize() = " << array.getSize() << endl; ); - for( int i = 0; i < this->getSize(); i++ ) - array[ i ] = ( *this )[ i ]; - } - - //! Erase data element at given position - void Erase( int ind ) - { - operator[]( ind ); - tnlDataElement< T >* tmp_it = iterator; - if( iterator -> Next() ) - iterator -> Next() -> Previous() = iterator -> Previous(); - if( iterator -> Previous() ) - iterator -> Previous() -> Next() = iterator -> Next(); - if( iterator -> Next() ) iterator = iterator -> Next(); - else - { - iterator = iterator -> Previous(); - index --; - } - if( first == tmp_it ) first = iterator; - if( last == tmp_it ) last = iterator; - delete tmp_it; - size --; - }; - - //! Erase data element with contained data at given position - void DeepErase( int ind ) - { - operator[]( ind ); - delete iterator -> Data(); - Erase( ind ); - }; - - //! Erase all data elements - void reset() - { - iterator = first; - tnlDataElement< T >* tmp_it; - while( iterator ) - { - tnlAssert( iterator, ); - tmp_it = iterator; - iterator = iterator -> Next(); - delete tmp_it; - } - first = last = 0; - size = 0; - }; - - //! Erase all data elements with contained data - void DeepEraseAll() - { - iterator = first; - tnlDataElement< T >* tmp_it; - while( iterator ) - { - tmp_it = iterator; - iterator = iterator -> Next(); - delete tmp_it -> Data(); - delete tmp_it; - } - first = last = 0; - size = 0; - }; - - //! Save the list in binary format - bool Save( tnlFile& file ) const - { -#ifdef HAVE_NOT_CXX11 - file. write< const int, tnlHost >( &size ); - for( int i = 0; i < size; i ++ ) - if( ! file. write< int, tnlHost, int >( &operator[]( i ), 1 ) ) - return false; - return true; -#else - file. write( &size ); - for( int i = 0; i < size; i ++ ) - if( ! file. write( &operator[]( i ), 1 ) ) - return false; - return true; - -#endif - } - - //! Save the list in binary format using method save of type T - bool DeepSave( tnlFile& file ) const - { -#ifdef HAVE_NOT_CXX11 - file. write< const int, tnlHost >( &size ); - for( int i = 0; i < size; i ++ ) - if( ! operator[]( i ). save( file ) ) return false; - return true; -#else - file. write( &size ); - for( int i = 0; i < size; i ++ ) - if( ! operator[]( i ). save( file ) ) return false; - return true; -#endif - } - - //! Load the list - bool Load( tnlFile& file ) - { -#ifdef HAVE_NOT_CXX11 - reset(); - int _size; - file. read< int, tnlHost >( &_size ); - if( _size < 0 ) - { - cerr << "The curve size is negative." << endl; - return false; - } - T t; - for( int i = 0; i < _size; i ++ ) - { - if( ! file. read< T, tnlHost >( &t ) ) - return false; - Append( t ); - } - return true; -#else - reset(); - int _size; - file. read( &_size, 1 ); - if( _size < 0 ) - { - cerr << "The curve size is negative." << endl; - return false; - } - T t; - for( int i = 0; i < _size; i ++ ) - { - if( ! file. read( &t, 1 ) ) - return false; - Append( t ); - } - return true; -#endif - }; - - //! Load the list using method Load of the type T - bool DeepLoad( tnlFile& file ) - { -#ifdef HAVE_NOT_CXX11 - reset(); - int _size; - file. read< int, tnlHost >( &_size ); - if( _size < 0 ) - { - cerr << "The list size is negative." << endl; - return false; - } - for( int i = 0; i < _size; i ++ ) - { - T t; - if( ! t. load( file ) ) return false; - Append( t ); - } - return true; -#else - reset(); - int _size; - file. read( &_size ); - if( _size < 0 ) - { - cerr << "The list size is negative." << endl; - return false; - } - for( int i = 0; i < _size; i ++ ) - { - T t; - if( ! t. load( file ) ) return false; - Append( t ); - } - return true; -#endif - }; + //! Destructor + ~tnlList(); + + static tnlString getType(); + + //! If the list is empty return 'true' + bool isEmpty() const; + + //! Return size of the list + int getSize() const; + + //! Indexing operator + T& operator[] ( const int& ind ); + + //! Indexing operator for constant instances + const T& operator[] ( const int& ind ) const; + + const tnlList& operator = ( const tnlList& lst ); + + //! Append new data element + bool Append( const T& data ); + + //! Prepend new data element + bool Prepend( const T& data ); + + //! Insert new data element at given position + bool Insert( const T& data, const int& ind ); + + //! Append copy of another list + bool AppendList( const tnlList< T >& lst ); + + //! Prepend copy of another list + bool PrependList( const tnlList< T >& lst ); + + template< typename Array > + void toArray( Array& array ); + + //! Erase data element at given position + void Erase( const int& ind ); + + //! Erase data element with contained data at given position + void DeepErase( const int& ind ); + + //! Erase all data elements + void reset(); + + //! Erase all data elements with contained data + void DeepEraseAll(); + + //! Save the list in binary format + bool Save( tnlFile& file ) const; + + //! Save the list in binary format using method save of type T + bool DeepSave( tnlFile& file ) const; + + //! Load the list + bool Load( tnlFile& file ); + + //! Load the list using method Load of the type T + bool DeepLoad( tnlFile& file ); -}; + protected: + //! Pointer to the first element + tnlDataElement< T >* first; + + //! Pointer to the last element + /*! We use pointer to last element while adding new element to keep order of elements + */ + tnlDataElement< T >* last; + + //! List size + int size; + + //! Iterator + mutable tnlDataElement< T >* iterator; + + //! Iterator index + mutable int index; + -template< typename T > ostream& operator << ( ostream& str, const tnlList< T >& list ) -{ - int i, size( list. getSize() ); - for( i = 0; i < size; i ++ ) - str << "Item " << i << ":" << list[ i ] << endl; - return str; }; +template< typename T > ostream& operator << ( ostream& str, const tnlList< T >& list ); + +#include<core/tnlList_impl.h> + #endif diff --git a/src/core/tnlList_impl.h b/src/core/tnlList_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..886d5959425e1f96ec911066cf8c53c2fe7411f7 --- /dev/null +++ b/src/core/tnlList_impl.h @@ -0,0 +1,391 @@ +/*************************************************************************** + tnlList_impl.h - description + ------------------- + begin : Mar, 5 Apr 2016 12:46 PM + copyright : (C) 2016 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef TNLLIST_IMPL_H +#define TNLLIST_IMPL_H + +#include <core/tnlFile.h> + +template< typename T > +tnlList< T >::tnlList() + : first( 0 ), last( 0 ), size( 0 ), iterator( 0 ), index( 0 ) +{ +} + +template< typename T > +tnlList< T >::tnlList( const tnlList& list ) + : first( 0 ), last( 0 ), size( 0 ), iterator( 0 ), index( 0 ) +{ + AppendList( list ); +} + +template< typename T > +tnlList< T >::~tnlList() +{ + reset(); +} + +template< typename T > +tnlString tnlList< T >::getType() +{ + return tnlString( "tnlList< " ) + ::getType< T >() + tnlString( " >" ); +} + +template< typename T > +bool tnlList< T >::isEmpty() const +{ + return ! size; +} + +template< typename T > +int tnlList< T >::getSize() const +{ + return size; +} + +template< typename T > +T& tnlList< T >::operator[]( const int& ind ) +{ + tnlAssert( ind < size, ); + int iter_dist = abs( index - ind ); + if( ! iterator || + iter_dist > ind || + iter_dist > size - ind ) + { + if( ind < size - ind ) + { + //cout << "Setting curent index to 0." << endl; + index = 0; + iterator = first; + } + else + { + //cout << "Setting curent index to size - 1." << endl; + index = size - 1; + iterator = last; + } + } + while( index != ind ) + { + //cout << " current index = " << index + // << " index = " << ind << endl; + if( ind < index ) + { + iterator = iterator -> Previous(); + index --; + } + else + { + iterator = iterator -> Next(); + index ++; + } + tnlAssert( iterator, ); + } + return iterator -> Data(); +}; + +template< typename T > +const T& tnlList< T >::operator[]( const int& ind ) const +{ + return const_cast< tnlList< T >* >( this ) -> operator[]( ind ); +} + +template< typename T > +const tnlList< T >& tnlList< T >::operator = ( const tnlList& lst ) +{ + AppendList( lst ); + return( *this ); +} + +template< typename T > +bool tnlList< T >::Append( const T& data ) +{ + if( ! first ) + { + tnlAssert( ! last, ); + first = last = new tnlDataElement< T >( data ); + if( ! first ) return false; + } + else + { + tnlDataElement< T >* new_element = new tnlDataElement< T >( data, last, 0 ); + if( ! new_element ) return false; + tnlAssert( last, ); + last = last -> Next() = new_element; + } + size ++; + return true; +}; + +template< typename T > +bool tnlList< T >::Prepend( const T& data ) +{ + if( ! first ) + { + tnlAssert( ! last, ); + first = last = new tnlDataElement< T >( data ); + if( ! first ) return false; + } + else + { + tnlDataElement< T >* new_element = new tnlDataElement< T >( data, 0, first ); + if( ! new_element ) return false; + first = first -> Previous() = new_element; + } + size ++; + index ++; + return true; +}; + +template< typename T > +bool tnlList< T >::Insert( const T& data, const int& ind ) +{ + tnlAssert( ind <= size || ! size, ); + if( ind == 0 ) return Prepend( data ); + if( ind == size ) return Append( data ); + operator[]( ind ); + tnlDataElement< T >* new_el = + new tnlDataElement< T >( data, + iterator -> Previous(), + iterator ); + if( ! new_el ) return false; + iterator -> Previous() -> Next() = new_el; + iterator -> Previous() = new_el; + iterator = new_el; + size ++; + return true; +}; + +template< typename T > +bool tnlList< T >::AppendList( const tnlList< T >& lst ) +{ + int i; + for( i = 0; i < lst. getSize(); i ++ ) + { + if( ! Append( lst[ i ] ) ) return false; + } + return true; +}; + +template< typename T > +bool tnlList< T >::PrependList( const tnlList< T >& lst ) + +{ + int i; + for( i = lst. getSize(); i > 0; i -- ) + if( ! Prepend( lst[ i - 1 ] ) ) return false; + return true; +}; + +template< typename T > + template< typename Array > +void tnlList< T >::toArray( Array& array ) +{ + tnlAssert( this->getSize() <= array.getSize(), + cerr << "this->getSize() = " << this->getSize() + << " array.getSize() = " << array.getSize() << endl; ); + for( int i = 0; i < this->getSize(); i++ ) + array[ i ] = ( *this )[ i ]; +} + +template< typename T > +void tnlList< T >::Erase( const int& ind ) +{ + operator[]( ind ); + tnlDataElement< T >* tmp_it = iterator; + if( iterator -> Next() ) + iterator -> Next() -> Previous() = iterator -> Previous(); + if( iterator -> Previous() ) + iterator -> Previous() -> Next() = iterator -> Next(); + if( iterator -> Next() ) iterator = iterator -> Next(); + else + { + iterator = iterator -> Previous(); + index --; + } + if( first == tmp_it ) first = iterator; + if( last == tmp_it ) last = iterator; + delete tmp_it; + size --; +}; + +template< typename T > +void tnlList< T >::DeepErase( const int& ind ) +{ + operator[]( ind ); + delete iterator -> Data(); + Erase( ind ); +}; + +template< typename T > +void tnlList< T >::reset() +{ + iterator = first; + tnlDataElement< T >* tmp_it; + while( iterator ) + { + tnlAssert( iterator, ); + tmp_it = iterator; + iterator = iterator -> Next(); + delete tmp_it; + } + first = last = 0; + size = 0; +}; + +template< typename T > +void tnlList< T >::DeepEraseAll() +{ + iterator = first; + tnlDataElement< T >* tmp_it; + while( iterator ) + { + tmp_it = iterator; + iterator = iterator -> Next(); + delete tmp_it -> Data(); + delete tmp_it; + } + first = last = 0; + size = 0; +}; + +template< typename T > +bool tnlList< T >::Save( tnlFile& file ) const +{ +#ifdef HAVE_NOT_CXX11 + file. write< const int, tnlHost >( &size ); + for( int i = 0; i < size; i ++ ) + if( ! file. write< int, tnlHost, int >( &operator[]( i ), 1 ) ) + return false; + return true; +#else + file. write( &size ); + for( int i = 0; i < size; i ++ ) + if( ! file. write( &operator[]( i ), 1 ) ) + return false; + return true; + +#endif +} + +template< typename T > +bool tnlList< T >::DeepSave( tnlFile& file ) const +{ +#ifdef HAVE_NOT_CXX11 + file. write< const int, tnlHost >( &size ); + for( int i = 0; i < size; i ++ ) + if( ! operator[]( i ). save( file ) ) return false; + return true; +#else + file. write( &size ); + for( int i = 0; i < size; i ++ ) + if( ! operator[]( i ). save( file ) ) return false; + return true; +#endif +} + +template< typename T > +bool tnlList< T >::Load( tnlFile& file ) +{ +#ifdef HAVE_NOT_CXX11 + reset(); + int _size; + file. read< int, tnlHost >( &_size ); + if( _size < 0 ) + { + cerr << "The curve size is negative." << endl; + return false; + } + T t; + for( int i = 0; i < _size; i ++ ) + { + if( ! file. read< T, tnlHost >( &t ) ) + return false; + Append( t ); + } + return true; +#else + reset(); + int _size; + file. read( &_size, 1 ); + if( _size < 0 ) + { + cerr << "The curve size is negative." << endl; + return false; + } + T t; + for( int i = 0; i < _size; i ++ ) + { + if( ! file. read( &t, 1 ) ) + return false; + Append( t ); + } + return true; +#endif +}; + +template< typename T > +bool tnlList< T >::DeepLoad( tnlFile& file ) +{ +#ifdef HAVE_NOT_CXX11 + reset(); + int _size; + file. read< int, tnlHost >( &_size ); + if( _size < 0 ) + { + cerr << "The list size is negative." << endl; + return false; + } + for( int i = 0; i < _size; i ++ ) + { + T t; + if( ! t. load( file ) ) return false; + Append( t ); + } + return true; +#else + reset(); + int _size; + file. read( &_size ); + if( _size < 0 ) + { + cerr << "The list size is negative." << endl; + return false; + } + for( int i = 0; i < _size; i ++ ) + { + T t; + if( ! t. load( file ) ) return false; + Append( t ); + } + return true; +#endif +}; + +template< typename T > +ostream& operator << ( ostream& str, const tnlList< T >& list ) +{ + int i, size( list. getSize() ); + for( i = 0; i < size; i ++ ) + str << "Item " << i << ":" << list[ i ] << endl; + return str; +}; + + + +#endif /* TNLLIST_IMPL_H */ + diff --git a/src/core/tnlObject.cpp b/src/core/tnlObject.cpp index e8157c1393552b8f298617576e63fe57f39ec7f0..e86cc0e532026e8d21047abe65a99632e840b0a7 100644 --- a/src/core/tnlObject.cpp +++ b/src/core/tnlObject.cpp @@ -85,7 +85,7 @@ bool tnlObject :: save( const tnlString& fileName ) const cerr << "I am not bale to open the file " << fileName << " for writing." << endl; return false; } - if( ! this -> save( file ) ) + if( ! this->save( file ) ) return false; if( ! file. close() ) { @@ -103,7 +103,7 @@ bool tnlObject :: load( const tnlString& fileName ) cerr << "I am not bale to open the file " << fileName << " for reading." << endl; return false; } - if( ! this -> load( file ) ) + if( ! this->load( file ) ) return false; if( ! file. close() ) { diff --git a/src/core/tnlString.cpp b/src/core/tnlString.cpp index 7ccf68a36a2245d96696798a877d032530533d15..265984f6f5bf2909e9e3564c468caef839727b1c 100644 --- a/src/core/tnlString.cpp +++ b/src/core/tnlString.cpp @@ -420,7 +420,7 @@ bool tnlString :: getLine( istream& stream ) { std :: string str; getline( stream, str ); - this -> setString( str. data() ); + this->setString( str. data() ); if( ! ( *this ) ) return false; return true; } diff --git a/src/core/tnlTimer.cpp b/src/core/tnlTimer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..30e43f41dfb9faa83ebee6dc6b06714c589ef5f8 --- /dev/null +++ b/src/core/tnlTimer.cpp @@ -0,0 +1,152 @@ +/*************************************************************************** + tnlTimer.cpp - description + ------------------- + begin : Mar 14, 2016 + copyright : (C) 2016 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <core/tnlTimer.h> + +#include "tnlConfig.h" +#ifdef HAVE_SYS_RESOURCE_H + #include <sys/resource.h> +#endif +#ifdef HAVE_SYS_TIME_H + #include <stddef.h> + #include <sys/time.h> + #define HAVE_TIME +#endif + + +tnlTimer defaultTimer; + +tnlTimer::tnlTimer() +{ + reset(); +} + +void tnlTimer::reset() +{ + this->initialCPUTime = 0; + this->totalCPUTime = 0.0; + this->initialRealTime = 0; + this->totalRealTime = 0.0; + this->initialCPUCycles = 0; + this->totalCPUCycles = 0; + this->stopState = true; +} + +void tnlTimer::stop() +{ + + if( ! this->stopState ) + { + /**** + * Real time + */ +#ifdef HAVE_TIME + struct timeval tp; + int rtn = gettimeofday( &tp, NULL ); + this->totalRealTime += ( double ) tp. tv_sec + 1.0e-6 * ( double ) tp. tv_usec - this->initialRealTime; +#endif + + /**** + * CPU time + */ +#ifdef HAVE_SYS_RESOURCE_H + rusage initUsage; + getrusage( RUSAGE_SELF, &initUsage ); + this->totalCPUTime += initUsage. ru_utime. tv_sec + 1.0e-6 * ( double ) initUsage. ru_utime. tv_usec - this->initialCPUTime; +#endif + + /**** + * CPU cycles + */ + this->totalCPUCycles += this->rdtsc() - this->initialCPUCycles; + this->stopState = true; + } +} + +void tnlTimer::start() +{ + /**** + * Real time + */ +#ifdef HAVE_TIME + struct timeval tp; + int rtn = gettimeofday( &tp, NULL ); + this->initialRealTime = ( double ) tp. tv_sec + 1.0e-6 * ( double ) tp. tv_usec; +#endif + + /**** + * CPU Time + */ +#ifdef HAVE_SYS_RESOURCE_H + rusage initUsage; + getrusage( RUSAGE_SELF, &initUsage ); + this->initialCPUTime = initUsage. ru_utime. tv_sec + 1.0e-6 * ( double ) initUsage. ru_utime. tv_usec; +#endif + + /**** + * CPU cycles + */ + this->initialCPUCycles = this->rdtsc(); + + this->stopState = false; +} + +double tnlTimer::getRealTime() +{ +#ifdef HAVE_TIME + if( ! this->stopState ) + { + this->stop(); + this->start(); + } + return this->totalRealTime; +#else + return -1; +#endif +} + +double tnlTimer::getCPUTime() +{ +#ifdef HAVE_SYS_RESOURCE_H + if( ! this->stopState ) + { + this->stop(); + this->start(); + } + return this->totalCPUTime; +#else + return -1; +#endif +} + +unsigned long long int tnlTimer::getCPUCycles() +{ + if( ! this->stopState ) + { + this->stop(); + this->start(); + } + return this->totalCPUCycles; +} + +bool tnlTimer::writeLog( tnlLogger& logger, int logLevel ) +{ + logger.writeParameter< double >( "Real time:", this->getRealTime(), logLevel ); + logger.writeParameter< double >( "CPU time:", this->getCPUTime(), logLevel ); + logger.writeParameter< unsigned long long int >( "CPU Cycles:", this->getCPUCycles(), logLevel ); + +} diff --git a/src/core/tnlTimer.h b/src/core/tnlTimer.h new file mode 100644 index 0000000000000000000000000000000000000000..b72001da772626e35f7371ab9f97ba3db1f7a296 --- /dev/null +++ b/src/core/tnlTimer.h @@ -0,0 +1,64 @@ +/*************************************************************************** + tnlTimer.h - description + ------------------- + begin : Mar 14, 2016 + copyright : (C) 2016 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + + +#ifndef TNLTIMER_H +#define TNLTIMER_H + +#include <core/tnlLogger.h> + +class tnlTimer +{ + public: + + tnlTimer(); + + void reset(); + + void stop(); + + void start(); + + double getRealTime(); + + double getCPUTime(); + + unsigned long long int getCPUCycles(); + + bool writeLog( tnlLogger& logger, int logLevel = 0 ); + + protected: + + double initialRealTime, totalRealTime, + initialCPUTime, totalCPUTime; + + unsigned long long int initialCPUCycles, totalCPUCycles; + + bool stopState; + + inline unsigned long long rdtsc() + { + unsigned hi, lo; + __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); + return ( ( unsigned long long ) lo ) | ( ( ( unsigned long long ) hi ) << 32 ); + } +}; + +extern tnlTimer defaultTimer; + +#endif /* TNLTIMER_H */ + diff --git a/src/core/vectors/tnlMultiVector1D_impl.h b/src/core/vectors/tnlMultiVector1D_impl.h index 1fe506de95cbb7890a50f3df9c8485aa3a70650e..b2348daf8a75f69e762ae26e71d229d6e54846d4 100644 --- a/src/core/vectors/tnlMultiVector1D_impl.h +++ b/src/core/vectors/tnlMultiVector1D_impl.h @@ -77,8 +77,8 @@ bool tnlMultiVector< 1, Real, Device, Index > :: setDimensions( const tnlStaticV { tnlAssert( dimensions[ 0 ] > 0, cerr << " dimensions[ 0 ] = " << dimensions[ 0 ] ); - this -> dimensions = dimensions; - return tnlVector< Real, Device, Index > :: setSize( this -> dimensions[ 0 ] ); + this->dimensions = dimensions; + return tnlVector< Real, Device, Index > :: setSize( this->dimensions[ 0 ] ); } template< typename Real, typename Device, typename Index > @@ -91,21 +91,21 @@ bool tnlMultiVector< 1, Real, Device, Index > :: setLike( const tnlMultiVector& template< typename Real, typename Device, typename Index > void tnlMultiVector< 1, Real, Device, Index > :: getDimensions( Index& xSize ) const { - xSize = this -> dimensions[ 0 ]; + xSize = this->dimensions[ 0 ]; } template< typename Real, typename Device, typename Index > const tnlStaticVector< 1, Index >& tnlMultiVector< 1, Real, Device, Index > :: getDimensions() const { - return this -> dimensions; + return this->dimensions; } template< typename Real, typename Device, typename Index > Index tnlMultiVector< 1, Real, Device, Index > :: getElementIndex( const Index i ) const { - tnlAssert( i >= 0 && i < this -> dimensions[ 0 ], + tnlAssert( i >= 0 && i < this->dimensions[ 0 ], cerr << "i = " << i - << "this -> dimensions[ 0 ] " << this -> dimensions[ 0 ] ); + << "this->dimensions[ 0 ] " << this->dimensions[ 0 ] ); return i; } @@ -139,9 +139,9 @@ template< typename Real, typename Device, typename Index > bool tnlMultiVector< 1, Real, Device, Index > :: operator == ( const MultiVector& Vector ) const { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to compare two Vectors with different dimensions." << endl - << "First Vector name dimensions are ( " << this -> getDimensions() << " )" << endl + << "First Vector name dimensions are ( " << this->getDimensions() << " )" << endl << "Second Vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); return tnlVector< Real, Device, Index > :: operator == ( Vector ); } @@ -158,9 +158,9 @@ tnlMultiVector< 1, Real, Device, Index >& tnlMultiVector< 1, Real, Device, Index > :: operator = ( const tnlMultiVector< 1, Real, Device, Index >& Vector ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to assign two Vectors with different dimensions." << endl - << "First vector dimensions are ( " << this -> getDimensions() << " )" << endl + << "First vector dimensions are ( " << this->getDimensions() << " )" << endl << "Second vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); tnlVector< Real, Device, Index > :: operator = ( Vector ); return ( *this ); @@ -172,9 +172,9 @@ tnlMultiVector< 1, Real, Device, Index >& tnlMultiVector< 1, Real, Device, Index > :: operator = ( const MultiVector& Vector ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to assign two Vectors with different dimensions." << endl - << "First vector dimensions are ( " << this -> getDimensions() << " )" << endl + << "First vector dimensions are ( " << this->getDimensions() << " )" << endl << "Second vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); tnlVector< Real, Device, Index > :: operator = ( Vector ); return ( *this ); diff --git a/src/core/vectors/tnlMultiVector2D_impl.h b/src/core/vectors/tnlMultiVector2D_impl.h index be3f3874d9f68504a3b9ff4ea09cc39f7c9fe3e8..2373ad127b621015a5009d9d154b41bf473ae21e 100644 --- a/src/core/vectors/tnlMultiVector2D_impl.h +++ b/src/core/vectors/tnlMultiVector2D_impl.h @@ -81,8 +81,8 @@ bool tnlMultiVector< 2, Real, Device, Index > :: setDimensions( const tnlStaticV { tnlAssert( dimensions[ 0 ] > 0 && dimensions[ 1 ] > 0, cerr << "dimensions = " << dimensions ); - this -> dimensions = dimensions; - return tnlVector< Real, Device, Index > :: setSize( this -> dimensions[ 1 ] * this -> dimensions[ 0 ] ); + this->dimensions = dimensions; + return tnlVector< Real, Device, Index > :: setSize( this->dimensions[ 1 ] * this->dimensions[ 0 ] ); } template< typename Real, typename Device, typename Index > @@ -95,25 +95,25 @@ bool tnlMultiVector< 2, Real, Device, Index > :: setLike( const MultiVector& mul template< typename Real, typename Device, typename Index > void tnlMultiVector< 2, Real, Device, Index > :: getDimensions( Index& jSize, Index& iSize ) const { - iSize = this -> dimensions[ 0 ]; - jSize = this -> dimensions[ 1 ]; + iSize = this->dimensions[ 0 ]; + jSize = this->dimensions[ 1 ]; } template< typename Real, typename Device, typename Index > const tnlStaticVector< 2, Index >& tnlMultiVector< 2, Real, Device, Index > :: getDimensions() const { - return this -> dimensions; + return this->dimensions; } template< typename Real, typename Device, typename Index > Index tnlMultiVector< 2, Real, Device, Index > :: getElementIndex( const Index j, const Index i ) const { - tnlAssert( i >= 0 && i < this -> dimensions[ 0 ] && j >= 0 && j < this -> dimensions[ 1 ], + tnlAssert( i >= 0 && i < this->dimensions[ 0 ] && j >= 0 && j < this->dimensions[ 1 ], cerr << "i = " << i << "j = " << j - << "this -> dimensions[ 0 ] = " << this -> dimensions[ 0 ] - << "this -> dimensions[ 1 ] = " << this -> dimensions[ 1 ] ); - return j * this -> dimensions[ 0 ] + i; + << "this->dimensions[ 0 ] = " << this->dimensions[ 0 ] + << "this->dimensions[ 1 ] = " << this->dimensions[ 1 ] ); + return j * this->dimensions[ 0 ] + i; } template< typename Real, typename Device, typename Index > @@ -146,9 +146,9 @@ template< typename Real, typename Device, typename Index > bool tnlMultiVector< 2, Real, Device, Index > :: operator == ( const MultiVector& Vector ) const { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to compare two Vectors with different dimensions." << endl - << "First vector dimensions are ( " << this -> getDimensions() << " )" << endl + << "First vector dimensions are ( " << this->getDimensions() << " )" << endl << "Second vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); return tnlVector< Real, Device, Index > :: operator == ( Vector ); } @@ -165,9 +165,9 @@ tnlMultiVector< 2, Real, Device, Index >& tnlMultiVector< 2, Real, Device, Index > :: operator = ( const tnlMultiVector< 2, Real, Device, Index >& Vector ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to assign two Vectors with different dimensions." << endl - << "First vector dimensions are ( " << this -> getDimensions() << " )" << endl + << "First vector dimensions are ( " << this->getDimensions() << " )" << endl << "Second vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); tnlVector< Real, Device, Index > :: operator = ( Vector ); return ( *this ); @@ -179,9 +179,9 @@ tnlMultiVector< 2, Real, Device, Index >& tnlMultiVector< 2, Real, Device, Index > :: operator = ( const MultiVector& Vector ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to assign two Vectors with different dimensions." << endl - << "First vector dimensions are ( " << this -> getDimensions() << " )" << endl + << "First vector dimensions are ( " << this->getDimensions() << " )" << endl << "Second vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); tnlVector< Real, Device, Index > :: operator = ( Vector ); return ( *this ); diff --git a/src/core/vectors/tnlMultiVector3D_impl.h b/src/core/vectors/tnlMultiVector3D_impl.h index a549954007be0df8a18ba2461688de0ac6d59065..371fc1df094fd644138ee48db756d4094e90b789 100644 --- a/src/core/vectors/tnlMultiVector3D_impl.h +++ b/src/core/vectors/tnlMultiVector3D_impl.h @@ -84,10 +84,10 @@ bool tnlMultiVector< 3, Real, Device, Index > :: setDimensions( const tnlStaticV { tnlAssert( dimensions[ 0 ] > 0 && dimensions[ 1 ] > 0 && dimensions[ 2 ], cerr << "dimensions = " << dimensions ); - this -> dimensions = dimensions; - return tnlVector< Real, Device, Index > :: setSize( this -> dimensions[ 2 ] * - this -> dimensions[ 1 ] * - this -> dimensions[ 0 ] ); + this->dimensions = dimensions; + return tnlVector< Real, Device, Index > :: setSize( this->dimensions[ 2 ] * + this->dimensions[ 1 ] * + this->dimensions[ 0 ] ); } template< typename Real, typename Device, typename Index > @@ -102,15 +102,15 @@ void tnlMultiVector< 3, Real, Device, Index > :: getDimensions( Index& kSize, Index& jSize, Index& iSize ) const { - iSize = this -> dimensions[ 0 ]; - jSize = this -> dimensions[ 1 ]; - kSize = this -> dimensions[ 2 ]; + iSize = this->dimensions[ 0 ]; + jSize = this->dimensions[ 1 ]; + kSize = this->dimensions[ 2 ]; } template< typename Real, typename Device, typename Index > const tnlStaticVector< 3, Index >& tnlMultiVector< 3, Real, Device, Index > :: getDimensions() const { - return this -> dimensions; + return this->dimensions; } template< typename Real, typename Device, typename Index > @@ -118,14 +118,14 @@ Index tnlMultiVector< 3, Real, Device, Index > :: getElementIndex( const Index k const Index j, const Index i ) const { - tnlAssert( i >= 0 && i < this -> dimensions[ 0 ] && - j >= 0 && j < this -> dimensions[ 1 ] && - k >= 0 && k < this -> dimensions[ 2 ], + tnlAssert( i >= 0 && i < this->dimensions[ 0 ] && + j >= 0 && j < this->dimensions[ 1 ] && + k >= 0 && k < this->dimensions[ 2 ], cerr << " i = " << i << " j = " << j << " k = " << k - << " this -> dimensions = " << this -> dimensions ); - return ( k * this -> dimensions[ 1 ] + j ) * this -> dimensions[ 0 ] + i; + << " this->dimensions = " << this->dimensions ); + return ( k * this->dimensions[ 1 ] + j ) * this->dimensions[ 0 ] + i; } template< typename Real, typename Device, typename Index > @@ -166,9 +166,9 @@ template< typename Real, typename Device, typename Index > bool tnlMultiVector< 3, Real, Device, Index > :: operator == ( const MultiVector& Vector ) const { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to compare two Vectors with different dimensions." << endl - << "First vector dimensions are ( " << this -> getDimensions() << " )" << endl + << "First vector dimensions are ( " << this->getDimensions() << " )" << endl << "Second vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); return tnlVector< Real, Device, Index > :: operator == ( Vector ); } @@ -185,9 +185,9 @@ tnlMultiVector< 3, Real, Device, Index >& tnlMultiVector< 3, Real, Device, Index > :: operator = ( const tnlMultiVector< 3, Real, Device, Index >& Vector ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to assign two Vectors with different dimensions." << endl - << "First vector dimensions are ( " << this -> getDimensions() << " )" << endl + << "First vector dimensions are ( " << this->getDimensions() << " )" << endl << "Second vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); tnlVector< Real, Device, Index > :: operator = ( Vector ); return ( *this ); @@ -199,9 +199,9 @@ tnlMultiVector< 3, Real, Device, Index >& tnlMultiVector< 3, Real, Device, Index > :: operator = ( const MultiVector& Vector ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to assign two Vectors with different dimensions." << endl - << "First vector dimensions are ( " << this -> getDimensions() << " )" << endl + << "First vector dimensions are ( " << this->getDimensions() << " )" << endl << "Second vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); tnlVector< Real, Device, Index > :: operator = ( Vector ); return ( *this ); diff --git a/src/core/vectors/tnlMultiVector4D_impl.h b/src/core/vectors/tnlMultiVector4D_impl.h index 2e34a41bbae4458b3c912c7107494bd9370f2015..2d99447c7cd9ea34dd25e66fb651ad8ae4b76932 100644 --- a/src/core/vectors/tnlMultiVector4D_impl.h +++ b/src/core/vectors/tnlMultiVector4D_impl.h @@ -87,11 +87,11 @@ bool tnlMultiVector< 4, Real, Device, Index > :: setDimensions( const tnlStaticV { tnlAssert( dimensions[ 0 ] > 0 && dimensions[ 1 ] > 0 && dimensions[ 2 ] && dimensions[ 3 ] > 0, cerr << "dimensions = " << dimensions ); - this -> dimensions = dimensions; - return tnlVector< Real, Device, Index > :: setSize( this -> dimensions[ 3 ] * - this -> dimensions[ 2 ] * - this -> dimensions[ 1 ] * - this -> dimensions[ 0 ] ); + this->dimensions = dimensions; + return tnlVector< Real, Device, Index > :: setSize( this->dimensions[ 3 ] * + this->dimensions[ 2 ] * + this->dimensions[ 1 ] * + this->dimensions[ 0 ] ); } template< typename Real, typename Device, typename Index > @@ -107,16 +107,16 @@ void tnlMultiVector< 4, Real, Device, Index > :: getDimensions( Index& lSize, Index& jSize, Index& iSize ) const { - iSize = this -> dimensions[ 0 ]; - jSize = this -> dimensions[ 1 ]; - kSize = this -> dimensions[ 2 ]; - lSize = this -> dimensions[ 3 ]; + iSize = this->dimensions[ 0 ]; + jSize = this->dimensions[ 1 ]; + kSize = this->dimensions[ 2 ]; + lSize = this->dimensions[ 3 ]; } template< typename Real, typename Device, typename Index > const tnlStaticVector< 4, Index >& tnlMultiVector< 4, Real, Device, Index > :: getDimensions() const { - return this -> dimensions; + return this->dimensions; } template< typename Real, typename Device, typename Index > @@ -125,16 +125,16 @@ Index tnlMultiVector< 4, Real, Device, Index > :: getElementIndex( const Index l const Index j, const Index i ) const { - tnlAssert( i >= 0 && i < this -> dimensions[ 0 ] && - j >= 0 && j < this -> dimensions[ 1 ] && - k >= 0 && k < this -> dimensions[ 2 ] && - l >= 0 && l < this -> dimensions[ 3 ], + tnlAssert( i >= 0 && i < this->dimensions[ 0 ] && + j >= 0 && j < this->dimensions[ 1 ] && + k >= 0 && k < this->dimensions[ 2 ] && + l >= 0 && l < this->dimensions[ 3 ], cerr << " i = " << i << " j = " << j << " k = " << k << " l = " << l - << " this -> dimensions = " << this -> dimensions ); - return ( ( l * this -> dimensions[ 2 ] + k ) * this -> dimensions[ 1 ] + j ) * this -> dimensions[ 0 ] + i; + << " this->dimensions = " << this->dimensions ); + return ( ( l * this->dimensions[ 2 ] + k ) * this->dimensions[ 1 ] + j ) * this->dimensions[ 0 ] + i; } template< typename Real, typename Device, typename Index > @@ -183,9 +183,9 @@ template< typename Real, typename Device, typename Index > bool tnlMultiVector< 4, Real, Device, Index > :: operator == ( const MultiVector& Vector ) const { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to compare two Vectors with different dimensions." << endl - << "First vector dimensions are ( " << this -> getDimensions() << " )" << endl + << "First vector dimensions are ( " << this->getDimensions() << " )" << endl << "Second vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); return tnlVector< Real, Device, Index > :: operator == ( Vector ); } @@ -202,9 +202,9 @@ tnlMultiVector< 4, Real, Device, Index >& tnlMultiVector< 4, Real, Device, Index > :: operator = ( const tnlMultiVector< 4, Real, Device, Index >& Vector ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to assign two Vectors with different dimensions." << endl - << "First vector dimensions are ( " << this -> getDimensions() << " )" << endl + << "First vector dimensions are ( " << this->getDimensions() << " )" << endl << "Second vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); tnlVector< Real, Device, Index > :: operator = ( Vector ); return ( *this ); @@ -216,9 +216,9 @@ tnlMultiVector< 4, Real, Device, Index >& tnlMultiVector< 4, Real, Device, Index > :: operator = ( const MultiVector& Vector ) { // TODO: Static assert on dimensions - tnlAssert( this -> getDimensions() == Vector. getDimensions(), + tnlAssert( this->getDimensions() == Vector. getDimensions(), cerr << "You are attempting to assign two Vectors with different dimensions." << endl - << "First vector dimensions are ( " << this -> getDimensions() << " )" << endl + << "First vector dimensions are ( " << this->getDimensions() << " )" << endl << "Second vector dimensions are ( " << Vector. getDimensions() << " )" << endl; ); tnlVector< Real, Device, Index > :: operator = ( Vector ); return ( *this ); diff --git a/src/core/vectors/tnlVectorOperationsHost_impl.h b/src/core/vectors/tnlVectorOperationsHost_impl.h index 1b5b42ee510701efe9e803f13a06dbb365c7eacc..1ea7fd98a1b17d5a237078bc9079d8da33d2cdd8 100644 --- a/src/core/vectors/tnlVectorOperationsHost_impl.h +++ b/src/core/vectors/tnlVectorOperationsHost_impl.h @@ -102,7 +102,7 @@ getVectorL1Norm( const Vector& v ) Real result( 0.0 ); const Index n = v. getSize(); #ifdef HAVE_OPENMP -#pragma omp parallel for reduction(+:result) if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for reduction(+:result) if( tnlHost::isOMPEnabled() && n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) result += fabs( v[ i ] ); @@ -120,7 +120,7 @@ getVectorL2Norm( const Vector& v ) Real result( 0.0 ); const Index n = v. getSize(); #ifdef HAVE_OPENMP -#pragma omp parallel for reduction(+:result) if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for reduction(+:result) if( tnlHost::isOMPEnabled() &&n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) { @@ -149,7 +149,7 @@ getVectorLpNorm( const Vector& v, Real result( 0.0 ); const Index n = v. getSize(); #ifdef HAVE_OPENMP -#pragma omp parallel for reduction(+:result) if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for reduction(+:result) if( tnlHost::isOMPEnabled() &&n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) result += pow( fabs( v[ i ] ), p ); @@ -166,7 +166,7 @@ typename Vector :: RealType tnlVectorOperations< tnlHost > :: getVectorSum( cons Real result( 0.0 ); const Index n = v. getSize(); #ifdef HAVE_OPENMP -#pragma omp parallel for reduction(+:result) if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for reduction(+:result) if( tnlHost::isOMPEnabled() &&n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) result += v[ i ]; @@ -254,7 +254,7 @@ getVectorDifferenceL1Norm( const Vector1& v1, Real result( 0.0 ); const Index n = v1. getSize(); #ifdef HAVE_OPENMP -#pragma omp parallel for reduction(+:result) if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for reduction(+:result) if( tnlHost::isOMPEnabled() &&n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) result += fabs( v1[ i ] - v2[ i ] ); @@ -276,7 +276,7 @@ getVectorDifferenceL2Norm( const Vector1& v1, Real result( 0.0 ); const Index n = v1. getSize(); #ifdef HAVE_OPENMP -#pragma omp parallel for reduction(+:result) if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for reduction(+:result) if( tnlHost::isOMPEnabled() &&n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) { @@ -310,7 +310,7 @@ getVectorDifferenceLpNorm( const Vector1& v1, Real result( 0.0 ); const Index n = v1. getSize(); #ifdef HAVE_OPENMP -#pragma omp parallel for reduction(+:result) if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for reduction(+:result) if( tnlHost::isOMPEnabled() &&n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) result += pow( fabs( v1. getElement( i ) - v2. getElement( i ) ), p ); @@ -330,7 +330,7 @@ typename Vector1::RealType tnlVectorOperations< tnlHost > :: getVectorDifference Real result( 0.0 ); const Index n = v1. getSize(); #ifdef HAVE_OPENMP -#pragma omp parallel for reduction(+:result) if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for reduction(+:result) if( tnlHost::isOMPEnabled() &&n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) result += v1. getElement( i ) - v2. getElement( i ); @@ -369,7 +369,7 @@ typename Vector1 :: RealType tnlVectorOperations< tnlHost > :: getScalarProduct( Real result( 0.0 ); const Index n = v1. getSize(); #ifdef HAVE_OPENMP - #pragma omp parallel for reduction(+:result) if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold + #pragma omp parallel for reduction(+:result) if( tnlHost::isOMPEnabled() && n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i++ ) result += v1[ i ] * v2[ i ]; @@ -409,13 +409,13 @@ void tnlVectorOperations< tnlHost > :: addVector( Vector1& y, const Index n = y. getSize(); if( thisMultiplicator == 1.0 ) #ifdef HAVE_OPENMP -#pragma omp parallel for if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for if( tnlHost::isOMPEnabled() && n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) y[ i ] += alpha * x[ i ]; else #ifdef HAVE_OPENMP -#pragma omp parallel for if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for if( tnlHost::isOMPEnabled() && n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) y[ i ] = thisMultiplicator * y[ i ] + alpha * x[ i ]; @@ -443,13 +443,13 @@ addVectors( Vector1& v, const Index n = v.getSize(); if( thisMultiplicator == 1.0 ) #ifdef HAVE_OPENMP -#pragma omp parallel for if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for if( tnlHost::isOMPEnabled() && n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) v[ i ] += multiplicator1 * v1[ i ] + multiplicator2 * v2[ i ]; else #ifdef HAVE_OPENMP -#pragma omp parallel for if( n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold +#pragma omp parallel for if( tnlHost::isOMPEnabled() && n > OpenMPVectorOperationsThreshold ) // TODO: check this threshold #endif for( Index i = 0; i < n; i ++ ) v[ i ] = thisMultiplicator * v[ i ] * multiplicator1 * v1[ i ] + multiplicator2 * v2[ i ]; diff --git a/src/core/vectors/tnlVector_impl.h b/src/core/vectors/tnlVector_impl.h index 52c484e5953a4d3e8d26c10c1faadb32eb0a31dd..9615e4ca8ed3e51eeb12a4ef694fe689b251bcdd 100644 --- a/src/core/vectors/tnlVector_impl.h +++ b/src/core/vectors/tnlVector_impl.h @@ -33,7 +33,7 @@ template< typename Real, typename Index > tnlVector< Real, Device, Index >::tnlVector( const Index size ) { - this -> setSize( size ); + this->setSize( size ); } diff --git a/src/debug/tnlDebugStructure.cpp b/src/debug/tnlDebugStructure.cpp index 067dca0cf5fff766fb86906e7f51282370a48d0c..4e5dfdae3bd1e7a890dc150b5b9e925815babafa 100644 --- a/src/debug/tnlDebugStructure.cpp +++ b/src/debug/tnlDebugStructure.cpp @@ -41,7 +41,7 @@ tnlDebugStructure :: ~tnlDebugStructure() void tnlDebugStructure :: setDebug( bool debug ) { - this -> debug = debug; + this->debug = debug; } void tnlDebugStructure :: AppendGroup( tnlDebugGroup* group ) diff --git a/src/functions/tnlMeshFunctionNormGetter.h b/src/functions/tnlMeshFunctionNormGetter.h index 93f65c1975db708087d6a4b750e4dfa0908bb49e..c83a83833242ac96c06913053b35b825e65a23a1 100644 --- a/src/functions/tnlMeshFunctionNormGetter.h +++ b/src/functions/tnlMeshFunctionNormGetter.h @@ -31,13 +31,14 @@ class tnlMeshFunctionNormGetter template< int Dimensions, typename MeshReal, typename MeshIndex, - int EntityDimensions > -class tnlMeshFunctionNormGetter< tnlMeshFunction< tnlGrid< Dimensions, MeshReal, tnlHost, MeshIndex >, EntityDimensions >, + int EntityDimensions, + typename Real > +class tnlMeshFunctionNormGetter< tnlMeshFunction< tnlGrid< Dimensions, MeshReal, tnlHost, MeshIndex >, EntityDimensions, Real >, tnlGrid< Dimensions, MeshReal, tnlHost, MeshIndex > > { public: - typedef tnlMeshFunction< tnlGrid< Dimensions, MeshReal, tnlHost, MeshIndex >, EntityDimensions > MeshFunctionType; + typedef tnlMeshFunction< tnlGrid< Dimensions, MeshReal, tnlHost, MeshIndex >, EntityDimensions, Real > MeshFunctionType; typedef tnlGrid< Dimensions, MeshReal, tnlHost, MeshIndex > GridType; typedef MeshReal MeshRealType; typedef tnlHost DeviceType; @@ -109,13 +110,14 @@ class tnlMeshFunctionNormGetter< tnlMeshFunction< tnlGrid< Dimensions, MeshReal, template< int Dimensions, typename MeshReal, typename MeshIndex, - int EntityDimensions > -class tnlMeshFunctionNormGetter< tnlMeshFunction< tnlGrid< Dimensions, MeshReal, tnlCuda, MeshIndex >, EntityDimensions >, + int EntityDimensions, + typename Real > +class tnlMeshFunctionNormGetter< tnlMeshFunction< tnlGrid< Dimensions, MeshReal, tnlCuda, MeshIndex >, EntityDimensions, Real >, tnlGrid< Dimensions, MeshReal, tnlCuda, MeshIndex > > { public: - typedef tnlMeshFunction< tnlGrid< Dimensions, MeshReal, tnlCuda, MeshIndex >, EntityDimensions > MeshFunctionType; + typedef tnlMeshFunction< tnlGrid< Dimensions, MeshReal, tnlCuda, MeshIndex >, EntityDimensions, Real > MeshFunctionType; typedef tnlGrid< Dimensions, MeshReal, tnlCuda, MeshIndex > GridType; typedef MeshReal MeshRealType; typedef tnlCuda DeviceType; diff --git a/src/functions/tnlTestFunction_impl.h b/src/functions/tnlTestFunction_impl.h index 46f70b3e4fa6bf5b4717702c176b201dc7c49e8b..32271a80d9f85abbb016ccdea29db394e447f293 100644 --- a/src/functions/tnlTestFunction_impl.h +++ b/src/functions/tnlTestFunction_impl.h @@ -291,31 +291,31 @@ getPartialDerivative( const VertexType& vertex, { case constant: return scale * ( ( tnlConstantFunction< Dimensions, Real >* ) function )-> - getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + template getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); case expBump: return scale * ( ( tnlExpBumpFunction< Dimensions, Real >* ) function )-> - getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + template getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); case sinBumps: return scale * ( ( tnlSinBumpsFunction< Dimensions, Real >* ) function )-> - getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + template getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); case sinWave: return scale * ( ( tnlSinWaveFunction< Dimensions, Real >* ) function )-> - getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + template getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); case cylinder: return scale * ( ( tnlCylinderFunction< Dimensions, Real >* ) function )-> - getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + template getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); case flowerpot: return scale * ( ( tnlFlowerpotFunction< Dimensions, Real >* ) function )-> - getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + template getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); case twins: return scale * ( ( tnlTwinsFunction< Dimensions, Real >* ) function )-> - getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + template getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); case pseudoSquare: return scale * ( ( tnlPseudoSquareFunction< Dimensions, Real >* ) function )-> - getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + template getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); case blob: return scale * ( ( tnlBlobFunction< Dimensions, Real >* ) function )-> - getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + template getPartialDerivative< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); default: return 0.0; } @@ -476,17 +476,17 @@ tnlTestFunction< FunctionDimensions, Real, Device >:: printFunction( ostream& str ) const { FunctionType* f = ( FunctionType* ) this->function; - switch( Device::DeviceType ) + if( std::is_same< Device, tnlHost >::value ) { - case tnlHostDevice: - str << *f; - return str; - case tnlCudaDevice: - tnlCuda::print( f, str ); - return str; - default: - return str; + str << *f; + return str; } + if( std::is_same< Device, tnlCuda >::value ) + { + tnlCuda::print( f, str ); + return str; + } + return str; } template< int FunctionDimensions, diff --git a/src/legacy/benchmarks/tnlSpmvBenchmarkAdaptiveRgCSRMatrix.h b/src/legacy/benchmarks/tnlSpmvBenchmarkAdaptiveRgCSRMatrix.h index 5d51a2723101db419640f18f9ccbc0888c26f6cb..794874d89857b3468837bcfd119512b117ce96bd 100644 --- a/src/legacy/benchmarks/tnlSpmvBenchmarkAdaptiveRgCSRMatrix.h +++ b/src/legacy/benchmarks/tnlSpmvBenchmarkAdaptiveRgCSRMatrix.h @@ -84,14 +84,14 @@ template< typename Real, typename Index> bool tnlSpmvBenchmarkAdaptiveRgCSRMatrix< Real, Device, Index > :: setup( const tnlCSRMatrix< Real, tnlHost, Index >& matrix ) { - //tnlAssert( this -> groupSize > 0, cerr << "groupSize = " << this -> groupSize ); + //tnlAssert( this->groupSize > 0, cerr << "groupSize = " << this->groupSize ); if( Device :: getDevice() == tnlHostDevice ) { - this -> matrix. tuneFormat( desiredChunkSize, cudaBlockSize ); - if( ! this -> matrix. copyFrom( matrix ) ) + this->matrix. tuneFormat( desiredChunkSize, cudaBlockSize ); + if( ! this->matrix. copyFrom( matrix ) ) return false; //matrix. printOut( cout, "text", 30 ); - //this -> matrix. printOut( cout, "text", 30 ); + //this->matrix. printOut( cout, "text", 30 ); } if( Device :: getDevice() == tnlCudaDevice ) { @@ -99,13 +99,13 @@ bool tnlSpmvBenchmarkAdaptiveRgCSRMatrix< Real, Device, Index > :: setup( const tnlAdaptiveRgCSRMatrix< Real, tnlHost, Index > hostMatrix( "tnlSpmvBenchmarkAdaptiveRgCSRMatrix< Real, Device, Index > :: setup : hostMatrix" ); hostMatrix. tuneFormat( desiredChunkSize, cudaBlockSize ); hostMatrix. copyFrom( matrix ); - if( ! this -> matrix. copyFrom( hostMatrix ) ) + if( ! this->matrix. copyFrom( hostMatrix ) ) return false; #else return false; #endif } - this -> setupOk = true; + this->setupOk = true; return true; } @@ -114,8 +114,8 @@ template< typename Real, typename Index> void tnlSpmvBenchmarkAdaptiveRgCSRMatrix< Real, Device, Index > :: tearDown() { - //this -> matrix. setSize( 0 ); - //this -> matrix. setNonzeroElements( 0 ); + //this->matrix. setSize( 0 ); + //this->matrix. setNonzeroElements( 0 ); } template< typename Real, @@ -123,19 +123,19 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkAdaptiveRgCSRMatrix< Real, Device, Index > :: writeProgress() const { - cout << left << setw( this -> formatColumnWidth - 15 ) << "Adap. Row-grouped CSR "; + cout << left << setw( this->formatColumnWidth - 15 ) << "Adap. Row-grouped CSR "; if( Device :: getDevice() == tnlCudaDevice ) - cout << setw( 5 ) << this -> desiredChunkSize - << setw( 10 ) << this -> cudaBlockSize; + cout << setw( 5 ) << this->desiredChunkSize + << setw( 10 ) << this->cudaBlockSize; else - cout << setw( 15 ) << this -> desiredChunkSize; - cout << right << setw( this -> timeColumnWidth ) << setprecision( 2 ) << this -> getTime() - << right << setw( this -> iterationsColumnWidth ) << this -> getIterations() - << right << setw( this -> gflopsColumnWidth ) << setprecision( 2 ) << this -> getGflops(); - if( this -> getBenchmarkWasSuccesful() ) - cout << right << setw( this -> benchmarkStatusColumnWidth ) << " OK - maxError is " << this -> maxError << ". "; + cout << setw( 15 ) << this->desiredChunkSize; + cout << right << setw( this->timeColumnWidth ) << setprecision( 2 ) << this->getTime() + << right << setw( this->iterationsColumnWidth ) << this->getIterations() + << right << setw( this->gflopsColumnWidth ) << setprecision( 2 ) << this->getGflops(); + if( this->getBenchmarkWasSuccesful() ) + cout << right << setw( this->benchmarkStatusColumnWidth ) << " OK - maxError is " << this->maxError << ". "; else - cout << right << setw( this -> benchmarkStatusColumnWidth ) << " FAILED"; + cout << right << setw( this->benchmarkStatusColumnWidth ) << " FAILED"; #ifndef HAVE_CUDA if( Device :: getDevice() == tnlCudaDevice ) tnlCudaSupportMissingMessage;; @@ -152,13 +152,13 @@ void tnlSpmvBenchmarkAdaptiveRgCSRMatrix< Real, Device, Index > :: writeToLogTab const tnlCSRMatrix< Real, tnlHost, Index >& csrMatrix, bool writeMatrixInfo ) const { - if( this -> getBenchmarkWasSuccesful() ) + if( this->getBenchmarkWasSuccesful() ) { tnlString bgColor="#FFFFFF"; - double speedUp = this -> getGflops() / csrGflops; + double speedUp = this->getGflops() / csrGflops; double rgCsrSpeedUp( 0.0 ); - if( this -> bestRgCSRGflops ) - rgCsrSpeedUp = this -> getGflops() / this -> bestRgCSRGflops; + if( this->bestRgCSRGflops ) + rgCsrSpeedUp = this->getGflops() / this->bestRgCSRGflops; switch( desiredChunkSize ) { case 1: bgColor = "#666666"; break; @@ -179,20 +179,20 @@ void tnlSpmvBenchmarkAdaptiveRgCSRMatrix< Real, Device, Index > :: writeToLogTab tnlString matrixPdfFile = baseFileName + tnlString( ".pdf" ); tnlString matrixHtmlFile = baseFileName + tnlString( ".html" ); tnlAdaptiveRgCSRMatrix< Real > argCsrMatrix( inputMtxFile ); - argCsrMatrix. tuneFormat( this -> desiredChunkSize, - this -> cudaBlockSize ); + argCsrMatrix. tuneFormat( this->desiredChunkSize, + this->cudaBlockSize ); argCsrMatrix. copyFrom( csrMatrix ); - this -> printMatrixInHtml( matrixHtmlFile, argCsrMatrix ); + this->printMatrixInHtml( matrixHtmlFile, argCsrMatrix ); if( rgCsrSpeedUp > 1.0 ) bgColor=getBgColorByRgCSRSpeedUp( rgCsrSpeedUp ); logFile << " <td bgcolor=" << bgColor << "> <a href=\"" << matrixPdfFile << "\">PDF</a>, <a href=\"" << matrixHtmlFile << "\">HTML</a></td> " << endl; - logFile << " <td bgcolor=" << bgColor << "> " << this -> getArtificialZeroElements() << "</td>" << endl; + logFile << " <td bgcolor=" << bgColor << "> " << this->getArtificialZeroElements() << "</td>" << endl; } - bgColor = this -> getBgColorBySpeedUp( speedUp ); + bgColor = this->getBgColorBySpeedUp( speedUp ); tnlString textColor = "#000000"; //getBgColorByRgCSRSpeedUp( rgCsrSpeedUp ); - logFile << " <td bgcolor=" << bgColor << "><font size=3 color=\"" << textColor << "\"> " << this -> getTime() << "</font></td>" << endl; - logFile << " <td bgcolor=" << bgColor << "><font size=3 color=\"" << textColor << "\"> " << this -> getGflops() << "</font></td>" << endl; + logFile << " <td bgcolor=" << bgColor << "><font size=3 color=\"" << textColor << "\"> " << this->getTime() << "</font></td>" << endl; + logFile << " <td bgcolor=" << bgColor << "><font size=3 color=\"" << textColor << "\"> " << this->getGflops() << "</font></td>" << endl; logFile << " <td bgcolor=" << bgColor << "><font size=3 color=\"" << textColor << "\"> " << speedUp << "</font></td>" << endl; } @@ -214,7 +214,7 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkAdaptiveRgCSRMatrix< Real, Device, Index > :: setDesiredChunkSize( const Index desiredChunkSize ) { - this -> desiredChunkSize = desiredChunkSize; + this->desiredChunkSize = desiredChunkSize; } template< typename Real, @@ -222,7 +222,7 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkAdaptiveRgCSRMatrix< Real, Device, Index > :: setCudaBlockSize( const Index cudaBlockSize ) { - this -> cudaBlockSize = cudaBlockSize; + this->cudaBlockSize = cudaBlockSize; } template< typename Real, @@ -230,7 +230,7 @@ template< typename Real, typename Index > Index tnlSpmvBenchmarkAdaptiveRgCSRMatrix< Real, Device, Index > :: getArtificialZeroElements() const { - return this -> matrix. getArtificialZeroElements(); + return this->matrix. getArtificialZeroElements(); } template< typename Real, @@ -238,7 +238,7 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkAdaptiveRgCSRMatrix< Real, Device, Index > :: setBestRgCSRGflops( const double& bestRgCSRGflops ) { - this -> bestRgCSRGflops = bestRgCSRGflops; + this->bestRgCSRGflops = bestRgCSRGflops; } template< typename Real, diff --git a/src/legacy/benchmarks/tnlSpmvBenchmarkBase_impl.h b/src/legacy/benchmarks/tnlSpmvBenchmarkBase_impl.h index dd51338e56a6ad4251de8c0a9c49060a90897ad4..cbe78d3829ec7930d40735a88dbb24e4f13fb8fa 100644 --- a/src/legacy/benchmarks/tnlSpmvBenchmarkBase_impl.h +++ b/src/legacy/benchmarks/tnlSpmvBenchmarkBase_impl.h @@ -41,44 +41,44 @@ tnlSpmvBenchmarkBase< Matrix >::tnlSpmvBenchmarkBase() template< typename Matrix > bool tnlSpmvBenchmarkBase< Matrix >::getBenchmarkWasSuccesful() const { - return this -> benchmarkWasSuccesful; + return this->benchmarkWasSuccesful; } template< typename Matrix > double tnlSpmvBenchmarkBase< Matrix >::getGflops() const { - return this -> gflops; + return this->gflops; } template< typename Matrix > double tnlSpmvBenchmarkBase< Matrix >::getTime() const { - return this -> time; + return this->time; } template< typename Matrix > void tnlSpmvBenchmarkBase< Matrix >::setMaxIterations( const int maxIterations ) { - this -> maxIterations = maxIterations; + this->maxIterations = maxIterations; } template< typename Matrix > int tnlSpmvBenchmarkBase< Matrix >::getIterations() const { - return this -> iterations; + return this->iterations; } template< typename Matrix > typename Matrix::IndexType tnlSpmvBenchmarkBase< Matrix >::getArtificialZeros() const { - return this -> artificialZeros; + return this->artificialZeros; } template< typename Matrix > typename Matrix::RealType tnlSpmvBenchmarkBase< Matrix >::getMaxError() const { - return this -> maxError; + return this->maxError; } template< typename Matrix > @@ -114,7 +114,7 @@ void tnlSpmvBenchmarkBase< Matrix >::runBenchmark( const tnlVector< RealType, De iterations ++; } - this -> time = rt_timer. getTime(); + this->time = rt_timer. getTime(); firstErrorOccurence = 0; tnlVector< RealType, tnlHost, IndexType > resB( "tnlSpmvBenchmark< Real, Device, Index, Matrix > :: runBenchmark : b" ); @@ -135,7 +135,7 @@ void tnlSpmvBenchmarkBase< Matrix >::runBenchmark( const tnlVector< RealType, De error = ( RealType ) fabs( refB[ j ] ); if( error > maxError ) firstErrorOccurence = j; - this -> maxError = Max( this -> maxError, error ); + this->maxError = Max( this->maxError, error ); /*if( error > tnlSpmvBenchmarkPrecision( error ) ) benchmarkWasSuccesful = false;*/ @@ -144,7 +144,7 @@ void tnlSpmvBenchmarkBase< Matrix >::runBenchmark( const tnlVector< RealType, De //cout << "First error was on " << firstErrorOccurence << endl; double flops = 2.0 * iterations * matrix.getNumberOfNonzeroMatrixElements(); - this -> gflops = flops / time * 1.0e-9; + this->gflops = flops / time * 1.0e-9; artificialZeros = matrix.getNumberOfMatrixElements() - matrix.getNumberOfNonzeroMatrixElements(); if( verbose ) @@ -154,20 +154,20 @@ void tnlSpmvBenchmarkBase< Matrix >::runBenchmark( const tnlVector< RealType, De template< typename Matrix > void tnlSpmvBenchmarkBase< Matrix >::writeProgressTableHeader() { - int totalWidth = this -> formatColumnWidth + - this -> timeColumnWidth + - this -> iterationsColumnWidth + - this -> gflopsColumnWidth + - this -> benchmarkStatusColumnWidth + - this -> infoColumnWidth; - - cout << left << setw( this -> formatColumnWidth - 5 ) << "MATRIX FORMAT" + int totalWidth = this->formatColumnWidth + + this->timeColumnWidth + + this->iterationsColumnWidth + + this->gflopsColumnWidth + + this->benchmarkStatusColumnWidth + + this->infoColumnWidth; + + cout << left << setw( this->formatColumnWidth - 5 ) << "MATRIX FORMAT" << left << setw( 5 ) << "BLOCK" - << right << setw( this -> timeColumnWidth ) << "TIME" - << right << setw( this -> iterationsColumnWidth ) << "ITERATIONS" - << right << setw( this -> gflopsColumnWidth ) << "GFLOPS" - << right << setw( this -> benchmarkStatusColumnWidth ) << "CHECK" - << left << setw( this -> infoColumnWidth ) << " INFO" << endl + << right << setw( this->timeColumnWidth ) << "TIME" + << right << setw( this->iterationsColumnWidth ) << "ITERATIONS" + << right << setw( this->gflopsColumnWidth ) << "GFLOPS" + << right << setw( this->benchmarkStatusColumnWidth ) << "CHECK" + << left << setw( this->infoColumnWidth ) << " INFO" << endl << setfill( '-' ) << setw( totalWidth ) << "--" << endl << setfill( ' '); } diff --git a/src/legacy/benchmarks/tnlSpmvBenchmarkCSRMatrix.h b/src/legacy/benchmarks/tnlSpmvBenchmarkCSRMatrix.h index a0912c1d4a7e8791a3e6d428df31cc2a13a70174..c2328ce2b2f156169402a36886bf2c8075d62f89 100644 --- a/src/legacy/benchmarks/tnlSpmvBenchmarkCSRMatrix.h +++ b/src/legacy/benchmarks/tnlSpmvBenchmarkCSRMatrix.h @@ -51,15 +51,15 @@ class tnlSpmvBenchmarkCSRMatrix : public tnlSpmvBenchmark< Real, tnlHost, Index, template< typename Real, typename Index> bool tnlSpmvBenchmarkCSRMatrix< Real, Index > :: setup( const tnlCSRMatrix< Real, tnlHost, Index >& matrix ) { - this -> matrix = matrix; + this->matrix = matrix; const Index size = matrix. getSize(); tnlVector< Real, tnlHost > refX( "ref-x", size ), refB( "ref-b", size), backwardRefB( "backwardRef-b", size); refX. setValue( 1.0 ); - this -> matrix. vectorProduct( refX, refB ); - this -> matrix. setBackwardSpMV( true ); - this -> matrix. vectorProduct( refX, backwardRefB ); - this -> matrix. setBackwardSpMV( false ); + this->matrix. vectorProduct( refX, refB ); + this->matrix. setBackwardSpMV( true ); + this->matrix. vectorProduct( refX, backwardRefB ); + this->matrix. setBackwardSpMV( false ); Real error( 0.0 ), maxError( 0.0 ); for( Index j = 0; j < refB. getSize(); j ++ ) { @@ -70,29 +70,29 @@ bool tnlSpmvBenchmarkCSRMatrix< Real, Index > :: setup( const tnlCSRMatrix< Real maxError = Max( error, maxError ); } forwardBackwardDifference = maxError; - this -> setupOk = true; + this->setupOk = true; return true; } template< typename Real, typename Index> void tnlSpmvBenchmarkCSRMatrix< Real, Index > :: tearDown() { - this -> matrix. setSize( 0 ); + this->matrix. setSize( 0 ); } template< typename Real, typename Index > void tnlSpmvBenchmarkCSRMatrix< Real, Index > :: writeProgress() const { - cout << left << setw( this -> formatColumnWidth ) << "CSR"; + cout << left << setw( this->formatColumnWidth ) << "CSR"; // cout << left << setw( 25 ) << matrixFormat << setw( 5 ) << cudaBlockSize; - cout << right << setw( this -> timeColumnWidth ) << setprecision( 2 ) << this -> getTime() - << right << setw( this -> iterationsColumnWidth ) << this -> getIterations() - << right << setw( this -> gflopsColumnWidth ) << setprecision( 2 ) << this -> getGflops(); - if( this -> getBenchmarkWasSuccesful() ) - cout << right << setw( this -> benchmarkStatusColumnWidth ) << " OK - SpMV diff. " << getForwardBackwardDifference(); + cout << right << setw( this->timeColumnWidth ) << setprecision( 2 ) << this->getTime() + << right << setw( this->iterationsColumnWidth ) << this->getIterations() + << right << setw( this->gflopsColumnWidth ) << setprecision( 2 ) << this->getGflops(); + if( this->getBenchmarkWasSuccesful() ) + cout << right << setw( this->benchmarkStatusColumnWidth ) << " OK - SpMV diff. " << getForwardBackwardDifference(); else - cout << right << setw( this -> benchmarkStatusColumnWidth ) << " FAILED "; + cout << right << setw( this->benchmarkStatusColumnWidth ) << " FAILED "; cout << endl; } @@ -104,10 +104,10 @@ void tnlSpmvBenchmarkCSRMatrix< Real, Index > :: writeToLogTable( ostream& logFi const tnlCSRMatrix< Real, tnlHost, Index >& csrMatrix, bool writeMatrixInfo ) const { - if( this -> getBenchmarkWasSuccesful() ) + if( this->getBenchmarkWasSuccesful() ) { - logFile << " <td> " << this -> getTime() << "</font></td>" << endl; - logFile << " <td> " << this -> getGflops() << "</td>" << endl; + logFile << " <td> " << this->getTime() << "</font></td>" << endl; + logFile << " <td> " << this->getGflops() << "</td>" << endl; } else { diff --git a/src/legacy/benchmarks/tnlSpmvBenchmarkCusparseCSRMatrix.h b/src/legacy/benchmarks/tnlSpmvBenchmarkCusparseCSRMatrix.h index 9b952a6d889d9cbd1b9031ba416e478e52c9f87f..d3907e582877687de233b2172119e5c794f2a7aa 100644 --- a/src/legacy/benchmarks/tnlSpmvBenchmarkCusparseCSRMatrix.h +++ b/src/legacy/benchmarks/tnlSpmvBenchmarkCusparseCSRMatrix.h @@ -48,9 +48,9 @@ class tnlSpmvBenchmarkCusparseCSRMatrix : public tnlSpmvBenchmark< Real, tnlCuda template< typename Real, typename Index> bool tnlSpmvBenchmarkCusparseCSRMatrix< Real, Index > :: setup( const tnlCSRMatrix< Real, tnlHost, Index >& matrix ) { - if( ! this -> matrix. copyFrom( matrix ) ) + if( ! this->matrix. copyFrom( matrix ) ) return false; - this -> setupOk = true; + this->setupOk = true; return true; } @@ -58,7 +58,7 @@ template< typename Real, typename Index> void tnlSpmvBenchmarkCusparseCSRMatrix< Real, Index > :: tearDown() { - this -> matrix. reset(); + this->matrix. reset(); } template< typename Real, @@ -72,15 +72,15 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkCusparseCSRMatrix< Real, Index > :: writeProgress() const { - cout << left << setw( this -> formatColumnWidth ) << "Cusparse"; + cout << left << setw( this->formatColumnWidth ) << "Cusparse"; // cout << left << setw( 25 ) << matrixFormat << setw( 5 ) << cudaBlockSize; - cout << right << setw( this -> timeColumnWidth ) << setprecision( 2 ) << this -> getTime() - << right << setw( this -> iterationsColumnWidth ) << this -> getIterations() - << right << setw( this -> gflopsColumnWidth ) << setprecision( 2 ) << this -> getGflops(); - if( this -> getBenchmarkWasSuccesful() ) - cout << right << setw( this -> benchmarkStatusColumnWidth ) << "OK "; + cout << right << setw( this->timeColumnWidth ) << setprecision( 2 ) << this->getTime() + << right << setw( this->iterationsColumnWidth ) << this->getIterations() + << right << setw( this->gflopsColumnWidth ) << setprecision( 2 ) << this->getGflops(); + if( this->getBenchmarkWasSuccesful() ) + cout << right << setw( this->benchmarkStatusColumnWidth ) << "OK "; else - cout << right << setw( this -> benchmarkStatusColumnWidth ) << " FAILED - maxError is " << this -> maxError << ". "; + cout << right << setw( this->benchmarkStatusColumnWidth ) << " FAILED - maxError is " << this->maxError << ". "; #ifndef HAVE_CUSP cout << "CUSPARSE library is missing."; #endif @@ -102,12 +102,12 @@ void tnlSpmvBenchmarkCusparseCSRMatrix< Real, Index > :: writeToLogTable( ostrea const tnlCSRMatrix< Real, tnlHost, Index >& csrMatrix, bool writeMatrixInfo ) const { - if( this -> getBenchmarkWasSuccesful() ) + if( this->getBenchmarkWasSuccesful() ) { - double speedUp = this -> getGflops() / csrGflops; - tnlString bgColor = this -> getBgColorBySpeedUp( speedUp ); - logFile << " <td bgcolor=" << bgColor << ">" << this -> getTime() << "</td>" << endl; - logFile << " <td bgcolor=" << bgColor << ">" << this -> getGflops() << "</td>" << endl; + double speedUp = this->getGflops() / csrGflops; + tnlString bgColor = this->getBgColorBySpeedUp( speedUp ); + logFile << " <td bgcolor=" << bgColor << ">" << this->getTime() << "</td>" << endl; + logFile << " <td bgcolor=" << bgColor << ">" << this->getGflops() << "</td>" << endl; logFile << " <td bgcolor=" << bgColor << "> " << speedUp << "</td>" << endl; } diff --git a/src/legacy/benchmarks/tnlSpmvBenchmarkHybridMatrix.h b/src/legacy/benchmarks/tnlSpmvBenchmarkHybridMatrix.h index 8dffd254eedc72d39c48991e462824127a670047..fc6f36ffbe1321dcc71b30cf171707d8fc08491d 100644 --- a/src/legacy/benchmarks/tnlSpmvBenchmarkHybridMatrix.h +++ b/src/legacy/benchmarks/tnlSpmvBenchmarkHybridMatrix.h @@ -63,7 +63,7 @@ class tnlSpmvBenchmarkHybridMatrix : public tnlSpmvBenchmark< Real, tnlHost, Ind template< typename Real, typename Index> void tnlSpmvBenchmarkHybridMatrix< Real, Index > :: setFileName( const tnlString& fileName ) { - this -> fileName = fileName; + this->fileName = fileName; } template< typename Real, typename Index> @@ -85,7 +85,7 @@ void tnlSpmvBenchmarkHybridMatrix< Real, Index > :: runBenchmark( const tnlVecto const tnlVector< Real, tnlHost, Index >& refB, bool verbose ) { - this -> benchmarkWasSuccesful = false; + this->benchmarkWasSuccesful = false; #ifdef HAVE_CUSP try { @@ -93,7 +93,7 @@ void tnlSpmvBenchmarkHybridMatrix< Real, Index > :: runBenchmark( const tnlVecto cusp::hyb_matrix< Index, Real, cusp::device_memory > A; // load a matrix stored in MatrixMarket format - cusp::io::read_matrix_market_file( A, this -> fileName. getString() ); + cusp::io::read_matrix_market_file( A, this->fileName. getString() ); // allocate storage for solution (x) and right hand side (b) cusp::array1d< Real, cusp::host_memory > host_x( A.num_rows, 1 ); @@ -108,17 +108,17 @@ void tnlSpmvBenchmarkHybridMatrix< Real, Index > :: runBenchmark( const tnlVecto tnlTimerRT rt_timer; rt_timer. Reset(); - this -> iterations = 0; + this->iterations = 0; //while( rt_timer. getTime() < time ) { - for( int i = 0; i < this -> maxIterations; i ++ ) + for( int i = 0; i < this->maxIterations; i ++ ) { cusp :: multiply( A, x, b ); cudaThreadSynchronize(); - this -> iterations ++; + this->iterations ++; } } - this -> time = rt_timer. getTime(); + this->time = rt_timer. getTime(); cusp::array1d< Real, cusp::host_memory > host_b( b ); host_b = b; @@ -127,18 +127,18 @@ void tnlSpmvBenchmarkHybridMatrix< Real, Index > :: runBenchmark( const tnlVecto { //f << refB[ j ] << " - " << host_b[ j ] << " = " << refB[ j ] - host_b[ j ] << endl; if( refB[ j ] != 0.0 ) - this -> maxError = Max( this -> maxError, ( Real ) fabs( refB[ j ] - host_b[ j ] ) / ( Real ) fabs( refB[ j ] ) ); + this->maxError = Max( this->maxError, ( Real ) fabs( refB[ j ] - host_b[ j ] ) / ( Real ) fabs( refB[ j ] ) ); else - this -> maxError = Max( this -> maxError, ( Real ) fabs( refB[ j ] ) ); + this->maxError = Max( this->maxError, ( Real ) fabs( refB[ j ] ) ); } - //if( this -> maxError < 1.0 ) - this -> benchmarkWasSuccesful = true; + //if( this->maxError < 1.0 ) + this->benchmarkWasSuccesful = true; //else - // this -> benchmarkWasSuccesful = false; + // this->benchmarkWasSuccesful = false; - double flops = 2.0 * this -> iterations * this -> nonzeroElements; - this -> gflops = flops / this -> time * 1.0e-9; + double flops = 2.0 * this->iterations * this->nonzeroElements; + this->gflops = flops / this->time * 1.0e-9; } catch( std::bad_alloc ) @@ -147,7 +147,7 @@ void tnlSpmvBenchmarkHybridMatrix< Real, Index > :: runBenchmark( const tnlVecto return; } #else - this -> benchmarkWasSuccesful = false; + this->benchmarkWasSuccesful = false; #endif writeProgress(); } @@ -156,15 +156,15 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkHybridMatrix< Real, Index > :: writeProgress() const { - cout << left << setw( this -> formatColumnWidth ) << "Hybrid"; + cout << left << setw( this->formatColumnWidth ) << "Hybrid"; // cout << left << setw( 25 ) << matrixFormat << setw( 5 ) << cudaBlockSize; - cout << right << setw( this -> timeColumnWidth ) << setprecision( 2 ) << this -> getTime() - << right << setw( this -> iterationsColumnWidth ) << this -> getIterations() - << right << setw( this -> gflopsColumnWidth ) << setprecision( 2 ) << this -> getGflops(); - if( this -> getBenchmarkWasSuccesful() ) - cout << right << setw( this -> benchmarkStatusColumnWidth ) << "OK "; + cout << right << setw( this->timeColumnWidth ) << setprecision( 2 ) << this->getTime() + << right << setw( this->iterationsColumnWidth ) << this->getIterations() + << right << setw( this->gflopsColumnWidth ) << setprecision( 2 ) << this->getGflops(); + if( this->getBenchmarkWasSuccesful() ) + cout << right << setw( this->benchmarkStatusColumnWidth ) << "OK "; else - cout << right << setw( this -> benchmarkStatusColumnWidth ) << " FAILED - maxError is " << this -> maxError << ". "; + cout << right << setw( this->benchmarkStatusColumnWidth ) << " FAILED - maxError is " << this->maxError << ". "; #ifndef HAVE_CUSP cout << "CUSP library is missing."; #endif @@ -179,12 +179,12 @@ void tnlSpmvBenchmarkHybridMatrix< Real, Index > :: writeToLogTable( ostream& lo const tnlCSRMatrix< Real, tnlHost, Index >& csrMatrix, bool writeMatrixInfo ) const { - if( this -> getBenchmarkWasSuccesful() ) + if( this->getBenchmarkWasSuccesful() ) { - double speedUp = this -> getGflops() / csrGflops; - tnlString bgColor = this -> getBgColorBySpeedUp( speedUp ); - logFile << " <td bgcolor=" << bgColor << ">" << this -> getTime() << "</td>" << endl; - logFile << " <td bgcolor=" << bgColor << ">" << this -> getGflops() << "</td>" << endl; + double speedUp = this->getGflops() / csrGflops; + tnlString bgColor = this->getBgColorBySpeedUp( speedUp ); + logFile << " <td bgcolor=" << bgColor << ">" << this->getTime() << "</td>" << endl; + logFile << " <td bgcolor=" << bgColor << ">" << this->getGflops() << "</td>" << endl; logFile << " <td bgcolor=" << bgColor << "> " << speedUp << "</td>" << endl; } @@ -201,7 +201,7 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkHybridMatrix< Real, Index > :: setNonzeroElements( const Index nonzeroElements ) { - this -> nonzeroElements = nonzeroElements; + this->nonzeroElements = nonzeroElements; } #endif /* TNLSPMVBENCHMARKHYBRIDMATRIX_H_ */ diff --git a/src/legacy/benchmarks/tnlSpmvBenchmarkRgCSRMatrix.h b/src/legacy/benchmarks/tnlSpmvBenchmarkRgCSRMatrix.h index 5209fededda3b0bd79bf46a5b30c421318d1e5a1..8dd3d85b83e4e59d37cde56eb4ff46a9f051a614 100644 --- a/src/legacy/benchmarks/tnlSpmvBenchmarkRgCSRMatrix.h +++ b/src/legacy/benchmarks/tnlSpmvBenchmarkRgCSRMatrix.h @@ -76,13 +76,13 @@ template< typename Real, typename Index> bool tnlSpmvBenchmarkRgCSRMatrix< Real, Device, Index > :: setup( const tnlCSRMatrix< Real, tnlHost, Index >& csrMatrix ) { - tnlAssert( this -> groupSize > 0, cerr << "groupSize = " << this -> groupSize ); + tnlAssert( this->groupSize > 0, cerr << "groupSize = " << this->groupSize ); if( Device :: getDevice() == tnlHostDevice ) { - this -> matrix. tuneFormat( groupSize, - this -> useAdaptiveGroupSize, - this -> adaptiveGroupSizeStrategy ); - if( ! this -> matrix. copyFrom( csrMatrix ) ) + this->matrix. tuneFormat( groupSize, + this->useAdaptiveGroupSize, + this->adaptiveGroupSizeStrategy ); + if( ! this->matrix. copyFrom( csrMatrix ) ) return false; } if( Device :: getDevice() == tnlCudaDevice ) @@ -90,16 +90,16 @@ bool tnlSpmvBenchmarkRgCSRMatrix< Real, Device, Index > :: setup( const tnlCSRMa #ifdef HAVE_CUDA tnlRgCSRMatrix< Real, tnlHost, Index > hostMatrix( "tnlSpmvBenchmarkRgCSRMatrix< Real, Device, Index > :: setup : hostMatrix" ); hostMatrix. tuneFormat( groupSize, - this -> useAdaptiveGroupSize, - this -> adaptiveGroupSizeStrategy ); + this->useAdaptiveGroupSize, + this->adaptiveGroupSizeStrategy ); hostMatrix. copyFrom( csrMatrix ); - if( ! this -> matrix. copyFrom( hostMatrix ) ) + if( ! this->matrix. copyFrom( hostMatrix ) ) return false; #else return false; #endif } - this -> setupOk = true; + this->setupOk = true; return true; } @@ -108,7 +108,7 @@ template< typename Real, typename Index> void tnlSpmvBenchmarkRgCSRMatrix< Real, Device, Index > :: tearDown() { - this -> matrix. reset(); + this->matrix. reset(); } template< typename Real, @@ -116,29 +116,29 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkRgCSRMatrix< Real, Device, Index > :: writeProgress() const { - cout << left << setw( this -> formatColumnWidth - 15 ) << "Row-grouped CSR "; + cout << left << setw( this->formatColumnWidth - 15 ) << "Row-grouped CSR "; if( Device :: getDevice() == tnlCudaDevice ) { if( useAdaptiveGroupSize ) cout << setw( 5 ) << "Var."; else - cout << setw( 5 ) << this -> groupSize; - cout << setw( 10 ) << this -> cudaBlockSize; + cout << setw( 5 ) << this->groupSize; + cout << setw( 10 ) << this->cudaBlockSize; } else { if( useAdaptiveGroupSize ) cout << setw( 15 ) << "Var."; else - cout << setw( 15 ) << this -> groupSize; + cout << setw( 15 ) << this->groupSize; } - cout << right << setw( this -> timeColumnWidth ) << setprecision( 2 ) << this -> getTime() - << right << setw( this -> iterationsColumnWidth ) << this -> getIterations() - << right << setw( this -> gflopsColumnWidth ) << setprecision( 2 ) << this -> getGflops(); - if( this -> getBenchmarkWasSuccesful() ) - cout << right << setw( this -> benchmarkStatusColumnWidth ) << " OK - maxError is " << this -> maxError << ". "; + cout << right << setw( this->timeColumnWidth ) << setprecision( 2 ) << this->getTime() + << right << setw( this->iterationsColumnWidth ) << this->getIterations() + << right << setw( this->gflopsColumnWidth ) << setprecision( 2 ) << this->getGflops(); + if( this->getBenchmarkWasSuccesful() ) + cout << right << setw( this->benchmarkStatusColumnWidth ) << " OK - maxError is " << this->maxError << ". "; else - cout << right << setw( this -> benchmarkStatusColumnWidth ) << " FAILED - maxError is " << this -> maxError << ". "; + cout << right << setw( this->benchmarkStatusColumnWidth ) << " FAILED - maxError is " << this->maxError << ". "; #ifndef HAVE_CUDA if( Device :: getDevice() == tnlCudaDevice ) tnlCudaSupportMissingMessage;; @@ -151,7 +151,7 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkRgCSRMatrix< Real, Device, Index > :: setGroupSize( const Index groupSize ) { - this -> groupSize = groupSize; + this->groupSize = groupSize; } template< typename Real, @@ -159,8 +159,8 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkRgCSRMatrix< Real, Device, Index > :: setCudaBlockSize( const Index cudaBlockSize ) { - this -> matrix. setCUDABlockSize( cudaBlockSize ); - this -> cudaBlockSize = cudaBlockSize; + this->matrix. setCUDABlockSize( cudaBlockSize ); + this->cudaBlockSize = cudaBlockSize; } template< typename Real, @@ -168,7 +168,7 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkRgCSRMatrix< Real, Device, Index > :: setUseAdaptiveGroupSize( bool useAdaptiveGroupSize ) { - this -> useAdaptiveGroupSize = useAdaptiveGroupSize; + this->useAdaptiveGroupSize = useAdaptiveGroupSize; } template< typename Real, @@ -176,7 +176,7 @@ template< typename Real, typename Index > void tnlSpmvBenchmarkRgCSRMatrix< Real, Device, Index > :: setAdaptiveGroupSizeStrategy( tnlAdaptiveGroupSizeStrategy adaptiveGroupSizeStrategy ) { - this -> adaptiveGroupSizeStrategy = adaptiveGroupSizeStrategy; + this->adaptiveGroupSizeStrategy = adaptiveGroupSizeStrategy; } template< typename Real, @@ -184,7 +184,7 @@ template< typename Real, typename Index > Index tnlSpmvBenchmarkRgCSRMatrix< Real, Device, Index > :: getArtificialZeroElements() const { - return this -> matrix. getArtificialZeroElements(); + return this->matrix. getArtificialZeroElements(); } template< typename Real, @@ -214,20 +214,20 @@ void tnlSpmvBenchmarkRgCSRMatrix< Real, Device, Index > :: writeToLogTable( ostr tnlString matrixHtmlFile( baseFileName ); matrixHtmlFile += tnlString( ".html" ); tnlRgCSRMatrix< Real > rgCsrMatrix( inputMtxFile ); - rgCsrMatrix. tuneFormat( this -> groupSize, - this -> useAdaptiveGroupSize, - this -> adaptiveGroupSizeStrategy ); + rgCsrMatrix. tuneFormat( this->groupSize, + this->useAdaptiveGroupSize, + this->adaptiveGroupSizeStrategy ); rgCsrMatrix. copyFrom( csrMatrix ); - this -> printMatrixInHtml( matrixHtmlFile, rgCsrMatrix ); + this->printMatrixInHtml( matrixHtmlFile, rgCsrMatrix ); logFile << " <td bgcolor=" << bgColor << "> <a href=\"" << matrixPdfFile << "\">PDF</a>,<a href=\"" << matrixHtmlFile << "\"> HTML</a></td>" << endl; - logFile << " <td bgcolor=" << bgColor << "> " << this -> getArtificialZeroElements() << "</td>" << endl; + logFile << " <td bgcolor=" << bgColor << "> " << this->getArtificialZeroElements() << "</td>" << endl; } - if( this -> getBenchmarkWasSuccesful() ) + if( this->getBenchmarkWasSuccesful() ) { - const double speedUp = this -> getGflops() / csrGflops; - bgColor = this -> getBgColorBySpeedUp( speedUp ); - logFile << " <td bgcolor=" << bgColor << ">" << this -> getTime() << "</td>" << endl; - logFile << " <td bgcolor=" << bgColor << "> " << this -> getGflops() << "</td>" << endl; + const double speedUp = this->getGflops() / csrGflops; + bgColor = this->getBgColorBySpeedUp( speedUp ); + logFile << " <td bgcolor=" << bgColor << ">" << this->getTime() << "</td>" << endl; + logFile << " <td bgcolor=" << bgColor << "> " << this->getGflops() << "</td>" << endl; logFile << " <td bgcolor=" << bgColor << "> " << speedUp << "</td>" << endl; } else diff --git a/src/legacy/matrices/tnlAdaptiveRgCSRMatrix.h b/src/legacy/matrices/tnlAdaptiveRgCSRMatrix.h index 0f9e338bbac4cdd203916165435b7d17a411a98d..ac14fc2576462d6831915b6ac90ea4ff2b13e51c 100644 --- a/src/legacy/matrices/tnlAdaptiveRgCSRMatrix.h +++ b/src/legacy/matrices/tnlAdaptiveRgCSRMatrix.h @@ -250,10 +250,10 @@ template< typename Real, typename Device, typename Index > bool tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: setSize( Index newSize ) { tnlAssert( newSize > 0, cerr << "newSize = " << newSize ); - this -> size = newSize; - if( ! groupInfo. setSize( this -> getSize() ) || - ! threads. setSize( this -> getSize() ) || - ! rowToGroupMapping. setSize( this -> getSize() ) ) + this->size = newSize; + if( ! groupInfo. setSize( this->getSize() ) || + ! threads. setSize( this->getSize() ) || + ! rowToGroupMapping. setSize( this->getSize() ) ) return false; threads. setValue( 0 ); rowToGroupMapping. setValue( 0 ); @@ -308,15 +308,15 @@ template< typename Real, typename Device, typename Index > void tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: tuneFormat( const Index desiredChunkSize, const Index cudaBlockSize ) { - this -> desiredChunkSize = desiredChunkSize; - this -> cudaBlockSize = cudaBlockSize; + this->desiredChunkSize = desiredChunkSize; + this->cudaBlockSize = cudaBlockSize; } template< typename Real, typename Device, typename Index > Index tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: getFirstThreadInRow( const Index row, const Index groupId ) const { dbgFunctionName( "tnlAdaptiveRgCSRMatrix< Real, tnlHost >", "getFirstThreadInRow" ); - tnlAssert( row >= 0 && row < this -> getSize(), cerr << " row = " << row << " size = " << this -> getSize() ); + tnlAssert( row >= 0 && row < this->getSize(), cerr << " row = " << row << " size = " << this->getSize() ); //dbgExpr( row ); //dbgExpr( groupInfo[ groupId ]. firstRow ); if( row == groupInfo[ groupId ]. firstRow ) @@ -327,7 +327,7 @@ Index tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: getFirstThreadInRow( cons template< typename Real, typename Device, typename Index > Index tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: getLastThreadInRow( const Index row, const Index groupId ) const { - tnlAssert( row >= 0 && row < this -> getSize(), cerr << " row = " << row << " size = " << this -> getSize() ); + tnlAssert( row >= 0 && row < this->getSize(), cerr << " row = " << row << " size = " << this->getSize() ); return threads. getElement( row ); } @@ -335,7 +335,7 @@ template< typename Real, typename Device, typename Index > bool tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatrix< Real, tnlHost, Index >& csrMatrix ) { dbgFunctionName( "tnlAdaptiveRgCSRMatrix< Real, tnlHost >", "copyFrom" ); - if( ! this -> setSize( csrMatrix. getSize() ) ) + if( ! this->setSize( csrMatrix. getSize() ) ) return false; if( Device :: getDevice() == tnlHostDevice ) @@ -360,14 +360,14 @@ bool tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatr * First compute the group size such that the number of the non-zero elements in each group is * approximately the same. */ - groupEnd += this -> groupSizeStep; - groupEnd = Min( groupEnd, this -> getSize() ); + groupEnd += this->groupSizeStep; + groupEnd = Min( groupEnd, this->getSize() ); nonzerosInGroup = csrMatrix. row_offsets[ groupEnd ] - csrMatrix. row_offsets[ groupBegin ]; rowsInGroup = groupEnd - groupBegin; if( nonzerosInGroup < cudaBlockSize * desiredChunkSize && - groupEnd < this -> getSize() && + groupEnd < this->getSize() && rowsInGroup < cudaBlockSize ) continue; @@ -466,7 +466,7 @@ bool tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatr numberOfStoredValues += cudaBlockSize * maxChunkSize; groupBegin = groupEnd; - if( groupBegin == this -> getSize() ) + if( groupBegin == this->getSize() ) { numberOfGroups = groupId; break; @@ -505,13 +505,13 @@ bool tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatr const Index matrixRow = groupRow + baseRow; dbgCout( "Row = " << matrixRow << " group row = " << groupRow << - " firstThreadInRow = " << this -> getFirstThreadInRow( matrixRow, groupId ) << - " lastThreadInRow = " << this -> getLastThreadInRow( matrixRow, groupId ) << + " firstThreadInRow = " << this->getFirstThreadInRow( matrixRow, groupId ) << + " lastThreadInRow = " << this->getLastThreadInRow( matrixRow, groupId ) << " inserting offset = " << index ); Index pos = csrMatrix. row_offsets[ matrixRow ]; Index rowCounter( 0 ); - for( Index thread = this -> getFirstThreadInRow( matrixRow, groupId ); - thread < this -> getLastThreadInRow( matrixRow, groupId ); + for( Index thread = this->getFirstThreadInRow( matrixRow, groupId ); + thread < this->getLastThreadInRow( matrixRow, groupId ); thread ++ ) { Index insertPosition = groupInfo[ groupId ]. offset + thread; @@ -546,11 +546,11 @@ bool tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatr { const Index matrixRow = groupRow + baseRow; dbgCout( "group row = " << row << - " firstThreadInRow = " << this -> getFirstThreadInRow( matrixRow, groupId ) << - " lastThreadInRow = " << this -> getLastThreadInRow( matrixRow, groupId ) << + " firstThreadInRow = " << this->getFirstThreadInRow( matrixRow, groupId ) << + " lastThreadInRow = " << this->getLastThreadInRow( matrixRow, groupId ) << " inserting offset = " << index ); - for( Index thread = this -> getFirstThreadInRow( matrixRow, groupId ); - thread < this -> getLastThreadInRow( matrixRow, groupId ); + for( Index thread = this->getFirstThreadInRow( matrixRow, groupId ); + thread < this->getLastThreadInRow( matrixRow, groupId ); thread ++ ) { tnlAssert( index < numberOfStoredValues, cerr << "Index = " << index << " numberOfStoredValues = " << numberOfStoredValues ); @@ -597,7 +597,7 @@ bool tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlAdaptiv numberOfGroups = adaptiveRgCSRMatrix. numberOfGroups; - if( ! this -> setSize( adaptiveRgCSRMatrix. getSize() ) ) + if( ! this->setSize( adaptiveRgCSRMatrix. getSize() ) ) return false; /**** @@ -624,7 +624,7 @@ Real tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: getElement( Index row, Index column ) const { dbgFunctionName( "tnlAdaptiveRgCSRMatrix< Real, tnlHost >", "getElement" ); - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); if( Device :: getDevice() == tnlHostDevice ) { @@ -637,10 +637,10 @@ Real tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: getElement( Index row, for( Index currentRow = firstRow; currentRow < lastRow; currentRow ++ ) { if( currentRow != row ) - pointer += this -> getLastThreadInRow( currentRow, groupId ) - this -> getFirstThreadInRow( currentRow, groupId ); + pointer += this->getLastThreadInRow( currentRow, groupId ) - this->getFirstThreadInRow( currentRow, groupId ); else - for( Index i = this -> getFirstThreadInRow( currentRow, groupId ); - i < this -> getLastThreadInRow( currentRow, groupId ); + for( Index i = this->getFirstThreadInRow( currentRow, groupId ); + i < this->getLastThreadInRow( currentRow, groupId ); i ++ ) { if( columns[ pointer ] == column ) @@ -665,20 +665,20 @@ void tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVe tnlVector< Real, Device, Index >& result ) const { dbgFunctionName( "tnlAdaptiveRgCSRMatrix< Real, tnlHost >", "vectorProduct" ) - tnlAssert( vec. getSize() == this -> getSize(), + tnlAssert( vec. getSize() == this->getSize(), cerr << "The matrix and vector for a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); - tnlAssert( result. getSize() == this -> getSize(), + tnlAssert( result. getSize() == this->getSize(), cerr << "The matrix and result vector of a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); if( Device :: getDevice() == tnlHostDevice ) { Real partialSums[ 256 ]; - const Index blockDim = this -> getCUDABlockSize(); + const Index blockDim = this->getCUDABlockSize(); for( Index bId = 0; bId < numberOfGroups; bId ++ ) //for( Index bId = 0; bId < 1; bId ++ ) { @@ -730,9 +730,9 @@ void tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVe continue; Index rowCounter( 0 ), chunkCounter( firstChunk ); Real partialSum( 0.0 ); - for( Index j = 0; j < this -> getSize(); j ++) + for( Index j = 0; j < this->getSize(); j ++) { - const Real val = this -> getElement( row, j ); + const Real val = this->getElement( row, j ); if( val != 0 ) { if( row == 2265 ) @@ -784,8 +784,8 @@ void tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVe * Check the result with the method getElement */ Real checkSum( 0.0 ); - for( Index i = 0; i < this -> getSize(); i ++ ) - checkSum += this -> getElement( row, i );// * vec[ i ]; + for( Index i = 0; i < this->getSize(); i ++ ) + checkSum += this->getElement( row, i );// * vec[ i ]; if( checkSum != sum ) { @@ -808,8 +808,8 @@ void tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVe /**** * Go over all groups ... */ - dbgExpr( this -> numberOfGroups ); - for( Index groupId = 0; groupId < this -> numberOfGroups; groupId ++ ) + dbgExpr( this->numberOfGroups ); + for( Index groupId = 0; groupId < this->numberOfGroups; groupId ++ ) { /**** * In each group compute partial sums of each thread @@ -817,14 +817,14 @@ void tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVe dbgExpr( groupId ); for( Index thread = 0; thread < cudaBlockSize; thread ++ ) { - idx[ thread ] = this -> groupInfo[ groupId ]. offset + thread; + idx[ thread ] = this->groupInfo[ groupId ]. offset + thread; psum[ thread ] = 0; for( Index chunkOffset = 0; - chunkOffset < this -> groupInfo[ groupId ]. chunkSize; + chunkOffset < this->groupInfo[ groupId ]. chunkSize; chunkOffset ++ ) { - if( this -> columns[ idx[ thread ] ] != -1 ) - psum[ thread ] += this -> nonzeroElements[ idx[ thread ] ] * vec[ this -> columns[ idx[ thread ] ] ]; + if( this->columns[ idx[ thread ] ] != -1 ) + psum[ thread ] += this->nonzeroElements[ idx[ thread ] ] * vec[ this->columns[ idx[ thread ] ] ]; idx[ thread ] += cudaBlockSize; } dbgExpr( psum[ thread ] ); @@ -837,10 +837,10 @@ void tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVe row < groupInfo[ groupId ]. firstRow + groupInfo[ groupId ]. size; row ++ ) { - dbgCout( "Row: " << row << " firstThreadInRow: " << this -> getFirstThreadInRow( row, groupId ) << " lastThreadInRow: " << this -> getLastThreadInRow( row, groupId ) ); + dbgCout( "Row: " << row << " firstThreadInRow: " << this->getFirstThreadInRow( row, groupId ) << " lastThreadInRow: " << this->getLastThreadInRow( row, groupId ) ); result[ row ] = 0.0; - for( Index thread = this -> getFirstThreadInRow( row, groupId ); - thread < this -> getLastThreadInRow( row, groupId ); + for( Index thread = this->getFirstThreadInRow( row, groupId ); + thread < this->getLastThreadInRow( row, groupId ); thread ++ ) { result[ row ] += psum[ thread ]; @@ -853,11 +853,11 @@ void tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVe if( Device :: getDevice() == tnlCudaDevice ) { #ifdef HAVE_CUDA - Index blockSize = this -> getCUDABlockSize(); - const Index size = this -> getSize(); + Index blockSize = this->getCUDABlockSize(); + const Index size = this->getSize(); Index desGridSize; - desGridSize = this -> numberOfGroups; + desGridSize = this->numberOfGroups; //desGridSize = (desGridSize < 4096) ? desGridSize : 4096; cudaThreadSynchronize(); @@ -907,16 +907,16 @@ void tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: printOutGroup( ostream& st Index groupBaseRow = groupInfo[ groupId ]. firstRow; for( Index row = firstRow; row < lastRow; row ++ ) { - Index firstThread = this -> getFirstThreadInRow( row, groupId ); - Index lastThread = this -> getLastThreadInRow( row, groupId ); + Index firstThread = this->getFirstThreadInRow( row, groupId ); + Index lastThread = this->getLastThreadInRow( row, groupId ); str << " Row number: " << row << " Threads: " << firstThread << " -- " << lastThread << endl; for( Index thread = firstThread; thread < lastThread; thread ++ ) { - Index threadOffset = this -> groupInfo[ groupId ]. offset + thread; + Index threadOffset = this->groupInfo[ groupId ]. offset + thread; str << " Thread: " << thread << " Thread Offset: " << threadOffset << " Chunk: "; for( Index i = 0; i < groupInfo[ groupId ]. chunkSize; i ++ ) - str << this -> nonzeroElements[ threadOffset + i * cudaBlockSize ] << "[" - << this -> columns[ threadOffset + i * cudaBlockSize ] << "], "; + str << this->nonzeroElements[ threadOffset + i * cudaBlockSize ] << "[" + << this->columns[ threadOffset + i * cudaBlockSize ] << "], "; str << endl; } str << endl; @@ -934,13 +934,13 @@ void tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: printOut( ostream& str, { str << "Structure of tnlAdaptiveRgCSRMatrix" << endl; str << "Matrix name:" << name << endl; - str << "Matrix size:" << this -> getSize() << endl; + str << "Matrix size:" << this->getSize() << endl; str << "Allocated elements:" << nonzeroElements. getSize() << endl; str << "Number of groups: " << numberOfGroups << endl; Index print_lines = lines; if( ! print_lines ) - print_lines = this -> getSize(); + print_lines = this->getSize(); for( Index groupId = 0; groupId < numberOfGroups; groupId ++ ) { @@ -956,26 +956,26 @@ void tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: printOut( ostream& str, { str << "<h1>Structure of tnlAdaptiveRgCSRMatrix</h1>" << endl; str << "<b>Matrix name:</b> " << name << "<p>" << endl; - str << "<b>Matrix size:</b> " << this -> getSize() << "<p>" << endl; + str << "<b>Matrix size:</b> " << this->getSize() << "<p>" << endl; str << "<b>Allocated elements:</b> " << nonzeroElements. getSize() << "<p>" << endl; - str << "<b>Number of groups:</b> " << this -> numberOfGroups << "<p>" << endl; + str << "<b>Number of groups:</b> " << this->numberOfGroups << "<p>" << endl; str << "<table border=1>" << endl; str << "<tr> <td> <b> GroupId </b> </td> <td> <b> Size </b> </td> <td> <b> Chunk size </b> </td> <td> <b> % of nonzeros </b> </td> </tr>" << endl; Index print_lines = lines; if( ! print_lines ) - print_lines = this -> getSize(); + print_lines = this->getSize(); - Index minGroupSize( this -> getSize() ); + Index minGroupSize( this->getSize() ); Index maxGroupSize( 0 ); - for( Index i = 0; i < this -> numberOfGroups; i ++ ) + for( Index i = 0; i < this->numberOfGroups; i ++ ) { - const Index groupSize = this -> groupInfo. getElement( i ). size; + const Index groupSize = this->groupInfo. getElement( i ). size; minGroupSize = Min( groupSize, minGroupSize ); maxGroupSize = Max( groupSize, maxGroupSize ); - const Index chunkSize = this -> groupInfo. getElement( i ). chunkSize; - const Index allElements = chunkSize * this -> cudaBlockSize; + const Index chunkSize = this->groupInfo. getElement( i ). chunkSize; + const Index allElements = chunkSize * this->cudaBlockSize; double filling = ( double ) ( allElements ) / - ( double ) this -> nonzeroElements. getSize(); + ( double ) this->nonzeroElements. getSize(); str << "<tr> <td> " << i << "</td> <td> " << groupSize << "</td> <td> " << chunkSize @@ -1005,32 +1005,32 @@ bool tnlAdaptiveRgCSRMatrix< Real, Device, Index > :: draw( ostream& str, if( format == "eps" ) { const int elementSize = 10; - this -> writePostscriptHeader( str, elementSize ); + this->writePostscriptHeader( str, elementSize ); /**** * Draw the groups */ for( Index groupId = 0; groupId < numberOfGroups; groupId ++ ) { - const Index groupSize = this -> groupInfo. getElement( groupId ). size; + const Index groupSize = this->groupInfo. getElement( groupId ). size; if( groupId % 2 == 0 ) str << "0.9 0.9 0.9 setrgbcolor" << endl; else str << "0.8 0.8 0.8 setrgbcolor" << endl; str << "0 -" << groupSize * elementSize - << " translate newpath 0 0 " << this -> getSize() * elementSize + << " translate newpath 0 0 " << this->getSize() * elementSize << " " << groupSize * elementSize << " rectfill" << endl; } /**** * Restore black color and the origin of the coordinates */ str << "0 0 0 setrgbcolor" << endl; - str << "0 " << this -> getSize() * elementSize << " translate" << endl; + str << "0 " << this->getSize() * elementSize << " translate" << endl; if( csrMatrix ) csrMatrix -> writePostscriptBody( str, elementSize, verbose ); else - this -> writePostscriptBody( str, elementSize, verbose ); + this->writePostscriptBody( str, elementSize, verbose ); str << "showpage" << endl; diff --git a/src/legacy/matrices/tnlCSRMatrix.h b/src/legacy/matrices/tnlCSRMatrix.h index b59f0e31397a5eda5f261c05575db22f84cf04f2..73e3d9f2e665a56fe0155e05f35246c0ada346f0 100644 --- a/src/legacy/matrices/tnlCSRMatrix.h +++ b/src/legacy/matrices/tnlCSRMatrix.h @@ -269,8 +269,8 @@ tnlString tnlCSRMatrix< Real, Device, Index > :: getType() const template< typename Real, typename Device, typename Index > bool tnlCSRMatrix< Real, Device, Index > :: setSize( Index new_size ) { - this -> size = new_size; - if( ! row_offsets. setSize( this -> size + 1 ) ) + this->size = new_size; + if( ! row_offsets. setSize( this->size + 1 ) ) return false; row_offsets. setValue( 0 ); last_nonzero_element = 0; @@ -283,7 +283,7 @@ bool tnlCSRMatrix< Real, Device, Index > :: setLike( const tnlCSRMatrix< Real, D dbgFunctionName( "tnlCSRMatrix< Real, Device, Index >", "setLike" ); dbgCout( "Setting size to " << matrix. getSize() << "." ); - this -> size = matrix. getSize(); + this->size = matrix. getSize(); if( ! nonzero_elements. setLike( matrix. nonzero_elements ) || ! columns. setLike( matrix. columns ) || ! row_offsets. setLike( matrix. row_offsets ) ) @@ -323,8 +323,8 @@ Index tnlCSRMatrix< Real, Device, Index > :: getNonzeroElements() const template< typename Real, typename Device, typename Index > Index tnlCSRMatrix< Real, Device, Index > :: getNonzeroElementsInRow( const Index& row ) const { - tnlAssert( row >= 0 && row < this -> getSize(), - cerr << "row = " << row << " this -> getSize() = " << this -> getSize() ); + tnlAssert( row >= 0 && row < this->getSize(), + cerr << "row = " << row << " this->getSize() = " << this->getSize() ); return row_offsets[ row + 1 ] - row_offsets[ row ]; } @@ -340,7 +340,7 @@ Index tnlCSRMatrix< Real, Device, Index > :: checkNonzeroElements() const template< typename Real, typename Device, typename Index > Index tnlCSRMatrix< Real, Device, Index > :: getRowLength( const Index row ) const { - tnlAssert( row >= 0 && row < this -> getSize(), ); + tnlAssert( row >= 0 && row < this->getSize(), ); return row_offsets[ row + 1 ] - row_offsets[ row ]; } @@ -390,7 +390,7 @@ bool tnlCSRMatrix< Real, Device, Index > :: shiftElements( Index position, } } last_nonzero_element += shift; - for( Index i = row + 1; i <= this -> size; i ++ ) + for( Index i = row + 1; i <= this->size; i ++ ) if( row_offsets[ i ] >= position ) { row_offsets[ i ] += shift; @@ -412,13 +412,13 @@ bool tnlCSRMatrix< Real, Device, Index > :: insertRow( Index row, Index* offsets ) { dbgFunctionName( "tnlCSRMatrix< Real, Device, Index >", "insertRow" ) - tnlAssert( row >=0 && row < this -> getSize(), + tnlAssert( row >=0 && row < this->getSize(), cerr << "The row " << row << " is out of the matrix." ); tnlAssert( elements > 0, cerr << "The number of elements to insert is negative:" << elements << "." ); tnlAssert( data != NULL, cerr << "Null pointer passed as data for the inserted row." ); - tnlAssert( first_column >=0 && first_column < this -> getSize(), + tnlAssert( first_column >=0 && first_column < this->getSize(), cerr << "first_column is out of the matrix" ); tnlAssert( offsets != NULL, cerr << "Null pointer passed as data for the column offsets." ); @@ -437,7 +437,7 @@ bool tnlCSRMatrix< Real, Device, Index > :: insertRow( Index row, /* * And now those which have column larger then size - 1 */ - while( elements > 0 && first_column + offsets[ elements - 1 ] >= this -> size ) + while( elements > 0 && first_column + offsets[ elements - 1 ] >= this->size ) { elements --; dbgCout( "Decreasing elements to " << elements << "." ); @@ -474,9 +474,9 @@ template< typename Real, typename Device, typename Index > Index tnlCSRMatrix< Real, Device, Index > :: getElementPosition( Index row, Index column ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); - tnlAssert( 0 <= column && column < this -> getSize(), + tnlAssert( 0 <= column && column < this->getSize(), cerr << "The column is outside the matrix." ); Index first_in_row = row_offsets[ row ]; Index last_in_row = row_offsets[ row + 1 ]; @@ -554,11 +554,11 @@ template< typename Real, typename Device, typename Index > Real tnlCSRMatrix< Real, Device, Index > :: rowProduct( Index row, const tnlVector< Real, Device, Index >& vec ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); - tnlAssert( vec. getSize() == this -> getSize(), + tnlAssert( vec. getSize() == this->getSize(), cerr << "The matrix and vector for multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); Index i = row_offsets[ row ]; Index last_in_row = row_offsets[ row + 1 ]; @@ -580,13 +580,13 @@ template< typename Real, void tnlCSRMatrix< Real, Device, Index > :: vectorProduct( const Vector1& vec, Vector2& result ) const { - tnlAssert( vec. getSize() == this -> getSize(), + tnlAssert( vec. getSize() == this->getSize(), cerr << "The matrix and vector for a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); - tnlAssert( result. getSize() == this -> getSize(), + tnlAssert( result. getSize() == this->getSize(), cerr << "The matrix and result vector of a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << result. getSize() << endl; ); const Index* cols = columns. getData(); @@ -598,7 +598,7 @@ void tnlCSRMatrix< Real, Device, Index > :: vectorProduct( const Vector1& vec, //#ifdef HAVE_OPENMP //#pragma omp parallel for //#endif - for( Index row = 0; row < this -> size; row ++ ) + for( Index row = 0; row < this->size; row ++ ) { Real product( 0.0 ); Index i = rw_offsets[ row ]; @@ -616,7 +616,7 @@ void tnlCSRMatrix< Real, Device, Index > :: vectorProduct( const Vector1& vec, //#ifdef HAVE_OPENMP //#pragma omp parallel for //#endif - for( Index row = 0; row < this -> size; row ++ ) + for( Index row = 0; row < this->size; row ++ ) { Real product( 0.0 ); Index i = rw_offsets[ row + 1 ] - 1; @@ -638,26 +638,26 @@ bool tnlCSRMatrix< Real, Device, Index > :: performSORIteration( const Real& ome Index firstRow, Index lastRow ) const { - tnlAssert( firstRow >=0 && firstRow < this -> getSize(), - cerr << "Wrong parameter firstRow. Should be in 0..." << this -> getSize() + tnlAssert( firstRow >=0 && firstRow < this->getSize(), + cerr << "Wrong parameter firstRow. Should be in 0..." << this->getSize() << " but it equals " << firstRow << endl; ); - tnlAssert( lastRow >=0 && lastRow < this -> getSize(), - cerr << "Wrong parameter lastRow. Should be in 0..." << this -> getSize() + tnlAssert( lastRow >=0 && lastRow < this->getSize(), + cerr << "Wrong parameter lastRow. Should be in 0..." << this->getSize() << " but it equals " << lastRow << endl; ); if( lastRow == 0 ) - lastRow = this -> getSize(); + lastRow = this->getSize(); for( Index i = firstRow; i < lastRow; i ++ ) { Real diagonal( 0.0 ); Real update = b[ i ]; - for( Index j = this -> row_offsets[ i ]; j < this -> row_offsets[ i + 1 ]; j ++ ) + for( Index j = this->row_offsets[ i ]; j < this->row_offsets[ i + 1 ]; j ++ ) { - const Index column = this -> columns[ j ]; + const Index column = this->columns[ j ]; if( column == i ) - diagonal = this -> nonzero_elements[ j ]; + diagonal = this->nonzero_elements[ j ]; else - update -= this -> nonzero_elements[ j ] * x[ column ]; + update -= this->nonzero_elements[ j ] * x[ column ]; } if( diagonal == ( Real ) 0.0 ) { @@ -673,13 +673,13 @@ bool tnlCSRMatrix< Real, Device, Index > :: performSORIteration( const Real& ome template< typename Real, typename Device, typename Index > void tnlCSRMatrix< Real, Device, Index > :: setBackwardSpMV( bool backwardSpMV ) { - this -> backwardSpMV = backwardSpMV; + this->backwardSpMV = backwardSpMV; } template< typename Real, typename Device, typename Index > Real tnlCSRMatrix< Real, Device, Index > :: getRowL1Norm( Index row ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); Index i = row_offsets[ row ]; Index last_in_row = row_offsets[ row + 1 ]; @@ -693,7 +693,7 @@ Real tnlCSRMatrix< Real, Device, Index > :: getRowL1Norm( Index row ) const template< typename Real, typename Device, typename Index > void tnlCSRMatrix< Real, Device, Index > :: multiplyRow( Index row, const Real& value ) { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); Index i = row_offsets[ row ]; Index last_in_row = row_offsets[ row + 1 ]; @@ -708,12 +708,12 @@ bool tnlCSRMatrix< Real, Device, Index > :: reorderRows( const tnlVector< Index, { dbgFunctionName( "tnlCSRMatrix< Real, Device, Index >", "reorderRows" ); last_nonzero_element = 0; - if( ! this -> setLike( inputCsrMatrix ) ) + if( ! this->setLike( inputCsrMatrix ) ) { cerr << "I am not able to allocate new memory for matrix reordering." << endl; return false; } - for( Index i = 0; i < this -> getSize(); i ++ ) + for( Index i = 0; i < this->getSize(); i ++ ) { tnlAssert( last_nonzero_element < nonzero_elements. getSize(), ); tnlAssert( last_nonzero_element < columns. getSize(), ); @@ -728,9 +728,9 @@ bool tnlCSRMatrix< Real, Device, Index > :: reorderRows( const tnlVector< Index, } tnlAssert( last_nonzero_element <= nonzero_elements. getSize(), ); tnlAssert( last_nonzero_element <= columns. getSize(), ); - row_offsets[ this -> getSize() ] = last_nonzero_element; - dbgExpr( row_offsets[ this -> getSize() ] ); - dbgExpr( this -> getSize() ); + row_offsets[ this->getSize() ] = last_nonzero_element; + dbgExpr( row_offsets[ this->getSize() ] ); + dbgExpr( this->getSize() ); return true; } @@ -804,12 +804,12 @@ void tnlCSRMatrix< Real, Device, Index > :: printOut( ostream& str, { str << "Structure of tnlCSRMatrix" << endl; str << "Matrix name:" << name << endl; - str << "Matrix size:" << this -> getSize() << endl; + str << "Matrix size:" << this->getSize() << endl; str << "Allocated elements:" << nonzero_elements. getSize() << endl; str << "Matrix rows:" << endl; Index print_lines = lines; if( ! print_lines ) - print_lines = this -> getSize(); + print_lines = this->getSize(); for( Index i = 0; i < print_lines; i ++ ) { Index first = row_offsets[ i ]; @@ -834,17 +834,17 @@ void tnlCSRMatrix< Real, Device, Index > :: getRowStatistics( Index& min_row_len Index& max_row_length, Index& average_row_length ) const { - min_row_length = this -> getSize(); + min_row_length = this->getSize(); max_row_length = 0; average_row_length = 0; - for( Index i = 0; i < this -> getSize(); i ++ ) + for( Index i = 0; i < this->getSize(); i ++ ) { Index row_length = row_offsets[ i + 1 ] - row_offsets[ i ]; min_row_length = Min( min_row_length, row_length ); max_row_length = Max( max_row_length, row_length ); average_row_length += row_length; } - average_row_length /= ( double ) this -> getSize(); + average_row_length /= ( double ) this->getSize(); }; template< typename Real, typename Device, typename Index > @@ -1023,8 +1023,8 @@ bool tnlCSRMatrix< Real, Device, Index > :: read( istream& file, if( verbose ) cout << "Non-zero elements parsed: " << setw( 9 ) << right << parsed_elements << endl; - if( ! this -> setSize( size ) || - ! this -> setNonzeroElements( parsed_elements ) ) + if( ! this->setSize( size ) || + ! this->setNonzeroElements( parsed_elements ) ) { cerr << "Not enough memory to allocate the sparse or the full matrix for testing." << endl; return false; @@ -1099,17 +1099,17 @@ void tnlCSRMatrix< Real, Device, Index > :: writePostscriptBody( ostream& str, const int elementSize, bool verbose ) const { - const double scale = elementSize * this -> getSize(); - double hx = scale / ( double ) this -> getSize(); + const double scale = elementSize * this->getSize(); + double hx = scale / ( double ) this->getSize(); Index lastRow( 0 ), lastColumn( 0 ); - for( Index row = 0; row < this -> getSize(); row ++ ) + for( Index row = 0; row < this->getSize(); row ++ ) { - for( Index i = this -> row_offsets[ row ]; i < this -> row_offsets[ row + 1 ]; i ++ ) + for( Index i = this->row_offsets[ row ]; i < this->row_offsets[ row + 1 ]; i ++ ) { - Real elementValue = this -> nonzero_elements[ i ]; + Real elementValue = this->nonzero_elements[ i ]; if( elementValue != ( Real ) 0.0 ) { - Index column = this -> columns[ i ]; + Index column = this->columns[ i ]; str << ( column - lastColumn ) * elementSize << " " << -( row - lastRow ) * elementSize << " translate newpath 0 0 " << elementSize << " " << elementSize << " rectstroke" << endl; diff --git a/src/legacy/matrices/tnlCusparseCSRMatrix.h b/src/legacy/matrices/tnlCusparseCSRMatrix.h index c05be19bb41890b52477a493342027d4846bb5d7..e993b1727bfc549404e06c5761f7af60f304cc1b 100644 --- a/src/legacy/matrices/tnlCusparseCSRMatrix.h +++ b/src/legacy/matrices/tnlCusparseCSRMatrix.h @@ -208,8 +208,8 @@ tnlString tnlCusparseCSRMatrix< Real, Device, Index > :: getType() const template< typename Real, typename Device, typename Index > bool tnlCusparseCSRMatrix< Real, Device, Index > :: setSize( Index new_size ) { - this -> size = new_size; - if( ! row_offsets. setSize( this -> size + 1 ) ) + this->size = new_size; + if( ! row_offsets. setSize( this->size + 1 ) ) return false; row_offsets. setValue( 0 ); return true; @@ -221,7 +221,7 @@ bool tnlCusparseCSRMatrix< Real, Device, Index > :: setLike( const tnlCusparseCS dbgFunctionName( "tnlCusparseCSRMatrix< Real, Device, Index >", "setLike" ); dbgCout( "Setting size to " << matrix. getSize() << "." ); - this -> size = matrix. getSize(); + this->size = matrix. getSize(); if( ! nonzero_elements. setLike( matrix. nonzero_elements ) || ! columns. setLike( matrix. columns ) || ! row_offsets. setLike( matrix. row_offsets ) ) @@ -283,13 +283,13 @@ bool tnlCusparseCSRMatrix< Real, Device, Index > :: addToElement( Index row, Ind template< typename Real, typename Device, typename Index > bool tnlCusparseCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatrix< Real, tnlHost, Index >& csr_matrix ) { - if( ! this -> setSize( csr_matrix. getSize() ) || - ! this -> setNonzeroElements( csr_matrix. getNonzeroElements() ) ) + if( ! this->setSize( csr_matrix. getSize() ) || + ! this->setNonzeroElements( csr_matrix. getNonzeroElements() ) ) return false; - this -> nonzero_elements = csr_matrix. nonzero_elements; - this -> columns = csr_matrix. columns; - this -> row_offsets = csr_matrix. row_offsets; + this->nonzero_elements = csr_matrix. nonzero_elements; + this->columns = csr_matrix. columns; + this->row_offsets = csr_matrix. row_offsets; return true; } @@ -309,10 +309,10 @@ void tnlCusparseCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVect #ifdef HAVE_CUSPARSE cusparseSpmv( cusparseHandle, cusparseMatDescr, - this -> getSize(), - this -> nonzero_elements. getData(), - this -> row_offsets. getData(), - this -> columns. getData(), + this->getSize(), + this->nonzero_elements. getData(), + this->row_offsets. getData(), + this->columns. getData(), x. getData(), b. getData() ); #endif diff --git a/src/legacy/matrices/tnlEllpackMatrix.h b/src/legacy/matrices/tnlEllpackMatrix.h index 33b3c28919b370a704b9b43e772a2580905e504d..118a7b393ed9b4e4d9d8f2996d3ba64b9c86bdd6 100644 --- a/src/legacy/matrices/tnlEllpackMatrix.h +++ b/src/legacy/matrices/tnlEllpackMatrix.h @@ -132,7 +132,7 @@ tnlString tnlEllpackMatrix< Real, tnlHost, Index > :: getType() const template< typename Real, typename Index > bool tnlEllpackMatrix< Real, tnlHost, Index > :: setSize( Index new_size ) { - this -> size = new_size; + this->size = new_size; if( ! ellpack_nonzero_elements. setSize( new_size * row_length ) ) return false; ellpack_nonzero_elements. setValue( 0 ); @@ -189,7 +189,7 @@ bool tnlEllpackMatrix< Real, tnlHost, Index > :: copyFrom( const tnlCSRMatrix< R row_length = average_row_length; }*/ - if( ! this -> setSize( csr_matrix. getSize() ) ) + if( ! this->setSize( csr_matrix. getSize() ) ) return false; /* @@ -197,7 +197,7 @@ bool tnlEllpackMatrix< Real, tnlHost, Index > :: copyFrom( const tnlCSRMatrix< R * They will be stored in the COO data array. */ Index coo_elements = 0; - for( Index i = 0; i < this -> getSize(); i ++ ) + for( Index i = 0; i < this->getSize(); i ++ ) { Index csr_row_length = csr_matrix. getRowLength( i ); if( csr_row_length > row_length ) @@ -210,8 +210,8 @@ bool tnlEllpackMatrix< Real, tnlHost, Index > :: copyFrom( const tnlCSRMatrix< R */ dbgCout( "Inserting CSR row ... "); artificial_zeros = 0; - dbgExpr( this -> getSize() ); - for( Index i = 0; i < this -> getSize(); i ++ ) + dbgExpr( this->getSize() ); + for( Index i = 0; i < this->getSize(); i ++ ) { Index csr_row_length = csr_matrix. getRowLength( i ); Index csr_row_offset = csr_matrix. row_offsets[ i ]; @@ -221,7 +221,7 @@ bool tnlEllpackMatrix< Real, tnlHost, Index > :: copyFrom( const tnlCSRMatrix< R */ while( j < csr_row_length && j < row_length ) { - Index element_pos = j * this -> getSize() + i; + Index element_pos = j * this->getSize() + i; ellpack_nonzero_elements[ element_pos ] = csr_matrix. nonzero_elements[ csr_row_offset + j ]; ellpack_columns[ element_pos ] = csr_matrix. columns[ csr_row_offset + j ]; dbgExpr( element_pos ); @@ -252,7 +252,7 @@ Real tnlEllpackMatrix< Real, tnlHost, Index > :: getElement( Index row, { dbgExpr( element_pos ); i ++; - element_pos += this -> getSize(); + element_pos += this->getSize(); } if( i < row_length && ellpack_columns[ element_pos ] == column ) return ellpack_nonzero_elements[ element_pos ]; @@ -263,11 +263,11 @@ template< typename Real, typename Index > Real tnlEllpackMatrix< Real, tnlHost, Index > :: rowProduct( Index row, const tnlVector< Real, tnlHost, Index >& vector ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); - tnlAssert( vector. getSize() == this -> getSize(), + tnlAssert( vector. getSize() == this->getSize(), cerr << "The matrix and vector for multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vector. getSize() << endl; ); Real product( 0.0 ); @@ -282,7 +282,7 @@ Real tnlEllpackMatrix< Real, tnlHost, Index > :: rowProduct( Index row, product += ellpack_nonzero_elements[ element_pos ] * vector[ ellpack_columns[ element_pos ] ]; i ++; - element_pos += this -> getSize(); + element_pos += this->getSize(); } if( i < row_length ) return product; @@ -294,16 +294,16 @@ template< typename Real, typename Index > void tnlEllpackMatrix< Real, tnlHost, Index > :: vectorProduct( const tnlVector< Real, tnlHost, Index >& x, tnlVector< Real, tnlHost, Index >& b ) const { - tnlAssert( x. getSize() == this -> getSize(), + tnlAssert( x. getSize() == this->getSize(), cerr << "The matrix and vector for a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << x. getSize() << endl; ); - tnlAssert( b. getSize() == this -> getSize(), + tnlAssert( b. getSize() == this->getSize(), cerr << "The matrix and result vector of a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << b. getSize() << endl; ); - for( Index i = 0; i < this -> getSize(); i ++) + for( Index i = 0; i < this->getSize(); i ++) b[ i ] = rowProduct( i, x ); }; @@ -313,18 +313,18 @@ void tnlEllpackMatrix< Real, tnlHost, Index > :: printOut( ostream& str, { str << "Structure of tnlEllpackMatrix" << endl; str << "Matrix name:" << name << endl; - str << "Matrix size:" << this -> getSize() << endl; + str << "Matrix size:" << this->getSize() << endl; str << "Allocated elements:" << ellpack_nonzero_elements. getSize() << endl; str << "Matrix row length:" << row_length << endl; - for( Index i = 0; i < this -> size; i ++ ) + for( Index i = 0; i < this->size; i ++ ) { str << i << "th row data: "; for( Index j = 0; j < row_length; j ++ ) - str << setprecision( 5 ) << setw( 8 ) << ellpack_nonzero_elements[ i + j * this -> getSize() ] << " "; + str << setprecision( 5 ) << setw( 8 ) << ellpack_nonzero_elements[ i + j * this->getSize() ] << " "; str << endl << i << "th row columns: "; for( Index j = 0; j < row_length; j ++ ) - str << setprecision( 5 ) << setw( 8 ) << ellpack_columns[ i + j * this -> getSize() ] << " "; + str << setprecision( 5 ) << setw( 8 ) << ellpack_columns[ i + j * this->getSize() ] << " "; str << endl; } } diff --git a/src/legacy/matrices/tnlEllpackMatrixCUDA.h b/src/legacy/matrices/tnlEllpackMatrixCUDA.h index 07e9216076197f614558e1b696ff4a1a537f61ce..95aef4d66a8ec2f6772d169f9d9a0e39cfe4c45d 100644 --- a/src/legacy/matrices/tnlEllpackMatrixCUDA.h +++ b/src/legacy/matrices/tnlEllpackMatrixCUDA.h @@ -166,7 +166,7 @@ tnlString tnlEllpackMatrix< Real, tnlCuda, Index > :: getType() const template< typename Real, typename Index > bool tnlEllpackMatrix< Real, tnlCuda, Index > :: setSize( Index new_size ) { - this -> size = new_size; + this->size = new_size; if( ! ellpack_nonzero_elements. setSize( new_size * row_length ) ) return false; ellpack_nonzero_elements. setValue( 0.0 ); @@ -233,7 +233,7 @@ bool tnlEllpackMatrix< Real, tnlCuda, Index > :: copyFrom( const tnlEllpackMatri dbgFunctionName( "tnlEllpackMatrix< Real, tnlCuda >", "copyFrom" ); row_length = ellpack_matrix. getRowLength(); - if( ! this -> setSize( ellpack_matrix. getSize() ) ) + if( ! this->setSize( ellpack_matrix. getSize() ) ) return false; if( ! setNonzeroCOOElements( ellpack_matrix. coo_nonzero_elements. getSize() ) ) @@ -258,16 +258,16 @@ template< typename Real, typename Index > void tnlEllpackMatrix< Real, tnlCuda, Index > :: vectorProduct( const tnlVector< Real, tnlCuda, Index >& x, tnlVector< Real, tnlCuda, Index >& b ) const { - tnlAssert( x. getSize() == this -> getSize(), + tnlAssert( x. getSize() == this->getSize(), cerr << "The matrix and vector for a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << x. getSize() << endl; ); - tnlAssert( b. getSize() == this -> getSize(), + tnlAssert( b. getSize() == this->getSize(), cerr << "The matrix and result vector of a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << b. getSize() << endl; ); #ifdef HAVE_CUDA - sparseEllpackMatrixVectorProductKernelCaller( this -> getSize(), + sparseEllpackMatrixVectorProductKernelCaller( this->getSize(), row_length, ellpack_nonzero_elements. getData(), ellpack_columns. getData(), @@ -282,9 +282,9 @@ template< typename Real, typename Index > Real tnlEllpackMatrix< Real, tnlCuda, Index > :: rowProduct( Index row, const tnlVector< Real, tnlCuda, Index >& vector ) const { - tnlAssert( vector. getSize() == this -> getSize(), + tnlAssert( vector. getSize() == this->getSize(), cerr << "The matrix and vector for a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vector. getSize() << endl; ); tnlAssert( false, ); diff --git a/src/legacy/matrices/tnlFastCSRMatrix.h b/src/legacy/matrices/tnlFastCSRMatrix.h index ffd3c7dc179cfb5789b035aa598222ce719aa687..4faf3e7509da8ff43fd37a77c7a3bbb056c8b060 100644 --- a/src/legacy/matrices/tnlFastCSRMatrix.h +++ b/src/legacy/matrices/tnlFastCSRMatrix.h @@ -203,10 +203,10 @@ tnlString tnlFastCSRMatrix< Real, tnlHost, Index > :: getType() const template< typename Real, typename Index > bool tnlFastCSRMatrix< Real, tnlHost, Index > :: setSize( Index new_size ) { - this -> size = new_size; - if( ! row_offsets. setSize( this -> size + 1 ) || - ! columns_sequences_offsets. setSize( this -> size + 1 ) || - ! column_sequences_lengths. setSize( this -> size ) ) + this->size = new_size; + if( ! row_offsets. setSize( this->size + 1 ) || + ! columns_sequences_offsets. setSize( this->size + 1 ) || + ! column_sequences_lengths. setSize( this->size ) ) return false; row_offsets. setValue( 0 ); columns_sequences_offsets. setValue( 0.0 ); @@ -256,7 +256,7 @@ Index tnlFastCSRMatrix< Real, tnlHost, Index > :: getColumnSequencesLength() con template< typename Real, typename Index > Index tnlFastCSRMatrix< Real, tnlHost, Index > :: getRowLength( Index row ) const { - tnlAssert( row >= 0 && row < this -> getSize(), ); + tnlAssert( row >= 0 && row < this->getSize(), ); return row_offsets[ row + 1 ] - row_offsets[ row ]; } @@ -297,10 +297,10 @@ template< typename Real, typename Index > bool tnlFastCSRMatrix< Real, tnlHost, Index > :: copyFrom( const tnlCSRMatrix< Real, tnlHost, Index >& csr_matrix ) { dbgFunctionName( "tnlFastCSRMatrix< Real, tnlHost >", "copyFrom" ); - if( ! this -> setSize( csr_matrix. getSize() ) ) + if( ! this->setSize( csr_matrix. getSize() ) ) return false; - if( ! this -> setNonzeroElements( csr_matrix. getNonzeroElements() ) ) + if( ! this->setNonzeroElements( csr_matrix. getNonzeroElements() ) ) return false; nonzero_elements = csr_matrix. nonzero_elements; @@ -309,7 +309,7 @@ bool tnlFastCSRMatrix< Real, tnlHost, Index > :: copyFrom( const tnlCSRMatrix< R last_nonzero_element = csr_matrix. last_nonzero_element; const Index compression_depth = 1024; - for( Index row = 0; row < this -> size; row ++ ) + for( Index row = 0; row < this->size; row ++ ) { Index column_sequence_offset = csr_matrix. row_offsets[ row ]; Index column_sequence_length = csr_matrix. row_offsets[ row + 1 ] - column_sequence_offset; @@ -357,9 +357,9 @@ template< typename Real, typename Index > Real tnlFastCSRMatrix< Real, tnlHost, Index > :: getElement( Index row, Index column ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); - tnlAssert( 0 <= column && column < this -> getSize(), + tnlAssert( 0 <= column && column < this->getSize(), cerr << "The column is outside the matrix." ); Index column_offset = columns_sequences_offsets[ row ]; Index data_offset = row_offsets[ row ]; @@ -379,11 +379,11 @@ template< typename Real, typename Index > Real tnlFastCSRMatrix< Real, tnlHost, Index > :: rowProduct( Index row, const tnlVector< Real, tnlHost, Index >& vec ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); - tnlAssert( vec. getSize() == this -> getSize(), + tnlAssert( vec. getSize() == this->getSize(), cerr << "The matrix and vector for multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); Index data_offset = row_offsets[ row ]; @@ -412,19 +412,19 @@ template< typename Real, typename Index > void tnlFastCSRMatrix< Real, tnlHost, Index > :: vectorProduct( const tnlVector< Real, tnlHost, Index >& vec, tnlVector< Real, tnlHost, Index >& result ) const { - tnlAssert( vec. getSize() == this -> getSize(), + tnlAssert( vec. getSize() == this->getSize(), cerr << "The matrix and vector for a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); - tnlAssert( result. getSize() == this -> getSize(), + tnlAssert( result. getSize() == this->getSize(), cerr << "The matrix and result vector of a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << result. getSize() << endl; ); const Index* cols = column_sequences. getData(); const Real* els = nonzero_elements. getData(); - for( Index row = 0; row < this -> size; row ++ ) + for( Index row = 0; row < this->size; row ++ ) { Index data_offset = row_offsets[ row ]; Index column_offset = columns_sequences_offsets[ row ]; @@ -479,12 +479,12 @@ void tnlFastCSRMatrix< Real, tnlHost, Index > :: printOut( ostream& str, { str << "Structure of tnlFastCSRMatrix" << endl; str << "Matrix name:" << name << endl; - str << "Matrix size:" << this -> getSize() << endl; + str << "Matrix size:" << this->getSize() << endl; str << "Allocated elements:" << nonzero_elements. getSize() << endl; str << "Matrix rows:" << endl; Index print_lines = lines; if( ! print_lines ) - print_lines = this -> getSize(); + print_lines = this->getSize(); for( Index i = 0; i < print_lines; i ++ ) { diff --git a/src/legacy/matrices/tnlFastRgCSRMatrix.h b/src/legacy/matrices/tnlFastRgCSRMatrix.h index b11e0b1fb2dc659df73b27f7ae94d52d2a7c33ac..44e4b287b9b2f9a4c741990372f3ad1dd371b96a 100644 --- a/src/legacy/matrices/tnlFastRgCSRMatrix.h +++ b/src/legacy/matrices/tnlFastRgCSRMatrix.h @@ -183,13 +183,13 @@ tnlString tnlFastRgCSRMatrix< Real, tnlHost, Index > :: getType() const template< typename Real, typename Index > bool tnlFastRgCSRMatrix< Real, tnlHost, Index > :: setSize( Index new_size ) { - this -> size = new_size; - Index blocks_number = this -> size / block_size + ( this -> size % block_size != 0 ); + this->size = new_size; + Index blocks_number = this->size / block_size + ( this->size % block_size != 0 ); if( ! block_offsets. setSize( blocks_number + 1 ) || ! columns_sequences_blocks_offsets. setSize( blocks_number + 1 ) || ! column_sequences_in_block. setSize( blocks_number ) || - ! columns_sequences_offsets. setSize( this -> size + 1 ) || - ! column_sequences_lengths. setSize( this -> size ) ) + ! columns_sequences_offsets. setSize( this->size + 1 ) || + ! column_sequences_lengths. setSize( this->size ) ) return false; block_offsets. setValue( 0 ); columns_sequences_blocks_offsets. setValue( 0 ); @@ -249,10 +249,10 @@ template< typename Real, typename Index > bool tnlFastRgCSRMatrix< Real, tnlHost, Index > :: copyFrom( const tnlFastCSRMatrix< Real, tnlHost >& fast_csr_matrix ) { dbgFunctionName( "tnlFastRgCSRMatrix< Real, tnlHost >", "copyFrom" ); - if( ! this -> setSize( fast_csr_matrix. getSize() ) ) + if( ! this->setSize( fast_csr_matrix. getSize() ) ) return false; - Index blocks_number = this -> size / block_size + ( this -> size % block_size != 0 ); + Index blocks_number = this->size / block_size + ( this->size % block_size != 0 ); tnlVector< Index > col_seq_block_size( "tnlFastRgCSRMatrix< Real, tnlHost, Index > :: col_seq_block_size" ); col_seq_block_size. setSize( blocks_number ); col_seq_block_size. setValue( 0 ); @@ -269,7 +269,7 @@ bool tnlFastRgCSRMatrix< Real, tnlHost, Index > :: copyFrom( const tnlFastCSRMat * The length of the longest sequence is stored in longest_sequence_length, * and the number of sequences in one block is stored in columns_sequences_in_block */ - for( Index i = 0; i < this -> getSize(); i ++ ) + for( Index i = 0; i < this->getSize(); i ++ ) { Index block_id = i / block_size; /* @@ -277,8 +277,8 @@ bool tnlFastRgCSRMatrix< Real, tnlHost, Index > :: copyFrom( const tnlFastCSRMat * We store it in the current_block_size */ Index current_block_size = block_size; - if( ( block_id + 1 ) * block_size > this -> getSize() ) - current_block_size = this -> getSize() % block_size; + if( ( block_id + 1 ) * block_size > this->getSize() ) + current_block_size = this->getSize() % block_size; Index current_column_sequence = fast_csr_matrix. columns_sequences_offsets[ i ]; @@ -342,7 +342,7 @@ bool tnlFastRgCSRMatrix< Real, tnlHost, Index > :: copyFrom( const tnlFastCSRMat column_sequences. setValue( -1 ); Index column_sequences_end( 0 ); Index inserted_column_sequences( 0 ); - for( Index i = 0; i < this -> getSize(); i ++ ) + for( Index i = 0; i < this->getSize(); i ++ ) { dbgCout( "Processing column-sequence for the line " << i ); Index block_id = i / block_size; @@ -413,7 +413,7 @@ bool tnlFastRgCSRMatrix< Real, tnlHost, Index > :: copyFrom( const tnlFastCSRMat Index total_elements( 0 ); Index max_row_in_block( 0 ); Index blocks_inserted( -1 ); - for( Index i = 0; i < this -> getSize(); i ++ ) + for( Index i = 0; i < this->getSize(); i ++ ) { if( i % block_size == 0 ) { @@ -427,7 +427,7 @@ bool tnlFastRgCSRMatrix< Real, tnlHost, Index > :: copyFrom( const tnlFastCSRMat //dbgExpr( nonzeros_in_row[ i ] ); max_row_in_block = Max( max_row_in_block, column_sequences_lengths[ i ] ); } - total_elements += max_row_in_block * ( this -> getSize() - blocks_inserted * block_size ); + total_elements += max_row_in_block * ( this->getSize() - blocks_inserted * block_size ); block_offsets[ block_offsets. getSize() - 1 ] = total_elements; @@ -454,8 +454,8 @@ bool tnlFastRgCSRMatrix< Real, tnlHost, Index > :: copyFrom( const tnlFastCSRMat * We store it in the current_block_size */ Index current_block_size = block_size; - if( ( i + 1 ) * block_size > this -> getSize() ) - current_block_size = this -> getSize() % block_size; + if( ( i + 1 ) * block_size > this->getSize() ) + current_block_size = this->getSize() % block_size; /* * We insert 'current_block_size' rows in this matrix with the stride @@ -471,7 +471,7 @@ bool tnlFastRgCSRMatrix< Real, tnlHost, Index > :: copyFrom( const tnlFastCSRMat Index j = block_offsets[ i ] + k; // position of the first element of the row Index element_row = i * block_size + k; //dbgExpr( element_row ); - if( element_row < this -> getSize() ) + if( element_row < this->getSize() ) { /* @@ -500,9 +500,9 @@ template< typename Real, typename Index > Real tnlFastRgCSRMatrix< Real, tnlHost, Index > :: getElement( Index row, Index column ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); - tnlAssert( 0 <= column && column < this -> getSize(), + tnlAssert( 0 <= column && column < this->getSize(), cerr << "The column is outside the matrix." ); Index block_id = row / block_size; @@ -513,8 +513,8 @@ Real tnlFastRgCSRMatrix< Real, tnlHost, Index > :: getElement( Index row, * We store it in the current_block_size */ Index current_block_size = block_size; - if( ( block_id + 1 ) * block_size > this -> getSize() ) - current_block_size = this -> getSize() % block_size; + if( ( block_id + 1 ) * block_size > this->getSize() ) + current_block_size = this->getSize() % block_size; Index pos = block_offset + block_row; Index column_offset = columns_sequences_offsets[ row ]; @@ -535,11 +535,11 @@ template< typename Real, typename Index > Real tnlFastRgCSRMatrix< Real, tnlHost, Index > :: rowProduct( Index row, const tnlVector< Real, tnlHost, Index >& vec ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); - tnlAssert( vec. getSize() == this -> getSize(), + tnlAssert( vec. getSize() == this->getSize(), cerr << "The matrix and vector for multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); Index block_id = row / block_size; @@ -550,8 +550,8 @@ Real tnlFastRgCSRMatrix< Real, tnlHost, Index > :: rowProduct( Index row, * We store it in the current_block_size */ Index current_block_size = block_size; - if( ( block_id + 1 ) * block_size > this -> getSize() ) - current_block_size = this -> getSize() % block_size; + if( ( block_id + 1 ) * block_size > this->getSize() ) + current_block_size = this->getSize() % block_size; Real product( 0.0 ); Index val_pos = block_offset + block_row; Index column_pos = columns_sequences_offsets[ row ]; @@ -570,16 +570,16 @@ template< typename Real, typename Index > void tnlFastRgCSRMatrix< Real, tnlHost, Index > :: vectorProduct( const tnlVector< Real, tnlHost, Index >& vec, tnlVector< Real, tnlHost, Index >& result ) const { - tnlAssert( vec. getSize() == this -> getSize(), + tnlAssert( vec. getSize() == this->getSize(), cerr << "The matrix and vector for a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); - tnlAssert( result. getSize() == this -> getSize(), + tnlAssert( result. getSize() == this->getSize(), cerr << "The matrix and result vector of a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << result. getSize() << endl; ); - for( Index row = 0; row < this -> getSize(); row ++ ) + for( Index row = 0; row < this->getSize(); row ++ ) { Index block_id = row / block_size; Index block_row = row % block_size; @@ -589,8 +589,8 @@ void tnlFastRgCSRMatrix< Real, tnlHost, Index > :: vectorProduct( const tnlVecto * We store it in the current_block_size */ Index current_block_size = block_size; - if( ( block_id + 1 ) * block_size > this -> getSize() ) - current_block_size = this -> getSize() % block_size; + if( ( block_id + 1 ) * block_size > this->getSize() ) + current_block_size = this->getSize() % block_size; Real product( 0.0 ); Index val_pos = block_offset + block_row; Index column_pos = columns_sequences_offsets[ row ]; @@ -615,22 +615,22 @@ void tnlFastRgCSRMatrix< Real, tnlHost, Index > :: printOut( ostream& str, { str << "Structure of tnlFastRgCSRMatrix" << endl; str << "Matrix name:" << name << endl; - str << "Matrix size:" << this -> getSize() << endl; + str << "Matrix size:" << this->getSize() << endl; str << "Allocated elements:" << nonzero_elements. getSize() << endl; str << "Matrix blocks: " << block_offsets. getSize() << endl; Index print_lines = lines; if( ! print_lines ) - print_lines = this -> getSize(); + print_lines = this->getSize(); - for( Index i = 0; i < this -> block_offsets. getSize() - 1; i ++ ) + for( Index i = 0; i < this->block_offsets. getSize() - 1; i ++ ) { if( i * block_size > print_lines ) continue; str << endl << "Block number: " << i << endl; str << " Lines: " << i * block_size << " -- " << ( i + 1 ) * block_size << endl; str << " Column sequences: " << column_sequences_in_block[ i ] << endl; - for( Index k = i * block_size; k < ( i + 1 ) * block_size && k < this -> getSize(); k ++ ) + for( Index k = i * block_size; k < ( i + 1 ) * block_size && k < this->getSize(); k ++ ) { str << " Line: " << k << flush << " Line length: " << column_sequences_lengths[ k ] << flush @@ -643,8 +643,8 @@ void tnlFastRgCSRMatrix< Real, tnlHost, Index > :: printOut( ostream& str, str << endl; Index current_block_size = block_size; - if( ( i + 1 ) * block_size > this -> getSize() ) - current_block_size = this -> getSize() % block_size; + if( ( i + 1 ) * block_size > this->getSize() ) + current_block_size = this->getSize() % block_size; Index block_length = block_offsets[ i + 1 ] - block_offsets[ i ]; Index row_length = block_length / block_size; str << " Block data: " << block_offsets[ i ] << " -- " << block_offsets[ i + 1 ] << endl; diff --git a/src/legacy/matrices/tnlFastRgCSRMatrixCUDA.h b/src/legacy/matrices/tnlFastRgCSRMatrixCUDA.h index 96f89a69fd2acdbbe9c6d0b0584ded7637358b16..643531c294a7e3f3c9fb0c0e17042b0f9871bdd4 100644 --- a/src/legacy/matrices/tnlFastRgCSRMatrixCUDA.h +++ b/src/legacy/matrices/tnlFastRgCSRMatrixCUDA.h @@ -201,13 +201,13 @@ tnlString tnlFastRgCSRMatrix< Real, tnlCuda, Index > :: getType() const template< typename Real, typename Index > bool tnlFastRgCSRMatrix< Real, tnlCuda, Index > :: setSize( int new_size ) { - this -> size = new_size; - int blocks_number = this -> size / block_size + ( this -> size % block_size != 0 ); + this->size = new_size; + int blocks_number = this->size / block_size + ( this->size % block_size != 0 ); if( ! block_offsets. setSize( blocks_number + 1 ) || - ! columns_sequences_offsets. setSize( this -> size + 1 ) || + ! columns_sequences_offsets. setSize( this->size + 1 ) || ! column_sequences_in_block. setSize( blocks_number ) || ! columns_sequences_blocks_offsets. setSize( blocks_number + 1 ) || - ! column_sequences_lengths. setSize( this -> size ) ) + ! column_sequences_lengths. setSize( this->size ) ) return false; block_offsets. setValue( 0 ); columns_sequences_blocks_offsets. setValue( 0 ); @@ -275,7 +275,7 @@ bool tnlFastRgCSRMatrix< Real, tnlCuda, Index > :: copyFrom( const tnlFastRgCSRM } block_size = coa_fast_csr_matrix. block_size; - if( ! this -> setSize( coa_fast_csr_matrix. getSize() ) || + if( ! this->setSize( coa_fast_csr_matrix. getSize() ) || ! nonzero_elements. setSize( coa_fast_csr_matrix. nonzero_elements. getSize() ) || ! column_sequences. setSize( coa_fast_csr_matrix. column_sequences. getSize() ) ) return false; @@ -304,9 +304,9 @@ template< typename Real, typename Index > Real tnlFastRgCSRMatrix< Real, tnlCuda, Index > :: getElement( int row, int column ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); - tnlAssert( 0 <= column && column < this -> getSize(), + tnlAssert( 0 <= column && column < this->getSize(), cerr << "The column is outside the matrix." ); tnlAssert( false, cerr << "Not Implemeted Yet!" ); return 0; @@ -316,7 +316,7 @@ template< typename Real, typename Index > Real tnlFastRgCSRMatrix< Real, tnlCuda, Index > :: rowProduct( int row, const tnlVector< Real, tnlCuda, Index >& vec ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); tnlAssert( vec != NULL, ); tnlAssert( false, cerr << "Not Implemented Yet!" ); @@ -330,7 +330,7 @@ void tnlFastRgCSRMatrix< Real, tnlCuda, Index > :: vectorProduct( const tnlVecto tnlAssert( vec != NULL && result != NULL,); #ifdef HAVE_CUDA - /*sparseFastCSRMatrixVectorProductKernel( this -> getSize(), + /*sparseFastCSRMatrixVectorProductKernel( this->getSize(), block_size, columns_sequences_blocks_offsets. getData(), columns_sequences_offsets. getData(), @@ -355,22 +355,22 @@ void tnlFastRgCSRMatrix< Real, tnlCuda, Index > :: printOut( ostream& str, { str << "Structure of tnlFastRgCSRMatrix" << endl; str << "Matrix name:" << name << endl; - str << "Matrix size:" << this -> getSize() << endl; + str << "Matrix size:" << this->getSize() << endl; str << "Allocated elements:" << nonzero_elements. getSize() << endl; str << "Matrix blocks: " << block_offsets. getSize() << endl; int print_lines = lines; if( ! print_lines ) - print_lines = this -> getSize(); + print_lines = this->getSize(); - for( int i = 0; i < this -> block_offsets. getSize() - 1; i ++ ) + for( int i = 0; i < this->block_offsets. getSize() - 1; i ++ ) { if( i * block_size > print_lines ) continue; str << endl << "Block number: " << i << endl; str << " Lines: " << i * block_size << " -- " << ( i + 1 ) * block_size << endl; str << " Column sequences: " << column_sequences_in_block. getElement( i ) << endl; - for( int k = i * block_size; k < ( i + 1 ) * block_size && k < this -> getSize(); k ++ ) + for( int k = i * block_size; k < ( i + 1 ) * block_size && k < this->getSize(); k ++ ) { str << " Line: " << k << flush << " Line length: " << column_sequences_lengths. getElement( k ) << flush @@ -383,8 +383,8 @@ void tnlFastRgCSRMatrix< Real, tnlCuda, Index > :: printOut( ostream& str, str << endl; int current_block_size = block_size; - if( ( i + 1 ) * block_size > this -> getSize() ) - current_block_size = this -> getSize() % block_size; + if( ( i + 1 ) * block_size > this->getSize() ) + current_block_size = this->getSize() % block_size; int block_length = block_offsets. getElement( i + 1 ) - block_offsets. getElement( i ); int row_length = block_length / block_size; str << " Block data: " << block_offsets. getElement( i ) << " -- " << block_offsets. getElement( i + 1 ) << endl; diff --git a/src/legacy/matrices/tnlFullMatrix.h b/src/legacy/matrices/tnlFullMatrix.h index a9a230314b4d445c6bf3759a47af79c140561d1e..1c81fd60eb15a216a46504e389e8b871a96b9d2f 100644 --- a/src/legacy/matrices/tnlFullMatrix.h +++ b/src/legacy/matrices/tnlFullMatrix.h @@ -184,11 +184,11 @@ template< typename Real, typename Device, typename Index > Real tnlFullMatrix< Real, Device, Index > :: rowProduct( const Index row, const tnlVector< Real, Device, Index >& vec ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); - tnlAssert( vec. getSize() == this -> getSize(), + tnlAssert( vec. getSize() == this->getSize(), cerr << "The matrix and vector for multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); const Index size = getSize(); @@ -215,13 +215,13 @@ template< typename Real, typename Device, typename Index > void tnlFullMatrix< Real, Device, Index > :: vectorProduct( const tnlVector< Real, Device, Index >& vec, tnlVector< Real, Device, Index >& result ) const { - tnlAssert( vec. getSize() == this -> getSize(), + tnlAssert( vec. getSize() == this->getSize(), cerr << "The matrix and vector for a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); - tnlAssert( result. getSize() == this -> getSize(), + tnlAssert( result. getSize() == this->getSize(), cerr << "The matrix and result vector of a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << result. getSize() << endl; ); const Index size = getSize(); diff --git a/src/legacy/matrices/tnlMatrix.h b/src/legacy/matrices/tnlMatrix.h index db31c122a3103ee73942da5040a99e6ad91bbec9..f3c2afdc563f4e792b42caa2483a43fd80c9b5c6 100644 --- a/src/legacy/matrices/tnlMatrix.h +++ b/src/legacy/matrices/tnlMatrix.h @@ -214,15 +214,15 @@ bool tnlMatrix< Real, Device, Index > :: operator == ( const tnlMatrix< Real, De template< typename Real, typename Device, typename Index > bool tnlMatrix< Real, Device, Index > :: compare( const tnlMatrix< Real, Device, Index >& m, bool verbose ) const { - if( this -> getSize() != m. getSize() ) + if( this->getSize() != m. getSize() ) return false; - const Index size = this -> getSize(); + const Index size = this->getSize(); for( Index i = 0; i < size; i ++ ) for( Index j = 0; j < size; j ++ ) { if( verbose ) cout << "Comparing: " << i << " / " << size << "\r"; - if( this -> getElement( i, j ) != m. getElement( i, j ) ) + if( this->getElement( i, j ) != m. getElement( i, j ) ) return false; } return true; @@ -276,7 +276,7 @@ template< typename Real, typename Device, typename Index > template< typename Real2 > tnlMatrix< Real, Device, Index >& tnlMatrix< Real, Device, Index > :: operator = ( const tnlMatrix< Real2, Device, Index >& matrix ) { - this -> size = matrix. getSize(); + this->size = matrix. getSize(); /*if( ! rowsReorderingPermutation. setSize( matrix. rowsReorderingPermutation. getSize() ) ) { cerr << "I am not able to allocat the row permutation vector for the new matrix." << endl; @@ -383,8 +383,8 @@ bool tnlMatrix< Real, Device, Index > :: read( istream& file, cerr << "There is not square matrix in the file." << endl; return false; } - if( ! this -> setSize( M ) || - ! this -> setNonzeroElements( L ) ) + if( ! this->setSize( M ) || + ! this->setNonzeroElements( L ) ) { cerr << "Not enough memory to allocate the sparse or the full matrix for testing." << endl; return false; @@ -407,9 +407,9 @@ bool tnlMatrix< Real, Device, Index > :: read( istream& file, parsed_elements ++; if( verbose ) cout << "Parsed elements: " << setw( 9 ) << right << parsed_elements << "\r" << flush; - this -> setElement( I - 1, J - 1, A ); + this->setElement( I - 1, J - 1, A ); if( symmetric && I != J ) - this -> setElement( J - 1, I - 1, A ); + this->setElement( J - 1, I - 1, A ); } return true; } @@ -431,10 +431,10 @@ bool tnlMatrix< Real, Device, Index > :: sortRowsDecreasingly( tnlVector< Index, */ for( Index i = 0; i < matrixSize; i ++ ) { - tnlAssert( this -> getNonzeroElementsInRow( i ) <= matrixSize, + tnlAssert( this->getNonzeroElementsInRow( i ) <= matrixSize, cerr << "getNonzeroElementsInRow( " << i << " ) = " << getNonzeroElementsInRow( i ) << "; matrixSize = " << matrixSize ); - permutation[ this -> getNonzeroElementsInRow( i ) ] ++; + permutation[ this->getNonzeroElementsInRow( i ) ] ++; } tnlVector< Index, tnlHost, Index > buckets( "tnlMatrix::reorderRowsDecreasingly:buckets" ); @@ -450,11 +450,11 @@ bool tnlMatrix< Real, Device, Index > :: sortRowsDecreasingly( tnlVector< Index, for( Index i = 0; i < matrixSize; i ++ ) { - tnlAssert( buckets[ matrixSize - this -> getNonzeroElementsInRow( i ) ] <= matrixSize, - cerr << "buckets[ matrixSize - this -> getNonzeroElementsInRow( i ) - 1 ] = " << buckets[ matrixSize - this -> getNonzeroElementsInRow( i ) - 1 ] + tnlAssert( buckets[ matrixSize - this->getNonzeroElementsInRow( i ) ] <= matrixSize, + cerr << "buckets[ matrixSize - this->getNonzeroElementsInRow( i ) - 1 ] = " << buckets[ matrixSize - this->getNonzeroElementsInRow( i ) - 1 ] << "; matrixSize = " << matrixSize ); - dbgExpr( buckets[ matrixSize - this -> getNonzeroElementsInRow( i ) ] ); - permutation[ buckets[ matrixSize - this -> getNonzeroElementsInRow( i ) ] ++ ] = i; + dbgExpr( buckets[ matrixSize - this->getNonzeroElementsInRow( i ) ] ); + permutation[ buckets[ matrixSize - this->getNonzeroElementsInRow( i ) ] ++ ] = i; } return true; } @@ -485,11 +485,11 @@ bool tnlMatrix< Real, Device, Index > :: draw( ostream& str, if( format == "eps" ) { const int elementSize = 10; - this -> writePostscriptHeader( str, elementSize ); + this->writePostscriptHeader( str, elementSize ); if( csrMatrix ) csrMatrix -> writePostscriptBody( str, elementSize, verbose ); else - this -> writePostscriptBody( str, elementSize, verbose ); + this->writePostscriptBody( str, elementSize, verbose ); str << "showpage" << endl; str << "%%EOF" << endl; @@ -506,7 +506,7 @@ template< typename Real, typename Device, typename Index > void tnlMatrix< Real, Device, Index > :: writePostscriptHeader( ostream& str, const int elementSize ) const { - const int scale = elementSize * this -> getSize(); + const int scale = elementSize * this->getSize(); str << "%!PS-Adobe-2.0 EPSF-2.0" << endl; str << "%%BoundingBox: 0 0 " << scale << " " << scale << endl; str << "%%Creator: TNL" << endl; @@ -520,8 +520,8 @@ void tnlMatrix< Real, Device, Index > :: writePostscriptBody( ostream& str, const int elementSize, bool verbose ) const { - const double scale = elementSize * this -> getSize(); - double hx = scale / ( double ) this -> getSize(); + const double scale = elementSize * this->getSize(); + double hx = scale / ( double ) this->getSize(); Index lastRow( 0 ), lastColumn( 0 ); for( Index row = 0; row < getSize(); row ++ ) { diff --git a/src/legacy/matrices/tnlRgCSRMatrix.h b/src/legacy/matrices/tnlRgCSRMatrix.h index f6d3f98bcdebd7e59908687ec757dff026d19e79..c7d5faeeb8642a7f45013309ad179e482790f0d3 100644 --- a/src/legacy/matrices/tnlRgCSRMatrix.h +++ b/src/legacy/matrices/tnlRgCSRMatrix.h @@ -242,7 +242,7 @@ tnlRgCSRMatrix< Real, Device, Index > :: tnlRgCSRMatrix( const tnlString& name ) cudaGetDevice( &cudaDevice ); cudaDeviceProp deviceProperties; cudaGetDeviceProperties( &deviceProperties, cudaDevice ); - //this -> maxCudaGridSize = deviceProperties. maxGridSize[ 0 ]; + //this->maxCudaGridSize = deviceProperties. maxGridSize[ 0 ]; #endif }; @@ -274,17 +274,17 @@ Index tnlRgCSRMatrix< Real, Device, Index > :: getCUDABlockSize() const template< typename Real, typename Device, typename Index > void tnlRgCSRMatrix< Real, Device, Index > :: setCUDABlockSize( Index blockSize ) { - tnlAssert( blockSize % this -> groupSize == 0, ) + tnlAssert( blockSize % this->groupSize == 0, ) cudaBlockSize = blockSize; } template< typename Real, typename Device, typename Index > bool tnlRgCSRMatrix< Real, Device, Index > :: setSize( Index new_size ) { - this -> size = new_size; - if( ! groupOffsets. setSize( this -> getSize() / groupSize + ( this -> getSize() % groupSize != 0 ) + 1 ) || - ! nonzeroElementsInRow. setSize( this -> getSize() ) || - ! adaptiveGroupSizes. setSize( this -> getSize() + 1 ) ) + this->size = new_size; + if( ! groupOffsets. setSize( this->getSize() / groupSize + ( this->getSize() % groupSize != 0 ) + 1 ) || + ! nonzeroElementsInRow. setSize( this->getSize() ) || + ! adaptiveGroupSizes. setSize( this->getSize() + 1 ) ) return false; groupOffsets. setValue( 0 ); nonzeroElementsInRow. setValue( 0 ); @@ -307,7 +307,7 @@ bool tnlRgCSRMatrix< Real, Device, Index > :: setNonzeroElements( Index elements template< typename Real, typename Device, typename Index > void tnlRgCSRMatrix< Real, Device, Index > :: reset() { - this -> size = 0; + this->size = 0; nonzeroElements. reset(); columns. reset(); groupOffsets. reset(); @@ -336,10 +336,10 @@ void tnlRgCSRMatrix< Real, Device, Index > :: tuneFormat( const Index groupSize, const bool useAdaptiveGroupSize, const tnlAdaptiveGroupSizeStrategy adaptiveGroupSizeStrategy ) { - tnlAssert( this -> groupSize > 0, ); - this -> groupSize = groupSize; - this -> useAdaptiveGroupSize = useAdaptiveGroupSize; - this -> adaptiveGroupSizeStrategy = adaptiveGroupSizeStrategy; + tnlAssert( this->groupSize > 0, ); + this->groupSize = groupSize; + this->useAdaptiveGroupSize = useAdaptiveGroupSize; + this->adaptiveGroupSizeStrategy = adaptiveGroupSizeStrategy; } @@ -356,7 +356,7 @@ bool tnlRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatrix< Real return false; } - if( ! this -> setSize( csr_matrix. getRows() ) ) + if( ! this->setSize( csr_matrix. getRows() ) ) return false; dbgExpr( csr_matrix. getSize() ); @@ -364,14 +364,14 @@ bool tnlRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatrix< Real * In case of adaptive group sizes compute maximum number of the non-zero elements in group. */ Index maxNonzeroElementsInGroup( 0 ); - if( this -> useAdaptiveGroupSize ) + if( this->useAdaptiveGroupSize ) { - if( this -> adaptiveGroupSizeStrategy == tnlAdaptiveGroupSizeStrategyByAverageRowSize ) + if( this->adaptiveGroupSizeStrategy == tnlAdaptiveGroupSizeStrategyByAverageRowSize ) { const Index averageRowSize = ceil( ( double ) csr_matrix. getNumberOfAllocatedElements() / ( double ) csr_matrix. getRows() ); maxNonzeroElementsInGroup = averageRowSize * groupSize; } - //if( this -> adaptiveGroupSizeStrategy == tnlAdaptiveGroupSizeStrategyByFirstGroup ) + //if( this->adaptiveGroupSizeStrategy == tnlAdaptiveGroupSizeStrategyByFirstGroup ) // for( Index row = 0; row < groupSize; row ++ ) // maxNonzeroElementsInGroup += csr_matrix. getNonzeroElementsInRow( row ); } @@ -387,16 +387,16 @@ bool tnlRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatrix< Real Index processedLines( 0 ); numberOfGroups = 0; groupOffsets[ 0 ] = 0; - for( Index i = 0; i < this -> getSize(); i ++ ) + for( Index i = 0; i < this->getSize(); i ++ ) { if( i > 0 && i % groupSize == 0 ) { currentGroupSize += groupSize; - if( ! this -> useAdaptiveGroupSize || + if( ! this->useAdaptiveGroupSize || ( nonzeroElementsInGroup > maxNonzeroElementsInGroup && cudaBlockSize % currentGroupSize == 0 ) || currentGroupSize == cudaBlockSize ) { - if( this -> useAdaptiveGroupSize ) + if( this->useAdaptiveGroupSize ) adaptiveGroupSizes[ numberOfGroups + 1 ] = currentGroupSize; dbgCout( numberOfGroups << "-th group size is " << currentGroupSize ); @@ -419,7 +419,7 @@ bool tnlRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatrix< Real } dbgExpr( processedLines ); - currentGroupSize = this -> getSize() - processedLines; + currentGroupSize = this->getSize() - processedLines; total_elements += max_row_in_block * ( currentGroupSize ); groupOffsets[ numberOfGroups + 1 ] = total_elements; if( useAdaptiveGroupSize ) @@ -432,7 +432,7 @@ bool tnlRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatrix< Real for( Index i = 1; i < adaptiveGroupSizes. getSize(); i ++ ) adaptiveGroupSizes[ i ] += adaptiveGroupSizes[ i - 1 ]; dbgExpr( adaptiveGroupSizes ); - dbgExpr( this -> getSize() ); + dbgExpr( this->getSize() ); } dbgCout( numberOfGroups << "-th group size is " << currentGroupSize ); numberOfGroups ++; @@ -477,7 +477,7 @@ bool tnlRgCSRMatrix< Real, Device, Index > :: copyFrom( const tnlCSRMatrix< Real /**** * Get the element position */ - tnlAssert( elementRow < this -> getSize(), cerr << "Element row = " << elementRow ); + tnlAssert( elementRow < this->getSize(), cerr << "Element row = " << elementRow ); Index elementPos = csr_matrix. row_offsets[ elementRow ]; while( elementPos < csr_matrix. row_offsets[ elementRow + 1 ] ) { @@ -505,9 +505,9 @@ copyFrom( const tnlRgCSRMatrix< Real, Device2, Index >& rgCSRMatrix ) dbgFunctionName( "tnlRgCSRMatrix< Real, Device, Index >", "copyFrom" ); tnlAssert( rgCSRMatrix. getSize() > 0, cerr << "Copying from matrix with non-positiove size." ); - this -> cudaBlockSize = rgCSRMatrix. cudaBlockSize; - this -> groupSize = rgCSRMatrix. groupSize; - if( ! this -> setSize( rgCSRMatrix. getSize() ) ) + this->cudaBlockSize = rgCSRMatrix. cudaBlockSize; + this->groupSize = rgCSRMatrix. groupSize; + if( ! this->setSize( rgCSRMatrix. getSize() ) ) return false; /**** @@ -518,19 +518,19 @@ copyFrom( const tnlRgCSRMatrix< Real, Device2, Index >& rgCSRMatrix ) dbgCout( "Allocating " << total_elements << " elements."); if( ! setNonzeroElements( total_elements ) ) return false; - this -> artificial_zeros = total_elements - rgCSRMatrix. getNonzeroElements(); - - this -> nonzeroElements = rgCSRMatrix. nonzeroElements; - this -> columns = rgCSRMatrix. columns; - this -> groupOffsets = rgCSRMatrix. groupOffsets; - this -> nonzeroElementsInRow = rgCSRMatrix. nonzeroElementsInRow; - this -> last_nonzero_element = rgCSRMatrix. last_nonzero_element; - - this -> numberOfGroups = rgCSRMatrix. numberOfGroups; - this -> adaptiveGroupSizes = rgCSRMatrix. adaptiveGroupSizes; - this -> useAdaptiveGroupSize = rgCSRMatrix. useAdaptiveGroupSize; - this -> adaptiveGroupSizeStrategy = rgCSRMatrix. adaptiveGroupSizeStrategy; - //this -> maxCudaGridSize = rgCSRMatrix. maxCudaGridSize; + this->artificial_zeros = total_elements - rgCSRMatrix. getNonzeroElements(); + + this->nonzeroElements = rgCSRMatrix. nonzeroElements; + this->columns = rgCSRMatrix. columns; + this->groupOffsets = rgCSRMatrix. groupOffsets; + this->nonzeroElementsInRow = rgCSRMatrix. nonzeroElementsInRow; + this->last_nonzero_element = rgCSRMatrix. last_nonzero_element; + + this->numberOfGroups = rgCSRMatrix. numberOfGroups; + this->adaptiveGroupSizes = rgCSRMatrix. adaptiveGroupSizes; + this->useAdaptiveGroupSize = rgCSRMatrix. useAdaptiveGroupSize; + this->adaptiveGroupSizeStrategy = rgCSRMatrix. adaptiveGroupSizeStrategy; + //this->maxCudaGridSize = rgCSRMatrix. maxCudaGridSize; return true; }; @@ -540,7 +540,7 @@ Real tnlRgCSRMatrix< Real, Device, Index > :: getElement( Index row, Index column ) const { dbgFunctionName( "tnlRgCSRMatrix< Real, Device, Index >", "getElement" ); - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); if( Device :: getDevice() == tnlHostDevice ) { @@ -577,11 +577,11 @@ template< typename Real, typename Device, typename Index > Real tnlRgCSRMatrix< Real, Device, Index > :: rowProduct( Index row, const tnlVector< Real, Device, Index >& vec ) const { - tnlAssert( 0 <= row && row < this -> getSize(), + tnlAssert( 0 <= row && row < this->getSize(), cerr << "The row is outside the matrix." ); - tnlAssert( vec. getSize() == this -> getSize(), + tnlAssert( vec. getSize() == this->getSize(), cerr << "The matrix and vector for multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); if( Device :: getDevice() == tnlHostDevice ) @@ -618,13 +618,13 @@ void tnlRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVector< Re tnlVector< Real, Device, Index >& result ) const { dbgFunctionName( "tnlRgCSRMatrix< Real, tnlHost >", "vectorProduct" ) - tnlAssert( vec. getSize() == this -> getSize(), + tnlAssert( vec. getSize() == this->getSize(), cerr << "The matrix and vector for a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); - tnlAssert( result. getSize() == this -> getSize(), + tnlAssert( result. getSize() == this->getSize(), cerr << "The matrix and result vector of a multiplication have different sizes. " - << "The matrix size is " << this -> getSize() << "." + << "The matrix size is " << this->getSize() << "." << "The vector size is " << vec. getSize() << endl; ); if( Device :: getDevice() == tnlHostDevice ) @@ -633,8 +633,8 @@ void tnlRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVector< Re /**** * This is exact emulation of the CUDA kernel */ - Index blockSize = 256; //this -> getCUDABlockSize(); - const Index size = this -> getSize(); + Index blockSize = 256; //this->getCUDABlockSize(); + const Index size = this->getSize(); Index gridSize = size / blockSize + ( size % blockSize != 0 ) + 1; for( Index blockIdx = 0; blockIdx < gridSize; blockIdx ++ ) for( Index threadIdx = 0; threadIdx < blockSize; threadIdx ++ ) @@ -643,10 +643,10 @@ void tnlRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVector< Re if( rowIndex >= size ) continue; - const Index groupIndex = floor( threadIdx / this -> groupSize ); - const Index globalGroupIndex = this -> getGroupIndexFromRow( rowIndex ); - const Index rowOffsetInGroup = this -> getRowIndexInGroup( rowIndex, globalGroupIndex ); - const Index currentGroupSize = this -> getCurrentGroupSize( globalGroupIndex ); + const Index groupIndex = floor( threadIdx / this->groupSize ); + const Index globalGroupIndex = this->getGroupIndexFromRow( rowIndex ); + const Index rowOffsetInGroup = this->getRowIndexInGroup( rowIndex, globalGroupIndex ); + const Index currentGroupSize = this->getCurrentGroupSize( globalGroupIndex ); tnlAssert( rowOffsetInGroup < currentGroupSize, cerr << "rowOffsetInGroup = " << rowOffsetInGroup << ", currentGroupSize = " << currentGroupSize ); Real product( 0.0 ); @@ -733,12 +733,12 @@ void tnlRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVector< Re if( Device :: getDevice() == tnlCudaDevice ) { #ifdef HAVE_CUDA - Index blockSize = this -> getCUDABlockSize(); - const Index size = this -> getSize(); + Index blockSize = this->getCUDABlockSize(); + const Index size = this->getSize(); - if( this -> useAdaptiveGroupSize ) + if( this->useAdaptiveGroupSize ) { - int gridSize = this -> numberOfGroups; + int gridSize = this->numberOfGroups; int numberOfGrids = gridSize / maxCudaGridSize + ( gridSize % maxCudaGridSize != 0 ); int gridNumber( 0 ); while( gridSize > 0 ) @@ -750,7 +750,7 @@ void tnlRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVector< Re /*tnlRgCSRMatrixAdpativeGroupSizeVectorProductKernel< Real, Index > <<< gridDim, blockDim, sharedBytes >>> ( gridNumber, - this -> maxCudaGridSize, + this->maxCudaGridSize, size, adaptiveGroupSizes. getData(), nonzeroElements. getData(), @@ -769,14 +769,14 @@ void tnlRgCSRMatrix< Real, Device, Index > :: vectorProduct( const tnlVector< Re int gridNumber( 0 ); while( gridSize > 0 ) { - /*int currentGridSize = Min( gridSize, this -> maxCudaGridSize ); + /*int currentGridSize = Min( gridSize, this->maxCudaGridSize ); dim3 gridDim( currentGridSize ), blockDim( blockSize ); tnlRgCSRMatrixVectorProductKernel< Real, Index > <<< gridDim, blockDim >>> ( gridNumber, - this -> maxCudaGridSize, + this->maxCudaGridSize, size, - this -> groupSize, + this->groupSize, nonzeroElements. getData(), columns. getData(), groupOffsets. getData(), @@ -807,22 +807,22 @@ void tnlRgCSRMatrix< Real, Device, Index > :: printOut( ostream& str, { str << "Structure of tnlRgCSRMatrix" << endl; str << "Matrix name:" << name << endl; - str << "Matrix size:" << this -> getSize() << endl; + str << "Matrix size:" << this->getSize() << endl; str << "Allocated elements:" << nonzeroElements. getSize() << endl; str << "Number of groups: " << groupOffsets. getSize() << endl; Index print_lines = lines; if( ! print_lines ) - print_lines = this -> getSize(); + print_lines = this->getSize(); - for( Index i = 0; i < this -> numberOfGroups; i ++ ) + for( Index i = 0; i < this->numberOfGroups; i ++ ) { if( i * groupSize > print_lines ) return; str << endl << "Block number: " << i << endl; - str << " Group size: " << this -> getCurrentGroupSize( i ) << endl; + str << " Group size: " << this->getCurrentGroupSize( i ) << endl; str << " Group non-zeros: "; - for( Index k = i * groupSize; k < ( i + 1 ) * groupSize && k < this -> getSize(); k ++ ) + for( Index k = i * groupSize; k < ( i + 1 ) * groupSize && k < this->getSize(); k ++ ) str << nonzeroElementsInRow. getElement( k ) << " "; str << endl; str << " Group data: " @@ -855,22 +855,22 @@ void tnlRgCSRMatrix< Real, Device, Index > :: printOut( ostream& str, { str << "<h1>Structure of tnlRgCSRMatrix</h1>" << endl; str << "<b>Matrix name:</b> " << name << "<p>" << endl; - str << "<b>Matrix size:</b> " << this -> getSize() << "<p>" << endl; + str << "<b>Matrix size:</b> " << this->getSize() << "<p>" << endl; str << "<b>Allocated elements:</b> " << nonzeroElements. getSize() << "<p>" << endl; - str << "<b>Number of groups:</b> " << this -> numberOfGroups << "<p>" << endl; + str << "<b>Number of groups:</b> " << this->numberOfGroups << "<p>" << endl; str << "<table border=1>" << endl; str << "<tr> <td> <b> GroupId </b> </td> <td> <b> Size </b> </td> <td> <b> % of nonzeros </b> </td> </tr>" << endl; Index print_lines = lines; if( ! print_lines ) - print_lines = this -> getSize(); + print_lines = this->getSize(); - for( Index i = 0; i < this -> numberOfGroups; i ++ ) + for( Index i = 0; i < this->numberOfGroups; i ++ ) { if( i * groupSize > print_lines ) return; - double filling = ( double ) ( this -> groupOffsets. getElement( i + 1 ) - this -> groupOffsets. getElement( i ) ) / - ( double ) this -> nonzeroElements. getSize(); - str << "<tr> <td> " << i << "</td> <td>" << this -> getCurrentGroupSize( i ) << " </td> <td> " << 100.0 * filling << "% </td></tr>" << endl; + double filling = ( double ) ( this->groupOffsets. getElement( i + 1 ) - this->groupOffsets. getElement( i ) ) / + ( double ) this->nonzeroElements. getSize(); + str << "<tr> <td> " << i << "</td> <td>" << this->getCurrentGroupSize( i ) << " </td> <td> " << 100.0 * filling << "% </td></tr>" << endl; } str << "</table>" << endl; str << endl; @@ -893,7 +893,7 @@ bool tnlRgCSRMatrix< Real, Device, Index > :: draw( ostream& str, if( format == "eps" ) { const int elementSize = 10; - this -> writePostscriptHeader( str, elementSize ); + this->writePostscriptHeader( str, elementSize ); /**** * Draw the groups @@ -906,19 +906,19 @@ bool tnlRgCSRMatrix< Real, Device, Index > :: draw( ostream& str, else str << "0.8 0.8 0.8 setrgbcolor" << endl; str << "0 -" << groupSize * elementSize - << " translate newpath 0 0 " << this -> getSize() * elementSize + << " translate newpath 0 0 " << this->getSize() * elementSize << " " << groupSize * elementSize << " rectfill" << endl; } /**** * Restore black color and the origin of the coordinates */ str << "0 0 0 setrgbcolor" << endl; - str << "0 " << this -> getSize() * elementSize << " translate" << endl; + str << "0 " << this->getSize() * elementSize << " translate" << endl; if( csrMatrix ) csrMatrix -> writePostscriptBody( str, elementSize, verbose ); else - this -> writePostscriptBody( str, elementSize, verbose ); + this->writePostscriptBody( str, elementSize, verbose ); str << "showpage" << endl; str << "%%EOF" << endl; @@ -937,28 +937,28 @@ Index tnlRgCSRMatrix< Real, Device, Index > :: getCurrentGroupSize( const Index /**** * If we use adaptive group sizes they are stored explicitly. */ - if( this -> useAdaptiveGroupSize ) - return this -> adaptiveGroupSizes. getElement( groupId + 1 ) - - this -> adaptiveGroupSizes. getElement( groupId ); + if( this->useAdaptiveGroupSize ) + return this->adaptiveGroupSizes. getElement( groupId + 1 ) - + this->adaptiveGroupSizes. getElement( groupId ); /**** * The last group may be smaller even if we have constant group size. */ - if( ( groupId + 1 ) * this -> groupSize > this -> getSize() ) - return this -> getSize() % this -> groupSize; + if( ( groupId + 1 ) * this->groupSize > this->getSize() ) + return this->getSize() % this->groupSize; /*** * If it is not the last group, return the common group size. */ - return this -> groupSize; + return this->groupSize; } template< typename Real, typename Device, typename Index > Index tnlRgCSRMatrix< Real, Device, Index > :: getGroupIndexFromRow( const Index row ) const { - tnlAssert( row < this -> getSize(), cerr << " row = " << row << " matrix size = " << this -> getSize() ); - if( this -> useAdaptiveGroupSize ) + tnlAssert( row < this->getSize(), cerr << " row = " << row << " matrix size = " << this->getSize() ); + if( this->useAdaptiveGroupSize ) { Index groupId = -1; - while( this -> adaptiveGroupSizes. getElement( groupId + 1 ) <= row ) + while( this->adaptiveGroupSizes. getElement( groupId + 1 ) <= row ) groupId ++; return groupId; } @@ -968,9 +968,9 @@ Index tnlRgCSRMatrix< Real, Device, Index > :: getGroupIndexFromRow( const Index template< typename Real, typename Device, typename Index > Index tnlRgCSRMatrix< Real, Device, Index > :: getRowIndexInGroup( const Index row, const Index groupId ) const { - tnlAssert( row < this -> getSize(), cerr << " row = " << row << " matrix size = " << this -> getSize() ); + tnlAssert( row < this->getSize(), cerr << " row = " << row << " matrix size = " << this->getSize() ); tnlAssert( groupId < numberOfGroups, cerr << " groupId = " << groupId << " numberOfGroups = " << numberOfGroups ); - if( this -> useAdaptiveGroupSize ) + if( this->useAdaptiveGroupSize ) return row - adaptiveGroupSizes. getElement( groupId ); return row % groupSize; diff --git a/src/legacy/solvers/tnlGMRESSolverOld.h b/src/legacy/solvers/tnlGMRESSolverOld.h index 41a8ec4bca5b34d798342d6352789fb1e17757a4..98d8dae911497480603596410591a9738d22763e 100644 --- a/src/legacy/solvers/tnlGMRESSolverOld.h +++ b/src/legacy/solvers/tnlGMRESSolverOld.h @@ -170,13 +170,13 @@ bool tnlGMRESSolverOld< Real, Device, Index > :: solve( const tnlMatrix< Real, D if( normb == 0.0 ) normb = 1.0; - this -> iteration = 0; - this -> residue = beta / normb; + this->iteration = 0; + this->residue = beta / normb; tnlSharedVector< Real, Device, Index > vi; tnlSharedVector< Real, Device, Index > vk; - while( this -> iteration < max_iterations && - this -> residue > max_residue ) + while( this->iteration < max_iterations && + this->residue > max_residue ) { const Index m = restarting; for( i = 0; i < m + 1; i ++ ) @@ -199,7 +199,7 @@ bool tnlGMRESSolverOld< Real, Device, Index > :: solve( const tnlMatrix< Real, D //dbgCout( " ----------- Starting m-loop -----------------" ); - for( i = 0; i < m && this -> iteration <= max_iterations; i++ ) + for( i = 0; i < m && this->iteration <= max_iterations; i++ ) { vi. bind( &( _v. getData()[ i * size ] ), size ); /**** @@ -260,20 +260,20 @@ bool tnlGMRESSolverOld< Real, Device, Index > :: solve( const tnlMatrix< Real, D cs[ i ], sn[ i ] ); - this -> residue = fabs( s[ i + 1 ] ) / normb; + this->residue = fabs( s[ i + 1 ] ) / normb; - if( this -> iteration % 10 == 0 && - this -> verbosity > 1 ) - this -> printOut(); - if( this -> residue < max_residue ) + if( this->iteration % 10 == 0 && + this->verbosity > 1 ) + this->printOut(); + if( this->residue < max_residue ) { update( i, m, _H, _s, _v, x ); - if( this -> verbosity > 0 ) - this -> printOut(); + if( this->verbosity > 0 ) + this->printOut(); return true; } //DBG_WAIT; - this -> iteration ++; + this->iteration ++; } update( m - 1, m, _H, _s, _v, x ); //dbgCout_ARRAY( x, size ); @@ -299,12 +299,12 @@ bool tnlGMRESSolverOld< Real, Device, Index > :: solve( const tnlMatrix< Real, D //dbgCout_ARRAY( r, size ); //dbgExpr( beta ); //dbgExpr( beta / normb ); - this -> residue = beta / normb; - this -> iteration ++; + this->residue = beta / normb; + this->iteration ++; } - if( this -> verbosity > 0 ) - this -> printOut(); - if( this -> iteration == max_iterations ) return false; + if( this->verbosity > 0 ) + this->printOut(); + if( this->iteration == max_iterations ) return false; return true; }; @@ -342,7 +342,7 @@ void tnlGMRESSolverOld< Real, Device, Index > :: update( Index k, tnlSharedVector< Real, Device, Index > vi; for( i = 0; i <= k; i++) { - vi. bind( &( v. getData()[ i * this -> size ] ), x. getSize() ); + vi. bind( &( v. getData()[ i * this->size ] ), x. getSize() ); x. alphaXPlusY( y[ i ], vi ); } }; diff --git a/src/legacy/solvers/tnlMatrixSolver.h b/src/legacy/solvers/tnlMatrixSolver.h index f5351963d3cfdec6be6ef77aa18fe467f324b178..21077d1432951197196451d1e065426e2420e498 100644 --- a/src/legacy/solvers/tnlMatrixSolver.h +++ b/src/legacy/solvers/tnlMatrixSolver.h @@ -89,49 +89,49 @@ tnlMatrixSolver< Real, Device, Index > :: tnlMatrixSolver( const tnlString& name template< typename Real, typename Device, typename Index > Index tnlMatrixSolver< Real, Device, Index > :: getIterationNumber() const { - return this -> iteration; + return this->iteration; }; template< typename Real, typename Device, typename Index > const Real& tnlMatrixSolver< Real, Device, Index > :: getResidue() const { - return this -> residue; + return this->residue; }; template< typename Real, typename Device, typename Index > void tnlMatrixSolver< Real, Device, Index > :: setVerbosity( int verbose ) { - this -> verbosity = verbose; + this->verbosity = verbose; }; template< typename Real, typename Device, typename Index > void tnlMatrixSolver< Real, Device, Index > :: setTimerCPU( tnlTimerCPU* timer ) { - this -> cpu_timer = timer; + this->cpu_timer = timer; }; template< typename Real, typename Device, typename Index > void tnlMatrixSolver< Real, Device, Index > :: setTimerRT( tnlTimerRT* timer ) { - this -> rt_timer = timer; + this->rt_timer = timer; }; template< typename Real, typename Device, typename Index > void tnlMatrixSolver< Real, Device, Index > :: printOut() { - if( this -> verbosity > 0 ) + if( this->verbosity > 0 ) { int cpu_time = 0; - if( this -> cpu_timer ) cpu_time = this -> cpu_timer -> getTime( 0, this -> solver_comm ); + if( this->cpu_timer ) cpu_time = this->cpu_timer -> getTime( 0, this->solver_comm ); if( MPIGetRank() != 0 ) return; // TODO: add EST //cout << " EST: " << estimated; cout << " ITER:" << setw( 8 ) << getIterationNumber() << " RES:" << setprecision( 5 ) << setw( 12 ) << getResidue(); - if( this -> cpu_timer ) + if( this->cpu_timer ) cout << " CPU: " << setw( 8 ) << cpu_time; - if( this -> rt_timer ) - cout << " ELA: " << setw( 8 ) << this -> rt_timer -> getTime(); + if( this->rt_timer ) + cout << " ELA: " << setw( 8 ) << this->rt_timer -> getTime(); cout << " \r" << flush; } }; diff --git a/src/legacy/solvers/tnlSORSolver.h b/src/legacy/solvers/tnlSORSolver.h index a184311b11ce7e0fdeb1d17683299514ca29c3c2..4cb3e4c97a330dba100faad6664a3fa436a2631c 100644 --- a/src/legacy/solvers/tnlSORSolver.h +++ b/src/legacy/solvers/tnlSORSolver.h @@ -69,13 +69,13 @@ tnlString tnlSORSolverOld< Real, Device, Index > :: getType() const template< typename Real, typename Device, typename Index > void tnlSORSolverOld< Real, Device, Index > :: setSOROmega( const Real& omega ) { - this -> sorOmega = omega; + this->sorOmega = omega; } template< typename Real, typename Device, typename Index > Real tnlSORSolverOld< Real, Device, Index > :: getSOROmega( ) const { - return this -> sorOmega; + return this->sorOmega; } template< typename Real, typename Device, typename Index > @@ -88,33 +88,33 @@ bool tnlSORSolverOld< Real, Device, Index > :: solve( const tnlMatrix< Real, Dev { const Index size = A. getSize(); - this -> iteration = 0; - this -> residue = max_residue + 1.0;; + this->iteration = 0; + this->residue = max_residue + 1.0;; Real bNorm = b. lpNorm( ( Real ) 2.0 ); - while( this -> iteration < max_iterations && - max_residue < this -> residue ) + while( this->iteration < max_iterations && + max_residue < this->residue ) { - A. performSORIteration( this -> sorOmega, + A. performSORIteration( this->sorOmega, b, x, 0, size ); - if( this -> iteration % 10 == 0 ) + if( this->iteration % 10 == 0 ) { - this -> residue = this -> getResidue( A, b, x, bNorm ); - if( this -> verbosity > 1 ) - this -> printOut(); + this->residue = this->getResidue( A, b, x, bNorm ); + if( this->verbosity > 1 ) + this->printOut(); } - this -> iteration ++; + this->iteration ++; } - if( this -> verbosity > 0 ) + if( this->verbosity > 0 ) { - this -> residue = this -> getResidue( A, b, x, bNorm ); - this -> printOut(); + this->residue = this->getResidue( A, b, x, bNorm ); + this->printOut(); } - if( this -> iteration <= max_iterations ) return true; + if( this->iteration <= max_iterations ) return true; return false; }; diff --git a/src/matrices/tnlCSRMatrix_impl.h b/src/matrices/tnlCSRMatrix_impl.h index c25354311c5c8e0799b4eafdbf4761839435ac69..6622a0e0d55e8a04e38a971fa5834d06221e2f1d 100644 --- a/src/matrices/tnlCSRMatrix_impl.h +++ b/src/matrices/tnlCSRMatrix_impl.h @@ -726,7 +726,7 @@ class tnlCSRMatrixDeviceDependentCode< tnlHost > const InVector* inVectorPtr = &inVector; OutVector* outVectorPtr = &outVector; #ifdef HAVE_OPENMP -#pragma omp parallel for private( matrixPtr, inVectorPtr, outVectorPtr ), schedule(static ) +#pragma omp parallel for firstprivate( matrixPtr, inVectorPtr, outVectorPtr ), schedule(static ), if( tnlHost::isOMPEnabled() ) #endif for( Index row = 0; row < rows; row ++ ) ( *outVectorPtr )[ row ] = matrixPtr->rowVectorProduct( row, *inVectorPtr ); diff --git a/src/matrices/tnlDenseMatrix_impl.h b/src/matrices/tnlDenseMatrix_impl.h index 557070f17207fb357e1b16094cabab3dbcb498ee..4e78c369d01cda60d87cf2dbb3cd2d21789ba7d4 100644 --- a/src/matrices/tnlDenseMatrix_impl.h +++ b/src/matrices/tnlDenseMatrix_impl.h @@ -48,7 +48,7 @@ template< typename Real, typename Index > tnlString tnlDenseMatrix< Real, Device, Index >::getTypeVirtual() const { - return this -> getType(); + return this->getType(); } template< typename Real, @@ -932,7 +932,7 @@ class tnlDenseMatrixDeviceDependentCode< tnlHost > OutVector& outVector ) { #ifdef HAVE_OPENMP -#pragma omp parallel for +#pragma omp parallel for if( tnlHost::isOMPEnabled() ) #endif for( Index row = 0; row < matrix.getRows(); row ++ ) outVector[ row ] = matrix.rowVectorProduct( row, inVector ); diff --git a/src/matrices/tnlEllpackMatrix_impl.h b/src/matrices/tnlEllpackMatrix_impl.h index a4197cb02dcf0fe6344a70843f8410cd03ec2689..6061ac0f22ead22825ae46ea4bc72524779860bd 100644 --- a/src/matrices/tnlEllpackMatrix_impl.h +++ b/src/matrices/tnlEllpackMatrix_impl.h @@ -688,7 +688,7 @@ class tnlEllpackMatrixDeviceDependentCode< tnlHost > OutVector& outVector ) { #ifdef HAVE_OPENMP -#pragma omp parallel for +#pragma omp parallel for if( tnlHost::isOMPEnabled() ) #endif for( Index row = 0; row < matrix.getRows(); row ++ ) outVector[ row ] = matrix.rowVectorProduct( row, inVector ); diff --git a/src/matrices/tnlMultidiagonalMatrix_impl.h b/src/matrices/tnlMultidiagonalMatrix_impl.h index f425782cfdd10bcee847d548b5178b1852020278..2c8a92d0a7b1b3f2db246d7817f0a490b1e6f7cd 100644 --- a/src/matrices/tnlMultidiagonalMatrix_impl.h +++ b/src/matrices/tnlMultidiagonalMatrix_impl.h @@ -735,7 +735,7 @@ class tnlMultidiagonalMatrixDeviceDependentCode< tnlHost > OutVector& outVector ) { #ifdef HAVE_OPENMP -#pragma omp parallel for +#pragma omp parallel for if( tnlHost::isOMPEnabled() ) #endif for( Index row = 0; row < matrix.getRows(); row ++ ) outVector[ row ] = matrix.rowVectorProduct( row, inVector ); diff --git a/src/matrices/tnlSlicedEllpackMatrix_impl.h b/src/matrices/tnlSlicedEllpackMatrix_impl.h index a185b5ea056148d71451bb961329843e4ab92463..b047ec08b3891c8ed6d6427cec95f8243424efbc 100644 --- a/src/matrices/tnlSlicedEllpackMatrix_impl.h +++ b/src/matrices/tnlSlicedEllpackMatrix_impl.h @@ -756,7 +756,7 @@ class tnlSlicedEllpackMatrixDeviceDependentCode< tnlHost > OutVector& outVector ) { #ifdef HAVE_OPENMP -#pragma omp parallel for +#pragma omp parallel for if( tnlHost::isOMPEnabled() ) #endif for( Index row = 0; row < matrix.getRows(); row ++ ) outVector[ row ] = matrix.rowVectorProduct( row, inVector ); diff --git a/src/matrices/tnlTridiagonalMatrix_impl.h b/src/matrices/tnlTridiagonalMatrix_impl.h index 6791f7b48fa5966121e1f0a2e045f1cf95f98506..3cb917dc81849e2ce12fa4e40a3c33945d2a332a 100644 --- a/src/matrices/tnlTridiagonalMatrix_impl.h +++ b/src/matrices/tnlTridiagonalMatrix_impl.h @@ -654,7 +654,7 @@ class tnlTridiagonalMatrixDeviceDependentCode< tnlHost > OutVector& outVector ) { #ifdef HAVE_OPENMP -#pragma omp parallel for +#pragma omp parallel for if( tnlHost::isOMPEnabled() ) #endif for( Index row = 0; row < matrix.getRows(); row ++ ) outVector[ row ] = matrix.rowVectorProduct( row, inVector ); diff --git a/src/mesh/grids/tnlGrid1D_impl.h b/src/mesh/grids/tnlGrid1D_impl.h index bd9f30ac8a3d52f1fd2a00156f32763d60fb04bb..c62ce6d88f994146759b73e130036b5312673356 100644 --- a/src/mesh/grids/tnlGrid1D_impl.h +++ b/src/mesh/grids/tnlGrid1D_impl.h @@ -56,7 +56,7 @@ template< typename Real, typename Index > tnlString tnlGrid< 1, Real, Device, Index >::getTypeVirtual() const { - return this -> getType(); + return this->getType(); } template< typename Real, @@ -109,7 +109,7 @@ template< typename Real, typename Index > void tnlGrid< 1, Real, Device, Index >::setDimensions( const CoordinatesType& dimensions ) { - this -> setDimensions( dimensions. x() ); + this->setDimensions( dimensions. x() ); } template< typename Real, @@ -278,7 +278,7 @@ tnlGrid< 1, Real, Device, Index >::getDifferenceAbsMax( const GridFunction& f1, cell.getCoordinates().x() < getDimensions().x(); cell.getCoordinates().x()++ ) { - IndexType c = this -> getEntityIndex( cell ); + IndexType c = this->getEntityIndex( cell ); maxDiff = Max( maxDiff, tnlAbs( f1[ c ] - f2[ c ] ) ); } return maxDiff; @@ -340,7 +340,7 @@ bool tnlGrid< 1, Real, Device, Index >::load( tnlFile& file ) cerr << "I was not able to load the domain description of a tnlGrid." << endl; return false; } - this -> setDimensions( dimensions ); + this->setDimensions( dimensions ); return true; }; @@ -384,7 +384,7 @@ bool tnlGrid< 1, Real, Device, Index >::write( const MeshFunction& function, { cerr << "The size ( " << function. getSize() << " ) of the mesh function does not agree with the DOFs ( " - << this -> template getEntitiesCount< Cell >() << " ) of a mesh." << endl; + << this->template getEntitiesCount< Cell >() << " ) of a mesh." << endl; return false; } fstream file; diff --git a/src/mesh/grids/tnlGrid2D_impl.h b/src/mesh/grids/tnlGrid2D_impl.h index c0b03f3c07e466ffdc60d8aae6fe206ca1b3ce3b..bfd4364aa2da8f6d43f25750451b9d65e6b70c77 100644 --- a/src/mesh/grids/tnlGrid2D_impl.h +++ b/src/mesh/grids/tnlGrid2D_impl.h @@ -57,7 +57,7 @@ template< typename Real, typename Index > tnlString tnlGrid< 2, Real, Device, Index > :: getTypeVirtual() const { - return this -> getType(); + return this->getType(); } template< typename Real, @@ -397,7 +397,7 @@ bool tnlGrid< 2, Real, Device, Index > :: save( tnlFile& file ) const return false; if( ! this->origin.save( file ) || ! this->proportions.save( file ) || - ! this -> dimensions.save( file ) ) + ! this->dimensions.save( file ) ) { cerr << "I was not able to save the domain description of a tnlGrid." << endl; return false; @@ -420,7 +420,7 @@ bool tnlGrid< 2, Real, Device, Index > :: load( tnlFile& file ) cerr << "I was not able to load the domain description of a tnlGrid." << endl; return false; } - this -> setDimensions( dimensions ); + this->setDimensions( dimensions ); return true; }; @@ -456,20 +456,20 @@ bool tnlGrid< 2, Real, Device, Index > :: writeMesh( const tnlString& fileName, if( format == "asymptote" ) { file << "size( " - << this -> getProportions(). x() << "cm , " - << this -> getProportions(). y() << "cm );" + << this->getProportions(). x() << "cm , " + << this->getProportions(). y() << "cm );" << endl << endl; MeshEntity< 0 > vertex( *this ); CoordinatesType& vertexCoordinates = vertex.getCoordinates(); VertexType v; - for( Index j = 0; j < this -> dimensions. y(); j ++ ) + for( Index j = 0; j < this->dimensions. y(); j ++ ) { file << "draw( "; vertexCoordinates.x() = 0; vertexCoordinates.y() = j; v = vertex.getCenter(); file << "( " << v. x() << ", " << v. y() << " )"; - for( Index i = 0; i < this -> dimensions. x(); i ++ ) + for( Index i = 0; i < this->dimensions. x(); i ++ ) { vertexCoordinates.x() = i + 1; vertexCoordinates.y() = j; @@ -479,14 +479,14 @@ bool tnlGrid< 2, Real, Device, Index > :: writeMesh( const tnlString& fileName, file << " );" << endl; } file << endl; - for( Index i = 0; i < this -> dimensions. x(); i ++ ) + for( Index i = 0; i < this->dimensions. x(); i ++ ) { file << "draw( "; vertexCoordinates.x() = i; vertexCoordinates.y() = 0; v = vertex.getCenter(); file << "( " << v. x() << ", " << v. y() << " )"; - for( Index j = 0; j < this -> dimensions. y(); j ++ ) + for( Index j = 0; j < this->dimensions. y(); j ++ ) { vertexCoordinates.x() = i; vertexCoordinates.y() = j + 1; @@ -500,8 +500,8 @@ bool tnlGrid< 2, Real, Device, Index > :: writeMesh( const tnlString& fileName, MeshEntity< 2 > cell( *this ); CoordinatesType& cellCoordinates = cell.getCoordinates(); const RealType cellMeasure = this->getSpaceSteps().x() * this->getSpaceSteps().y(); - for( Index i = 0; i < this -> dimensions. x(); i ++ ) - for( Index j = 0; j < this -> dimensions. y(); j ++ ) + for( Index i = 0; i < this->dimensions. x(); i ++ ) + for( Index j = 0; j < this->dimensions. y(); j ++ ) { cellCoordinates.x() = i; cellCoordinates.y() = j; @@ -510,18 +510,18 @@ bool tnlGrid< 2, Real, Device, Index > :: writeMesh( const tnlString& fileName, << "$\" ), ( " << v. x() << ", " << v. y() << " ), S );" << endl; } - for( Index i = 0; i < this -> dimensions. x(); i ++ ) - for( Index j = 0; j < this -> dimensions. y(); j ++ ) + for( Index i = 0; i < this->dimensions. x(); i ++ ) + for( Index j = 0; j < this->dimensions. y(); j ++ ) { VertexType v1, v2, c; /**** * East edge normal */ - /*v1 = this -> getVertex( CoordinatesType( i + 1, j ), v1 ); - v2 = this -> getVertex( CoordinatesType( i + 1, j + 1 ), v2 ); + /*v1 = this->getVertex( CoordinatesType( i + 1, j ), v1 ); + v2 = this->getVertex( CoordinatesType( i + 1, j + 1 ), v2 ); c = ( ( Real ) 0.5 ) * ( v1 + v2 ); - this -> getEdgeNormal< 1, 0 >( CoordinatesType( i, j ), v ); + this->getEdgeNormal< 1, 0 >( CoordinatesType( i, j ), v ); v *= 0.5; file << "draw( ( " << c. x() << ", " << c. y() << " )--( " << c. x() + v. x() << ", " << c.y() + v. y() << " ), Arrow(size=1mm),p=green);" << endl; @@ -529,10 +529,10 @@ bool tnlGrid< 2, Real, Device, Index > :: writeMesh( const tnlString& fileName, /**** * West edge normal */ - /*this -> getVertex< -1, -1 >( CoordinatesType( i, j ), v1 ); - this -> getVertex< -1, 1 >( CoordinatesType( i, j ), v2 ); + /*this->getVertex< -1, -1 >( CoordinatesType( i, j ), v1 ); + this->getVertex< -1, 1 >( CoordinatesType( i, j ), v2 ); c = ( ( Real ) 0.5 ) * ( v1 + v2 ); - this -> getEdgeNormal< -1, 0 >( CoordinatesType( i, j ), v ); + this->getEdgeNormal< -1, 0 >( CoordinatesType( i, j ), v ); v *= 0.5; file << "draw( ( " << c. x() << ", " << c. y() << " )--( " << c. x() + v. x() << ", " << c.y() + v. y() << " ), Arrow(size=1mm),p=blue);" << endl; @@ -540,10 +540,10 @@ bool tnlGrid< 2, Real, Device, Index > :: writeMesh( const tnlString& fileName, /**** * North edge normal */ - /*this -> getVertex< 1, 1 >( CoordinatesType( i, j ), v1 ); - this -> getVertex< -1, 1 >( CoordinatesType( i, j ), v2 ); + /*this->getVertex< 1, 1 >( CoordinatesType( i, j ), v1 ); + this->getVertex< -1, 1 >( CoordinatesType( i, j ), v2 ); c = ( ( Real ) 0.5 ) * ( v1 + v2 ); - this -> getEdgeNormal< 0, 1 >( CoordinatesType( i, j ), v ); + this->getEdgeNormal< 0, 1 >( CoordinatesType( i, j ), v ); v *= 0.5; file << "draw( ( " << c. x() << ", " << c. y() << " )--( " << c. x() + v. x() << ", " << c.y() + v. y() << " ), Arrow(size=1mm),p=green);" << endl; @@ -551,10 +551,10 @@ bool tnlGrid< 2, Real, Device, Index > :: writeMesh( const tnlString& fileName, /**** * South edge normal */ - /*this -> getVertex< 1, -1 >( CoordinatesType( i, j ), v1 ); - this -> getVertex< -1, -1 >( CoordinatesType( i, j ), v2 ); + /*this->getVertex< 1, -1 >( CoordinatesType( i, j ), v1 ); + this->getVertex< -1, -1 >( CoordinatesType( i, j ), v2 ); c = ( ( Real ) 0.5 ) * ( v1 + v2 ); - this -> getEdgeNormal< 0, -1 >( CoordinatesType( i, j ), v ); + this->getEdgeNormal< 0, -1 >( CoordinatesType( i, j ), v ); v *= 0.5; file << "draw( ( " << c. x() << ", " << c. y() << " )--( " << c. x() + v. x() << ", " << c.y() + v. y() << " ), Arrow(size=1mm),p=blue);" << endl; diff --git a/src/mesh/grids/tnlGrid3D_impl.h b/src/mesh/grids/tnlGrid3D_impl.h index 55974cfd2c0c10338497295da4a8a33ef157f6e4..e1608d67d184caed263a2e6b2e7e22c9e4a83498 100644 --- a/src/mesh/grids/tnlGrid3D_impl.h +++ b/src/mesh/grids/tnlGrid3D_impl.h @@ -61,7 +61,7 @@ template< typename Real, typename Index > tnlString tnlGrid< 3, Real, Device, Index > :: getTypeVirtual() const { - return this -> getType(); + return this->getType(); } template< typename Real, @@ -203,7 +203,7 @@ template< typename Real, typename Index > void tnlGrid< 3, Real, Device, Index > :: setDimensions( const CoordinatesType& dimensions ) { - return this -> setDimensions( dimensions. x(), dimensions. y(), dimensions. z() ); + return this->setDimensions( dimensions. x(), dimensions. y(), dimensions. z() ); } template< typename Real, @@ -213,7 +213,7 @@ __cuda_callable__ inline const typename tnlGrid< 3, Real, Device, Index > :: CoordinatesType& tnlGrid< 3, Real, Device, Index > :: getDimensions() const { - return this -> dimensions; + return this->dimensions; } template< typename Real, @@ -423,7 +423,7 @@ template< typename Real, cell.getCoordinates().x() < getDimensions().x(); cell.getCoordinates().x()++ ) { - IndexType c = this -> getEntityIndex( cell ); + IndexType c = this->getEntityIndex( cell ); maxDiff = Max( maxDiff, tnlAbs( f1[ c ] - f2[ c ] ) ); } return maxDiff; @@ -528,10 +528,10 @@ bool tnlGrid< 3, Real, Device, Index > :: write( const MeshFunction& function, const tnlString& fileName, const tnlString& format ) const { - if( this -> template getEntitiesCount< Cell >() != function. getSize() ) + if( this->template getEntitiesCount< Cell >() != function. getSize() ) { cerr << "The size ( " << function. getSize() - << " ) of a mesh function does not agree with the DOFs ( " << this -> template getEntitiesCount< Cell >() << " ) of a mesh." << endl; + << " ) of a mesh function does not agree with the DOFs ( " << this->template getEntitiesCount< Cell >() << " ) of a mesh." << endl; return false; } fstream file; diff --git a/src/mesh/grids/tnlGridTraverser.h b/src/mesh/grids/tnlGridTraverser.h index 8b05a88e4eeec5212c3b8a67f33c92f4372a0ca4..8427932dfd340d80ac60187e72522222531baf90 100644 --- a/src/mesh/grids/tnlGridTraverser.h +++ b/src/mesh/grids/tnlGridTraverser.h @@ -112,8 +112,8 @@ class tnlGridTraverser< tnlGrid< 2, Real, tnlHost, Index > > static void processEntities( const GridType& grid, - const CoordinatesType& begin, - const CoordinatesType& end, + const CoordinatesType begin, + const CoordinatesType end, const CoordinatesType& entityOrientation, const CoordinatesType& entityBasis, UserData& userData ); diff --git a/src/mesh/grids/tnlGridTraverser_impl.h b/src/mesh/grids/tnlGridTraverser_impl.h index 93a6fdac22bae92f285b42c94dd559ead740eb25..8c9d6bde083940f9cebdc5ba094a0cbdb85c22f7 100644 --- a/src/mesh/grids/tnlGridTraverser_impl.h +++ b/src/mesh/grids/tnlGridTraverser_impl.h @@ -38,10 +38,11 @@ processEntities( const CoordinatesType& entityBasis, UserData& userData ) { + + GridEntity entity( grid ); entity.setOrientation( entityOrientation ); entity.setBasis( entityBasis ); - if( processOnlyBoundaryEntities ) { entity.getCoordinates() = begin; @@ -172,8 +173,8 @@ void tnlGridTraverser< tnlGrid< 2, Real, tnlHost, Index > >:: processEntities( const GridType& grid, - const CoordinatesType& begin, - const CoordinatesType& end, + const CoordinatesType begin, + const CoordinatesType end, const CoordinatesType& entityOrientation, const CoordinatesType& entityBasis, UserData& userData ) @@ -211,6 +212,7 @@ processEntities( } else { +//#pragma omp parallel for firstprivate( entity, begin, end ) if( tnlHost::isOMPEnabled() ) for( entity.getCoordinates().y() = begin.y(); entity.getCoordinates().y() <= end.y(); entity.getCoordinates().y() ++ ) diff --git a/src/mesh/tnlDummyMesh.h b/src/mesh/tnlDummyMesh.h index 6c3c5274b7002ee7ce8c053f8c292ad3ded23100..255d75fa5011e59b050b9ff6d7a7ba423ef88318 100644 --- a/src/mesh/tnlDummyMesh.h +++ b/src/mesh/tnlDummyMesh.h @@ -28,9 +28,13 @@ class tnlDummyMesh typedef Real RealType; typedef Device DeviceType; typedef Index IndexType; - + typedef tnlDummyMesh< Real, Device, Index > ThisType; + static const int meshDimensions = 1; - + + constexpr static int getMeshDimensions() { return meshDimensions; } + + const Real& getParametricStep(){ return 0.0; } tnlString getSerializationType() const { return tnlString( "tnlDummyMesh" ); } diff --git a/src/operators/CMakeLists.txt b/src/operators/CMakeLists.txt index 87ce7309512ca0b3bbb1bad46a2655eb5b5e7dcf..3ab7e12a6678cd719ce4c1e33bf14bdf104ac72f 100755 --- a/src/operators/CMakeLists.txt +++ b/src/operators/CMakeLists.txt @@ -5,7 +5,6 @@ ADD_SUBDIRECTORY( operator-Q ) ADD_SUBDIRECTORY( operator-curvature ) SET( headers tnlDirichletBoundaryConditions.h - tnlDirichletBoundaryConditions_impl.h tnlExactFunctionInverseOperator.h tnlExactIdentityOperator.h tnlExactOperatorComposition.h diff --git a/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator.h b/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator.h index af39c588118eb976eec6425cd2c9d068d530c5e5..9b16952d403e5b707a52c41983b40c4de4085034 100644 --- a/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator.h +++ b/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator.h @@ -52,7 +52,7 @@ class tnlFiniteVolumeNonlinearOperator< tnlGrid< 1,MeshReal, Device, MeshIndex > typename Vector, typename Matrix > __cuda_callable__ - void updateLinearSystem( const RealType& time, + void setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -106,7 +106,7 @@ class tnlFiniteVolumeNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex typename Vector, typename Matrix > __cuda_callable__ - void updateLinearSystem( const RealType& time, + void setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -158,7 +158,7 @@ class tnlFiniteVolumeNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex typename Vector, typename Matrix > __cuda_callable__ - void updateLinearSystem( const RealType& time, + void setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, diff --git a/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator_impl.h b/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator_impl.h index 9bd82a6965d7253712ac51446a31577a95f3df22..2ab2cf18c7b373c460b2e9c566e9978c89bf716c 100644 --- a/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator_impl.h +++ b/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator_impl.h @@ -71,7 +71,7 @@ template< typename MeshEntity, __cuda_callable__ void tnlFiniteVolumeNonlinearOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -155,7 +155,7 @@ template< typename MeshEntity, __cuda_callable__ void tnlFiniteVolumeNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -268,7 +268,7 @@ __cuda_callable__ #endif void tnlFiniteVolumeNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, diff --git a/src/operators/diffusion/tnlExactMeanCurvature.h b/src/operators/diffusion/tnlExactMeanCurvature.h index bb4b3d67fb798ad1c8d2a5605cea77c532528d12..19506f8382db826d52fa016399c194431854379d 100644 --- a/src/operators/diffusion/tnlExactMeanCurvature.h +++ b/src/operators/diffusion/tnlExactMeanCurvature.h @@ -44,7 +44,7 @@ class tnlExactMeanCurvature template< typename Real > void setRegularizationEpsilon( const Real& eps) { - nonlinearDiffusion.getNonlinearity().getInnerOperator().setRegularizationEpislon( eps ); + nonlinearDiffusion.getNonlinearity().getInnerOperator().setRegularizationEpsilon( eps ); } template< typename Function > diff --git a/src/operators/diffusion/tnlExactNonlinearDiffusion.h b/src/operators/diffusion/tnlExactNonlinearDiffusion.h index 3dd005bc237d56b8539c8acb9fcba8ebd8179848..87403c37446355e7f0392ebcfe5f67a692f8371b 100644 --- a/src/operators/diffusion/tnlExactNonlinearDiffusion.h +++ b/src/operators/diffusion/tnlExactNonlinearDiffusion.h @@ -73,7 +73,7 @@ class tnlExactNonlinearDiffusion< 1, Nonlinearity, InnerOperator > const RealType u_xx = innerOperator.template getPartialDerivative< Function, 2, 0, 0 >( function, v, time ); const RealType g = nonlinearity( function, v, time ); const RealType g_x = nonlinearity.template getPartialDerivative< Function, 1, 0, 0 >( function, v, time ); - return u_xx - u_x * g_x / g; + return u_xx * g + u_x * g_x; } protected: @@ -131,7 +131,7 @@ class tnlExactNonlinearDiffusion< 2, Nonlinearity, InnerOperator > const RealType g_x = nonlinearity.template getPartialDerivative< Function, 1, 0, 0 >( function, v, time ); const RealType g_y = nonlinearity.template getPartialDerivative< Function, 0, 1, 0 >( function, v, time ); - return u_xx + u_yy - ( g_x * u_x + g_y * u_y ) / g; + return ( u_xx + u_yy ) * g + g_x * u_x + g_y * u_y; } protected: @@ -193,7 +193,7 @@ class tnlExactNonlinearDiffusion< 3, Nonlinearity, InnerOperator > const RealType g_y = nonlinearity.template getPartialDerivative< Function, 0, 1, 0 >( function, v, time ); const RealType g_z = nonlinearity.template getPartialDerivative< Function, 0, 0, 1 >( function, v, time ); - return u_xx + u_yy + u_zz - ( g_x * u_x + g_y * u_y + g_z * u_z ) / g; + return ( u_xx + u_yy + u_zz ) * g + g_x * u_x + g_y * u_y + g_z * u_z; } protected: diff --git a/src/operators/diffusion/tnlLinearDiffusion.h b/src/operators/diffusion/tnlLinearDiffusion.h index b4683676e673a985b0a233f5a3f016b9f8bf7f4e..9c63d19b641e79c4a8c282154e74273e1f1c80bd 100644 --- a/src/operators/diffusion/tnlLinearDiffusion.h +++ b/src/operators/diffusion/tnlLinearDiffusion.h @@ -55,12 +55,10 @@ class tnlLinearDiffusion< tnlGrid< 1,MeshReal, Device, MeshIndex >, Real, Index static constexpr int getMeshDimensions() { return Dimensions; } - template< int EntityDimensions = Dimensions > - using MeshFunction = tnlMeshFunction< MeshType, EntityDimensions >; - static tnlString getType(); - template< typename PreimageFunction, typename MeshEntity > + template< typename PreimageFunction, + typename MeshEntity > __cuda_callable__ inline Real operator()( const PreimageFunction& u, const MeshEntity& entity, @@ -72,19 +70,17 @@ class tnlLinearDiffusion< tnlGrid< 1,MeshReal, Device, MeshIndex >, Real, Index const IndexType& index, const MeshEntity& entity ) const; - template< typename MeshEntity, - typename Vector, - typename MatrixRow > + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > __cuda_callable__ - inline void updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunction< 1 >& u, - Vector& b, - MatrixRow& matrixRow ) const; - + inline void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const; }; @@ -110,10 +106,6 @@ class tnlLinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index static constexpr int getMeshDimensions() { return Dimensions; } - - template< int EntityDimensions = Dimensions > - using MeshFunction = tnlMeshFunction< MeshType, EntityDimensions >; - static tnlString getType(); template< typename PreimageFunction, typename EntityType > @@ -127,19 +119,18 @@ class tnlLinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index inline Index getLinearSystemRowLength( const MeshType& mesh, const IndexType& index, const EntityType& entity ) const; - - template< typename Vector, - typename MatrixRow, - typename EntityType > + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > __cuda_callable__ - inline void updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const EntityType& entity, - const MeshFunction< 2 >& u, - Vector& b, - MatrixRow& matrixRow ) const; + inline void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const; }; @@ -165,10 +156,6 @@ class tnlLinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index static constexpr int getMeshDimensions() { return Dimensions; } - template< int EntityDimensions = Dimensions > - using MeshFunction = tnlMeshFunction< MeshType, EntityDimensions >; - - static tnlString getType(); template< typename PreimageFunction, @@ -184,19 +171,17 @@ class tnlLinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index const IndexType& index, const EntityType& entity ) const; - template< typename Vector, - typename MatrixRow, - typename EntityType > + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > __cuda_callable__ - inline void updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const EntityType& entity, - const MeshFunction< 3 >& u, - Vector& b, - MatrixRow& matrixRow ) const; - + inline void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const; }; diff --git a/src/operators/diffusion/tnlLinearDiffusion_impl.h b/src/operators/diffusion/tnlLinearDiffusion_impl.h index ef38d2e8b0f65119b6769fb778b9475df777ec4d..04e4177f6a1b3950912d70926fade6d7d17724a1 100644 --- a/src/operators/diffusion/tnlLinearDiffusion_impl.h +++ b/src/operators/diffusion/tnlLinearDiffusion_impl.h @@ -82,25 +82,27 @@ template< typename MeshReal, typename MeshIndex, typename Real, typename Index > - template< typename MeshEntity, - typename Vector, - typename Matrix > + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > __cuda_callable__ inline void tnlLinearDiffusion< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunction< 1 >& u, - Vector& b, - Matrix& matrix ) const +setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const { + static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." ); + static_assert( PreimageFunction::getEntitiesDimensions() == 1, "Wrong preimage function" ); const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); + const IndexType& index = entity.getIndex(); typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); - const RealType lambdaX = tau * mesh.template getSpaceStepsProducts< -2 >(); + const RealType lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >(); matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< -1 >(), - lambdaX ); matrixRow.setElement( 1, index, 2.0 * lambdaX ); matrixRow.setElement( 2, neighbourEntities.template getEntityIndex< 1 >(), - lambdaX ); @@ -171,26 +173,28 @@ template< typename MeshReal, typename MeshIndex, typename Real, typename Index > - template< typename Vector, + template< typename PreimageFunction, + typename MeshEntity, typename Matrix, - typename EntityType > + typename Vector > __cuda_callable__ inline void tnlLinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const EntityType& entity, - const MeshFunction< 2 >& u, - Vector& b, - Matrix& matrix ) const +setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const { + static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." ); + static_assert( PreimageFunction::getEntitiesDimensions() == 2, "Wrong preimage function" ); + const IndexType& index = entity.getIndex(); typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); - const RealType lambdaX = tau * mesh.template getSpaceStepsProducts< -2, 0 >(); - const RealType lambdaY = tau * mesh.template getSpaceStepsProducts< 0, -2 >(); - const typename EntityType::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); + const RealType lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< 0, -1 >(), -lambdaY ); matrixRow.setElement( 1, neighbourEntities.template getEntityIndex< -1, 0 >(), -lambdaX ); matrixRow.setElement( 2, index, 2.0 * ( lambdaX + lambdaY ) ); @@ -266,27 +270,29 @@ template< typename MeshReal, typename MeshIndex, typename Real, typename Index > - template< typename Vector, + template< typename PreimageFunction, + typename MeshEntity, typename Matrix, - typename EntityType > + typename Vector > __cuda_callable__ inline void tnlLinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const EntityType& entity, - const MeshFunction< 3 >& u, - Vector& b, - Matrix& matrix ) const +setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const { - const typename EntityType::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); + static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." ); + static_assert( PreimageFunction::getEntitiesDimensions() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); + const IndexType& index = entity.getIndex(); typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); - const RealType lambdaX = tau * mesh.template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType lambdaY = tau * mesh.template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType lambdaZ = tau * mesh.template getSpaceStepsProducts< 0, 0, -2 >(); + const RealType lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< 0, 0, -1 >(), -lambdaZ ); matrixRow.setElement( 1, neighbourEntities.template getEntityIndex< 0, -1, 0 >(), -lambdaY ); matrixRow.setElement( 2, neighbourEntities.template getEntityIndex< -1, 0, 0 >(), -lambdaX ); diff --git a/src/operators/diffusion/tnlNonlinearDiffusion_impl.h b/src/operators/diffusion/tnlNonlinearDiffusion_impl.h index 88f0bae7ea1b840b24c3f37e73f5a2ba4874a69d..be5e87d68c57ce72093beb484aacb0ed729b070d 100644 --- a/src/operators/diffusion/tnlNonlinearDiffusion_impl.h +++ b/src/operators/diffusion/tnlNonlinearDiffusion_impl.h @@ -71,7 +71,7 @@ template< typename MeshEntity, __cuda_callable__ void tnlNonlinearDiffusion< tnlGrid< 1, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -80,7 +80,7 @@ updateLinearSystem( const RealType& time, Vector& b, Matrix& matrix ) const { - nonlinearDiffusionOperator.updateLinearSystem( time, tau, mesh, index, entity, u, b, matrix ); + nonlinearDiffusionOperator.setMatrixElements( time, tau, mesh, index, entity, u, b, matrix ); } template< typename MeshReal, @@ -148,7 +148,7 @@ template< typename MeshEntity, __cuda_callable__ void tnlNonlinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -157,7 +157,7 @@ updateLinearSystem( const RealType& time, Vector& b, Matrix& matrix ) const { - nonlinearDiffusionOperator.updateLinearSystem( time, tau, mesh, index, entity, u, b, matrix ); + nonlinearDiffusionOperator.setMatrixElements( time, tau, mesh, index, entity, u, b, matrix ); } template< typename MeshReal, @@ -225,7 +225,7 @@ template< typename MeshEntity, __cuda_callable__ void tnlNonlinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -234,7 +234,7 @@ updateLinearSystem( const RealType& time, Vector& b, Matrix& matrix ) const { - nonlinearDiffusionOperator.updateLinearSystem( time, tau, mesh, index, entity, u, b, matrix ); + nonlinearDiffusionOperator.setMatrixElements( time, tau, mesh, index, entity, u, b, matrix ); } #endif /* TNLNONLINEARDIFFUSION_IMPL_H */ diff --git a/src/operators/diffusion/tnlOneSidedMeanCurvature.h b/src/operators/diffusion/tnlOneSidedMeanCurvature.h index 87386d89d8fe0145235e6b6c9f09b9226f536bbb..a75f0f855257f3bdb8b8665b1c5c46bb53241579 100644 --- a/src/operators/diffusion/tnlOneSidedMeanCurvature.h +++ b/src/operators/diffusion/tnlOneSidedMeanCurvature.h @@ -106,7 +106,7 @@ class tnlOneSidedMeanCurvature typename Vector, typename Matrix > __cuda_callable__ - void updateLinearSystem( const RealType& time, + void setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -115,7 +115,7 @@ class tnlOneSidedMeanCurvature Vector& b, Matrix& matrix ) const { - this->nonlinearDiffusion.updateLinearSystem( time, tau, mesh, index, entity, u, b, matrix ); + this->nonlinearDiffusion.setMatrixElements( time, tau, mesh, index, entity, u, b, matrix ); } protected: diff --git a/src/operators/diffusion/tnlOneSidedNonlinearDiffusion.h b/src/operators/diffusion/tnlOneSidedNonlinearDiffusion.h index 1eb186f934d4d7b6f705a53ec2518d11700a9715..e6f62e3edfda873916198ce45f8bcec8609361b2 100644 --- a/src/operators/diffusion/tnlOneSidedNonlinearDiffusion.h +++ b/src/operators/diffusion/tnlOneSidedNonlinearDiffusion.h @@ -71,7 +71,7 @@ class tnlOneSidedNonlinearDiffusion< tnlGrid< 1,MeshReal, Device, MeshIndex >, N { const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); const typename MeshEntity::MeshType& mesh = entity.getMesh(); - const RealType& hx_div = mesh.template getSpaceStepsProducts< -2 >(); + const RealType& hx_div = entity.getMesh().template getSpaceStepsProducts< -2 >(); const IndexType& center = entity.getIndex(); const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); @@ -92,26 +92,24 @@ class tnlOneSidedNonlinearDiffusion< tnlGrid< 1,MeshReal, Device, MeshIndex >, N return 3; } - template< typename MeshEntity, - typename MeshFunction, - typename Vector, - typename Matrix > + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > __cuda_callable__ - void updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunction& u, - Vector& b, - Matrix& matrix ) const + inline void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const { typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); const IndexType& center = entity.getIndex(); const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - const RealType lambda_x = tau * mesh.template getSpaceStepsProducts< -2 >(); + const RealType lambda_x = tau * entity.getMesh().template getSpaceStepsProducts< -2 >(); const RealType& nonlinearity_center = this->nonlinearity[ center ]; const RealType& nonlinearity_west = this->nonlinearity[ west ]; const RealType aCoef = -lambda_x * nonlinearity_west; @@ -167,8 +165,8 @@ class tnlOneSidedNonlinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, { const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); const typename MeshEntity::MeshType& mesh = entity.getMesh(); - const RealType& hx_div = mesh.template getSpaceStepsProducts< -2, 0 >(); - const RealType& hy_div = mesh.template getSpaceStepsProducts< 0, -2 >(); + const RealType& hx_div = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hy_div = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); const IndexType& center = entity.getIndex(); const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >(); const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); @@ -194,19 +192,17 @@ class tnlOneSidedNonlinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, return 5; } - template< typename MeshEntity, - typename MeshFunction, - typename Vector, - typename Matrix > + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > __cuda_callable__ - void updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunction& u, - Vector& b, - Matrix& matrix ) const + inline void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const { typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); @@ -215,8 +211,8 @@ class tnlOneSidedNonlinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - const RealType lambda_x = tau * mesh.template getSpaceStepsProducts< -2, 0 >(); - const RealType lambda_y = tau * mesh.template getSpaceStepsProducts< 0, -2 >(); + const RealType lambda_x = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType lambda_y = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); const RealType& nonlinearity_center = this->nonlinearity[ center ]; const RealType& nonlinearity_west = this->nonlinearity[ west ]; const RealType& nonlinearity_south = this->nonlinearity[ south ]; @@ -278,9 +274,9 @@ class tnlOneSidedNonlinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, { const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); const typename MeshEntity::MeshType& mesh = entity.getMesh(); - const RealType& hx_div = mesh.template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& hy_div = mesh.template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& hz_div = mesh.template getSpaceStepsProducts< 0, 0, -2 >(); + const RealType& hx_div = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hy_div = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hz_div = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); const IndexType& center = entity.getIndex(); const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); @@ -313,19 +309,17 @@ class tnlOneSidedNonlinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, return 7; } - template< typename MeshEntity, - typename MeshFunction, - typename Vector, - typename Matrix > + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > __cuda_callable__ - void updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunction& u, - Vector& b, - Matrix& matrix ) const + inline void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const { typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); @@ -338,9 +332,9 @@ class tnlOneSidedNonlinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - const RealType lambda_x = tau * mesh.template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType lambda_y = tau * mesh.template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType lambda_z = tau * mesh.template getSpaceStepsProducts< 0, 0, -2 >(); + const RealType lambda_x = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType lambda_y = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType lambda_z = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); const RealType& nonlinearity_center = this->nonlinearity[ center ]; const RealType& nonlinearity_west = this->nonlinearity[ west ]; const RealType& nonlinearity_south = this->nonlinearity[ south ]; diff --git a/src/operators/euler/fvm/tnlLaxFridrichs_impl.h b/src/operators/euler/fvm/tnlLaxFridrichs_impl.h index c5b014ee6fa4d709e6487fca2357eb7f910bfa09..92cb7b70781005ced0dda7f658be5979a6e01214 100644 --- a/src/operators/euler/fvm/tnlLaxFridrichs_impl.h +++ b/src/operators/euler/fvm/tnlLaxFridrichs_impl.h @@ -53,7 +53,7 @@ template< typename Real, template< int, typename, typename, typename > class GridGeometry > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureGradient >::bindMesh( const MeshType& mesh ) { - this -> mesh = &mesh; + this->mesh = &mesh; } template< typename Real, @@ -74,7 +74,7 @@ template< typename Real, template< int, typename, typename, typename > class GridGeometry > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureGradient > :: setRegularization( const RealType& epsilon ) { - this -> regularizeEps = epsilon; + this->regularizeEps = epsilon; } template< typename Real, @@ -84,7 +84,7 @@ template< typename Real, template< int, typename, typename, typename > class GridGeometry > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureGradient > :: setViscosityCoefficient( const RealType& v ) { - this -> viscosityCoefficient = v; + this->viscosityCoefficient = v; } template< typename Real, @@ -106,7 +106,7 @@ template< typename Real, template< typename Vector > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureGradient > :: setRhoU1( Vector& rho_u1 ) { - this -> rho_u1. bind( rho_u1 ); + this->rho_u1. bind( rho_u1 ); } template< typename Real, @@ -117,7 +117,7 @@ template< typename Real, template< typename Vector > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureGradient > :: setRhoU2( Vector& rho_u2 ) { - this -> rho_u2. bind( rho_u2 ); + this->rho_u2. bind( rho_u2 ); } template< typename Real, @@ -139,7 +139,7 @@ template< typename Real, template< typename Vector > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureGradient > :: setPressureGradient( Vector& grad_p ) { - this -> pressureGradient = &grad_p; + this->pressureGradient = &grad_p; } template< typename Real, @@ -157,10 +157,10 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureG tnlAssert( pressureGradient, cerr << "No pressure gradient was set in the the Lax-Fridrichs scheme." ) const IndexType& c = centralVolume; - const IndexType e = this -> mesh -> getElementNeighbour( centralVolume, 1, 0 ); - const IndexType w = this -> mesh -> getElementNeighbour( centralVolume, -1, 0 ); - const IndexType n = this -> mesh -> getElementNeighbour( centralVolume, 0, 1 ); - const IndexType s = this -> mesh -> getElementNeighbour( centralVolume, 0, -1 ); + const IndexType e = this->mesh -> getElementNeighbour( centralVolume, 1, 0 ); + const IndexType w = this->mesh -> getElementNeighbour( centralVolume, -1, 0 ); + const IndexType n = this->mesh -> getElementNeighbour( centralVolume, 0, 1 ); + const IndexType s = this->mesh -> getElementNeighbour( centralVolume, 0, -1 ); const RealType u1_e = rho_u1[ e ] / regularize( rho[ e ] ); const RealType u1_w = rho_u1[ w ] / regularize( rho[ w ] ); @@ -177,7 +177,7 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureG * Get the central volume and its neighbours (east, north, west, south) coordinates */ CoordinatesType c_coordinates, e_coordinates, n_coordinates, w_coordinates, s_coordinates; - this -> mesh -> getElementCoordinates( c, c_coordinates ); + this->mesh -> getElementCoordinates( c, c_coordinates ); e_coordinates = n_coordinates = w_coordinates = s_coordinates = c_coordinates; e_coordinates. x() ++; w_coordinates. x() --; @@ -187,20 +187,20 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureG /**** * Get the volumes measure */ - const RealType mu_D_c = this -> mesh -> getElementMeasure( c_coordinates ); - const RealType mu_D_e = this -> mesh -> getElementMeasure( e_coordinates ); - const RealType mu_D_n = this -> mesh -> getElementMeasure( n_coordinates ); - const RealType mu_D_w = this -> mesh -> getElementMeasure( w_coordinates ); - const RealType mu_D_s = this -> mesh -> getElementMeasure( s_coordinates ); + const RealType mu_D_c = this->mesh -> getElementMeasure( c_coordinates ); + const RealType mu_D_e = this->mesh -> getElementMeasure( e_coordinates ); + const RealType mu_D_n = this->mesh -> getElementMeasure( n_coordinates ); + const RealType mu_D_w = this->mesh -> getElementMeasure( w_coordinates ); + const RealType mu_D_s = this->mesh -> getElementMeasure( s_coordinates ); /**** * Get the edge normals */ VertexType e_normal, w_normal, n_normal, s_normal; - this -> mesh -> template getEdgeNormal< 1, 0 >( c_coordinates, e_normal ); - this -> mesh -> template getEdgeNormal< -1, 0 >( c_coordinates, w_normal ); - this -> mesh -> template getEdgeNormal< 0, 1 >( c_coordinates, n_normal ); - this -> mesh -> template getEdgeNormal< 0, -1 >( c_coordinates, s_normal ); + this->mesh -> template getEdgeNormal< 1, 0 >( c_coordinates, e_normal ); + this->mesh -> template getEdgeNormal< -1, 0 >( c_coordinates, w_normal ); + this->mesh -> template getEdgeNormal< 0, 1 >( c_coordinates, n_normal ); + this->mesh -> template getEdgeNormal< 0, -1 >( c_coordinates, s_normal ); /**** * Compute the fluxes @@ -245,7 +245,7 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureG rho_f_n * n_normal. x() + rho_g_n * n_normal. y() + rho_f_w * w_normal. x() + rho_g_w * w_normal. y() + rho_f_s * s_normal. x() + rho_g_s * s_normal. y() ) - + this -> viscosityCoefficient * 1.0 / ( 8.0 * tau ) * mu_D_c * + + this->viscosityCoefficient * 1.0 / ( 8.0 * tau ) * mu_D_c * ( ( mu_D_c + mu_D_e ) * ( rho[ e ] - rho[ c ] ) + ( mu_D_c + mu_D_n ) * ( rho[ n ] - rho[ c ] ) + ( mu_D_c + mu_D_w ) * ( rho[ w ] - rho[ c ] ) + @@ -258,7 +258,7 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureG rho_u1_f_n * n_normal. x() + rho_u1_g_n * n_normal. y() + rho_u1_f_w * w_normal. x() + rho_u1_g_w * w_normal. y() + rho_u1_f_s * s_normal. x() + rho_u1_g_s * s_normal. y() ) - + this -> viscosityCoefficient * 1.0 / ( 8.0 * tau ) * mu_D_c * + + this->viscosityCoefficient * 1.0 / ( 8.0 * tau ) * mu_D_c * ( ( mu_D_c + mu_D_e ) * ( rho_u1[ e ] - rho_u1[ c ] ) + ( mu_D_c + mu_D_n ) * ( rho_u1[ n ] - rho_u1[ c ] ) + ( mu_D_c + mu_D_w ) * ( rho_u1[ w ] - rho_u1[ c ] ) + @@ -272,7 +272,7 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureG rho_u2_f_n * n_normal. x() + rho_u2_g_n * n_normal. y() + rho_u2_f_w * w_normal. x() + rho_u2_g_w * w_normal. y() + rho_u2_f_s * s_normal. x() + rho_u2_g_s * s_normal. y() ) - + this -> viscosityCoefficient * 1.0 / ( 8.0 * tau ) * mu_D_c * + + this->viscosityCoefficient * 1.0 / ( 8.0 * tau ) * mu_D_c * ( ( mu_D_c + mu_D_e ) * ( rho_u2[ e ] - rho_u2[ c ] ) + ( mu_D_c + mu_D_n ) * ( rho_u2[ n ] - rho_u2[ c ] ) + ( mu_D_c + mu_D_w ) * ( rho_u2[ w ] - rho_u2[ c ] ) + @@ -287,7 +287,7 @@ template< typename Real, template< int, typename, typename, typename > class GridGeometry > Real tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, GridGeometry >, PressureGradient > :: regularize( const Real& r ) const { - return r + ( ( r >= 0 ) - ( r < 0 ) ) * this -> regularizeEps; + return r + ( ( r >= 0 ) - ( r < 0 ) ) * this->regularizeEps; } /**** @@ -313,7 +313,7 @@ template< typename Real, typename PressureGradient > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry >, PressureGradient > :: bindMesh( const MeshType& mesh ) { - this -> mesh = &mesh; + this->mesh = &mesh; } template< typename Real, @@ -322,7 +322,7 @@ template< typename Real, typename PressureGradient > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry >, PressureGradient > :: setRegularization( const RealType& epsilon ) { - this -> regularizeEps = epsilon; + this->regularizeEps = epsilon; } template< typename Real, @@ -331,7 +331,7 @@ template< typename Real, typename PressureGradient > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry >, PressureGradient > :: setViscosityCoefficient( const RealType& v ) { - this -> viscosityCoefficient = v; + this->viscosityCoefficient = v; } template< typename Real, @@ -341,7 +341,7 @@ template< typename Real, template< typename Vector > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry >, PressureGradient > :: setRho( Vector& rho ) { - this -> rho. bind( rho ); + this->rho. bind( rho ); } template< typename Real, @@ -351,7 +351,7 @@ template< typename Real, template< typename Vector > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry >, PressureGradient > :: setRhoU1( Vector& rho_u1 ) { - this -> rho_u1. bind( rho_u1 ); + this->rho_u1. bind( rho_u1 ); } template< typename Real, @@ -361,7 +361,7 @@ template< typename Real, template< typename Vector > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry >, PressureGradient > :: setRhoU2( Vector& rho_u2 ) { - this -> rho_u2. bind( rho_u2 ); + this->rho_u2. bind( rho_u2 ); } template< typename Real, @@ -391,7 +391,7 @@ template< typename Real, template< typename Vector > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry >, PressureGradient > :: setPressureGradient( Vector& grad_p ) { - this -> pressureGradient = &grad_p; + this->pressureGradient = &grad_p; } template< typename Real, @@ -407,16 +407,16 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry tnlAssert( mesh, cerr << "No mesh has been binded with the Lax-Fridrichs scheme." ); tnlAssert( pressureGradient, cerr << "No pressure gradient was set in the the Lax-Fridrichs scheme." ) - const IndexType& xSize = this -> mesh -> getDimensions(). x(); - const IndexType& ySize = this -> mesh -> getDimensions(). y(); - const RealType hx = this -> mesh -> getParametricStep(). x(); - const RealType hy = this -> mesh -> getParametricStep(). y(); + const IndexType& xSize = this->mesh -> getDimensions(). x(); + const IndexType& ySize = this->mesh -> getDimensions(). y(); + const RealType hx = this->mesh -> getParametricStep(). x(); + const RealType hy = this->mesh -> getParametricStep(). y(); const IndexType& c = centralVolume; - const IndexType e = this -> mesh -> getElementNeighbour( centralVolume, 1, 0 ); - const IndexType w = this -> mesh -> getElementNeighbour( centralVolume, -1, 0 ); - const IndexType n = this -> mesh -> getElementNeighbour( centralVolume, 0, 1 ); - const IndexType s = this -> mesh -> getElementNeighbour( centralVolume, 0, -1 ); + const IndexType e = this->mesh -> getElementNeighbour( centralVolume, 1, 0 ); + const IndexType w = this->mesh -> getElementNeighbour( centralVolume, -1, 0 ); + const IndexType n = this->mesh -> getElementNeighbour( centralVolume, 0, 1 ); + const IndexType s = this->mesh -> getElementNeighbour( centralVolume, 0, -1 ); /**** * rho_t + ( rho u_1 )_x + ( rho u_2 )_y = 0 @@ -425,7 +425,7 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry const RealType u1_w = rho_u1[ w ] / regularize( rho[ w ] ); const RealType u2_n = rho_u2[ n ] / regularize( rho[ n ] ); const RealType u2_s = rho_u2[ s ] / regularize( rho[ s ] ); - rho_t = this -> viscosityCoefficient / tau * 0.25 * ( rho[ e ] + rho[ w ] + rho[ s ] + rho[ n ] - 4.0 * rho[ c ] ) + rho_t = this->viscosityCoefficient / tau * 0.25 * ( rho[ e ] + rho[ w ] + rho[ s ] + rho[ n ] - 4.0 * rho[ c ] ) - ( rho[ e ] * u1_e - rho[ w ] * u1_w ) / ( 2.0 * hx ) - ( rho[ n ] * u2_n - rho[ s ] * u2_s ) / ( 2.0 * hy ); @@ -438,14 +438,14 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry /**** * ( rho * u1 )_t + ( rho * u1 * u1 )_x + ( rho * u1 * u2 )_y - p_x = 0 */ - rho_u1_t = this -> viscosityCoefficient / tau * 0.25 * ( rho_u1[ e ] + rho_u1[ w ] + rho_u1[ s ] + rho_u1[ n ] - 4.0 * rho_u1[ c ] ) + rho_u1_t = this->viscosityCoefficient / tau * 0.25 * ( rho_u1[ e ] + rho_u1[ w ] + rho_u1[ s ] + rho_u1[ n ] - 4.0 * rho_u1[ c ] ) - ( rho_u1[ e ] * u1_e - rho_u1[ w ] * u1_w ) / ( 2.0 * hx ) - ( rho_u1[ n ] * u2_n - rho_u1[ s ] * u2_s ) / ( 2.0 * hy ) - grad_p. x(); /**** * ( rho * u2 )_t + ( rho * u2 * u1 )_x + ( rho * u2 * u2 )_y - p_y = 0 */ - rho_u2_t = this -> viscosityCoefficient / tau * 0.25 * ( rho_u2[ e ] + rho_u2[ w ] + rho_u2[ s ] + rho_u2[ n ] - 4.0 * rho_u2[ c ] ) + rho_u2_t = this->viscosityCoefficient / tau * 0.25 * ( rho_u2[ e ] + rho_u2[ w ] + rho_u2[ s ] + rho_u2[ n ] - 4.0 * rho_u2[ c ] ) - ( rho_u2[ e ] * u1_e - rho_u2[ w ] * u1_w ) / ( 2.0 * hx ) - ( rho_u2[ n ] * u2_n - rho_u2[ s ] * u2_s ) / ( 2.0 * hy ) - grad_p. y(); @@ -465,16 +465,16 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry tnlAssert( mesh, cerr << "No mesh has been binded with the Lax-Fridrichs scheme." ); tnlAssert( pressureGradient, cerr << "No pressure gradient was set in the the Lax-Fridrichs scheme." ) - const IndexType& xSize = this -> mesh -> getDimensions(). x(); - const IndexType& ySize = this -> mesh -> getDimensions(). y(); - const RealType hx = this -> mesh -> getParametricStep(). x(); - const RealType hy = this -> mesh -> getParametricStep(). y(); + const IndexType& xSize = this->mesh -> getDimensions(). x(); + const IndexType& ySize = this->mesh -> getDimensions(). y(); + const RealType hx = this->mesh -> getParametricStep(). x(); + const RealType hy = this->mesh -> getParametricStep(). y(); const IndexType& c = centralVolume; - const IndexType e = this -> mesh -> getElementNeighbour( centralVolume, 1, 0 ); - const IndexType w = this -> mesh -> getElementNeighbour( centralVolume, -1, 0 ); - const IndexType n = this -> mesh -> getElementNeighbour( centralVolume, 0, 1 ); - const IndexType s = this -> mesh -> getElementNeighbour( centralVolume, 0, -1 ); + const IndexType e = this->mesh -> getElementNeighbour( centralVolume, 1, 0 ); + const IndexType w = this->mesh -> getElementNeighbour( centralVolume, -1, 0 ); + const IndexType n = this->mesh -> getElementNeighbour( centralVolume, 0, 1 ); + const IndexType s = this->mesh -> getElementNeighbour( centralVolume, 0, -1 ); /**** * rho_t + ( rho u_1 )_x + ( rho u_2 )_y = 0 @@ -483,7 +483,7 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry const RealType u1_w = rho_u1[ w ] / regularize( rho[ w ] ); const RealType u2_n = rho_u2[ n ] / regularize( rho[ n ] ); const RealType u2_s = rho_u2[ s ] / regularize( rho[ s ] ); - rho_t = this -> viscosityCoefficient / tau * 0.25 * ( rho[ e ] + rho[ w ] + rho[ s ] + rho[ n ] - 4.0 * rho[ c ] ) + rho_t = this->viscosityCoefficient / tau * 0.25 * ( rho[ e ] + rho[ w ] + rho[ s ] + rho[ n ] - 4.0 * rho[ c ] ) - ( rho[ e ] * u1_e - rho[ w ] * u1_w ) / ( 2.0 * hx ) - ( rho[ n ] * u2_n - rho[ s ] * u2_s ) / ( 2.0 * hy ); @@ -496,14 +496,14 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry /**** * ( rho * u1 )_t + ( rho * u1 * u1 )_x + ( rho * u1 * u2 )_y - p_x = 0 */ - rho_u1_t = this -> viscosityCoefficient / tau * 0.25 * ( rho_u1[ e ] + rho_u1[ w ] + rho_u1[ s ] + rho_u1[ n ] - 4.0 * rho_u1[ c ] ) + rho_u1_t = this->viscosityCoefficient / tau * 0.25 * ( rho_u1[ e ] + rho_u1[ w ] + rho_u1[ s ] + rho_u1[ n ] - 4.0 * rho_u1[ c ] ) - ( rho_u1[ e ] * u1_e - rho_u1[ w ] * u1_w ) / ( 2.0 * hx ) - ( rho_u1[ n ] * u2_n - rho_u1[ s ] * u2_s ) / ( 2.0 * hy ) - grad_p. x(); /**** * ( rho * u2 )_t + ( rho * u2 * u1 )_x + ( rho * u2 * u2 )_y - p_y = 0 */ - rho_u2_t = this -> viscosityCoefficient / tau * 0.25 * ( rho_u2[ e ] + rho_u2[ w ] + rho_u2[ s ] + rho_u2[ n ] - 4.0 * rho_u2[ c ] ) + rho_u2_t = this->viscosityCoefficient / tau * 0.25 * ( rho_u2[ e ] + rho_u2[ w ] + rho_u2[ s ] + rho_u2[ n ] - 4.0 * rho_u2[ c ] ) - ( rho_u2[ e ] * u1_e - rho_u2[ w ] * u1_w ) / ( 2.0 * hx ) - ( rho_u2[ n ] * u2_n - rho_u2[ s ] * u2_s ) / ( 2.0 * hy ) - grad_p. y(); @@ -511,7 +511,7 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry /**** * e_t + ( ( e + p ) * u )_x + ( ( e + p ) * v )_y = 0 */ - e_t = this -> viscosityCoefficient / tau * 0.25 * ( energy[ e ] + energy[ w ] + energy[ s ] + energy[ n ] - 4.0 * energy[ c ] ) + e_t = this->viscosityCoefficient / tau * 0.25 * ( energy[ e ] + energy[ w ] + energy[ s ] + energy[ n ] - 4.0 * energy[ c ] ) - ( ( energy[ e ] + p[ e ] ) * u1_e - ( energy[ w ] + p[ w ] ) * u1_w ) / ( 2.0 * hx ) - ( ( energy[ n ] + p[ n ] ) * u2_n - ( energy[ s ] + p[ s ] ) * u2_s ) / ( 2.0 * hy ); } @@ -523,7 +523,7 @@ template< typename Real, typename PressureGradient > Real tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index, tnlIdenticalGridGeometry >, PressureGradient > :: regularize( const Real& r ) const { - return r + ( ( r >= 0 ) - ( r < 0 ) ) * this -> regularizeEps; + return r + ( ( r >= 0 ) - ( r < 0 ) ) * this->regularizeEps; } diff --git a/src/operators/geometric/tnlExactGradientNorm.h b/src/operators/geometric/tnlExactGradientNorm.h index 42af00e87e9d86fa80d3fdbc5fed18237c5a6df3..1b03c3cf12670d7a3826be7f70adc62908939a31 100644 --- a/src/operators/geometric/tnlExactGradientNorm.h +++ b/src/operators/geometric/tnlExactGradientNorm.h @@ -45,7 +45,7 @@ class tnlExactGradientNorm< 1, Real > tnlExactGradientNorm() : epsilonSquare( 0.0 ){}; - void setRegularization( const Real& epsilon ) + void setRegularizationEpsilon( const Real& epsilon ) { this->epsilonSquare = epsilon*epsilon; } @@ -113,7 +113,7 @@ class tnlExactGradientNorm< 2, Real > tnlExactGradientNorm() : epsilonSquare( 0.0 ){}; - void setRegularization( const Real& epsilon ) + void setRegularizationEpsilon( const Real& epsilon ) { this->epsilonSquare = epsilon*epsilon; } @@ -187,7 +187,7 @@ class tnlExactGradientNorm< 3, Real > tnlExactGradientNorm() : epsilonSquare( 0.0 ){}; - void setRegularization( const Real& epsilon ) + void setRegularizationEpsilon( const Real& epsilon ) { this->epsilonSquare = epsilon*epsilon; } diff --git a/src/operators/tnlDirichletBoundaryConditions.h b/src/operators/tnlDirichletBoundaryConditions.h index 01f55a1e8e6861f2db5d0a8f6458acbd70ee284b..b155bb7d964cd2d1c98bccb24470c79d69c6ecff 100644 --- a/src/operators/tnlDirichletBoundaryConditions.h +++ b/src/operators/tnlDirichletBoundaryConditions.h @@ -20,6 +20,7 @@ #include <operators/tnlOperator.h> #include <functions/tnlConstantFunction.h> +#include <functions/tnlFunctionAdapter.h> template< typename Mesh, typename Function = tnlConstantFunction< Mesh::getMeshDimensions(), typename Mesh::RealType >, @@ -36,57 +37,86 @@ class tnlDirichletBoundaryConditions { public: - typedef Mesh MeshType; - typedef Function FunctionType; - typedef Real RealType; - typedef typename MeshType::DeviceType DeviceType; - typedef Index IndexType; - - typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType; - typedef typename MeshType::VertexType VertexType; - - static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } + typedef Mesh MeshType; + typedef Function FunctionType; + typedef Real RealType; + typedef typename MeshType::DeviceType DeviceType; + typedef Index IndexType; - static void configSetup( tnlConfigDescription& config, - const tnlString& prefix = "" ); + typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType; + typedef typename MeshType::VertexType VertexType; - bool setup( const tnlParameterContainer& parameters, - const tnlString& prefix = "" ); + static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } - void setFunction( const Function& function ); - - Function& getFunction(); + static void configSetup( tnlConfigDescription& config, + const tnlString& prefix = "" ) + { + Function::configSetup( config, prefix ); + } + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ) + { + return this->function.setup( parameters, prefix ); + } - const Function& getFunction() const; - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const; + void setFunction( const Function& function ) + { + this->function = function; + } + + Function& getFunction() + { + return this->function; + } + + const Function& getFunction() const + { + return this->function; + } + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); + return tnlFunctionAdapter< MeshType, Function >::template getValue( this->function, entity, time ); + } + + template< typename EntityType > + __cuda_callable__ + IndexType getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 1; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + typename Matrix::MatrixRow matrixRow = matrix.getRow( entity.getIndex() ); + const IndexType& index = entity.getIndex(); + matrixRow.setElement( 0, index, 1.0 ); + b[ index ] = tnlFunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); + } - template< typename EntityType > - __cuda_callable__ - IndexType getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const; - - template< typename MatrixRow, - typename EntityType, - typename MeshFunction > - __cuda_callable__ - void updateLinearSystem( const RealType& time, - const MeshType& mesh, - const IndexType& index, - const EntityType& entity, - const MeshFunction& u, - DofVectorType& b, - MatrixRow& matrixRow ) const; protected: - Function function; + Function function; //static_assert( Device::DeviceType == Function::Device::DeviceType ); }; @@ -99,6 +129,4 @@ ostream& operator << ( ostream& str, const tnlDirichletBoundaryConditions< Mesh, return str; } -#include <operators/tnlDirichletBoundaryConditions_impl.h> - #endif /* TNLDIRICHLETBOUNDARYCONDITIONS_H_ */ diff --git a/src/operators/tnlDirichletBoundaryConditions_impl.h b/src/operators/tnlDirichletBoundaryConditions_impl.h deleted file mode 100644 index f78db6237a04fe3ac07afa66497c15237dc9a947..0000000000000000000000000000000000000000 --- a/src/operators/tnlDirichletBoundaryConditions_impl.h +++ /dev/null @@ -1,144 +0,0 @@ -/*************************************************************************** - tnlDirichletBoundaryConditions_impl.h - description - ------------------- - begin : Nov 17, 2014 - copyright : (C) 2014 by oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -#ifndef TNLDIRICHLETBOUNDARYCONDITIONS_IMPL_H_ -#define TNLDIRICHLETBOUNDARYCONDITIONS_IMPL_H_ - -#include <functions/tnlFunctionAdapter.h> - -template< typename Mesh, - typename Function, - int MeshEntitiesDimensions, - typename Real, - typename Index > -void -tnlDirichletBoundaryConditions< Mesh, Function, MeshEntitiesDimensions, Real, Index >:: -configSetup( tnlConfigDescription& config, - const tnlString& prefix ) -{ - Function::configSetup( config, prefix ); -} - -template< typename Mesh, - typename Function, - int MeshEntitiesDimensions, - typename Real, - typename Index > -bool -tnlDirichletBoundaryConditions< Mesh, Function, MeshEntitiesDimensions, Real, Index >:: -setup( const tnlParameterContainer& parameters, - const tnlString& prefix ) -{ - return this->function.setup( parameters, prefix ); -} - -template< typename Mesh, - typename Function, - int MeshEntitiesDimensions, - typename Real, - typename Index > -void -tnlDirichletBoundaryConditions< Mesh, Function, MeshEntitiesDimensions, Real, Index >:: -setFunction( const Function& function ) -{ - this->function = function; -} - -template< typename Mesh, - typename Function, - int MeshEntitiesDimensions, - typename Real, - typename Index > -Function& -tnlDirichletBoundaryConditions< Mesh, Function, MeshEntitiesDimensions, Real, Index >:: -getFunction() -{ - return this->function; -} - -template< typename Mesh, - typename Function, - int MeshEntitiesDimensions, - typename Real, - typename Index > -const Function& -tnlDirichletBoundaryConditions< Mesh, Function, MeshEntitiesDimensions, Real, Index >:: -getFunction() const -{ - return *this->function; -} - - -template< typename Mesh, - typename Function, - int MeshEntitiesDimensions, - typename Real, - typename Index > -template< typename EntityType, - typename MeshFunction > -__cuda_callable__ -const Real -tnlDirichletBoundaryConditions< Mesh, Function, MeshEntitiesDimensions, Real, Index >:: -operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time ) const -{ - //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); - return tnlFunctionAdapter< MeshType, Function >::template getValue( this->function, entity, time ); -} - -template< typename Mesh, - typename Function, - int MeshEntitiesDimensions, - typename Real, - typename Index > - template< typename EntityType > -__cuda_callable__ -Index -tnlDirichletBoundaryConditions< Mesh, Function, MeshEntitiesDimensions, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const -{ - return 1; -} - -template< typename Mesh, - typename Function, - int MeshEntitiesDimensions, - typename Real, - typename Index > - template< typename Matrix, - typename EntityType, - typename MeshFunction > -__cuda_callable__ -void -tnlDirichletBoundaryConditions< Mesh, Function, MeshEntitiesDimensions, Real, Index >:: -updateLinearSystem( const RealType& time, - const MeshType& mesh, - const IndexType& index, - const EntityType& entity, - const MeshFunction& u, - DofVectorType& b, - Matrix& matrix ) const -{ - typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); - matrixRow.setElement( 0, index, 1.0 ); - b[ index ] = tnlFunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); -} - -#endif /* TNLDIRICHLETBOUNDARYCONDITIONS_IMPL_H_ */ diff --git a/src/operators/tnlNeumannBoundaryConditions.h b/src/operators/tnlNeumannBoundaryConditions.h index 06e109e36e6082bb8a9a4f452c52adfedaa9f7d6..dabef95f9893e768b75ac842b74a63f402d30be2 100644 --- a/src/operators/tnlNeumannBoundaryConditions.h +++ b/src/operators/tnlNeumannBoundaryConditions.h @@ -1,6 +1,8 @@ #ifndef TNLNEUMANNBOUNDARYCONDITIONS_H #define TNLNEUMANNBOUNDARYCONDITIONS_H +#include <functions/tnlFunctionAdapter.h> + template< typename Mesh, typename Function, typename Real = typename Mesh::RealType, @@ -49,7 +51,11 @@ template< typename MeshReal, typename Index > class tnlNeumannBoundaryConditions< tnlGrid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > : public tnlNeumannBoundaryConditionsBase< Function >, - public tnlDomain< 1, MeshBoundaryDomain > + public tnlOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, + MeshBoundaryDomain, + 1, 1, + Real, + Index > { public: @@ -62,32 +68,68 @@ class tnlNeumannBoundaryConditions< tnlGrid< 1, MeshReal, Device, MeshIndex >, F typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType; typedef tnlStaticVector< 1, RealType > VertexType; typedef typename MeshType::CoordinatesType CoordinatesType; + typedef tnlNeumannBoundaryConditions< MeshType, Function, Real, Index > ThisType; + typedef tnlNeumannBoundaryConditionsBase< Function > BaseType; template< typename EntityType, typename MeshFunction > __cuda_callable__ const RealType operator()( const MeshFunction& u, const EntityType& entity, - const RealType& time = 0 ) const; + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighbourEntities = entity.getNeighbourEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + return u[ neighbourEntities.template getEntityIndex< 1 >() ] - entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + else + return u[ neighbourEntities.template getEntityIndex< -1 >() ] + entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + + } template< typename EntityType > __cuda_callable__ Index getLinearSystemRowLength( const MeshType& mesh, const IndexType& index, - const EntityType& entity ) const; - - template< typename MatrixRow, - typename EntityType, - typename MeshFunction > - __cuda_callable__ - void updateLinearSystem( const RealType& time, - const MeshType& mesh, - const IndexType& index, - const EntityType& entity, - const MeshFunction& u, - DofVectorType& b, - MatrixRow& matrixRow ) const; + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighbourEntities = entity.getNeighbourEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighbourEntities.template getEntityIndex< 1 >(), -1.0 ); + b[ index ] = - entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + else + { + matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } }; /**** @@ -101,44 +143,113 @@ template< typename MeshReal, typename Index > class tnlNeumannBoundaryConditions< tnlGrid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > : public tnlNeumannBoundaryConditionsBase< Function >, - public tnlDomain< 2, MeshBoundaryDomain > + public tnlOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, + MeshBoundaryDomain, + 2, 2, + Real, + Index > + { public: - typedef tnlGrid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - - typedef Function FunctionType; - typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType; - typedef tnlStaticVector< 2, RealType > VertexType; - typedef typename MeshType::CoordinatesType CoordinatesType; - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const; - - template< typename EntityType > - __cuda_callable__ - Index getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const; + typedef tnlGrid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; - template< typename MatrixRow, - typename EntityType, - typename MeshFunction > - __cuda_callable__ - void updateLinearSystem( const RealType& time, - const MeshType& mesh, - const IndexType& index, - const EntityType& entity, - const MeshFunction& u, - DofVectorType& b, - MatrixRow& matrixRow ) const; + typedef Function FunctionType; + typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType; + typedef tnlStaticVector< 2, RealType > VertexType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef tnlNeumannBoundaryConditions< MeshType, Function, Real, Index > ThisType; + typedef tnlNeumannBoundaryConditionsBase< Function > BaseType; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighbourEntities = entity.getNeighbourEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighbourEntities.template getEntityIndex< 1, 0 >() ] - entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighbourEntities.template getEntityIndex< -1, 0 >() ] + entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighbourEntities.template getEntityIndex< 0, 1 >() ] - entity.getMesh().getSpaceSteps().y() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighbourEntities.template getEntityIndex< 0, -1 >() ] + entity.getMesh().getSpaceSteps().y() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighbourEntities = entity.getNeighbourEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighbourEntities.template getEntityIndex< 1, 0 >(), -1.0 ); + b[ index ] = - entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighbourEntities.template getEntityIndex< 0, 1 >(), -1.0 ); + b[ index ] = - entity.getMesh().getSpaceSteps().y() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } }; /**** @@ -152,45 +263,136 @@ template< typename MeshReal, typename Index > class tnlNeumannBoundaryConditions< tnlGrid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > : public tnlNeumannBoundaryConditionsBase< Function >, - public tnlDomain< 3, MeshBoundaryDomain > + public tnlOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, + MeshBoundaryDomain, + 3, 3, + Real, + Index > { public: - typedef tnlGrid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - - typedef Function FunctionType; - typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType; - typedef tnlStaticVector< 3, RealType > VertexType; - typedef typename MeshType::CoordinatesType CoordinatesType; + typedef tnlGrid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const; - - - template< typename EntityType > - __cuda_callable__ - Index getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const; - - template< typename MatrixRow, - typename EntityType, - typename MeshFunction > - __cuda_callable__ - void updateLinearSystem( const RealType& time, - const MeshType& mesh, - const IndexType& index, - const EntityType& entity, - const MeshFunction& u, - DofVectorType& b, - MatrixRow& matrixRow ) const; + typedef Function FunctionType; + typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType; + typedef tnlStaticVector< 3, RealType > VertexType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef tnlNeumannBoundaryConditions< MeshType, Function, Real, Index > ThisType; + typedef tnlNeumannBoundaryConditionsBase< Function > BaseType; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighbourEntities = entity.getNeighbourEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighbourEntities.template getEntityIndex< 1, 0, 0 >() ] - entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighbourEntities.template getEntityIndex< -1, 0, 0 >() ] + entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighbourEntities.template getEntityIndex< 0, 1, 0 >() ] - entity.getMesh().getSpaceSteps().y() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighbourEntities.template getEntityIndex< 0, -1, 0 >() ] + entity.getMesh().getSpaceSteps().y() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + return u[ neighbourEntities.template getEntityIndex< 0, 0, 1 >() ] - entity.getMesh().getSpaceSteps().z() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + return u[ neighbourEntities.template getEntityIndex< 0, 0, -1 >() ] + entity.getMesh().getSpaceSteps().z() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighbourEntities = entity.getNeighbourEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighbourEntities.template getEntityIndex< 1, 0, 0 >(), -1.0 ); + b[ index ] = - entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< -1, 0, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighbourEntities.template getEntityIndex< 0, 1, 0 >(), -1.0 ); + b[ index ] = - entity.getMesh().getSpaceSteps().y() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< 0, -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighbourEntities.template getEntityIndex< 0, 0, 1 >(), -1.0 ); + b[ index ] = - entity.getMesh().getSpaceSteps().z() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< 0, 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } }; template< typename Mesh, diff --git a/src/operators/tnlNeumannBoundaryConditions_impl.h b/src/operators/tnlNeumannBoundaryConditions_impl.h index adb01b87ee245a2978f2a230a11db09081103261..a9c39d0722183b4d0262e584bf35b8afd2611af4 100644 --- a/src/operators/tnlNeumannBoundaryConditions_impl.h +++ b/src/operators/tnlNeumannBoundaryConditions_impl.h @@ -49,7 +49,7 @@ getFunction() const /**** * 1D grid */ - +/* template< typename MeshReal, typename Device, typename MeshIndex, @@ -106,7 +106,7 @@ template< typename MeshReal, __cuda_callable__ void tnlNeumannBoundaryConditions< tnlGrid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const MeshType& mesh, const IndexType& index, const EntityType& entity, @@ -130,11 +130,12 @@ updateLinearSystem( const RealType& time, b[ index ] = mesh.getSpaceSteps().x() * tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); } -} +}*/ /**** * 2D grid */ +/* template< typename MeshReal, typename Device, typename MeshIndex, @@ -204,7 +205,7 @@ template< typename MeshReal, __cuda_callable__ void tnlNeumannBoundaryConditions< tnlGrid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const MeshType& mesh, const IndexType& index, const EntityType& entity, @@ -242,11 +243,12 @@ updateLinearSystem( const RealType& time, b[ index ] = mesh.getSpaceSteps().y() * tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); } -} +}*/ /**** * 3D grid */ +/* template< typename MeshReal, typename Device, typename MeshIndex, @@ -326,7 +328,7 @@ template< typename MeshReal, __cuda_callable__ void tnlNeumannBoundaryConditions< tnlGrid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const MeshType& mesh, const IndexType& index, const EntityType& entity, @@ -379,6 +381,7 @@ updateLinearSystem( const RealType& time, tnlFunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); } } +*/ #endif /* TNLNEUMANNBOUNDARYCONDITIONS_IMPL_H */ diff --git a/src/problems/tnlHeatEquationProblem.h b/src/problems/tnlHeatEquationProblem.h index 704f25ca27fc749d388cb2d50495d576e64b0d57..c47cf4072376d4ae668670994f0c4e851ccc7341 100644 --- a/src/problems/tnlHeatEquationProblem.h +++ b/src/problems/tnlHeatEquationProblem.h @@ -29,6 +29,7 @@ #include <operators/diffusion/tnlLinearDiffusion.h> #include <matrices/tnlEllpackMatrix.h> #include <functions/tnlMeshFunction.h> +#include <core/tnlTimer.h> template< typename Mesh, typename BoundaryCondition, @@ -59,6 +60,9 @@ class tnlHeatEquationProblem : public tnlPDEProblem< Mesh, void writeProlog( tnlLogger& logger, const tnlParameterContainer& parameters ) const; + + bool writeEpilog( tnlLogger& logger ); + bool setup( const tnlParameterContainer& parameters ); @@ -108,6 +112,8 @@ class tnlHeatEquationProblem : public tnlPDEProblem< Mesh, BoundaryCondition boundaryCondition; RightHandSide rightHandSide; + + tnlTimer gpuTransferTimer; }; #include <problems/tnlHeatEquationProblem_impl.h> diff --git a/src/problems/tnlHeatEquationProblem_impl.h b/src/problems/tnlHeatEquationProblem_impl.h index ce68ff2b4cf1b40846cff2931af31f4aa38fbdc5..11f1f8569ed90539d3d5c2f8378c37d92470b97c 100644 --- a/src/problems/tnlHeatEquationProblem_impl.h +++ b/src/problems/tnlHeatEquationProblem_impl.h @@ -68,6 +68,19 @@ writeProlog( tnlLogger& logger, const tnlParameterContainer& parameters ) const { } +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +bool +tnlHeatEquationProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +writeEpilog( tnlLogger& logger ) +{ + logger.writeParameter< const char* >( "GPU transfer time:", "" ); + this->gpuTransferTimer.writeLog( logger, 1 ); + return true; +} + template< typename Mesh, typename BoundaryCondition, typename RightHandSide, @@ -76,6 +89,7 @@ bool tnlHeatEquationProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: setup( const tnlParameterContainer& parameters ) { + this->gpuTransferTimer.reset(); if( ! this->boundaryCondition.setup( parameters, "boundary-conditions-" ) || ! this->rightHandSide.setup( parameters, "right-hand-side-" ) ) return false; @@ -207,6 +221,7 @@ getExplicitRHS( const RealType& time, this->bindDofs( mesh, uDofs ); MeshFunctionType fu( mesh, fuDofs ); tnlExplicitUpdater< Mesh, MeshFunctionType, DifferentialOperator, BoundaryCondition, RightHandSide > explicitUpdater; + explicitUpdater.setGPUTransferTimer( this->gpuTransferTimer ); explicitUpdater.template update< typename Mesh::Cell >( time, mesh, diff --git a/src/problems/tnlPDEProblem.h b/src/problems/tnlPDEProblem.h index 7be3d7f0a161a2c0a7295961c73c4d94bad6bb16..480ce0dfd71cb19d951e3a3ab256cd6c2defa530 100644 --- a/src/problems/tnlPDEProblem.h +++ b/src/problems/tnlPDEProblem.h @@ -50,6 +50,9 @@ class tnlPDEProblem : public tnlProblem< Real, Device, Index > void writeProlog( tnlLogger& logger, const tnlParameterContainer& parameters ) const; + + bool writeEpilog( tnlLogger& logger ) const; + bool setMeshDependentData( const MeshType& mesh, MeshDependentDataType& meshDependentData ); diff --git a/src/problems/tnlPDEProblem_impl.h b/src/problems/tnlPDEProblem_impl.h index 9954e2b1f4294c348fd4f197f7e3dfb6e08f273d..0b8cbf4f66a7e537f9ed6f102c0c9dd8348583ef 100644 --- a/src/problems/tnlPDEProblem_impl.h +++ b/src/problems/tnlPDEProblem_impl.h @@ -54,6 +54,18 @@ writeProlog( tnlLogger& logger, const tnlParameterContainer& parameters ) const { } +template< typename Mesh, + typename Real, + typename Device, + typename Index > +bool +tnlPDEProblem< Mesh, Real, Device, Index >:: +writeEpilog( tnlLogger& logger ) const +{ + return true; +} + + template< typename Mesh, typename Real, typename Device, diff --git a/src/solvers/cfd/navier-stokes/tnlNavierStokesSolver_impl.h b/src/solvers/cfd/navier-stokes/tnlNavierStokesSolver_impl.h index 085eadf14febf6d65334361dbd2d5b16693c51f9..09021f4d2beccdb396464c41525623d3ea135576 100644 --- a/src/solvers/cfd/navier-stokes/tnlNavierStokesSolver_impl.h +++ b/src/solvers/cfd/navier-stokes/tnlNavierStokesSolver_impl.h @@ -323,7 +323,7 @@ void tnlNavierStokesSolver< AdvectionScheme, const IndexType size = dofs_rho.getSize(); #ifdef HAVE_OPENMP - #pragma omp parallel for + #pragma omp parallel for, if( tnlHost::isOMPEnabled() ) #endif for( IndexType c = 0; c < size; c++ ) { @@ -331,7 +331,7 @@ void tnlNavierStokesSolver< AdvectionScheme, const RealType u1 = this->u1[ c ] = dofs_rho_u1[ c ] / dofs_rho[ c ]; const RealType u2 = this->u2[ c ] = dofs_rho_u2[ c ] / dofs_rho[ c ]; this->u[ c ] = sqrt( u1*u1 + u2*u2 ); - //this->p[ c ] = dofs_rho[ c ] * this -> R * this -> T; + //this->p[ c ] = dofs_rho[ c ] * this->R * this->T; this->p[ c ] = ( this->gamma - 1.0 ) * ( dofs_e[ c ] - 0.5 * this->rho[ c ] * ( this->u1[ c ] * this->u1[ c ] + this->u2[ c ] * this->u2[ c ] ) ); this->energy[ c ] = dofs_e[ c ]; @@ -447,7 +447,7 @@ void tnlNavierStokesSolver< AdvectionScheme, writePhysicalVariables( time, -4 ); #ifdef HAVE_OPENMP - #pragma omp parallel for + #pragma omp parallel for, if( tnlHost::isOMPEnabled() ) #endif for( IndexType j = 0; j < ySize; j ++ ) for( IndexType i = 0; i < xSize; i ++ ) @@ -468,7 +468,7 @@ void tnlNavierStokesSolver< AdvectionScheme, tau ); //rho_u1_t[ c ] += ; - //rho_u2_t[ c ] -= startUpCoefficient * this -> gravity * this -> rho[ c ]; + //rho_u2_t[ c ] -= startUpCoefficient * this->gravity * this->rho[ c ]; /*** * Add the viscosity term diff --git a/src/solvers/linear/krylov/tnlBICGStabSolver_impl.h b/src/solvers/linear/krylov/tnlBICGStabSolver_impl.h index 8532424ef49bdc2633f91e3aa36cd39cdc8f9177..d38b0519c35549c379a645091cc2396dedea0ebd 100644 --- a/src/solvers/linear/krylov/tnlBICGStabSolver_impl.h +++ b/src/solvers/linear/krylov/tnlBICGStabSolver_impl.h @@ -39,8 +39,8 @@ template< typename Matrix, tnlString tnlBICGStabSolver< Matrix, Preconditioner > :: getType() const { return tnlString( "tnlBICGStabSolver< " ) + - this -> matrix -> getType() + ", " + - this -> preconditioner -> getType() + " >"; + this->matrix -> getType() + ", " + + this->preconditioner -> getType() + " >"; } template< typename Matrix, @@ -67,14 +67,14 @@ template< typename Matrix, typename Preconditioner > void tnlBICGStabSolver< Matrix, Preconditioner > :: setMatrix( const MatrixType& matrix ) { - this -> matrix = &matrix; + this->matrix = &matrix; } template< typename Matrix, typename Preconditioner > void tnlBICGStabSolver< Matrix, Preconditioner > :: setPreconditioner( const Preconditioner& preconditioner ) { - this -> preconditioner = &preconditioner; + this->preconditioner = &preconditioner; } template< typename Matrix, @@ -85,15 +85,15 @@ bool tnlBICGStabSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vect dbgFunctionName( "tnlBICGStabSolver", "Solve" ); if( ! this->setSize( matrix->getRows() ) ) return false; - this -> resetIterations(); - this -> setResidue( this -> getConvergenceResidue() + 1.0 ); + this->resetIterations(); + this->setResidue( this->getConvergenceResidue() + 1.0 ); RealType alpha, beta, omega, s1, s2, rho( 0.0 ), bNorm( 0.0 ); // r_0 = b - A x_0, p_0 = r_0 // r^ast_0 = r_0 dbgCout( "Computing Ax" ); - this -> matrix -> vectorProduct( x, r ); + this->matrix -> vectorProduct( x, r ); //if( bNorm == 0.0 ) bNorm = 1.0; @@ -132,7 +132,7 @@ bool tnlBICGStabSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vect M -> Solve( M_tmp, Ap ); } else*/ - this -> matrix -> vectorProduct( p, Ap ); + this->matrix -> vectorProduct( p, Ap ); //dbgCout( "Computing alpha" ); s2 = Ap. scalarProduct( r_ast ); @@ -154,7 +154,7 @@ bool tnlBICGStabSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vect M -> Solve( M_tmp, As ); } else*/ - this -> matrix -> vectorProduct( s, As ); + this->matrix -> vectorProduct( s, As ); s1 = As. scalarProduct( s ); s2 = As. scalarProduct( As ); diff --git a/src/solvers/linear/krylov/tnlCGSolver_impl.h b/src/solvers/linear/krylov/tnlCGSolver_impl.h index 86bea9efd293ee7a9db34950d983bfbf70343f42..e6ad7b74312d3246347fb10a01f59b4e78c6d9e4 100644 --- a/src/solvers/linear/krylov/tnlCGSolver_impl.h +++ b/src/solvers/linear/krylov/tnlCGSolver_impl.h @@ -29,8 +29,8 @@ template< typename Matrix, tnlString tnlCGSolver< Matrix, Preconditioner > :: getType() const { return tnlString( "tnlCGSolver< " ) + - this -> matrix -> getType() + ", " + - this -> preconditioner -> getType() + " >"; + this->matrix -> getType() + ", " + + this->preconditioner -> getType() + " >"; } template< typename Matrix, @@ -57,14 +57,14 @@ template< typename Matrix, typename Preconditioner > void tnlCGSolver< Matrix, Preconditioner > :: setMatrix( const MatrixType& matrix ) { - this -> matrix = &matrix; + this->matrix = &matrix; } template< typename Matrix, typename Preconditioner > void tnlCGSolver< Matrix, Preconditioner > :: setPreconditioner( const Preconditioner& preconditioner ) { - this -> preconditioner = &preconditioner; + this->preconditioner = &preconditioner; } template< typename Matrix, @@ -138,11 +138,11 @@ solve( const Vector& b, Vector& x ) */ new_r.swap( r ); - if( this -> getIterations() % 10 == 0 ) - this -> setResidue( ResidueGetter :: getResidue( *matrix, b, x, bNorm ) ); + if( this->getIterations() % 10 == 0 ) + this->setResidue( ResidueGetter :: getResidue( *matrix, b, x, bNorm ) ); } - this -> setResidue( ResidueGetter :: getResidue( *matrix, b, x, bNorm ) ); - this -> refreshSolverMonitor( true ); + this->setResidue( ResidueGetter :: getResidue( *matrix, b, x, bNorm ) ); + this->refreshSolverMonitor( true ); return this->checkConvergence(); }; diff --git a/src/solvers/linear/krylov/tnlTFQMRSolver.h b/src/solvers/linear/krylov/tnlTFQMRSolver.h index ab25f3e349e752bdac403a2323fada4fe34aa30e..32d250f52a18ecf23f961dabc04b1c5a0b89e1e4 100644 --- a/src/solvers/linear/krylov/tnlTFQMRSolver.h +++ b/src/solvers/linear/krylov/tnlTFQMRSolver.h @@ -75,7 +75,9 @@ class tnlTFQMRSolver : public tnlObject, bool setSize( IndexType size ); - tnlVector< RealType, Device, IndexType > d, r, w, u, v, r_ast, Au; + tnlVector< RealType, Device, IndexType > d, r, w, u, v, r_ast, Au, M_tmp; + + IndexType size; const MatrixType* matrix; const PreconditionerType* preconditioner; diff --git a/src/solvers/linear/krylov/tnlTFQMRSolver_impl.h b/src/solvers/linear/krylov/tnlTFQMRSolver_impl.h index b5e72e6456d4fdb968d3d611d4b97985f87a51df..72dd40e313478ca3e6dcb53a8bd76fa93fb9f2ed 100644 --- a/src/solvers/linear/krylov/tnlTFQMRSolver_impl.h +++ b/src/solvers/linear/krylov/tnlTFQMRSolver_impl.h @@ -18,17 +18,12 @@ #ifndef tnlTFQMRSolver_implH #define tnlTFQMRSolver_implH -template< typename RealType, - typename Vector > -RealType computeTFQMRNewP( Vector& p, - const Vector&r, - const RealType& beta, - const RealType& omega, - const Vector& Ap ); - template< typename Matrix, typename Preconditioner > tnlTFQMRSolver< Matrix, Preconditioner > :: tnlTFQMRSolver() +: size( 0 ), + matrix( 0 ), + preconditioner( 0 ) { } @@ -65,14 +60,14 @@ template< typename Matrix, typename Preconditioner > void tnlTFQMRSolver< Matrix, Preconditioner > :: setMatrix( const MatrixType& matrix ) { - this -> matrix = &matrix; + this->matrix = &matrix; } template< typename Matrix, typename Preconditioner > void tnlTFQMRSolver< Matrix, Preconditioner > :: setPreconditioner( const Preconditioner& preconditioner ) { - this -> preconditioner = &preconditioner; + this->preconditioner = &preconditioner; } template< typename Matrix, @@ -81,17 +76,31 @@ template< typename Matrix, bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector& x ) { dbgFunctionName( "tnlTFQMRSolver", "Solve" ); - if( ! this -> setSize( matrix -> getRows() ) ) return false; + if( ! this->setSize( matrix -> getRows() ) ) return false; - RealType tau, theta, eta, rho, alpha, w_norm; - RealType b_norm = b. lpNorm( 2.0 ); - if( b_norm == 0.0 ) - b_norm = 1.0; + RealType tau, theta, eta, rho, alpha, b_norm, w_norm; - this -> matrix -> vectorProduct( x, r ); - r. addVector( b, 1.0, -1.0 ); + if( preconditioner ) { + preconditioner -> solve( b, M_tmp ); + b_norm = M_tmp. lpNorm( ( RealType ) 2.0 ); + + matrix -> vectorProduct( x, M_tmp ); + M_tmp.addVector( b, 1.0, -1.0 ); + preconditioner -> solve( M_tmp, r ); + } + else { + b_norm = b. lpNorm( 2.0 ); + matrix -> vectorProduct( x, r ); + r.addVector( b, 1.0, -1.0 ); + } w = u = r; - matrix -> vectorProduct( u, Au ); + if( preconditioner ) { + matrix -> vectorProduct( u, M_tmp ); + preconditioner -> solve( M_tmp, Au ); + } + else { + matrix -> vectorProduct( u, Au ); + } v = Au; d. setValue( 0.0 ); tau = r. lpNorm( 2.0 ); @@ -101,6 +110,9 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector& // only to avoid compiler warning; alpha is initialized inside the loop alpha = 0.0; + if( b_norm == 0.0 ) + b_norm = 1.0; + this->resetIterations(); this->setResidue( tau / b_norm ); @@ -109,12 +121,18 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector& const IndexType iter = this->getIterations(); if( iter % 2 == 1 ) { - alpha = rho / v. scalarProduct( this -> r_ast ); + alpha = rho / v. scalarProduct( this->r_ast ); } else { // not necessary in odd iter since the previous iteration // already computed v_{m+1} = A*u_{m+1} - matrix -> vectorProduct( u, Au ); + if( preconditioner ) { + matrix -> vectorProduct( u, M_tmp ); + preconditioner -> solve( M_tmp, Au ); + } + else { + matrix -> vectorProduct( u, Au ); + } } w.addVector( Au, -alpha ); d.addVector( u, 1.0, theta * theta * eta / alpha ); @@ -131,20 +149,26 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector& } if( iter % 2 == 0 ) { - const RealType rho_new = w. scalarProduct( this -> r_ast ); + const RealType rho_new = w. scalarProduct( this->r_ast ); const RealType beta = rho_new / rho; rho = rho_new; u.addVector( w, 1.0, beta ); v.addVector( Au, beta, beta * beta ); - matrix -> vectorProduct( u, Au ); + if( preconditioner ) { + matrix -> vectorProduct( u, M_tmp ); + preconditioner -> solve( M_tmp, Au ); + } + else { + matrix -> vectorProduct( u, Au ); + } v.addVector( Au, 1.0 ); } else { u.addVector( v, -alpha ); } - this -> refreshSolverMonitor(); + this->refreshSolverMonitor(); } // this->matrix->vectorProduct( x, r ); @@ -165,13 +189,17 @@ template< typename Matrix, typename Preconditioner > bool tnlTFQMRSolver< Matrix, Preconditioner > :: setSize( IndexType size ) { + if( this->size == size ) + return true; + this->size = size; if( ! d. setSize( size ) || ! r. setSize( size ) || ! w. setSize( size ) || ! u. setSize( size ) || ! v. setSize( size ) || ! r_ast. setSize( size ) || - ! Au. setSize( size ) ) + ! Au. setSize( size ) || + ! M_tmp. setSize( size ) ) { cerr << "I am not able to allocate all supporting vectors for the TFQMR solver." << endl; return false; diff --git a/src/solvers/linear/stationary/tnlSORSolver_impl.h b/src/solvers/linear/stationary/tnlSORSolver_impl.h index 273bf9e81a3165525d851e641182e28e605cc4a2..ca8df5aa0134f2984ef2dbf06c631ef739a54ddb 100644 --- a/src/solvers/linear/stationary/tnlSORSolver_impl.h +++ b/src/solvers/linear/stationary/tnlSORSolver_impl.h @@ -28,8 +28,8 @@ template< typename Matrix, typename Preconditioner > tnlString tnlSORSolver< Matrix, Preconditioner > :: getType() const { return tnlString( "tnlSORSolver< " ) + - this -> matrix -> getType() + ", " + - this -> preconditioner -> getType() + " >"; + this->matrix -> getType() + ", " + + this->preconditioner -> getType() + " >"; } template< typename Matrix, @@ -63,27 +63,27 @@ setup( const tnlParameterContainer& parameters, template< typename Matrix, typename Preconditioner > void tnlSORSolver< Matrix, Preconditioner > :: setOmega( const RealType& omega ) { - this -> omega = omega; + this->omega = omega; } template< typename Matrix, typename Preconditioner > const typename tnlSORSolver< Matrix, Preconditioner > :: RealType& tnlSORSolver< Matrix, Preconditioner > :: getOmega( ) const { - return this -> omega; + return this->omega; } template< typename Matrix, typename Preconditioner > void tnlSORSolver< Matrix, Preconditioner > :: setMatrix( const MatrixType& matrix ) { - this -> matrix = &matrix; + this->matrix = &matrix; } template< typename Matrix, typename Preconditioner > void tnlSORSolver< Matrix, Preconditioner > :: setPreconditioner( const Preconditioner& preconditioner ) { - this -> preconditioner = &preconditioner; + this->preconditioner = &preconditioner; } @@ -94,8 +94,8 @@ bool tnlSORSolver< Matrix, Preconditioner > :: solve( const Vector& b, { const IndexType size = matrix -> getRows(); - this -> resetIterations(); - this -> setResidue( this -> getConvergenceResidue() + 1.0 ); + this->resetIterations(); + this->setResidue( this->getConvergenceResidue() + 1.0 ); RealType bNorm = b. lpNorm( ( RealType ) 2.0 ); @@ -106,11 +106,11 @@ bool tnlSORSolver< Matrix, Preconditioner > :: solve( const Vector& b, row, x, this->getOmega() ); - this -> setResidue( ResidueGetter :: getResidue( *matrix, x, b, bNorm ) ); - this -> refreshSolverMonitor(); + this->setResidue( ResidueGetter :: getResidue( *matrix, x, b, bNorm ) ); + this->refreshSolverMonitor(); } - this -> setResidue( ResidueGetter :: getResidue( *matrix, x, b, bNorm ) ); - this -> refreshSolverMonitor( true ); + this->setResidue( ResidueGetter :: getResidue( *matrix, x, b, bNorm ) ); + this->refreshSolverMonitor( true ); return this->checkConvergence(); }; diff --git a/src/solvers/ode/tnlEulerSolver.h b/src/solvers/ode/tnlEulerSolver.h index b7c92c7259209a7d2339ba72d371001f2c097846..13df781c2632042d34750083c4ce99e4958e30de 100644 --- a/src/solvers/ode/tnlEulerSolver.h +++ b/src/solvers/ode/tnlEulerSolver.h @@ -22,6 +22,7 @@ #include <config/tnlConfigDescription.h> #include <solvers/ode/tnlExplicitSolver.h> #include <config/tnlParameterContainer.h> +#include <core/tnlTimer.h> template< typename Problem > class tnlEulerSolver : public tnlExplicitSolver< Problem > @@ -60,6 +61,8 @@ class tnlEulerSolver : public tnlExplicitSolver< Problem > DofVectorType k1; RealType cflCondition; + + //tnlTimer timer, updateTimer; }; #include <solvers/ode/tnlEulerSolver_impl.h> diff --git a/src/solvers/ode/tnlEulerSolver_impl.h b/src/solvers/ode/tnlEulerSolver_impl.h index e89041ef955d0eab7e81190f9076038fb0157201..b9284d6a609f5833c663f4eb33e0051b01aabc5c 100644 --- a/src/solvers/ode/tnlEulerSolver_impl.h +++ b/src/solvers/ode/tnlEulerSolver_impl.h @@ -32,6 +32,8 @@ template< typename Problem > tnlEulerSolver< Problem > :: tnlEulerSolver() : cflCondition( 0.0 ) { + //timer.reset(); + //updateTimer.reset(); }; template< typename Problem > @@ -63,13 +65,13 @@ bool tnlEulerSolver< Problem > :: setup( const tnlParameterContainer& parameters template< typename Problem > void tnlEulerSolver< Problem > :: setCFLCondition( const RealType& cfl ) { - this -> cflCondition = cfl; + this->cflCondition = cfl; } template< typename Problem > const typename Problem :: RealType& tnlEulerSolver< Problem > :: getCFLCondition() const { - return this -> cflCondition; + return this->cflCondition; } template< typename Problem > @@ -78,6 +80,7 @@ bool tnlEulerSolver< Problem > :: solve( DofVectorType& u ) /**** * First setup the supporting meshes k1...k5 and k_tmp. */ + //timer.start(); if( ! k1. setLike( u ) ) { cerr << "I do not have enough memory to allocate a supporting grid for the Euler explicit solver." << endl; @@ -96,7 +99,7 @@ bool tnlEulerSolver< Problem > :: solve( DofVectorType& u ) this->resetIterations(); this->setResidue( this->getConvergenceResidue() + 1.0 ); - this -> refreshSolverMonitor(); + this->refreshSolverMonitor(); /**** * Start the main loop @@ -106,28 +109,32 @@ bool tnlEulerSolver< Problem > :: solve( DofVectorType& u ) /**** * Compute the RHS */ + //timer.stop(); this->problem->getExplicitRHS( time, currentTau, u, k1 ); + //timer.start(); RealType lastResidue = this->getResidue(); RealType maxResidue( 0.0 ); - if( this -> cflCondition != 0.0 ) + if( this->cflCondition != 0.0 ) { maxResidue = k1. absMax(); - if( currentTau * maxResidue > this -> cflCondition ) + if( currentTau * maxResidue > this->cflCondition ) { currentTau *= 0.9; continue; } } RealType newResidue( 0.0 ); + //updateTimer.start(); computeNewTimeLevel( u, currentTau, newResidue ); + //updateTimer.stop(); this->setResidue( newResidue ); /**** * When time is close to stopTime the new residue * may be inaccurate significantly. */ - if( currentTau + time == this -> stopTime ) this->setResidue( lastResidue ); + if( currentTau + time == this->stopTime ) this->setResidue( lastResidue ); time += currentTau; if( ! this->nextIteration() ) @@ -136,28 +143,30 @@ bool tnlEulerSolver< Problem > :: solve( DofVectorType& u ) /**** * Compute the new time step. */ - if( time + currentTau > this -> getStopTime() ) - currentTau = this -> getStopTime() - time; //we don't want to keep such tau - else this -> tau = currentTau; + if( time + currentTau > this->getStopTime() ) + currentTau = this->getStopTime() - time; //we don't want to keep such tau + else this->tau = currentTau; - this -> refreshSolverMonitor(); + this->refreshSolverMonitor(); /**** * Check stop conditions. */ if( time >= this->getStopTime() || - ( this -> getConvergenceResidue() != 0.0 && this->getResidue() < this -> getConvergenceResidue() ) ) + ( this->getConvergenceResidue() != 0.0 && this->getResidue() < this->getConvergenceResidue() ) ) { - this -> refreshSolverMonitor(); + this->refreshSolverMonitor(); + //std::cerr << std::endl << "RHS Timer = " << timer.getRealTime() << std::endl; + //std::cerr << std::endl << "Update Timer = " << updateTimer.getRealTime() << std::endl; return true; } - if( this -> cflCondition != 0.0 ) + if( this->cflCondition != 0.0 ) { currentTau /= 0.95; currentTau = Min( currentTau, this->getMaxTau() ); } - } + } }; template< typename Problem > @@ -166,15 +175,15 @@ void tnlEulerSolver< Problem > :: computeNewTimeLevel( DofVectorType& u, RealType& currentResidue ) { RealType localResidue = RealType( 0.0 ); - IndexType size = k1. getSize(); + const IndexType size = k1. getSize(); RealType* _u = u. getData(); RealType* _k1 = k1. getData(); - if( DeviceType :: getDevice() == tnlHostDevice ) + if( std::is_same< DeviceType, tnlHost >::value ) { -#ifdef HAVE_OPENMP -#pragma omp parallel for reduction(+:localResidue) firstprivate( _u, _k1, tau ) -#endif +//#ifdef HAVE_OPENMP +//#pragma omp parallel for reduction(+:localResidue) firstprivate( _u, _k1, tau ) if( tnlHost::isOMPEnabled() ) +//#endif for( IndexType i = 0; i < size; i ++ ) { const RealType add = tau * _k1[ i ]; @@ -182,7 +191,7 @@ void tnlEulerSolver< Problem > :: computeNewTimeLevel( DofVectorType& u, localResidue += fabs( add ); } } - if( DeviceType :: getDevice() == tnlCudaDevice ) + if( std::is_same< DeviceType, tnlCuda >::value ) { #ifdef HAVE_CUDA dim3 cudaBlockSize( 512 ); @@ -209,7 +218,7 @@ void tnlEulerSolver< Problem > :: computeNewTimeLevel( DofVectorType& u, #endif } localResidue /= tau * ( RealType ) size; - :: MPIAllreduce( localResidue, currentResidue, 1, MPI_SUM, this -> solver_comm ); + :: MPIAllreduce( localResidue, currentResidue, 1, MPI_SUM, this->solver_comm ); } #ifdef HAVE_CUDA diff --git a/src/solvers/ode/tnlMersonSolver_impl.h b/src/solvers/ode/tnlMersonSolver_impl.h index bc512effd6a874b3458860ad78de26ebc8893bd2..fee7015670cd1cfcc78f1862fe38e3e305059b59 100644 --- a/src/solvers/ode/tnlMersonSolver_impl.h +++ b/src/solvers/ode/tnlMersonSolver_impl.h @@ -122,13 +122,13 @@ bool tnlMersonSolver< Problem > :: setup( const tnlParameterContainer& parameter template< typename Problem > void tnlMersonSolver< Problem > :: setAdaptivity( const RealType& a ) { - this -> adaptivity = a; + this->adaptivity = a; }; template< typename Problem > bool tnlMersonSolver< Problem > :: solve( DofVectorType& u ) { - if( ! this -> problem ) + if( ! this->problem ) { cerr << "No problem was set for the Merson ODE solver." << endl; return false; @@ -165,7 +165,7 @@ bool tnlMersonSolver< Problem > :: solve( DofVectorType& u ) this->resetIterations(); this->setResidue( this->getConvergenceResidue() + 1.0 ); - this -> refreshSolverMonitor(); + this->refreshSolverMonitor(); /**** * Start the main loop @@ -176,7 +176,7 @@ bool tnlMersonSolver< Problem > :: solve( DofVectorType& u ) * Compute Runge-Kutta coefficients */ computeKFunctions( u, time, currentTau ); - if( this -> testingMode ) + if( this->testingMode ) writeGrids( u ); /**** @@ -197,13 +197,13 @@ bool tnlMersonSolver< Problem > :: solve( DofVectorType& u ) * When time is close to stopTime the new residue * may be inaccurate significantly. */ - if( currentTau + time == this -> stopTime ) this->setResidue( lastResidue ); + if( currentTau + time == this->stopTime ) this->setResidue( lastResidue ); time += currentTau; if( ! this->nextIteration() ) return false; } - this -> refreshSolverMonitor(); + this->refreshSolverMonitor(); /**** * Compute the new time step. @@ -212,22 +212,22 @@ bool tnlMersonSolver< Problem > :: solve( DofVectorType& u ) { currentTau *= 0.8 * pow( adaptivity / eps, 0.2 ); currentTau = Min( currentTau, this->getMaxTau() ); - :: MPIBcast( currentTau, 1, 0, this -> solver_comm ); + :: MPIBcast( currentTau, 1, 0, this->solver_comm ); } - if( time + currentTau > this -> getStopTime() ) - currentTau = this -> getStopTime() - time; //we don't want to keep such tau - else this -> tau = currentTau; + if( time + currentTau > this->getStopTime() ) + currentTau = this->getStopTime() - time; //we don't want to keep such tau + else this->tau = currentTau; /**** * Check stop conditions. */ //cerr << "residue = " << residue << endl; - //cerr << "this -> getConvergenceResidue() = " << this -> getConvergenceResidue() << endl; + //cerr << "this->getConvergenceResidue() = " << this->getConvergenceResidue() << endl; if( time >= this->getStopTime() || - ( this -> getConvergenceResidue() != 0.0 && this->getResidue() < this -> getConvergenceResidue() ) ) + ( this->getConvergenceResidue() != 0.0 && this->getResidue() < this->getConvergenceResidue() ) ) { - this -> refreshSolverMonitor(); + this->refreshSolverMonitor(); return true; } } @@ -274,28 +274,28 @@ void tnlMersonSolver< Problem > :: computeKFunctions( DofVectorType& u, this->problem->getExplicitRHS( time, tau, u, k1 ); #ifdef HAVE_OPENMP - #pragma omp parallel for firstprivate( size, _kAux, _u, _k1, tau, tau_3 ) + #pragma omp parallel for firstprivate( size, _kAux, _u, _k1, tau, tau_3 ) if( tnlHost::isOMPEnabled() ) #endif for( IndexType i = 0; i < size; i ++ ) _kAux[ i ] = _u[ i ] + tau * ( 1.0 / 3.0 * _k1[ i ] ); this->problem->getExplicitRHS( time + tau_3, tau, kAux, k2 ); #ifdef HAVE_OPENMP - #pragma omp parallel for firstprivate( size, _kAux, _u, _k1, _k2, tau, tau_3 ) + #pragma omp parallel for firstprivate( size, _kAux, _u, _k1, _k2, tau, tau_3 ) if( tnlHost::isOMPEnabled() ) #endif for( IndexType i = 0; i < size; i ++ ) _kAux[ i ] = _u[ i ] + tau * 1.0 / 6.0 * ( _k1[ i ] + _k2[ i ] ); this->problem->getExplicitRHS( time + tau_3, tau, kAux, k3 ); #ifdef HAVE_OPENMP - #pragma omp parallel for firstprivate( size, _kAux, _u, _k1, _k3, tau, tau_3 ) + #pragma omp parallel for firstprivate( size, _kAux, _u, _k1, _k3, tau, tau_3 ) if( tnlHost::isOMPEnabled() ) #endif for( IndexType i = 0; i < size; i ++ ) _kAux[ i ] = _u[ i ] + tau * ( 0.125 * _k1[ i ] + 0.375 * _k3[ i ] ); this->problem->getExplicitRHS( time + 0.5 * tau, tau, kAux, k4 ); #ifdef HAVE_OPENMP - #pragma omp parallel for firstprivate( size, _kAux, _u, _k1, _k3, _k4, tau, tau_3 ) + #pragma omp parallel for firstprivate( size, _kAux, _u, _k1, _k3, _k4, tau, tau_3 ) if( tnlHost::isOMPEnabled() ) #endif for( IndexType i = 0; i < size; i ++ ) _kAux[ i ] = _u[ i ] + tau * ( 0.5 * _k1[ i ] - 1.5 * _k3[ i ] + 2.0 * _k4[ i ] ); @@ -420,7 +420,7 @@ typename Problem :: RealType tnlMersonSolver< Problem > :: computeError( const R } #endif } - :: MPIAllreduce( eps, maxEps, 1, MPI_MAX, this -> solver_comm ); + :: MPIAllreduce( eps, maxEps, 1, MPI_MAX, this->solver_comm ); return maxEps; } @@ -454,7 +454,7 @@ void tnlMersonSolver< Problem > :: computeNewTimeLevel( DofVectorType& u, if( DeviceType :: getDevice() == tnlHostDevice ) { #ifdef HAVE_OPENMP -#pragma omp parallel for reduction(+:localResidue) firstprivate( size, _u, _k1, _k4, _k5, tau ) +#pragma omp parallel for reduction(+:localResidue) firstprivate( size, _u, _k1, _k4, _k5, tau ) if( tnlHost::isOMPEnabled() ) #endif for( IndexType i = 0; i < size; i ++ ) { @@ -493,7 +493,7 @@ void tnlMersonSolver< Problem > :: computeNewTimeLevel( DofVectorType& u, #endif } localResidue /= tau * ( RealType ) size; - :: MPIAllreduce( localResidue, currentResidue, 1, MPI_SUM, this -> solver_comm ); + :: MPIAllreduce( localResidue, currentResidue, 1, MPI_SUM, this->solver_comm ); } diff --git a/src/solvers/ode/tnlODESolverMonitor_impl.h b/src/solvers/ode/tnlODESolverMonitor_impl.h index 4eed193d24e5ff432b24563418dca31fa4167f98..44ff3d69d2b5a76a5bef95abc13720f66ffd7911 100644 --- a/src/solvers/ode/tnlODESolverMonitor_impl.h +++ b/src/solvers/ode/tnlODESolverMonitor_impl.h @@ -28,16 +28,16 @@ tnlODESolverMonitor< RealType, IndexType> :: tnlODESolverMonitor() template< typename RealType, typename IndexType > void tnlODESolverMonitor< RealType, IndexType> :: refresh() { - if( this -> verbose > 0 && this -> getIterations() % this -> refreshRate == 0 ) + if( this->verbose > 0 && this->getIterations() % this->refreshRate == 0 ) { // TODO: add EST //cout << " EST: " << estimated; - cout << " ITER:" << setw( 8 ) << this -> getIterations() - << " TAU:" << setprecision( 5 ) << setw( 12 ) << this -> getTimeStep() - << " T:" << setprecision( 5 ) << setw( 12 ) << this -> getTime() - << " RES:" << setprecision( 5 ) << setw( 12 ) << this -> getResidue() - << " CPU: " << setw( 8 ) << this -> getCPUTime() - << " ELA: " << setw( 8 ) << this -> getRealTime(); + cout << " ITER:" << setw( 8 ) << this->getIterations() + << " TAU:" << setprecision( 5 ) << setw( 12 ) << this->getTimeStep() + << " T:" << setprecision( 5 ) << setw( 12 ) << this->getTime() + << " RES:" << setprecision( 5 ) << setw( 12 ) << this->getResidue() + << " CPU: " << setw( 8 ) << this->getCPUTime() + << " ELA: " << setw( 8 ) << this->getRealTime(); /*double flops = ( double ) tnl_flops_counter. getFlops(); if( flops ) { @@ -45,31 +45,31 @@ void tnlODESolverMonitor< RealType, IndexType> :: refresh() }*/ cout << " \r" << flush; } - this -> refreshing ++; + this->refreshing ++; } template< typename RealType, typename IndexType > void tnlODESolverMonitor< RealType, IndexType> :: setTimeStep( const RealType& timeStep ) { - this -> timeStep = timeStep; + this->timeStep = timeStep; } template< typename RealType, typename IndexType > const RealType& tnlODESolverMonitor< RealType, IndexType> :: getTimeStep() const { - return this -> timeStep; + return this->timeStep; } template< typename RealType, typename IndexType > void tnlODESolverMonitor< RealType, IndexType> :: setTime( const RealType& time ) { - this -> time = time; + this->time = time; } template< typename RealType, typename IndexType > const RealType& tnlODESolverMonitor< RealType, IndexType> :: getTime() const { - return this -> time; + return this->time; } #endif /* TNLODESOLVERMONITOR_IMPL_H_ */ diff --git a/src/solvers/pde/tnlExplicitTimeStepper.h b/src/solvers/pde/tnlExplicitTimeStepper.h index 9d3dc11a2754673c08fc008b6ebeabb0caa354fd..9c251443789c79ad7c453a75640df1d16a36ddab 100644 --- a/src/solvers/pde/tnlExplicitTimeStepper.h +++ b/src/solvers/pde/tnlExplicitTimeStepper.h @@ -21,7 +21,7 @@ #include <solvers/ode/tnlODESolverMonitor.h> #include <config/tnlConfigDescription.h> #include <config/tnlParameterContainer.h> -#include <core/tnlTimerRT.h> +#include <core/tnlTimer.h> #include <core/tnlLogger.h> @@ -85,7 +85,9 @@ class tnlExplicitTimeStepper MeshDependentDataType* meshDependentData; - tnlTimerRT explicitUpdaterTimer; + tnlTimer preIterateTimer, explicitUpdaterTimer, mainTimer, postIterateTimer; + + long long int allIterations; }; #include <solvers/pde/tnlExplicitTimeStepper_impl.h> diff --git a/src/solvers/pde/tnlExplicitTimeStepper_impl.h b/src/solvers/pde/tnlExplicitTimeStepper_impl.h index e47e0c562eeaa1f0040abc80e4763897330dc04c..69ab112ab668b1e971a65b5d812cd3f1a7a355f4 100644 --- a/src/solvers/pde/tnlExplicitTimeStepper_impl.h +++ b/src/solvers/pde/tnlExplicitTimeStepper_impl.h @@ -27,7 +27,8 @@ tnlExplicitTimeStepper< Problem, OdeSolver >:: tnlExplicitTimeStepper() : odeSolver( 0 ), problem( 0 ), - timeStep( 0 ) + timeStep( 0 ), + allIterations( 0 ) { }; @@ -57,6 +58,9 @@ tnlExplicitTimeStepper< Problem, OdeSolver >:: init( const MeshType& mesh ) { this->explicitUpdaterTimer.reset(); + this->mainTimer.reset(); + this->preIterateTimer.reset(); + this->postIterateTimer.reset(); return true; } @@ -113,7 +117,8 @@ solve( const RealType& time, MeshDependentDataType& meshDependentData ) { tnlAssert( this->odeSolver, ); - this->odeSolver->setTau( this -> timeStep ); + mainTimer.start(); + this->odeSolver->setTau( this->timeStep ); this->odeSolver->setProblem( * this ); this->odeSolver->setTime( time ); this->odeSolver->setStopTime( stopTime ); @@ -121,7 +126,11 @@ solve( const RealType& time, this->odeSolver->setMaxTau( ( stopTime - time ) / ( typename OdeSolver< Problem >::RealType ) this->odeSolver->getMinIterations() ); this->mesh = &mesh; this->meshDependentData = &meshDependentData; - return this->odeSolver->solve( dofVector ); + if( ! this->odeSolver->solve( dofVector ) ) + return false; + mainTimer.stop(); + this->allIterations += this->odeSolver->getIterations(); + return true; } template< typename Problem, @@ -133,6 +142,7 @@ getExplicitRHS( const RealType& time, DofVectorType& u, DofVectorType& fu ) { + this->preIterateTimer.start(); if( ! this->problem->preIterate( time, tau, *( this->mesh), @@ -143,9 +153,11 @@ getExplicitRHS( const RealType& time, return; //return false; // TODO: throw exception } - this->explicitUpdaterTimer.start(); + this->preIterateTimer.stop(); + this->explicitUpdaterTimer.start(); this->problem->getExplicitRHS( time, tau, *( this->mesh ), u, fu, *( this->meshDependentData ) ); this->explicitUpdaterTimer.stop(); + this->postIterateTimer.start(); if( ! this->problem->postIterate( time, tau, *( this->mesh ), @@ -156,6 +168,7 @@ getExplicitRHS( const RealType& time, return; //return false; // TODO: throw exception } + this->postIterateTimer.stop(); } template< typename Problem, @@ -164,7 +177,15 @@ bool tnlExplicitTimeStepper< Problem, OdeSolver >:: writeEpilog( tnlLogger& logger ) { - logger.writeParameter< double >( "Explicit update computation time:", this->explicitUpdaterTimer.getTime() ); + logger.writeParameter< long long int >( "Iterations count:", this->allIterations ); + logger.writeParameter< const char* >( "Pre-iterate time:", "" ); + this->preIterateTimer.writeLog( logger, 1 ); + logger.writeParameter< const char* >( "Explicit update computation:", "" ); + this->explicitUpdaterTimer.writeLog( logger, 1 ); + logger.writeParameter< const char* >( "Explicit time stepper time:", "" ); + this->mainTimer.writeLog( logger, 1 ); + logger.writeParameter< const char* >( "Post-iterate time:", "" ); + this->postIterateTimer.writeLog( logger, 1 ); return true; } diff --git a/src/solvers/pde/tnlExplicitUpdater.h b/src/solvers/pde/tnlExplicitUpdater.h index 6956c8b29e9a200d054677f7ec31e737c78fe66b..eabe8c62a3eb7483ab5548effe5d0c26c6a89029 100644 --- a/src/solvers/pde/tnlExplicitUpdater.h +++ b/src/solvers/pde/tnlExplicitUpdater.h @@ -19,6 +19,7 @@ #define TNLEXPLICITUPDATER_H_ #include <functions/tnlFunctionAdapter.h> +#include <core/tnlTimer.h> template< typename Real, typename MeshFunction, @@ -72,6 +73,14 @@ class tnlExplicitUpdater DifferentialOperator, BoundaryConditions, RightHandSide > TraverserUserData; + + tnlExplicitUpdater() + : gpuTransferTimer( 0 ){} + + void setGPUTransferTimer( tnlTimer& timer ) + { + this->gpuTransferTimer = &timer; + } template< typename EntityType > void update( const RealType& time, @@ -126,6 +135,10 @@ class tnlExplicitUpdater *userData.time ); } }; + + protected: + + tnlTimer* gpuTransferTimer; }; #include <solvers/pde/tnlExplicitUpdater_impl.h> diff --git a/src/solvers/pde/tnlExplicitUpdater_impl.h b/src/solvers/pde/tnlExplicitUpdater_impl.h index 16a2c0346402907c21701d280609deddd27a3cad..a2c3ff1ce79b1547716f08b5ca1c69d5f011f5ab 100644 --- a/src/solvers/pde/tnlExplicitUpdater_impl.h +++ b/src/solvers/pde/tnlExplicitUpdater_impl.h @@ -23,6 +23,8 @@ #include <mesh/grids/tnlTraverser_Grid2D.h> #include <mesh/grids/tnlTraverser_Grid3D.h> +#include "tnlExplicitUpdater.h" + template< typename Mesh, typename MeshFunction, typename DifferentialOperator, @@ -60,12 +62,17 @@ update( const RealType& time, } if( std::is_same< DeviceType, tnlCuda >::value ) { + if( this->gpuTransferTimer ) + this->gpuTransferTimer->start(); RealType* kernelTime = tnlCuda::passToDevice( time ); DifferentialOperator* kernelDifferentialOperator = tnlCuda::passToDevice( differentialOperator ); BoundaryConditions* kernelBoundaryConditions = tnlCuda::passToDevice( boundaryConditions ); RightHandSide* kernelRightHandSide = tnlCuda::passToDevice( rightHandSide ); MeshFunction* kernelU = tnlCuda::passToDevice( u ); MeshFunction* kernelFu = tnlCuda::passToDevice( fu ); + if( this->gpuTransferTimer ) + this->gpuTransferTimer->stop(); + TraverserUserData userData( *kernelTime, *kernelDifferentialOperator, *kernelBoundaryConditions, *kernelRightHandSide, *kernelU, *kernelFu ); checkCudaDevice; tnlTraverser< MeshType, EntityType > meshTraverser; @@ -78,7 +85,10 @@ update( const RealType& time, ( mesh, userData ); - checkCudaDevice; + if( this->gpuTransferTimer ) + this->gpuTransferTimer->start(); + + checkCudaDevice; tnlCuda::freeFromDevice( kernelTime ); tnlCuda::freeFromDevice( kernelDifferentialOperator ); tnlCuda::freeFromDevice( kernelBoundaryConditions ); @@ -86,6 +96,10 @@ update( const RealType& time, tnlCuda::freeFromDevice( kernelU ); tnlCuda::freeFromDevice( kernelFu ); checkCudaDevice; + + if( this->gpuTransferTimer ) + this->gpuTransferTimer->stop(); + } } diff --git a/src/solvers/pde/tnlLinearSystemAssembler.h b/src/solvers/pde/tnlLinearSystemAssembler.h index 14753fb7877ae1f1126b541345099a1da28a916f..74b7b6e44056915b0b9fbee59f1cd56d132b74f6 100644 --- a/src/solvers/pde/tnlLinearSystemAssembler.h +++ b/src/solvers/pde/tnlLinearSystemAssembler.h @@ -121,14 +121,13 @@ class tnlLinearSystemAssembler const EntityType& entity ) { ( *userData.b )[ entity.getIndex() ] = 0.0; - userData.boundaryConditions->updateLinearSystem - ( *userData.time + *userData.tau, - mesh, - entity.getIndex(), + userData.boundaryConditions->setMatrixElements + ( *userData.u, entity, - *userData.u, - *userData.b, - *userData.matrix ); + *userData.time + *userData.tau, + *userData.tau, + *userData.matrix, + *userData.b ); } }; @@ -143,15 +142,13 @@ class tnlLinearSystemAssembler const EntityType& entity ) { ( *userData.b )[ entity.getIndex() ] = 0.0; - userData.differentialOperator->updateLinearSystem - ( *userData.time, - *userData.tau, - mesh, - entity.getIndex(), + userData.differentialOperator->setMatrixElements + ( *userData.u, entity, - *userData.u, - *userData.b, - *userData.matrix ); + *userData.time + *userData.tau, + *userData.tau, + *userData.matrix, + *userData.b ); typedef tnlFunctionAdapter< MeshType, RightHandSide > RhsFunctionAdapter; typedef tnlFunctionAdapter< MeshType, MeshFunction > MeshFunctionAdapter; diff --git a/src/solvers/pde/tnlPDESolver.h b/src/solvers/pde/tnlPDESolver.h index 87c1f18e5b36a0814455703c9d689a54004f043b..03df9d6e00b961f5e424a5d8b3a633da8db781cc 100644 --- a/src/solvers/pde/tnlPDESolver.h +++ b/src/solvers/pde/tnlPDESolver.h @@ -21,7 +21,6 @@ #include <core/tnlObject.h> #include <config/tnlConfigDescription.h> #include <config/tnlParameterContainer.h> -#include <solvers/tnlSolverMonitor.h> #include <core/tnlLogger.h> template< typename Problem, @@ -73,13 +72,9 @@ class tnlPDESolver : public tnlObject const RealType& getSnapshotPeriod() const; - void setIoRtTimer( tnlTimerRT& ioRtTimer); + void setIoTimer( tnlTimer& ioTimer); - void setComputeRtTimer( tnlTimerRT& computeRtTimer ); - - void setIoCpuTimer( tnlTimerCPU& ioCpuTimer ); - - void setComputeCpuTimer( tnlTimerCPU& computeCpuTimer ); + void setComputeTimer( tnlTimer& computeTimer ); bool solve(); @@ -99,10 +94,7 @@ class tnlPDESolver : public tnlObject ProblemType* problem; - tnlTimerRT *ioRtTimer, *computeRtTimer; - - tnlTimerCPU *ioCpuTimer, *computeCpuTimer; - + tnlTimer *ioTimer, *computeTimer; }; #include <solvers/pde/tnlPDESolver_impl.h> diff --git a/src/solvers/pde/tnlPDESolver_impl.h b/src/solvers/pde/tnlPDESolver_impl.h index cb820815a14d99c2184ae9d56bbafa1c16dfa1a2..b0356073984a277c1af4930c41dff14927e3ed27 100644 --- a/src/solvers/pde/tnlPDESolver_impl.h +++ b/src/solvers/pde/tnlPDESolver_impl.h @@ -18,6 +18,9 @@ #ifndef TNLPDESOLVER_IMPL_H_ #define TNLPDESOLVER_IMPL_H_ +#include "tnlPDESolver.h" + + template< typename Problem, typename TimeStepper > tnlPDESolver< Problem, TimeStepper >:: @@ -29,10 +32,8 @@ tnlPDESolver() timeStep( 1.0 ), timeStepOrder( 0.0 ), problem( 0 ), - ioRtTimer( 0 ), - computeRtTimer( 0 ), - ioCpuTimer( 0 ), - computeCpuTimer( 0 ) + ioTimer( 0 ), + computeTimer( 0 ) { } @@ -150,6 +151,7 @@ writeProlog( tnlLogger& logger, logger.writeSystemInformation( parameters ); logger.writeSeparator(); logger.writeCurrentTime( "Started at:" ); + logger.writeSeparator(); return true; } @@ -287,27 +289,15 @@ getTimeStepOrder() const } template< typename Problem, typename TimeStepper > -void tnlPDESolver< Problem, TimeStepper > :: setIoRtTimer( tnlTimerRT& ioRtTimer ) +void tnlPDESolver< Problem, TimeStepper > :: setIoTimer( tnlTimer& ioTimer ) { - this->ioRtTimer = &ioRtTimer; + this->ioTimer = &ioTimer; } template< typename Problem, typename TimeStepper > -void tnlPDESolver< Problem, TimeStepper > :: setComputeRtTimer( tnlTimerRT& computeRtTimer ) +void tnlPDESolver< Problem, TimeStepper > :: setComputeTimer( tnlTimer& computeTimer ) { - this -> computeRtTimer = &computeRtTimer; -} - -template< typename Problem, typename TimeStepper > -void tnlPDESolver< Problem, TimeStepper > :: setIoCpuTimer( tnlTimerCPU& ioCpuTimer ) -{ - this -> ioCpuTimer = &ioCpuTimer; -} - -template< typename Problem, typename TimeStepper > -void tnlPDESolver< Problem, TimeStepper > :: setComputeCpuTimer( tnlTimerCPU& computeCpuTimer ) -{ - this -> computeCpuTimer = & computeCpuTimer; + this->computeTimer = &computeTimer; } template< typename Problem, typename TimeStepper > @@ -329,21 +319,17 @@ solve() IndexType step( 0 ); IndexType allSteps = ceil( ( this->finalTime - this->initialTime ) / this->snapshotPeriod ); - this->ioRtTimer->start(); - this->ioCpuTimer->start(); - this->computeRtTimer->stop(); - this->computeCpuTimer->stop(); - + this->ioTimer->reset(); + this->computeTimer->reset(); + + this->ioTimer->start(); if( ! this->problem->makeSnapshot( t, step, mesh, this->dofs, this->meshDependentData ) ) { cerr << "Making the snapshot failed." << endl; return false; - } - - this->ioRtTimer->stop(); - this->ioCpuTimer->stop(); - this->computeRtTimer->start(); - this->computeCpuTimer->start(); + } + this->ioTimer->stop(); + this->computeTimer->start(); /**** * Initialize the time stepper @@ -353,29 +339,24 @@ solve() this->timeStepper->setTimeStep( this->timeStep * pow( mesh.getSmallestSpaceStep(), this->timeStepOrder ) ); while( step < allSteps ) { - RealType tau = Min( this -> snapshotPeriod, - this -> finalTime - t ); + RealType tau = Min( this->snapshotPeriod, + this->finalTime - t ); if( ! this->timeStepper->solve( t, t + tau, mesh, this->dofs, this->meshDependentData ) ) return false; step ++; t += tau; - this->ioRtTimer->start(); - this->ioCpuTimer->start(); - this->computeRtTimer->stop(); - this->computeCpuTimer->stop(); - + this->ioTimer->start(); + this->computeTimer->stop(); if( ! this->problem->makeSnapshot( t, step, mesh, this->dofs, this->meshDependentData ) ) { cerr << "Making the snapshot failed." << endl; return false; } - - this->ioRtTimer->stop(); - this->ioCpuTimer->stop(); - this->computeRtTimer->start(); - this->computeCpuTimer->start(); + this->ioTimer->stop(); + this->computeTimer->start(); } + this->computeTimer->stop(); return true; } @@ -384,7 +365,8 @@ bool tnlPDESolver< Problem, TimeStepper >:: writeEpilog( tnlLogger& logger ) const { - return this->timeStepper->writeEpilog( logger ); + return ( this->timeStepper->writeEpilog( logger ) && + this->problem->writeEpilog( logger ) ); } #endif /* TNLPDESOLVER_IMPL_H_ */ diff --git a/src/solvers/pde/tnlSemiImplicitTimeStepper.h b/src/solvers/pde/tnlSemiImplicitTimeStepper.h index 05f16704e760f44ab54d433211a56ddaa5a29623..5ce8dbf48b38f2db3d5992510a777d3072fe6235 100644 --- a/src/solvers/pde/tnlSemiImplicitTimeStepper.h +++ b/src/solvers/pde/tnlSemiImplicitTimeStepper.h @@ -80,9 +80,11 @@ class tnlSemiImplicitTimeStepper RealType timeStep; - tnlTimerRT preIterateTimer, linearSystemAssemblerTimer, linearSystemSolverTimer, postIterateTimer; + tnlTimer preIterateTimer, linearSystemAssemblerTimer, linearSystemSolverTimer, postIterateTimer; bool verbose; + + long long int allIterations; }; #include <solvers/pde/tnlSemiImplicitTimeStepper_impl.h> diff --git a/src/solvers/pde/tnlSemiImplicitTimeStepper_impl.h b/src/solvers/pde/tnlSemiImplicitTimeStepper_impl.h index d13ef8050448da323e657cab41935696c8c9b4a4..34dede52de49d918cc624efef53cceb9245048d6 100644 --- a/src/solvers/pde/tnlSemiImplicitTimeStepper_impl.h +++ b/src/solvers/pde/tnlSemiImplicitTimeStepper_impl.h @@ -20,13 +20,16 @@ #include <core/mfuncs.h> +#include "tnlSemiImplicitTimeStepper.h" + template< typename Problem, typename LinearSystemSolver > tnlSemiImplicitTimeStepper< Problem, LinearSystemSolver >:: tnlSemiImplicitTimeStepper() : problem( 0 ), linearSystemSolver( 0 ), - timeStep( 0 ) + timeStep( 0 ), + allIterations( 0 ) { }; @@ -75,6 +78,7 @@ init( const MeshType& mesh ) return false; this->linearSystemAssemblerTimer.reset(); this->linearSystemSolverTimer.reset(); + this->allIterations = 0; return true; } @@ -84,7 +88,7 @@ void tnlSemiImplicitTimeStepper< Problem, LinearSystemSolver >:: setProblem( ProblemType& problem ) { - this -> problem = &problem; + this->problem = &problem; }; template< typename Problem, @@ -93,7 +97,7 @@ Problem* tnlSemiImplicitTimeStepper< Problem, LinearSystemSolver >:: getProblem() const { - return this -> problem; + return this->problem; }; template< typename Problem, @@ -187,6 +191,7 @@ solve( const RealType& time, return false; } this->linearSystemSolverTimer.stop(); + this->allIterations += this->linearSystemSolver->getIterations(); //if( verbose ) // cout << endl; @@ -214,10 +219,15 @@ bool tnlSemiImplicitTimeStepper< Problem, LinearSystemSolver >:: writeEpilog( tnlLogger& logger ) { - logger.writeParameter< double >( "Pre-iterate time:", this->preIterateTimer.getTime() ); - logger.writeParameter< double >( "Linear system assembler time:", this->linearSystemAssemblerTimer.getTime() ); - logger.writeParameter< double >( "Linear system solver time:", this->linearSystemSolverTimer.getTime() ); - logger.writeParameter< double >( "Post-iterate time:", this->postIterateTimer.getTime() ); + logger.writeParameter< long long int >( "Iterations count:", this->allIterations ); + logger.writeParameter< const char* >( "Pre-iterate time:", "" ); + this->preIterateTimer.writeLog( logger, 1 ); + logger.writeParameter< const char* >( "Linear system assembler time:", "" ); + this->linearSystemAssemblerTimer.writeLog( logger, 1 ); + logger.writeParameter< const char* >( "Linear system solver time:", "" ); + this->linearSystemSolverTimer.writeLog( logger, 1 ); + logger.writeParameter< const char* >( "Post-iterate time:", "" ); + this->postIterateTimer.writeLog( logger, 1 ); return true; } diff --git a/src/solvers/tnlIterativeSolverMonitor_impl.h b/src/solvers/tnlIterativeSolverMonitor_impl.h index 7f65f9e596b3cbdc1d8101c3f35c33f6d011c5e7..998706a7e86fefb0d384beb074b7e92322f797c7 100644 --- a/src/solvers/tnlIterativeSolverMonitor_impl.h +++ b/src/solvers/tnlIterativeSolverMonitor_impl.h @@ -35,37 +35,37 @@ tnlIterativeSolverMonitor< Real, Index > :: tnlIterativeSolverMonitor() template< typename Real, typename Index> void tnlIterativeSolverMonitor< Real, Index > :: setIterations( const Index& iterations ) { - this -> iterations = iterations; + this->iterations = iterations; } template< typename Real, typename Index> const Index& tnlIterativeSolverMonitor< Real, Index > :: getIterations() const { - return this -> iterations; + return this->iterations; } template< typename Real, typename Index> void tnlIterativeSolverMonitor< Real, Index > :: setResidue( const Real& residue ) { - this -> residue = residue; + this->residue = residue; } template< typename Real, typename Index> const Real& tnlIterativeSolverMonitor< Real, Index > :: getResidue() const { - return this -> residue; + return this->residue; } template< typename Real, typename Index> void tnlIterativeSolverMonitor< Real, Index > :: setVerbose( const Index& verbose ) { - this -> verbose = verbose; + this->verbose = verbose; } template< typename Real, typename Index> void tnlIterativeSolverMonitor< Real, Index > :: setRefreshRate( const Index& refreshRate ) { - this -> refreshRate = refreshRate; + this->refreshRate = refreshRate; } template< typename Real, typename Index> @@ -74,9 +74,9 @@ void tnlIterativeSolverMonitor< Real, Index > :: refresh( bool force ) if( this->verbose > 0 && ( force || this->getIterations() % this->refreshRate == 0 ) ) { cout << " ITER:" << setw( 8 ) << this->getIterations() - << " RES:" << setprecision( 5 ) << setw( 12 ) << this -> getResidue() - << " CPU: " << setw( 8 ) << this -> getCPUTime() - << " ELA: " << setw( 8 ) << this -> getRealTime() + << " RES:" << setprecision( 5 ) << setw( 12 ) << this->getResidue() + << " CPU: " << setw( 8 ) << this->getCPUTime() + << " ELA: " << setw( 8 ) << this->getRealTime() << " \r" << flush; } this->refreshing ++; diff --git a/src/solvers/tnlIterativeSolver_impl.h b/src/solvers/tnlIterativeSolver_impl.h index dc86d6179280a4fe66e0a83aee48b4562df89d4a..281948456788f74507f9e475654d961f7be242a0 100644 --- a/src/solvers/tnlIterativeSolver_impl.h +++ b/src/solvers/tnlIterativeSolver_impl.h @@ -38,7 +38,7 @@ template< typename Real, typename Index > void tnlIterativeSolver< Real, Index> :: configSetup( tnlConfigDescription& config, const tnlString& prefix ) { - config.addEntry< int > ( prefix + "max-iterations", "Maximal number of iterations the solver may perform.", 100000 ); + config.addEntry< int > ( prefix + "max-iterations", "Maximal number of iterations the solver may perform.", 100000000000 ); config.addEntry< int > ( prefix + "min-iterations", "Minimal number of iterations the solver must perform.", 0 ); config.addEntry< double >( prefix + "convergence-residue", "Convergence occurs when the residue drops bellow this limit.", 1.0e-6 ); config.addEntry< double >( prefix + "divergence-residue", "Divergence occurs when the residue exceeds given limit.", DBL_MAX ); @@ -60,31 +60,31 @@ bool tnlIterativeSolver< Real, Index> :: setup( const tnlParameterContainer& par template< typename Real, typename Index > void tnlIterativeSolver< Real, Index> :: setMaxIterations( const Index& maxIterations ) { - this -> maxIterations = maxIterations; + this->maxIterations = maxIterations; } template< typename Real, typename Index > const Index& tnlIterativeSolver< Real, Index> :: getMaxIterations() const { - return this -> maxIterations; + return this->maxIterations; } template< typename Real, typename Index > void tnlIterativeSolver< Real, Index> :: setMinIterations( const Index& minIterations ) { - this -> minIterations = minIterations; + this->minIterations = minIterations; } template< typename Real, typename Index > const Index& tnlIterativeSolver< Real, Index> :: getMinIterations() const { - return this -> minIterations; + return this->minIterations; } template< typename Real, typename Index > void tnlIterativeSolver< Real, Index> :: resetIterations() { - this -> currentIteration = 0; + this->currentIteration = 0; } template< typename Real, typename Index > @@ -143,7 +143,7 @@ const Index& tnlIterativeSolver< Real, Index>:: getIterations() const { - return this -> currentIteration; + return this->currentIteration; } template< typename Real, typename Index > @@ -174,36 +174,36 @@ const Real& tnlIterativeSolver< Real, Index> :: getDivergenceResidue() const template< typename Real, typename Index > void tnlIterativeSolver< Real, Index> :: setResidue( const Real& residue ) { - this -> currentResidue = residue; + this->currentResidue = residue; } template< typename Real, typename Index > const Real& tnlIterativeSolver< Real, Index> :: getResidue() const { - return this -> currentResidue; + return this->currentResidue; } template< typename Real, typename Index > void tnlIterativeSolver< Real, Index> :: setRefreshRate( const Index& refreshRate ) { - this -> refreshRate = refreshRate; + this->refreshRate = refreshRate; } template< typename Real, typename Index > void tnlIterativeSolver< Real, Index> :: setSolverMonitor( tnlIterativeSolverMonitor< Real, Index >& solverMonitor ) { - this -> solverMonitor = &solverMonitor; + this->solverMonitor = &solverMonitor; } template< typename Real, typename Index > void tnlIterativeSolver< Real, Index> :: refreshSolverMonitor( bool force ) { - if( this -> solverMonitor ) + if( this->solverMonitor ) { - this -> solverMonitor -> setIterations( this -> getIterations() ); - this -> solverMonitor -> setResidue( this -> getResidue() ); - this -> solverMonitor -> setRefreshRate( this-> refreshRate ); - this -> solverMonitor -> refresh( force ); + this->solverMonitor -> setIterations( this->getIterations() ); + this->solverMonitor -> setResidue( this->getResidue() ); + this->solverMonitor -> setRefreshRate( this-> refreshRate ); + this->solverMonitor -> refresh( force ); } } diff --git a/src/solvers/tnlSolverConfig_impl.h b/src/solvers/tnlSolverConfig_impl.h index 01d005335aac5b531af61f05bb0768317688d382..fcf4221c421827eb730f17ffaa71f547e17ac7f9 100644 --- a/src/solvers/tnlSolverConfig_impl.h +++ b/src/solvers/tnlSolverConfig_impl.h @@ -156,7 +156,7 @@ bool tnlSolverConfig< ConfigTag, ProblemConfig >::configSetup( tnlConfigDescript config.addDelimiter( " === Logs and messages ===" ); config.addEntry< int >( "verbose", "Set the verbose mode. The higher number the more messages are generated.", 1 ); - config.addEntry< tnlString >( "log-file", "Log file for the computation." ); + config.addEntry< tnlString >( "log-file", "Log file for the computation.", "log.txt" ); config.addEntry< int >( "log-width", "Number of columns of the log table.", 80 ); return true; diff --git a/src/solvers/tnlSolverStarter.h b/src/solvers/tnlSolverStarter.h index 7b9bc2d8f3757487ac9f479ac274ab18ddef4ddd..87c67ac8d72ea3c6fd7575b4c0e63375558001be 100644 --- a/src/solvers/tnlSolverStarter.h +++ b/src/solvers/tnlSolverStarter.h @@ -19,8 +19,7 @@ #define TNLSOLVERSTARTER_H_ #include <config/tnlParameterContainer.h> -#include <core/tnlTimerRT.h> -#include <core/tnlTimerCPU.h> +#include <core/tnlTimer.h> #include <ostream> template< typename MeshConfig > @@ -45,9 +44,7 @@ class tnlSolverStarter int logWidth; - tnlTimerRT ioRtTimer, computeRtTimer, totalRtTimer; - - tnlTimerCPU ioCpuTimer, computeCpuTimer, totalCpuTimer; + tnlTimer ioTimer, computeTimer, totalTimer; }; #include <solvers/tnlSolverStarter_impl.h> diff --git a/src/solvers/tnlSolverStarter_impl.h b/src/solvers/tnlSolverStarter_impl.h index e9bce4d8cc08a540ded118b9c48800dc3b3aef12..2126dec4cbc478522f809eca8530566ba11cccfd 100644 --- a/src/solvers/tnlSolverStarter_impl.h +++ b/src/solvers/tnlSolverStarter_impl.h @@ -21,6 +21,7 @@ #include <tnlConfig.h> #include <core/tnlLogger.h> #include <core/tnlString.h> +#include <core/tnlCuda.h> #include <solvers/ode/tnlMersonSolver.h> #include <solvers/ode/tnlEulerSolver.h> #include <solvers/linear/stationary/tnlSORSolver.h> @@ -90,6 +91,9 @@ bool tnlSolverStarter< ConfigTag > :: run( const tnlParameterContainer& paramete /**** * Create and set-up the problem */ + if( ! tnlHost::setup( parameters ) || + ! tnlCuda::setup( parameters ) ) + return false; Problem problem; if( ! problem.setup( parameters ) ) { @@ -347,11 +351,14 @@ class tnlSolverStarterExplicitTimeStepperSetter typedef typename Problem::IndexType IndexType; typedef tnlODESolverMonitor< RealType, IndexType > SolverMonitorType; + const int verbose = parameters.getParameter< int >( "verbose" ); + ExplicitSolver explicitSolver; explicitSolver.setup( parameters ); - int verbose = parameters.getParameter< int >( "verbose" ); explicitSolver.setVerbose( verbose ); + SolverMonitorType odeSolverMonitor; + odeSolverMonitor.setVerbose( verbose ); if( ! problem.getSolverMonitor() ) explicitSolver.setSolverMonitor( odeSolverMonitor ); else @@ -390,10 +397,13 @@ class tnlSolverStarterSemiImplicitTimeStepperSetter typedef typename Problem::IndexType IndexType; typedef tnlIterativeSolverMonitor< RealType, IndexType > SolverMonitorType; + const int verbose = parameters.getParameter< int >( "verbose" ); + LinearSystemSolverType linearSystemSolver; linearSystemSolver.setup( parameters ); SolverMonitorType solverMonitor; + solverMonitor.setVerbose( verbose ); if( ! problem.getSolverMonitor() ) linearSystemSolver.setSolverMonitor( solverMonitor ); else @@ -441,7 +451,7 @@ bool tnlSolverStarter< ConfigTag > :: setDiscreteSolver( Problem& problem, DiscreteSolver solver; double omega = parameters. getParameter< double >( "sor-omega" ); solver. setOmega( omega ); - //solver. setVerbose( this -> verbose ); + //solver. setVerbose( this->verbose ); return setSemiImplicitTimeDiscretisation< Problem >( problem, parameters, solver ); } @@ -450,7 +460,7 @@ bool tnlSolverStarter< ConfigTag > :: setDiscreteSolver( Problem& problem, typedef tnlCGSolver< typename Problem :: DiscreteSolverMatrixType, typename Problem :: DiscreteSolverPreconditioner > DiscreteSolver; DiscreteSolver solver; - //solver. setVerbose( this -> verbose ); + //solver. setVerbose( this->verbose ); return setSemiImplicitTimeDiscretisation< Problem >( problem, parameters, solver ); } @@ -459,7 +469,7 @@ bool tnlSolverStarter< ConfigTag > :: setDiscreteSolver( Problem& problem, typedef tnlBICGStabSolver< typename Problem :: DiscreteSolverMatrixType, typename Problem :: DiscreteSolverPreconditioner > DiscreteSolver; DiscreteSolver solver; - //solver. setVerbose( this -> verbose ); + //solver. setVerbose( this->verbose ); return setSemiImplicitTimeDiscretisation< Problem >( problem, parameters, solver ); } @@ -470,7 +480,7 @@ bool tnlSolverStarter< ConfigTag > :: setDiscreteSolver( Problem& problem, DiscreteSolver solver; int restarting = parameters. getParameter< int >( "gmres-restarting" ); solver. setRestarting( restarting ); - //solver. setVerbose( this -> verbose ); + //solver. setVerbose( this->verbose ); return setSemiImplicitTimeDiscretisation< Problem >( problem, parameters, solver ); } cerr << "Unknown discrete solver " << discreteSolver << "." << endl; @@ -485,8 +495,9 @@ bool tnlSolverStarter< ConfigTag > :: runPDESolver( Problem& problem, const tnlParameterContainer& parameters, TimeStepper& timeStepper ) { - this->totalCpuTimer.reset(); - this->totalRtTimer.reset(); + this->totalTimer.reset(); + this->totalTimer.start(); + /**** * Set-up the PDE solver @@ -529,16 +540,10 @@ bool tnlSolverStarter< ConfigTag > :: runPDESolver( Problem& problem, /**** * Set-up timers */ - this->computeRtTimer.reset(); - this->computeCpuTimer.reset(); - this->ioRtTimer.reset(); - this->ioRtTimer.stop(); - this->ioCpuTimer.reset(); - this->ioCpuTimer.stop(); - solver.setComputeRtTimer( this->computeRtTimer ); - solver.setComputeCpuTimer( this->computeCpuTimer ); - solver.setIoRtTimer( this->ioRtTimer ); - solver.setIoCpuTimer( this->ioCpuTimer ); + this->computeTimer.reset(); + this->ioTimer.reset(); + solver.setComputeTimer( this->computeTimer ); + solver.setIoTimer( this->ioTimer ); /**** * Start the solver @@ -566,10 +571,8 @@ bool tnlSolverStarter< ConfigTag > :: runPDESolver( Problem& problem, /**** * Stop timers */ - this->computeRtTimer.stop(); - this->computeCpuTimer.stop(); - this->totalCpuTimer.stop(); - this->totalRtTimer.stop(); + this->computeTimer.stop(); + this->totalTimer.stop(); /**** * Write an epilog @@ -599,17 +602,18 @@ template< typename ConfigTag > bool tnlSolverStarter< ConfigTag > :: writeEpilog( ostream& str, const Solver& solver ) { tnlLogger logger( logWidth, str ); + logger.writeSeparator(); logger.writeCurrentTime( "Finished at:" ); if( ! solver.writeEpilog( logger ) ) - return false; - logger.writeParameter< double >( "IO Real Time:", this -> ioRtTimer. getTime() ); - logger.writeParameter< double >( "IO CPU Time:", this -> ioCpuTimer. getTime() ); - logger.writeParameter< double >( "Compute Real Time:", this -> computeRtTimer. getTime() ); - logger.writeParameter< double >( "Compute CPU Time:", this -> computeCpuTimer. getTime() ); - logger.writeParameter< double >( "Total Real Time:", this -> totalRtTimer. getTime() ); - logger.writeParameter< double >( "Total CPU Time:", this -> totalCpuTimer. getTime() ); + return false; + logger.writeParameter< const char* >( "Compute time:", "" ); + this->computeTimer.writeLog( logger, 1 ); + logger.writeParameter< const char* >( "I/O time:", "" ); + this->ioTimer.writeLog( logger, 1 ); + logger.writeParameter< const char* >( "Total time:", "" ); + this->totalTimer.writeLog( logger, 1 ); char buf[ 256 ]; - sprintf( buf, "%f %%", 100 * ( ( double ) this -> totalCpuTimer. getTime() ) / this -> totalRtTimer. getTime() ); + sprintf( buf, "%f %%", 100 * ( ( double ) this->totalTimer.getCPUTime() ) / this->totalTimer.getRealTime() ); logger.writeParameter< char* >( "CPU usage:", buf ); logger.writeSeparator(); return true; diff --git a/src/solvers/tnlSolver_impl.h b/src/solvers/tnlSolver_impl.h index 33d9b2fe8b794321db5ec0089f459959ed0bfd1e..58c1bce84ffbe1d8b7dc9dec946741c0221453af 100644 --- a/src/solvers/tnlSolver_impl.h +++ b/src/solvers/tnlSolver_impl.h @@ -21,6 +21,7 @@ #include <solvers/tnlSolverInitiator.h> #include <solvers/tnlSolverStarter.h> #include <solvers/tnlSolverConfig.h> +#include <core/tnlCuda.h> template< template< typename Real, typename Device, typename Index, typename MeshType, typename MeshConfig, typename SolverStarter > class ProblemSetter, template< typename MeshConfig > class ProblemConfig, @@ -33,6 +34,10 @@ run( int argc, char* argv[] ) tnlConfigDescription configDescription; ProblemConfig< MeshConfig >::configSetup( configDescription ); tnlSolverConfig< MeshConfig, ProblemConfig< MeshConfig> >::configSetup( configDescription ); + configDescription.addDelimiter( "Parallelization setup:" ); + tnlHost::configSetup( configDescription ); + tnlCuda::configSetup( configDescription ); + if( ! parseCommandLine( argc, argv, configDescription, parameters ) ) return false; diff --git a/tests/benchmarks/heat-equation-benchmark/BenchmarkLaplace.h b/tests/benchmarks/heat-equation-benchmark/BenchmarkLaplace.h index ed76f3e8b4d048fd5327392cf54a6dd8b9bc72a0..76269b7139f3c58d82721652f911297803a3ba26 100644 --- a/tests/benchmarks/heat-equation-benchmark/BenchmarkLaplace.h +++ b/tests/benchmarks/heat-equation-benchmark/BenchmarkLaplace.h @@ -35,15 +35,15 @@ class BenchmarkLaplace< tnlGrid< 1,MeshReal, Device, MeshIndex >, Real, Index > const MeshEntity& entity, const RealType& time = 0.0 ) const; - __cuda_callable__ template< typename MeshEntity > + __cuda_callable__ Index getLinearSystemRowLength( const MeshType& mesh, const IndexType& index, const MeshEntity& entity ) const; template< typename MeshEntity, typename Vector, typename MatrixRow > __cuda_callable__ - void updateLinearSystem( const RealType& time, + void setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -77,15 +77,15 @@ class BenchmarkLaplace< tnlGrid< 2,MeshReal, Device, MeshIndex >, Real, Index > const MeshEntity& entity, const RealType& time = 0.0 ) const; - __cuda_callable__ template< typename MeshEntity > + __cuda_callable__ Index getLinearSystemRowLength( const MeshType& mesh, const IndexType& index, const MeshEntity& entity ) const; template< typename MeshEntity, typename Vector, typename MatrixRow > __cuda_callable__ - void updateLinearSystem( const RealType& time, + void setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -119,15 +119,15 @@ class BenchmarkLaplace< tnlGrid< 3,MeshReal, Device, MeshIndex >, Real, Index > const MeshEntity& entity, const RealType& time = 0.0 ) const; - __cuda_callable__ template< typename MeshEntity > + __cuda_callable__ Index getLinearSystemRowLength( const MeshType& mesh, const IndexType& index, const MeshEntity& entity ) const; template< typename MeshEntity, typename Vector, typename MatrixRow > __cuda_callable__ - void updateLinearSystem( const RealType& time, + void setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, diff --git a/tests/benchmarks/heat-equation-benchmark/BenchmarkLaplace_impl.h b/tests/benchmarks/heat-equation-benchmark/BenchmarkLaplace_impl.h index 862eddc7878509a6dfde868bd31aacc0698db38f..6cec357de6f5a0a5cd5c6ae93668be721d48c559 100644 --- a/tests/benchmarks/heat-equation-benchmark/BenchmarkLaplace_impl.h +++ b/tests/benchmarks/heat-equation-benchmark/BenchmarkLaplace_impl.h @@ -80,7 +80,7 @@ template< typename MeshReal, __cuda_callable__ void BenchmarkLaplace< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -188,7 +188,7 @@ template< typename MeshReal, __cuda_callable__ void BenchmarkLaplace< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, @@ -305,7 +305,7 @@ template< typename MeshReal, __cuda_callable__ void BenchmarkLaplace< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, +setMatrixElements( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, diff --git a/tests/benchmarks/heat-equation-benchmark/HeatEquationBenchmarkProblem_impl.h b/tests/benchmarks/heat-equation-benchmark/HeatEquationBenchmarkProblem_impl.h index 7eb8edb1ed54f60d26d4b649ea1d13a011d552d2..42842c4ab88ac701ad4f50b94d6292bce720fa0b 100644 --- a/tests/benchmarks/heat-equation-benchmark/HeatEquationBenchmarkProblem_impl.h +++ b/tests/benchmarks/heat-equation-benchmark/HeatEquationBenchmarkProblem_impl.h @@ -196,7 +196,7 @@ getExplicitRHS( const RealType& time, ( u[ c - gridXSize ] - 2.0 * u[ c ] + u[ c + gridXSize ] ) * hy_inv ); } - + /*this->bindDofs( mesh, _u ); tnlExplicitUpdater< Mesh, MeshFunctionType, DifferentialOperator, BoundaryCondition, RightHandSide > explicitUpdater; MeshFunctionType u( mesh, _u ); diff --git a/tests/benchmarks/tnl-benchmark-simple-heat-equation.h b/tests/benchmarks/tnl-benchmark-simple-heat-equation.h index 8e9608604e2cf67a2f768dc0d85c6ba234a05944..b30210815a3303fcc0206510c37a6cecdedf94af 100644 --- a/tests/benchmarks/tnl-benchmark-simple-heat-equation.h +++ b/tests/benchmarks/tnl-benchmark-simple-heat-equation.h @@ -22,6 +22,7 @@ #include <stdio.h> #include <config/tnlConfigDescription.h> #include <config/tnlParameterContainer.h> +#include <core/tnlTimer.h> #include <core/tnlTimerRT.h> #include <core/tnlCuda.h> @@ -447,8 +448,8 @@ bool solveHeatEquationHost( const tnlParameterContainer& parameters ) /**** * Initiation */ - Real* u = new Real[ gridXSize * gridYSize ]; - Real* aux = new Real[ gridXSize * gridYSize ]; + Real* __restrict__ u = new Real[ gridXSize * gridYSize ]; + Real* __restrict__ aux = new Real[ gridXSize * gridYSize ]; if( ! u || ! aux ) { cerr << "I am not able to allocate grid function for grid size " << gridXSize << "x" << gridYSize << "." << endl; @@ -484,13 +485,13 @@ bool solveHeatEquationHost( const tnlParameterContainer& parameters ) */ if( verbose ) cout << "Starting the solver main loop..." << endl; - tnlTimerRT timer; - timer.reset(); + tnlTimer timer, computationTimer, updateTimer; timer.start(); Real time( 0.0 ); Index iteration( 0 ); while( time < finalTime ) { + computationTimer.start(); const Real timeLeft = finalTime - time; const Real currentTau = tau < timeLeft ? tau : timeLeft; @@ -524,20 +525,22 @@ bool solveHeatEquationHost( const tnlParameterContainer& parameters ) for( Index i = 1; i < gridXSize - 1; i++ ) { const Index c = j * gridXSize + i; - aux[ c ] = currentTau * ( ( u[ c - 1 ] - 2.0 * u[ c ] + u[ c + 1 ] ) * hx_inv + + aux[ c ] = ( ( u[ c - 1 ] - 2.0 * u[ c ] + u[ c + 1 ] ) * hx_inv + ( u[ c - gridXSize ] - 2.0 * u[ c ] + u[ c + gridXSize ] ) * hy_inv ); } + computationTimer.stop(); - - Real absMax( 0.0 ); + updateTimer.start(); + Real absMax( 0.0 ), residue( 0.0 ); for( Index i = 0; i < dofsCount; i++ ) { - const Real a = fabs( aux[ i ] ); - absMax = a > absMax ? a : absMax; + const Real add = currentTau * aux[ i ]; + u[ i ] += add; + residue += fabs( add ); + /*const Real a = fabs( aux[ i ] ); + absMax = a > absMax ? a : absMax;*/ } - - for( Index i = 0; i < dofsCount; i++ ) - u[ i ] += aux[ i ]; + updateTimer.stop(); time += currentTau; iteration++; @@ -547,7 +550,15 @@ bool solveHeatEquationHost( const tnlParameterContainer& parameters ) timer.stop(); if( verbose ) cout << endl << "Finished..." << endl; - cout << "Computation time is " << timer.getTime() << " sec. i.e. " << timer.getTime() / ( double ) iteration << "sec. per iteration." << endl; + tnlLogger logger( 72, std::cout ); + logger.writeSeparator(); + logger.writeParameter< const char* >( "Compute time:", "" ); + timer.writeLog( logger, 1 ); + logger.writeParameter< const char* >( "Explicit update computation:", "" ); + computationTimer.writeLog( logger, 1 ); + logger.writeParameter< const char* >( "Euler solver update:", "" ); + updateTimer.writeLog( logger, 1 ); + logger.writeSeparator(); /*** * Freeing allocated memory diff --git a/tests/unit-tests/matrices/tnlAdaptiveRgCSRMatrixTester.h b/tests/unit-tests/matrices/tnlAdaptiveRgCSRMatrixTester.h index 89fe32067057ebb976a356826495e77ebeae0d86..c12c8309244bb78779ccc8ef905916e9182a4ad3 100644 --- a/tests/unit-tests/matrices/tnlAdaptiveRgCSRMatrixTester.h +++ b/tests/unit-tests/matrices/tnlAdaptiveRgCSRMatrixTester.h @@ -101,7 +101,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub tnlCSRMatrix< Real > csrMatrix; //( "test-matrix:Empty" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:Empty" ); - this -> setEmptyMatrix( csrMatrix, size ); + this->setEmptyMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -118,7 +118,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub tnlCSRMatrix< Real > csrMatrix; //( "test-matrix:Diagonal" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:Diagonal" ); - this -> setDiagonalMatrix( csrMatrix, size ); + this->setDiagonalMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -135,7 +135,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub //( "test-matrix:Tridiagonal" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:Tridiagonal" ); int size = 12; - this -> setTridiagonalMatrix( csrMatrix, size ); + this->setTridiagonalMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -153,7 +153,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub //( "test-matrix:upperTriangular" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:upperTriangular" ); const int size = 12; - this -> setUpperTriangularMatrix( csrMatrix, size ); + this->setUpperTriangularMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -171,7 +171,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub //( "test-matrix:full" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:full" ); const int size = 12; - this -> setFullMatrix( csrMatrix, size ); + this->setFullMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -189,7 +189,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub //( "test-matrix:bcsstk20" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:bcsstk20" ); const int size = 12; - this -> setBcsstk20Matrix( csrMatrix ); + this->setBcsstk20Matrix( csrMatrix ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -208,7 +208,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub const int size = 35; tnlCSRMatrix< Real > csrMatrix;//( "test-matrix:Empty" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:Empty" ); - this -> setEmptyMatrix( csrMatrix, size ); + this->setEmptyMatrix( csrMatrix, size ); if( Device :: getDevice() == tnlHostDevice ) argcsrMatrix. copyFrom( csrMatrix ); else @@ -238,7 +238,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub const int size = 35; tnlCSRMatrix< Real > csrMatrix;//( "test-matrix:Diagonal" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:Diagonal" ); - this -> setDiagonalMatrix( csrMatrix, size ); + this->setDiagonalMatrix( csrMatrix, size ); if( Device :: getDevice() == tnlHostDevice ) argcsrMatrix. copyFrom( csrMatrix ); else @@ -267,7 +267,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub const int size = 12; tnlCSRMatrix< Real > csrMatrix;//( "test-matrix:TriDiagonal" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:TriDiagonal" ); - this -> setTridiagonalMatrix( csrMatrix, size ); + this->setTridiagonalMatrix( csrMatrix, size ); if( Device :: getDevice() == tnlHostDevice ) argcsrMatrix. copyFrom( csrMatrix ); else @@ -295,7 +295,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub const int size = 12; tnlCSRMatrix< Real > csrMatrix;//( "test-matrix:TriDiagonal" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:TriDiagonal" ); - this -> setUpperTriangularMatrix( csrMatrix, size ); + this->setUpperTriangularMatrix( csrMatrix, size ); if( Device :: getDevice() == tnlHostDevice ) argcsrMatrix. copyFrom( csrMatrix ); else @@ -324,7 +324,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub const int size = 12; tnlCSRMatrix< Real > csrMatrix;//( "test-matrix:full" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:full" ); - this -> setFullMatrix( csrMatrix, size ); + this->setFullMatrix( csrMatrix, size ); if( Device :: getDevice() == tnlHostDevice ) argcsrMatrix. copyFrom( csrMatrix ); else @@ -352,7 +352,7 @@ template< class Real, typename Device > class tnlAdaptiveRgCSRMatrixTester : pub { tnlCSRMatrix< Real > csrMatrix;//( "test-matrix:TriDiagonal" ); tnlAdaptiveRgCSRMatrix< Real, Device > argcsrMatrix( "test-matrix:TriDiagonal" ); - this -> setBcsstk20Matrix( csrMatrix ); + this->setBcsstk20Matrix( csrMatrix ); if( Device :: getDevice() == tnlHostDevice ) argcsrMatrix. copyFrom( csrMatrix ); else diff --git a/tests/unit-tests/matrices/tnlRgCSRMatrixTester.h b/tests/unit-tests/matrices/tnlRgCSRMatrixTester.h index 6b24cbb1b2a04e7837a4a28f0ea18963dcdff30d..52c7260ee7b05939194cc48d9b1755937a7f2ab9 100644 --- a/tests/unit-tests/matrices/tnlRgCSRMatrixTester.h +++ b/tests/unit-tests/matrices/tnlRgCSRMatrixTester.h @@ -95,7 +95,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, const int size = 12; tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; - this -> setEmptyMatrix( csrMatrix, size ); + this->setEmptyMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -111,7 +111,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, const int size = 12; tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; - this -> setDiagonalMatrix( csrMatrix, size ); + this->setDiagonalMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -127,7 +127,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; int size = 12; - this -> setTridiagonalMatrix( csrMatrix, size ); + this->setTridiagonalMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -144,7 +144,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; const int size = 12; - this -> setUpperTriangularMatrix( csrMatrix, size ); + this->setUpperTriangularMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -161,7 +161,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; const int size = 12; - this -> setUpperTriangularMatrix( csrMatrix, size ); + this->setUpperTriangularMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -178,7 +178,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; const int size = 12; - this -> setBcsstk20Matrix( csrMatrix ); + this->setBcsstk20Matrix( csrMatrix ); argcsrMatrix. copyFrom( csrMatrix ); bool error( false ); @@ -195,7 +195,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, const int size = 35; tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; - this -> setEmptyMatrix( csrMatrix, size ); + this->setEmptyMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); tnlVector< T > x, b1, b2; @@ -214,7 +214,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, const int size = 35; tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; - this -> setDiagonalMatrix( csrMatrix, size ); + this->setDiagonalMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); tnlVector< T > x, b1, b2; @@ -233,7 +233,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, const int size = 12; tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; - this -> setTridiagonalMatrix( csrMatrix, size ); + this->setTridiagonalMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); tnlVector< T > x, b1, b2; @@ -252,7 +252,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, const int size = 12; tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; - this -> setUpperTriangularMatrix( csrMatrix, size ); + this->setUpperTriangularMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); tnlVector< T > x, b1, b2; @@ -271,7 +271,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, const int size = 12; tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; - this -> setFullMatrix( csrMatrix, size ); + this->setFullMatrix( csrMatrix, size ); argcsrMatrix. copyFrom( csrMatrix ); tnlVector< T > x, b1, b2; @@ -289,7 +289,7 @@ template< class T > class tnlRgCSRMatrixTester : public CppUnit :: TestCase, { tnlCSRMatrix< T > csrMatrix; tnlRgCSRMatrix< T > argcsrMatrix; - this -> setBcsstk20Matrix( csrMatrix ); + this->setBcsstk20Matrix( csrMatrix ); argcsrMatrix. copyFrom( csrMatrix ); const int size = csrMatrix. getRows(); diff --git a/tests/unit-tests/operators/diffusion/tnlOneSidedMeanCurvatureTest.h b/tests/unit-tests/operators/diffusion/tnlOneSidedMeanCurvatureTest.h index 7a82fed0f79fba18745cc8b8ecb40beaae0bac6b..6b53f3d910a6a962d501fff696d3e3abda7b3bd6 100644 --- a/tests/unit-tests/operators/diffusion/tnlOneSidedMeanCurvatureTest.h +++ b/tests/unit-tests/operators/diffusion/tnlOneSidedMeanCurvatureTest.h @@ -40,7 +40,7 @@ class tnlOneSidedMeanCurvatureTest typedef typename ApproximateOperator::RealType RealType; typedef typename ApproximateOperator::IndexType IndexType; - const IndexType coarseMeshSize[ 3 ] = { 1024, 256, 64 }; + const IndexType coarseMeshSize[ 3 ] = { 128, 256, 64 }; const RealType eoc[ 3 ] = { 2.0, 2.0, 2.0 }; const RealType tolerance[ 3 ] = { 0.05, 0.05, 0.05 }; @@ -65,6 +65,8 @@ class tnlOneSidedMeanCurvatureTest this->setupMesh( meshSize ); ApproximateOperator approximateOperator( this->mesh ); ExactOperatorType exactOperator; + approximateOperator.setRegularizationEpsilon( 1.0 ); + exactOperator.setRegularizationEpsilon( 1.0 ); this->performTest( approximateOperator, exactOperator, errors, @@ -128,7 +130,7 @@ bool setMesh() int main( int argc, char* argv[] ) { const bool verbose( true ); - const bool write( false ); + const bool write( true ); if( ! setMesh< tnlHost, write, verbose >() ) return EXIT_FAILURE; diff --git a/tests/unit-tests/solver/tnlSolverTester.h b/tests/unit-tests/solver/tnlSolverTester.h index 7f374cf242f6b30151ccd431d52d082ffb6f5b60..2a998cb0bd764150f5c7c687dddfee3b88a8d979 100644 --- a/tests/unit-tests/solver/tnlSolverTester.h +++ b/tests/unit-tests/solver/tnlSolverTester.h @@ -47,7 +47,7 @@ class tnlSolverTesterProblem void writeProlog( tnlLogger& logger, const tnlParameterContainer& parameters ) const { }; - bool setup( const tnlParameterContainer& parameters ) { this -> dofVector. setSize( 100 ); return true; }; + bool setup( const tnlParameterContainer& parameters ) { this->dofVector. setSize( 100 ); return true; }; bool setInitialCondition( const tnlParameterContainer& parameters ) { return true; }; @@ -55,7 +55,7 @@ class tnlSolverTesterProblem tnlSolverMonitor< RealType, IndexType >* getSolverMonitor() { return 0; }; - DofVectorType& getDofVector() { return this -> dofVector;}; + DofVectorType& getDofVector() { return this->dofVector;}; void GetExplicitRHS( const RealType& time, const RealType& tau, diff --git a/tools/src/tnl-diff.cpp b/tools/src/tnl-diff.cpp index d46e1563a35a6dc28c0bfd53f215fd0a47e5ac6a..07493f1157332d8105cab3a32554c343f0a0dd8d 100644 --- a/tools/src/tnl-diff.cpp +++ b/tools/src/tnl-diff.cpp @@ -50,12 +50,12 @@ int main( int argc, char* argv[] ) int verbose = parameters. getParameter< int >( "verbose" ); tnlString meshFile = parameters. getParameter< tnlString >( "mesh" ); - if( meshFile == "" ) + /*if( meshFile == "" ) { if( ! processFiles< tnlDummyMesh< double, tnlHost, int > >( parameters ) ) return EXIT_FAILURE; return EXIT_SUCCESS; - } + }*/ tnlString meshType; if( ! getObjectType( meshFile, meshType ) ) { diff --git a/tools/src/tnl-diff.h b/tools/src/tnl-diff.h index c2a49e076f1321f3854b08401792be80bee76bc9..6699647af809d1c752241e5a469dcd9785852bf0 100644 --- a/tools/src/tnl-diff.h +++ b/tools/src/tnl-diff.h @@ -23,9 +23,146 @@ #include <core/mfilename.h> #include <core/vectors/tnlVector.h> #include <core/vectors/tnlStaticVector.h> +#include <functions/tnlMeshFunction.h> template< typename Mesh, typename Element, typename Real, typename Index > -bool computeDifference( const Mesh& mesh, const tnlParameterContainer& parameters ) +bool computeDifferenceOfMeshFunctions( const Mesh& mesh, const tnlParameterContainer& parameters ) +{ + bool verbose = parameters. getParameter< bool >( "verbose" ); + tnlList< tnlString > inputFiles = parameters. getParameter< tnlList< tnlString > >( "input-files" ); + tnlString mode = parameters. getParameter< tnlString >( "mode" ); + tnlString outputFileName = parameters. getParameter< tnlString >( "output-file" ); + double snapshotPeriod = parameters. getParameter< double >( "snapshot-period" ); + bool writeDifference = parameters. getParameter< bool >( "write-difference" ); + + fstream outputFile; + outputFile.open( outputFileName.getString(), std::fstream::out ); + if( ! outputFile ) + { + cerr << "Unable to open the file " << outputFileName << "." << endl; + return false; + } + outputFile << "#"; + outputFile << std::setw( 6 ) << "Time"; + outputFile << std::setw( 18 ) << "L1 diff." + << std::setw( 18 ) << "L2 diff." + << std::setw( 18 ) << "Max. diff." + << std::setw( 18 ) << "Total L1 diff." + << std::setw( 18 ) << "Total L2 diff." + << std::setw( 18 ) << "Total Max. diff." + << endl; + if( verbose ) + cout << endl; + + tnlMeshFunction< Mesh, Mesh::getMeshDimensions(), Real > v1( mesh ), v2( mesh ), diff( mesh ); + Real totalL1Diff( 0.0 ), totalL2Diff( 0.0 ), totalMaxDiff( 0.0 ); + for( int i = 0; i < inputFiles. getSize(); i ++ ) + { + if( mode == "couples" ) + { + if( i + 1 == inputFiles.getSize() ) + { + cerr << endl << "Skipping the file " << inputFiles[ i ] << " since there is no file to couple it with." << endl; + outputFile.close(); + return false; + } + if( verbose ) + cout << "Processing files " << inputFiles[ i ] << " and " << inputFiles[ i + 1 ] << "... \r" << flush; + if( ! v1.load( inputFiles[ i ] ) || + ! v2.load( inputFiles[ i + 1 ] ) ) + { + cerr << "Unable to read the files " << inputFiles[ i ] << " and " << inputFiles[ i + 1 ] << "." << endl; + outputFile.close(); + return false; + } + outputFile << std::setw( 6 ) << i/2 * snapshotPeriod << " "; + i++; + } + if( mode == "sequence" ) + { + if( i == 0 ) + { + if( verbose ) + cout << "Reading the file " << inputFiles[ 0 ] << "... \r" << flush; + if( ! v1.load( inputFiles[ 0 ] ) ) + { + cerr << "Unable to read the file " << inputFiles[ 0 ] << endl; + outputFile.close(); + return false; + } + } + if( verbose ) + cout << "Processing the files " << inputFiles[ 0 ] << " and " << inputFiles[ i ] << "... \r" << flush; + if( ! v2.load( inputFiles[ i ] ) ) + { + cerr << "Unable to read the file " << inputFiles[ 1 ] << endl; + outputFile.close(); + return false; + } + outputFile << std::setw( 6 ) << ( i - 1 ) * snapshotPeriod << " "; + } + if( mode == "halves" ) + { + const int half = inputFiles. getSize() / 2; + if( i == 0 ) + i = half; + if( verbose ) + cout << "Processing files " << inputFiles[ i - half ] << " and " << inputFiles[ i ] << "... \r" << flush; + if( ! v1.load( inputFiles[ i - half ] ) || + ! v2.load( inputFiles[ i ] ) ) + { + cerr << "Unable to read the files " << inputFiles[ i - half ] << " and " << inputFiles[ i ] << "." << endl; + outputFile.close(); + return false; + } + //if( snapshotPeriod != 0.0 ) + outputFile << std::setw( 6 ) << ( i - half ) * snapshotPeriod << " "; + } + diff = v1; + diff -= v2; + Real l1Diff = diff.getLpNorm( 1.0 ); + Real l2Diff = diff.getLpNorm( 2.0 ); + Real maxDiff = diff.getMaxNorm(); + if( snapshotPeriod != 0.0 ) + { + totalL1Diff += snapshotPeriod * l1Diff; + totalL2Diff += snapshotPeriod * l2Diff * l2Diff; + } + else + { + totalL1Diff += l1Diff; + totalL2Diff += l2Diff * l2Diff; + } + totalMaxDiff = Max( totalMaxDiff, maxDiff ); + outputFile << std::setw( 18 ) << l1Diff + << std::setw( 18 ) << l2Diff + << std::setw( 18 ) << maxDiff + << std::setw( 18 ) << totalL1Diff + << std::setw( 18 ) << sqrt( totalL2Diff ) + << std::setw( 18 ) << totalMaxDiff << endl; + + if( writeDifference ) + { + tnlString differenceFileName; + differenceFileName = inputFiles[ i ]; + RemoveFileExtension( differenceFileName ); + differenceFileName += ".diff.tnl"; + //diff.setLike( v1 ); + diff = v1; + diff -= v2; + diff.save( differenceFileName ); + } + } + outputFile.close(); + + if( verbose ) + cout << endl; + return true; +} + + +template< typename Mesh, typename Element, typename Real, typename Index > +bool computeDifferenceOfVectors( const Mesh& mesh, const tnlParameterContainer& parameters ) { bool verbose = parameters. getParameter< bool >( "verbose" ); tnlList< tnlString > inputFiles = parameters. getParameter< tnlList< tnlString > >( "input-files" ); @@ -158,6 +295,16 @@ bool computeDifference( const Mesh& mesh, const tnlParameterContainer& parameter return true; } +template< typename Mesh, typename Element, typename Real, typename Index > +bool computeDifference( const Mesh& mesh, const tnlString& objectType, const tnlParameterContainer& parameters ) +{ + if( objectType == "tnlMeshFunction" ) + return computeDifferenceOfMeshFunctions< Mesh, Element, Real, Index >( mesh, parameters ); + if( objectType == "tnlVector" || objectType == "tnlSharedVector" ) + return computeDifferenceOfVectors< Mesh, Element, Real, Index >( mesh, parameters ); +} + + template< typename Mesh, typename Element, typename Real > bool setIndexType( const Mesh& mesh, const tnlString& inputFileName, @@ -166,16 +313,19 @@ bool setIndexType( const Mesh& mesh, { tnlString indexType; if( parsedObjectType[ 0 ] == "tnlMultiVector" || - parsedObjectType[ 0 ] == "tnlSharedMultiVector" ) + parsedObjectType[ 0 ] == "tnlSharedMultiVector" ) indexType = parsedObjectType[ 4 ]; if( parsedObjectType[ 0 ] == "tnlSharedVector" || parsedObjectType[ 0 ] == "tnlVector" ) indexType = parsedObjectType[ 3 ]; + if(parsedObjectType[ 0 ] == "tnlMeshFunction" ) + return computeDifference< Mesh, Element, Real, typename Mesh::IndexType >( mesh, parsedObjectType[ 0 ], parameters ); + if( indexType == "int" ) - return computeDifference< Mesh, Element, Real, int >( mesh, parameters ); + return computeDifference< Mesh, Element, Real, int >( mesh, parsedObjectType[ 0 ], parameters ); if( indexType == "long-int" ) - return computeDifference< Mesh, Element, Real, long int >( mesh, parameters ); + return computeDifference< Mesh, Element, Real, long int >( mesh, parsedObjectType[ 0 ], parameters ); cerr << "Unknown index type " << indexType << "." << endl; return false; } @@ -241,6 +391,8 @@ bool setElementType( const Mesh& mesh, if( parsedObjectType[ 0 ] == "tnlMultiVector" || parsedObjectType[ 0 ] == "tnlSharedMultiVector" ) elementType = parsedObjectType[ 2 ]; + if( parsedObjectType[ 0 ] == "tnlMeshFunction" ) + elementType = parsedObjectType[ 3 ]; if( parsedObjectType[ 0 ] == "tnlSharedVector" || parsedObjectType[ 0 ] == "tnlVector" ) elementType = parsedObjectType[ 1 ]; diff --git a/tools/tnl-compile.in b/tools/tnl-compile.in index b5bd16e7ae1c88cc5138239211b73170e523a2eb..3ded5560392e047176921d69b35d35a93909fcf8 100644 --- a/tools/tnl-compile.in +++ b/tools/tnl-compile.in @@ -7,7 +7,7 @@ CXX_STD_FLAGS="-std=c++11" for option in "$@" do case $option in - --cuda ) CUDA_FLAGS="-DHAVE_CUDA `tnl-cuda-arch`" ;; + --cuda ) CUDA_FLAGS="-DHAVE_CUDA --std c++11 `tnl-cuda-arch`" ;; --debug ) DEBUG_FLAGS="-g -O0" esac done