Loading src/TNL/SharedPointer.h +37 −34 Original line number Diff line number Diff line Loading @@ -47,13 +47,8 @@ namespace TNL { /*** * Use the lazy mode if you do not want to call the object constructor in the * shared pointer constructor. You may call it later via the method recreate. */ template< typename Object, typename Device = typename Object::DeviceType, bool lazy = false > typename Device = typename Object::DeviceType > class SharedPointer { static_assert( ! std::is_same< Device, void >::value, "The device cannot be void. You need to specify the device explicitly in your code." ); Loading @@ -62,8 +57,8 @@ class SharedPointer /**** * Specialization for Devices::Host */ template< typename Object, bool lazy > class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer template< typename Object > class SharedPointer< Object, Devices::Host > : public SmartPointer { private: // Convenient template alias for controlling the selection of copy- and Loading @@ -75,14 +70,14 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer std::is_same< typename std::remove_cv< Object >::type, Object_ >::value >; // friend class will be needed for templated assignment operators template< typename Object_, typename Device_, bool lazy_ > template< typename Object_, typename Device_ > friend class SharedPointer; public: typedef Object ObjectType; typedef Devices::Host DeviceType; typedef SharedPointer< Object, Devices::Host, lazy > ThisType; typedef SharedPointer< Object, Devices::Host > ThisType; template< typename... Args > explicit SharedPointer( Args... args ) Loading @@ -91,7 +86,6 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer #ifdef TNL_DEBUG_SHARED_POINTERS std::cerr << "Creating shared pointer to " << demangle(typeid(ObjectType).name()) << std::endl; #endif if( ! lazy ) this->allocate( args... ); } Loading @@ -103,9 +97,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer } // conditional constructor for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > SharedPointer( const SharedPointer< Object_, DeviceType, lazy_ >& pointer ) SharedPointer( const SharedPointer< Object_, DeviceType >& pointer ) : pd( (PointerData*) pointer.pd ) { this->pd->counter += 1; Loading @@ -119,9 +113,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer } // conditional constructor for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > SharedPointer( SharedPointer< Object_, DeviceType, lazy_ >&& pointer ) SharedPointer( SharedPointer< Object_, DeviceType >&& pointer ) : pd( (PointerData*) pointer.pd ) { pointer.pd = nullptr; Loading Loading @@ -201,9 +195,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer } // conditional operator for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > const ThisType& operator=( const SharedPointer< Object_, DeviceType, lazy_ >& ptr ) const ThisType& operator=( const SharedPointer< Object_, DeviceType >& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; Loading @@ -221,9 +215,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer } // conditional operator for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > const ThisType& operator=( SharedPointer< Object_, DeviceType, lazy_ >&& ptr ) const ThisType& operator=( SharedPointer< Object_, DeviceType >&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; Loading @@ -236,6 +230,11 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer return true; } void clear() { this->free(); } ~SharedPointer() { this->free(); Loading Loading @@ -282,8 +281,8 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer /**** * Specialization for CUDA */ template< typename Object, bool lazy > class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer template< typename Object > class SharedPointer< Object, Devices::Cuda > : public SmartPointer { private: // Convenient template alias for controlling the selection of copy- and Loading @@ -295,21 +294,20 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer std::is_same< typename std::remove_cv< Object >::type, Object_ >::value >; // friend class will be needed for templated assignment operators template< typename Object_, typename Device_, bool lazy_ > template< typename Object_, typename Device_ > friend class SharedPointer; public: typedef Object ObjectType; typedef Devices::Cuda DeviceType; typedef SharedPointer< Object, Devices::Cuda, lazy > ThisType; typedef SharedPointer< Object, Devices::Cuda > ThisType; template< typename... Args > explicit SharedPointer( Args... args ) : pd( nullptr ), cuda_pointer( nullptr ) { if( ! lazy ) this->allocate( args... ); } Loading @@ -322,9 +320,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer } // conditional constructor for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > SharedPointer( const SharedPointer< Object_, DeviceType, lazy_ >& pointer ) SharedPointer( const SharedPointer< Object_, DeviceType >& pointer ) : pd( (PointerData*) pointer.pd ), cuda_pointer( pointer.cuda_pointer ) { Loading @@ -341,9 +339,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer } // conditional constructor for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > SharedPointer( SharedPointer< Object_, DeviceType, lazy_ >&& pointer ) SharedPointer( SharedPointer< Object_, DeviceType >&& pointer ) : pd( (PointerData*) pointer.pd ), cuda_pointer( pointer.cuda_pointer ) { Loading Loading @@ -450,9 +448,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer } // conditional operator for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > const ThisType& operator=( const SharedPointer< Object_, DeviceType, lazy_ >& ptr ) const ThisType& operator=( const SharedPointer< Object_, DeviceType >& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; Loading @@ -479,9 +477,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer } // conditional operator for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > const ThisType& operator=( SharedPointer< Object_, DeviceType, lazy_ >&& ptr ) const ThisType& operator=( SharedPointer< Object_, DeviceType >&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; Loading Loading @@ -519,6 +517,11 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer #endif } void clear() { this->free(); } ~SharedPointer() { this->free(); Loading src/TNL/Solvers/Linear/BICGStab.h +2 −2 Original line number Diff line number Diff line Loading @@ -39,8 +39,8 @@ class BICGStab : public Object, typedef typename Matrix::DeviceType DeviceType; typedef Matrix MatrixType; typedef Preconditioner PreconditionerType; typedef SharedPointer< const MatrixType, DeviceType, true > MatrixPointer; typedef SharedPointer< const PreconditionerType, DeviceType, true > PreconditionerPointer; typedef SharedPointer< const MatrixType, DeviceType > MatrixPointer; typedef SharedPointer< const PreconditionerType, DeviceType > PreconditionerPointer; BICGStab(); Loading src/TNL/Solvers/Linear/BICGStab_impl.h +5 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,11 @@ template< typename Matrix, typename Preconditioner > BICGStab< Matrix, Preconditioner > :: BICGStab() { /**** * Clearing the shared pointer means that there is no * preconditioner set. */ this->preconditioner.clear(); } template< typename Matrix, Loading src/TNL/Solvers/Linear/CG.h +2 −2 Original line number Diff line number Diff line Loading @@ -38,8 +38,8 @@ class CG : public Object, typedef typename Matrix::DeviceType DeviceType; typedef Matrix MatrixType; typedef Preconditioner PreconditionerType; typedef SharedPointer< const MatrixType, DeviceType, true > MatrixPointer; typedef SharedPointer< const PreconditionerType, DeviceType, true > PreconditionerPointer; typedef SharedPointer< const MatrixType, DeviceType > MatrixPointer; typedef SharedPointer< const PreconditionerType, DeviceType > PreconditionerPointer; CG(); Loading src/TNL/Solvers/Linear/CG_impl.h +5 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,11 @@ template< typename Matrix, typename Preconditioner > CG< Matrix, Preconditioner > :: CG() { /**** * Clearing the shared pointer means that there is no * preconditioner set. */ this->preconditioner.clear(); } template< typename Matrix, Loading Loading
src/TNL/SharedPointer.h +37 −34 Original line number Diff line number Diff line Loading @@ -47,13 +47,8 @@ namespace TNL { /*** * Use the lazy mode if you do not want to call the object constructor in the * shared pointer constructor. You may call it later via the method recreate. */ template< typename Object, typename Device = typename Object::DeviceType, bool lazy = false > typename Device = typename Object::DeviceType > class SharedPointer { static_assert( ! std::is_same< Device, void >::value, "The device cannot be void. You need to specify the device explicitly in your code." ); Loading @@ -62,8 +57,8 @@ class SharedPointer /**** * Specialization for Devices::Host */ template< typename Object, bool lazy > class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer template< typename Object > class SharedPointer< Object, Devices::Host > : public SmartPointer { private: // Convenient template alias for controlling the selection of copy- and Loading @@ -75,14 +70,14 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer std::is_same< typename std::remove_cv< Object >::type, Object_ >::value >; // friend class will be needed for templated assignment operators template< typename Object_, typename Device_, bool lazy_ > template< typename Object_, typename Device_ > friend class SharedPointer; public: typedef Object ObjectType; typedef Devices::Host DeviceType; typedef SharedPointer< Object, Devices::Host, lazy > ThisType; typedef SharedPointer< Object, Devices::Host > ThisType; template< typename... Args > explicit SharedPointer( Args... args ) Loading @@ -91,7 +86,6 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer #ifdef TNL_DEBUG_SHARED_POINTERS std::cerr << "Creating shared pointer to " << demangle(typeid(ObjectType).name()) << std::endl; #endif if( ! lazy ) this->allocate( args... ); } Loading @@ -103,9 +97,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer } // conditional constructor for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > SharedPointer( const SharedPointer< Object_, DeviceType, lazy_ >& pointer ) SharedPointer( const SharedPointer< Object_, DeviceType >& pointer ) : pd( (PointerData*) pointer.pd ) { this->pd->counter += 1; Loading @@ -119,9 +113,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer } // conditional constructor for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > SharedPointer( SharedPointer< Object_, DeviceType, lazy_ >&& pointer ) SharedPointer( SharedPointer< Object_, DeviceType >&& pointer ) : pd( (PointerData*) pointer.pd ) { pointer.pd = nullptr; Loading Loading @@ -201,9 +195,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer } // conditional operator for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > const ThisType& operator=( const SharedPointer< Object_, DeviceType, lazy_ >& ptr ) const ThisType& operator=( const SharedPointer< Object_, DeviceType >& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; Loading @@ -221,9 +215,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer } // conditional operator for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > const ThisType& operator=( SharedPointer< Object_, DeviceType, lazy_ >&& ptr ) const ThisType& operator=( SharedPointer< Object_, DeviceType >&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; Loading @@ -236,6 +230,11 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer return true; } void clear() { this->free(); } ~SharedPointer() { this->free(); Loading Loading @@ -282,8 +281,8 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer /**** * Specialization for CUDA */ template< typename Object, bool lazy > class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer template< typename Object > class SharedPointer< Object, Devices::Cuda > : public SmartPointer { private: // Convenient template alias for controlling the selection of copy- and Loading @@ -295,21 +294,20 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer std::is_same< typename std::remove_cv< Object >::type, Object_ >::value >; // friend class will be needed for templated assignment operators template< typename Object_, typename Device_, bool lazy_ > template< typename Object_, typename Device_ > friend class SharedPointer; public: typedef Object ObjectType; typedef Devices::Cuda DeviceType; typedef SharedPointer< Object, Devices::Cuda, lazy > ThisType; typedef SharedPointer< Object, Devices::Cuda > ThisType; template< typename... Args > explicit SharedPointer( Args... args ) : pd( nullptr ), cuda_pointer( nullptr ) { if( ! lazy ) this->allocate( args... ); } Loading @@ -322,9 +320,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer } // conditional constructor for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > SharedPointer( const SharedPointer< Object_, DeviceType, lazy_ >& pointer ) SharedPointer( const SharedPointer< Object_, DeviceType >& pointer ) : pd( (PointerData*) pointer.pd ), cuda_pointer( pointer.cuda_pointer ) { Loading @@ -341,9 +339,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer } // conditional constructor for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > SharedPointer( SharedPointer< Object_, DeviceType, lazy_ >&& pointer ) SharedPointer( SharedPointer< Object_, DeviceType >&& pointer ) : pd( (PointerData*) pointer.pd ), cuda_pointer( pointer.cuda_pointer ) { Loading Loading @@ -450,9 +448,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer } // conditional operator for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > const ThisType& operator=( const SharedPointer< Object_, DeviceType, lazy_ >& ptr ) const ThisType& operator=( const SharedPointer< Object_, DeviceType >& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; Loading @@ -479,9 +477,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer } // conditional operator for non-const -> const data template< typename Object_, bool lazy_, template< typename Object_, typename = typename Enabler< Object_ >::type > const ThisType& operator=( SharedPointer< Object_, DeviceType, lazy_ >&& ptr ) const ThisType& operator=( SharedPointer< Object_, DeviceType >&& ptr ) { this->free(); this->pd = (PointerData*) ptr.pd; Loading Loading @@ -519,6 +517,11 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer #endif } void clear() { this->free(); } ~SharedPointer() { this->free(); Loading
src/TNL/Solvers/Linear/BICGStab.h +2 −2 Original line number Diff line number Diff line Loading @@ -39,8 +39,8 @@ class BICGStab : public Object, typedef typename Matrix::DeviceType DeviceType; typedef Matrix MatrixType; typedef Preconditioner PreconditionerType; typedef SharedPointer< const MatrixType, DeviceType, true > MatrixPointer; typedef SharedPointer< const PreconditionerType, DeviceType, true > PreconditionerPointer; typedef SharedPointer< const MatrixType, DeviceType > MatrixPointer; typedef SharedPointer< const PreconditionerType, DeviceType > PreconditionerPointer; BICGStab(); Loading
src/TNL/Solvers/Linear/BICGStab_impl.h +5 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,11 @@ template< typename Matrix, typename Preconditioner > BICGStab< Matrix, Preconditioner > :: BICGStab() { /**** * Clearing the shared pointer means that there is no * preconditioner set. */ this->preconditioner.clear(); } template< typename Matrix, Loading
src/TNL/Solvers/Linear/CG.h +2 −2 Original line number Diff line number Diff line Loading @@ -38,8 +38,8 @@ class CG : public Object, typedef typename Matrix::DeviceType DeviceType; typedef Matrix MatrixType; typedef Preconditioner PreconditionerType; typedef SharedPointer< const MatrixType, DeviceType, true > MatrixPointer; typedef SharedPointer< const PreconditionerType, DeviceType, true > PreconditionerPointer; typedef SharedPointer< const MatrixType, DeviceType > MatrixPointer; typedef SharedPointer< const PreconditionerType, DeviceType > PreconditionerPointer; CG(); Loading
src/TNL/Solvers/Linear/CG_impl.h +5 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,11 @@ template< typename Matrix, typename Preconditioner > CG< Matrix, Preconditioner > :: CG() { /**** * Clearing the shared pointer means that there is no * preconditioner set. */ this->preconditioner.clear(); } template< typename Matrix, Loading