Speeding up matrix multiplication and inversion
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a script which runs a loop, within which several matrix multiplications and inversions are computed (different matrices each iteration of the loop, sometimes different sizes). Each consecutive iteration relies on previous iterations, so parfor is not an option.
I've profiled my code and the slowest part (typically taking around 80% of the complete wall clock time) are those matrix multiplications and inversions, so I'd really like to speed that up if possible, but I'm aware Matlab operation on matrices/vectors are already very well optimised.
Is there any way at all to speed this up? Could MEX help at all? Could using a GPU and gpuArray help at all? (although this is a last resort).
Thanks a lot in advance, Olie
2 Kommentare
Alfonso Nieto-Castanon
am 21 Jan. 2015
Everything else been exhausted reworking the math is the most likely path to speed-ups in your code. Could you share some code showing the specific matrix operations that you are computing to see if something comes to mind?
Joss Knight
am 2 Feb. 2015
Post some example MATLAB code, and I'll tell you what advantage you might get out of running on a GPU. For a large matrix multiplication or inversion you could well get a significant speedup.
Antworten (2)
John D'Errico
am 21 Jan. 2015
So you can't parallelize the computations. Large enough problems will already be multi-threaded when there is a gain anyway, but they need to be pretty large before that starts happening.
The best way to speed things up is to bump up your CPU speed. Replacing hard disks with solid state memory drives can also help some. GPU might be a gain, though I know nothing there.
Frequently, you can improve your code, even when you think you have wrung all you can from it. You might be surprised. Perhaps you can write it in a completely different way. For example, if you need to solve multiple problems with different size matrices, things can be done with block diagonal matrices.
As for Mex, unless you can write better code than those who provided optimized code based on the BLAS, I doubt you would gain much.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!