Commit 57905d13 authored by Vít Hanousek's avatar Vít Hanousek
Browse files

Introduction of Communicators and DistributedMesh.

Only MPICommunicator and DistributedGrid is implemented.
parent 85f0dae7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
ADD_SUBDIRECTORY( Config )
ADD_SUBDIRECTORY( Containers )
ADD_SUBDIRECTORY( Communicators )
ADD_SUBDIRECTORY( Debugging )
ADD_SUBDIRECTORY( Devices )
ADD_SUBDIRECTORY( Exceptions )
@@ -31,7 +32,6 @@ set( headers
     Logger.h
     Logger_impl.h
     Math.h
     mpi-supp.h
     ParallelFor.h
     param-types.h
     SharedPointer.h
+4 −0
Original line number Diff line number Diff line
SET( headers MpiCommunicator.h
             NoDistrCommunicator.h )

INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/TNL/Communicators )
+126 −0
Original line number Diff line number Diff line
/***************************************************************************
                          MpiCommunicator.h  -  description
                             -------------------
    begin                : 2005/04/23
    copyright            : (C) 2005 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once

#ifdef HAVE_MPI

#include <mpi.h>

namespace TNL {
namespace Communicators {
        
    class MpiCommunicator
    {

        private:
        inline MPI_Datatype MPIDataType( const signed char ) { return MPI_CHAR; };
        inline MPI_Datatype MPIDataType( const signed short int ) { return MPI_SHORT; };
        inline MPI_Datatype MPIDataType( const signed int ) { return MPI_INT; };
        inline MPI_Datatype MPIDataType( const signed long int ) { return MPI_LONG; };
        inline MPI_Datatype MPIDataType( const unsigned char ) { return MPI_UNSIGNED_CHAR; };
        inline MPI_Datatype MPIDataType( const unsigned short int ) { return MPI_UNSIGNED_SHORT; };
        inline MPI_Datatype MPIDataType( const unsigned int ) { return MPI_UNSIGNED; };
        inline MPI_Datatype MPIDataType( const unsigned long int ) { return MPI_UNSIGNED_LONG; };
        inline MPI_Datatype MPIDataType( const float ) { return MPI_FLOAT; };
        inline MPI_Datatype MPIDataType( const double ) { return MPI_DOUBLE; };
        inline MPI_Datatype MPIDataType( const long double ) { return MPI_LONG_DOUBLE; };
        
        public:

        typedef MPI::Request Request;
        MPI::Request NullRequest;

        void Init(int argc, char **argv)
        {
            MPI::Init(argc,argv);
            NullRequest=MPI::REQUEST_NULL;
        };

        void Finalize()
        {
            MPI::Finalize();
        };

        bool IsInitialized()
        {
            return MPI::Is_initialized();
        };

        int GetRank()
        {
            return MPI::COMM_WORLD.Get_rank();
        };

        int GetSize()
        {
            return MPI::COMM_WORLD.Get_size();
        };

        //dim-number of dimesions, distr array of guess distr - 0 for computation
        //distr array will be filled by computed distribution
        //more information in MPI documentation
        void DimsCreate(int nproc, int dim, int *distr)
        {
            MPI_Dims_create(nproc, dim, distr);
        };

        void Barrier()
        {
            MPI::COMM_WORLD.Barrier();
        };

        template <typename T>
        Request ISend( const T *data, int count, int dest)
        {
                return MPI::COMM_WORLD.Isend((void*) data, count, MPIDataType(*data) , dest, 0);
        };    

        template <typename T>
        Request IRecv( const T *data, int count, int src)
        {
                return MPI::COMM_WORLD.Irecv((void*) data, count, MPIDataType(*data) , src, 0);
        };

        void WaitAll(Request *reqs, int length)
        {
                MPI::Request::Waitall(length, reqs);
        };

        template< typename T > 
        void Bcast(  T& data, int count, int root)
        {
                MPI::COMM_WORLD.Bcast((void*) &data, count,  MPIDataType(data), root);
        };

      /*  template< typename T >
        void Allreduce( T& data,
                     T& reduced_data,
                     int count,
                     const MPI_Op &op)
        {
                MPI::COMM_WORLD.Allreduce((void*) &data, (void*) &reduced_data,count,MPIDataType(data),op);
        };

        template< typename T >
        void Reduce( T& data,
                    T& reduced_data,
                    int count,
                    MPI_Op &op,
                    int root)
        {
             MPI::COMM_WORLD.Reduce((void*) &data, (void*) &reduced_data,count,MPIDataType(data),op,root);
        };*/
    };

}//namespace Communicators
} // namespace TNL

#endif
+104 −0
Original line number Diff line number Diff line
/***************************************************************************
                          NoDistrCommunicator.h  -  description
                             -------------------
    begin                : 2018/01/09
    copyright            : (C) 2018 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once

namespace TNL {
namespace Communicators {
        
    class NoDistrCommunicator
    {


        public:

        typedef int Request;
        Request NullRequest;

        void Init(int argc, char **argv)
        {
        };

        void Finalize()
        {
        };

        bool IsInitialized()
        {   
            return true;
        };

        int GetRank()
        {
            return 0;
        };

        int GetSize()
        {
            return 1;
        };

        void DimsCreate(int nproc, int dim, int *distr)
        {
            for(int i=0;i<dim;i++)
            {
                distr[i]=1;
            }
        };

        void Barrier()
        {
        };

        template <typename T>
        Request ISend( const T *data, int count, int dest)
        {
            return 1;
        };    

        template <typename T>
        Request IRecv( const T *data, int count, int src)
        {
            return 1;
        };

        void WaitAll(Request *reqs, int length)
        {
        };

        template< typename T > 
        void Bcast(  T& data, int count, int root)
        {
        };

       /* template< typename T >
        void Allreduce( T& data,
                     T& reduced_data,
                     int count,
                     const MPI_Op &op)
        {
                MPI::COMM_WORLD.Allreduce((void*) &data, (void*) &reduced_data,count,MPIDataType(data),op);
        };

        template< typename T >
        void Reduce( T& data,
                    T& reduced_data,
                    int count,
                    MPI_Op &op,
                    int root)
        {
             MPI::COMM_WORLD.Reduce((void*) &data, (void*) &reduced_data,count,MPIDataType(data),op,root);
        };*/
    };

} // namespace Communicators
} // namespace TNL

+10 −11
Original line number Diff line number Diff line
@@ -13,8 +13,8 @@
#include <TNL/Functions/MeshFunctionGnuplotWriter.h>
#include <TNL/Functions/MeshFunctionVTKWriter.h>
#include <TNL/SharedPointer.h>
#include <TNL/Meshes/DistributedGrid.h>
#include <TNL/Meshes/DistributedGridSynchronizer.h>
#include <TNL/Meshes/DistributedMeshes/DistributedMesh.h>
#include <TNL/Meshes/DistributedMeshes/DistributedMeshSynchronizer.h>

#pragma once

@@ -39,6 +39,8 @@ class MeshFunction :
      typedef Real RealType;
      typedef Containers::Vector< RealType, DeviceType, IndexType > VectorType;
      typedef Functions::MeshFunction< Mesh, MeshEntityDimension, Real > ThisType;
      typedef Meshes::DistributedMeshes::DistributedMesh<MeshType> DistributedMeshType;
      typedef Meshes::DistributedMeshes::DistributedMeshSynchronizer<ThisType> DistributedMeshSynchronizerType;
 
      static constexpr int getEntitiesDimension() { return MeshEntityDimension; }
      
@@ -158,15 +160,13 @@ class MeshFunction :
 
      using Object::boundLoad;

#ifdef USE_MPI
      void synchronize(void);    
#endif
      template< typename Communicator>
      void Synchronize(Communicator &comm);    

 
   protected:

#ifdef USE_MPI
      Meshes::DistributedGridSynchronizer<Meshes::DistributedGrid<MeshType>,ThisType> synchronizer;    
#endif
      DistributedMeshSynchronizerType synchronizer;    
      
      MeshPointer meshPointer;
      
@@ -174,10 +174,9 @@ class MeshFunction :
 
      template< typename, typename > friend class MeshFunctionEvaluator;

#ifdef USE_MPI
   private:
      void SetupSynchronizer(Meshes::DistributedGrid<Mesh> *distrgrid);
#endif   
      void SetupSynchronizer(DistributedMeshType *distrMesh);
   
};

} // namespace Functions
Loading