Does matlab support parallelized loops on GPU

1 view (last 30 days)
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!

Accepted Answer

Joss Knight
Joss Knight on 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.

More Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!