Thursday, November 19, 2009

Scientific Computing / Linear Algebra Library Survey

This is my 101st times surveying linear algebra libraries for C++. Originally I tried to google the performance comparison from one to the other, but unexpectedly this is the most fruitful survey I have ever had since three months ago.

  1. Linear Algebra Libraries by Claire Mouton, March 2009.
    Detailed comparison btw CPPLapack, Eigen, Flens, Gmm++, GNU Scientific Library, IT++, Lapack++, MTL, PETSc, Seldon, SparseLib++, TNT, Trilinos, uBlas, and others by listing developers, license, interface, performance description, portability, dependencies, and some limitations. A very clear and useful document.

  2. On the Reusability and Numeric Efficiency of C++ Packages in Scientific Computing
    http://www.linuxclustersinstitute.org/conferences/archive/2003/PDF/Mello_U.pdf
    by Ulisses Mello and Ildar Khabibrakhmanov, IBM T.J. Watson Research Center, Yorktown, NY, USA

    Performance comparison by plots in different Blas level 1, 2, 3 experiments. It compares ATLAS, Goto Blas, Blitz, uBlas, STL implementation, Fortran 77 code, C code, bsm, MTL, and A++. It's more like pure performance comparison regardless its interface or whether there is OO wrapper or not. It also provides some observations and reasons why one beats another.

  3. Help choosing a C++ matrix library
    http://old.nabble.com/Help-choosing-a-C%2B%2B-matrix-library-td18857631.html
    In-depth forum discussion. Point out several requirements for a good matrix library.
Some webpages regarding specific libraries:
  1. Goto Blas
    http://www.utexas.edu/features/2006/goto/
    The author's story. Goto is the author's Japanese last name. GotoBlas is known to be the fastest Blas library in the world. It is handcrafted down to assembly code for different specific architectures.
  2. Discussion about the adoption of either uBlas or MTL4
    http://stackoverflow.com/questions/1067821/ublas-vs-matrix-template-library-mtl4
    One mentioned Eigen.
  3. Eigen benchmark
    http://eigen.tuxfamily.org/index.php?title=Benchmark
    OO abstract, though it provides readable and maintainable code, is always a penalty for performance consideration. Eigen is one of the actively developing libraries which claims its performance. Others as I know are MTL and armadillo. One reason of not claiming performance of their C++ code is because although they provide OO interface, many of them are "wrappers" of Blas and Lapack, like IT++, Lapack++, in order to provide Fortran level performance instead of C++ implementations. It is interesting to note that Eigen claims their code is at a similar speed as ATLAS (Automatically Tuned Linear Algebra Software) and Goto Blas (critically parts are written in assembly). The other thing that is worth noting is that the FLOPS drops when performing vector-vector additions over a certain vector size, while in the IBM report above it happens in matrix-vector multiplication instead. By the way, the performance results are all about Blas level 1, 2, 3. None of them compare solving linear systems or some other advanced decomposition method, like SVD, Cholesky, eigenvalue, etc.
Short conclusion: My criteria are OO wraper, namespace, performance, and actively developing or not. I used to be pro MTL4 before I look closer Eigen. Though their is no direct comparison between MTL4 and Eigen (there is a comparison btw MTL2 and Eigen where MTL2 is very slow in Eigen benchmark). MTL4 in their performance report does not beat Goto Blas but the Eigen authors claim they do. Though there is no way to convince myself the comparison is fair, Eigen does provide several "lazy" shortcut and comfortable coding interface compared with MTL4. The other candidate is Boost::uBlas. The advantage of uBlas is it is part of Boost project. That seems to imply more users and better maintenance at the first glance. However, comparing those three, MTL4 seems much more updated than uBlas, and Eigen is more actively updated on its website than the rest two. Eigen also seems more willing to provide other decomposition methods like SVD, eigenvalues.

The last thing: license. LGPL vs. GPL used to be a very big drawback of Qt before version 4.5 since GPL means using the library is equivalent to open your source code to everyone who have access to GPL code (virtually every human being), while LGPL provides flexibility for commercial software and closed code is permitted. Eigen is either GPL or LGPL. It depends on your choice. MTL4 seems not that liberal.