The Generalized Matrix Chain Algorithm
Paper · 2018 · Henrik Barthels, Marcin Copik and Paolo Bientinesi
Summary
The classical matrix chain problem (MCP) consists in finding the parenthesization of a product of several matrices that requires the fewest scalar operations. In practice, expressions are more complex: operands may be transposed or inverted, they have structural properties, and they are evaluated through library kernels such as BLAS and LAPACK. The authors formulate a generalized problem (GMCP) and propose the GMC algorithm. It maps an expression onto a sequence of calls to the available kernels and minimizes an arbitrary cost metric, such as FLOPs, execution time, or a vector metric. To achieve this, the algorithm operates on symbolic expressions, uses pattern matching, and infers and propagates the properties of intermediate results. The method is part of the linear algebra compiler Linnea. In the experiments, the generated code is on average about 9 times faster than Matlab, Julia, Eigen, Armadillo, and Blaze. The paper shows that the routine expert work of manually selecting optimal kernels, which can take days, can be automated in fractions of a second.
Key points
- The algorithm generalizes the dynamic programming approach of the classical MCP: it treats combinations of unary operators (transposition, inversion) with multiplication as an extended set of binary operations.
- Matrix properties are taken into account: lower and upper triangularity, symmetry, diagonality, SPD. They are propagated to intermediate results so that specialized kernels can be selected.
- The code generated by GMC was the fastest in 86% of the tests. In the remaining cases, it was at most 1.66 times slower than the best solution, and noticeably slower (by more than 1.1 times) in only 4% of the tests.
- The competitors were more than 10 times slower in at least 10–25% of the tests. In the worst case, naive implementations in Eigen and Matlab lagged behind by a factor of about 200.
- Generating a solution takes on average 0.13 s (from 0.0002 to 0.9 s). Where GMC lost, the cause was faster implementations of individual kernels in other libraries (for example, the outer product), not a worse parenthesization.
Institutions
Fields, topics and concepts
Shelves 4The field of science this work belongs to (OpenAlex fields).Computer Science · 19,503 worksArtificial Intelligence · 18,805 worksComputational Theory and Mathematics · 496 worksHardware and Architecture · 183 works
Cite
Cite as Henrik Barthels, Marcin Copik and Paolo Bientinesi. 2018. The Generalized Matrix Chain Algorithm. arXiv:1804.04021 (Proceedings of 2018 IEEE/ACM International Symposium on Code Generation and Optimization, Vienna, Austria, February 24-28, 2018).
@misc{barthels2018generalized,
title = {{The Generalized Matrix Chain Algorithm}},
author = {Henrik Barthels, Marcin Copik and Paolo Bientinesi},
year = {2018},
doi = {10.1145/3168804},
eprint = {1804.04021},
archivePrefix = {arXiv},
url = {https://doi.org/10.1145/3168804}
}References
- 2017. Intel®Math Kernel Library documentation. https://software.intel.com/en-us/mkl-reference-manual-for-c. (2017). OpenAlex ↗ · Scholar ↗
- 2017. Matlab documentation. http://www.mathworks.com/help/matlab. (2017). OpenAlex ↗ · Scholar ↗
- Zaid Albataineh and Fathi M. Salem. 2014. A Blind Adaptive CDMA Receiver Based on State Space Structures. CoRR abs/1408.0196 (2014). — arXiv:1408.0196 OpenAlex ↗ · Scholar ↗
- Edward Anderson, Zhaojun Bai, Christian Bischof, Susan Blackford, Jack Dongarra, Jeremy Du Croz, Anne Greenbaum, Sven Hammarling, A McKenney, and D Sorensen. 1999. LAPACK Users’ guide. Vol. 9. SIAM. OpenAlex ↗ · Scholar ↗
- Henrik Barthels. 2016. A Compiler for Linear Algebra Operations. In SPLASH ’16 Companion. ACM, Amsterdam, Netherlands. https://doi.org/10.1145/2984043.2998539 Student Research Competition. — doi:10.1145/2984043.2998539 OpenAlex ↗ · Scholar ↗
- Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and Alan Edelman. 2012. Julia: A Fast Dynamic Language for Technical Computing. (September 2012). arXiv:1209.5145 — arXiv:1209.5145 OpenAlex ↗ · Scholar ↗
- Paolo Bientinesi, Brian Gunter, and Robert A. van de Geijn. 2008. Families of Algorithms Related to the Inversion of a Symmetric Positive Definite Matrix. ACM Trans. Math. Softw. 35, 1, Article 3 (July 2008), 22 pages. doi:10.1145/1377603.1377606 OpenAlex ↗ · Scholar ↗
- Phillip G. Bradford, Gregory J.E. Rawlins, and Gregory E. Shannon. 1998. Efficient Matrix Chain Ordering in Polylog Time. SIAM J. Comput. 27, 2 (1998), 466–490. OpenAlex ↗ · Scholar ↗
- Alexander M. Bronstein, Yoni Choukroun, Ron Kimmel, and Matan Sela. 2016. Consistent Discretization and Minimization of the L1 Norm on Manifolds. CoRR abs/1609.05434 (2016). arXiv:1609.05434 — arXiv:1609.05434 OpenAlex ↗ · Scholar ↗
- Francis Y. Chin. 1978. An O(N) Algorithm for Determining a Near-optimal Computation Order of Matrix Chain Products. Commun. ACM 21, 7 (July 1978), 544–549. doi:10.1145/359545.359556 OpenAlex ↗ · Scholar ↗
- Jaeyoung Choi, Jack J Dongarra, and David W Walker. 1995. The Design of a Parallel Dense Linear Algebra Software Library: Reduction to Hessenberg, Tridiagonal, and Bidiagonal Form. Numerical Algorithms 10, 2 (1995), 379–399. OpenAlex ↗ · Scholar ↗
- Jim Christian. 1993. Flatterms, Discrimination Nets, and Fast Term Rewriting. Journal of automated reasoning 10, 1 (1993), 95–113. OpenAlex ↗ · Scholar ↗
- Thomas H. Cormen, Ronald L. Rivest, and Charles E. Leiserson. 1990. Introduction to Algorithms. McGraw-Hill, Inc. OpenAlex ↗ · Scholar ↗
- Artur Czumaj. 1996. Very Fast Approximation of the Matrix Chain Product Problem. Journal of Algorithms 21, 1 (1996), 71–79. OpenAlex ↗ · Scholar ↗
- Yin Ding and Ivan W. Selesnick. 2016. Sparsity-Based Correction of Exponential Artifacts. Signal Processing 120 (2016), 236–248. OpenAlex ↗ · Scholar ↗
- Jack J. Dongarra, Jeremy Du Croz, Sven Hammarling, and Iain S. Duff. 1990. A set of Level 3 Basic Linear Algebra Subprograms. ACM Transactions on Mathematical Software (TOMS) 16, 1 (1990), 1–17. OpenAlex ↗ · Scholar ↗
- Jack J. Dongarra, Sven Hammarling, Richard J. Hanson, and Jeremy Croz. 1988. An Extended set of FORTRAN Basic Linear Algebra Subprograms. ACM Transactions on Mathematical Software (TOMS) 14, 4 (1988), 399. OpenAlex ↗ · Scholar ↗
- Diego Fabregat-Traver and Paolo Bientinesi. 2011. Automatic Generation of Loop-Invariants for Matrix Operations. In Computational Science and its Applications, International Conference. IEEE Computer Society, Los Alamitos, CA, USA, 82–92. OpenAlex ↗ · Scholar ↗
- Diego Fabregat-Traver and Paolo Bientinesi. 2011. Knowledge-Based Automatic Generation of Partitioned Matrix Expressions. CASC 6885, 4 (2011), 144–157. OpenAlex ↗ · Scholar ↗
- Diego Fabregat-Traver and Paolo Bientinesi. 2013. A Domain-Specific Compiler for Linear Algebra Operations. In High Performance Computing for Computational Science – VECPAR 2010 (Lecture Notes in Computer Science), O. Marques M. Dayde and K. Nakajima (Eds.), Vol. 7851. Springer, Heidelberg, 346–361. OpenAlex ↗ · Scholar ↗
- Diego Fabregat-Traver and Paolo Bientinesi. 2013. Application-tailored Linear Algebra Algorithms: A search-sased Approach. International Journal of High Performance Computing Applications (IJH-PCA) 27, 4 (Nov. 2013), 425 – 438. OpenAlex ↗ · Scholar ↗
- Gene H. Golub and Charles F. Van Loan. 2013. Matrix Computations. Vol. 4. Johns Hopkins. OpenAlex ↗ · Scholar ↗
- Albert Gräf. 1991. Left-to-Right Tree Pattern Matching. In International Conference on Rewriting Techniques and Applications. Springer, 323–334. OpenAlex ↗ · Scholar ↗
- Gaël Guennebaud, Benoı̂t Jacob, et al. 2010. Eigen v3. http://eigen.tuxfamily.org. (2010). OpenAlex ↗ · Scholar ↗
- M. Hejazi, S. M. Azimi-Abarghouyi, B. Makki, M. Nasiri-Kenari, and T. Svensson. 2016. Robust Successive Compute-and-Forward Over Multiuser Multirelay Networks. IEEE Transactions on Vehicular Technology 65, 10 (Oct 2016), 8112–8129. https://doi.org/10.1109/TVT.2015.2506981 — doi:10.1109/tvt.2015.2506981 OpenAlex ↗ · Scholar ↗
- T.C. Hu and M.T. Shing. 1982. Computation of Matrix Chain Products. Part I. SIAM J. Comput. 11, 2 (1982), 362–373. OpenAlex ↗ · Scholar ↗
- T.C. Hu and M.T. Shing. 1984. Computation of Matrix Chain Products. Part II. SIAM J. Comput. 13, 2 (1984), 228–251. OpenAlex ↗ · Scholar ↗
- Klaus Iglberger, Georg Hager, Jan Treibig, and Ulrich Rüde. 2012. Expression Templates Revisited: A Performance Analysis of the Current ET Methodologies. SIAM Journal on Scientific Computing 34, 2 (2012), C42–C69. OpenAlex ↗ · Scholar ↗
- Manuel Krebber. 2017. Non-linear Associative-Commutative Many-to-One Pattern Matching with Sequence Variables. CoRR abs/1705.00907 (2017). http://arxiv.org/abs/1705.00907 — arXiv:1705.00907 OpenAlex ↗ · Scholar ↗
- Chuck L. Lawson, Richard J. Hanson, David R. Kincaid, and Fred T. Krogh. 1979. Basic Linear Algebra Subprograms for FORTRAN Usage. ACM Transactions on Mathematical Software (TOMS) 5, 3 (1979), 308– 323. OpenAlex ↗ · Scholar ↗
- Heejo Lee, Jong Kim, Sung Je Hong, and Sunggu Lee. 2003. Processor Allocation and Task Scheduling of Matrix Chain Products on Parallel Systems. Parallel and Distributed Systems, IEEE Transactions on 14, 4 (2003), 394–407. OpenAlex ↗ · Scholar ↗
- Noël M Nachtigal, Satish C Reddy, and Lloyd N Trefethen. 1992. How Fast are Nonsymmetric Matrix Iterations? SIAM J. Matrix Anal. Appl. 13, 3 (1992), 778–795. OpenAlex ↗ · Scholar ↗
- Nadia Nedjah, Colin Walter, and Stephen Eldridge. 1997. Optimal Left-to-Right Pattern-Matching Automata. In Algebraic and Logic Programming. Springer, 273–286. OpenAlex ↗ · Scholar ↗
- Elias D. Niño, Adrian Sandu, and Xinwei Deng. 2016. A Parallel Implementation of the Ensemble Kalman Filter Based on Modified Cholesky Decomposition. CoRR abs/1606.00807 (2016). http://arxiv.org/abs/1606.00807 — arXiv:1606.00807 OpenAlex ↗ · Scholar ↗
- Kazufumi Nishida, Yasuaki Ito, and Koji Nakano. 2011. Accelerating the Dynamic Programming for the Matrix Chain Product on the GPU. In Networking and Computing (ICNC), 2011 Second International Conference on. IEEE, 320–326. OpenAlex ↗ · Scholar ↗
- Silvia Noschese and Lothar Reichel. 2016. Some Matrix Nearness Problems Suggested by Tikhonov Regularization. Linear Algebra Appl. 502 (2016), 366–386. OpenAlex ↗ · Scholar ↗
- Devangi N Parikh, Maggie E Myers, and Robert A van de Geijn. 2017. Deriving Correct High-Performance Algorithms. arXiv preprint arXiv:1710.04286 (2017). arXiv:1710.04286 — arXiv:1710.04286 OpenAlex ↗ · Scholar ↗
- Elmar Peise and Paolo Bientinesi. 2012. Performance Modeling for Dense Linear Algebra. In Proceedings of the 2012 SC Companion: High Performance Computing, Networking Storage and Analysis (PMBS12) (SCC ’12). IEEE Computer Society, Washington, DC, USA, 406–416. OpenAlex ↗ · Scholar ↗
- Elmar Peise and Paolo Bientinesi. 2015. A Study on the Influence of Caching: Sequences of Dense Linear Algebra Kernels. In High Performance Computing for Computational Science – VECPAR 2014 (Lecture Notes in Computer Science), Michel Daydé, Osni Marques, and Kengo Nakajima (Eds.), Vol. 8969. Spring… — arXiv:1402.5897 OpenAlex ↗ · Scholar ↗
- Elmar Peise and Paolo Bientinesi. 2015. The ELAPS Framework: Experimental Linear Algebra Performance Studies. CoRR abs/1504.08035 (2015). http://arxiv.org/abs/1504.08035 — arXiv:1504.08035 OpenAlex ↗ · Scholar ↗
- Prakash Ramanan. 1996. An Efficient Parallel Algorithm for the Matrix-Chain-Product Problem. SIAM J. Comput. 25, 4 (1996), 874– 893. OpenAlex ↗ · Scholar ↗
- V. Rao, A. Sandu, M. Ng, and E. Nino-Ruiz. 2015. Robust Data Assimilation Using L 1 and Huber Norms. ArXiv e-prints (Nov. 2015). arXiv:math.NA/1511.01593 OpenAlex ↗ · Scholar ↗
- Vishwas Rao, Adrian Sandu, Michael Ng, and Elias D. Nino-Ruiz. 2017. Robust Data Assimilation Using L 1 and Huber Norms. SIAM Journal on Scientific Computing 39, 3 (2017), B548–B570. https://doi.org/10.1137/15M1045910 — doi:10.1137/15m1045910 OpenAlex ↗ · Scholar ↗
- Henrik Ronellenfitsch, Marc Timme, and Dirk Witthaut. 2015. A Dual Method for Computing Power Transfer Distribution Factors. CoRR abs/1510.04645 (2015). http://arxiv.org/abs/1510.04645 — arXiv:1510.04645 OpenAlex ↗ · Scholar ↗
- Conrad Sanderson. 2010. Armadillo: An Open Source C++ Linear Algebra Library for Fast Prototyping and Computationally Intensive Experiments. (2010). OpenAlex ↗ · Scholar ↗
- Jeremy G. Siek, Ian Karlin, and Elizabeth R. Jessup. 2008. Build to Order Linear Algebra Kernels. In Parallel and Distributed Processing, 2008. IPDPS 2008. IEEE International Symposium on. IEEE, 1–8. OpenAlex ↗ · Scholar ↗
- Daniele G. Spampinato and Markus Püschel. 2014. A Basic Linear Algebra Compiler. In Proceedings of Annual IEEE/ACM International Symposium on Code Generation and Optimization. ACM, 23. OpenAlex ↗ · Scholar ↗
- Daniele G Spampinato and Markus Püschel. 2016. A Basic Linear Algebra Compiler for Structured Matrices. In International Symposium on Code Generation and Optimization (CGO). 117–127. OpenAlex ↗ · Scholar ↗
- Damian Straszak and Nisheeth K Vishnoi. 2015. On a Natural Dynamics for Linear Programming. (2015). arXiv:1511.07020 — arXiv:1511.07020 OpenAlex ↗ · Scholar ↗
- Steve Strate, Roger L. Wainwright, et al. 1990. Parallelization of the Dynamic Programming Algorithm for the Matrix Chain Product on a Hypercube. In Applied Computing, 1990., Proceedings of the 1990 Symposium on. IEEE, 78–84. OpenAlex ↗ · Scholar ↗
- Todd L. Veldhuizen. 1998. Arrays in Blitz++. In International Symposium on Computing in Object-Oriented Parallel Environments. Springer, 223–230. OpenAlex ↗ · Scholar ↗
This page in Markdown https://md.research.elamur.ai/free/en/papers/barthels-2018-generalized-matrix-chain-algorithm/