Ivan Bychkov
Ivan Bychkov

Reputation: 308

Wrong MPI_Scatter

The program below consists of only one significant MPI function per se (MPI_Scatter). And it works wrong: the function returns MPI_SUCCESS, but the data received by Clients (nonzero ranks) differ from the data sent by Server (rank zero).

#include <stdio.h>
#include <mpi.h>

int main(int argc, char* argv[])
{
    int rank;
    int data;
    int temp;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    if (rank == 0)
    {
        data = 123; // data to send
        MPI_Scatter(&data, 1, MPI_INT, &temp, 1, MPI_INT, 0, MPI_COMM_WORLD); // MPI_SUCCESS
    }   
    else
    {
        MPI_Scatter(NULL, 0, MPI_INT, &data, 1, MPI_INT, 0, MPI_COMM_WORLD); // MPI_SUCCESS     
        printf("\nClient[%i] data = %i", rank, data);   // Incorrect data received
    }

    MPI_Finalize();
    return 0;
}

Upvotes: 1

Views: 331

Answers (1)

pyCthon
pyCthon

Reputation: 12341

Heres a little picture to help you understand,

enter image description here

Reference : http://www.mpitutorial.com/mpi-scatter-gather-and-allgather/

Upvotes: 4

Related Questions