Commit e059f1a1 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Replaced send/receive for Array(,View) and mpiSend/mpiReceive for String with...

Replaced send/receive for Array(,View) and mpiSend/mpiReceive for String with a general implementation in the MPI namespace

Also added analogous functions: MPI::sendrecv, MPI::bcast.
parent 9d33be3e
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -793,13 +793,6 @@ File& operator>>( File& file, Array< Value, Device, Index, Allocator >& array );
template< typename Value, typename Device, typename Index, typename Allocator >
File& operator>>( File&& file, Array< Value, Device, Index, Allocator >& array );

template< typename Value, typename Device, typename Index, typename Allocator >
void send( const Array< Value, Device, Index, Allocator >& array, int dest, int tag = 0, MPI_Comm comm = MPI_COMM_WORLD );

template< typename Value, typename Device, typename Index, typename Allocator >
void receive( Array< Value, Device, Index, Allocator >& array, int src, int tag = 0, MPI_Comm comm = MPI_COMM_WORLD );


} // namespace Containers
} // namespace TNL

+0 −21
Original line number Diff line number Diff line
@@ -845,26 +845,5 @@ File& operator>>( File&& file, Array< Value, Device, Index, Allocator >& array )
   return f >> array;
}

template< typename Value, typename Device, typename Index, typename Allocator >
void send( const Array< Value, Device, Index, Allocator >& array, int dest, int tag, MPI_Comm comm )
{
   send( array.getConstView(), dest, tag, comm );
}

template< typename Value, typename Device, typename Index, typename Allocator >
void receive( Array< Value, Device, Index, Allocator >& array, int src, int tag, MPI_Comm comm )
{
#ifdef HAVE_MPI
   TNL_ASSERT_TRUE( false, "Does not work" );
   MPI_Status status;
   Index size;
   MPI_Recv( ( void* ) size, 1, MPI::getDataType< Index >(), src, tag, comm, &status );
   std::cerr << "Size = " << size << std::endl;
   array.setSize( size );
   MPI_Recv( ( void* ) array.getData(), size * sizeof( Value ), MPI_BYTE, src, tag, comm, &status );
#endif
}


} // namespace Containers
} // namespace TNL
+0 −5
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@
#include <TNL/File.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
#include <TNL/MPI.h>

namespace TNL {
namespace Containers {
@@ -596,10 +595,6 @@ File& operator>>( File& file, ArrayView< Value, Device, Index > view );
template< typename Value, typename Device, typename Index >
File& operator>>( File&& file, ArrayView< Value, Device, Index > view );

template< typename Value, typename Device, typename Index >
void send( const ArrayView< Value, Device, Index >& view, int dest, int tag = 0, MPI_Comm comm = MPI_COMM_WORLD );


} // namespace Containers
} // namespace TNL

+0 −12
Original line number Diff line number Diff line
@@ -472,17 +472,5 @@ File& operator>>( File&& file, ArrayView< Value, Device, Index > view )
   return f >> view;
}

template< typename Value, typename Device, typename Index >
void send( const ArrayView< Value, Device, Index >& view, int dest, int tag, MPI_Comm comm )
{
#ifdef HAVE_MPI
   TNL_ASSERT_TRUE( false, "Does not work" );
   auto size = view.getSize();
   MPI_Send( ( const void* ) size, 1, MPI::getDataType< Index >(), dest, tag, comm );
   MPI_Send( ( const void* ) view.getData(), view.getSize() * sizeof( Value ), MPI_BYTE, dest, tag, comm );
#endif
}


} // namespace Containers
} // namespace TNL
+5 −5
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
#include <sstream>

#include <TNL/String.h>
#include <TNL/MPI/Wrappers.h>
#include <TNL/MPI/Utils.h>

#ifdef HAVE_MPI
#define TNL_MPI_PRINT( message )                                                                                                 \
@@ -28,7 +28,7 @@ else
      __tnl_mpi_print_stream_ << "Node " << TNL::MPI::GetRank() << " of " << TNL::MPI::GetSize() << " : "                        \
                              << message << std::endl;                                                                           \
      TNL::String __tnl_mpi_print_string_( __tnl_mpi_print_stream_.str() );                                                      \
      mpiSend( __tnl_mpi_print_string_, 0, std::numeric_limits< int >::max() );                                                  \
      TNL::MPI::send( __tnl_mpi_print_string_, 0, std::numeric_limits< int >::max() );                                           \
   }                                                                                                                             \
   else                                                                                                                          \
   {                                                                                                                             \
@@ -36,7 +36,7 @@ else
      for( int __tnl_mpi_print_j = 1; __tnl_mpi_print_j < TNL::MPI::GetSize(); __tnl_mpi_print_j++ )                             \
      {                                                                                                                          \
         TNL::String __tnl_mpi_print_string_;                                                                                    \
         mpiReceive( __tnl_mpi_print_string_, __tnl_mpi_print_j, std::numeric_limits< int >::max() );                            \
         TNL::MPI::recv( __tnl_mpi_print_string_, __tnl_mpi_print_j, std::numeric_limits< int >::max() );                        \
         std::cerr << __tnl_mpi_print_string_;                                                                                   \
      }                                                                                                                          \
   }                                                                                                                             \
@@ -79,7 +79,7 @@ else
         __tnl_mpi_print_stream_ << "Node " << TNL::MPI::GetRank() << " of " << TNL::MPI::GetSize() << " : "                     \
                                 << message << std::endl;                                                                        \
         TNL::String __tnl_mpi_print_string_( __tnl_mpi_print_stream_.str() );                                                   \
         mpiSend( __tnl_mpi_print_string_, 0, std::numeric_limits< int >::max() );                                               \
         TNL::MPI::send( __tnl_mpi_print_string_, 0, std::numeric_limits< int >::max() );                                        \
      }                                                                                                                          \
   }                                                                                                                             \
   else                                                                                                                          \
@@ -93,7 +93,7 @@ else
            if( __tnl_mpi_print_cond )                                                                                           \
            {                                                                                                                    \
               TNL::String __tnl_mpi_print_string_;                                                                              \
               mpiReceive( __tnl_mpi_print_string_, __tnl_mpi_print_j, std::numeric_limits< int >::max() );                      \
               TNL::MPI::recv( __tnl_mpi_print_string_, __tnl_mpi_print_j, std::numeric_limits< int >::max() );                  \
               std::cerr << __tnl_mpi_print_string_;                                                                             \
            }                                                                                                                    \
         }                                                                                                                       \
Loading