我需要在处理器之间传输一个可变长度的向量。更具体地说,一个处理器监听其他几个处理器的发送。这就是我认为就足够了:
// receiving processor (rank 0):
MPI::Status status;
MPI::COMM_WORLD.Probe(MPI::ANY_SOURCE, my_tag, status);
const auto sender = status.Get_source();
const auto n_bytes = status.Get_count(MPI::BYTE);
std::cerr << n_bytes << std::endl;
auto row = std::vector<size_t>(n_bytes / sizeof(size_t));
MPI::COMM_WORLD.Recv(&row.front(), n_bytes, MPI::BYTE, sender, my_tag);
// sending processor:
const size_t n = 10; // example value
auto row = std::vector<size_t>(n, 0);
const auto n_bytes = n * sizeof(size_t);
MPI::COMM_WORLD.Send(&row.front(), n_bytes, MPI::BYTE, 0, my_tag);
但是,接收处理器报告n_bytes == 0
. 使用是否Probe / Recv
正确?