I want to use a for-loop inside parfor, is it possible? If not what is the alternative?
Thanks,

 採用された回答

Edric Ellis
Edric Ellis 2011 年 6 月 17 日

1 投票

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 件のコメント

Mohamed
Mohamed 2011 年 6 月 17 日
Thanks Edric :)
I have another question please, the main purpose of parfor is just time ? or if i have multiple circles with different x,y position and same radius and wanna to draw them and move them SIMULTANEOUSLY ... can parfor help me ??
Thanks,
Walter Roberson
Walter Roberson 2011 年 6 月 17 日
If I remember correctly, the actual plotting all goes through the same thread. I do not know, though, if that extends to updating the properties of existing plot objects: I think for consistency that would have to go through the single thread too.
Benoit
Benoit 2012 年 6 月 29 日
Hello,
I actually have problems with the above code as I get the message that the variable x cannot classified.
??? Error: The variable x in a parfor cannot be classified. See Parallel for Loops in MATLAB, "Overview".
There must be that variable x must be defined somehow. Any help appreciated.
Thanks!
Walter Roberson
Walter Roberson 2012 年 6 月 29 日
In a recent thread we have been discussion whether the workers have access to graphics at all (I don't have the toolbox to check myself.) The evidence is suggestive that the workers do not have graphics access, but I have not happened to read any definite statement of that.
Edric Ellis
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
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 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2011 年 6 月 17 日

編集済み:

2015 年 3 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by