Parfor fails but for doesn't?

hi all,
If I use the code:
scalar_matrix=sptensor([nPoints-kernel_length nInput_kernels nNodes]);
for j=1:(nPoints-kernel_length),
a=input_kernel_matrix*(output(:,j:kernel_length+j-1).');
if nnz(a)==0
scalar_matrix(j,:,:)=sptensor([nInput_kernels nNodes]);
else
scalar_matrix(j,:,:)=sptensor(a);
end;
if mod(j,10000)==0
display(j);
end;
end;
Then everything works fine. However, if I replace the for with parfor it crashes. The code seems fine for parellization to me. Any idea why? I use the tensor toolbox (external toolbox).

4 Comments

Does "crashes" mean, that MATLAB stops with an error message? Then posting this message would make an answer much easier.
Hi Jan,
Thanks. Yes, it does. Here is the message:
"
??? Error using ==> parallel_function at 598
Error in ==> subsasgn at 86
Attempt to reference field of non-structure array.
Error in ==> build_scalar_matrix_sparse at 7
parfor j=1:(nPoints-kernel_length),
"
Odd odd.
Ummm, try
which -all parfor
just in case you have a parfor.m on your path that isn't the right one.
Also, try removing the comma at the end of the "for" line: it is not needed and might be causing problems perhaps.
Can you post a more complete example of your code? It would be especially helpful if you could post a snipped of code that initializes all the input variables to values representative of your application.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Asked:

Eli
on 15 Oct 2011

Community Treasure Hunt

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

Start Hunting!