Error when using sptensor in parfor

2 ビュー (過去 30 日間)
Ezra Altabet
Ezra Altabet 2022 年 8 月 5 日
コメント済み: Matt J 2022 年 8 月 9 日
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 件のコメント
Matt J
Matt J 2022 年 8 月 5 日
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.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2022 年 8 月 5 日
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 件のコメント
Ezra Altabet
Ezra Altabet 2022 年 8 月 9 日
Thank you. Just out of curiosity, is there a way that I could use just the tabular data format so that I can write to any element in the parfor loop instead of just a slice, or does that violate the limits of parfor? In my specific example, elements that need to be changed only get set to 1, if that simplifies the problem.
Matt J
Matt J 2022 年 8 月 9 日
I don't follow.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by