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!