Does matlab support parallelized loops on GPU
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
THwang
le 14 Mar 2018
Réponse apportée : Joss Knight
le 14 Mar 2018
In my project I need to invert millions of matrices (execute something like the following code) many times. These are millions of small tasks, which should be suitable for GPU computing. I searched for a while I only find matlab support arrayfun on gpu. Is there anyway I can implement the following code on GPU (the for loop part)?
A=normrnd(0,1,6);
N=1,000,000;
A=repmat(A,N,1);
inv_A=zeros(N*6,6);
for i=1:N
inv_A((i-1)*6+1:i*6,:)=A((i-1)*6+1:i*6,:)\eye(6);
end
Thank you!
0 commentaires
Réponse acceptée
Joss Knight
le 14 Mar 2018
Scrap A = repmat(A,N,1) and instead repeat along dim 3. Then use pagefun.
A = repmat(A,1,1,N);
inv_A = pagefun(@mldivide, A, eye(6));
Or just use inv.
inv_A = pagefun(@inv, A);
However, you shouldn't ever be computing the inverse of a matrix, you should use mldivide to compute the solution to your linear system accurately for each output.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!