<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Memory leak in FEAST routines  in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-leak-in-FEAST-routines/m-p/1181477#M29355</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I was experimenting with the FEAST routines and found a problem with memory leaks.&lt;/P&gt;

&lt;P&gt;In particular, the zfeast_heev routine works perfectly fine, when the parameter "x" is allocated on the stack, e.g, when one defines:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;MKL_Complex16 x[DIM*m0];&lt;/P&gt;

&lt;P&gt;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.&lt;/P&gt;

&lt;P&gt;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.&lt;/P&gt;

&lt;P&gt;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&amp;nbsp; -L${MKLROOT}/lib/intel64&amp;nbsp; -lmkl_intel_thread -lmkl_rt -lmkl_core -lmkl_intel_lp64 -lm"&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Can somebody reproduce this issue, maybe also with icc?&amp;nbsp; How would one correctly allocate dynamic memory for the use in the FEAST routines?&lt;/P&gt;

&lt;P&gt;Regards, Moritz&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;#include &amp;lt;iostream&amp;gt;&lt;BR /&gt;
	#include &amp;lt;cmath&amp;gt;&lt;BR /&gt;
	#include &amp;lt;string&amp;gt;&lt;BR /&gt;
	#include &amp;lt;complex&amp;gt;&lt;BR /&gt;
	#include &amp;lt;malloc.h&amp;gt;&lt;/P&gt;

&lt;P&gt;#include "mkl.h"&lt;BR /&gt;
	#include "mkl_solvers_ee.h"&lt;/P&gt;

&lt;P&gt;using namespace std;&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	int main(int args, char** argv){&lt;BR /&gt;
	&amp;nbsp; const MKL_INT m0=4;&lt;BR /&gt;
	&amp;nbsp; double lambdamin=-1,lambdamax=2;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; const MKL_INT DIM=4;&lt;BR /&gt;
	&amp;nbsp; MKL_Complex16 A[4][4]={&amp;nbsp; \&lt;BR /&gt;
	{{0.,0.},{sqrt(3.)/2.,0.},{0.,0.},{0.,0.}},&amp;nbsp; \&lt;BR /&gt;
	{{sqrt(3.)/2.,0.},{0.,0.},{1.,0.},{0.,0.}},&amp;nbsp; \&lt;BR /&gt;
	{{0.,0.},{1.,0.},{0.,0.},{sqrt(3.)/2.,0.}},&amp;nbsp; \&lt;BR /&gt;
	{{0.,0.},{0.,0.},{sqrt(3.)/2.,0.},{0.,0.}} };&lt;BR /&gt;
	//The exact eigenvalues are: -1.5, -0.5, 0.5 and 1.5&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; MKL_Complex16 zero = {0.0, 0.0};&lt;BR /&gt;
	&amp;nbsp; char uplo = 'F';&lt;BR /&gt;
	&amp;nbsp; MKL_INT fpm[128];&lt;BR /&gt;
	&amp;nbsp; MKL_INT n=DIM;&lt;BR /&gt;
	&amp;nbsp; double epsout=0.;&lt;BR /&gt;
	&amp;nbsp; MKL_INT loop=0;&lt;BR /&gt;
	&amp;nbsp; MKL_INT m0var=m0;&lt;BR /&gt;
	&amp;nbsp; MKL_INT m=m0;&lt;BR /&gt;
	&amp;nbsp; double res=0.;&lt;BR /&gt;
	&amp;nbsp; int info=0;&lt;BR /&gt;
	&amp;nbsp; double lambdaptr[DIM];&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	#define X_ON_HEAP_CPP&lt;BR /&gt;
	#ifdef X_ON_HEAP_C&lt;BR /&gt;
	&amp;nbsp; MKL_Complex16 *x=(MKL_Complex16*)malloc(sizeof(MKL_Complex16)*DIM*m0);&lt;BR /&gt;
	#elif defined(X_ON_HEAP_CPP)&lt;BR /&gt;
	&amp;nbsp; MKL_Complex16 *x=new MKL_Complex16[DIM*m0];&lt;BR /&gt;
	#else&lt;BR /&gt;
	&amp;nbsp; MKL_Complex16 x[DIM*m0];&lt;BR /&gt;
	#endif&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp; feastinit(fpm);&lt;BR /&gt;
	&amp;nbsp; fpm[0]=1;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; zfeast_heev( &amp;amp;uplo, &amp;amp;n,&amp;nbsp; \&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (MKL_Complex16 *) &amp;amp;A[0][0], &amp;amp;n,&amp;nbsp; \&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fpm, &amp;amp;epsout, &amp;amp;loop, &amp;amp;lambdamin, &amp;amp;lambdamax, &amp;amp;m0var, \&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lambdaptr, (MKL_Complex16 *) x, &amp;amp;m, &amp;amp;res, &amp;amp;info);&lt;/P&gt;

&lt;P&gt;&amp;nbsp; cout&amp;lt;&amp;lt;"Nr of eigenvalues found: "&amp;lt;&amp;lt;m&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;flush;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp; for(int i=0;i&amp;lt;m;i++)cout&amp;lt;&amp;lt;lambdaptr&lt;I&gt;&amp;lt;&amp;lt;endl;&lt;/I&gt;&lt;/P&gt;

&lt;P&gt;#ifdef X_ON_HEAP&lt;BR /&gt;
	&amp;nbsp; free(x);&lt;BR /&gt;
	#elif defined(X_ON_HEAP_CPP)&lt;BR /&gt;
	&amp;nbsp; delete[] x;&lt;BR /&gt;
	#endif&lt;BR /&gt;
	&amp;nbsp; cout&amp;lt;&amp;lt;"Done"&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;flush;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; return 0;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 May 2018 17:57:52 GMT</pubDate>
    <dc:creator>cygorek__moritz</dc:creator>
    <dc:date>2018-05-10T17:57:52Z</dc:date>
    <item>
      <title>Memory leak in FEAST routines</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-leak-in-FEAST-routines/m-p/1181477#M29355</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I was experimenting with the FEAST routines and found a problem with memory leaks.&lt;/P&gt;

&lt;P&gt;In particular, the zfeast_heev routine works perfectly fine, when the parameter "x" is allocated on the stack, e.g, when one defines:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;MKL_Complex16 x[DIM*m0];&lt;/P&gt;

&lt;P&gt;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.&lt;/P&gt;

&lt;P&gt;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.&lt;/P&gt;

&lt;P&gt;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&amp;nbsp; -L${MKLROOT}/lib/intel64&amp;nbsp; -lmkl_intel_thread -lmkl_rt -lmkl_core -lmkl_intel_lp64 -lm"&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Can somebody reproduce this issue, maybe also with icc?&amp;nbsp; How would one correctly allocate dynamic memory for the use in the FEAST routines?&lt;/P&gt;

&lt;P&gt;Regards, Moritz&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;#include &amp;lt;iostream&amp;gt;&lt;BR /&gt;
	#include &amp;lt;cmath&amp;gt;&lt;BR /&gt;
	#include &amp;lt;string&amp;gt;&lt;BR /&gt;
	#include &amp;lt;complex&amp;gt;&lt;BR /&gt;
	#include &amp;lt;malloc.h&amp;gt;&lt;/P&gt;

&lt;P&gt;#include "mkl.h"&lt;BR /&gt;
	#include "mkl_solvers_ee.h"&lt;/P&gt;

&lt;P&gt;using namespace std;&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	int main(int args, char** argv){&lt;BR /&gt;
	&amp;nbsp; const MKL_INT m0=4;&lt;BR /&gt;
	&amp;nbsp; double lambdamin=-1,lambdamax=2;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; const MKL_INT DIM=4;&lt;BR /&gt;
	&amp;nbsp; MKL_Complex16 A[4][4]={&amp;nbsp; \&lt;BR /&gt;
	{{0.,0.},{sqrt(3.)/2.,0.},{0.,0.},{0.,0.}},&amp;nbsp; \&lt;BR /&gt;
	{{sqrt(3.)/2.,0.},{0.,0.},{1.,0.},{0.,0.}},&amp;nbsp; \&lt;BR /&gt;
	{{0.,0.},{1.,0.},{0.,0.},{sqrt(3.)/2.,0.}},&amp;nbsp; \&lt;BR /&gt;
	{{0.,0.},{0.,0.},{sqrt(3.)/2.,0.},{0.,0.}} };&lt;BR /&gt;
	//The exact eigenvalues are: -1.5, -0.5, 0.5 and 1.5&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; MKL_Complex16 zero = {0.0, 0.0};&lt;BR /&gt;
	&amp;nbsp; char uplo = 'F';&lt;BR /&gt;
	&amp;nbsp; MKL_INT fpm[128];&lt;BR /&gt;
	&amp;nbsp; MKL_INT n=DIM;&lt;BR /&gt;
	&amp;nbsp; double epsout=0.;&lt;BR /&gt;
	&amp;nbsp; MKL_INT loop=0;&lt;BR /&gt;
	&amp;nbsp; MKL_INT m0var=m0;&lt;BR /&gt;
	&amp;nbsp; MKL_INT m=m0;&lt;BR /&gt;
	&amp;nbsp; double res=0.;&lt;BR /&gt;
	&amp;nbsp; int info=0;&lt;BR /&gt;
	&amp;nbsp; double lambdaptr[DIM];&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	#define X_ON_HEAP_CPP&lt;BR /&gt;
	#ifdef X_ON_HEAP_C&lt;BR /&gt;
	&amp;nbsp; MKL_Complex16 *x=(MKL_Complex16*)malloc(sizeof(MKL_Complex16)*DIM*m0);&lt;BR /&gt;
	#elif defined(X_ON_HEAP_CPP)&lt;BR /&gt;
	&amp;nbsp; MKL_Complex16 *x=new MKL_Complex16[DIM*m0];&lt;BR /&gt;
	#else&lt;BR /&gt;
	&amp;nbsp; MKL_Complex16 x[DIM*m0];&lt;BR /&gt;
	#endif&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp; feastinit(fpm);&lt;BR /&gt;
	&amp;nbsp; fpm[0]=1;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; zfeast_heev( &amp;amp;uplo, &amp;amp;n,&amp;nbsp; \&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (MKL_Complex16 *) &amp;amp;A[0][0], &amp;amp;n,&amp;nbsp; \&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fpm, &amp;amp;epsout, &amp;amp;loop, &amp;amp;lambdamin, &amp;amp;lambdamax, &amp;amp;m0var, \&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lambdaptr, (MKL_Complex16 *) x, &amp;amp;m, &amp;amp;res, &amp;amp;info);&lt;/P&gt;

&lt;P&gt;&amp;nbsp; cout&amp;lt;&amp;lt;"Nr of eigenvalues found: "&amp;lt;&amp;lt;m&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;flush;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp; for(int i=0;i&amp;lt;m;i++)cout&amp;lt;&amp;lt;lambdaptr&lt;I&gt;&amp;lt;&amp;lt;endl;&lt;/I&gt;&lt;/P&gt;

&lt;P&gt;#ifdef X_ON_HEAP&lt;BR /&gt;
	&amp;nbsp; free(x);&lt;BR /&gt;
	#elif defined(X_ON_HEAP_CPP)&lt;BR /&gt;
	&amp;nbsp; delete[] x;&lt;BR /&gt;
	#endif&lt;BR /&gt;
	&amp;nbsp; cout&amp;lt;&amp;lt;"Done"&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;flush;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; return 0;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 17:57:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-leak-in-FEAST-routines/m-p/1181477#M29355</guid>
      <dc:creator>cygorek__moritz</dc:creator>
      <dc:date>2018-05-10T17:57:52Z</dc:date>
    </item>
    <item>
      <title>Moritz, this routine should</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-leak-in-FEAST-routines/m-p/1181478#M29356</link>
      <description>&lt;P&gt;Moritz, this routine should work with memory allocates on the stack or on the heap. First of all pls try to link the example properly as &lt;A href="https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor"&gt;MKL Linker Adviser&lt;/A&gt; recommends.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 18:51:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-leak-in-FEAST-routines/m-p/1181478#M29356</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2018-05-10T18:51:17Z</dc:date>
    </item>
  </channel>
</rss>

