How Can I Parallel this?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
Can the code below be done in parallel? RTBlock.mat file has the necessary variables for the ART function. ProductImage in block 2 uses the ProductImage from block 1, etc. Any ideas how I can parallel or speed up this code? It seems impossible, but I'm wondering if anyone out there has defied the odd.
%Initial setup
ProductImage = InitialRimage; % Setup the initial ProductImage
for block = 1:10
%Uncompress 336 X 25 cells
load(['c:/Project/RTBlock_' num2str(block) '.mat']);
ProductImage = ART(block, Pointers, Weights, ImageGain, ErrorGain, TrueScan, ProductImage);
end
I'm using MATLAB R2023a with Image Processing & Parallel Computing Toolboxes. I have access to 14 cores, 20 logical processors, and Nvidia RTX 3080 GPU.
Thanks in advance!
0 个评论
回答(1 个)
Walter Roberson
2023-4-28
Running it in parallel is only possible if the calculation being done turns out to be a reduction variable; see https://www.mathworks.com/help/parallel-computing/reduction-variable.html
2 个评论
Raymond Norris
2023-4-28
@DB do you have a collection RTBlock projects? Within your project folder you have 10 MAT-files that you're looping through. As Walter mentioned, unless ProductImage is a reduction variable (and by the sounds of it, I'd say no), another consideration is to loop over set of projects (in parallel). For instance
list_of_projects = dir('c:\Project*');
parfor idx = 1:numel(list_of_projects)
unit_of_work(idx)
end
function unit_of_work(idx)
%Initial setup
ProductImage = InitialRimage; % Setup the initial ProductImage
mat_files = dir('c:\Project\RTBlock_*.mat');
for block = 1:numel(mat_files)
%Uncompress 336 X 25 cells
load(['c:/Project' num2str(idx) '/RTBlock_' num2str(block) '.mat']);
ProductImage = ART(block, Pointers, Weights, ImageGain, ErrorGain, TrueScan, ProductImage);
end
Also keep in mind, running a local pool will (by default) cancel out any multi-threading. The gain of multi-processing might be partially canceled out by the lack of multi-threading.
Walter Roberson
2023-4-28
Also;
In some cases, if the results of the previous block are not needed until "late" in the calculation of the new block, then you can overlap calculations by using SPMD and labSend() the completed until to the next unit in the chain. You would probably only want to be using a pool size of 2 for that, I think.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!