Quantcast
Channel: Intel® Software - Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 3005

Memory leak in FEAST routines

$
0
0

Hi,

I was experimenting with the FEAST routines and found a problem with memory leaks.

In particular, the zfeast_heev routine works perfectly fine, when the parameter "x" is allocated on the stack, e.g, when one defines:

 MKL_Complex16 x[DIM*m0];

but when it is dynamically allocated and stored on the heap, I get a segmentation fault upon calling free (or delete). This implies that the routines do something with this pointer that it is not supposed to do.

I append a minimal example. If you comment out "#define X_ON_HEAP_CPP", the memory is allocated on the stack and everything works fine. With the definition, or that of "#define X_ON_HEAP", the memory is allocated on the heap and the program segfaults when free (or delete) is called.

I am using mkl version 2018.2.199 and compile using g++ version 5.4.0, which I call with the compile flags "-I${MKLROOT}/include  -L${MKLROOT}/lib/intel64  -lmkl_intel_thread -lmkl_rt -lmkl_core -lmkl_intel_lp64 -lm"

 

Can somebody reproduce this issue, maybe also with icc?  How would one correctly allocate dynamic memory for the use in the FEAST routines?

Regards, Moritz

 

#include <iostream>
#include <cmath>
#include <string>
#include <complex>
#include <malloc.h>

#include "mkl.h"
#include "mkl_solvers_ee.h"

using namespace std;

int main(int args, char** argv){
  const MKL_INT m0=4;
  double lambdamin=-1,lambdamax=2;
 

  const MKL_INT DIM=4;
  MKL_Complex16 A[4][4]={  \
{{0.,0.},{sqrt(3.)/2.,0.},{0.,0.},{0.,0.}},  \
{{sqrt(3.)/2.,0.},{0.,0.},{1.,0.},{0.,0.}},  \
{{0.,0.},{1.,0.},{0.,0.},{sqrt(3.)/2.,0.}},  \
{{0.,0.},{0.,0.},{sqrt(3.)/2.,0.},{0.,0.}} };
//The exact eigenvalues are: -1.5, -0.5, 0.5 and 1.5

 

  MKL_Complex16 zero = {0.0, 0.0};
  char uplo = 'F';
  MKL_INT fpm[128];
  MKL_INT n=DIM;
  double epsout=0.;
  MKL_INT loop=0;
  MKL_INT m0var=m0;
  MKL_INT m=m0;
  double res=0.;
  int info=0;
  double lambdaptr[DIM];

#define X_ON_HEAP_CPP
#ifdef X_ON_HEAP_C
  MKL_Complex16 *x=(MKL_Complex16*)malloc(sizeof(MKL_Complex16)*DIM*m0);
#elif defined(X_ON_HEAP_CPP)
  MKL_Complex16 *x=new MKL_Complex16[DIM*m0];
#else
  MKL_Complex16 x[DIM*m0];
#endif

  feastinit(fpm);
  fpm[0]=1;

  zfeast_heev( &uplo, &n,  \
      (MKL_Complex16 *) &A[0][0], &n,  \
      fpm, &epsout, &loop, &lambdamin, &lambdamax, &m0var, \
      lambdaptr, (MKL_Complex16 *) x, &m, &res, &info);

  cout<<"Nr of eigenvalues found: "<<m<<endl<<flush;
   
  for(int i=0;i<m;i++)cout<<lambdaptr[i]<<endl;

#ifdef X_ON_HEAP
  free(x);
#elif defined(X_ON_HEAP_CPP)
  delete[] x;
#endif
  cout<<"Done"<<endl<<flush;

  return 0;
}

 

 

 

 

 


Viewing all articles
Browse latest Browse all 3005

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>