2014-09-22 84 views
1

我想发送一个使用MPI_Bcast函数的结构,但我得到一个错误。
结构定义::MPI结构错误

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

回答

1

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

+0

它的工作原理... – 2014-09-22 17:18:07