某些情况下,接收者不知道消息尺寸,此时当然可以用一个足够大的空间去接收,但我们可以用MPI_Probe去首先探测消息尺寸,然后再分配相应空间,然后再正式接收消息,可以认为MPI_Probe和MPI_Recv很类似,只是不真正执行接收操作
MPI_Probe(
int source, //source rank, or MPI_ANY_SOURCE (integer)
int tag, //tag value or MPI_ANY_TAG (integer)
MPI_Comm comm, //communicator (handle)
MPI_Status *status)
例子,设进程1随机决定发送给其它进程的数据个数,其他进程需要先探测真实尺寸,然后接收:
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <tim