2015-10-22 70 views
0

我一直在嘗試兩天以上,看看我做了什麼錯誤,但找不到任何東西。我不斷收到以下錯誤:MPI分段錯誤(信號11)

= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES

= EXIT CODE: 139

= CLEANING UP REMAINING PROCESSES

= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES

YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11) 

This typically refers to a problem with your application. 

Please see the FAQ page for debugging suggestions 

make: *** [run] Error 139 

所以,問題顯然是MPI_BCAST和其他功能我有MPI_GATHER。 你能幫我弄清楚有什麼問題嗎? 當我編譯代碼我鍵入以下內容:

/usr/bin/mpicc -I/usr/include -L/usr/lib z.main.c z.mainMR.c z.mainWR.c -o 1dcode -g -lm 

出馬:

usr/bin/mpirun -np 2 ./1dcode dat.txt o.out.txt 

例如我的代碼,包括這樣的功能:

#include <stdio.h> 
#include <stdlib.h> 
#include <ctype.h> 
#include <math.h> 
#include <string.h> 
#include "functions.h" 
#include <mpi.h> 
/*...................z.mainMR master function............. */ 
void MASTER(int argc, char *argv[], int nPROC, int nWRs, int mster) 
{ 

/*... Define all the variables we going to use in z.mainMR function..*/ 
double tend, dtfactor, dtout, D, b, dx, dtexpl, dt, time; 
int MM, M, maxsteps, nsteps; 
FILE *datp, *outp; 
/*.....Reading the data file "dat" then saving the data in o.out.....*/ 
datp = fopen(argv[1],"r"); // Open the file in read mode 
outp = fopen(argv[argc-1],"w"); // Open output file in write mode 
if(datp != NULL) // If data file is not empty continue 
{ 
fscanf(datp,"%d %lf %lf %lf %lf %lf",&MM,&tend,&dtfactor,&dtout,&D,&b); // read the data 
fprintf(outp,"data>>>\nMM=%d\ntend=%lf\ndtfactor=%lf\ndtout=%lf\nD=%lf\nb=%lf\n",MM,tend,dtfactor,dtout,D,b); 
fclose(datp); // Close the data file 
fclose(outp); // Close the output file 
} 
else // If the file is empty then print an error message 
{ 
    printf("There is something wrong. Maybe file is empty.\n"); 
} 

/*.... Find dx, M, dtexpl, dt and the maxsteps........*/ 
dx = 1.0/ (double) MM; 
M = b * MM; 
dtexpl = (dx * dx)/(2.0 * D); 
dt = dtfactor * dtexpl; 
maxsteps = (int)(tend/dt) + 1; 

/*...Pack integers in iparms array, reals in parms array...*/ 
int iparms[2] = {MM,M}; 
double parms[4] = {dx, dt, D, b}; 
MPI_BCAST(iparms,2, MPI_INT,0,MPI_COMM_WORLD); 
MPI_BCAST(parms, 4, MPI_DOUBLE,0, MPI_COMM_WORLD); 
} 
+0

爲什麼投我的問題?這是我在這個網站上的第一個問題,我真的需要幫助。我道歉,如果我犯了一些錯別字,或使它看起來像一團糟。 – Ruzayqat

+1

你是如何清楚地**推斷出問題出現在'MPI_BCAST'中的?除了C函數調用實際上拼寫爲'MPI_Bcast'這一事實之外,我沒有看到MPI調用顯示出任何問題。 –

+0

哇!救了我。這是我第一次使用mpi ..問題出在拼寫上!哈哈..兩天試..我只是從某處複製了函數,它是MPI_BCAST而不是MPI_Bcast。 非常感謝你 – Ruzayqat

回答

2

運行時錯誤是由於MPICH的特定特徵和C語言特性的不幸組合。

MPICH提供單個庫文件內的兩個C和Fortran接口代碼:

000000000007c7a0 W MPI_BCAST 
00000000000cd180 W MPI_Bcast 
000000000007c7a0 W PMPI_BCAST 
00000000000cd180 T PMPI_Bcast 
000000000007c7a0 W mpi_bcast 
000000000007c7a0 W mpi_bcast_ 
000000000007c7a0 W mpi_bcast__ 
000000000007c7a0 W pmpi_bcast 
000000000007c7a0 T pmpi_bcast_ 
000000000007c7a0 W pmpi_bcast__ 

函數Fortran呼叫在各種別名的出口,以支持多種不同的Fortran編譯器在同一時間,包括全部大寫MPI_BCASTMPI_BCAST本身未在mpi.h中聲明,但ANSI C允許在沒有原型聲明的情況下調用函數。通過將-std=c99傳遞給編譯器來啓用C99會導致有關隱式聲明MPI_BCAST函數的警告。另外-Wall會導致警告。該代碼將無法與Open MPI鏈接,該Open MPI在獨立庫中提供Fortran接口,該鏈接庫不會鏈接到mpicc

即使代碼編譯和鏈接正確,Fortran函數也希望所有參數都通過引用傳遞。另外,Fortran MPI調用還會返回錯誤代碼的附加輸出參數。因此分段故障。

爲了避免將來出現此類錯誤,請編譯-Wall -Werror,這應該儘可能早地發現類似的問題。

2

只是讓這有一個正式的答案:你拼寫爲MPI_BcastMPI_BCAST。我會假設這會在你嘗試訪問一個不存在的函數時拋出鏈接錯誤,但顯然它沒有。

我的猜測是你的MPI實現在同一個頭文件中定義了Fortran和C MPI函數。你的程序然後不小心調用了Fortran函數MPI_BCAST,並且類型沒有加起來(MPI_INTEGER(Fortran)不一定是MPI_INT(C)),以某種方式給你段錯誤。

相關問題