Best way to nest parfoor in for loops?

1 Ansicht (letzte 30 Tage)
Tristan
Tristan am 8 Okt. 2014
Bearbeitet: Iain am 8 Okt. 2014
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.

Akzeptierte Antwort

Iain
Iain am 8 Okt. 2014
Bearbeitet: Iain am 8 Okt. 2014
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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by