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

Code refactoring.

Added parallel reduction to communicators.
parent 703f68bf
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -235,24 +235,24 @@ class MpiCommunicator
#endif  
        }

      /*  template< typename T >
        static void Allreduce( T& data,
                     T& reduced_data,
        template< typename T >
        static 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);
            MPI::COMM_WORLD.Allreduce( (void*) data, (void*) reduced_data,count,MPIDataType(data),op);
        };

        template< typename T >
        static void Reduce( T& data,
                    T& reduced_data,
        static 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);
        };*/
             MPI::COMM_WORLD.Reduce( (void*) data, (void*) reduced_data,count,MPIDataType(data),op,root);
        };

      static void writeProlog( Logger& logger ) 
      {
+19 −13
Original line number Diff line number Diff line
@@ -12,6 +12,12 @@

#include <TNL/Logger.h>

#ifdef HAVE_MPI
#include <mpi.h>
#else
enum MPI_Op { MPI_SUM, MPI_MAX };
#endif

namespace TNL {
namespace Communicators {
        
@@ -96,24 +102,24 @@ class NoDistrCommunicator
      {
      }

     /* template< typename T >
      static void Allreduce( T& data,
                   T& reduced_data,
      template< typename T >
      static 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);
         memcpy( ( void* ) reduced_data, ( void* ) data, count * sizeof( T ) );
      };

      template< typename T >
      static void Reduce( T& data,
                  T& reduced_data,
      static 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);
      };*/
         memcpy( ( void* ) reduced_data, ( void* ) data, count * sizeof( T ) );
      };

      static void writeProlog( Logger& logger ){};
};
+2 −0
Original line number Diff line number Diff line
@@ -5,7 +5,9 @@ SET( headers BufferEntitiesHelper.h
             DistributedGrid_1D.h
             DistributedGrid_1D.hpp
             DistributedGrid_2D.h
             DistributedGrid_2D.hpp
             DistributedGrid_3D.h
             DistributedGrid_3D.hpp
             DistributedGridSynchronizer.h
             DistributedGridIO.h
             )
+70 −65

File changed.

Preview size limit exceeded, changes collapsed.

+4 −1
Original line number Diff line number Diff line
@@ -51,7 +51,8 @@ template< typename RealType, typename Device, typename Index >
   template< typename CommunicatorType>
void
DistributedMesh< Grid< 1, RealType, Device, Index > >::
setGlobalGrid( const GridType& globalGrid, const CoordinatesType& overlap )
setGlobalGrid( const GridType& globalGrid,
               const CoordinatesType& overlap )
{
   this->globalGrid = globalGrid;
   this->isSet = true;
@@ -82,6 +83,7 @@ setGlobalGrid( const GridType& globalGrid, const CoordinatesType& overlap )
       globalDimensions = globalGrid.getDimensions();
       globalBegin = CoordinatesType(0);
       localBegin = CoordinatesType(0);
       this->domainDecomposition[ 0 ];
       return;
   }
   else
@@ -93,6 +95,7 @@ setGlobalGrid( const GridType& globalGrid, const CoordinatesType& overlap )
           right=rank+1;

       this->domainDecomposition[ 0 ] = rank;
       std::cerr << "setting domain decomposition to " << this->domainDecomposition << std::endl;

       globalDimensions=globalGrid.getDimensions();                 

Loading