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.
翻译:在使用像MATLAB这样的脚本语言编写数值计算高性能代码时,将大型for循环中的操作进行向量化至关重要。否则,即使是中等规模的问题,代码也会因过于缓慢而无法使用。然而,在向量化过程中,代码往往失去其原有结构,可读性降低。这在有限元实现中尤为明显,尽管有限元方法本身具有良好的结构性。一个基本的解决方法是,将代码的向量化部分与数学部分分离,这可以通过将代码构建在已向量化的基础线性代数子程序之上轻松实现——这一思想在过去十五年的系列论文中被采用,开发出既快速又保持结构化和可读性的代码。本文讨论了向量化基础线性代数包,并引入基于多重线性代数的形式化方法,对该包中的函数以及MATLAB的分页运算函数进行解释和严格定义。我们提供了不同复杂度计算的示例,包括法向量、体积的计算以及有限元方法。基准测试表明,我们同样实现了快速计算。使用该库,我们可以编写紧密遵循数学思维的代码,从而更易于编写、理解、复用和扩展代码。