필터 지우기
필터 지우기

How to optimize code for GPU and remove for loops?

조회 수: 4 (최근 30일)
Mantas Vaitonis
Mantas Vaitonis 2018년 6월 23일
댓글: Mantas Vaitonis 2018년 7월 5일
Hello, I am trying to optimize this code for GPU in order to speed up calculations. Here is small data sample, but mine data is quite big (1000000x100) and there can be a number of this size arrays. I was trying to use arrayfun but due to indexing it was not an option. 3D arrays were used as well with no luck to achieve my goal. The idea of code is to eliminate pair duplicates. Here is sample for, which due to for loops and other is very slow for big data:
x1=[2 1 4 5 3;5 2 3 3 4;5 4 1 1 2;3 5 1 4 2;3 3 2 1 2];
idx1=[1 1 0 0 1;1 1 1 0 0;1 1 0 1 1;1 0 1 1 1;1 1 1 1 1];
idx=gpuArray(idx1);
x=gpuArray(x1);
[n1 n2]=size(x);
for i=1:n1
c(i,:)=x(i,x(i,:));
end
for j=1:n1
idx2(j)={find(idx(j,:)>0)};
tempIdx=ones(size(idx(j,:)));
idx3(j)={find(idx(j,:)>0)};
for i=1:n2
if(i==c(j,i))
if any(c(j,i)==idx2{j})
if tempIdx(c(j,i)==idx2{j})==1
idx2{j}(c(j,i)==idx2{j})=NaN;
tempIdx(x(j,i))=0;
end
end
end
end
end
Array x represents pairs and array idx represents the invoking of pair.
  댓글 수: 3
umichguy84
umichguy84 2018년 7월 5일
Can you explain in words what your trying to achieve. I'm not sure what you mean by pair duplicates.
Mantas Vaitonis
Mantas Vaitonis 2018년 7월 5일
Hello, It is no longer necessary, did find a solution.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by