Borrar filtros
Borrar filtros

Parfor on increasing array

12 visualizaciones (últimos 30 días)
DIMITRY
DIMITRY el 28 de Oct. de 2015
Respondida: Edric Ellis el 29 de Oct. de 2015
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 comentario
Adam
Adam el 28 de Oct. de 2015
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.

Iniciar sesión para comentar.

Respuestas (1)

Edric Ellis
Edric Ellis el 29 de Oct. de 2015
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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by