4.4 点对点通信
通信模式
1.同步 2.缓冲 3.标准 4.就绪
https://wenku.baidu.com/view/3318805b69eae009581bec35.html
mpi_barrier
//?路障同步
inline void mpi_barrier() {
// MPI_Barrier uses busy waiting. Try to avoid.
// CHECK(0 == MPI_Barrier(mpi_comm()));
std::vector<MPI_Request> reqs(mpi_size(), MPI_REQUEST_NULL);
int dummy = 0;
for (int i = 0; i < mpi_size(); i++) {
//非阻塞式接收
int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Request *request)
MPI_Irecv(&dummy, 1, MPI_INT, i, 0, mpi_comm(), &reqs[i]);
}
for (int i = 0; i < mpi_size(); i++) {
int MPI_Send( buf, count, datatype, dest, tag, comm );
//阻塞传送
MPI_Send(&dummy, 1, MPI_INT, i, 0, mpi_comm());
}
for (int i = 0; i < mpi_size(); i++) {
for (unsigned long x = 1;; x = std::min(x * 2, 2000)) {
int flag = 0;
//complete check 不阻塞
MPI_Test(&reqs[i], &flag, MPI_STATUSES_IGNORE);
if (flag) {
break;
}
usleep(x);
}
}
}
A.阻塞 B.非阻塞
所以发送一共有8种 接收只有AB两种