Error when using sptensor in parfor

2 visualizaciones (últimos 30 días)
Ezra Altabet
Ezra Altabet el 5 de Ag. de 2022
Comentada: Matt J el 9 de Ag. de 2022
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 comentario
Matt J
Matt J el 5 de Ag. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 5 de Ag. de 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 comentarios
Ezra Altabet
Ezra Altabet el 9 de Ag. de 2022
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 el 9 de Ag. de 2022
I don't follow.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by