Do I need to initiate the parallel computing toolbox for my code to run on multiple cores?

2 views (last 30 days)
I have a function that I minimize using fmincon. I am exploring the possibility of making my code run faster. I got rid of all for loops and replaced them with vectorised code. I further wanted to try the parallel computing toolbox. Yet before doing so, I checked how many cores MATLAB is using because if it is using already multiple cores, why would I need the parallel computing toolbox? Though I am not sure and this is a first question I would like to ask. I noticed that MATLAB actually does use all the cores when I inititate fmincon. How is it possible that multiple cores are used while I did not initiate the parallel comuting toolbox?

Accepted Answer

Bruno Luong
Bruno Luong on 21 Mar 2022
Edited: Bruno Luong on 21 Mar 2022
MATLAB has many low level functions are multi-thread coded and potentially use all the CPU core.
In this case parallel tbx will not bring you any speed up on the same computer. You can however use GPU, that can speed up in some specific cases.
  4 Comments
Walter Roberson
Walter Roberson on 21 Mar 2022
Edited: Walter Roberson on 21 Mar 2022
Most of fmincon does not use multi-threaded core. However:
  • when executing the objective function, any mathematical calculations there are potentially executed in multi-threaded code.
  • However, automatic multi-threading is only done if MATLAB estimates that it would save time to do that, so it tends to restrict it to "expensive" calculations that can be carried out in parallel, or to operations that work on large arrays. For example adding two arrays can potentially be done with multiple threads -- for example each column could potentially be done independently.... but for small arrays it is faster to do them in a single thread.
  • iterative work can only be effectively run in parallel if it is working on sufficiently large arrays; for the most part, the automatic multi-core algorithms cannot make decisions in parallel.
  • There is a UseParallel option, when enables using the Parallel Computing Toolbox to estimate gradients in parallel.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics 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!