Best way to nest parfoor in for loops?

1 vue (au cours des 30 derniers jours)
Tristan
Tristan le 8 Oct 2014
Modifié(e) : Iain le 8 Oct 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.

Réponse acceptée

Iain
Iain le 8 Oct 2014
Modifié(e) : Iain le 8 Oct 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.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by