**- 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 ^{[3]} and their various versions across Matlab releases. Matlab relies on the proprietary Intel MKL ^{[4]} and AMD ACML ^{[5]} 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 ^{[6]} and LAPACK ^{[7]} 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 ^{[8]} (*libmwmagma.dll*). Similarly, for sparse data Matlab uses the SuiteSparse ^{[9]} library by University of Florida’s Tim Davis, whose work on sparse matrix software has very recently earned him SIAM fellowship ^{[10]}. SuiteSparse is used ^{[11]} 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 ^{[12]}, slides (FEX #12295) ^{[13]}. A detailed presentation of some of the algorithms can be found in Tim’s book “Direct Methods for Sparse Linear Systems ^{[14]}” (SIAM, 2006), which should not be confused with Tim’s other book, the widely-popular “Matlab Primer ^{[15]}“. A more recent technical description of the sparse algorithms is provided in an ACM paper ^{[16]}.

SuiteSparse has been incorporated into Matlab’s core functionality over the span of several years, between 2000 and 2009 (details ^{[17]}). 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 ^{[18]} 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 ^{[19]}), which was discussed on Loren’s blog ^{[20]}. 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 ^{[9]} 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**^{[21]} 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 ^{[22]}. 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 ^{[24]} 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/blog/sparse-data-math-info**

URLs in this post:

[1] Image: **http://undocumentedmatlab.com/feed/**

[2] **email feed**: **http://undocumentedmatlab.com/subscribe_email.html**

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[21] * spparms*:

[22] here: **https://undocumentedmatlab.com/files/sparse_lib_versions.m**

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

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

[25] Parsing mlint (Code Analyzer) output : **https://undocumentedmatlab.com/blog/parsing-mlint-code-analyzer-output**

[26] Introduction to UDD : **https://undocumentedmatlab.com/blog/introduction-to-udd**

[27] Creating a simple UDD class : **https://undocumentedmatlab.com/blog/creating-a-simple-udd-class**

[28] Getting default HG property values : **https://undocumentedmatlab.com/blog/getting-default-hg-property-values**

[29] Plot markers transparency and color gradient : **https://undocumentedmatlab.com/blog/plot-markers-transparency-and-color-gradient**

[30] Quirks with parfor vs. for : **https://undocumentedmatlab.com/blog/quirks-with-parfor-vs-for**

Click here to print.

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

2 Comments To "Sparse data math info"

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

#2 CommentByYair AltmanOn August 8, 2013 @ 9:21 am…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.