How do the algorithms for calculating matlab matrices work?

How do matlab calculations work? In particular, how does it work with matrices? Can anyone explain, or give links to the relevant literature?

The background is that I created a class in c++ to work with matrices. But when I set up a test for the speed of multiplying matrices in matlab and matrices of my class, it turned out that matlab copes with calculations almost 200 times faster.

About your class. The template class contains data about the size of the matrix and a pointer to a one-dimensional array that stores consecutive rows of the matrix, since I assumed that with a one-dimensional array, calculations would go faster. I also accessed array elements by calculating their address manually, as it turned out that sometimes this worked much faster than accessing an array element through an index. But that wasn't enough. The time for matrix multiplication in matlab also has a cubic dependence on the size of the matrices. There were suggestions that the calculations are done via a video card, or there is some very fast matrix multiplication algorithm, or perhaps my class is not optimized that much. Matlab also performs all other operations with matrices much faster.

1 answers

The speed of matrix calculations strongly depends on how the data is located in memory, whether SIMD instructions are used, and the spin of loops. This depends on the compiler used and its settings. Lay out your code, we'll stroke it.

Currently, writing your own linear algebra is relevant only for educational purposes, and it is far from a fact that you will overtake ATLAS, MKL or other libraries - the methods of fitting the code to the processor there are very cruel, and if you do not know the features a specific chip-figs you catch up with the luminaries.

Uploading the calculations to the video card increases the calculation speed by orders of magnitude, and complicates the development by the same orders of magnitude.

Well, about algorithms-for sure, large matlab matrices click on the Strassen algorithm, because there is no point in doing it head-on.

 1
Author: gbg, 2019-09-22 08:30:29