MPI Bcast与MPI_Type_create_struct分段错误 [英] MPI Bcast with MPI_Type_create_struct segmentation fault

查看:137
本文介绍了MPI Bcast与MPI_Type_create_struct分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm forcing myself to do a broadcast with a personal struct in C-language MPI. Basically I've created the struct Vector3d.

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

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

Then i've been reading and code this for each MPI Process.

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数组.

Then i do the broadcast of an array of Vector3d with this.

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);
}

运行它时我已经知道了.

And i've got this when i run it.

[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).
--------------------------------------------------------------------------

请帮助!

推荐答案

您的胶印中有错字

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

应该是offset[2].我想这就是解决bcast问题的全部方法.

Should be offset[2] instead. I guess that and fixing the bcast problem is all it takes.

offsetof函数的结果又是什么?如何运作?

Also what is the result of your offsetof function? How does it work?

这篇关于MPI Bcast与MPI_Type_create_struct分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆