How can I convert this loop from a 'for' loop to a 'parfor' loop?
Afficher commentaires plus anciens
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
Réponses (1)
Edric Ellis
le 23 Fév 2015
0 votes
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.
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!