0

I'm trying to run the below code but get an error message:

The variable R in a parfor cannot be classified

Any way to solve it?

R=zeros(M,N,Us,Vs,'single');
parfor indM=1:M   
    for indN=1:N
        for indv=1:Vs           
           temp=squeeze(X(indM,indN,:,indv));          
           if(sum(temp(:)~=0))
             R(indM,indN,:,indv)= FractionalFFT_mid0(temp,a);    
           end
        end
    end
end
3
  • @PavelOganesyan: I don't see a duplicate to that question as each worker only accesses the (indM,:,:,:) slice. Commented Jan 22, 2015 at 13:39
  • @PavelOganesyan - That is not the right duplicate. The one by Daniel is the correct one, which I have selected to be the final duplicate. Commented Jan 22, 2015 at 15:33
  • @rayryeng: I don't see the other questions as duplicates. Here, we have the very simple case of not slicing along the last dimension, whereas the other dupes were about more complex issues. Consequently, I have reopened the question. Commented Jan 22, 2015 at 15:37

1 Answer 1

1

Older versions of Matlab require that the parfor-sliced index is the last one (newer versions, e.g. 2014b no longer have the requirements).

R=zeros(N,Us,Vs,M,'single');
parfor indM=1:M   
    for indN=1:N
        for indv=1:Vs           
           temp=squeeze(X(indM,indN,:,indv));          
           if(sum(temp(:)~=0))
             R(indN,:,indv,indM)= FractionalFFT_mid0(temp,a);    
           end
        end
    end
end

%# get R back the way you wanted originally
R = permute(R,[4 1 2 3]);
Sign up to request clarification or add additional context in comments.

3 Comments

Hm, I don't think there ever was such a requirement - I just tried R2007b (the first version with parfor in mostly its current form - R2007a and prior releases had a completely different parfor...), and the following: x = zeros(4); parfor (idx = 1:4), x(idx,1) = 7, end worked as I expected. There have definitely been some changes in what's supported in terms of nested FOR loops though.
Having said that, I don't know why re-ordering the subscripts makes that work.
@Edric: The OP's example does work (with some random data) for me in R2014b, but in the past, re-ordering of index variables has helped. I do not remember where I saw it in the documentation, or whether I found it out via trial and error; parfor did use to be a bit iffy at times.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.