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

Showing results for

- Intel Community
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
- creating a MATLAB .mex file using dspsv

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

Highlighted
##

I'm trying to use the MKL libraries to build a MATLAB routine to solve a matrix equation with a packed storage symmetric matrix (to save memory). I'm able to get it up and running fine using the following code, but for larger problems (say 5000x5000, which is still relatively small) it will run fine ~50% of the time, and crash MATLAB ~50% of the time. Does anybody see anything that I am obviously doing wrong?

cossmann__Steven

Beginner

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

12-07-2011
07:00 AM

24 Views

creating a MATLAB .mex file using dspsv

#include

#include

#include

typedef size_t INT;

#define MKL_INT INT

#include "mkl_lapacke.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])

{

/* Locals */

lapack_int n, nr, lda, ldb, info;

double *ar, *br;

ar = mxGetPr(prhs[0]); /* pointer to first input matrix */

br = mxGetPr(prhs[1]); /* pointer to second input matrix */

// dimensions of input matrix A //

lda = mxGetM(prhs[0]);

n = mxGetM(prhs[1]);

// dimensions of input matrix B //

ldb = n;

nr = mxGetN(prhs[1]);

if (lda != (ldb*(ldb+1)/2))

mexErrMsgTxt("Error, size mismatch.");

// Local arrays //

lapack_int *ipiv;

ipiv = (lapack_int *) mxMalloc(2*n*sizeof(lapack_int));

//lapack_int ipiv;

info = LAPACKE_dspsv( LAPACK_COL_MAJOR, 'U', n, nr, ar, ipiv, br, ldb);

mxFree(ipiv);

}

2 Replies

Highlighted
##

The problem appears to be something I'm doing wront in LAPACKE_dspsv. When the only thing I do is remove the size checking for the symmetric matrices and change to dgesv using:

cossmann__Steven

Beginner

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

12-07-2011
10:11 AM

24 Views

[cpp]info = LAPACKE_dgesv( LAPACK_COL_MAJOR, n, nr, ar, lda, ipiv, br, ldb);[/cpp]

everything seems to work perfectly. At least I haven't been able to crash it yet. Using dspsv, it would generally run once, and then crash the next time it ran. The input matrix is a column matrix that has the right number of elements for a packed storage matrix (n*(n+1)/2), so I have no idea what the problem could be, especially since it seems to work correctly for very small arrays and when it does run it runs fine for large arrays as well. Any ideas?

Highlighted
##

Nevermind, I figured it out I think. I was linking to the dynamic libraries and they weren't being unloaded after I ran "clear all". I statically linked and everything seems to be working.

cossmann__Steven

Beginner

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

12-07-2011
11:00 AM

24 Views

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