【发布时间】:2016-05-07 21:05:15
【问题描述】:
您好,我正在尝试通过 MPI 的点对点通信发送 2-dim 数组的边缘。
struct image {
/* image data block */
double **data; //2dim array
/* boundaries */
double *top;
double *bot;
double *left;
double *right;
/* dimensions */
int width;
int height;
};
每个节点都有自己的图像(相同的宽度和高度)以及应该接收交换数据的边界。每个节点都已经知道在哪里发送/接收数据。接收缓冲区(顶部,机器人,左,右)已经分配。 不行的是我在交换过程中总是遇到分段错误。
这是我的批判方法:
void MPI_stencil_p_to_p(struct image *img, int *neighbours, MPI_Comm comm)
{
int count = 0;
for (int i = 0; i < 4; ++i)
{
if (neighbours[i] != MPI_PROC_NULL){
count+=2;
}
}
MPI_Status status[count];
MPI_Request req[count];
int count_tmp = count;
for (int i = 0; i < 4; ++i)
{
if (neighbours[i] != MPI_PROC_NULL){
count_tmp--;
if (i == 0)
{
printf("%d: %d\n", ra, neighbours[i]);
printf("works %d\n", ra);
MPI_Isend(img->data[0], img->width, MPI_DOUBLE, neighbours[i], TAG, comm, &req[count_tmp]);
count_tmp--;
MPI_Irecv(&img->top, img->width, MPI_DOUBLE, neighbours[i], TAG, comm, &req[count_tmp]);
continue;
} else if (i == 2)
{
printf("%d: %d\n", ra, neighbours[i]);
int len = img->height-1;
MPI_Isend(img->data[len], img->width, MPI_DOUBLE, neighbours[i], TAG, comm, &req[count_tmp]);
count_tmp--;
MPI_Irecv(&img->bot, img->width, MPI_DOUBLE, neighbours[i], TAG, comm, &req[count_tmp]);
continue;
}
MPI_Datatype col;
MPI_Type_vector(img->height, 1, img->width, MPI_DOUBLE, &col);
MPI_Type_commit(&col);
if (i == 1)
{
printf("%d: %d\n", ra, neighbours[i]);
MPI_Isend(&img->data[0][0], 1, col, neighbours[i], TAG, comm, &req[count_tmp]);
count_tmp--;
MPI_Irecv(&img->right, img->height, MPI_DOUBLE, neighbours[i], TAG, comm, &req[count_tmp]);
} else
{
printf("%d: %d\n", ra, neighbours[i]);
int len = img->width-1;
MPI_Isend(&img->data[0][len], 1, col, neighbours[i], TAG, comm, &req[count_tmp]);
count_tmp--;
MPI_Irecv(&img->left, img->height, MPI_DOUBLE, neighbours[i], TAG, comm, &req[count_tmp]);
}
MPI_Type_free(&col);
}
}
if (MPI_Waitall(count, req, status) != MPI_SUCCESS)
error_exit(EXIT_FAILURE, "MPI_Waitall");
}
谢谢你帮助我!
【问题讨论】: