Stack Exchange
Scatterv in MPI works only for root process
I want to use scatterv function but he works only for root process. Here is my code:
int elements_per_proc = len / size;
int difference = len - elements_per_proc * size;
int* chunk_sizes = (int*)(malloc(sizeof(int) * size));
int* displ = (int*)(malloc(sizeof(int) * size));                                                                                                                                                                                                
for(i=0;i<size;i++){
    chunk_sizes[i] = elements_per_proc;
    displ[i] = i * elements_per_proc;
}
chunk_sizes[size - 1] += difference;

int current_recv_size = elements_per_proc + (rank == size - 1 ? difference : 0);

struct option toReturn[current_recv_size];
MPI_Scatterv(&op,chunk_sizes,displ,mpi_op_type,&toReturn,current_recv_size,mpi_op_type,0,MPI_COMM_WORLD);

After that I tried to print the element in toReturn but only the process 0 return a valid results. Tell me why, thanks.

Could you try to use MPI_Scatterv(op,chunk_sizes,displ,mpi_op_type,toReturn,...) ?

It return the same results also without the '&'

Could you post a minimal complete example? The problem can be due to toReturn not being allocated on processes other than root, the definition of mpi_op_type can be flawed... As is, it will be hard to answer your question!
