How can I convert this loop from a 'for' loop to a 'parfor' loop?
Mostrar comentarios más antiguos
function M=getMatrix(P,T)
n=length(P);
[ne,~]=size(T);
M=sparse(n,n);
for i=1:ne
k=T(i,:);
Me=subMatrix(P(k,:));
M(k,k) = M(k,k) + Me;
end
return
Respuestas (1)
Edric Ellis
el 23 de Feb. de 2015
0 votos
I suspect this is not likely to be possible directly since you are effectively updating arbitrary elements of M on each iteration of the loop. PARFOR loops can only operate when each loop iteration accesses separate elements of the output variables (this is known as "slicing").
You might get some benefit by performing the underlying calculations in a PARFOR loop and then having a separate FOR loop to update M afterwards - providing the calculation inside subMatrix is expensive enough.
Categorías
Más información sobre Parallel for-Loops (parfor) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!