필터 지우기
필터 지우기

Best way to nest parfoor in for loops?

조회 수: 2 (최근 30일)
Tristan
Tristan 2014년 10월 8일
편집: Iain 2014년 10월 8일
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