我已经尝试了两天以上,看看我做了什么错,但我找不到任何东西。我一直收到以下错误:
=终止您的一个申请流程
=退出代码:139
=清理剩余的过程
=你可以忽略以下的清理消息
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 :(得分:4)
运行时错误是由于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_BCAST
。 MPI_BCAST
本身未在mpi.h
中声明,但ANSI C允许在没有先前原型声明的情况下调用函数。通过将-std=c99
传递给编译器来启用C99会导致关于MPI_BCAST
函数的隐式声明的警告。另外-Wall
会导致警告。代码将无法与Open MPI链接,Open MPI在mpicc
未链接的单独库中提供Fortran接口。
即使代码正确编译和链接,Fortran函数也希望通过引用传递所有参数。此外,Fortran MPI调用会返回一个额外的输出参数,其中返回错误代码。因此分段错误。
为防止将来出现此类错误,请使用-Wall -Werror
进行编译,以便尽早发现类似问题。
答案 1 :(得分:2)
这样做有一个正式答案:你将MPI_Bcast
拼写为MPI_BCAST
。我会假设这会因为尝试访问一个不存在的函数而引发链接错误,但显然它没有。
我的猜测是你的MPI实现在同一个头文件中定义了Fortran和C MPI函数。然后你的程序意外地调用了Fortran函数MPI_BCAST
并且类型没有加起来(MPI_INTEGER
(Fortran)不一定是MPI_INT
(C)),不知何故给你了段错误。 / p>