On a vectorized basic linear algebra package for prototyping codes in MATLAB

Alexej Moskovka,Talal Rahman,Jan Valdman,Jon Eivind Vatne
2024-03-16
Abstract:When writing high-performance code for numerical computation in a scripting language like MATLAB, it is crucial to have the operations in a large for-loop vectorized. If not, the code becomes too slow to use, even for a moderately large problem. However, in the process of vectorizing, the code often loses its original structure and becomes less readable. This is particularly true in the case of a finite element implementation, even though finite element methods are inherently structured. A basic remedy to this is the separation of the vectorization part from the mathematics part of the code, which is easily achieved through building the code on top of the basic linear algebra subprograms that are already vectorized codes, an idea that has been used in a series of papers over the last fifteen years, developing codes that are fast and still structured and readable. We discuss the vectorized basic linear algebra package and introduce a formalism using multi-linear algebra to explain and define formally the functions in the package, as well as MATLAB pagetime functions. We provide examples from computations of varying complexity, including the computation of normal vectors, volumes, and finite element methods. Benchmarking shows that we also get fast computations. Using the library, we can write codes that closely follow our mathematical thinking, making writing, following, reusing, and extending the code easier.
Mathematical Software
What problem does this paper attempt to address?
The problem that this paper attempts to solve is how to achieve efficient vectorization operations while maintaining code structure and readability when writing high - performance numerical computing code in MATLAB. Specifically, the paper focuses on: 1. **Improving computational efficiency**: When using scripting languages such as MATLAB for numerical computing, if vectorization operations are not implemented within large loops, the code can become very slow and even useless for medium - sized problems. Therefore, the paper aims to accelerate the computation by vectorizing the basic linear algebra package. 2. **Maintaining code structure and readability**: During the vectorization process, the code often loses its original structure and becomes difficult to read, especially in finite - element implementations. The paper proposes a method that separates the vectorized part from the mathematical part, making the code both efficient and easy to understand, modify, and extend. To achieve the above - mentioned goals, the paper introduces a formal method based on multilinear algebra to interpret and define functions in the vectorized basic linear algebra package and provides several computational examples with different levels of complexity, including normal vector, volume calculation, and applications of the finite - element method. In addition, benchmark tests show that using this library can significantly improve the computational speed. ### Main problem summary - **Problem background**: The for - loop in MATLAB can lead to performance bottlenecks, especially when dealing with large - scale finite - element problems. - **Solution**: By introducing a vectorized basic linear algebra package, separate the vectorization operation from the mathematical logic, thereby improving the execution efficiency and readability of the code. - **Specific applications**: The paper shows how to use this library to write more efficient and structured code, especially suitable for various element types in geometric computing and the finite - element method. ### Formula representation During the discussion, the formulas involved are represented in Markdown format as follows: - **Homomorphic space and tensor product**: \[ \text{Hom}(U, V)=\{\text{linear transformation } U \to V\} \] \[ U\otimes V =\{\text{linear combination of } u\otimes v\}/\text{bilinear relation} \] - **Page - level matrix multiplication**: \[ A\otimes B\to \text{Hom}(U, X)\otimes W_1\otimes W_2 \] When \(W = W_1 = W_2\): \[ \text{Hom}(V, U)\otimes W\otimes \text{Hom}(U, X)\otimes W\to \text{Hom}(V, X)\otimes W \] These formulas help readers understand the mathematical principles behind vectorization operations and ensure the correctness and readability of the formulas.