Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
Chih
Chih am 13 Okt. 2013
Bearbeitet: Matt J am 13 Okt. 2013
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.

Antworten (1)

Matt J
Matt J am 13 Okt. 2013
Bearbeitet: Matt J am 13 Okt. 2013
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,

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by