マルチコアCPUとGPUを併用した並列計算 / Parallel computing combined use of multi-core CPU and multi-GPU

9 次查看(过去 30 天)
以下のプログラムをマルチコアCPUとGPUを併用して並列計算をしたいのですが、parpoolで並列プールを呼び出しても、マルチコアCPU物理コア数のみしか呼び出せません。どのように設定すればGPUを併用した並列計算をできるのでしょうか?
I would like to perform parallel computation of the following program by combined use of multi-core CPU and multi-GPU, but when I call the parpool('local'), MATLAB can only be called the multi-core CPU. How should I set it up so that I can do the parallel calculation by combined use of multi-core CPU and multi-GPU?
n = 10000;
m = 500;
v = zeros(1,n);
parpool('local');
parfor i=1:n
A = rand(1,m);
B = rand(m,1);
v(i) = A*B;
end
delete(gcp('nocreate'));
  1 个评论
Masanari DATEKYU
Masanari DATEKYU 2021-10-16
過去の質問から、以下のプログラムを実行 / From past questions, run the following program
n = 1000;
m = 500;
v = zeros(1,n);
parpool('local');
tic;
parfor i=1:n
if mod(i,16)==0
gpuDevice(1);
A = rand(1,m,'gpuArray');
B = rand(m,1,'gpuArray');
v(i) = A*B;
elseif mod(i,16)==1
gpuDevice(2);
A = rand(1,m,'gpuArray');
B = rand(m,1,'gpuArray');
v(i) = A*B;
elseif mod(i,16)==2
gpuDevice(3);
A = rand(1,m,'gpuArray');
B = rand(m,1,'gpuArray');
v(i) = A*B;
elseif mod(i,16)==3
gpuDevice(4);
A = rand(1,m,'gpuArray');
B = rand(m,1,'gpuArray');
v(i) = A*B;
else
A = rand(1,m);
B = rand(m,1);
v(i) = A*B;
end
end
toc
delete(gcp('nocreate'));
Result:CPU → 0.39sec、CPU+GPU→50sec
GPU使用量が増えたためGPU並列計算が可能となったが、何故か実行時間がCPUよりも劇的に増えた。
Parallel computation by combined use of multi-core CPU and multi-GPU can be done because of the increased GPU usage, but processing time of CPU+GPU is more dramatically long than the only multi-core CPU

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 並列計算の基礎 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!