How does MATLAB internally store sparse arrays / Calling MKL's sparse BLAS library for sparse matrix operations

13 Ansichten (letzte 30 Tage)
SHORT VERSION
This is a list of all the sparse formats that MKL supports. Not all of these are supported for the most up-to-date Inspector-executor Sparse BLAS routines, but MKL includes conversion functions so I can make any of these formats work. Does MATLAB use (or have the ability to convert to/from) any of these formats? If so, which ones. If not, how might I convert the format manually and/or is there a better way to call MKL's sparse BLAS routines?
.
.
MORE INFO
I would like to be able to call Intel's MKL library for sparse matrix operations, since apparently sparse matrix operations in MATLAB are still single threaded (I mean, I understand that there isnt enough time to add every new feature, but you'd think this would be a higher priority in a product called "MATrix LABratory"...).
At any rate, Im working on a project where being able to do multi-threaded sparse matrix operations is basically required, so I am trying to figure out the best way to call MKL for sparse operations.
I am in the process of trying to update the MKL library from 2017.0 to 2018.2 using this guide from Intel's website, though I suspect this won't actually work for sparse matrix operations since I'm fairly sure that MATLAB isn't using MKL for these operations (Im fairly sure that MKL 2017.0 supports some form of multi-threaded sparse operations). Even so, I had planned on doing this anyways to unlock the AVX-512 compute abilities in a computer I just finished building, so I figure I mine as well see if I can kill 2 birds with 1 stone.
Assuming updating the MKL library doesn't work, (I think) I'll have to write some sort of wrapper to manually call MKL for sparse operations. I know Matlab provides a few example c/c++ functions for this purpose (that Im hoping won't be too hard to modify, since my c/c++ is iffy at best). However, I don't know if MATLAB stores sparse arrays in a format that MKL supports (and if so which format).
  1 Kommentar
Jiaen Liu
Jiaen Liu am 13 Jun. 2018
I'm running into the same situation. I'm wondering if there is any benchmark about the speed gain of using Intel's multithreading to calculate a sparse matrix multiplied by a dense matrix compared to the Matlab's current implementation. I know you just started this project. Thank you for initializing the effort.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

James Tursa
James Tursa am 26 Mai 2018
Bearbeitet: James Tursa am 27 Mai 2018
MATLAB stores sparse matrices in the CSC 0-based format, except MATLAB does not store the pointerB and pointerE info the same way. MATLAB combines these into one array called Jc. So you would have to convert this part. But the values and row indexes are stored exactly the same in column ordered fashion.
If you are simply passing pointers to the MKL library, and the integers are the same size, you should be able to use the following:
mxGetPr(etc) for values
mxGetIr(etc) for rows
mxGetJc(etc) for pointerB
mxGetJc(etc)+1 for pointerE
If you are using complex data and R2017b memory model then you will have to copy the separate real & imaj data to interleaved format first.
  11 Kommentare
Anthony Barone
Anthony Barone am 6 Jun. 2018
Bearbeitet: Anthony Barone am 6 Jun. 2018
So, I actually think ive figured out the main error from lines 46-47. I was initializing the structure all wrong. This seems to work.
typedef struct {
sparse_matrix_type_t type;
sparse_fill_mode_t mode;
sparse_diag_type_t diag;
} matrix_descr;
struct matrix_descr descrA;
struct matrix_descr descrB;
descrA.type = SPARSE_MATRIX_TYPE_GENERAL;
descrB.type = SPARSE_MATRIX_TYPE_GENERAL;
I'm still getting a warning where I re-assign the output to a mxArray, but I imagine I can fix this...I just need to take a closer look at the functions for doing this and the examples that matlab provides.
First though, i need to update gcc (once I fixed the struct definition error i got a notice that mex officially supports gcc 6.3.x, and 4.4.7-17 is unsupported). Unfortunately I dont have root access on this machine, and I think to get a local copy of gcc I need to build it from source (which isnt THAT hard, but is somewhat time consuming).
James Tursa
James Tursa am 6 Jun. 2018
For converting the output back to mxArray, I thought our strategy was to build the output mxArray first, then build the output MKL sparse matrix from that. That way the MKL sparse output would already be part of the output mxArray and there would be no conversion to do. (All subject to mwIndex being the same size as MKL_INT of course).
But in any event, I will wait until your next post giving me your status and we can work from there.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by