This is an erroneous MPI program -- it assumes that the MPI
implementation has infinite buffering. Short version of how to fix:
for the case of iMyRank != 0 (I assume that this application is only
run with 2 processes), swap the receives to go before the sends, or use
non-blocking communications.
See section 3.5 of the MPI-1 standard, in particular example 3.9 for a
detailed explanation of this issue.
On Aug 1, 2005, at 10:10 AM, a17567182 wrote:
> Hello,
>
> Could someone explain, why the following code works for MSG_SIZE=4096,
> but does
> no work for MSG_SIZE=16384. The messages are composed of doubles, so
> the bigger
> message has 131072 bytes length, which, as far as I know, involves
> rendez-vous
> communication protocol for implementation of communications.
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <mpi.h>
>
> //#define MSG_SIZE 16384
> #define MSG_SIZE 4096
>
> int main(int argc, char** argv){
>
> int iMyRank, iPeerRank;
> int iIntTypeSize, iDoubleTypeSize, iRecvdCount;
> double* pdBufIn, *pdBufOut;
> MPI_Status status1, status2;
>
> MPI_Init(&argc,&argv);
> MPI_Comm_rank(MPI_COMM_WORLD,&iMyRank);
>
> MPI_Type_size(MPI_INT,&iIntTypeSize);
> MPI_Type_size(MPI_DOUBLE,&iDoubleTypeSize);
> if( sizeof(double) != iDoubleTypeSize ) {fprintf(stderr,"Different
> sizes
> for DOUBLE type\n"); return 0;}
> if( sizeof(int) != iIntTypeSize ) {fprintf(stderr,"Different sizes
> for INT
> type\n"); return 0;}
> pdBufIn = (double *)calloc(MSG_SIZE,sizeof(double));
> pdBufOut = (double *)calloc(MSG_SIZE,sizeof(double));
>
> fprintf(stderr,"%d: start %d bytes\n", iMyRank,
> MSG_SIZE*iDoubleTypeSize);
> fflush(stderr);
> if(iMyRank==0){
> MPI_Send(&iMyRank,1,MPI_INT,1,10,MPI_COMM_WORLD);
> MPI_Send(pdBufOut,MSG_SIZE,MPI_DOUBLE,1,30,MPI_COMM_WORLD);
>
> MPI_Recv(&iPeerRank,1,MPI_INT,MPI_ANY_SOURCE,11,MPI_COMM_WORLD,&status1
> );
> MPI_Recv(pdBufIn,MSG_SIZE,MPI_DOUBLE,status1.MPI_SOURCE,31,MPI_COMM_WOR
> LD,&status2);
> }else{
> MPI_Send(&iMyRank,1,MPI_INT,0,11,MPI_COMM_WORLD);
> MPI_Send(pdBufOut,MSG_SIZE,MPI_DOUBLE,0,31,MPI_COMM_WORLD);
>
> MPI_Recv(&iPeerRank,1,MPI_INT,MPI_ANY_SOURCE,10,MPI_COMM_WORLD,&status1
> );
> MPI_Recv(pdBufIn,MSG_SIZE,MPI_DOUBLE,status1.MPI_SOURCE,30,MPI_COMM_WOR
> LD,&status2);
> }
> fprintf(stderr,"%d: done\n",iMyRank);
> MPI_Finalize();
>
> return 0;
> }
>
> Thanks!
>
> Anton
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> This list is archived at http://www.lam-mpi.org/MailArchives/lam/
>
--
{+} Jeff Squyres
{+} jsquyres_at_[hidden]
{+} http://www.lam-mpi.org/
|