[英]*** stack smashing detected *** error at the return of a function using FEAST
I have a long program in which I have a function for calculating eigenvalues of a large matrix using FEAST. 我有一个很长的程序,其中有一个函数用于使用FEAST计算大型矩阵的特征值。 Right at the return of that function I get a * stack smashing detected * error and I lose all the results.
就在该函数返回时,我得到了*检测到堆栈崩溃*错误,并且我丢失了所有结果。 Here is my the function
这是我的功能
void Model::eigensolver(double* val, int* ia, int* ja, const int n, int m0, std::string outfilename)
{
// compute Eigenvalues and Eigenvectors by calling FEAST library from MKL
const char uplo='U';
MKL_INT fpm[128], loop;
feastinit(fpm);
//fpm[0]=1;
const double emin=-1,emax=100;
MKL_INT eig_found=0;
double res,epsout;
double *eigenvalues= new double [m0];
double *eig_vec = new double [m0*_dof];
int info;
std::cout << "Everything ready, making call to FEAST." << std::endl;
dfeast_scsrev(&uplo, &n, val, ia, ja, fpm, &epsout, &loop, &emin, &emax, &m0, eigenvalues, eig_vec, &eig_found, &res, &info );
if (info != 0) {
std::cout << "Something is wrong in eigensolver. Info=" << info << std::endl;
exit(0);
}
std::cout << loop << " iterations taken to converge." << std::endl;
std::cout << eig_found << " eigenvalues found in the interval." << std::endl;
std::ofstream evals;
evals.open("evals.dat");
std::cout<<"The eigenfrequencies are:"<<std::endl;
for (int i = 0; i < eig_found; i++)
evals << eigenvalues[i] << std::endl;
evals.close();
delete[] eigenvalues;
delete[] eig_vec;
std::cout << "Writen eigenvalues to file evals.dat." << std::endl;
return;
}
The dfeast_scsrev is a function from FEAST library (also part of intel MKL). dfeast_scsrev是FEAST库(也是intel MKL的一部分)中的函数。 The error happens right at the return (ie after the "Written eigenvalues to file evals.dat." is printing).
该错误就在返回时发生(即在打印“将特征值写入文件evals.dat”之后)。 Depending on the problem I run, sometimes I also get segmentation fault right at the same point.
根据我遇到的问题,有时我也会在同一时间遇到分割错误。
If I remove the FEAST function call, there is no error. 如果删除FEAST函数调用,则没有错误。 So, I am confused what I am doing wrong.
因此,我很困惑自己在做什么错。 I am trying valgrind, but because of the size of my code, it is taking a long time to run.
我正在尝试使用valgrind,但由于我的代码太大,因此运行时间很长。
Looking at the docs at https://software.intel.com/en-us/node/521749 , I see that res
should point to an "Array of length m0" . 查看https://software.intel.com/zh-cn/node/521749上的文档,我看到
res
应该指向“长度为m0的数组” 。 Your res
is only a single double
. 您的
res
仅是一个double
。 Of course, dfeast_scsrev does not know this and writes happily beyond the boundary, thus ruining your stack. 当然,dfeast_scsrev不知道这一点,并且快乐地在边界之外写入,从而破坏了堆栈。
So the fix is: 因此解决方法是:
double *res = new double [m0];
instead of double res;
而不是
double res;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.