Does matlab support parallelized loops on GPU
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Joss Knight
2018-3-14
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!