Commit e2f66b49 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Lazy parameter at SharedPointer was removed.

parent b797dcb5
Loading
Loading
Loading
Loading
+27 −34
Original line number Diff line number Diff line
@@ -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." );
@@ -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
@@ -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 )
@@ -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... );
      }

@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -282,8 +276,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
@@ -295,21 +289,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... );
      }

@@ -322,9 +315,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 )
      {
@@ -341,9 +334,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 )
      {
@@ -450,9 +443,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;
@@ -479,9 +472,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;
+2 −2
Original line number Diff line number Diff line
@@ -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();

+2 −2
Original line number Diff line number Diff line
@@ -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();
+2 −2
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@ public:
   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;
   typedef Containers::Vector< RealType, DeviceType, IndexType > DeviceVector;
   typedef Containers::Vector< RealType, Devices::Host, IndexType > HostVector;

+2 −2
Original line number Diff line number Diff line
@@ -37,8 +37,8 @@ public:
   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;

   GMRES();

Loading