for exemple
clc,clear all
close all
%% CPU
tic
num.n=1*2^18;
num.tspan = 2e-09;
num.dt=num.tspan/(num.n-1);
T = zeros(1, num.n);
for k=1:1:num.n
T(k)=(k-1)*num.dt-num.tspan/2;
end
toc
%% GPU
clear all
close all
tic
num.n=gpuArray(1*2^18);
num.tspan =gpuArray(2e-09);
num.dt=gpuArray(num.tspan/(num.n-1));
T = gpuArray(zeros(1, num.n));
for k=1:1:num.n
T(k)=(k-1)*num.dt-num.tspan/2;
end
toc
the result is
Elapsed time is 0.027964 seconds.
Elapsed time is 47.296786 seconds.