필터 지우기
필터 지우기

How can i preallocate memory for sliced output variables in parfor loop?

조회 수: 4 (최근 30일)
Chih
Chih 2013년 10월 13일
편집: Matt J 2013년 10월 13일
How can i preallocate memory for sliced output variables in a parfor loop? Following is the example mentioned in Matlab Parallel Computing toolbox. The array "b" in the example is the sliced output variable. But, there is no preallocation of memory for "b". Isn't that going to affect the performance of Matlab in parfor loop?
a = 0;
z = 0;
r = rand(1,10);
parfor ii = 1:10
a = ii;
z = z + ii;
b(ii) = r(ii);
end
Thanks.

답변 (1개)

Matt J
Matt J 2013년 10월 13일
편집: Matt J 2013년 10월 13일
Why not just pre-allocate b prior to the parfor loop?
a = 0;
z = 0;
r = rand(1,10);
b=zeros(size(r));
parfor ii = 1:10
....
end,

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by