我正在尝试使用MPI-2功能进行单面通信,以便为分布式哈希表编写程序。每个进程在开始时向所有其他进程公开内存(B)。然后,希望每个进程可以在不同步的情况下访问其他内存。到目前为止,我所拥有的内容如下所示(来自示例http://mpi.deino.net/mpi_functions/MPI_Put.html的修改后的代码)。最后,在某些情况下,我得到了错误的B [99]值(因运行而异)。我做错了什么?
编辑:我现在通过等待调用解决了上述问题,但我想等待每个MPI_Get调用的完成。但看起来唯一的选择是需要全局同步的MPI_Win_fence,或者每个MPI_Get调用的MPI_Win_start / MPI_Win_complete。可以如下所示调用后者一次,并且可以在每次MPI_Get调用后等待吗?
#include "mpi.h"
#include "stdio.h"
#define SIZE2 200
int main(int argc, char *argv[])
{
int rank, nprocs, *B;
MPI_Group comm_group;
MPI_Win winl;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &B);
for(int i=0; i<SIZE2; i++) B[i] = 0;
MPI_Comm_group(MPI_COMM_WORLD, &comm_group);
MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int),MPI_INFO_NULL, MPI_COMM_WORLD, &winl);
MPI_Win_post(comm_group, 0, winl);
MPI_Win_start(comm_group, 0, winl);
if(rank == 0)
{
int drank = (rank == 0) ? 1 : 0;
int value = 200, value1;
int index = 99;
MPI_Get(&value1, 1, MPI_INT, drank, index+1, 1, MPI_INT, winl);
MPI_Put(&value, 1, MPI_INT, drank, index, 1, MPI_INT, winl);
MPI_Get(&value1, 1, MPI_INT, drank, index+1, 1, MPI_INT, winl);
MPI_Put(&value, 1, MPI_INT, drank, index, 1, MPI_INT, winl);
}
MPI_Win_complete(winl);
MPI_Win_wait(winl);
printf("%d: %d %d\n",rank,B[99],B[100]);
MPI_Group_free(&comm_group);
MPI_Win_free(&winl);
MPI_Free_mem(B);
MPI_Finalize();
return 0;
}