16#ifndef PECLET_CORE_HALO_NBX_HPP
17#define PECLET_CORE_HALO_NBX_HPP
46 template <
typename PackNext,
typename OnRecv>
47 void exchange(PackNext&& packNext, OnRecv&& onRecv,
int tag = 0) {
49 std::vector<std::unique_ptr<std::vector<char>>> sendBufs;
50 std::vector<MPI_Request> sendReqs;
52 auto buf = std::make_unique<std::vector<char>>();
53 int dest = packNext(*buf);
57 MPI_Issend(buf->data(),
static_cast<int>(buf->size()),
MPI_BYTE, dest, tag, comm_, &req);
58 sendBufs.push_back(std::move(buf));
59 sendReqs.push_back(req);
63 bool barrierStarted =
false;
66 std::vector<char> recvBuf;
74 recvBuf.resize(count);
80 if (!barrierStarted) {
82 MPI_Testall(
static_cast<int>(sendReqs.size()), sendReqs.data(), &allSent,
86 barrierStarted =
true;
void exchange(PackNext &&packNext, OnRecv &&onRecv, int tag=0)
NbxEngine(MPI_Comm comm=MPI_COMM_WORLD)
int MPI_Comm_size(MPI_Comm, int *s)
int MPI_Testall(int, MPI_Request *, int *flag, MPI_Status *)
#define MPI_STATUS_IGNORE
int MPI_Iprobe(int, int, MPI_Comm, int *flag, MPI_Status *)
int MPI_Recv(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status *)
#define MPI_STATUSES_IGNORE
int MPI_Ibarrier(MPI_Comm, MPI_Request *)
int MPI_Get_count(const MPI_Status *, MPI_Datatype, int *c)
int MPI_Issend(const void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *)
int MPI_Comm_rank(MPI_Comm, int *r)
int MPI_Test(MPI_Request *, int *flag, MPI_Status *)