How to improve code for gpu?
    1 view (last 30 days)
  
       Show older comments
    
Hello everybody. I am bit struggling with the following function for removing duplicate pairs when there is signal for the pair. I would like to move this function to GPU in order not to use for loop. The code is here:
if true
  % code
end
clear;
tic
p1=[5 4 1 2 1]; idx2=[1 2 4 5];n3=[1 2 3 4 5];
p=gpuArray(p1);
idx=gpuArray(idx2);
n=gpuArray(n3);
[m,n2]=size(p);
t=p(p);
otherIdx=ones(size(idx),'gpuArray');
otherIdx1=otherIdx;
idx1=idx;
c=p(p);
for i=1:n2
        if (c(i)==4)
     k(i)=any(p(i)==idx1);
       k1(i)=any(c(i)==idx1);
       k2(i)=any(otherIdx1((c(i)==idx1)));
      [idxx,otherIdxx]=arrayfun(@testas,k,k1,k2);
        end
            if any(p(i)==idx)
                if any(c(i)==idx)
                    if otherIdx((c(i)==idx))==1
                        idx(c(i)==idx)=NaN; 
                        otherIdx(p(i))=0;          
                  %  end
                end
            end
          end
end
idx
toc
//////////////////////
function [idxx,otherIdxx]=testas(k,k1,k2)
if k==1   
  if k1==1
     if k2==1
     idxx=NaN; 
     otherIdxx=0;          
     end
  end
end
end
Is arrayfun suitable for this case?
Answers (0)
See Also
Categories
				Find more on GPU Computing 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!