How does one use the MPI_Sendrecv function (instead of MPI_Send and
MPI_Recv) to assure they don't have a deadlock their code when the
size of the data being received is unknown prior to the send? From my
research so far, this problem is usually solved by using MPI_Send and
MPI_Recv (or some variation of these basic functions) and preceding
the MPI_Recv with something like:
MPI_Probe(source,tag,comm,&status);
MPI_Get_count(&status,mpi_datatype,&count);
buf=new datatype[count];
MPI_Recv(buf,count,mpi_datatype,source,0,MPI_COMM_WORLD,&status);
I tried the following code example and it appeared that the code got
hung up on the MPI_Probe call (right and left refer to neighbor nodes'
id's).
if(mynode==0){
MPI_Probe(right,right,MPI_COMM_WORLD,&status);
MPI_Get_count(&status,MPI_DOUBLE,&count);
receive=new double[count];
MPI_Sendrecv(&differ[0],size,MPI_DOUBLE,right,mynode,&receive_right[0],count,MPI_DOUBLE,right,right,MPI_COMM_WORLD,&status);
}
else if(mynode==(numnodes-1)){
MPI_Probe(left,left,MPI_COMM_WORLD,&status);
MPI_Get_count(&status,MPI_DOUBLE,&count);
receive=new double[count];
MPI_Sendrecv(&differ[0],size,MPI_DOUBLE,left,mynode,&receive_left[0],count,MPI_DOUBLE,left,left,MPI_COMM_WORLD,&status);
}
else{
MPI_Probe(right,right,MPI_COMM_WORLD,&status);
MPI_Get_count(&status,MPI_DOUBLE,&count);
receive=new double[count];
MPI_Sendrecv(&differ[0],size,MPI_DOUBLE,right,mynode,&receive_right[0],count,MPI_DOUBLE,right,right,MPI_COMM_WORLD,&status);
MPI_Probe(left,left,MPI_COMM_WORLD,&status);
MPI_Get_count(&status,MPI_DOUBLE,&count);
receive=new double[count];
MPI_Sendrecv(&differ[0],size,MPI_DOUBLE,left,mynode,&receive_left[0],count,MPI_DOUBLE,left,left,MPI_COMM_WORLD,&status);
}
Does anyone know how to find out the length of the data to be received
using the MPI_Sendrecv function without having to send two messages
(one just for the data size and the other for the actual data)? I
guess that a programmer could always provide over sized receive
buffers that would be sure to fit any possible data length but usually
people don't have the memory to waste with that solution either.
Thanks for you insights on this.
-Darcy
|
|
0
|
|
|
|
Reply
|
plasma.simulation (1)
|
1/29/2008 6:09:54 PM |
|
I would be interested where your research gave such an example. MPI is
such that the size argument is the MAXIMUM size, not exact size. Just
set size to be big enough for the biggest message (and use a buffer
large enough), and after you receive you can use the get count routine
to find out how big a message was actually received.
You are hanging because you are probing before a message has been sent.
Since you are using a sendrecv, you cannot probe for the message.
Also, from your example code, you should know the size of the message
because you are sending the same size as you are receiving. I assume
this is just because you tried to make a simple example. Unless there
is some inherent reason you cannot just receive into a MAX sized buffer
and check the size after completeion, that is your best solution. If
this is undoable, then I don't know of any solution other than two
messages if you are set on using sendrecv.
On a note of elegance, you may want to try something like this:
if (mynode == 0) left = MPI_PROC_NULL;
else left = mynode - 1;
if (mynode == numnodes-1) right = MPI_RPOC_NULL;
else right = mynode+1;
Then you don't need to check rank before doing the sendrecvs.
I hope this help.
Dave.
Darcy wrote:
> How does one use the MPI_Sendrecv function (instead of MPI_Send and
> MPI_Recv) to assure they don't have a deadlock their code when the
> size of the data being received is unknown prior to the send? From my
> research so far, this problem is usually solved by using MPI_Send and
> MPI_Recv (or some variation of these basic functions) and preceding
> the MPI_Recv with something like:
>
> MPI_Probe(source,tag,comm,&status);
> MPI_Get_count(&status,mpi_datatype,&count);
> buf=new datatype[count];
> MPI_Recv(buf,count,mpi_datatype,source,0,MPI_COMM_WORLD,&status);
>
> I tried the following code example and it appeared that the code got
> hung up on the MPI_Probe call (right and left refer to neighbor nodes'
> id's).
>
> if(mynode==0){
> MPI_Probe(right,right,MPI_COMM_WORLD,&status);
> MPI_Get_count(&status,MPI_DOUBLE,&count);
> receive=new double[count];
>
> MPI_Sendrecv(&differ[0],size,MPI_DOUBLE,right,mynode,&receive_right[0],count,MPI_DOUBLE,right,right,MPI_COMM_WORLD,&status);
> }
> else if(mynode==(numnodes-1)){
> MPI_Probe(left,left,MPI_COMM_WORLD,&status);
> MPI_Get_count(&status,MPI_DOUBLE,&count);
> receive=new double[count];
>
> MPI_Sendrecv(&differ[0],size,MPI_DOUBLE,left,mynode,&receive_left[0],count,MPI_DOUBLE,left,left,MPI_COMM_WORLD,&status);
> }
> else{
> MPI_Probe(right,right,MPI_COMM_WORLD,&status);
> MPI_Get_count(&status,MPI_DOUBLE,&count);
> receive=new double[count];
>
> MPI_Sendrecv(&differ[0],size,MPI_DOUBLE,right,mynode,&receive_right[0],count,MPI_DOUBLE,right,right,MPI_COMM_WORLD,&status);
> MPI_Probe(left,left,MPI_COMM_WORLD,&status);
> MPI_Get_count(&status,MPI_DOUBLE,&count);
> receive=new double[count];
>
> MPI_Sendrecv(&differ[0],size,MPI_DOUBLE,left,mynode,&receive_left[0],count,MPI_DOUBLE,left,left,MPI_COMM_WORLD,&status);
> }
>
> Does anyone know how to find out the length of the data to be received
> using the MPI_Sendrecv function without having to send two messages
> (one just for the data size and the other for the actual data)? I
> guess that a programmer could always provide over sized receive
> buffers that would be sure to fit any possible data length but usually
> people don't have the memory to waste with that solution either.
> Thanks for you insights on this.
>
> -Darcy
--
Dr. David Cronk, Ph.D. phone: (865) 974-3735
Research Director fax: (865) 974-8296
Innovative Computing Lab http://www.cs.utk.edu/~cronk
University of Tennessee, Knoxville
|
|
0
|
|
|
|
Reply
|
David
|
1/29/2008 6:45:04 PM
|
|
|
1 Replies
155 Views
(page loaded in 0.065 seconds)
Similiar Articles: Unknown number of return values - comp.soft-sys.matlabI want to receive all return values of the function, ... ... "Stephan" <stephanjunek@hotmail.com> wrote in message ... all you have to do is use a switchyard on the length of ... Token Type bug - help? - comp.text.pdfBut of several hundred people to receive it, a handful ... or with their program crashing with some message about ... Just for laffs, I tried "Reduce file size" to 'save as ... Error message of Solaris Volume Manager on Sun V440 - comp.unix ...... default) Write option: parallel (default) Size ... M p 8208 unknown /dev/dsk/c1t0d0s4 # showrev Hostname ... Oralce ... damorgan@x.washington.edu> wrote in message ... Connecting USB to parallel device (in Windows 7?) - comp.periphs ...Nothing shows the Agere printer once I receive the message that ... for iPod device - comp.os.ms ..... the stack size ... Xilinx LPT programmer help - comp.arch.fpga unknown ... the firing squad problem - comp.programming... an array of finite state machines ('soldiers'), length N ... N is unknown, that's the point. > Question: Can a ... If you receive both signals at the same time, you send ... No tftpdnld command - comp.dcom.sys.ciscoDo you wish to continue? y/n [n]: y Ready to receive ... in directory Error getting file system status (Unknown ... program load complete, entry point: 0x80008000, size ... How to get envelope from AM signal without phase shift - comp.dsp ...For optics, that time is related to the size of the ... It is this *transient* change to an *unknown* state that ... how does the energy get from the transmit to the receive ... Smoothing Spline -- any existing efficient routines? - comp.lang ...... the 40000 element array I receive an error message ... XX SIGM = SS END ELSE: MESSAGE, 'Wrong number of arguments' ENDCASE NUM = SIZE ... NUM) > ; Definition of the unknown ... strndup: RFC - comp.compilers.lcc... comp.std.c I noticed that there was a message ... and many others, so I do not see how size_t could be unknown ... size_t lgh) /* length token can receive ... .g64 images - comp.sys.cbmThis results in a block transfer size of at least ... Linux during X11 startup for more than 2secs (for unknown ... "Martin Brunner" <mbrunner@mcnon.com> wrote in message ... MPI_Sendrecv - MCS Division :: HomeSends and receives a message Synopsis int MPI_Sendrecv(void ... be declared as an array of size ... be non-negative; tags in a receive (MPI_Recv, MPI_Irecv, MPI_Sendrecv, etc ... Send-receive - Message Passing Interface (MPI) Forum Home Page... send-receive operation can receive a message sent by a regular send operation. MPI_SENDRECV(sendbuf ... MPI_STATUS_SIZE), IERROR . Execute a blocking send and receive ... 7/9/2012 2:17:50 PM
|