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

Code refactoring.

Added command line arguments for a grid domain decomposition setup.
parent c15c9fe9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -73,6 +73,11 @@ class MpiCommunicator
#endif         
      }
      
      static void setRedirection( bool redirect_ )
      {
         redirect = redirect_;
      }
      
      static void setupRedirection()
      {
         if(isDistributed() && redirect )
+6 −4
Original line number Diff line number Diff line
@@ -35,11 +35,13 @@ class NoDistrCommunicator
      static void Init(int argc, char **argv, bool redirect=false)
      {
          NullRequest=-1;
      };
      }
      
      static void Finalize()
      {
      };
      static void setRedirection( bool redirect_ ) {}
      
      static void setupRedirection(){}

      static void Finalize(){}

      static bool IsInitialized()
      {   
+19 −2
Original line number Diff line number Diff line
@@ -33,9 +33,21 @@ class DistributedMesh<Grid< 1, RealType, Device, Index >>
      DistributedMesh()
      : isSet(false ){};

      bool setup( const Config::ParameterContainer& parameters,
                  const String& prefix )
      {
         this->domainDecomposition.x() = parameters.getParameter< int >( "grid-domain-decomposition-x" );
         return true;
      }      
      
      void setDomainDecomposition( const CoordinatesType& domainDecomposition )
      {
         this->domainDecomposition = domainDecomposition;
      }
      
      const CoordinatesType& getDomainDecomposition()
      {
         return this->rank;
         return this->domainDecomposition;
      }
      
      template<typename CommunicatorType>
@@ -86,6 +98,8 @@ class DistributedMesh<Grid< 1, RealType, Device, Index >>
             if(rank!=nproc-1)
                 right=rank+1;
             
             this->domainDecomposition[ 0 ] = rank;

             globalSize=globalGrid.getDimensions();                 

             //compute local mesh size               
@@ -223,6 +237,9 @@ class DistributedMesh<Grid< 1, RealType, Device, Index >>
      int rank;
      int nproc;
      
      CoordinatesType domainDecomposition;
      CoordinatesType subdomainCoordinates;      
        
      int numberOfLarger;
        
      int left;
+20 −14
Original line number Diff line number Diff line
@@ -33,17 +33,30 @@ class DistributedMesh<Grid< 2, RealType, Device, Index >>
     
   public:
      DistributedMesh()
      : isSet( false ) {};
      : isSet( false ), domainDecomposition( 0 ) {};
      
      void setDomainDecomposition( const CoordinatesType& domainDecomposition )
      {
         this->domainDecomposition = domainDecomposition;
      }
      
      const CoordinatesType getDomainDecomposition()
      {
         return this->domainDecomposition;
      }

      bool setup( const Config::ParameterContainer& parameters,
                  const String& prefix )
      {
         this->domainDecomposition.x() = parameters.getParameter< int >( "grid-domain-decomposition-x" );
         this->domainDecomposition.y() = parameters.getParameter< int >( "grid-domain-decomposition-y" );
         return true;
      }      

      
      template< typename CommunicatorType >
      void setGlobalGrid( GridType &globalGrid,
                          CoordinatesType overlap,
                          int *distribution=NULL )
                          CoordinatesType overlap )
      {
         isSet=true;

@@ -85,17 +98,10 @@ class DistributedMesh<Grid< 2, RealType, Device, Index >>
         }
         else
         {
            //compute node distribution
            int dims[ 2 ];
            if(distribution!=NULL)
            {
               dims[0]=distribution[0];
               dims[1]=distribution[1];
            }
            else
            {
               dims[0]=0;
               dims[1]=0;
            }
            dims[ 0 ] = domainDecomposition[ 0 ];
            dims[ 1 ] = domainDecomposition[ 1 ];

            CommunicatorType::DimsCreate( nproc, 2, dims );
            domainDecomposition[ 0 ] = dims[ 0 ];
+27 −15
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@

#pragma once

#include <TNL/Config/ConfigDescription.h>
#include <TNL/Meshes/Grid.h>

namespace TNL {
@@ -41,6 +42,27 @@ class DistributedMesh<Grid< 3, RealType, Device, Index >>
      DistributedMesh()
      : isSet( false ) {};
      
      static void configSetup( Config::ConfigDescription& config )
      {
         config.addEntry< int >( "grid-domain-decomposition-x", "Number of grid subdomains along x-axis.", 0 );
         config.addEntry< int >( "grid-domain-decomposition-y", "Number of grid subdomains along y-axis.", 0 );
         config.addEntry< int >( "grid-domain-decomposition-z", "Number of grid subdomains along z-axis.", 0 );
      }
      
      bool setup( const Config::ParameterContainer& parameters,
                  const String& prefix )
      {
         this->domainDecomposition.x() = parameters.getParameter< int >( "grid-domain-decomposition-x" );
         this->domainDecomposition.y() = parameters.getParameter< int >( "grid-domain-decomposition-y" );
         this->domainDecomposition.z() = parameters.getParameter< int >( "grid-domain-decomposition-z" );
         return true;
      }      
      
      void setDomainDecomposition( const CoordinatesType& domainDecomposition )
      {
         this->domainDecomposition = domainDecomposition;
      }      
      
      const CoordinatesType& getDomainDecomposition()
      {
         return this->domainDecomposition;
@@ -48,8 +70,7 @@ class DistributedMesh<Grid< 3, RealType, Device, Index >>

      template< typename CommunicatorType > 
      void setGlobalGrid( GridType &globalGrid,
                          CoordinatesType overlap,
                           int *distribution=NULL )
                          CoordinatesType overlap )
      {
         isSet=true;           

@@ -99,18 +120,9 @@ class DistributedMesh<Grid< 3, RealType, Device, Index >>
            //With MPI
            //compute node distribution
            int dims[ 3 ];
            if(distribution!=NULL)
            {
               dims[ 0 ] = distribution[ 0 ];
               dims[ 1 ] = distribution[ 1 ];
               dims[ 2 ] = distribution[ 2 ];
            }
            else
            {
               dims[ 0 ] = 0;
               dims[ 1 ] = 0;
               dims[ 2 ] = 0;
            }
            dims[ 0 ] = domainDecomposition[ 0 ];
            dims[ 1 ] = domainDecomposition[ 1 ];
            dims[ 2 ] = domainDecomposition[ 2 ];
            
            CommunicatorType::DimsCreate( nproc, 3, dims );
            domainDecomposition[ 0 ] = dims[ 0 ];
@@ -258,7 +270,7 @@ class DistributedMesh<Grid< 3, RealType, Device, Index >>
         TNL_ASSERT_TRUE(isSet,"DistributedGrid is not set, but used by SetupGrid");
         grid.setOrigin(localOrigin);
         grid.setDimensions(localGridSize);
         //compute local proporions by sideefect
         //compute local proportions by side efect
         grid.setSpaceSteps(spaceSteps);
         grid.SetDistMesh(this);
      };
Loading