Most people will tell you that probes should only be used when there are
no other options as it is an expensive routine. For a situation like
this, since you know a message will arrive, it may be better to define a
DATA_MAX that is the maximum size of the data. Then you receive with
DATA_MAX as the count. Upon return, you can check the number of
elements with MPI_Get_count().
The count argument to MPI_Recv is a maximum. It is perfectly legal (and
common for certain classes of applictions) to try to receive more
elements than were sent. Just make sure that DATA_MAX is the maximum,
as trying to receive fewer elements than were sent is an error.
Dave.
Heiko Bauke wrote:
> Hi,
>
> On Thu, 19 May 2005 12:32:02 -0700 (PDT)
> ThanhVu Nguyen <tvn_email-debianml_at_[hidden]> wrote:
>
> check with MPI_Probe and MPI_Get_count the number of elements before
> calling MPI_Recv.
>
>
>>vector<int> data; //unknown size
>>
>>if (taskID == Sender){
>> data.push_back(1);
>> data.push_back(2);
>>
>> MPI_Send(&data[0],data.size(),MPI_INT .... ); // send
>>}
>>if (taskId == Receiver){
>> // QUESTION here -> how to receive the sending data ? the
>> receiver
>
>
> MPI_Probe(0, tag, MPI_COMM_WORLD, &status);
> MPI_Get_count(&status, MPI_INT, &count);
> data.resize(count);
> MPI_Recv(&data[0],data.size(),MPI_INT .... ); // recv
>
>
>>}
>
>
>
> Heiko
>
--
Dr. David Cronk, Ph.D. phone: (865) 974-3735
Research Leader fax: (865) 974-8296
Innovative Computing Lab http://www.cs.utk.edu/~cronk
University of Tennessee, Knoxville
|