Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library
- Memory leak in FEAST routines

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

cygorek__moritz

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-10-2018
10:57 AM

34 Views

Memory leak in FEAST routines

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*<<endl;*

#ifdef X_ON_HEAP

free(x);

#elif defined(X_ON_HEAP_CPP)

delete[] x;

#endif

cout<<"Done"<<endl<<flush;

return 0;

}

Link Copied

1 Reply

Gennady_F_Intel

Moderator

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-10-2018
11:51 AM

34 Views

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.