Calculation of integrals and summation with an error "The following error occurred converting from gpuArray to double: Conversion to double from gpuArray is not possible"

1 Ansicht (letzte 30 Tage)
Hello. I try to reduce the time for the performance of the following code using Parallel Computing Toolbox
function z=test_GPU
tic
tt=-0.000689609;t=0.242731; muu=0.365908;
f_f=gpuArray.linspace(0,100,101); f_b=gpuArray.linspace(-3000,3000,6001);
[m,NN]=meshgrid(f_f,f_b);
y1= @(N,q,k) t*q./k.*log((-k.^2+2*k.*q-q.^2+muu+1i*(2*pi*N.*t-(2*m(1,:)+1)*pi*t))./(-k.^2-2*k.*q-...
q.^2+muu+1i*(2*pi*N.*t-(2*m(1,:)+1)*pi*t)))./(tt*pi+integral(@(a)a.*tanh((a.^2-muu)./(2*t)).*log((2*a.^2+2*a.*q+...
q.^2-2*muu-1i*2*pi*N*t)./(2*a.^2-2*a.*q+q.^2-2*muu-1i*2*pi*N*t))./q-2,0,10000,'AbsTol',1e-5,'RelTol',1e-3,'ArrayValued',true));
R1=@(q,k) integral(@(N)y1(N,q,k),3000,10^6,'AbsTol',1e-5,'RelTol',1e-3,'ArrayValued',true);
R11=@(q,k) integral(@(N)y1(N,q,k),-10^6,-3000,'AbsTol',1e-5,'RelTol',1e-3,'ArrayValued',true);
y2=@(q,k) t*q./k.*log((-k.^2+2*k.*q-q.^2+muu+1i*(2*pi*NN(:,1).*t-(2*m(1,:)+1)*pi*t))./(-k.^2-2*k.*q-...
q.^2+muu+1i*(2*pi*NN(:,1).*t-(2*m(1,:)+1)*pi*t)))./(tt*pi+integral(@(a)a.*tanh((a.^2-muu)./(2*t)).*log((2*a.^2+2*a.*q+...
q.^2-2*muu-1i*2*pi*NN(:,1).*t)./(2*a.^2-2*a.*q+q.^2-2*muu-1i*2*pi*NN(:,1).*t))./q-2,0,10000,'AbsTol',1e-5,'RelTol',1e-3,'ArrayValued',true));
R2=@(q,k) sum(y2(q,k));
S=@(q,k) R1(q,k)+R11(q,k)+R2(q,k)-4*sqrt(2)/pi*(1/1000)/(pi^(3/2)*sqrt(t))*q.^2;
Sigma=@(k) integral(@(q)S(q,k),0.001,7,'AbsTol',1e-5,'RelTol',1e-3,'ArrayValued',true);
A=Sigma(1);
A=gather(A);
plot(m(1,:),real(A),m(1,:),imag(A))
grid on
toc
end
Without GPU on my computer I have around 1 minute calculation time. But with GPU unfortunately I got an error ""The following error occurred converting from gpuArray to double: Conversion to double from gpuArray is not possible". What is the problem here? Thank you in a advance for any comments.
  2 Kommentare
Yuriy Yerin
Yuriy Yerin am 24 Okt. 2018
The following error occurred converting from gpuArray to double:
Conversion to double from gpuArray is not possible.
Error in integralCalc/iterateArrayValued (line 184)
qsubs(:,1) = qsubsk(:);
Error in integralCalc/vadapt (line 130)
[q,errbnd] = iterateArrayValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in test_GPU>@(q,k)integral(@(N)y1(N,q,k),3000,10^6,'AbsTol',1e-5,'RelTol',1e-3,'ArrayValued',true)
(line 24)
R1=@(q,k) integral(@(N)y1(N,q,k),3000,10^6,'AbsTol',1e-5,'RelTol',1e-3,'ArrayValued',true);
Error in test_GPU>@(q,k)R1(q,k)+R11(q,k)+R2(q,k)-4*sqrt(2)/pi*(1/1000)/(pi^(3/2)*sqrt(t))*q.^2 (line 32)
S=@(q,k) R1(q,k)+R11(q,k)+R2(q,k)-4*sqrt(2)/pi*(1/1000)/(pi^(3/2)*sqrt(t))*q.^2;
Error in test_GPU>@(q)S(q,k) (line 40)
Sigma=@(k) integral(@(q)S(q,k),0.001,7,'AbsTol',1e-5,'RelTol',1e-3,'ArrayValued',true);
Error in integralCalc/iterateArrayValued (line 156)
fxj = FUN(t(1)).*w(1);
Error in integralCalc/vadapt (line 130)
[q,errbnd] = iterateArrayValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in test_GPU>@(k)integral(@(q)S(q,k),0.001,7,'AbsTol',1e-5,'RelTol',1e-3,'ArrayValued',true) (line
40)
Sigma=@(k) integral(@(q)S(q,k),0.001,7,'AbsTol',1e-5,'RelTol',1e-3,'ArrayValued',true);
Error in test_GPU (line 42)
A=Sigma(1);

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Joss Knight
Joss Knight am 28 Okt. 2018
On the face of it this code is not very advisable to run on the GPU, since I don't think it is well vectorized. Still, for a pointer, this error comes when you try to assign a gpuArray into elements of a non-CPU array.
A(indices) = gpuArray(b);
So you could try checking that everything you're passing to integral is a gpuArray.
However, it's just as likely that the assignment is something integral is doing internally because it doesn't natively support gpuArray data.
  1 Kommentar
Yuriy Yerin
Yuriy Yerin am 29 Okt. 2018
Thank you for the response. It was just attempt to improve the performance of my code. So that's why I tried to find the answer. Thanks again

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by