繁体   English   中英

***使用FEAST在函数返回时检测到堆栈粉碎错误***

[英]*** stack smashing detected *** error at the return of a function using FEAST

我有一个很长的程序,其中有一个函数用于使用FEAST计算大型矩阵的特征值。 就在该函数返回时,我得到了*检测到堆栈崩溃*错误,并且我丢失了所有结果。 这是我的功能

    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;
}

dfeast_scsrev是FEAST库(也是intel MKL的一部分)中的函数。 该错误就在返回时发生(即在打印“将特征值写入文件evals.dat”之后)。 根据我遇到的问题,有时我也会在同一时间遇到分割错误。

如果删除FEAST函数调用,则没有错误。 因此,我很困惑自己在做什么错。 我正在尝试使用valgrind,但由于我的代码太大,因此运行时间很长。

查看https://software.intel.com/zh-cn/node/521749上的文档,我看到res应该指向“长度为m0的数组” 您的res仅是一个double 当然,dfeast_scsrev不知道这一点,并且快乐地在边界之外写入,从而破坏了堆栈。

因此解决方法是:

double *res = new double [m0]; 而不是double res;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM