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

Optimized layers of NeighboutGridEntitiesStorage and fixed tnl-benchmark-simple-heat-eqauation.

parent b14a72a0
Loading
Loading
Loading
Loading
+25 −25
Original line number Diff line number Diff line
@@ -17,31 +17,31 @@

namespace TNL {

template< typename T > constexpr T tnlMinValue() { Assert( false, ); return T(); };
template<> constexpr char               tnlMinValue< char >() { return CHAR_MIN; }
template<> constexpr unsigned char      tnlMinValue< unsigned char >() { return 0; }
template<> constexpr short int          tnlMinValue< short int >() { return SHRT_MIN; }
template<> constexpr unsigned short int tnlMinValue< unsigned short int >() { return 0; }
template<> constexpr int                tnlMinValue< int >() { return INT_MIN; }
template<> constexpr unsigned int       tnlMinValue< unsigned int >() { return 0; }
template<> constexpr long int           tnlMinValue< long int >() { return LONG_MIN; }
template<> constexpr unsigned long int  tnlMinValue< unsigned long int >() { return 0; }
template<> constexpr float              tnlMinValue< float >() { return -FLT_MAX; }
template<> constexpr double             tnlMinValue< double >() { return -DBL_MAX; }
template<> constexpr long double        tnlMinValue< long double >() { return -LDBL_MAX; }

template< typename T > constexpr T tnlMaxValue() { Assert( false, ); return T(); };
template<> constexpr char               tnlMaxValue< char >() { return CHAR_MAX; }
template<> constexpr unsigned char      tnlMaxValue< unsigned char >() { return UCHAR_MAX; }
template<> constexpr short int          tnlMaxValue< short int >() { return SHRT_MAX; }
template<> constexpr unsigned short int tnlMaxValue< unsigned short int >() { return USHRT_MAX; }
template<> constexpr int                tnlMaxValue< int >() { return INT_MAX; }
template<> constexpr unsigned int       tnlMaxValue< unsigned int >() { return UINT_MAX; }
template<> constexpr long int           tnlMaxValue< long int >() { return LONG_MAX; }
template<> constexpr unsigned long int  tnlMaxValue< unsigned long int >() { return ULONG_MAX; }
template<> constexpr float              tnlMaxValue< float >() { return FLT_MAX; }
template<> constexpr double             tnlMaxValue< double >() { return DBL_MAX; }
template<> constexpr long double        tnlMaxValue< long double >() { return LDBL_MAX; }
template< typename T > constexpr T MinValue() { return T();};
template<> constexpr char               MinValue< char >() { return CHAR_MIN; }
template<> constexpr unsigned char      MinValue< unsigned char >() { return 0; }
template<> constexpr short int          MinValue< short int >() { return SHRT_MIN; }
template<> constexpr unsigned short int MinValue< unsigned short int >() { return 0; }
template<> constexpr int                MinValue< int >() { return INT_MIN; }
template<> constexpr unsigned int       MinValue< unsigned int >() { return 0; }
template<> constexpr long int           MinValue< long int >() { return LONG_MIN; }
template<> constexpr unsigned long int  MinValue< unsigned long int >() { return 0; }
template<> constexpr float              MinValue< float >() { return -FLT_MAX; }
template<> constexpr double             MinValue< double >() { return -DBL_MAX; }
template<> constexpr long double        MinValue< long double >() { return -LDBL_MAX; }

template< typename T > constexpr T MaxValue() { return T();};
template<> constexpr char               MaxValue< char >() { return CHAR_MAX; }
template<> constexpr unsigned char      MaxValue< unsigned char >() { return UCHAR_MAX; }
template<> constexpr short int          MaxValue< short int >() { return SHRT_MAX; }
template<> constexpr unsigned short int MaxValue< unsigned short int >() { return USHRT_MAX; }
template<> constexpr int                MaxValue< int >() { return INT_MAX; }
template<> constexpr unsigned int       MaxValue< unsigned int >() { return UINT_MAX; }
template<> constexpr long int           MaxValue< long int >() { return LONG_MAX; }
template<> constexpr unsigned long int  MaxValue< unsigned long int >() { return ULONG_MAX; }
template<> constexpr float              MaxValue< float >() { return FLT_MAX; }
template<> constexpr double             MaxValue< double >() { return DBL_MAX; }
template<> constexpr long double        MaxValue< long double >() { return LDBL_MAX; }

} // namespace TNL
+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ reduce( Operation& operation,
         return Multireduction< Devices::Host >::reduce( operation, n, size, hostArray1, ldInput1, hostArray2, hostResult );
      }
      else {
         return Multireduction< Devices::Host >::reduce( operation, n, size, hostArray1, ldInput1, nullptr, hostResult );
         return Multireduction< Devices::Host >::reduce( operation, n, size, hostArray1, ldInput1, ( RealType* ) nullptr, hostResult );
      }
   }

+5 −5
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ class tnlParallelReductionMin
      return min( current, data1[ idx ] );
   };

   __cuda_callable__ ResultType initialValue() { return tnlMaxValue< ResultType>(); };
   __cuda_callable__ ResultType initialValue() { return MaxValue< ResultType>(); };
 
   __cuda_callable__ void cudaFirstReduction( ResultType& result,
                                              const IndexType& index,
@@ -120,7 +120,7 @@ class tnlParallelReductionMax
      return max( current, data1[ idx ] );
   };

   __cuda_callable__ ResultType initialValue() { return tnlMinValue< ResultType>(); };
   __cuda_callable__ ResultType initialValue() { return MinValue< ResultType>(); };
 
   __cuda_callable__ void cudaFirstReduction( ResultType& result,
                                              const IndexType& index,
@@ -273,7 +273,7 @@ class tnlParallelReductionAbsMin : public tnlParallelReductionMin< Real, Index >
      return min( current, abs( data1[ idx ] ) );
   };

   __cuda_callable__ ResultType initialValue() { return tnlMaxValue< ResultType>(); };
   __cuda_callable__ ResultType initialValue() { return MaxValue< ResultType>(); };
 
   __cuda_callable__ void cudaFirstReduction( ResultType& result,
                                              const IndexType& index,
@@ -517,7 +517,7 @@ class tnlParallelReductionDiffMin : public tnlParallelReductionMin< Real, Index
      return min( current, data1[ idx ] - data2[ idx ] );
   };

   __cuda_callable__ ResultType initialValue() { return tnlMaxValue< ResultType>(); };
   __cuda_callable__ ResultType initialValue() { return MaxValue< ResultType>(); };
 
   __cuda_callable__ void cudaFirstReduction( ResultType& result,
                                              const IndexType& index,
@@ -604,7 +604,7 @@ class tnlParallelReductionDiffAbsMin : public tnlParallelReductionMin< Real, Ind
      return min( current, abs( data1[ idx ] - data2[ idx ] ) );
   };

   __cuda_callable__ ResultType initialValue() { return tnlMaxValue< ResultType>(); };
   __cuda_callable__ ResultType initialValue() { return MaxValue< ResultType>(); };
 
   __cuda_callable__ void cudaFirstReduction( ResultType& result,
                                              const IndexType& index,
+66 −9
Original line number Diff line number Diff line
@@ -12,18 +12,26 @@

#include <TNL/Devices/Cuda.h>
#include <TNL/Meshes/MeshDimensionsTag.h>
#include <TNL/Meshes/GridEntityConfig.h>

namespace TNL {
namespace Meshes {

template< typename GridEntity,
          int NeighbourEntityDimensions >
class NeighbourGridEntityLayer
: public NeighbourGridEntityLayer< GridEntity, NeighbourEntityDimensions - 1 >
          int NeighbourEntityDimensions,
          typename GridEntityConfig,
          bool storage = GridEntityConfig::template neighbourEntityStorage< GridEntity >( NeighbourEntityDimensions ) >
class NeighbourGridEntityLayer{};   
   
template< typename GridEntity,
          int NeighbourEntityDimensions,
          typename GridEntityConfig >
class NeighbourGridEntityLayer< GridEntity, NeighbourEntityDimensions, GridEntityConfig, true >
: public NeighbourGridEntityLayer< GridEntity, NeighbourEntityDimensions - 1, GridEntityConfig >
{
   public:
 
      typedef NeighbourGridEntityLayer< GridEntity, NeighbourEntityDimensions - 1 > BaseType;
      typedef NeighbourGridEntityLayer< GridEntity, NeighbourEntityDimensions - 1, GridEntityConfig > BaseType;
      typedef NeighbourGridEntityGetter< GridEntity, NeighbourEntityDimensions > NeighbourEntityGetterType;
 
      using BaseType::getNeighbourEntities;
@@ -53,8 +61,9 @@ class NeighbourGridEntityLayer
      NeighbourEntityGetterType neighbourEntities;
};

template< typename GridEntity >
class NeighbourGridEntityLayer< GridEntity, 0 >
template< typename GridEntity,
          typename GridEntityConfig >
class NeighbourGridEntityLayer< GridEntity, 0, GridEntityConfig, true >
{
   public:
 
@@ -84,11 +93,58 @@ class NeighbourGridEntityLayer< GridEntity, 0 >
 
};

template< typename GridEntity >
template< typename GridEntity,
          int NeighbourEntityDimensions,
          typename GridEntityConfig >
class NeighbourGridEntityLayer< GridEntity, NeighbourEntityDimensions, GridEntityConfig, false >
: public NeighbourGridEntityLayer< GridEntity, NeighbourEntityDimensions - 1, GridEntityConfig >
{
   public:
      
      typedef NeighbourGridEntityLayer< GridEntity, NeighbourEntityDimensions - 1, GridEntityConfig > BaseType;      
      typedef NeighbourGridEntityGetter< GridEntity, NeighbourEntityDimensions > NeighbourEntityGetterType;

      using BaseType::getNeighbourEntities;      
         
      __cuda_callable__
      NeighbourGridEntityLayer( const GridEntity& entity )
      : BaseType( entity )
      {};

      __cuda_callable__
      const NeighbourEntityGetterType& getNeighbourEntities( const MeshDimensionsTag< NeighbourEntityDimensions >& tag ) const {};
 
      __cuda_callable__
      void refresh( const typename GridEntity::GridType& grid,
                    const typename GridEntity::GridType::IndexType& entityIndex ) {};
};

template< typename GridEntity,
          typename GridEntityConfig >
class NeighbourGridEntityLayer< GridEntity, 0, GridEntityConfig, false >
{
   public:
      
      typedef NeighbourGridEntityGetter< GridEntity, 0 > NeighbourEntityGetterType;
         
      __cuda_callable__
      NeighbourGridEntityLayer( const GridEntity& entity ){}

      __cuda_callable__
      const NeighbourEntityGetterType& getNeighbourEntities( const MeshDimensionsTag< 0 >& tag ) const {};
 
      __cuda_callable__
      void refresh( const typename GridEntity::GridType& grid,
                    const typename GridEntity::GridType::IndexType& entityIndex ) {};

};

template< typename GridEntity,
          typename GridEntityConfig >
class NeighbourGridEntitiesStorage
: public NeighbourGridEntityLayer< GridEntity, GridEntity::meshDimensions >
: public NeighbourGridEntityLayer< GridEntity, GridEntity::meshDimensions, GridEntityConfig >
{
   typedef NeighbourGridEntityLayer< GridEntity, GridEntity::meshDimensions > BaseType;
   typedef NeighbourGridEntityLayer< GridEntity, GridEntity::meshDimensions, GridEntityConfig > BaseType;
 
   public:
 
@@ -116,6 +172,7 @@ class NeighbourGridEntitiesStorage
      };      
};


} // namespace Meshes
} // namespace TNL
+4 −4
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ class GridEntity< Meshes::Grid< Dimensions, Real, Device, Index >, EntityDimensi
      typedef GridEntity< GridType, entityDimensions, Config > ThisType;
      typedef typename GridType::VertexType VertexType;
 
      typedef NeighbourGridEntitiesStorage< ThisType > NeighbourGridEntitiesStorageType;
      typedef NeighbourGridEntitiesStorage< ThisType, Config > NeighbourGridEntitiesStorageType;
 
      template< int NeighbourEntityDimensions = entityDimensions >
      using NeighbourEntities =
@@ -187,7 +187,7 @@ class GridEntity< Meshes::Grid< Dimensions, Real, Device, Index >, Dimensions, C
      typedef Containers::StaticVector< meshDimensions, IndexType > EntityOrientationType;
      typedef Containers::StaticVector< meshDimensions, IndexType > EntityBasisType;
      typedef GridEntity< GridType, entityDimensions, Config > ThisType;
      typedef NeighbourGridEntitiesStorage< ThisType > NeighbourGridEntitiesStorageType;
      typedef NeighbourGridEntitiesStorage< ThisType, Config > NeighbourGridEntitiesStorageType;
 
      template< int NeighbourEntityDimensions = entityDimensions >
      using NeighbourEntities =
@@ -309,7 +309,7 @@ class GridEntity< Meshes::Grid< Dimensions, Real, Device, Index >, 0, Config >
      typedef Containers::StaticVector< meshDimensions, IndexType > EntityOrientationType;
      typedef Containers::StaticVector< meshDimensions, IndexType > EntityBasisType;
      typedef GridEntity< GridType, entityDimensions, Config > ThisType;
      typedef NeighbourGridEntitiesStorage< ThisType > NeighbourGridEntitiesStorageType;
      typedef NeighbourGridEntitiesStorage< ThisType, Config > NeighbourGridEntitiesStorageType;
 
      template< int NeighbourEntityDimensions = entityDimensions >
      using NeighbourEntities =
Loading