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"
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
Antworten (1)
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.
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!