フィルターのクリア

Parfor on increasing array

12 ビュー (過去 30 日間)
DIMITRY
DIMITRY 2015 年 10 月 28 日
回答済み: Edric Ellis 2015 年 10 月 29 日
Hi World,
I would like to know how to reduce a computing time from hours...and hours to less time... In fact I have an increasing array define like X =[]; that is increasing at each iteration from a for loop X(end+1,:) = [Z T V];
I would like to know how it would be possible to use a parfor loop on an increasing array as I have an error message using it in a such case. 'THE PARFOR loop cannot run due to the way X is used' !
Regards,
  1 件のコメント
Adam
Adam 2015 年 10 月 28 日
You need to have a fixed sized array to run a parfor loop. If it keeps resizing in the middle of processing the other workers will not be able to function correctly.
Usually a loop that is slow that has a resizing array is slow precisely because of the resizing array. If you can estimate an upper bound on the size the array can reach then predeclare it at that size and trim off the unused part at the end instead.

サインインしてコメントする。

回答 (1 件)

Edric Ellis
Edric Ellis 2015 年 10 月 29 日
parfor does support increasing arrays in this way, even if it is not necessarily desirable. To do that though, you must use [] to concatenate together the pieces. So, for example, you could do something like this:
x = [];
parfor idx = 1:10
x = [x; rand(1, 3)];
end
This is explained in the doc relating to "reductions".
However, if you know in advance how large x needs to be (as in the example above), it's much better to do something more like
x = zeros(10, 3);
parfor idx = 1:10
x(idx, :) = rand(1, 3);
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by