I am doing some heavy computational work using arrayfun with GPU in MATLAB.
My code looks like this
N = 2000;
dp = 0.005;
p1 = [0:dp:1];
p2 = [0:dp:1];
pB = [0:dp:2];
[p1,p2,pB] = meshgrid(p1,p2,pB);
p1 = gpuArray(p1);
p2 = gpuArray(p2);
pB = gpuArray(pB);
A = zeros(N,1);
parfor i = 1:N
A(i) = arrayfun(@MYFUN,p1,p2,pB);
end
First, I am surprised that for N=2000, the parfor almost takes the same time as the ordinary for loop (when using parfor, it seems that my MATLAB connects to 6 workers). Is that because my laptop only has 1 GPU, so parfor isn't helping?