gpt4 book ai didi

c - MPI 结构错误

转载 作者:太空宇宙 更新时间:2023-11-04 03:44:25 26 4
gpt4 key购买 nike

我正在尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com