【问题标题】:MPI Bcast with MPI_Type_create_struct segmentation fault具有 MPI_Type_create_struct 分段错误的 MPI Bcast
【发布时间】:2014-01-13 15:14:33
【问题描述】:

我强迫自己使用 C 语言 MPI 中的个人结构进行广播。基本上我已经创建了 struct Vector3d。

typedef struct {
    double x, y, z;
} Vector3d;

然后我一直在阅读并为每个 MPI 进程编写代码。

int rank, size;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

// MPI Struct para Vector3d
int nroItems = 3;
int blockLengths[3] = { 1, 1, 1 };
MPI_Datatype types[3] = { MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE };
MPI_Datatype MPI_Vector3d;
MPI_Aint     offsets[3];
offsets[0] = offsetof(Vector3d, x);
offsets[1] = offsetof(Vector3d, y);
offsets[3] = offsetof(Vector3d, z);

MPI_Type_create_struct(nroItems, blockLengths, offsets, types, &MPI_Vector3d);
MPI_Type_commit(&MPI_Vector3d);

然后我用这个广播一个 Vector3d 数组。

Vector3d * num = (Vector3d *) malloc(sizeof(Vector3d) * 10);
if(rank == 0) {
    ... 
    ...
    MPI_Bcast(num, 10, MPI_Vector3d, 0, MPI_COMM_WORLD);
} else {
    MPI_Bcast(num, 10, MPI_Vector3d, 0, MPI_COMM_WORLD);
}

当我运行它时我得到了它。

[mario-elementary:24020] *** Process received signal ***
[mario-elementary:24020] Signal: Segmentation fault (11)
[mario-elementary:24020] Signal code: Address not mapped (1)
[mario-elementary:24020] Failing at address: 0x56fae13e2cc8
[mario-elementary:24020] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0xfcb0) [0x2b7d6fce7cb0]
[mario-elementary:24020] [ 1] /lib/x86_64-linux-gnu/libc.so.6(+0x14ae90) [0x2b7d70040e90]
[mario-elementary:24020] [ 2] /usr/lib/libmpi.so.0(+0x3f812) [0x2b7d6fa67812]
...
...etc
--------------------------------------------------------------------------
mpirun noticed that process rank 0 with PID 24020 on node mario-elementary exited on signal 11 (Segmentation fault).
--------------------------------------------------------------------------

请帮忙!

【问题讨论】:

  • 在 else 部分的 MPI_Bcast 调用中,您提到 root 值为 0,那不应该是一个非零等级吗?

标签: c mpi


【解决方案1】:

您的偏移量中有错字

offsets[3] = offsetof(Vector3d, z);

应该改为offset[2]。我想只要解决 bcast 问题就可以了。

你的 offsetof 函数的结果是什么?它是如何工作的?

【讨论】:

  • 是的!有段错误...谢谢!
猜你喜欢
  • 2016-10-02
  • 2011-10-03
  • 2014-05-07
  • 1970-01-01
  • 2017-06-25
  • 2019-06-26
  • 1970-01-01
  • 1970-01-01
  • 2011-12-24
相关资源
最近更新 更多