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

2 次查看(过去 30 天)
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?

采纳的回答

Bruno Luong
Bruno Luong 2022-3-21
编辑:Bruno Luong 2022-3-21
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 个评论
Walter Roberson
Walter Roberson 2022-3-21
编辑:Walter Roberson 2022-3-21
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by