笛卡尔拓扑中的边界交换mpi

问题描述:

我想在我的mpi程序中执行边界交换。 我有结构,看起来像:笛卡尔拓扑中的边界交换mpi

cell** local_petri_A; 

local_petri_A = calloc(p_local_petri_x_dim,sizeof(*local_petri_A)); 

for(int i = 0; i < p_local_petri_x_dim ; i ++){ 
     local_petri_A[i] = calloc(p_local_petri_y_dim,sizeof(**local_petri_A)); 
    } 

其中单元为:

typedef struct { 
    int color; 
    int strength; 
} cell; 

我想有一个交流计划像这样的画面:border exchange in cartesian topology

所以我把我的计划在笛卡尔拓扑结构中,首先定义mpi类型以执行交换: void create_types(){

//////////////////////////////// 
//////////////////////////////// 
// cell type 
const int nitems=2; 
int   blocklengths[2] = {1,1}; 
MPI_Datatype types[2] = {MPI_INT, MPI_INT}; 
MPI_Aint  offsets[2]; 

offsets[0] = offsetof(cell, color); 
offsets[1] = offsetof(cell, strength); 

MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_cell_t); 
MPI_Type_commit(&mpi_cell_t); 
//////////////////////////////// 
/////////////////////////////// 

MPI_Type_vector (x_inside , 1 , 1 , mpi_cell_t , & border_row_t); 
MPI_Type_commit (& border_row_t); 
/*we put the stride to x_dim to get only one column*/ 
MPI_Type_vector (y_inside , 1 , p_local_petri_x_dim , MPI_DOUBLE , & border_col_t); 
MPI_Type_commit (& border_col_t); 

}

,最后尝试执行从南北交流:

/*send to the north receive from the south */ 
    MPI_Sendrecv (& local_petri_A[0][1] , 1 , border_row_t , p_north , TAG_EXCHANGE ,& local_petri_A [0][ p_local_petri_y_dim -1] , 1 , border_row_t , p_south , TAG_EXCHANGE ,cart_comm , MPI_STATUS_IGNORE); 
    /*send to the south receive from the north */ 
    MPI_Sendrecv (& local_petri_A[0][ p_local_petri_y_dim -2] , 1 , border_row_t , p_south , TAG_EXCHANGE ,& local_petri_A [0][0] , 1 , border_row_t , p_north , TAG_EXCHANGE ,cart_comm , MPI_STATUS_IGNORE); 

注意:本节x_inside和y_inside是数组的“内部”尺寸(无鬼影部分)和p_local_petri_dim是整个阵列的尺寸。

然后,我有这样的错误:enter image description here

有什么,我做错了?

非常感谢您的帮助。

问题在于你分配2D数组的方式。 您分配一个数组数组,因此连续内存中不可能有两行。因此,您的ddt列与您的二维数组布局不匹配。您可以参考MPI_Bcast a dynamic 2d array正确地分配您的数组。作为一个注意事项,Fortran没有这种问题,所以如果这是一个选项,那会让你的生活更轻松。

+0

好吧,它不会为列而工作,但行呢?在这里,我只尝试发送一些行,我仍然有一个错误,我的分配行在memry中是contiguos,不是吗? –

+0

有没有办法使它适合mpi类型? –

+0

行肯定是连续的。请使用[Minimal,Complete和Verifiable示例](https://stackoverflow.com/help/mcve)编辑您的问题,我将查看它 –