필터 지우기
필터 지우기

Speeding up matrix multiplication and inversion

조회 수: 2 (최근 30일)
Oliver Dellar
Oliver Dellar 2015년 1월 21일
댓글: Joss Knight 2015년 2월 2일
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
Alfonso Nieto-Castanon
Alfonso Nieto-Castanon 2015년 1월 21일
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 2015년 2월 2일
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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Thorsten
Thorsten 2015년 1월 21일
편집: Thorsten 2015년 1월 21일
If the matrices are sparse, coding them as such using
Msparse = sparse(M);
may help.
  댓글 수: 1
Oliver Dellar
Oliver Dellar 2015년 1월 21일
Sorry should have mentioned, I've tried that, and typically get a tiny bit of speedup, but nothing at all significant. Thank you though.

댓글을 달려면 로그인하십시오.


John D'Errico
John D'Errico 2015년 1월 21일
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.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by