% vector algebra on CPU
t = tic();v1 = Vector(X,Y,Z,Vx,Vy,Vz);v11 = Vector(X,-Y,Z,-Vx,Vy,Vz);v111 = v1+v11;v1111 = v1*v11;cpuTime = toc( t )% vector algebra on GPU
t = tic();v2 = Vector(gpuArray(X),gpuArray(Y),gpuArray(Z),gpuArray(Vx),gpuArray(Vy),gpuArray(Vz));v22 = Vector(gpuArray(X),gpuArray(-Y),gpuArray(Z),gpuArray(-Vx),gpuArray(Vy),gpuArray(Vz));v222 = v2+v22;v2222 = v2*v22;v222 = gather( v222 ); % Fetch the data back from the GPU
v2222 = gather( v2222 ); gpuTime = toc( t )
MATLAB: Is it normal that the computation time on GPU for the first time be longer than the running it for more than 2 times? (run the code for first time on GPU and also after reset the device takes more time but after 2 or 3 times it shows the short time
gpu computational time
Best Answer