2016-02-26 45 views
-2

我想MPI_Bcast廣播發送到多個節點,我得到分段錯誤與錯誤有時:139或錯誤:255以下是我的代碼:MPI_Bcast段錯誤139

char proposal[20]; 
char rep; 
int size, rank; 
printf("1\n"); 
//Initialization 
MPI_Init(&argc, &argv); 

printf("init\n"); 
//Getting size and rank of processes 
MPI_Comm_size(MPI_COMM_WORLD, &size); 
printf("abc\n"); 
MPI_Comm_rank(MPI_COMM_WORLD, &rank); 

printf("2\n"); 
//Proposal message for root node 
if(rank == 0) 
{ 
    printf("string copy\n"); 
    strcpy("Choose a or b\n", proposal); 
} 

printf("3\n"); 
//Broadcasting message 
MPI_Bcast(proposal, 20, MPI_CHAR, 0, MPI_COMM_WORLD); 
printf("broadcast\n"); 
printf("%s", proposal); 

我真的感謝如果我能得到任何幫助。

回答

2

strcpy第一個參數是目的地,第二個是源。你有它倒過來。

+0

我不認爲這是問題,因爲我刪除了該部分,錯誤仍然存​​在。 – anonymousCoder

+0

這顯然是一個問題。它是*問題嗎?我不知道。代碼不完整,沒有其他可見的問題。 –

+0

它可能是一個問題,但我改變了它,錯誤仍然存​​在。就代碼而言。是的,除了我包括的庫和MPI_Finalize()在外的所有內容都已完成 – anonymousCoder