I am using parfor for the first time. I run a piece of code 'multiple' times and get an output y each time. Finally, I take average of all such y to get the avg_y. So, I decided to use parfor for the 'multiple' times.
My laptop is quad core and my question is that can't I run the parfor more than 4 times? As I want to run the parfor loop code 10 times and then average the y values....

 Akzeptierte Antwort

Matt J
Matt J am 8 Nov. 2021
Bearbeitet: Matt J am 8 Nov. 2021

0 Stimmen

The number of loop iterations isn't limited by the number of cores you have. However, if you have 4 cores, the loop iterations cannot be split into more than 4 parallel groups. So, for example, if you have 40 loop iterations, each core must do 10 of them.

3 Kommentare

Jaya
Jaya am 8 Nov. 2021
That means, I need not do anything and directly do the parfor for 10 iterations and it will take care how to divide the tasks? Then, I (or code) can just average all the 10 outputs at the end normally?
Matt J
Matt J am 8 Nov. 2021
Yes.
Jaya
Jaya am 8 Nov. 2021
Thanks. I did that later. Actually I asked another question related to this but the reverse case. Can you please take a look at that also? Link is https://www.mathworks.com/matlabcentral/answers/1581179-specifying-more-cores-than-needed-for-parfor-any-speedup

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 8 Nov. 2021

Kommentiert:

am 8 Nov. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by