1
这里是一个玩具的例子,我把使用CPU加速执行的parfoor函数放在一起。即使在审查了Parallel文档之后,我仍然很困惑如何将它升级到我的GPU上运行(Nvidia 980ti)。使用并行工具箱的GPU上的简单蒙特卡洛
希望有关如何更新此代码在GPU上运行的任何指针。
干杯。
% toy example--monte carlo estimation of pi using for loops
tic;
N = 1000000000;
hitcounter = 0;
for i = 1:N
x = rand;
y = rand;
if (y < sqrt(1-x*x))
hitcounter = hitcounter + 1;
end
end
disp(hitcounter/N*4)
toc;
% toy example--monte carlo estimation of pi using parfor loops
tic;
N = 1000000000;
hitcounter = 0;
parfor i = 1:N
x = rand;
y = rand;
if (y < sqrt(1-x*x))
hitcounter = hitcounter + 1;
end
end
disp(hitcounter/N*4)
toc;