Best way to nest parfoor in for loops?

2 次查看(过去 30 天)
I'm running some code that requires time-consuming function evaluation within 4-5 nested loops. I want to make one of the loops into a parfor loop to improve speed.
What criteria should I be considering when deciding which of the for loops to replace with parfor? Does it matter? I've read that because parfor requires some overhead, it should be the outer-most loop, but does this make a big difference? What else should I consider?
Thanks in advance.

采纳的回答

Iain
Iain 2014-10-8
编辑:Iain 2014-10-8
There are a few things to consider -
1. Is each loop iteration entirely independent of the prior ones? - If not, you can't turn it into a parfor unless you do really fancy stuff.
2. Is there a better optimisation? - For example, don't recalculate stuff if you already have the answer.
3. How long does each loop take? If you do a loop twice, and the first time it's slow, but the second etc. are faster, then theres not necessarily much to be gained making it parallel.
4. What is the cause of the time taken? If it's disk accesses, then you'll probably struggle to make any gains unless the disk accesses are in the parfor.
5. How do the loops interact? - This might make it hard to put some loops in the parfor.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by