How to use GPU to calculate double integral with multivariable function
古いコメントを表示
Hi,
I am currently trying to use my GPU to accelerate my calculation time but I have not been able to make it work.
My code is :
clc, clear all
tic
% Parameters
B = gpuArray(1);
Z = gpuArray(single(0:1:14)); % The interval should be 0:0.001:14
R = gpuArray(single(-3:1:3)); % The interval should be -3:0.001:3
phi = gpuArray(5);
Fo = gpuArray(1);
H1 = gpuArray(2);
H2 = gpuArray(12);
% Vector R & Z length
R_len = uint8(length(R));
Z_len = uint8(length(Z));
% Initial definition of tetha
tetha = zeros(Z_len,R_len,'gpuArray');
% Calculation of tetha at different values of Z(k) & R(p)
for k = 1:Z_len
for p = 1:R_len
% Double definite integration of function
A = integral2(@(phi_1,Fo_1) (1./(Fo-Fo_1).^(3./2)).*exp(-(R(p).^2+1)./(4*(Fo-Fo_1))).*exp((2.*R(p).*cos(phi-phi_1))./(4*(Fo-Fo_1))).*(exp(-(Z(k)-B.*phi_1./(2*pi)).^2./(4*(Fo-Fo_1)))-exp(-(Z(k)+B*phi_1./(2*pi)).^2./(4*(Fo-Fo_1)))),2*pi*H1/B,2*pi*H2/B,0,Fo-0.02);
% Calculation of tetha with value of A
tetha(k,p) = B./(16.*pi.^(5/2)).*A;
end
end
toc
However, when I run this code I get the error message:
Error using eps
Class must be 'single' or 'double'.
Error in integral2Calc>integral2t (line 58)
EPS100 = 100*eps(outcls);
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in theta_spiral_surface (line 36)
A = integral2(@(phi_1,Fo_1)
(1./(Fo-Fo_1).^(3./2)).*exp(-(R(p).^2+1)./(4*(Fo-Fo_1))).*exp((2.*R(p).*cos(phi-phi_1))./(4*(Fo-Fo_1))).*(exp(-(Z(k)-B.*phi_1./(2*pi)).^2./(4*(Fo-Fo_1)))-exp(-(Z(k)+B*phi_1./(2*pi)).^2./(4*(Fo-Fo_1)))),2*pi*H1/B,2*pi*H2/B,0,Fo-0.02);
>>
My code works when I use normal variables (not gpuArray), but it takes a lot of time when I use a small step for Z & R, hence the need for optimization.
I think this error has something to do with my function handle in the integral2 function because it has more variables than the independant variables @(phi_1,Fo_1). When I test this code with another function such as (note that there are not any other variables than phi_1 & Fo_1): @(phi_1,Fo_1) (phi_1.^2+Fo_1.^2), the code seems to work properly.
Any suggestions on how I could perform the double integral with my multivariable function on my GPU?
Thank you for your help,
Arny
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Parallel Computing Fundamentals についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!