MATLAB Answers

0

How to make Matlab use all CPU cores?

Asked by Benjamin on 4 Sep 2019
Latest activity Answered by Rik
on 4 Sep 2019
Hello
I have a computer with the configuration of CPU = 2.2 GHz and RAM = 64 GB with 24 cores!
however, since Matlab uses just one core, I have long runtime. I have a "for" loop in my code, but when I use parfor, or parpool my runtime doesn't change or I even get errors. I need to know how can I make my code and Matlab use more cores to accelerate the runs?
Here is the Matlab code

  0 Comments

Sign in to comment.

1 Answer

Answer by Rik
on 4 Sep 2019

The value of n is only 63, so the main constriction in your code is the while loop, which can't be parallelized.
Matlab is fundamentally linear, which can only under some circumstances be mitigated. parfor has an overhead, because it needs to duplicate data in memory for each worker. Fewer iterations means less chance to have your investment work out. Mathworks engineers do spend a lot of time speeding up calculations, which is easier for matrix manipulations.
Your main problem is not with the loop itself, it's with 14000 calls to fsolve (see profiler screenshot below). It is probably more efficient to attempt to change your algorithm instead of trying to make your code run in parallel.
Capture.PNG
You should be aware that 2.2GHz isn't that fast in the context of a single-threaded calculation. Higher end CPUs are currently almost double that. Your computer configuration is optimized for multi-threaded workloads, which Matlab is not.

  0 Comments

Sign in to comment.