Low performance on Matrix operations when using parallel computing tools

1 view (last 30 days)
Normal operations in Matlab are well optimized. For example, if I ran,
A = rand(500,500);
b = rand(500,1);
for i = 1 : 1000000
A * b;
It ran fast and consumed all computing resources available. ( It finished in about 30s)
However, if I explicitly created parallel workers by,
And re-ran above codes, all the artificial created workers were idle. Meanwhile, it seemed Matlab only ran the program on the master thread, which resulted in much slower performance than that of not using parpool. (it finished in about 3000s, about 100x slower) Further, if I shutdown the parallel pool through down left button (or delete(gcp)) and ran the above code again, sometimes Matlab execute this fast, sometimes not. A restart always fixed the problem.
Is that normal? It seemed Matlab will not automatically parallel its optimized builtin functions when explicitly using parallel toolbox.
Occasionally, I would receive the following information, after turning off parallel workers,
MATLAB detected: 24 physical cores.
MATLAB detected: 48 logical cores.
MATLAB was assigned: 4 logical cores by the OS.
MATLAB is using: 4 logical cores.
MATLAB is not using all logical cores because hyper-threading is enabled.
MATLAB is not using all logical cores because Operating System restricted the number of cores to: 4.
What can I do if I want to program using parfor as well as taking advantage of high efficient optimized builtin functions?
  1 Comment
Adam on 27 Mar 2018
Threads can't subdivide so if you are using parallel threads in an outer loop then each only has 1 core available to it, in general so will not be optimal in itself. Parallelisation is not an exact science - you have to try out often many combinations or ways of calculating results to find the optimal performance, but usually allowing Matlab's optimised functions to work at their best, without subduing them to a single core each, would tend to be better.

Sign in to comment.

Answers (0)


Find more on Parallel Computing Fundamentals 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!