Speeding up matrix multiplication and inversion
4 次查看(过去 30 天)
显示 更早的评论
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
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
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 个)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!