MPI-2中的分段错误

时间:2011-11-15 17:34:46

标签: c++ segmentation-fault mpi

任何想法为什么以下会给我一个段错误?

buf_int = new int[12];
buf_int[0] = stx1.min;
buf_int[1] = stx1.max;
buf_int[2] = stx2.min;
buf_int[3] = stx2.max;
buf_int[4] = sty1.min;
buf_int[6] = sty2.max;

MPI_Bcast(&buf_int, 12, MPI_INT, 0, MPI_COMM_WORLD);

stx1.min = buf_int[0];

如果我注释掉最后一行,我不会得到段错误,但是如果我把它留下来,我会得到

=====================================================================================
=   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
=   EXIT CODE: 11
=   CLEANING UP REMAINING PROCESSES
=   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
=====================================================================================

错误结果是分段错误。如果无法从给出的代码中推断出错误,我可以包含更多。

buf_int被声明为

int* buf_int;

1 个答案:

答案 0 :(得分:1)

由于MPI_Bcast的签名是这样的:

int MPI_Bcast(
  void *buffer,
  int count,
  MPI_Datatype datatype,
  int root,
  MPI_Comm comm
);

取自documentation,您应该将该函数称为:

MPI_Bcast(buf_int, 12, MPI_INT, 0, MPI_COMM_WORLD);

即,将buf_int作为第一个参数传递,而不是&bug_int

您可以通过向下滚动page来查看示例代码,并比较使用情况。