【发布时间】:2016-10-23 14:26:47
【问题描述】:
我需要执行 MPI_Gather 之类的操作,但我需要按照与进程等级不同的顺序存储收集到的数据。我以为我可以这样做:
int i;
int gathervals[10];
int my_val, my_place_in_storage;
/* init MPI etc ... then ... */
my_val = some_fcn_of_rank(my_rank, ...)
my_place_in_storage = some_other_fcn(my_val, my_rank, ...)
if (my_rank == 0){
/* my_val on proc 0 does go in gathervals[0], which simplifies
things */
gathervals[0] = my_val;
for (i=1; i<num_procs; i++){
MPI_Recv(&gathervals[i], 1, MPI_INT, MPI_ANY_SOURCE,
i, MPI_COMM_WORLD, stat_mpi);
}
}else{
MPI_Send(&mv_val, 1, MPI_INT, 0, my_place_in_storage,
MPI_COMM_WORLD);
}
我的想法是 proc 0 将启动循环并等到从 my_place_in_storage 为 1 的 proc 发布发送,然后 proc 0 将接收该消息并将值放入 gathervals[1]。然后它将迭代并等待,直到它看到来自 proc 的 my_place_in_storage 为 2 的帖子,等等。
这应该有效吗?我在 proc 0 上遇到了段错误,我试图找出原因。我认为这个可能有点不正统的代码块将是开始的地方。我已经验证了所有my_place_in_storage 值的正确性。
【问题讨论】:
-
如果您遇到段错误或其他错误,请发帖minimal reproducible example。