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

Improved macro TNL_MPI_RINT to work even wihout MPI.

Added macro TNL_MPI_PRINT_COND for conditional print outs.
parent e99d6c87
Loading
Loading
Loading
Loading
+47 −13
Original line number Diff line number Diff line
@@ -536,7 +536,11 @@ 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++ )                                                                                                    \
@@ -549,4 +553,34 @@ for( int __tnl_mpi_print_j = 0;
      }                                                                                                                          \
      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;                                                                          \
      }                                                                                                                          \
      TNL::Communicators::MpiCommunicator::Barrier( TNL::Communicators::MpiCommunicator::AllGroup );                             \
   }                                                                                                                             \
}
#else
#define TNL_MPI_PRINT_COND( condition, message )                                                                                 \
   if( condition ) std::cerr << message << std::endl;
#endif