48 #ifndef COMM_MPI_SMART_H
49 #define COMM_MPI_SMART_H
53 #include "../general/util.h"
58 #include "../storage/stream.h"
64 std::list<std::pair<MPI_Request,std::shared_ptr<std::vector<char> > > > send_buf;
67 comm_mpi_smart(
const char URI[],
const bool quiet, MPI_Comm world = MPI_COMM_WORLD ) :
comm_mpi(URI, quiet, world) {}
70 test_completion_blocking();
74 void send_impl_(
message msg,
const std::vector<bool> &is_sending ) {
75 auto bytes = std::vector<char>(msg.
detach());
77 if(bytes.size() > INT_MAX) {
78 std::cerr <<
"MUI Error [comm_mpi_smart.h]: Trying to send more data than is possible with MPI_Isend." << std::endl
79 <<
"This is likely because there is too much data per MPI rank." << std::endl
80 <<
"The program will now abort. Try increasing the number of MPI ranks." << std::endl;
86 send_buf.emplace_back(MPI_Request(), std::make_shared<std::vector<char> >(bytes));
87 MPI_Isend(send_buf.back().second->data(), send_buf.back().second->size(), MPI_BYTE, i, 0,
96 message recv_impl_() {
103 MPI_Get_count(&status, MPI_BYTE, &count);
104 std::vector<char> rcv_buf(count);
105 MPI_Recv( rcv_buf.data(), count, MPI_BYTE, status.MPI_SOURCE, status.MPI_TAG,
domain_remote_, MPI_STATUS_IGNORE );
115 void test_completion() {
116 for(
auto itr=send_buf.begin(), end=send_buf.end(); itr != end; ) {
118 MPI_Test(&(itr->first), &test, MPI_STATUS_IGNORE);
119 if( test ) itr = send_buf.erase(itr);
126 void test_completion_blocking() {
127 while (send_buf.size() > 0) {
128 for(
auto itr=send_buf.begin(), end=send_buf.end(); itr != end; ) {
129 MPI_Wait(&(itr->first), MPI_STATUS_IGNORE);
130 itr = send_buf.erase(itr);
Definition: comm_mpi_smart.h:62
comm_mpi_smart(const char URI[], const bool quiet, MPI_Comm world=MPI_COMM_WORLD)
Definition: comm_mpi_smart.h:67
virtual ~comm_mpi_smart()
Definition: comm_mpi_smart.h:68
Definition: comm_mpi.h:61
MPI_Comm domain_remote_
Definition: comm_mpi.h:173
int remote_size_
Definition: comm_mpi.h:176
static dispatcher< std::string, std::function< communicator *(const char[], const bool)> > & instance()
Definition: lib_singleton.h:58
File containing class definition of communication interface. This is the base class for all other com...
Structures and methods to create a new communicator based on chosen protocols.
Class definition of base MPI communicator.
Structure to contain and manipulate data from internal data to MPI message.
communicator * create_comm_mpi_smart(const char URI[], const bool quiet)
Definition: comm_mpi_smart.h:136
std::vector< char > detach()
Definition: message.h:96
static message make(const id_type &id, types &&... data)
Definition: message.h:72