LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Brian Barrett (brbarret_at_[hidden])
Date: 2004-10-12 12:17:23


Hello -

You have a couple of problems with the small code snipet you sent.
First, you send from all non-zero ranks to rank zero but never receive
those sends. You need a matching MPI_Recv for each call to MPI_Send.
Second, your buffer message3 is only large enough if you only have 1
process in MPI_COMM_WORLD. Otherwise, it is way too small - it needs
to be 100 chars *per rank*.

Finally, puts() only outputs 1 line, so it will stop after the first
NULL character. Since you are copying the entire 100 byte message2
buffer, the NULLs after "hello world" are also copied, so puts() will
stop writing after the first "hello world" in message3.

Hope this helps,

Brian

On Oct 12, 2004, at 9:34 AM, Imran Ahmed khan wrote:

> hi,
>
> when i wrote the following program...
> ---
>
> int main(int argc, char **argv )
> {
> char message2[100]="hello world";
> char message3[100];
> int i,rank, size, type=99,tag=66;
> MPI_Status status;
> MPI_Init(&argc, &argv);
> MPI_Comm_size(MPI_COMM_WORLD,&size);
> MPI_Comm_rank(MPI_COMM_WORLD, &rank);
>
> if(rank!=0)
> {
> MPI_Send(message2, 100, MPI_CHAR,0,tag, MPI_COMM_WORLD);
> }
>
> MPI_Gather(message2, 100, MPI_CHAR,message3,100,MPI_CHAR ,0,
> MPI_COMM_WORLD);
> puts(message3);
>
> MPI_Finalize();
> return 0;
> }
>
> ----
>
> in output i m receiving only one " hello world" .... but i should
> recieve 2 " hello world" msgs from 2 nodes.... please help me in this
> regard.
>
> thanx
> Imran
>
> _________________________________________________________________
> Don't just search. Find. Check out the new MSN Search!
> http://search.msn.com/
>
> _______________________________________________
> This list is archived at http://www.lam-mpi.org/MailArchives/lam/
>

-- 
   Brian Barrett
   LAM/MPI developer and all around nice guy
   Have an LAM/MPI day: http://www.lam-mpi.org/