Execute parfor iterations in order!
古いコメントを表示
Hi,
I want to use Matlab parallelization to do this parfor in order like 1, 2, 3, ... , and I have limitted number of workers/cores, say 4.
parfor cnt = 1:20
do_something(cnt)
end
This is important for me to run cnt = 1:4 first, and once one of them finished, I need to start running next one which will be 5. I would appreciate your suggestions.
Thanks!
2 件のコメント
James Tursa
2021 年 11 月 22 日
Why do they need to be run in order? Does the result of the 1:4 iterations serve as inputs to the 5:8 iterations, etc.?
Sina Gharebaghi
2021 年 11 月 22 日
採用された回答
その他の回答 (1 件)
You need not run 4 times first and then start with 5. You can directly do the parfor for 1:20. Assuming yours is a quad core, then each core will take the task of doing 5 iterations. How it splits that is not a thing for us to worry.
I asked this similar question some time ago.Here is the link.
5 件のコメント
Sina Gharebaghi
2021 年 11 月 22 日
By 'run them in order', do you mean all the operations inside the for loop aren't independent?
From my knowledge, if output of one iteration is required for next iteration then I don't think parfor can be used for that. Since, logically, the cores working at the 'same' time cannot get the previous output of another core that performed (say) 1st iteration.
If this isn't the case for you then maybe you can elaborate on that 1-4 thing in your next comment and I or someone else can better answer then.
Sina Gharebaghi
2021 年 11 月 22 日
Jaya
2021 年 11 月 22 日
Then I don't really think or don't know if or how can you still use parfor for this case. Since I understand your situation as something that requires simulation stopping based on some result you get in between the iterations. And as you might know, parfor cannot use a break statement.
Sina Gharebaghi
2021 年 11 月 22 日
カテゴリ
ヘルプ センター および File Exchange で Parallel for-Loops (parfor) についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!