Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab GPU计算在非标量输出下运行并行仿真_Matlab_Gpu_Simulation_Montecarlo - Fatal编程技术网

Matlab GPU计算在非标量输出下运行并行仿真

Matlab GPU计算在非标量输出下运行并行仿真,matlab,gpu,simulation,montecarlo,Matlab,Gpu,Simulation,Montecarlo,我想使用GPU计算来运行并行模拟。输入是一个随机向量X,输出是一个大小未知的向量Y。以下是一个工作示例,说明了我想做的事情: %% Find roots to a polynomial with random coefficients and randomly truncate this vector. clear clc % Parameters Mc = 100; % number of simulations p_degree = 1000; % degree of po

我想使用GPU计算来运行并行模拟。输入是一个随机向量
X
,输出是一个大小未知的向量
Y
。以下是一个工作示例,说明了我想做的事情:

%% Find roots to a polynomial with random coefficients and randomly truncate this vector.
clear 
clc

% Parameters
Mc = 100;        % number of simulations
p_degree = 1000; % degree of polynomial

% Simulate Data
parallel.gpu.rng(1);
for ii = 1:Mc
    sgpu(ii).f = gpuArray.rand(p_degree,1);  % Structure to be used in arrayfun with GPU
    s(ii).f = gather(sgpu(ii).f); % Structure to be used in arrayfun with CPU
end

% Calculate using CPU
t = tic();
A = arrayfun(@(x)(temp_roots(x.f)), s, 'UniformOutput', false);
time_CPU = toc(t);

% Calculate using GPU
t = tic();
B = arrayfun(@(x)(temp_roots(x.f)), sgpu, 'UniformOutput', false);
time_GPU = toc(t);

% Output times
sprintf( '%1.2fsecs (CPU)', time_CPU)
sprintf( '%1.2fsecs (GPU)', time_GPU)

function [r] = temp_roots(p)
a = roots(p);
b = ceil(rand(1)*size(a,1));
r = a(1:b);
end
使用带有gpuArray输入的arrayfun不会提高计算时间。我认为这是因为arrayfun和gpuArray输入不允许使用句柄
'UniformOutput',false
。实际上,根据上的帮助文件,“不支持更改输入或输出数组(cat、重塑等)的大小或形状的操作”。因此,我假设,
B=arrayfun(@(x)(temp_根(x.f)),sgpu,'UniformOutput',false)是在CPU上计算的,因此我们看不到性能的提高

我的问题是这些。有没有办法使用
arrayfun
或其他函数,以便我可以在GPU上运行大量独立的模拟?当输入为gpuArray true时,我是否断言
'UniformOutput',false
不是arrayfun的有效句柄?为什么我在工作示例中看不到计算性能的提高——机械上发生了什么?当
'UniformOutput',提供false
时,Matlab是否在CPU上运行
arrayfun