shiva v wrote:
> Hello folks,
>
>
> int main (int argc, char *argv[])
> {
>
> int nprocs, myrank, i=0, data = 0;
The type of data is int,
sizeof (data) will probably return 4 (4 bytes)
> MPI_Status status;
>
> MPI_Init(&argc, &argv);
> MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
> MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
>
> if(myrank == 0) {
> printf("\n main thread no of procs %d \n",
> nprocs);
> for(i = 1; i < nprocs; i++) {
> MPI_Recv ( &data, sizeof(data), MPI_INT, i, 1,
>
Here you say you want to receive 4 INTEGERS (=16 bytes)
overwriting whatever follows 'data' in memory. (most likely the
MPI_Status variable)
> MPI_COMM_WORLD, &status);
> printf("\n %d thread %d \n", data, i );
> }
> } else {
> data = 2 * myrank;
> printf ("\n In thread %d , the value of data is %d
> \n", myrank, data );
>
> MPI_Send (&data, sizeof(data), MPI_INT, 0, 1,
Same here: you send 16 bytes worth of data, where data is only 4 bytes.
Conclusion: the count argument in the send and receive routines
specifies the number of basic blocks you send, not the number of bytes.
Greetings,
Dries
|