This project has moved and is read-only. For the latest updates, please go here.

Sparse matrix performance

Apr 23, 2014 at 7:17 PM
Edited Jun 27, 2014 at 10:04 PM
Just wanted to share some of the sparse matrix routines I use. Most of the stuff originally came from Sparsekit.

Source: (deleted)
Test app: (deleted)

Benchmark (the last two columns show the timings in msecs):
Operation     Name        Rows Columns    Values  Original   Extension
Multiply      fidapm02     537     537     19145      9161          35
Mult.D.Left   fidapm02     537     537     19145      9618           2
Mult.D.Right  fidapm02     537     537     19145       137           2
Transpose     fidap035   19716   19716    217972      2643           3
Clear. Rows   fidap035   19716   19716    217972       435           6
Clear. Cols   fidap035   19716   19716    196319      6404           6
Perm. Rows    fidapm07    2065    2065     45184      4131           7
Perm. Cols    fidapm07    2065    2065     45184      5451           3
Norm. Rows    fidapm09    4683    4683     93733      2176           3
Norm. Cols    fidapm09    4683    4683     93733      3551           4
Add.D.Scalar  fidapm09    4683    4683     93733      2483           6
Add.D.Matrix  fidapm09    4683    4683     95053      2352           4
Apr 24, 2014 at 12:43 AM
That's a massive speedup, thanks a lot for sharing this!

It is tracked in #216 for the next beta (v3.0.0-beta02), together with #172.

Thanks,
Christoph
Marked as answer by cdrnet on 5/2/2014 at 10:32 AM
Jun 27, 2014 at 10:15 PM
Edited Oct 16, 2014 at 2:11 PM
I've changed the Matlab mat file reading code a bit, using the fact that Matlab actually uses CSC storage.

Source: deleted

Benchmark:
Reading A-1000-x-1000.mat ...
(1000x1000) 181096 nonzeros / 458ms
(1000x1000) 181096 nonzeros / 89ms
  OK

Reading A-1000-x-1200.mat ...
(1000x1200) 217531 nonzeros / 493ms
(1000x1200) 217531 nonzeros / 81ms
  OK

Reading A-5000-x-5000.mat ...
(5000x5000) 1219075 nonzeros / 3037ms
(5000x5000) 1219075 nonzeros / 477ms
  OK

Reading A-7500-x-5000.mat ...
(7500x5000) 1144644 nonzeros / 2761ms
(7500x5000) 1144644 nonzeros / 464ms
  OK

Reading C-1500-x-1500.mat ...
(1500x1500) 88175 nonzeros / 3953ms
(1500x1500) 88175 nonzeros / 71ms
  OK
The first 4 matrices have real entries. The deflate decompression is dominating the runtime. The last matrix is complex valued. The new version's quite a bit faster, since the old code has lots of calls to matrix.At(...).
Jul 23, 2014 at 7:54 PM
Thanks again. I've included the change and extended it to the writer as well. Since dense matrices are stored in column-major format it was possible to optimize the dense case slightly as well, along the same lines. Available in the MathNet.Numerics.Data.Matlab v3.0.0 package.

Thanks,
Christoph
Oct 16, 2014 at 2:14 PM
Edited Oct 20, 2014 at 10:12 AM
I needed a fast Kronecker product for sparse matrices recently, so here's the updated code. Feel free to use ...

Source: MathNet.Numerics.Extensions-src.zip

Benchmark (old vs. new):
Kronecker    ( 5x 5) X (2410x2410)    9200ms   20ms  OK
Kronecker    ( 5x10) X (2410x2410)   18563ms   26ms  OK
Kronecker    (10x 5) X (2410x2410)   36610ms   33ms  OK
EDIT: changed the smaller matrix to be dense, to make the difference in runtime clearer.
var B = (SparseMatrix)SparseMatrix.Build.SparseOfMatrix(DenseMatrix.CreateRandom(m, n, new ContinuousUniform()));