5

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 )

Message is defined as 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:

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

If is it 128, then:

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 :

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]

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

2 Answers 2

5

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).

Sign up to request clarification or add additional context in comments.

2 Comments

I can't really post my actual code because this is a homework.
Sorry. Without more info it's going to be hard to fix this.
-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.