Effacer les filtres
Effacer les filtres

"Index exceeds matrix dimensions" error when using parfor

4 vues (au cours des 30 derniers jours)
Siva
Siva le 17 Juin 2015
Commenté : Walter Roberson le 15 Mar 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.

Réponse acceptée

Edric Ellis
Edric Ellis le 17 Juin 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 commentaires
Zhiyuan Yang
Zhiyuan Yang le 14 Mar 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 le 15 Mar 2016
We will need to see your code

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Parallel Server dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by