Commit 02c76403 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Refactoring: remove DirectionCount, rename pow3 in Directions to i3pow

parent e60499c2
Loading
Loading
Loading
Loading
+22 −54
Original line number Diff line number Diff line
@@ -110,20 +110,19 @@ public:
        return result-1;
    }*/

    static int add(int direction)
    static constexpr int add(int direction)
    {
        if(direction==0)
            return 0;

        if(direction>0)
            return 2*pow3(direction-1); //positive direction has higer index
            return 2*i3pow(direction-1); //positive direction has higer index
        else
            return pow3(-direction-1);


            return i3pow(-direction-1);
    }

    static int pow3(int exp)
    // return 3^exp
    static constexpr int i3pow(int exp)
    {
        int ret=1;
        for(int i=0;i<exp;i++)
@@ -132,37 +131,6 @@ public:
    }
};

//for c++11 -- in c++14 simply 3^dim-1
template<int dim>
class DirectionCount
{
public:
    static constexpr int get(){return 0;}
};

template <>
class DirectionCount<1>
{
public:
    static constexpr int get(){return 2;}
};

template <>
class DirectionCount<2>
{
public:
    static constexpr int get(){return 8;}
};

template <>
class DirectionCount<3>
{
public:
    static constexpr int get(){return 26;}
};


} // namespace DistributedMeshes
} // namespace Meshes
} // namespace TNL
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ class DistributedMesh< Grid< Dimension, Real, Device, Index > >

      static constexpr int getMeshDimension() { return Dimension; };

      static constexpr int getNeighborsCount() { return DirectionCount<Dimension>::get(); } //c++14 may use Directions::pow3(Dimension)-1
      static constexpr int getNeighborsCount() { return Directions::i3pow(Dimension)-1; }

      DistributedMesh();

+15 −17
Original line number Diff line number Diff line
@@ -30,14 +30,14 @@ template< int MeshDimension,
class DistributedMeshSynchronizer< DistributedMesh< Grid< MeshDimension, GridReal, Device, Index > >, MeshDimension >
{
   public:
      static constexpr int getMeshDimension() { return MeshDimension; };
      static constexpr int getNeighborCount() {return DirectionCount<MeshDimension>::get();};

      typedef typename Grid< MeshDimension, GridReal, Device, Index >::Cell Cell;
      typedef typename Grid< MeshDimension, GridReal, Device, Index >::DistributedMeshType DistributedGridType;
      typedef typename DistributedGridType::CoordinatesType CoordinatesType;
      using SubdomainOverlapsType = typename DistributedGridType::SubdomainOverlapsType;

      static constexpr int getMeshDimension() { return DistributedGridType::getMeshDimension(); };
      static constexpr int getNeighborsCount() { return DistributedGridType::getNeighborsCount(); };

      enum PeriodicBoundariesCopyDirection
      {
         BoundaryToOverlap,
@@ -74,7 +74,7 @@ class DistributedMeshSynchronizer< DistributedMesh< Grid< MeshDimension, GridRea

         const int *neighbors = distributedGrid->getNeighbors();

         for( int i=0; i<this->getNeighborCount(); i++ )
         for( int i=0; i<this->getNeighborsCount(); i++ )
         {
            Index sendSize=1;//send and receive  areas have the same size

@@ -126,7 +126,7 @@ class DistributedMeshSynchronizer< DistributedMesh< Grid< MeshDimension, GridRea
         if( !distributedGrid->isDistributed() ) return;

         // allocate buffers (setSize does nothing if the array size is already correct)
         for( int i=0; i<this->getNeighborCount(); i++ ) {
         for( int i=0; i<this->getNeighborsCount(); i++ ) {
            sendBuffers[ i ].setSize( sendSizes[ i ] * sizeof(RealType) );
            recieveBuffers[ i ].setSize( sendSizes[ i ] * sizeof(RealType));
         }
@@ -143,12 +143,12 @@ class DistributedMeshSynchronizer< DistributedMesh< Grid< MeshDimension, GridRea
            PeriodicBoundariesMaskPointer( nullptr ) ); // the mask is used only when receiving data );

         //async send and receive
         MPI_Request requests[2*this->getNeighborCount()];
         MPI_Request requests[2*this->getNeighborsCount()];
         MPI_Comm group = distributedGrid->getCommunicationGroup();
         int requestsCount( 0 );

         //send everything, recieve everything
         for( int i=0; i<this->getNeighborCount(); i++ )
         for( int i=0; i<this->getNeighborsCount(); i++ )
         {
            /*TNL_MPI_PRINT( "Sending data... " << i << " sizes -> "
               << sendSizes[ i ] << "sendDimensions -> " <<  sendDimensions[ i ]
@@ -199,7 +199,7 @@ class DistributedMeshSynchronizer< DistributedMesh< Grid< MeshDimension, GridRea
         using RealType = typename MeshFunctionType::RealType;
         using Helper = BufferEntitiesHelper< MeshFunctionType, PeriodicBoundariesMaskPointer, getMeshDimension(), RealType, Device >;

         for(int i=0;i<this->getNeighborCount();i++)
         for(int i=0;i<this->getNeighborsCount();i++)
         {
            bool isBoundary=( neighbor[ i ] == -1 );
            if( ! isBoundary || periodicBoundaries )
@@ -211,24 +211,22 @@ class DistributedMeshSynchronizer< DistributedMesh< Grid< MeshDimension, GridRea

   private:

      Containers::StaticArray< getNeighborCount(), int > sendSizes;
      Containers::Array< std::uint8_t, Device, Index > sendBuffers[getNeighborCount()];
      Containers::Array< std::uint8_t, Device, Index > recieveBuffers[getNeighborCount()];
      Containers::StaticArray< getNeighborsCount(), int > sendSizes;
      Containers::Array< std::uint8_t, Device, Index > sendBuffers[getNeighborsCount()];
      Containers::Array< std::uint8_t, Device, Index > recieveBuffers[getNeighborsCount()];

      PeriodicBoundariesCopyDirection periodicBoundariesCopyDirection = BoundaryToOverlap;

      CoordinatesType sendDimensions[getNeighborCount()];
      CoordinatesType recieveDimensions[getNeighborCount()];
      CoordinatesType sendBegin[getNeighborCount()];
      CoordinatesType recieveBegin[getNeighborCount()];
      CoordinatesType sendDimensions[getNeighborsCount()];
      CoordinatesType recieveDimensions[getNeighborsCount()];
      CoordinatesType sendBegin[getNeighborsCount()];
      CoordinatesType recieveBegin[getNeighborsCount()];

      DistributedGridType *distributedGrid;

      bool isSet;
};


} // namespace DistributedMeshes
} // namespace Meshes
} // namespace TNL