【问题标题】:segmentation faults in MPI-2MPI-2 中的分段错误
【发布时间】:2011-12-29 17:58:24
【问题描述】:

知道为什么以下内容会给我一个段错误吗?

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];

如果我注释掉最后一行,我不会得到段错误,但如果我把它留在里面,我会得到 ​​p>

=====================================================================================
=   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;

【问题讨论】:

  • 发布MPI_Bcast的签名和buf_int的类型。
  • MPI_Bcast 的签名是什么意思?喜欢返回码?
  • 我的意思是MPI_Bcast 是如何声明的;参数类型有哪些?
  • MPI_Bcast 的参数可以在mpi.deino.net/mpi_functions/MPI_Bcast.html 查看。参数 MPI_INT 和 MPI_COMM_WORLD 是 mpi 标头中的预定义类型。

标签: c++ segmentation-fault mpi


【解决方案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可以查看示例代码,并比较用法。

【讨论】:

  • 你完全正确!在课堂上,我们一直在调用 &buf_int ...我想我们一定是在以不同的方式声明数组。谢谢!
猜你喜欢
  • 2014-05-07
  • 2023-04-11
  • 2017-06-25
  • 2019-06-26
  • 2011-12-24
  • 2012-01-24
  • 2012-05-11
  • 2015-02-18
  • 2017-07-24
相关资源
最近更新 更多