How can I accelerate this function with GPU arrayfun

Hi,
I want to accelerate a function like below with GPU. The real code is too complex so I put a simplified version here.
The main problem of this code is at the 5th line of nestedFcn: Indexing is not supported.
And the 1st line of nestedFcn : The size and shape for all variables must be the same. Variable 'test2' differs from 'test'.
Is there any way to do that?
% code
function gtest
Np=10;
test = zeros(Np);
test(1,1)=1;
E = rand(1,Np);
gpuVector = gpuArray.colon(1, Np);
function out = nestedFcn(k)
test2 = test*acos(E(k));
temp = rdivide(1,(rand()-test2));
% need a diag function below
for i_d=1:Np
out(i_d,1) = temp(i_d,i_d);
end
end
% Call arrayfun.
arrayfun(@nestedFcn, gpuVector)
end

Answers (0)

Products

Asked:

on 8 Aug 2018

Commented:

on 28 Dec 2022

Community Treasure Hunt

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

Start Hunting!