48 std::vector<std::vector<char>>& sendBufs,
49 [[maybe_unused]]
int tag = 7373)
51 std::vector<char> recvBuf;
54 const int myRank = comm.rank();
55 const int numProc = comm.size();
60 const MPI_Comm mpiComm = comm;
65 std::vector<MPI_Request> sendRequests;
66 sendRequests.reserve(numProc);
67 for (
int to = 0; to < numProc; ++to)
69 if (to == myRank || sendBufs[to].empty())
71 sendRequests.emplace_back();
72 MPI_Issend(sendBufs[to].data(),
static_cast<int>(sendBufs[to].size()),
73 MPI_BYTE, to, tag, mpiComm, &sendRequests.back());
78 const auto receivePending = [&]
83 MPI_Improbe(MPI_ANY_SOURCE, tag, mpiComm, &flag, &message, &status);
87 MPI_Get_count(&status, MPI_BYTE, &count);
88 const std::size_t offset = recvBuf.size();
89 recvBuf.resize(offset +
static_cast<std::size_t
>(count));
90 MPI_Mrecv(recvBuf.data() + offset, count, MPI_BYTE, &message, MPI_STATUS_IGNORE);
91 MPI_Improbe(MPI_ANY_SOURCE, tag, mpiComm, &flag, &message, &status);
98 MPI_Request barrierRequest = MPI_REQUEST_NULL;
99 bool barrierActive =
false;
108 MPI_Test(&barrierRequest, &barrierDone, MPI_STATUS_IGNORE);
109 done = (barrierDone != 0);
114 MPI_Testall(
static_cast<int>(sendRequests.size()),
115 sendRequests.data(), &sendsDone, MPI_STATUSES_IGNORE);
118 MPI_Ibarrier(mpiComm, &barrierRequest);
119 barrierActive =
true;
126 MPI_Barrier(mpiComm);
128 assert(comm.size() == 1 &&
"Sparse data exchange between multiple ranks requires MPI");
std::vector< char > exchangeSparse(const Communication &comm, std::vector< std::vector< char > > &sendBufs, int tag=7373)
Exchange variable-sized byte messages with a sparse set of peer processes.
Definition nonblockingsparseexchange.hh:47