Error when using sptensor in parfor
2 views (last 30 days)
Show older comments
I am trying to edit a sparse tensor from the Tensor Toolbox inside a parfor loop. However I am getting the "Unable to classify the variable 'tau' in the body of the parfor-loop. I thought this might be a slicing issue, however when I tried testing using a 3D matrix with smaller dimensions the parfor loop runs. Unfortunately the needed tensor size is too big for me to use a native 3D matrix, and so I am trying to stay with a sparse tensor if possible. Any ideas how I can correct this? A simplified code is provided:
tau = sptensor([],[],[N N M]);
opts = parforOptions(gcp,'RangePartitionMethod','fixed','SubrangeSize',100);
parfor (i = 1:N-1, opts)
mytemp_p_k = sptensor([],[],[N M]);
mytemp_p_k(a,b) = <edit matrix>
tau(i,:,:) = mytemp_p_k;
end
1 Comment
Matt J
on 5 Aug 2022
However I am getting the "Unable to classify the variable 'tau' in the body of the parfor-loop.
Do you mean a Code Analyzer warning? I, for one, get no such warning.
Accepted Answer
Matt J
on 5 Aug 2022
You could try with ndSparse() instead of sptensor()
The following modified code ran fine for me.
[N,M]=deal(100);
tau = ndSparse.spalloc([N N M],N^2*M/100);
opts = parforOptions(gcp,'RangePartitionMethod','fixed','SubrangeSize',100);
parfor (i = 1:N-1, opts)
mytemp_p_k = sprand(N,M,0.01);
tau(i,:,:) = mytemp_p_k;
end
6 Comments
More Answers (0)
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!