Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPI_Recv - How to determine count?

Tags:

c++

mpi

So let's say I have an MPI program with 2 processes, rank 0 and rank 1.

int i[20], j[20], temp, size; 

In process with rank 0, I have

for(temp=0; temp<20; temp++)
    i[temp] =  temp; 
MPI_Send(i, 15, MPI_INT, 1, 1, MPI_COMM_WORLD);

and let's say process with rank 1 then does

// At this point, size is declared, but not assigned any value. 
MPI_Recv(j,size, MPI_INT, 0, 1, MPI_COMM_WORLD): 
cout << "I have received " << size << " elements" ; 

My question is, in the above statement, does "size" need to be declared? Or does MPI_Recv somehow "know" that it is receiving 15 elements, and automatically sets size = 15? If size is not defined, what happens to the code?

Basically, my question is, I am sending a different number of elements to processors with different ranks, all messages originating from rank 0. I want to know if I should first send the size across, and then prepare the processors to receive that many elements, or if I can just send the array and the processes automatically pick the size up from there.

like image 644
Hari Sundararajan Avatar asked Mar 01 '11 18:03

Hari Sundararajan


People also ask

What is count in MPI send?

https://www.open-mpi.org/doc/v1.8/man3/MPI_Recv.3.php , count argument holds the number of elements in the buffer. count. Maximum number of elements to receive (integer). Number of bytes must be calculated by multiplying number of elements (count) and size of each element (given by the constant of type MPI_Datatype).

What does MPI_Recv return?

This function returns an overflow error if all incoming data does not fit into the receive buffer. If the received message is shorter than the buffer, only the part of the buffer that corresponds to the message is modified. The remainder of the buffer is not modified. Processes can send messages to themselves.

What is MPI_ Probe?

MPI_Probe is a pre-receive query about a message. You can use it to snoop on an incoming message to decide how it should be received.


1 Answers

Look at the documentation for MPI_Recv:

Input Parameters

count maximum number of elements in receive buffer (integer)

So yes, you do need to pass in a value. Note that it need not be the actual number of elements you're receiving, but only the maximum number of elements that your buffer can hold. In your case, you just need to pass 20. The Notes section also mentions how to determine the actual number of elements that were received:

The count argument indicates the maximum length of a message; the actual number can be determined with MPI_Get_count.

like image 181
casablanca Avatar answered Oct 09 '22 17:10

casablanca