How Can I Parallel this?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 28 de Abr. de 2023
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 comentarios
Raymond Norris
el 28 de Abr. de 2023
@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
el 28 de Abr. de 2023
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.
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!