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 Computing Fundamentals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!