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

Merge branch 'lbm' into 'develop'

Lbm

See merge request !26
parents 75a4ea7a 42e2e442
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
SET( headers MpiCommunicator.h
             MpiDefs.h
             MPIPrint.h
             MPITypeResolver.h
             NoDistrCommunicator.h
             ScopedInitializer.h
    )
+106 −0
Original line number Diff line number Diff line
/***************************************************************************
                          MPIPrint.h  -  description
                             -------------------
    begin                : Feb 7, 2019
    copyright            : (C) 2019 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once

#include <sstream>
#include <TNL/Communicators/MpiCommunicator.h>

#ifdef HAVE_MPI
#define TNL_MPI_PRINT( message )                                                                                                 \
if( ! TNL::Communicators::MpiCommunicator::IsInitialized() )                                                                     \
   std::cerr << message << std::endl;                                                                                            \
else                                                                                                                             \
{                                                                                                                                \
   if( TNL::Communicators::MpiCommunicator::GetRank() > 0 )                                                                      \
   {                                                                                                                             \
      std::stringstream __tnl_mpi_print_stream_;                                                                                 \
      __tnl_mpi_print_stream_ << "Node " << TNL::Communicators::MpiCommunicator::GetRank() << " of "                             \
         << TNL::Communicators::MpiCommunicator::GetSize() << " : " << message << std::endl;                                     \
      TNL::String __tnl_mpi_print_string_( __tnl_mpi_print_stream_.str().c_str() );                                              \
      __tnl_mpi_print_string_.send( 0, std::numeric_limits< int >::max() );                                                                                         \
   }                                                                                                                             \
   else                                                                                                                          \
   {                                                                                                                             \
      std::cerr << "Node 0 of " << TNL::Communicators::MpiCommunicator::GetSize() << " : " << message << std::endl;              \
      for( int __tnl_mpi_print_j = 1;                                                                                            \
           __tnl_mpi_print_j < TNL::Communicators::MpiCommunicator::GetSize();                                                   \
           __tnl_mpi_print_j++ )                                                                                                 \
         {                                                                                                                       \
            TNL::String __tnl_mpi_print_string_;                                                                                 \
            __tnl_mpi_print_string_.receive( __tnl_mpi_print_j, std::numeric_limits< int >::max() );                                                                \
            std::cerr << __tnl_mpi_print_string_;                                                                                \
         }                                                                                                                       \
   }                                                                                                                             \
}
#else
#define TNL_MPI_PRINT( message )                                                                                                 \
   std::cerr << message << std::endl;
#endif

#ifdef HAVE_MPI
#define TNL_MPI_PRINT_MASTER( message )                                                                                          \
if( ! TNL::Communicators::MpiCommunicator::IsInitialized() )                                                                     \
   std::cerr << message << std::endl;                                                                                            \
else                                                                                                                             \
{                                                                                                                                \
   if( TNL::Communicators::MpiCommunicator::GetRank() == 0 )                                                                     \
   {                                                                                                                             \
      std::cerr << "Master node : " << message << std::endl;                                                                     \
   }                                                                                                                             \
}
#else
#define TNL_MPI_PRINT_MASTER( message )                                                                                          \
   std::cerr << message << std::endl;
#endif

#ifdef HAVE_MPI
#define TNL_MPI_PRINT_COND( condition, message )                                                                                 \
if( ! TNL::Communicators::MpiCommunicator::IsInitialized() )                                                                     \
{                                                                                                                                \
   if( condition) std::cerr << message << std::endl;                                                                             \
}                                                                                                                                \
else                                                                                                                             \
{                                                                                                                                \
   if( TNL::Communicators::MpiCommunicator::GetRank() > 0 )                                                                      \
   {                                                                                                                             \
      int __tnl_mpi_print_cnd = ( condition );                                                                                   \
      TNL::Communicators::MpiCommunicator::Send( &__tnl_mpi_print_cnd, 1, 0, 0 );                                                \
      if( condition ) {                                                                                                          \
         std::stringstream __tnl_mpi_print_stream_;                                                                              \
         __tnl_mpi_print_stream_ << "Node " << TNL::Communicators::MpiCommunicator::GetRank() << " of "                          \
            << TNL::Communicators::MpiCommunicator::GetSize() << " : " << message << std::endl;                                  \
         TNL::String __tnl_mpi_print_string_( __tnl_mpi_print_stream_.str().c_str() );                                           \
         __tnl_mpi_print_string_.send( 0, std::numeric_limits< int >::max() );                                                                                      \
      }                                                                                                                          \
   }                                                                                                                             \
   else                                                                                                                          \
   {                                                                                                                             \
      if( condition )                                                                                                            \
         std::cerr << "Node 0 of " << TNL::Communicators::MpiCommunicator::GetSize() << " : " << message << std::endl;           \
      for( int __tnl_mpi_print_j = 1;                                                                                            \
           __tnl_mpi_print_j < TNL::Communicators::MpiCommunicator::GetSize();                                                   \
           __tnl_mpi_print_j++ )                                                                                                 \
         {                                                                                                                       \
            int __tnl_mpi_print_cond;                                                                                            \
            TNL::Communicators::MpiCommunicator::Recv( &__tnl_mpi_print_cond, 1, __tnl_mpi_print_j, 0 );                         \
            if( __tnl_mpi_print_cond )                                                                                           \
            {                                                                                                                    \
               TNL::String __tnl_mpi_print_string_;                                                                              \
               __tnl_mpi_print_string_.receive( __tnl_mpi_print_j, std::numeric_limits< int >::max() );                                                             \
               std::cerr << __tnl_mpi_print_string_;                                                                             \
            }                                                                                                                    \
         }                                                                                                                       \
   }                                                                                                                             \
}
#else
#define TNL_MPI_PRINT_COND( condition, message )                                                                                 \
   std::cerr << message << std::endl;
#endif
 No newline at end of file
+103 −0
Original line number Diff line number Diff line
/***************************************************************************
                          MPITypeResolver.h  -  description
                             -------------------
    begin                : Feb 4, 2019
    copyright            : (C) 2019 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once

namespace TNL {
namespace Communicators {

#ifdef HAVE_MPI
template<typename Type>
struct MPITypeResolver
{
   static inline MPI_Datatype getType()
   {
      switch( sizeof( Type ) )
      {
         case sizeof( char ):
            return MPI_CHAR;
         case sizeof( int ):
            return MPI_INT;
         case sizeof( short int ):
            return MPI_SHORT;
         case sizeof( long int ):
            return MPI_LONG;
      }
      TNL_ASSERT_TRUE(false, "Fatal Error - Unknown MPI Type");
   };
};

template<> struct MPITypeResolver< char >
{
    static inline MPI_Datatype getType(){return MPI_CHAR;};
};

template<> struct MPITypeResolver< int >
{
    static inline MPI_Datatype getType(){return MPI_INT;};
};

template<> struct MPITypeResolver< short int >
{
    static inline MPI_Datatype getType(){return MPI_SHORT;};
};

template<> struct MPITypeResolver< long int >
{
    static inline MPI_Datatype getType(){return MPI_LONG;};
};

template<> struct MPITypeResolver< unsigned char >
{
    static inline MPI_Datatype getType(){return MPI_UNSIGNED_CHAR;};
};

template<> struct MPITypeResolver< unsigned short int >
{
    static inline MPI_Datatype getType(){return MPI_UNSIGNED_SHORT;};
};

template<> struct MPITypeResolver< unsigned int >
{
    static inline MPI_Datatype getType(){return MPI_UNSIGNED;};
};

template<> struct MPITypeResolver< unsigned long int >
{
    static inline MPI_Datatype getType(){return MPI_UNSIGNED_LONG;};
};

template<> struct MPITypeResolver< float >
{
    static inline MPI_Datatype getType(){return MPI_FLOAT;};
};

template<> struct MPITypeResolver< double >
{
    static inline MPI_Datatype getType(){return MPI_DOUBLE;};
};

template<> struct MPITypeResolver< long double >
{
    static inline MPI_Datatype getType(){return MPI_LONG_DOUBLE;};
};

template<> struct MPITypeResolver< bool >
{
   // sizeof(bool) is implementation-defined: https://stackoverflow.com/a/4897859
   static_assert( sizeof(bool) == 1, "The systems where sizeof(bool) != 1 are not supported by MPI." );
   static inline MPI_Datatype getType() { return MPI_C_BOOL; };
};
#endif
   
   
   
   } // namespace Communicators
} // namespace TNL
+76 −112

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -55,12 +55,12 @@ class NoDistrCommunicator
          return false;
      }

      static int GetRank(CommunicationGroup group)
      static int GetRank(CommunicationGroup group = AllGroup )
      {
          return 0;
      }

      static int GetSize(CommunicationGroup group)
      static int GetSize(CommunicationGroup group = AllGroup )
      {
          return 1;
      }
Loading