Borrar filtros
Borrar filtros

"Index exceeds matrix dimensions" error when using parfor

4 visualizaciones (últimos 30 días)
Siva
Siva el 17 de Jun. de 2015
Comentada: Walter Roberson el 15 de Mzo. de 2016
I am using Matlab R2013a 64-bit. I am getting an "Index exceeds matrix dimensions" error when using parfor. The following is a minimal code that produces this error.
matlabpool open 4
nbig = 200;
nsmall = 100;
x = rand(3,nsmall);
parfor n = 1:nbig
if (n <= nsmall)
a = x(:,n);
else
a = zeros(3,1);
end
end
matlabpool close
I am wondering why this happens. Thanks.

Respuesta aceptada

Edric Ellis
Edric Ellis el 17 de Jun. de 2015
parfor is treating x as a sliced variable because of the form of indexing you're using. Once x is determined to be "sliced", the parfor machinery sends slices of x to the workers without knowledge of what they're going to do. Hence it tries to send slices of x that do not exist, and you get the error.
You could make this loop work by forcing parfor to send the whole value of x to each worker by including an operation inside the loop that is not in the sliced form. Here's one way:
parfor n = 1:nbig
if n <= size(x,1) % unsliced access to "x" forces "x" to be "broadcast"
a = x(:, n);
else
a = zeros(3, 1);
end
end
  2 comentarios
Zhiyuan Yang
Zhiyuan Yang el 14 de Mzo. de 2016
Hi. I got the similar problem. When I run an enumeration combination problem with nchoosek(1:24,n). it works fine. But when I work for nchoosek(1:27,n) n starts from 1 and it terminates at 9 and the program halted. Erroring: Index exceeds matrix dimensions. Do you what is wrong? Thank you very much!
Walter Roberson
Walter Roberson el 15 de Mzo. de 2016
We will need to see your code

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Parallel Server en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by