필터 지우기
필터 지우기

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 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