MPI中的Scatterv仅适用于根进程

时间:2016-11-06 23:05:45

标签: c parallel-processing mpi

我想使用scatterv函数,但他只适用于root进程。这是我的代码:

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);

之后我尝试在toReturn中打印元素,但只有进程0返回有效结果。告诉我原因,谢谢。

0 个答案:

没有答案