<?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 Issue with mkl_free() in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933684#M13909</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am writing an image registration program and I find that a strange error when using mkl_free(). I wrote an implementation of the matrix exponential function - expm() - from MATLAB using MKL functions. I have tested it individually by itself and it works without running into any errors.&lt;/P&gt;
&lt;P&gt;The code can be found here:&amp;nbsp;&lt;A href="https://github.com/poliu2s/MKL/blob/master/matrix_exponential.cpp"&gt;https://github.com/poliu2s/MKL/blob/master/matrix_exponential.cpp&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The problem occurs when I call it from other functions who need it for calculation. My program currently crashes right before I call the first&amp;nbsp;mkl_free() so I suspect it is some form of memory leak. But shouldn't matrices used within the function be self contained? I do not see how freeing them would cause my entire program to crash.&lt;/P&gt;
&lt;P&gt;Calls to&amp;nbsp;mkl_free_buffers(); and mkl_thread_free_buffers(); produce no effect that I can observe. I have tried turning off the Intel Memory Manager with&amp;nbsp;mkl_disable_fast_mm() at the cost of speed at the beginning of the program's execution but also to no avail.&lt;/P&gt;
&lt;P&gt;I have checked the inputs going into the function itself and the matrix is perfectly valid - just like the ones I used during testing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone have any suggestions as to why my program crashes when I call mkl_free(array)?&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jun 2013 00:58:14 GMT</pubDate>
    <dc:creator>Po</dc:creator>
    <dc:date>2013-06-26T00:58:14Z</dc:date>
    <item>
      <title>Issue with mkl_free()</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933684#M13909</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am writing an image registration program and I find that a strange error when using mkl_free(). I wrote an implementation of the matrix exponential function - expm() - from MATLAB using MKL functions. I have tested it individually by itself and it works without running into any errors.&lt;/P&gt;
&lt;P&gt;The code can be found here:&amp;nbsp;&lt;A href="https://github.com/poliu2s/MKL/blob/master/matrix_exponential.cpp"&gt;https://github.com/poliu2s/MKL/blob/master/matrix_exponential.cpp&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The problem occurs when I call it from other functions who need it for calculation. My program currently crashes right before I call the first&amp;nbsp;mkl_free() so I suspect it is some form of memory leak. But shouldn't matrices used within the function be self contained? I do not see how freeing them would cause my entire program to crash.&lt;/P&gt;
&lt;P&gt;Calls to&amp;nbsp;mkl_free_buffers(); and mkl_thread_free_buffers(); produce no effect that I can observe. I have tried turning off the Intel Memory Manager with&amp;nbsp;mkl_disable_fast_mm() at the cost of speed at the beginning of the program's execution but also to no avail.&lt;/P&gt;
&lt;P&gt;I have checked the inputs going into the function itself and the matrix is perfectly valid - just like the ones I used during testing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone have any suggestions as to why my program crashes when I call mkl_free(array)?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2013 00:58:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933684#M13909</guid>
      <dc:creator>Po</dc:creator>
      <dc:date>2013-06-26T00:58:14Z</dc:date>
    </item>
    <item>
      <title>the code looks fine. I tried</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933685#M13910</link>
      <description>&lt;P&gt;the code looks fine. I tried to call these routines from another funstion. I don't see problem. regard to memory leaks - the last leaks problem has been fixed in the last 11.0 u5 released resently.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2013 17:48:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933685#M13910</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2013-06-26T17:48:56Z</dc:date>
    </item>
    <item>
      <title>Thanks for responding Gennady</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933686#M13911</link>
      <description>&lt;P&gt;Thanks for responding Gennady.&lt;/P&gt;
&lt;P&gt;I was able call the function from another function as well. However, when I implemented a new optimization algorithm which required this function, it started crashing on the second iteration at mkl_free().&lt;/P&gt;
&lt;P&gt;I know this may be difficult for others to reproduce, but my collaborator also had a similar issue. Do you have any suggestions on what I could do to resolve this problem?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2013 18:09:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933686#M13911</guid>
      <dc:creator>Po</dc:creator>
      <dc:date>2013-06-26T18:09:05Z</dc:date>
    </item>
    <item>
      <title>&gt;&gt;...I do not see how freeing</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933687#M13912</link>
      <description>&amp;gt;&amp;gt;...I do not see how freeing them would cause my entire program to crash...
&amp;gt;&amp;gt;
&amp;gt;&amp;gt;...it started crashing on the second iteration at mkl_free()...

Here are two &lt;STRONG&gt;generic&lt;/STRONG&gt; examples to simulate your problem ( replace &lt;STRONG&gt;malloc&lt;/STRONG&gt; and &lt;STRONG&gt;free&lt;/STRONG&gt; with MKL functions ):

&lt;STRONG&gt;[ Test 1 ]&lt;/STRONG&gt;
...
char *pChar = ( char * )&lt;STRONG&gt;malloc&lt;/STRONG&gt;( sizeof( char ) * 1 );
...
// Do something else
...
&lt;STRONG&gt;free&lt;/STRONG&gt;( pChar );
...
&lt;STRONG&gt;free&lt;/STRONG&gt;( pChar ); &amp;lt;= Could crash here
...

&lt;STRONG&gt;[ Test 2 ]&lt;/STRONG&gt;
...
char *pChar = ( char * )&lt;STRONG&gt;malloc&lt;/STRONG&gt;( sizeof( char ) * 1 );
...
// Do something else
...
if( pChar != NULL )
{
&lt;STRONG&gt;free&lt;/STRONG&gt;( pChar );
pChar = NULL;
}
...
// Do something else
...
if( pChar != NULL )
{
&lt;STRONG&gt;free&lt;/STRONG&gt;( pChar ); // These two lines of code won't be executed since pChar is already NULL
pChar = NULL;
}
...</description>
      <pubDate>Thu, 27 Jun 2013 03:46:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933687#M13912</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2013-06-27T03:46:10Z</dc:date>
    </item>
    <item>
      <title>actually he has already used</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933688#M13913</link>
      <description>&lt;P&gt;actually he has already used mkl_malloc&amp;nbsp;&lt;/P&gt;
&lt;P&gt;double* A = (double*)mkl_malloc(4 * 4 * sizeof(double), 64);&lt;/P&gt;
&lt;P&gt;double* B = (double*)mkl_malloc(4 * 4 * sizeof(double), 64);&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2013 04:26:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933688#M13913</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2013-06-27T04:26:36Z</dc:date>
    </item>
    <item>
      <title>Hi Po,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933689#M13914</link>
      <description>&lt;P&gt;Hi Po,&lt;/P&gt;
&lt;P&gt;The return pointer (return m_exp ) in the funtion matrix_exponential()&amp;nbsp;looks be incorrect memory operation.&lt;/P&gt;
&lt;P&gt;as you see, before&amp;nbsp;call the function,&amp;nbsp; you have&lt;/P&gt;
&lt;P&gt;B=malloc() // B point a block of memory, let's say M1&lt;/P&gt;
&lt;P&gt;and &amp;nbsp;m_exp=malloc() &amp;nbsp;in function internally.&amp;nbsp;&amp;nbsp; // m_exp point another block of memory, let's&amp;nbsp;M2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Then&amp;nbsp;return pointer m_exp.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;B=m_exp.&amp;nbsp; // move B to the memory pointed by m_exp.&amp;nbsp; B-&amp;gt; M2&lt;/P&gt;
&lt;P&gt;Thus even if you release B, &amp;nbsp;the memory malloced by B at beginning (M1)&amp;nbsp;is leaked (or B&amp;nbsp;become dangling pointer).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess, this prolem&amp;nbsp;invoke other&amp;nbsp;memory problem. (include crash later when second call)&amp;nbsp;some time.&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Ying&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2013 06:46:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933689#M13914</guid>
      <dc:creator>Ying_H_Intel</dc:creator>
      <dc:date>2013-06-27T06:46:56Z</dc:date>
    </item>
    <item>
      <title>upps, thanks Ying. i have</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933690#M13915</link>
      <description>&lt;P&gt;upps, thanks Ying. i have overlooked this issue.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2013 07:51:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933690#M13915</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2013-06-27T07:51:48Z</dc:date>
    </item>
    <item>
      <title>Thanks so much for everyone's</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933691#M13916</link>
      <description>&lt;P&gt;Thanks so much for everyone's help, I appreciate all the comments.&lt;/P&gt;
&lt;P&gt;I fixed the memory leak error that Ying mentioned in his post. My new is code is still at:&amp;nbsp;&lt;A href="https://github.com/poliu2s/MKL/blob/master/matrix_exponential.cpp"&gt;https://github.com/poliu2s/MKL/blob/master/matrix_exponential.cpp&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;However, the error with using mkl_free() still exists. I have pinpointed that my application is crashing at&amp;nbsp;mkl_free(M_power); or mkl_free(M_power1); which I have commented out on Github. The matrices I am working with contain in the range of 7500x3 elements.&lt;/P&gt;
&lt;P&gt;Is there anything else that I could have overlooked?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2013 00:07:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933691#M13916</guid>
      <dc:creator>Po</dc:creator>
      <dc:date>2013-07-05T00:07:10Z</dc:date>
    </item>
    <item>
      <title>Hi Po,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933692#M13917</link>
      <description>&lt;P&gt;Hi Po,&lt;/P&gt;
&lt;P&gt;the new code looks fine.&amp;nbsp;Just a small problem, if with&amp;nbsp;the function&amp;nbsp;double *&amp;nbsp;matrix_exponential(double* matrix, double* result),&lt;/P&gt;
&lt;P&gt;the compiler&amp;nbsp; will report, error C2561: 'matrix_exponential' : function must return a value&lt;/P&gt;
&lt;P&gt;So I change it&amp;nbsp;to&amp;nbsp;void&amp;nbsp;matrix_exponential(double* matrix, double* result) and uncomment the two line of mkl_free(). and add mkl_free(A), mkl_free(B) in main(). The code seem runs without problem.&lt;/P&gt;
&lt;P&gt;You mentioned the matrix in your application contain 7500x4 matrix. Then what the real code looks like?&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Ying&lt;/P&gt;
&lt;P&gt;&amp;nbsp;You mentioned, the matrix&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2013 06:32:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933692#M13917</guid>
      <dc:creator>Ying_H_Intel</dc:creator>
      <dc:date>2013-07-08T06:32:18Z</dc:date>
    </item>
    <item>
      <title>Hi Ying,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933693#M13918</link>
      <description>&lt;P&gt;Hi Ying,&lt;/P&gt;
&lt;P&gt;Thanks for pointing out that last mistake (I was using it for illustration purposes so I didn't catch it). I have posted a portion of the code I am working with here:&amp;nbsp;&lt;A href="https://github.com/poliu2s/MKL/tree/master/project"&gt;https://github.com/poliu2s/MKL/tree/master/project&lt;/A&gt;. It better describes the issue. I am running the testPoseDerivative.cpp without issue but there is a memory leak currently in MultiObjModelMKL.cpp that occurs on line 52 with m_exp2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I try to mkl_free that m_exp2 matrix or comment out the line (it is unused in matrix_exponential()), it will cause the test to crash during runtime. The matrices I am using can be seen in&amp;nbsp;&lt;STRONG&gt;EuclideanModel.txt&amp;nbsp;&lt;/STRONG&gt;file.&lt;/P&gt;
&lt;P&gt;Thanks again for your help so far,&lt;/P&gt;
&lt;P&gt;Po&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2013 18:39:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933693#M13918</guid>
      <dc:creator>Po</dc:creator>
      <dc:date>2013-07-09T18:39:53Z</dc:date>
    </item>
    <item>
      <title>Hi Po,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933694#M13919</link>
      <description>&lt;P&gt;Hi Po,&lt;/P&gt;
&lt;P&gt;As there is only part of code, i can't test.&amp;nbsp; Do you have run memory leak check&amp;nbsp;tools, like Intel Parallel Ampilifer and see&amp;nbsp;if it can detect the real&amp;nbsp;cause?&lt;/P&gt;
&lt;P&gt;And what is your mkl version?&amp;nbsp; and how do you link mkl? if&amp;nbsp;you are using MKL threading library,&amp;nbsp;what about if try MKL sequential library?&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Ying&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2013 04:39:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933694#M13919</guid>
      <dc:creator>Ying_H_Intel</dc:creator>
      <dc:date>2013-07-15T04:39:43Z</dc:date>
    </item>
    <item>
      <title>Could mkl_free accept ptr = 0</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933695#M13920</link>
      <description>&lt;P&gt;Could mkl_free accept ptr = 0; as the standard free function? This information would be nice in the documentation.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2013 09:07:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Issue-with-mkl-free/m-p/933695#M13920</guid>
      <dc:creator>naszta</dc:creator>
      <dc:date>2013-10-25T09:07:43Z</dc:date>
    </item>
  </channel>
</rss>

