Does matlab support parallelized loops on GPU
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
THwang
am 14 Mär. 2018
Beantwortet: Joss Knight
am 14 Mär. 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 Kommentare
Akzeptierte Antwort
Joss Knight
am 14 Mär. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear Algebra finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!