Turn on suggestions

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

Showing results for

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

Po

Beginner

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

06-25-2013
05:58 PM

67 Views

Issue with mkl_free()

Hi,

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.

The code can be found here: https://github.com/poliu2s/MKL/blob/master/matrix_exponential.cpp

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 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.

Calls to 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 mkl_disable_fast_mm() at the cost of speed at the beginning of the program's execution but also to no avail.

I have checked the inputs going into the function itself and the matrix is perfectly valid - just like the ones I used during testing.

Does anyone have any suggestions as to why my program crashes when I call mkl_free(array)?

Link Copied

11 Replies

Gennady_F_Intel

Moderator

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

06-26-2013
10:48 AM

67 Views

Po

Beginner

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

06-26-2013
11:09 AM

67 Views

Thanks for responding Gennady.

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().

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?

SKost

Valued Contributor II

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

06-26-2013
08:46 PM

67 Views

Gennady_F_Intel

Moderator

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

06-26-2013
09:26 PM

67 Views

actually he has already used mkl_malloc

double* A = (double*)mkl_malloc(4 * 4 * sizeof(double), 64);

double* B = (double*)mkl_malloc(4 * 4 * sizeof(double), 64);

Ying_H_Intel

Employee

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

06-26-2013
11:46 PM

67 Views

Hi Po,

The return pointer (return m_exp ) in the funtion matrix_exponential() looks be incorrect memory operation.

as you see, before call the function, you have

B=malloc() // B point a block of memory, let's say M1

and m_exp=malloc() in function internally. // m_exp point another block of memory, let's M2

Then return pointer m_exp.

B=m_exp. // move B to the memory pointed by m_exp. B-> M2

Thus even if you release B, the memory malloced by B at beginning (M1) is leaked (or B become dangling pointer).

I guess, this prolem invoke other memory problem. (include crash later when second call) some time.

Best Regards,

Ying

Gennady_F_Intel

Moderator

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

06-27-2013
12:51 AM

67 Views

upps, thanks Ying. i have overlooked this issue.

Po

Beginner

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

07-04-2013
05:07 PM

67 Views

Thanks so much for everyone's help, I appreciate all the comments.

I fixed the memory leak error that Ying mentioned in his post. My new is code is still at: https://github.com/poliu2s/MKL/blob/master/matrix_exponential.cpp.

However, the error with using mkl_free() still exists. I have pinpointed that my application is crashing at 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.

Is there anything else that I could have overlooked?

Ying_H_Intel

Employee

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

07-07-2013
11:32 PM

67 Views

Hi Po,

the new code looks fine. Just a small problem, if with the function double * matrix_exponential(double* matrix, double* result),

the compiler will report, error C2561: 'matrix_exponential' : function must return a value

So I change it to void 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.

You mentioned the matrix in your application contain 7500x4 matrix. Then what the real code looks like?

Best Regards,

Ying

You mentioned, the matrix

Po

Beginner

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

07-09-2013
11:39 AM

67 Views

Hi Ying,

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: https://github.com/poliu2s/MKL/tree/master/project. 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.

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 **EuclideanModel.txt **file.

Thanks again for your help so far,

Po

Ying_H_Intel

Employee

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

07-14-2013
09:39 PM

67 Views

Hi Po,

As there is only part of code, i can't test. Do you have run memory leak check tools, like Intel Parallel Ampilifer and see if it can detect the real cause?

And what is your mkl version? and how do you link mkl? if you are using MKL threading library, what about if try MKL sequential library?

Best Regards,

Ying

naszta

Beginner

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

10-25-2013
02:07 AM

67 Views

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