2015-10-22 69 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)),以某种方式给你段错误。

相关问题