简体   繁体   English

MPI_Recv中的消息被截断

[英]Message Truncated in MPI_Recv

I have the adjacency matrix and the following code: 我有邻接矩阵和以下代码:

if (is_broadcast_message) {
    MPI_Send(&broadcast_message,1,MPI_INT,j,3,MPI_COMM_WORLD);
    MPI_Send(&message,20,MPI_CHAR,j,3,MPI_COMM_WORLD);
}

Where broadcast_message=128 (random number just to know when I'm receiving, that this was a broadcast message ) 其中broadcast_message=128 (随机数只是为了知道我何时接收到,这是一条广播消息)

Message is defined as char[20]. 消息定义为char [20]。

else if (i have to send only to a node) {
    MPI_Send(&destination,1,MPI_INT,next_hop[destination],3,MPI_COMM_WORLD);
    MPI_Send(&message,20, MPI_CHAR, next_hop[destination],3,MPI_COMM_WORLD);
}

When I'm receiving I first check if recv_payload is 128 (broadcast value) or other value: 收到recv_payload我首先检查recv_payload128 (广播值)还是其他值:

MPI_Recv(&recv_material,1,MPI_INT,MPI_ANY_SOURCE,3,MPI_COMM_WORLD,&status2);

If is it 128, then: 如果是128,则:

MPI_Recv(&message,20,MPI_CHAR,from_d,3,MPI_COMM_WORLD,&status2);

and I'm forwarding the message to all the processes 我正在将消息转发到所有流程

MPI_Send(&message,20,MPI_CHAR,j,3,MPI_COMM_WORLD);

If it's not 128, I'm checking if i am the destination : 如果不是128,我正在检查我是否是目的地:

if(recv_material == rank)
    MPI_Recv(&mesaj,20,MPI_CHAR,from_d,3,MPI_COMM_WORLD,&status2);

Else, I'm sending on nexthop[recv_material] 否则,我正在发送nexthop [recv_material]

MPI_Send(&mesaj,20,MPI_CHAR,next_hop[recv_material],3,MPI_COMM_WORLD);

The problem is that i get the following error and I don't know why : 问题是我收到以下错误,但我不知道为什么:

Fatal error in MPI_Recv: Message truncated, error stack:
MPI_Recv(186).....................: MPI_Recv(buf=0x7fffbce8f2a4, count=1, MPI_INT
src=MPI_ANY_SOURCE, tag=3, MPI_COMM_WORLD, status=0x7fffbce8f250) failed
MPIDI_CH3U_Receive_data_found(129): Message from rank 7 and tag 3 truncated;
20 bytes   received but buffer size is 4

It appears that your problem is that your buffer is too small to receive the message that's being sent. 看来您的问题是您的缓冲区太小而无法接收正在发送的消息。 From your explanation, it sounds like you're doing the right thing, but my guess is that somewhere along the way, the order in which you think the messages should be arriving is not the actual order in which they're arriving. 根据您的解释,听起来您做的正确,但是我的猜测是,在此过程中的某个地方,您认为消息到达的顺序不是消息到达的实际顺序。 You should try to match things up yourself and make sure that everything matches correctly. 您应该尝试自己进行匹配,并确保所有内容正确匹配。

If you need more help, you should post your actual code, though you should also trim it down to a Minimal Working Example ( http://sscce.org ). 如果您需要更多帮助,则应发布实际代码,尽管还应将其缩减为“最小工作示例”( http://sscce.org )。

You're sending multiple message between one pair of processes. 您正在一对进程之间发送多条消息。 This is the case to use tags. 使用标签就是这种情况。 So why do you use the same tag for all messages? 那么,为什么对所有邮件都使用相同的标签? Use tags to disambiguate, and then post a receive for a specific tag. 使用标签消除歧义,然后发布特定标签的收货。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM