以下代码为我提供了正确答案
MPI_Win win;
MPI_Win_create(xyz, nsd*nnc, sizeof(double), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
MPI_Win_fence(0, win);
for(i=0; i<nnl; i++)
{
int gb_node_num = nodeLToG[i];
int rank_to_get_from = gb_node_num/mnc;
int buffer_position = gb_node_num%mnc;
MPI_Get(&x_cord[i], 1, MPI_DOUBLE, rank_to_get_from, nsd*buffer_position, 1, MPI_DOUBLE, win);
MPI_Get(&y_cord[i], 1, MPI_DOUBLE, rank_to_get_from, nsd*buffer_position+1, 1, MPI_DOUBLE, win);
}
MPI_Win_fence(0, win);
for(i=0;i<nnl;i++)
{
lNode[i].setX(x_cord[i]);
lNode[i].setY(y_cord[i]);
}
如果我将MPI_Win_fence()进一步向下移动,如下所示,则不会得到结果。为什么会有所作为?
for(i=0; i<nnl; i++)
{
int gb_node_num = nodeLToG[i];
int rank_to_get_from = gb_node_num/mnc;
int buffer_position = gb_node_num%mnc;
MPI_Get(&x_cord[i], 1, MPI_DOUBLE, rank_to_get_from, nsd*buffer_position, 1, MPI_DOUBLE, win);
MPI_Get(&y_cord[i], 1, MPI_DOUBLE, rank_to_get_from, nsd*buffer_position+1, 1, MPI_DOUBLE, win);
}
for(i=0;i<nnl;i++)
{
lNode[i].setX(x_cord[i]);
lNode[i].setY(y_cord[i]);
}
MPI_Win_fence(0, win);
我们应该如何使用MPI_Win_fence()?你能指出一些参考吗?