1
votes

I have this piece of code which I want to run in parallel. One of the arguments passed to the function containing the parfor loop is a function handle which then is executed inside the parfor loop. Like this

[X] = randstep( X,params,roomfun )
  ...
  parfor i=1:N
    while ~ok
      X(:,i) = A*X(:,i);
      if roomfun(X(:,i))
        ok = 1;
      end
    end
  end

However, MATLAB complains about roomfun, saying it is indexed but not sliced. This is of course not the case since it is function which can be executed fine without the other loop iterations.

Is there any way I can tell matlab this is a function or maybe another way I can organize the loops in order to get this running in parallel?

1

1 Answers

1
votes

First of all, this is only a warning, not an error. So the parfor loop should run just fine.

Secondly, the warning about something being indexed but not sliced comes from mlint, which, while pretty good, doesn't understand everything, so if it interprets something wrong, don't sweat it.

Thirdly, in R2012b, I don't even get the warning anymore (mlint has gotten smarter), which further shows that there's nothing to worry about.

Finally, if there really was a slicing problem, it's still not an issue that would prevent the loop from running in parallel - all the warning says is that an array is sent in its entirety to the workers, which can slow down the parfor loop in case the array is large.