c - MPI 结构错误

标签 c struct char mpi

我正在尝试使用 MPI_Bcast 函数发送结构,但出现错误。
结构定义::

typedef struct _data{
      char table[5][20];
}data;

数据类型创建::

data t[100];
const int nitems=1;
int blocklengths[1] = {200};
MPI_Datatype types[1] = {MPI_CHAR};
MPI_Datatype mpi_d_type;
MPI_Aint     offsets[1];
offsets[0] = offsetof(data, table);
MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_d_type);
MPI_Type_commit(&mpi_d_type);
if (myid == ROOT) {
//reading values from stdin and storing into 't'
}
MPI_Bcast( t, 100, mpi_d_type, ROOT, MPI_COMM_WORLD);

以下是我收到的错误..

[surya:00652] [ 0] 0   libsystem_c.dylib                   0x00007fff8c65892a _sigtramp + 26
[surya:00652] [ 1] 0   ???                                 0x0000000000000000 0x0 + 0
[surya:00652] [ 2] 0   libsystem_c.dylib                   0x00007fff8c6b304c getenv + 29
[surya:00652] [ 3] 0   libsystem_c.dylib                   0x00007fff8c674b35 _simple_asl_init + 25
[surya:00652] [ 4] 0   libsystem_c.dylib                   0x00007fff8c66bfd0 pthread_once + 87
[surya:00652] [ 5] 0   libsystem_c.dylib                   0x00007fff8c6748f8 _simple_asl_log_prog +    48
[surya:00652] [ 6] 0   libsystem_c.dylib                   0x00007fff8c6b0d37 __stack_chk_fail + 183
[surya:00652] [ 7] 0   a.out                               0x0000000109a14e3a main + 810
[surya:00652] [ 8] 0   libdyld.dylib                       0x00007fff86b0c7e1 start + 0
[surya:00652] *** End of error message ***
--------------------------------------------------------------------------
mpirun noticed that process rank 1 with PID 652 on node surya exited on signal 11 (Segmentation      fault: 11).

最佳答案

您的 blocklengths 的值是结构声明中字符数的两倍。 5*20 数组只有 100 个 char 元素,但您告诉 MPI 每个元素有 200 个。

关于c - MPI 结构错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25979261/

相关文章:

c++ - Qt C++ 中对库方法的 undefined reference

struct - 如何在 ColdFusion <2016 中保留结构中的分配顺序

pointers - Go 似乎没有像我想的那样传递指针

c++ - C 和 C++ 中 char 的区别?

java - 从数组中赋值时出现 Char 数组编译时错误

c - 解析 SSL/TLS 字段。

c - 指针初始化(char 和 int)

c - 为什么 timelocal 和 mktime 无法正确处理夏令时?

c - 为什么不只在 header 中声明结构?这不会使 include-guards 变得不必要吗?

在 C 中将一个 int 转换为一个 4 字节的 char 数组