Why does MATLAB use only single core when function lu is used?

9 views (last 30 days)
Hi,
I try to LU factorize a matrix with multi-cores (4 cores). I assume that MATLAB automatically figures out available multicores and runs LU function with the multi-cores. However, when I see Task Manager of Windows, MATLAB does not use all available multicores. On the MATLAB command line, MATLAB identifies the correct number of cores, but LU does not seem to fully utilize them. Can you suggest how to fully use the resource with function LU? Thanks!
Evan

Answers (1)

John D'Errico
John D'Errico on 1 Sep 2016
Edited: John D'Errico on 1 Sep 2016
In general, MATLAB tries to use multiple cores only when there will be a gain from doing so. Since there is overhead in trying to split up a problem across cores, only large problems will see any gain. So typical linear algebra problems need to be large before multiple cores are used, as most problems finish within small fractions of a second anyway.
At times, I have managed to get all the cores running on my machine. But it can take a seriously large problem.
  2 Comments
evan um
evan um on 1 Sep 2016
Edited: Walter Roberson on 1 Sep 2016
Thanks for your kind answer. My test matrix is big. It is about 500K-by-500K sparse matrix. I tested the matrix with MATLAB version 2011 and 2013. Do you use a newer version? I simply use
[L U]=lu(test_matrix(ordering_vector, ordering_vector)
Is there any option/switch to trigger multi-core computation? Once again, thanks for your kind comment.
John D'Errico
John D'Errico on 1 Sep 2016
Edited: John D'Errico on 1 Sep 2016
There is no flag to set to force the basic LU to use multiple cores. It may be that the sparse version of LU will never go multi-threaded, since sparse matrices would seem to be not so easily parallelized. This is a large enough problem that if it WERE possible, then I expect you would see it happening there.
These things do change with MATLAB version, so newer releases have become more capable and more capable in this respect.
I just ran a quick test on my system (R2016a on a Mac with 4 cores), and I was unable to get it to go past 1 core on a smaller problem, although I did choose problems that took several minutes to solve. While yours is considerably larger, I would have expected to see something if this were possible.
Then I ran a second series of tests with full matrices of various sizes. Even for relatively small problems that took less 5 seconds to solve, this very quickly gobbled up all of the cores on my CPU.
So sparsity did prevent MATLAB from grabbing multiple cores. It is clearly much easier to farm out the job on full matrices.

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!