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

Implemented String send and receive + reimplemented TNL_MPI_PRINT and TNL_MPI_PRINT_COND.

parent 2f44059b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
SET( headers MpiCommunicator.h
             MpiDefs.h
             MPIPrint.h
             MPITypeResolver.h
             NoDistrCommunicator.h
             ScopedInitializer.h
+0 −48
Original line number Diff line number Diff line
@@ -541,51 +541,3 @@ bool MpiCommunicator::redirect = true;
} // namespace Communicators
} // namespace TNL
#ifdef HAVE_MPI
#define TNL_MPI_PRINT( message )                                                                                                 \
if( ! TNL::Communicators::MpiCommunicator::IsInitialized() )                                                                     \
   std::cerr << message << std::endl;                                                                                            \
else                                                                                                                             \
   for( int __tnl_mpi_print_j = 0;                                                                                               \
        __tnl_mpi_print_j < TNL::Communicators::MpiCommunicator::GetSize( TNL::Communicators::MpiCommunicator::AllGroup );       \
        __tnl_mpi_print_j++ )                                                                                                    \
   {                                                                                                                             \
      if( __tnl_mpi_print_j == TNL::Communicators::MpiCommunicator::GetRank( TNL::Communicators::MpiCommunicator::AllGroup ) )   \
      {                                                                                                                          \
         std::cerr << "Node " << __tnl_mpi_print_j << " of "                                                                     \
                   << TNL::Communicators::MpiCommunicator::GetSize( TNL::Communicators::MpiCommunicator::AllGroup )              \
                   << " : " << message << std::endl << std::flush;                                                                    \
      }                                                                                                                          \
      TNL::Communicators::MpiCommunicator::Barrier( TNL::Communicators::MpiCommunicator::AllGroup );                             \
   }
#else
#define TNL_MPI_PRINT( 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                                                                                                                             \
{                                                                                                                                \
   for( int __tnl_mpi_print_j = 0;                                                                                               \
        __tnl_mpi_print_j < TNL::Communicators::MpiCommunicator::GetSize( TNL::Communicators::MpiCommunicator::AllGroup );       \
        __tnl_mpi_print_j++ )                                                                                                    \
   {                                                                                                                             \
      if( __tnl_mpi_print_j == TNL::Communicators::MpiCommunicator::GetRank( TNL::Communicators::MpiCommunicator::AllGroup ) )   \
      {                                                                                                                          \
         if( condition )                                                                                                         \
            std::cerr << "Node " << __tnl_mpi_print_j << " of "                                                                  \
                      << TNL::Communicators::MpiCommunicator::GetSize( TNL::Communicators::MpiCommunicator::AllGroup )           \
                      << " : " << message << std::endl << std::flush;                                                                          \
      }                                                                                                                          \
      TNL::Communicators::MpiCommunicator::Barrier( TNL::Communicators::MpiCommunicator::AllGroup );                             \
   }                                                                                                                             \
}
#else
#define TNL_MPI_PRINT_COND( condition, message )                                                                                 \
   if( condition ) std::cerr << message << std::endl;
#endif
+2 −2
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#include <TNL/Containers/Array.h>
#include <TNL/Meshes/DistributedMeshes/BufferEntitiesHelper.h>
#include <TNL/Meshes/DistributedMeshes/Directions.h>
#include <TNL/Communicators/MPIPrint.h>

namespace TNL {
namespace Functions{
@@ -123,7 +124,6 @@ class DistributedMeshSynchronizer< Functions::MeshFunction< Grid< MeshDimension,
                  recieveBegin[i]=tmp;
               }
            }

         }
     }

+18 −1
Original line number Diff line number Diff line
@@ -15,6 +15,10 @@
#include <vector>
#include <string>

#ifdef HAVE_MPI
#include <mpi.h>
#endif

namespace TNL {

class String;
@@ -210,8 +214,21 @@ public:
   /// @param separator Character, which separates substrings in given string.
   std::vector< String > split( const char separator = ' ', bool skipEmpty = false ) const;

#ifdef HAVE_MPI

   /****
    * \brief Sends the string to the target MPI process.
    */
   void send( int target, int tag = 0, MPI_Comm mpi_comm = MPI_COMM_WORLD );

   /****
    * \brief Receives a string from the source MPI process.
    */
   void receive( int source, int tag = 0, MPI_Comm mpi_comm = MPI_COMM_WORLD );

   //! Broadcast to other nodes in MPI cluster
   // void MPIBcast( int root, MPI_Comm mpi_comm = MPI_COMM_WORLD );
#endif
};

/// \brief Returns concatenation of \e string1 and \e string2.
+21 −8
Original line number Diff line number Diff line
@@ -13,9 +13,9 @@
#include <TNL/String.h>
#include <TNL/Assert.h>
#include <TNL/Math.h>
//#ifdef USE_MPI
//   #include <mpi.h>
//#endif
#ifdef HAVE_MPI
   #include <mpi.h>
#endif

namespace TNL {

@@ -233,18 +233,32 @@ String::split( const char separator, bool skipEmpty ) const
   return parts;
}

#ifdef HAVE_MPI
inline void String::send( int target, int tag, MPI_Comm mpi_comm )
{
   int size = this->getSize();
   MPI_Send( &size, 1, MPI_INT, target, tag, mpi_comm );
   MPI_Send( this->getString(), this->length(), MPI_CHAR, target, tag, mpi_comm );
}

inline void String::receive( int source, int tag, MPI_Comm mpi_comm )
{
   int size;
   MPI_Status status;
   MPI_Recv( &size, 1, MPI_INT, source, tag, mpi_comm, &status );
   this->setSize( size );
   MPI_Recv( const_cast< void* >( ( const void* ) this->data() ), size, MPI_CHAR, source, tag, mpi_comm,  &status );
}

/*
inline void String :: MPIBcast( int root, MPI_Comm comm )
{
#ifdef USE_MPI
   dbgFunctionName( "mString", "MPIBcast" );
   int iproc;
   MPI_Comm_rank( MPI_COMM_WORLD, &iproc );
   TNL_ASSERT( string, );
   int len = strlen( string );
   MPI_Bcast( &len, 1, MPI_INT, root, comm );
   dbgExpr( iproc );
   dbgExpr( len );
   if( iproc != root )
   {
      if( length < len )
@@ -256,11 +270,10 @@ inline void String :: MPIBcast( int root, MPI_Comm comm )
   }
 
   MPI_Bcast( string, len + 1, MPI_CHAR, root, comm );
   dbgExpr( iproc );
   dbgExpr( string );
#endif
}
*/
#endif

inline String operator+( char string1, const String& string2 )
{