for loop in parfor
조회 수: 14 (최근 30일)
이전 댓글 표시
I want to use a for-loop inside parfor, is it possible? If not what is the alternative?
Thanks,
댓글 수: 0
채택된 답변
Edric Ellis
2011년 6월 17일
Yes, it's possible. For example,
parfor ii=1:10
for jj=1:10
x(ii,jj) = rand
end
end
Note that this example is so computationally trivial that it is much slower than a serial version.
댓글 수: 6
Edric Ellis
2012년 7월 2일
@Benoit - which version are you running? The ability to recognise 'x' as a sliced variable was added relatively recently.
@Walter - matlabpool workers (either local workers with PCT or cluster workers with MDCS) have no visible graphics of their own. However, they can generate off-screen graphics and call 'print' to files.
Niels
2015년 3월 6일
편집: Niels
2015년 3월 6일
Hi Edric, I am trying to run a slightly modified script:
a = linspace(0,10);
parfor ii=1:10
for jj=1:length(a)
x(ii,jj) = rand;
end
end
However, Matlab complains about the x variable classification. But I don't quite understand, why it shouldn't work. Any ideas? Thanks in advance, Niels.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!