Effacer les filtres
Effacer les filtres

Speeding up matrix multiplication and inversion

2 vues (au cours des 30 derniers jours)
Oliver Dellar
Oliver Dellar le 21 Jan 2015
Commenté : Joss Knight le 2 Fév 2015
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 commentaires
Alfonso Nieto-Castanon
Alfonso Nieto-Castanon le 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
Joss Knight le 2 Fév 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.

Connectez-vous pour commenter.

Réponses (2)

Thorsten
Thorsten le 21 Jan 2015
Modifié(e) : Thorsten le 21 Jan 2015
If the matrices are sparse, coding them as such using
Msparse = sparse(M);
may help.
  1 commentaire
Oliver Dellar
Oliver Dellar le 21 Jan 2015
Sorry should have mentioned, I've tried that, and typically get a tiny bit of speedup, but nothing at all significant. Thank you though.

Connectez-vous pour commenter.


John D'Errico
John D'Errico le 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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by