如何使用图拓扑实现对角线邻域通信?

时间:2018-08-02 12:10:27

标签: mpi

another topic中,我请求高效且不易出错的集体对角邻域通信实现,并且收到@Zulan的评论,以创建其中对角连接为边缘。

然后,我读了MPI standard v 3.1(第294-295页)中的MPI_Graph_create()示例,并尝试创建一个图形以进行对角线通讯:

int main_rank;
int top_right;
int top_left;
int bottom_right;
int bottom_left;
int main_coords[2];
// comm_cart is created by MPI_Cart_create()
MPI_Comm_rank (comm_cart, &main_rank);  
MPI_Cart_coords (comm_cart, main_rank, 2, main_coords);

// Finding the rank of diagonal processes, considering periodic topology
int top_right_coords[2] = {(main_coords[0]+1)%ny, (main_coords[1]+1)%nx};
MPI_Cart_rank (comm_cart, top_right_coords, &top_right);
int top_left_coords[2] = {(main_coords[0]+1)%ny, (main_coords[1]-1)%nx};
MPI_Cart_rank (comm_cart, top_left_coords, &top_left);
int bottom_right_coords[2] = {(main_coords[0]-1)%ny, (main_coords[1]+1)%nx};
MPI_Cart_rank (comm_cart, bottom_right_coords, &bottom_right);
int bottom_left_coords[2] = {(main_coords[0]-1)%ny, (main_coords[1]-1)%nx};
MPI_Cart_rank (comm_cart, bottom_left_coords, &bottom_left);

MPI_Comm comm_diagonal;
const int nnodes {5};
int index[nnodes] = {4, 5, 6, 7, 8};
int edges[8] = {top_right, top_left, bottom_right, bottom_left,
                main_rank, main_rank, main_rank, main_rank};

MPI_Graph_create (comm_cart, nnodes, index, edges, 0, &comm_diagonal);

// Use MPI_Neighbor_alltoallw (..., comm_diagonal)
// for collective diagonal communication

以图形方式,您可以看到我的代码背后的逻辑:

enter image description here

但是,当我运行代码时,出现以下错误:

Fatal error in PMPI_Neighbor_alltoallw: Invalid communicator, error stack:
PMPI_Neighbor_alltoallw(165):  MPI_Neighbor_alltoallw(sendbuf=0x1e5d890, sendcounts=0x7fff04e9ad10, sdispls=0x7fff04e9ac30, sendtypes=0x7fff04e9ace4, recvbuf=0x1e5d890, recvcounts=0x7fff04e9ad20, rdispls=0x7fff04e9ac50, recvtypes=0x7fff04e9acf4, comm=MPI_COMM_NULL)
PMPI_Neighbor_alltoallw(119): Null communicator

我认为错误是由于我的MPI_Graph_create()返回NULL通信器这一事实引起的。当我使用普通的笛卡尔传播器(comm_cart)时,一切正常。

问题

  • 我的MPI_Graph_create()有什么问题?
  • 您有MPI_Graph_create()的有效示例吗?

有关更多信息:我使用Intel MPI和Intel编译器来编译代码。

0 个答案:

没有答案