**- Undocumented Matlab - https://undocumentedmatlab.com -**

Sparse data math info

Posted By Yair Altman On July 31, 2013 | __2 Comments__

Two weeks ago, I posted about Matlab’s math libraries ^{[1]} and their various versions across Matlab releases. Matlab relies on the proprietary Intel MKL ^{[2]} and AMD ACML ^{[3]} libraries for most of its core math, matrix manipulation and linear algebra functions, for Intel/AMD CPUs (respectively). MKL and ACML are adaptations of, and wrappers for, the ubiquitous BLAS ^{[4]} and LAPACK ^{[5]} packages (LAPACK uses BLAS for its low-level functionality).

Unfortunately, BLAS can be used only with full (non-sparse) matrix data on a CPU. So, for GPU support Matlab uses MAGMA ^{[6]} (*libmwmagma.dll*). Similarly, for sparse data Matlab uses the SuiteSparse ^{[7]} library by University of Florida’s Tim Davis, whose work on sparse matrix software has very recently earned him SIAM fellowship ^{[8]}. SuiteSparse is used ^{[9]} by Google Earth and Street-View to create their amazing real-time 3D renditions.

SuiteSparse relies on sparse-data algorithms that have been developed over many years (since the 70’s elsewhere, since 1991 at UFL), and continuously evolve to this day. A presentation about the algorithms in 2006 is available: video ^{[10]}, slides (FEX #12295) ^{[11]}. A detailed presentation of some of the algorithms can be found in Tim’s book “Direct Methods for Sparse Linear Systems ^{[12]}” (SIAM, 2006), which should not be confused with Tim’s other book, the widely-popular “Matlab Primer ^{[13]}“. A more recent technical description of the sparse algorithms is provided in an ACM paper ^{[14]}.

SuiteSparse has been incorporated into Matlab’s core functionality over the span of several years, between 2000 and 2009 (details ^{[15]}). The functions were apparently incorporated into *libmwmathlinalg.dll, libmwmathcore.dll, libcolamd.dll, libmwspmatrix.dll, libmwumfpack.dll, libmwumfpack_api.dll, libmwcholmod.dll, libmwamd.dll, libmwspqr.dll, libmwma57.dll, libmwcsparse.dll, libmwspqr.dll* (and possibly a couple of other DLLs I missed). On *nix systems, the libraries have the same name, with an **.so* extension (e.g., *libmwcsparse.so*). All these dynamic libraries are located in the */bin/%arch%/* folder of the Matlab installation, alongside the rest of Matlab’s libs. The lib names are pretty self-explanatory, for example *libmwspqr.dll* contains the SuiteSparse QR ^{[16]} library; *libmwcsparse.dll* contains the CSparse library (which is described in the above-mentioned SIAM book).

Back in 2007, SuiteSparse could be used in Matlab as a separate package on the File Exchange (#12233 ^{[17]}), which was discussed on Loren’s blog ^{[18]}. Since Matlab has incorporated SuiteSparse into its core functions, FEX #12233 is no longer available. We can still download the sources directly from the SuiteSparse page ^{[7]} on UFL.

Unlike BLAS, LAPACK, FFTW and MKL, there is no known way to directly extract the sparse-libs version info in Matlab. But there is an indirect way to do so, and in the process, we discover lots of interesting information about the internal mechanisms of the sparse algos.

We begin by setting the debugging information to maximum using the **spparms**^{[19]} function. This not only provides version info, but also all kinds of diagnostics about the sparse matrices and the selected algorithm path. For example (note the highlighted version info text):

```
>> spparms('spumoni',2)
>> load west0479
>> b = rand(size(west0479,1));
>> x = west0479 \ b;
sp\: bandwidth = 388+1+337.
sp\: is A diagonal? no.
sp\: is band density (0.01) > bandden (0.50) to try banded solver? no.
sp\: is A triangular? no.
sp\: is A morally triangular? no.
sp\: is A a candidate for Cholesky (symmetric, real positive diagonal)? no.
sp\: use Unsymmetric MultiFrontal PACKage with automatic reordering.
UMFPACK V5.4.0 (May 20, 2009), Control:
Matrix entry defined as: double
Int (generic integer) defined as: UF_long
BLAS library used: Fortran BLAS. size of BLAS integer: 8
MATLAB: yes.
CPU timer: ANSI clock ( ) routine.
number of rows in matrix A: 479
number of columns in matrix A: 479
entries in matrix A: 1887
memory usage reported in: 16-byte Units
size of int: 4 bytes
size of UF_long: 8 bytes
size of pointer: 8 bytes
size of numerical entry: 8 bytes
strategy used: unsymmetric
ordering used: colamd on A
modify Q during factorization: yes
prefer diagonal pivoting: no
pivots with zero Markowitz cost: 133
... % lots of other interesting internal information
```

A Matlab script to extract the sparse libs’ version info is provided here ^{[20]}. The script runs a few sparse math operations that more-or-less cover the sparse libs, and then reports the version data when it’s done. In order to parse the debugging info, the script uses either an external OS * grep* command (which is available on Linux & Macs), or a Matlab equivalent

```
>> sparse_lib_versions
... % numerous debugging info...
=> sparse matrix library versions (from C:\Users\Yair\AppData\Local\Temp\sparse_info.txt):
============================================================
AMD version 2.2.0, May 31, 2007: approximate minimum degree ordering
AMD version 2.2.0, May 31, 2007, results:
colamd version 2.5, May 5, 2006: OK.
CHOLMOD version 1.7.0, Sept 20, 2008: : status: OK
CHOLMOD version 1.7.0, Sept 20, 2008: : status: OK
SuiteSparseQR, version 1.1.0 (Sept 20, 2008)
UMFPACK V5.4.0 (May 20, 2009), Control:
UMFPACK V5.4.0 (May 20, 2009), Info:
```

It looks like MathWorks haven’t updated Matlab’s sparse libs in quite a few years. These libraries continue to be improved continuously, but most of the tweaks are quite minor and no important bugs were found for many years, so I guess that we can’t really complain.

I will be visiting clients in Austria and Switzerland in August. If you live in the area, I will be happy to meet you to discuss how I could bring value to your needs, as consultant, contractor or trainer. Please email me ^{[22]} if you think that this could be relevant for you. The relevant dates are:

- Vienna – Aug 18, 25-26
- Salzburg – Aug 19-23
- Zurich – Aug 26-29

*Bis bald!*

Categories: Medium risk of breaking in future versions, Stock Matlab function, Undocumented feature

2 Comments (Open | Close)

Article printed from Undocumented Matlab: **https://undocumentedmatlab.com**

URL to article: **https://undocumentedmatlab.com/articles/sparse-data-math-info**

URLs in this post:

[1] Matlab’s math libraries: **http://undocumentedmatlab.com/blog/math-libraries-version-info-upgrade/**

[2] MKL: **http://en.wikipedia.org/wiki/Math_Kernel_Library**

[3] ACML: **http://en.wikipedia.org/wiki/AMD_Core_Math_Library**

[4] BLAS: **http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms**

[5] LAPACK: **http://en.wikipedia.org/wiki/LAPACK**

[6] MAGMA: **http://icl.cs.utk.edu/magma/**

[7] SuiteSparse: **http://www.cise.ufl.edu/research/sparse/SuiteSparse/**

[8] SIAM fellowship: **http://connect.siam.org/announcing-the-2013-class-of-siam-fellows**

[9] used: **http://google-opensource.blogspot.co.il/2012/05/introducing-ceres-solver-nonlinear.html**

[10] video: **http://www.cise.ufl.edu/research/sparse/SIAM06/**

[11] slides (FEX #12295): **http://www.mathworks.com/matlabcentral/fileexchange/12295-slides-for-the-video-direct-methods-for-sparse-linear-systems-the-matlab-sparse-backslash**

[12] Direct Methods for Sparse Linear Systems: **http://www.cise.ufl.edu/research/sparse/CSparse/**

[13] Matlab Primer: **http://www.crcpress.com/product/isbn/9781439828625**

[14] ACM paper: **http://dl.acm.org/authorize?6504337**

[15] details: **http://www.cise.ufl.edu/research/sparse/**

[16] SuiteSparse QR: **http://www.cise.ufl.edu/research/sparse/SPQR**

[17] #12233: **http://www.mathworks.com/matlabcentral/fileexchange/12233**

[18] Loren’s blog: **http://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/**

[19] * spparms*:

[20] here: **http://undocumentedmatlab.com/files/sparse_lib_versions.m**

[21] Matlab equivalent: **http://www.mathworks.com/matlabcentral/fileexchange/9647-grep-a-pedestrian-very-fast-grep-utility**

[22] email me: **mailto: altmany @gmail.com?subject=AT-CH meeting&body=Hi Yair, &cc=;&bcc=**

[23] Math libraries version info & upgrade : **https://undocumentedmatlab.com/articles/math-libraries-version-info-upgrade**

[24] Function definition meta-info : **https://undocumentedmatlab.com/articles/function-definition-meta-info**

[25] Simulink Data Dictionary : **https://undocumentedmatlab.com/articles/simulink-data-dictionary**

[26] Controlling plot data-tips : **https://undocumentedmatlab.com/articles/controlling-plot-data-tips**

[27] Draggable plot data-tips : **https://undocumentedmatlab.com/articles/draggable-plot-data-tips**

[28] Additional license data : **https://undocumentedmatlab.com/articles/additional-license-data**

Click here to print.

Copyright © Yair Altman - Undocumented Matlab. All rights reserved.

2 Comments To "Sparse data math info"

#1 CommentByDrazickOn August 8, 2013 @ 09:17Why don’t you open a Google+ Page?

#2 CommentByYair AltmanOn August 8, 2013 @ 09:21…because it’s too much trouble to manually update the g+ page with each post every week…

If you wish to follow this blog, the best way is to subscribe via RSS or email using the links at the top-right of each page on this website.