フィルターのクリア

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

5 ビュー (過去 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.
Snoopy
Snoopy 2022 年 3 月 23 日
Thanks a lot for all the answers.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by