我正在尝试使用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).
答案 0 :(得分:1)
您的blocklengths
的值是结构声明中字符数的两倍。 5*20
数组只有100 char
个元素,但是你告诉MPI每个元素有200个。