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
- Segmentation fault trying to use mkl_dcscmm from a Matlab mex file

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

Tony_K_

Beginner

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

09-06-2013
06:21 AM

72 Views

Segmentation fault trying to use mkl_dcscmm from a Matlab mex file

mex -v -largeArrayDims -g mkl_sfmult.cpp

testA = sprand(10,5,0.5);

testB = rand(5,8);

testC = mkl_sfmult(testA, testB)

When I start Matlab in gdb, it appears the segmentation fault occurs in mkl_spblas_lp64_mc_dcsr1tg__f__mmout_par (), in mkl_spblas_lp64_dcsr1tg__f__mmout_par (), in mkl_sfmult.mexa64, otherwise just question marks in the stack trace.

I've tried making a standalone executable where I hard-code the data for a few test matrices, and I get the right result with no segfaults outside of Matlab. I'd really prefer to have a Matlab interface if possible, without needing to save the matrix data to disk or generating new source code for each problem instance. Maybe I'll try using loadlibrary instead? I've been searching through the literature and available libraries and MKL is the only multi-threaded implementation of the sparse matrix times dense matrix kernel that I can find.

Any ideas, recommendations, more info you'd need to figure out what's going on here? Thanks.

Link Copied

4 Replies

TimP

Black Belt

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

09-06-2013
08:59 AM

72 Views

http://software.intel.com/en-us/articles/determining-root-cause-of-sigsegv-or-sigbus-errors

gives a checklist which you might follow

Tony_K_

Beginner

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

09-09-2013
09:33 AM

72 Views

Thanks. Indeed it was a dumb indexing mistake, too much switching between 0-based and 1-based languages.

Where I had used A_Jc[k+1] for the number of nonzeros, it should've been A_Jc

The simple mex file works with that change, though sequential MKL appears to be slower than Matlab's own implementation of this operation. Multithreaded MKL is a little faster than serial Matlab, if the matrices are big enough.

TimP

Black Belt

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

09-09-2013
09:47 AM

72 Views

If you use OpenMP outside the MKL function calls, you would need to set OMP_NESTED in order to activate mkl threaded. You probably need to fiddle with number of threads etc in an effort to give each MKL thread its own core in hope of making this advantageous.

Wouldn't MATLAB itself use a threaded library?

Tony_K_

Beginner

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

09-09-2013
10:17 AM

72 Views

Wow, thanks for the quick reply. I had forgotten to remove the debug flag, and a few other things. Whether the mex file will use multiple cores is being inconsistent - it seems to depend on the value of MKL_NUM_THREADS when I compile the mex file, which doesn't make much sense to me. Matlab might be doing something quirky with the environment variables.

As best I can tell, Matlab doesn't do multithreaded sparse operations yet, at least not sparse*dense matmul. It uses its own version of MKL for dense BLAS, but not sparse.

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